parent
e469af2ebc
commit
6326daa120
@ -0,0 +1,4 @@ |
|||||||
|
__kernel void Fill (__global TYPE* data, TYPE a) |
||||||
|
{ |
||||||
|
data[get_global_id(0)] = a; |
||||||
|
} |
@ -0,0 +1,138 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2009-2016 jMonkeyEngine |
||||||
|
* 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 'jMonkeyEngine' 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 com.jme3.opencl.lwjgl; |
||||||
|
|
||||||
|
import com.jme3.math.Quaternion; |
||||||
|
import com.jme3.math.Vector2f; |
||||||
|
import com.jme3.math.Vector4f; |
||||||
|
import com.jme3.opencl.*; |
||||||
|
import java.nio.ByteBuffer; |
||||||
|
import org.lwjgl.opencl.CL10; |
||||||
|
import org.lwjgl.opencl.CLKernel; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @author Sebastian Weiss |
||||||
|
*/ |
||||||
|
public class LwjglKernel extends Kernel { |
||||||
|
|
||||||
|
private final CLKernel kernel; |
||||||
|
|
||||||
|
public LwjglKernel(CLKernel kernel) { |
||||||
|
this.kernel = kernel; |
||||||
|
} |
||||||
|
|
||||||
|
public CLKernel getKernel() { |
||||||
|
return kernel; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getName() { |
||||||
|
return kernel.getInfoString(CL10.CL_KERNEL_FUNCTION_NAME); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public int getArgCount() { |
||||||
|
return kernel.getInfoInt(CL10.CL_KERNEL_NUM_ARGS); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setArg(int index, LocalMemPerElement t) { |
||||||
|
throw new UnsupportedOperationException("Not supported yet."); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setArg(int index, LocalMem t) { |
||||||
|
throw new UnsupportedOperationException("Not supported yet."); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setArg(int index, Buffer t) { |
||||||
|
throw new UnsupportedOperationException("Not supported yet."); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setArg(int index, byte b) { |
||||||
|
throw new UnsupportedOperationException("Not supported yet."); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setArg(int index, short s) { |
||||||
|
throw new UnsupportedOperationException("Not supported yet."); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setArg(int index, int i) { |
||||||
|
throw new UnsupportedOperationException("Not supported yet."); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setArg(int index, long l) { |
||||||
|
throw new UnsupportedOperationException("Not supported yet."); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setArg(int index, float f) { |
||||||
|
throw new UnsupportedOperationException("Not supported yet."); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setArg(int index, double d) { |
||||||
|
throw new UnsupportedOperationException("Not supported yet."); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setArg(int index, Vector2f v) { |
||||||
|
throw new UnsupportedOperationException("Not supported yet."); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setArg(int index, Vector4f v) { |
||||||
|
throw new UnsupportedOperationException("Not supported yet."); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setArg(int index, Quaternion q) { |
||||||
|
throw new UnsupportedOperationException("Not supported yet."); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void setArg(int index, ByteBuffer buffer, long size) { |
||||||
|
throw new UnsupportedOperationException("Not supported yet."); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Event Run(CommandQueue queue) { |
||||||
|
throw new UnsupportedOperationException("Not supported yet."); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,111 @@ |
|||||||
|
/* |
||||||
|
* Copyright (c) 2009-2016 jMonkeyEngine |
||||||
|
* 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 'jMonkeyEngine' 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 com.jme3.opencl.lwjgl; |
||||||
|
|
||||||
|
import com.jme3.opencl.Kernel; |
||||||
|
import com.jme3.opencl.KernelCompilationException; |
||||||
|
import com.jme3.opencl.Program; |
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.logging.Level; |
||||||
|
import java.util.logging.Logger; |
||||||
|
import org.lwjgl.PointerBuffer; |
||||||
|
import org.lwjgl.opencl.*; |
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
* @author Sebastian Weiss |
||||||
|
*/ |
||||||
|
public class LwjglProgram implements Program { |
||||||
|
private static final Logger LOG = Logger.getLogger(LwjglProgram.class.getName()); |
||||||
|
|
||||||
|
private final CLProgram program; |
||||||
|
private final LwjglContext context; |
||||||
|
|
||||||
|
public LwjglProgram(CLProgram program, LwjglContext context) { |
||||||
|
this.program = program; |
||||||
|
this.context = context; |
||||||
|
} |
||||||
|
|
||||||
|
public CLProgram getProgram() { |
||||||
|
return program; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void build(String args) throws KernelCompilationException { |
||||||
|
int ret = CL10.clBuildProgram(program, (PointerBuffer) null, args, null); |
||||||
|
if (ret != CL10.CL_SUCCESS) { |
||||||
|
String log = Log(); |
||||||
|
LOG.log(Level.WARNING, "Unable to compile program:\n{0}", log); |
||||||
|
if (ret == CL10.CL_BUILD_PROGRAM_FAILURE) { |
||||||
|
throw new KernelCompilationException("Failed to build program", ret, log); |
||||||
|
} else { |
||||||
|
Utils.checkError(ret, "clBuildProgram"); |
||||||
|
} |
||||||
|
} else { |
||||||
|
LOG.log(Level.INFO, "Program compiled:\n{0}", Log()); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void build() throws KernelCompilationException { |
||||||
|
build(""); |
||||||
|
} |
||||||
|
|
||||||
|
private String Log() { |
||||||
|
StringBuilder str = new StringBuilder(); |
||||||
|
for (LwjglDevice device : context.getDevices()) { |
||||||
|
CLDevice d = device.getDevice(); |
||||||
|
str.append(device.getName()).append(":\n"); |
||||||
|
str.append(program.getBuildInfoString(d, CL10.CL_PROGRAM_BUILD_LOG)); |
||||||
|
str.append('\n'); |
||||||
|
} |
||||||
|
return str.toString(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Kernel createKernel(String name) { |
||||||
|
CLKernel kernel = CL10.clCreateKernel(program, name, Utils.errorBuffer); |
||||||
|
Utils.checkError(Utils.errorBuffer, "clCreateKernel"); |
||||||
|
return new LwjglKernel(kernel); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Kernel[] createAllKernels() { |
||||||
|
CLKernel[] kernels = program.createKernelsInProgram(); |
||||||
|
Kernel[] kx = new Kernel[kernels.length]; |
||||||
|
for (int i=0; i<kernels.length; ++i) { |
||||||
|
kx[i] = new LwjglKernel(kernels[i]); |
||||||
|
} |
||||||
|
return kx; |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue