diff options
-rw-r--r-- | resources/cl-impl.cfg | 8 | ||||
-rw-r--r-- | resources/clImplCustomCode.c | 33 | ||||
-rw-r--r-- | src/com/jogamp/opencl/CLPlatform.java | 7 | ||||
-rw-r--r-- | src/com/jogamp/opencl/llb/impl/CLImpl.java | 21 |
4 files changed, 49 insertions, 20 deletions
diff --git a/resources/cl-impl.cfg b/resources/cl-impl.cfg index 1f9240a2..977f430e 100644 --- a/resources/cl-impl.cfg +++ b/resources/cl-impl.cfg @@ -45,11 +45,6 @@ ProcAddressNameExpr $UpperCase(arg) #...or force all ForceProcAddressGen __ALL__ -Unignore clGetExtensionFunctionAddress -RenameJavaMethod clGetExtensionFunctionAddress clGetExtensionFunctionAddressImpl -AccessControl clGetExtensionFunctionAddressImpl PROTECTED -ArgumentIsString clGetExtensionFunctionAddressImpl 0 - #append to generated c files CustomCCode #include <CL/cl.h> CustomCCode #include <CL/cl_ext.h> @@ -79,6 +74,9 @@ ForceProcAddressGen clSetEventCallback Ignore clSetMemObjectDestructorCallback ForceProcAddressGen clSetMemObjectDestructorCallback +Ignore clGetExtensionFunctionAddress +ForceProcAddressGen clGetExtensionFunctionAddress + #take buffer capacity from input param 5 ReturnValueCapacity clEnqueueMapBuffer {5} diff --git a/resources/clImplCustomCode.c b/resources/clImplCustomCode.c index fba3cb3d..d1442f66 100644 --- a/resources/clImplCustomCode.c +++ b/resources/clImplCustomCode.c @@ -409,3 +409,36 @@ Java_com_jogamp_opencl_llb_impl_CLImpl_clSetMemObjectDestructorCallback0(JNIEnv return _res; } + +/* Java->C glue code: + * Java package: com.jogamp.opencl.llb.impl.CLImpl + * Java method: java.nio.ByteBuffer dispatch_clGetExtensionFunctionAddressImpl(java.lang.String func_name) + * C function: void * clGetExtensionFunctionAddress(const char * func_name); + */ +JNIEXPORT jlong JNICALL +Java_com_jogamp_opencl_llb_impl_CLImpl_dispatch_1clGetExtensionFunctionAddress1__Ljava_lang_String_2J(JNIEnv *env, jobject _unused, + jstring func_name, jlong procAddress) { + + typedef void * (*_local_ARG)(const char * func_name); + _local_ARG ptr_clGetExtensionFunctionAddress; + const char* _strchars_func_name = NULL; + void * _res; + + if (NULL != func_name) { + _strchars_func_name = (*env)->GetStringUTFChars(env, func_name, (jboolean*) NULL); + if (NULL == _strchars_func_name) { + (*env)->ThrowNew(env, (*env)->FindClass(env, "java/lang/OutOfMemoryError"), "Failed to get UTF-8 chars for argument \"func_name\""); + return 0; + } + } + + ptr_clGetExtensionFunctionAddress = (_local_ARG) (intptr_t) procAddress; + _res = (* ptr_clGetExtensionFunctionAddress) ((char *) _strchars_func_name); + + if (NULL != func_name) { + (*env)->ReleaseStringUTFChars(env, func_name, _strchars_func_name); + } + if (NULL == _res) return 0; + + return (jlong)_res; +} diff --git a/src/com/jogamp/opencl/CLPlatform.java b/src/com/jogamp/opencl/CLPlatform.java index 9e5308f9..6c08e9ee 100644 --- a/src/com/jogamp/opencl/CLPlatform.java +++ b/src/com/jogamp/opencl/CLPlatform.java @@ -174,11 +174,6 @@ public class CLPlatform { @Override public long resolve(String name, DynamicLookupHelper lookup) { - //FIXME workaround to fix a gluegen issue - if(name.endsWith("Impl")) { - name = name.substring(0, name.length() - "Impl".length()); - } - if(name.endsWith("KHR") || name.endsWith("EXT")) { long address = ((CLImpl) cl).clGetExtensionFunctionAddress(name); if(address != 0) { @@ -203,7 +198,7 @@ public class CLPlatform { } //eagerly init function to query extension addresses (used in reset()) - table.initEntry("clGetExtensionFunctionAddressImpl", libOpenCL); + table.initEntry("clGetExtensionFunctionAddress", libOpenCL); table.reset(libOpenCL); return null; } diff --git a/src/com/jogamp/opencl/llb/impl/CLImpl.java b/src/com/jogamp/opencl/llb/impl/CLImpl.java index d4a1672b..c5a49f44 100644 --- a/src/com/jogamp/opencl/llb/impl/CLImpl.java +++ b/src/com/jogamp/opencl/llb/impl/CLImpl.java @@ -32,7 +32,6 @@ package com.jogamp.opencl.llb.impl; import com.jogamp.common.nio.NativeSizeBuffer; -import com.jogamp.common.os.Platform; import com.jogamp.common.util.LongLongHashMap; import com.jogamp.opencl.CLErrorHandler; import com.jogamp.opencl.CLException; @@ -256,19 +255,23 @@ public class CLImpl extends CLAbstractImpl { int event_byte_offset, Object errcode_ret, int errcode_ret_byte_offset); /** - * Returns the extension function address for the given function name. + * Returns the address of a extension function with the supplied name. */ public long clGetExtensionFunctionAddress(String name) { - ByteBuffer res = super.clGetExtensionFunctionAddressImpl(name); - if(res == null) { - return 0; - }else if (Platform.is32Bit()) { - return res.getInt(); - } else { - return res.getLong(); + + final long address = addressTable._addressof_clGetExtensionFunctionAddress; + + if (address == 0) { + throw new UnsupportedOperationException("Method not available"); } + + return dispatch_clGetExtensionFunctionAddress1(name, address); } + /** Entry point (through function pointer) to C language function: <br> <code> void * {@native clGetExtensionFunctionAddress}(const char * func_name); </code> */ + private native long dispatch_clGetExtensionFunctionAddress1(String func_name, long procAddress); + + public CLProcAddressTable getAddressTable() { return addressTable; } |