Added support for OpenCL 1.2 [UNTESTED]

This commit is contained in:
Ioannis Tsakpinis 2011-11-16 14:36:28 +00:00
parent fb788c9ec1
commit ad7769f9c9
22 changed files with 943 additions and 166 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002-2010 LWJGL Project
* Copyright (c) 2002-2011 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -31,8 +31,6 @@
*/
package org.lwjgl.opencl;
import org.lwjgl.PointerWrapperAbstract;
/**
* Instances of this class can be used to receive OpenCL program build notifications.
* A single CLBuildProgramCallback instance should only be used with programs created
@ -40,37 +38,6 @@ import org.lwjgl.PointerWrapperAbstract;
*
* @author Spasi
*/
public abstract class CLBuildProgramCallback extends PointerWrapperAbstract {
private CLContext context;
protected CLBuildProgramCallback() {
super(CallbackUtil.getBuildProgramCallback());
}
/**
* Sets the context that contains the CLPrograms to which we're registered.
*
* @param context the CLContext object
*/
void setContext(final CLContext context) {
this.context = context;
}
/**
* Called from native code.
*
* @param program_address the CLProgram object pointer
*/
private void handleMessage(long program_address) {
handleMessage(context.getCLProgram(program_address));
}
/**
* The callback method.
*
* @param program the CLProgram object that was built
*/
protected abstract void handleMessage(CLProgram program);
public abstract class CLBuildProgramCallback extends CLProgramCallback {
}

View file

@ -53,23 +53,23 @@ final class CLChecks {
/**
* Calculates the number of bytes in the specified cl_mem buffer rectangle region.
*
* @param origin the host origin
* @param offset the host offset
* @param region the rectangle region
* @param row_pitch the host row pitch
* @param slice_pitch the host slice pitch
*
* @return the region size in bytes
*/
static int calculateBufferRectSize(final PointerBuffer origin, final PointerBuffer region, long row_pitch, long slice_pitch) {
static int calculateBufferRectSize(final PointerBuffer offset, final PointerBuffer region, long row_pitch, long slice_pitch) {
if ( !LWJGLUtil.CHECKS )
return 0;
final long x = origin.get(0);
final long y = origin.get(1);
final long z = origin.get(2);
final long x = offset.get(0);
final long y = offset.get(1);
final long z = offset.get(2);
if ( LWJGLUtil.DEBUG && (x < 0 || y < 0 || z < 0) )
throw new IllegalArgumentException("Invalid cl_mem host origin: " + x + ", " + y + ", " + z);
throw new IllegalArgumentException("Invalid cl_mem host offset: " + x + ", " + y + ", " + z);
final long w = region.get(0);
final long h = region.get(1);

View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2002-2011 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.opencl;
/**
* Instances of this class can be used to receive OpenCL program compilation notifications.
* A single CLCompileProgramCallback instance should only be used with programs created
* in the same CLContext.
*
* @author Spasi
*/
public abstract class CLCompileProgramCallback extends CLProgramCallback {
}

View file

@ -49,10 +49,14 @@ public final class CLContext extends CLObjectChild<CLPlatform> {
private static final CLContextUtil util = (CLContextUtil)CLPlatform.getInfoUtilInstance(CLContext.class, "CL_CONTEXT_UTIL");
private final CLObjectRegistry<CLCommandQueue> clCommandQueues;
private final CLObjectRegistry<CLMem> clMems;
private final CLObjectRegistry<CLSampler> clSamplers;
private final CLObjectRegistry<CLProgram> clPrograms;
private final CLObjectRegistry<CLEvent> clEvents;
private final CLObjectRegistry<CLMem> clMems;
private final CLObjectRegistry<CLSampler> clSamplers;
private final CLObjectRegistry<CLProgram> clPrograms;
private final CLObjectRegistry<CLEvent> clEvents;
private long
contextCallback,
printfCallback;
CLContext(final long pointer, final CLPlatform platform) {
super(pointer, platform);
@ -269,4 +273,50 @@ public final class CLContext extends CLObjectChild<CLPlatform> {
CLObjectRegistry<CLEvent> getCLEventRegistry() { return clEvents; }
private boolean checkCallback(final long callback, final int result) {
if ( result == 0 && (callback == 0 || isValid()) )
return true;
if ( callback != 0 )
CallbackUtil.deleteGlobalRef(callback);
return false;
}
/**
* Associates this context with the specified context callback reference. If the context
* is invalid, the callback reference is deleted. NO-OP if user_data is 0.
*
* @param callback the context callback pointer
*/
void setContextCallback(final long callback) {
if ( checkCallback(callback, 0) )
this.contextCallback = callback;
}
/**
* Associates this context with the specified printf callback reference. If the context
* is invalid, the callback reference is deleted. NO-OP if user_data is 0.
*
* @param callback the printf callback pointer
*/
void setPrintfCallback(final long callback, final int result) {
if ( checkCallback(callback, result) )
this.printfCallback = callback;
}
/**
* Decrements the context's reference count. If the reference
* count hits zero, it also deletes
* any callback objects associated with it.
*/
void releaseImpl() {
if ( release() > 0 )
return;
if ( contextCallback != 0 )
CallbackUtil.deleteGlobalRef(contextCallback);
if ( printfCallback != 0 )
CallbackUtil.deleteGlobalRef(printfCallback);
}
}

View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2002-2011 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.opencl;
/**
* Instances of this class can be used to receive OpenCL program linkage notifications.
* A single CLLinkProgramCallback instance should only be used with programs created
* in the same CLContext.
*
* @author Spasi
*/
public abstract class CLLinkProgramCallback extends CLProgramCallback {
}

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2002-2011 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.opencl;
import org.lwjgl.PointerWrapperAbstract;
/**
* Instances of this class can be used to receive OpenCL printf messages.
* Different CLContexts should use different CLPrintfCallback instances.
*
* @author Spasi
*/
public abstract class CLPrintfCallback extends PointerWrapperAbstract {
protected CLPrintfCallback() {
super(CallbackUtil.getPrintfCallback());
}
/** The callback method. */
protected abstract void handleMessage(String data);
}

View file

@ -0,0 +1,74 @@
/*
* Copyright (c) 2002-2011 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.lwjgl.opencl;
import org.lwjgl.PointerWrapperAbstract;
/**
* Base class for OpenCL program action notifications.
*
* @author Spasi
*/
abstract class CLProgramCallback extends PointerWrapperAbstract {
private CLContext context;
protected CLProgramCallback() {
super(CallbackUtil.getProgramCallback());
}
/**
* Sets the context that contains the CLPrograms to which we're registered.
*
* @param context the CLContext object
*/
final void setContext(final CLContext context) {
this.context = context;
}
/**
* Called from native code.
*
* @param program_address the CLProgram object pointer
*/
private void handleMessage(long program_address) {
handleMessage(context.getCLProgram(program_address));
}
/**
* The callback method.
*
* @param program the CLProgram object affected
*/
protected abstract void handleMessage(CLProgram program);
}

View file

@ -70,7 +70,7 @@ final class CallbackUtil {
*
* @param ref the GlobalRef memory address.
*/
private static native void deleteGlobalRef(long ref);
static native void deleteGlobalRef(long ref);
/**
* Deletes the global reference represented by user_data if an OpenCL error occured.
@ -99,40 +99,6 @@ final class CallbackUtil {
*/
static native long getContextCallback();
/**
* Associates the specified CLContext with the specified global reference. If the context
* is invalid, the global reference is deleted. NO-OP if user_data is 0.
*
* @param context the CLContext to register
* @param user_data the global reference pointer
*/
static void registerCallback(final CLContext context, final long user_data) {
if ( user_data == 0 )
return;
if ( context.isValid() )
contextUserData.put(context, user_data);
else
deleteGlobalRef(user_data);
}
/**
* Decrements the specified context's reference count, clears its association
* with a CLContextCallback object if it exists and deletes the corresponding
* global reference.
*
* @param context the CLContext to unregister
*/
static void unregisterCallback(final CLContext context) {
if ( context.release() > 0 )
return;
final Long user_data = contextUserData.remove(context);
if ( user_data != null )
deleteGlobalRef(user_data);
}
/* [ Other callback functionality ]
The other callbacks are simpler. We create the GlobalRef before passing the callback,
we delete it when we receive the callback call.
@ -150,7 +116,7 @@ final class CallbackUtil {
*
* @return the callback function address
*/
static native long getBuildProgramCallback();
static native long getProgramCallback();
/**
* Returns the memory address of the native function we pass to clEnqueueNativeKernel.
@ -166,6 +132,13 @@ final class CallbackUtil {
*/
static native long getEventCallback();
/**
* Returns the memory address of the native function we pass to clSetPrintfCallback.
*
* @return the callback function address
*/
static native long getPrintfCallback();
/**
* Returns the memory address of the native function we pass to clCreateContext(FromType),
* when <code>APPLEContextLoggingUtil.SYSTEM_LOG_CALLBACK</code> is used.

View file

@ -123,7 +123,7 @@ final class InfoUtilFactory {
Util.checkCLError(errcode_ret.get(0));
return __result;
} finally {
CallbackUtil.registerCallback(__result, user_data);
if ( __result != null ) __result.setContextCallback(user_data);
}
}

View file

@ -373,20 +373,22 @@ public class Utils {
if ( param != null && p.getSimpleName().equals(param.getSimpleName()) )
break;
if ( p.getAnnotation(NullTerminated.class) != null )
continue;
final Class type = Utils.getJavaType(p.getType());
if ( type.equals(CharSequence.class) ) {
if ( offset == null )
offset = p.getSimpleName() + ".length()";
else
offset += " + " + p.getSimpleName() + ".length()";
if ( p.getAnnotation(NullTerminated.class) != null ) offset += " + 1";
//if ( p.getAnnotation(NullTerminated.class) != null ) offset += " + 1";
} else if ( type.equals(CharSequence[].class) ) {
if ( offset == null )
offset = "APIUtil.getTotalLength(" + p.getSimpleName() + ")";
else
offset += " + APIUtil.getTotalLength(" + p.getSimpleName() + ")";
if ( p.getAnnotation(NullTerminated.class) != null ) offset += " + " + p.getSimpleName() + ".length";
//if ( p.getAnnotation(NullTerminated.class) != null ) offset += " + " + p.getSimpleName() + ".length";
}
}

View file

@ -51,7 +51,7 @@ public class CLPDCapabilitiesGenerator {
// TODO: Add future versions here
private static final int[][] CL_VERSIONS = {
{ 1 }, // OpenCL 1
{ 1, 2 }, // OpenCL 1
};
static void generateClassPrologue(final PrintWriter writer, final String name) {