From 9433e6047828583a507ddf118e26c4c150721edf Mon Sep 17 00:00:00 2001 From: Sylvain Munaut Date: Thu, 24 Jul 2014 01:32:52 +0200 Subject: fosphor/cl: Handle CL 1.1 vs 1.2 differently The OpenCL 1.2 is nicer but we can't always use it and on linux, even if the CL_VERSION_1_2 exists, we can't trust it because distrib sometimes have CL 1.2 headers with a CL 1.1 dispatcher. So instead, we only assume we have 1.1 header and lib at compile time. Then at run-time we do a dynamic lookup of the 1.2 symbols from the lib. We also check if the actual selected platform does support 1.2 (you could have a 1.2 dispatcher with a 1.1 platform implementation). If both conditions are satisfied, then we dispatch the call to the 1.2 implementation and if not, then we dispatch them to a local fallback implementation of the functions (but limited to the functions we need) It's not pretty but it should work and it isolates all the hack magic inside cl_compat.{c,h} and you just use the CL1.2 API normally outside of it. Signed-off-by: Sylvain Munaut --- lib/fosphor/cl.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/fosphor/cl.c') diff --git a/lib/fosphor/cl.c b/lib/fosphor/cl.c index 7cbb795..edf82c3 100644 --- a/lib/fosphor/cl.c +++ b/lib/fosphor/cl.c @@ -34,6 +34,7 @@ #include #include "cl_platform.h" +#include "cl_compat.h" #if defined(__APPLE__) || defined(MAXOSX) # include @@ -461,7 +462,7 @@ cl_do_init(struct fosphor *self) /* GL shared objects */ /* Waterfall texture */ - cl->mem_waterfall = clCreateFromGLTexture2D(cl->ctx, + cl->mem_waterfall = clCreateFromGLTexture(cl->ctx, CL_MEM_READ_WRITE, GL_TEXTURE_2D, 0, fosphor_gl_get_shared_id(self, GL_ID_TEX_WATERFALL), &err @@ -469,7 +470,7 @@ cl_do_init(struct fosphor *self) CL_ERR_CHECK(err, "Unable to share waterfall texture into OpenCL context"); /* Histogram texture */ - cl->mem_histogram = clCreateFromGLTexture2D(cl->ctx, + cl->mem_histogram = clCreateFromGLTexture(cl->ctx, CL_MEM_READ_WRITE, GL_TEXTURE_2D, 0, fosphor_gl_get_shared_id(self, GL_ID_TEX_HISTOGRAM), &err @@ -600,6 +601,10 @@ fosphor_cl_init(struct fosphor *self) fprintf(stderr, "[+] Selected device: %s\n", dev_name); + /* Setup compatibility layer for this platform */ + cl_compat_init(); + cl_compat_check_platform(cl->pl_id); + /* Initialize selected platform / device */ err = cl_do_init(self); if (err) -- cgit v1.2.3