summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Pouzenc <ludovic@pouzenc.fr>2013-03-10 15:47:28 +0000
committerLudovic Pouzenc <ludovic@pouzenc.fr>2013-03-10 15:47:28 +0000
commit149388bfe5069aaefe7bbcd43cca59703e42531d (patch)
tree933c615a1721b346700e6cb2bcce41517f2d2ae3
parentae7574e62a0a629b7b33a0df56091a51bba275cb (diff)
download2013-gpudataviz-149388bfe5069aaefe7bbcd43cca59703e42531d.tar.gz
2013-gpudataviz-149388bfe5069aaefe7bbcd43cca59703e42531d.tar.bz2
2013-gpudataviz-149388bfe5069aaefe7bbcd43cca59703e42531d.zip
Commit POURRI : problème de synchro pb GPU/CPU
git-svn-id: file:///var/svn/2013-gpudataviz/trunk@21 371a6b4a-a258-45f8-9dcc-bdd82ce0ac9d
-rw-r--r--src/gpudataviz.cpp43
-rw-r--r--src/opencl_mesh_kit.cpp62
-rw-r--r--src/opencl_mesh_kit.hpp3
3 files changed, 60 insertions, 48 deletions
diff --git a/src/gpudataviz.cpp b/src/gpudataviz.cpp
index b22864e..91ef5fa 100644
--- a/src/gpudataviz.cpp
+++ b/src/gpudataviz.cpp
@@ -281,40 +281,41 @@ bool MyGTKGLSceneWidget::do_mouse_logic(GdkEventType type, guint state, guint x,
* GDK_MOD1_MASK, ... (normally MOD1 it is the Alt key)
* GDK_SUPER_MASK, GDK_HYPER_MASK, GDK_META_MASK (extra keybord modifier keys)
*/
- // Static variables to hold previous mouse button event
- static GdkEventType prev_type = GDK_NOTHING;
- /*static guint prev_state=0; UNUSED FOR NOW */
- static guint drag_x=0, drag_y=0;
-
+ static GdkEventType prev_type = GDK_NOTHING; // Static variable to hold previous mouse button event
+ static guint drag_x=0, drag_y=0; // Static for DRAGING displacement calculus
+ static float t=0.0f; // XXX Just for playing with time
bool redraw=false; // Setting it to true will queue a redraw to the widget (invalidate)
- std::cout << "event type " << type << " state " << state << " on (" << x << "," << y << ") " << std::endl;
+ // For event filter debug (display all events)
+ //std::cout << "event type " << type << " state " << state << " on (" << x << "," << y << ") " << std::endl;
/* *** BEGIN event filtering *** */
MOUSE_DRAG_START(GDK_BUTTON2_MASK) {
drag_x=x; drag_y=y;
- //std::cout << "this->camera == {" << this->camera.rx << ", " << this->camera.ry << ", " << this->camera.tz << "}" << std::endl;
}
+ // Carmera rotation
MOUSE_DRAGING(GDK_BUTTON2_MASK) {
float mouse_sensivity = 0.2f;
gint dx = drag_x - x; // Delta movement (since last event)
gint dy = drag_y - y; // Not unsigned !
- // Yes dy for camera.rx, and -= operator
- // GTK mouse coords and Opengl are not on the same coords system
- this->camera.rx -= mouse_sensivity * dy;
- this->camera.ry -= mouse_sensivity * dx;
+ this->camera.rx -= mouse_sensivity * dy; // Camera position update
+ this->camera.ry -= mouse_sensivity * dx; // Yes dy for camera.rx, and -= operator :
+ // GTK mouse coords and OpenGL ones are not on the same coords system
drag_x = x; drag_y = y;
redraw=true;
}
+ // Camera zoom-in
MOUSE_WHEEL(GDK_SCROLL_UP, 0, 0) {
+
if (this->camera.tz + 0.5f <= -0.5f) {
this->camera.tz += 0.5f;
redraw=true;
}
}
+ // Camera zoom-out
MOUSE_WHEEL(GDK_SCROLL_DOWN, 0, 0) {
if (this->camera.tz - 0.5f >= -9.0f) {
this->camera.tz -= 0.5f;
@@ -322,10 +323,19 @@ bool MyGTKGLSceneWidget::do_mouse_logic(GdkEventType type, guint state, guint x,
}
}
+ /*
MOUSE_CLIC(GDK_BUTTON1_MASK, 0, 0) {
//TODO
this->clKit.execKernel("water1", 0.0f);
redraw=true;
+ }*/
+
+ MOUSE_DRAGING(GDK_BUTTON1_MASK) {
+ t+=0.1f;
+ std::cout << "execKernel(\"water1\", " << t << ");" << std::endl;
+ int res = this->clKit.execKernel("water1", t);
+ std::cout << " -> " << res << std::endl;
+ redraw=true;
}
@@ -341,15 +351,8 @@ bool MyGTKGLSceneWidget::do_mouse_logic(GdkEventType type, guint state, guint x,
// Previous button event retention for double-clic filtering
- switch(type) {
- case GDK_BUTTON_PRESS:
- case GDK_BUTTON_RELEASE:
- case GDK_2BUTTON_PRESS:
- prev_type=type;
-// prev_state=state;
- break;
- default:
- break;
+ if ( type == GDK_BUTTON_PRESS || type == GDK_2BUTTON_PRESS || type == GDK_BUTTON_RELEASE ) {
+ prev_type=type;
}
if ( redraw ) queue_draw();
diff --git a/src/opencl_mesh_kit.cpp b/src/opencl_mesh_kit.cpp
index a9010e8..abdf04d 100644
--- a/src/opencl_mesh_kit.cpp
+++ b/src/opencl_mesh_kit.cpp
@@ -155,51 +155,59 @@ cl_int OpenCLMeshKit::compileKernels(std::list<std::string> names, const char so
return 0;
}
-cl_int OpenCLMeshKit::execKernel(std::string kernelName, float time) {
+cl_int OpenCLMeshKit::execKernel(std::string kernelName, float karg_time) {
- cl_int res;
- cl_event eventND[1];
- size_t globalWorkSize[2], localWorkSize[2];
+ cl_int res;
+ cl_event eventND[1];
+ size_t globalWorkSize[2], localWorkSize[2];
cl_kernel kernel;
+ struct timespec before, after;
+
+ clock_gettime(CLOCK_MONOTONIC_RAW, &before);
std::map<std::string,cl_kernel>::iterator ii=this->kernels.find(kernelName);
if ( ii==this->kernels.end() ) {
- std::cerr << "execKernel(\"" << kernelName << "\", " << time << ") failed : no kernel found with this name" << std::endl;
+ std::cerr << "execKernel(\"" << kernelName << "\", " << karg_time \
+ << ") failed : no kernel found with this name" << std::endl;
return -1;
}
-
+
kernel=this->kernels[kernelName];
- // Set local and global work group sizes
- globalWorkSize[0]=this->meshWidth;
- globalWorkSize[1]=this->meshHeight;
- localWorkSize[0]=this->groupSize;
- localWorkSize[1]=1;
+ // Set local and global work group sizes
+ globalWorkSize[0]=this->meshWidth;
+ globalWorkSize[1]=this->meshHeight;
+ localWorkSize[0]=this->groupSize;
+ localWorkSize[1]=1;
- res=clEnqueueAcquireGLObjects(this->cl_cq, 1, &(this->cl_vbo), 0, 0, NULL);
+ res=clEnqueueAcquireGLObjects(this->cl_cq, 1, &(this->cl_vbo), 0, 0, NULL);
- res=clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&(this->cl_vbo)); // float4 *pos
- res=clSetKernelArg(kernel, 1, sizeof(cl_uint), (void *)&(this->meshWidth));
- res=clSetKernelArg(kernel, 2, sizeof(cl_uint), (void *)&(this->meshHeight));
- res=clSetKernelArg(kernel, 3, sizeof(float), (void *)&time);
+ res=clSetKernelArg(kernel, 0, sizeof(cl_mem), (void *)&(this->cl_vbo)); // float4 *pos
+ res=clSetKernelArg(kernel, 1, sizeof(cl_uint), (void *)&(this->meshWidth));
+ res=clSetKernelArg(kernel, 2, sizeof(cl_uint), (void *)&(this->meshHeight));
+ res=clSetKernelArg(kernel, 3, sizeof(float), (void *)&karg_time);
- // Execute kernel on given device
- res=clEnqueueNDRangeKernel(this->cl_cq, kernel, 2, NULL, globalWorkSize, localWorkSize, 0, NULL, eventND);
- if ( res != CL_SUCCESS ) {
+ // Execute kernel on given device
+ res=clEnqueueNDRangeKernel(this->cl_cq, kernel, 2, NULL, globalWorkSize, localWorkSize, 0, NULL, eventND);
+ if ( res != CL_SUCCESS ) {
std::cerr << "clEnqueueNDRangeKernel() failed" << std::endl;
- return 1;
- }
+ return 1;
+ }
//TODO : return values checking
- res=clFlush(this->cl_cq);
+ res=clFlush(this->cl_cq);
// (CPU) Wait until GPU kernel execution end
- res=clWaitForEvents(1,eventND); //XXX: SimpleGL utilise une attente active, pourquoi ?
- res=clReleaseEvent(eventND[0]);
- res=clEnqueueReleaseGLObjects(this->cl_cq, 1, &(this->cl_vbo), 0, 0, 0);
- res=clFinish(this->cl_cq);
+ res=clWaitForEvents(1,eventND); //XXX: SimpleGL utilise une attente active, pourquoi ?
+ res=clReleaseEvent(eventND[0]);
+ res=clEnqueueReleaseGLObjects(this->cl_cq, 1, &(this->cl_vbo), 0, 0, 0);
+ res=clFinish(this->cl_cq);
+
+ clock_gettime(CLOCK_MONOTONIC_RAW, &after);
+ //TODO : remove this debug hint
+ std::cout << "execTime : " << after.tv_nsec - before.tv_nsec << std::cout;
- return CL_SUCCESS;
+ return CL_SUCCESS;
}
void OpenCLMeshKit::releaseKernels() {
diff --git a/src/opencl_mesh_kit.hpp b/src/opencl_mesh_kit.hpp
index f99c6c2..ee6bfa5 100644
--- a/src/opencl_mesh_kit.hpp
+++ b/src/opencl_mesh_kit.hpp
@@ -3,6 +3,7 @@
#include <map>
#include <list>
#include <cstring>
+#include <time.h>
#ifndef STRINGIFY
#define STRINGIFY(x) #x
@@ -14,7 +15,7 @@ class OpenCLMeshKit
//RAII is violated but it is really triky to do differently
cl_int initCL(intptr_t gl_display, intptr_t gl_context, intptr_t gl_vbo, size_t meshWidth, size_t meshHeight, size_t groupSize);
cl_int compileKernels(std::list<std::string> names, const char source[], size_t sourceLen);
- cl_int execKernel(std::string kernelName, float time);
+ cl_int execKernel(std::string kernelName, float karg_time);
void releaseKernels();
size_t getMeshWidth();