OpenGL/CL sharing is not working with lwjgl3. It seems that the context is set up the wrong way.

For now, disable the sharing methods.
Also retrieving the program binaries is disabled, the current implementation would throw a segfault.
This commit is contained in:
shamanDevel 2016-05-09 07:55:46 +02:00
parent 5e098b0493
commit 9a3dce2fb3
7 changed files with 24 additions and 1 deletions

View File

@ -32,6 +32,7 @@ dependencies {
compile project(':jme3-jogg')
compile project(':jme3-jogl')
compile project(':jme3-lwjgl')
// compile project(':jme3-lwjgl3')
compile project(':jme3-networking')
compile project(':jme3-niftygui')
compile project(':jme3-plugins')

View File

@ -203,6 +203,7 @@ public class LwjglBuffer extends Buffer {
@Override
public Event releaseBufferForSharingAsync(CommandQueue queue) {
Utils.assertSharingPossible();
Utils.pointerBuffers[0].rewind();
long q = ((LwjglCommandQueue) queue).getQueue();
int ret = CL10GL.clEnqueueReleaseGLObjects(q, buffer, null, Utils.pointerBuffers[0]);
@ -212,6 +213,7 @@ public class LwjglBuffer extends Buffer {
}
@Override
public void releaseBufferForSharingNoEvent(CommandQueue queue) {
Utils.assertSharingPossible();
long q = ((LwjglCommandQueue) queue).getQueue();
int ret = CL10GL.clEnqueueReleaseGLObjects(q, buffer, null, null);
Utils.checkError(ret, "clEnqueueReleaseGLObjects");

View File

@ -161,6 +161,7 @@ public class LwjglContext extends Context {
@Override
public Buffer bindVertexBuffer(VertexBuffer vb, MemoryAccess access) {
Utils.assertSharingPossible();
int id = vb.getId();
if (id == -1) {
throw new IllegalArgumentException("vertex buffer was not yet uploaded to the GPU or is CPU only");
@ -174,6 +175,7 @@ public class LwjglContext extends Context {
@Override
public Image bindImage(com.jme3.texture.Image image, Texture.Type textureType, int miplevel, MemoryAccess access) {
Utils.assertSharingPossible();
int imageID = image.getId();
if (imageID == -1) {
throw new IllegalArgumentException("image was not yet uploaded to the GPU");
@ -188,6 +190,7 @@ public class LwjglContext extends Context {
@Override
protected Image bindPureRenderBuffer(FrameBuffer.RenderBuffer buffer, MemoryAccess access) {
Utils.assertSharingPossible();
int renderbuffer = buffer.getId();
if (renderbuffer == -1) {
throw new IllegalArgumentException("renderbuffer was not yet uploaded to the GPU");

View File

@ -544,6 +544,7 @@ public class LwjglImage extends Image {
}
@Override
public Event releaseImageForSharingAsync(CommandQueue queue) {
Utils.assertSharingPossible();
Utils.pointerBuffers[0].rewind();
long q = ((LwjglCommandQueue) queue).getQueue();
int ret = CL10GL.clEnqueueReleaseGLObjects(q, image, null, Utils.pointerBuffers[0]);
@ -553,6 +554,7 @@ public class LwjglImage extends Image {
}
@Override
public void releaseImageForSharingNoEvent(CommandQueue queue) {
Utils.assertSharingPossible();
long q = ((LwjglCommandQueue) queue).getQueue();
int ret = CL10GL.clEnqueueReleaseGLObjects(q, image, null, null);
Utils.checkError(ret, "clEnqueueReleaseGLObjects");

View File

@ -153,7 +153,7 @@ public class LwjglProgram extends Program {
ByteBuffer binaries = ByteBuffer.allocateDirect(size);
binaryPointers.put(index, binaries);
//TODO: why the hell does this throw a segfault ?!?
//Fixme: why the hell does this line throw a segfault ?!?
ret = CL10.clGetProgramInfo(program, CL10.CL_PROGRAM_BINARIES, binaryPointers, null);
Utils.checkError(ret, "clGetProgramInfo: CL_PROGRAM_BINARIES");

View File

@ -50,6 +50,12 @@ public class Utils {
private static final Logger LOG = Logger.getLogger(Utils.class.getName());
private Utils() {}
public static final boolean CL_GL_SHARING_POSSIBLE = com.jme3.system.lwjgl.LwjglContext.CL_GL_SHARING_POSSIBLE;
public static void assertSharingPossible() {
if (!CL_GL_SHARING_POSSIBLE) {
throw new OpenCLException("OpenGL/CL sharing not possible");
}
}
public static int getMajorVersion(String version, String prefix) {
String s = version.substring(prefix.length());

View File

@ -75,6 +75,10 @@ public abstract class LwjglContext implements JmeContext {
private static final Logger logger = Logger.getLogger(LwjglContext.class.getName());
//Fixme: OpenGL/CL sharing does not work yet, this line disables the sharing methods
//(They will throw an OpenCLException)
public static final boolean CL_GL_SHARING_POSSIBLE = false;
protected static final String THREAD_NAME = "jME3 Main";
protected AtomicBoolean created = new AtomicBoolean(false);
@ -296,6 +300,11 @@ public abstract class LwjglContext implements JmeContext {
logger.info("OpenCL context created");
}
private long createContext(final CLPlatform platform, final List<CLDevice> devices) throws Exception {
//Fixme: OpenGL/CL sharing does not work. The properties seem to be setup wrongly
// If it works, set CL_GL_SHARING_POSSIBLE to true to enable the sharing
// methods again
final int propertyCount = 2 + 4 + 1;
final PointerBuffer properties = PointerBuffer.allocateDirect(propertyCount + devices.size());