From efef3d54e145ff25f9c901c125ffcdefefbe0d96 Mon Sep 17 00:00:00 2001 From: shamanDevel Date: Mon, 2 May 2016 20:58:39 +0200 Subject: [PATCH] Querying the program binaries won't be supported by the Jocl binding. See the comments inside JoclProgram.getBinary for the reason. --- .../com/jme3/opencl/jocl/JoclContext.java | 6 ++++ .../com/jme3/opencl/jocl/JoclProgram.java | 35 ++++++++++++++----- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/jme3-jogl/src/main/java/com/jme3/opencl/jocl/JoclContext.java b/jme3-jogl/src/main/java/com/jme3/opencl/jocl/JoclContext.java index eca2db012..163e27c68 100644 --- a/jme3-jogl/src/main/java/com/jme3/opencl/jocl/JoclContext.java +++ b/jme3-jogl/src/main/java/com/jme3/opencl/jocl/JoclContext.java @@ -222,6 +222,12 @@ public class JoclContext extends Context { return new JoclProgram(p, this); } + @Override + public Program createProgramFromBinary(ByteBuffer binaries, Device device) { + //Not supported because JoclProgram.getBinaries is also not supported. + throw new UnsupportedOperationException("No supported by Jocl"); + } + private static class ReleaserImpl implements ObjectReleaser { private long id; private final List devices; diff --git a/jme3-jogl/src/main/java/com/jme3/opencl/jocl/JoclProgram.java b/jme3-jogl/src/main/java/com/jme3/opencl/jocl/JoclProgram.java index 1714446cf..157ce63cf 100644 --- a/jme3-jogl/src/main/java/com/jme3/opencl/jocl/JoclProgram.java +++ b/jme3-jogl/src/main/java/com/jme3/opencl/jocl/JoclProgram.java @@ -31,12 +31,10 @@ */ package com.jme3.opencl.jocl; -import com.jme3.opencl.Kernel; -import com.jme3.opencl.KernelCompilationException; -import com.jme3.opencl.OpenCLObjectManager; -import com.jme3.opencl.Program; +import com.jme3.opencl.*; import com.jogamp.common.nio.PointerBuffer; import com.jogamp.opencl.CLPlatform; +import com.jogamp.opencl.CLProgram; import com.jogamp.opencl.llb.CL; import com.jogamp.opencl.util.CLUtil; import java.nio.ByteBuffer; @@ -44,8 +42,6 @@ import java.util.logging.Level; import java.util.logging.Logger; import static com.jogamp.common.nio.Buffers.newDirectByteBuffer; -import static com.jogamp.opencl.CLException.newException; -import static com.jogamp.opencl.llb.CL.CL_SUCCESS; /** * * @author shaman @@ -65,8 +61,18 @@ public class JoclProgram extends Program { } @Override - public void build(String args) throws KernelCompilationException { - int ret = cl.clBuildProgram(program, 0, null, args, null); + public void build(String args, Device... devices) throws KernelCompilationException { + PointerBuffer deviceList = null; + int deviceCount = 0; + if (devices != null) { + deviceList = PointerBuffer.allocateDirect(devices.length); + for (Device d : devices) { + deviceList.put(((JoclDevice) d).id); + } + deviceCount = devices.length; + deviceList.rewind(); + } + int ret = cl.clBuildProgram(program, deviceCount, deviceList, args, null); if (ret != CL.CL_SUCCESS) { String log = Log(); LOG.log(Level.WARNING, "Unable to compile program:\n{0}", log); @@ -126,6 +132,19 @@ public class JoclProgram extends Program { return kx; } + @Override + public ByteBuffer getBinary(Device device) { + //There is no way to do this in Jocl: + //The low-level bindings need a buffer of adresses to buffers. For that + //the class InternalBufferUtil is used, but this class is not public. + //I also can't create a temporal instance of CLProgram because the constructor + //that takes only the native pointer is private. + //So the only way would be to create the CLProgram directly from the beginning. + //I don't want to do this because then I would have to use the whole + //bunch of garbage the CLProgram class is doing in background. + throw new UnsupportedOperationException("Jocl does not expose this operation"); + } + private static class ReleaserImpl implements ObjectReleaser { private long program; private ReleaserImpl(long program) {