OpenCL bug fixes on MacOS.

Improved 64bit pointer detection.
This commit is contained in:
Ioannis Tsakpinis 2010-10-01 22:20:14 +00:00
parent 3470552355
commit f80e5a94d6
7 changed files with 45 additions and 28 deletions

View File

@ -40,6 +40,7 @@ package org.lwjgl;
*/ */
abstract class DefaultSysImplementation implements SysImplementation { abstract class DefaultSysImplementation implements SysImplementation {
public native int getJNIVersion(); public native int getJNIVersion();
public native int getPointerSize();
public native void setDebug(boolean debug); public native void setDebug(boolean debug);
public long getTimerResolution() { public long getTimerResolution() {

View File

@ -77,15 +77,13 @@ public final class Sys {
}); });
} }
private static boolean loadLibrary(final String lib_name) { private static void loadLibrary(final String lib_name) {
try { try {
doLoadLibrary(lib_name); doLoadLibrary(lib_name);
return false;
} catch (UnsatisfiedLinkError e) { } catch (UnsatisfiedLinkError e) {
if (implementation.has64Bit()) { if (implementation.has64Bit()) {
try { try {
doLoadLibrary(lib_name + POSTFIX64BIT); doLoadLibrary(lib_name + POSTFIX64BIT);
return true;
} catch (UnsatisfiedLinkError e2) { } catch (UnsatisfiedLinkError e2) {
LWJGLUtil.log("Failed to load 64 bit library: " + e2.getMessage()); LWJGLUtil.log("Failed to load 64 bit library: " + e2.getMessage());
} }
@ -97,13 +95,14 @@ public final class Sys {
static { static {
implementation = createImplementation(); implementation = createImplementation();
is64Bit = loadLibrary(JNI_LIBRARY_NAME); loadLibrary(JNI_LIBRARY_NAME);
is64Bit = implementation.getPointerSize() == 8;
int native_jni_version = implementation.getJNIVersion(); int native_jni_version = implementation.getJNIVersion();
int required_version = implementation.getRequiredJNIVersion(); int required_version = implementation.getRequiredJNIVersion();
if (native_jni_version != required_version) if (native_jni_version != required_version)
throw new LinkageError("Version mismatch: jar version is '" + required_version + throw new LinkageError("Version mismatch: jar version is '" + required_version +
"', native libary version is '" + native_jni_version + "'"); "', native library version is '" + native_jni_version + "'");
implementation.setDebug(LWJGLUtil.DEBUG); implementation.setDebug(LWJGLUtil.DEBUG);
} }

View File

@ -51,6 +51,11 @@ interface SysImplementation {
*/ */
int getJNIVersion(); int getJNIVersion();
/**
* Returns the platform's pointer size in bytes
*/
int getPointerSize();
void setDebug(boolean debug); void setDebug(boolean debug);
/** /**

View File

@ -430,9 +430,11 @@ final class APIUtil {
static Set<String> getExtensions(final String extensionList) { static Set<String> getExtensions(final String extensionList) {
final Set<String> extensions = new HashSet<String>(); final Set<String> extensions = new HashSet<String>();
final StringTokenizer tokenizer = new StringTokenizer(extensionList); if ( extensionList != null ) {
while ( tokenizer.hasMoreTokens() ) final StringTokenizer tokenizer = new StringTokenizer(extensionList);
extensions.add(tokenizer.nextToken()); while ( tokenizer.hasMoreTokens() )
extensions.add(tokenizer.nextToken());
}
return extensions; return extensions;
} }

View File

@ -34,6 +34,8 @@ package org.lwjgl.opencl;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.lwjgl.opencl.CL10.*;
/** /**
* Utility class that handles OpenCL API callbacks. * Utility class that handles OpenCL API callbacks.
* *
@ -79,7 +81,7 @@ final class CallbackUtil {
* @param user_data the GlobalRef memory address * @param user_data the GlobalRef memory address
*/ */
static void checkCallback(final int errcode, final long user_data) { static void checkCallback(final int errcode, final long user_data) {
if ( errcode != 0x0 && user_data != 0 ) if ( errcode != CL_SUCCESS && user_data != 0 )
deleteGlobalRef(user_data); deleteGlobalRef(user_data);
} }
@ -107,7 +109,7 @@ final class CallbackUtil {
* @param user_data the global reference pointer * @param user_data the global reference pointer
*/ */
static void registerCallback(final CLContext context, final long user_data) { static void registerCallback(final CLContext context, final long user_data) {
if ( context.getPointer() == 0 ) { if ( context.getPointerUnsafe() == 0 ) {
if ( user_data != 0 ) if ( user_data != 0 )
deleteGlobalRef(user_data); deleteGlobalRef(user_data);
return; return;

View File

@ -33,6 +33,7 @@ package org.lwjgl.test.opencl;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
import org.lwjgl.PointerBuffer; import org.lwjgl.PointerBuffer;
import org.lwjgl.opencl.*; import org.lwjgl.opencl.*;
import org.lwjgl.opencl.api.CLBufferRegion; import org.lwjgl.opencl.api.CLBufferRegion;
@ -49,7 +50,7 @@ public class HelloOpenCL {
public HelloOpenCL() { public HelloOpenCL() {
} }
protected void execute() { protected static void execute() {
try { try {
CL.create(); CL.create();
@ -135,28 +136,31 @@ public class HelloOpenCL {
clRetainMemObject(buffer); clRetainMemObject(buffer);
final long exec_caps = device.getInfoLong(CL_DEVICE_EXECUTION_CAPABILITIES); if ( LWJGLUtil.getPlatform() != LWJGLUtil.PLATFORM_MACOSX ) {
if ( (exec_caps & CL_EXEC_NATIVE_KERNEL) == CL_EXEC_NATIVE_KERNEL ) { // TODO: Native kernels crash on MacOSX, disable this until we can debug properly.
System.out.println("-TRYING TO EXEC NATIVE KERNEL-"); final long exec_caps = device.getInfoLong(CL_DEVICE_EXECUTION_CAPABILITIES);
final CLCommandQueue queue = clCreateCommandQueue(context, device, 0, null); if ( (exec_caps & CL_EXEC_NATIVE_KERNEL) == CL_EXEC_NATIVE_KERNEL ) {
System.out.println("-TRYING TO EXEC NATIVE KERNEL-");
final CLCommandQueue queue = clCreateCommandQueue(context, device, 0, null);
clEnqueueNativeKernel(queue, new CLNativeKernel() { clEnqueueNativeKernel(queue, new CLNativeKernel() {
protected void execute(final ByteBuffer[] memobjs) { protected void execute(final ByteBuffer[] memobjs) {
if ( memobjs == null ) if ( memobjs == null )
System.out.println("OK, it's null"); System.out.println("OK, it's null");
else { else {
System.out.println("memobjs = " + memobjs.length); System.out.println("memobjs = " + memobjs.length);
for ( int k = 0; k < memobjs.length; k++ ) { for ( int k = 0; k < memobjs.length; k++ ) {
System.out.println("memobjs[" + k + "].remaining() = " + memobjs[k].remaining()); System.out.println("memobjs[" + k + "].remaining() = " + memobjs[k].remaining());
for ( int l = memobjs[k].position(); l < memobjs[k].limit(); l++ ) { for ( int l = memobjs[k].position(); l < memobjs[k].limit(); l++ ) {
memobjs[k].put(l, (byte)l); memobjs[k].put(l, (byte)l);
}
} }
} }
} }
} }, new CLMem[] { buffer }, new long[] { 128 }, null, null);
}, new CLMem[] { buffer }, new long[] { 128 }, null, null);
clFinish(queue); clFinish(queue);
}
} }
clReleaseMemObject(buffer); clReleaseMemObject(buffer);

View File

@ -61,6 +61,10 @@ void putAttrib(attrib_list_t *list, int attrib) {
list->current_index++; list->current_index++;
} }
JNIEXPORT jint JNICALL Java_org_lwjgl_DefaultSysImplementation_getPointerSize(JNIEnv *env, jclass clazz) {
return (jint)sizeof(void *);
}
JNIEXPORT void JNICALL Java_org_lwjgl_DefaultSysImplementation_setDebug JNIEXPORT void JNICALL Java_org_lwjgl_DefaultSysImplementation_setDebug
(JNIEnv *env, jobject ignored, jboolean enable) { (JNIEnv *env, jobject ignored, jboolean enable) {
debug = enable == JNI_TRUE ? true : false; debug = enable == JNI_TRUE ? true : false;