From aa769549e1268c67f3dbd62191a4071aead0f877 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sun, 17 Feb 2013 12:30:56 +0000 Subject: Ajout init openCL, debut binding buffers (mais l'extension pour les VBO n'est pas active !) git-svn-id: file:///var/svn/2013-gpudataviz/trunk@11 371a6b4a-a258-45f8-9dcc-bdd82ce0ac9d --- tests/poc_c/compil.sh | 9 +++- tests/poc_c/main.c | 112 +++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 100 insertions(+), 21 deletions(-) (limited to 'tests/poc_c') diff --git a/tests/poc_c/compil.sh b/tests/poc_c/compil.sh index f636aaf..d64cc67 100755 --- a/tests/poc_c/compil.sh +++ b/tests/poc_c/compil.sh @@ -1,10 +1,15 @@ #!/bin/bash -e +AMDAPP_PATH=/opt/AMDAPP + CFLAGS="-Wall -g" LDFLAGS="-Wall -g" -CFLAGS="$CFLAGS $(pkg-config --cflags gtkglextmm-1.2)" -LIBS="$(pkg-config --libs gtkglextmm-1.2)" +CFLAGS="$CFLAGS $(pkg-config --cflags gtkglextmm-1.2) -I$AMDAPP_PATH/include" +LIBS="$(pkg-config --libs gtkglextmm-1.2) -lGLEW -lOpenCL -L$AMDAPP_PATH/lib/x86_64" +echo "Compiling..." gcc $CFLAGS -c main.c -o main.o + +echo "Linking..." gcc $LDFLAGS -o main main.o $LIBS diff --git a/tests/poc_c/main.c b/tests/poc_c/main.c index 2b86f0f..4e2be04 100644 --- a/tests/poc_c/main.c +++ b/tests/poc_c/main.c @@ -3,9 +3,12 @@ #include #include -#include +/*#include */ +#include // For VBO OpenGL extensions #include +#include + #include // X11 specific gboolean gl_area_on_draw (GtkObject* area, GdkEventExpose* event, gpointer data) { @@ -18,8 +21,6 @@ gboolean gl_area_on_draw (GtkObject* area, GdkEventExpose* event, gpointer data) return FALSE; } - printf("on_draw_glx_current_context==%p\n", (void *)glXGetCurrentContext()); - GtkAllocation allocation; gtk_widget_get_allocation (GTK_WIDGET (area), &allocation); GLdouble viewport_width = (GLdouble) allocation.width; @@ -83,6 +84,12 @@ int main(int argc, char *argv[]) { Display *glx_display; // X11 specific gboolean res; + glewInit(); + if ( !glewIsSupported("GL_ARB_vertex_buffer_object") ) { + fputs ("OpenGL extension GL_ARB_vertex_buffer_object is mandatory for this application\n", stderr); + return EXIT_FAILURE; + } + gtk_init(&argc, &argv); if (gdk_gl_init_check(&argc, &argv) == FALSE ) { fputs ("Failed to initialize GDKGLExt.\n", stderr); @@ -144,34 +151,101 @@ int main(int argc, char *argv[]) { printf("glx_current_context==%p\n", (void *)glx_context); printf("glx_current_display==%p\n", (void *)glx_display); + + cl_context_properties cpsGL[] = { + /* CL_CONTEXT_PLATFORM value to be filled later */ + CL_CONTEXT_PLATFORM, (cl_context_properties) NULL, + CL_GLX_DISPLAY_KHR, (intptr_t) glx_display, + CL_GL_CONTEXT_KHR, (intptr_t) glx_context, 0 + }; /* END : X11 specific */ gdk_gl_drawable_gl_end (drawable); - //TODO OpenCL init (platform pointer). In a while loop for trying all ? - /* BEGIN : X11 specific */ - cl_context_properties cpsGL[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platform, - CL_GLX_DISPLAY_KHR, (intptr_t) glx_display, - CL_GL_CONTEXT_KHR, (intptr_t) glx_context, 0 - }; + cl_uint i, plat_count; + cl_platform_id *plat_ids, plat_id; + char pbuf[100]; + size_t deviceSize; + cl_device_id device; + cl_context cl_ctx; + cl_command_queue commandQueue; - /* - if (!clGetGLContextInfoKHR) - { - clGetGLContextInfoKHR = (clGetGLContextInfoKHR_fn) clGetExtensionFunctionAddressForPlatform(platform, "clGetGLContextInfoKHR"); - if (!clGetGLContextInfoKHR) - { - std::cout << "Failed to query proc address for clGetGLContextInfoKHR"; - } - } + typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetGLContextInfoKHR_fn)( + const cl_context_properties *properties, + cl_gl_context_info param_name, + size_t param_value_size, + void *param_value, + size_t *param_value_size_ret); + clGetGLContextInfoKHR_fn clGetGLContextInfoKHR_proc; -*/ + clGetPlatformIDs(0, NULL, &plat_count); // Get platform count + if ( ! ( plat_count > 0 ) ) { + fputs ("Failed to find an OpenCL platform\n", stderr); + return EXIT_FAILURE; + } + plat_ids=malloc(sizeof(cl_platform_id *) * plat_count); + clGetPlatformIDs(plat_count, plat_ids, &plat_count); // Get platform IDs + + for(i=0;i