started with the image api, refactored buffer

define_list_fix
shamanDevel 9 years ago
parent a6be243db1
commit 4416295069
  1. 133
      jme3-core/src/main/java/com/jme3/opencl/Buffer.java
  2. 171
      jme3-core/src/main/java/com/jme3/opencl/CL.java
  3. 64
      jme3-core/src/main/java/com/jme3/opencl/Context.java
  4. 196
      jme3-core/src/main/java/com/jme3/opencl/Image.java
  5. 2
      jme3-core/src/main/java/com/jme3/opencl/Kernel.java
  6. 79
      jme3-examples/src/main/java/jme3test/opencl/HelloOpenCL.java
  7. 112
      jme3-lwjgl/src/main/java/com/jme3/opencl/lwjgl/LwjglBuffer.java
  8. 51
      jme3-lwjgl/src/main/java/com/jme3/opencl/lwjgl/LwjglContext.java
  9. 351
      jme3-lwjgl/src/main/java/com/jme3/opencl/lwjgl/LwjglImage.java
  10. 6
      jme3-lwjgl/src/main/java/com/jme3/opencl/lwjgl/LwjglKernel.java
  11. 8
      jme3-lwjgl/src/main/java/com/jme3/opencl/lwjgl/Utils.java

@ -37,44 +37,121 @@ import java.nio.ByteBuffer;
*
* @author Sebastian Weiss
*/
public interface Buffer {
public abstract class Buffer {
int getSize();
public abstract int getSize();
MemoryAccess getMemoryAccessFlags();
public abstract MemoryAccess getMemoryAccessFlags();
void read(CommandQueue queue, ByteBuffer dest, int size, int offset);
void read(CommandQueue queue, ByteBuffer dest, int size);
void read(CommandQueue queue, ByteBuffer dest);
public abstract void read(CommandQueue queue, ByteBuffer dest, int size, int offset);
Event readAsync(CommandQueue queue, ByteBuffer dest, int size, int offset);
Event readAsync(CommandQueue queue, ByteBuffer dest, int size);
Event readAsync(CommandQueue queue, ByteBuffer dest);
public void read(CommandQueue queue, ByteBuffer dest, int size) {
read(queue, dest, size, 0);
}
void write(CommandQueue queue, ByteBuffer src, int size, int offset);
void write(CommandQueue queue, ByteBuffer src, int size);
void write(CommandQueue queue, ByteBuffer src);
public void read(CommandQueue queue, ByteBuffer dest) {
read(queue, dest, getSize());
}
Event writeAsync(CommandQueue queue, ByteBuffer src, int size, int offset);
Event writeAsync(CommandQueue queue, ByteBuffer src, int size);
Event writeAsync(CommandQueue queue, ByteBuffer src);
public abstract Event readAsync(CommandQueue queue, ByteBuffer dest, int size, int offset);
void copyTo(CommandQueue queue, Buffer dest, int size, int srcOffset, int destOffset);
void copyTo(CommandQueue queue, Buffer dest, int size);
void copyTo(CommandQueue queue, Buffer dest);
public Event readAsync(CommandQueue queue, ByteBuffer dest, int size) {
return readAsync(queue, dest, size, 0);
}
Event copyToAsync(CommandQueue queue, Buffer dest, int size, int srcOffset, int destOffset);
Event copyToAsync(CommandQueue queue, Buffer dest, int size);
Event copyToAsync(CommandQueue queue, Buffer dest);
public Event readAsync(CommandQueue queue, ByteBuffer dest) {
return readAsync(queue, dest, getSize());
}
ByteBuffer map(CommandQueue queue, int size, int offset, MappingAccess access);
ByteBuffer map(CommandQueue queue, int size, MappingAccess access);
ByteBuffer map(CommandQueue queue, MappingAccess access);
void unmap(CommandQueue queue, ByteBuffer ptr);
public abstract void write(CommandQueue queue, ByteBuffer src, int size, int offset);
//TODO: async mapping
public void write(CommandQueue queue, ByteBuffer src, int size) {
write(queue, src, size, 0);
}
//TODO: clEnqueueFillBuffer
public void write(CommandQueue queue, ByteBuffer src) {
write(queue, src, getSize());
}
//TODO: image read/write
public abstract Event writeAsync(CommandQueue queue, ByteBuffer src, int size, int offset);
public Event writeAsync(CommandQueue queue, ByteBuffer src, int size) {
return writeAsync(queue, src, size, 0);
}
public Event writeAsync(CommandQueue queue, ByteBuffer src) {
return writeAsync(queue, src, getSize());
}
public abstract void copyTo(CommandQueue queue, Buffer dest, int size, int srcOffset, int destOffset);
public void copyTo(CommandQueue queue, Buffer dest, int size) {
copyTo(queue, dest, size, 0, 0);
}
public void copyTo(CommandQueue queue, Buffer dest) {
copyTo(queue, dest, getSize());
}
public abstract Event copyToAsync(CommandQueue queue, Buffer dest, int size, int srcOffset, int destOffset);
public Event copyToAsync(CommandQueue queue, Buffer dest, int size) {
return copyToAsync(queue, dest, size, 0, 0);
}
public Event copyToAsync(CommandQueue queue, Buffer dest) {
return copyToAsync(queue, dest, getSize());
}
public abstract ByteBuffer map(CommandQueue queue, int size, int offset, MappingAccess access);
public ByteBuffer map(CommandQueue queue, int size, MappingAccess access) {
return map(queue, size, 0, access);
}
public ByteBuffer map(CommandQueue queue, MappingAccess access) {
return map(queue, getSize(), access);
}
public abstract void unmap(CommandQueue queue, ByteBuffer ptr);
public abstract AsyncMapping mapAsync(CommandQueue queue, int size, int offset, MappingAccess access);
public AsyncMapping mapAsync(CommandQueue queue, int size, MappingAccess access) {
return mapAsync(queue, size, 0, access);
}
public AsyncMapping mapAsync(CommandQueue queue, MappingAccess access) {
return mapAsync(queue, getSize(), 0, access);
}
public abstract Event fillAsync(CommandQueue queue, ByteBuffer pattern, int size, int offset);
//TODO: copy to image
/**
* Result of an async mapping operation, contains the event and the target byte buffer.
* This is a work-around since no generic pair-structure is avaiable.
*
* @author Sebastian Weiss
*/
public static class AsyncMapping {
public final Event event;
public final ByteBuffer buffer;
public AsyncMapping(Event event, ByteBuffer buffer) {
super();
this.event = event;
this.buffer = buffer;
}
public Event getEvent() {
return event;
}
public ByteBuffer getBuffer() {
return buffer;
}
}
public abstract Event copyToImageAsync(CommandQueue queue, Image dest, long srcOffset, long[] destOrigin, long[] destRegion);
}

@ -1,171 +0,0 @@
/*
* 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;
import java.nio.*;
/**
* Interface for OpenCL implementations
*
* @author Sebastian Weiss
*/
@Deprecated
public interface CL {
//temp buffers for argument passing
public static class TempBuffer {
/**
* 16-Bytes (4 floats) of a byte buffer
*/
public final ByteBuffer b16;
/**
* Short-buffer view on b16
*/
public final ShortBuffer b16s;
/**
* int buffer view on b16
*/
public final IntBuffer b16i;
/**
* long buffer view on b16
*/
public final LongBuffer b16l;
/**
* float buffer view on b16
*/
public final FloatBuffer b16f;
/**
* double buffer view on b16
*/
public final DoubleBuffer b16d;
public TempBuffer(ByteBuffer b16) {
this.b16 = b16;
b16.rewind();
this.b16s = b16.asShortBuffer();
this.b16i = b16.asIntBuffer();
this.b16l = b16.asLongBuffer();
this.b16f = b16.asFloatBuffer();
this.b16d = b16.asDoubleBuffer();
}
}
/**
* Returns up to 4 temp buffer instances
*
* @return
*/
TempBuffer[] getTempBuffers();
//entry point
long getContext();
//OpenCL functions
long clCreateCommandQueue(long context, long device, boolean profiling);
void clReleaseCommandQueue(long queue);
long clCreateBuffer(long context, MemoryAccess access, int size, ByteBuffer hostPtr);
long clEnqueueReadBuffer(long queue, long buffer, boolean blocking, int offset, int size, ByteBuffer ptr);
long clEnqueueWriteBuffer(long queue, long buffer, boolean blocking, int offset, int size, ByteBuffer ptr);
long clEnqueueCopyBuffer(long queue, long srcBuffer, long dstBuffer, int srcOffset, int dstOffset, int size);
long clEnqueueFillBuffer(long queue, long buffer, ByteBuffer pattern, int patternSize, int offset, int size);
long clEnqueueMapBuffer(long queue, long buffer, boolean blocking, MappingAccess flags, int offset, int size);
long clCreateImage(long context, MemoryAccess access, Context.ImageFormat format, Context.ImageDescriptor desc, ByteBuffer ptr);
Context.ImageFormat[] clGetSupportedImageFormats(long context, MemoryAccess ma, Context.ImageType type);
long clEnqueueReadImage(long queue, long image, boolean blocking, ByteBuffer origin, ByteBuffer region, int rowPitch, int slicePitch, ByteBuffer ptr);
long clEnqueueWriteImage(long queue, long image, boolean blocking, ByteBuffer origin, ByteBuffer region, int inputRowPitch, int intputSlicePitch, ByteBuffer ptr);
long clEnqueueCopyImage(long queue, long srcImage, long dstImage, ByteBuffer srcOrigin, ByteBuffer dstOrigin, ByteBuffer region);
long clEnqueueFillImage(long queue, long image, ByteBuffer fillColor, ByteBuffer origin, ByteBuffer region);
long clEnqueueCopyImageToBuffer(long queue, long srcImage, long dstBuffer, ByteBuffer srcOrigin, ByteBuffer region, int dstOffset);
long clEnqueueCopyBufferToImage(long queue, long srcBuffer, long dstImage, int srcOffset, ByteBuffer dstOrigin, ByteBuffer region);
long clEnqueueMapImage(long queue, long image, boolean blocking, MappingAccess ma, ByteBuffer origin, ByteBuffer region, int rowPitch, int slicePitch);
//TODO: clGetImageInfo
void clReleaseMemObject(long mem);
long clEnqueueUnmapMemObject(long queue, long mem, ByteBuffer ptr);
int getMemSize(long mem); //uses clGetMemObjectInfo
long clCreateProgramWithSource(long context, CharSequence[] sources);
//TODO: create from binary
long clReleaseProgram(long program);
void clBuildProgram(long program, long[] devices, CharSequence optpions) throws KernelCompilationException;
String getKernelNames(long program); //uses clGetProgramInfo
long clCreateKernel(long program, String kernelName);
void clReleaseKernel(long kernel);
void clSetKernelArg(long kernel, int argIndex, int argSize, ByteBuffer argValue);
String getKernelName(long kernel); //uses clGetKernelInfo
int getKernelNumArgs(long kernel); //uses clGetKernelInfo
//TODO: clGetKernelWorkGroupInfo
long clEnqueueNDRangeKernel(long queue, long kernel, int workDim,
ByteBuffer globalWorkOffset, ByteBuffer globalWorkSize, ByteBuffer localWorkSize);
void clWaitForEvents(long[] events);
void clWaitForEvent(long event);
boolean isEventCompleted(long event); //uses clGetEventInfo
void clReleaseEvent(long event);
void clFlush(long queue);
void clFinish(long queue);
}

@ -34,6 +34,9 @@ package com.jme3.opencl;
import com.jme3.asset.AssetInfo;
import com.jme3.asset.AssetKey;
import com.jme3.asset.AssetManager;
import com.jme3.opencl.Image.ImageDescriptor;
import com.jme3.opencl.Image.ImageFormat;
import com.jme3.opencl.Image.ImageType;
import com.jme3.scene.VertexBuffer;
import com.jme3.scene.mesh.IndexBuffer;
import java.io.BufferedReader;
@ -70,68 +73,9 @@ public abstract class Context {
return createBufferFromHost(data, MemoryAccess.READ_WRITE);
}
public static enum ImageChannelOrder {
R, Rx, A,
INTENSITY,
LUMINANCE,
RG, RGx, RA,
RGB, RGBx,
RGBA,
ARGB, BGRA
}
public static enum ImageChannelType {
SNORM_INT8,
SNORM_INT16,
UNORM_INT8,
UNROM_INT16,
UNORM_SHORT_565,
UNROM_SHORT_555,
UNORM_INT_101010,
SIGNED_INT8,
SIGNED_INT16,
SIGNED_INT32,
UNSIGNED_INT8,
UNSIGNED_INT16,
UNSIGNED_INT32,
HALF_FLOAT,
FLOAT
}
public static class ImageFormat { //Struct
public ImageChannelOrder channelOrder;
public ImageChannelType channelType;
}
public static enum ImageType {
IMAGE_1D,
IMAGE_1D_BUFFER,
IMAGE_2D,
IMAGE_3D,
IMAGE_1D_ARRAY,
IMAGE_2D_ARRAY
}
public static class ImageDescriptor { //Struct
public ImageType type;
public int width;
public int height;
public int depth;
public int arraySize;
public int rowPitch;
public int slicePitch;
public int numMipLevels;
public int numSamples;
public Buffer buffer;
}
public abstract Image createImage(MemoryAccess access, ImageFormat format, ImageDescriptor descr, ByteBuffer hostPtr);
//TODO: add simplified methods for 1D, 2D, 3D textures
public abstract ImageFormat[] querySupportedFormats(MemoryAccess access, ImageType type);
//Interop
public abstract Buffer bindVertexBuffer(VertexBuffer vb);

@ -31,10 +31,206 @@
*/
package com.jme3.opencl;
import com.jme3.math.ColorRGBA;
import java.nio.ByteBuffer;
import java.util.Objects;
/**
*
* @author Sebastian Weiss
*/
public interface Image {
public static enum ImageChannelType {
SNORM_INT8,
SNORM_INT16,
UNORM_INT8,
UNORM_INT16,
UNORM_SHORT_565,
UNORM_SHORT_555,
UNORM_INT_101010,
SIGNED_INT8,
SIGNED_INT16,
SIGNED_INT32,
UNSIGNED_INT8,
UNSIGNED_INT16,
UNSIGNED_INT32,
HALF_FLOAT,
FLOAT
}
public static enum ImageChannelOrder {
R, Rx, A,
INTENSITY,
LUMINANCE,
RG, RGx, RA,
RGB, RGBx,
RGBA,
ARGB, BGRA
}
public static class ImageFormat { //Struct
public ImageChannelOrder channelOrder;
public ImageChannelType channelType;
public ImageFormat() {
}
public ImageFormat(ImageChannelOrder channelOrder, ImageChannelType channelType) {
this.channelOrder = channelOrder;
this.channelType = channelType;
}
@Override
public String toString() {
return "ImageFormat{" + "channelOrder=" + channelOrder + ", channelType=" + channelType + '}';
}
@Override
public int hashCode() {
int hash = 5;
hash = 61 * hash + Objects.hashCode(this.channelOrder);
hash = 61 * hash + Objects.hashCode(this.channelType);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final ImageFormat other = (ImageFormat) obj;
if (this.channelOrder != other.channelOrder) {
return false;
}
if (this.channelType != other.channelType) {
return false;
}
return true;
}
}
public static enum ImageType {
IMAGE_1D,
IMAGE_1D_BUFFER,
IMAGE_2D,
IMAGE_3D,
IMAGE_1D_ARRAY,
IMAGE_2D_ARRAY
}
public static class ImageDescriptor { //Struct
public ImageType type;
public long width;
public long height;
public long depth;
public long arraySize;
public long rowPitch;
public long slicePitch;
/*
public int numMipLevels; //They must always be set to zero
public int numSamples;
*/
public ImageDescriptor() {
}
public ImageDescriptor(ImageType type, long width, long height, long depth, long arraySize, long rowPitch, long slicePitch) {
this.type = type;
this.width = width;
this.height = height;
this.depth = depth;
this.arraySize = arraySize;
this.rowPitch = rowPitch;
this.slicePitch = slicePitch;
}
public ImageDescriptor(ImageType type, long width, long height, long depth, long arraySize) {
this.type = type;
this.width = width;
this.height = height;
this.depth = depth;
this.arraySize = arraySize;
this.rowPitch = 0;
this.slicePitch = 0;
}
@Override
public String toString() {
return "ImageDescriptor{" + "type=" + type + ", width=" + width + ", height=" + height + ", depth=" + depth + ", arraySize=" + arraySize + ", rowPitch=" + rowPitch + ", slicePitch=" + slicePitch + '}';
}
}
long getWidth();
long getHeight();
long getDepth();
long getRowPitch();
long getSlicePitch();
long getArraySize();
ImageFormat getImageFormat();
ImageType getImageType();
int getElementSize();
void readImage(CommandQueue queue, ByteBuffer dest, long[] origin, long[] region, long rowPitch, long slicePitch);
Event readImageAsync(CommandQueue queue, ByteBuffer dest, long[] origin, long[] region, long rowPitch, long slicePitch);
void writeImage(CommandQueue queue, ByteBuffer dest, long[] origin, long[] region, long rowPitch, long slicePitch);
Event writeImageAsync(CommandQueue queue, ByteBuffer dest, long[] origin, long[] region, long rowPitch, long slicePitch);
void copyTo(CommandQueue queue, Image dest, long[] srcOrigin, long[] destOrigin, long[] region);
Event copyToAsync(CommandQueue queue, Image dest, long[] srcOrigin, long[] destOrigin, long[] region);
ImageMapping map(CommandQueue queue, long[] origin, long[] region, MappingAccess access);
ImageMapping mapAsync(CommandQueue queue, long[] origin, long[] region, MappingAccess access);
void unmap(CommandQueue queue, ImageMapping mapping);
public static class ImageMapping {
public final ByteBuffer buffer;
public final long rowPitch;
public final long slicePitch;
public final Event event;
public ImageMapping(ByteBuffer buffer, long rowPitch, long slicePitch, Event event) {
this.buffer = buffer;
this.rowPitch = rowPitch;
this.slicePitch = slicePitch;
this.event = event;
}
public ImageMapping(ByteBuffer buffer, long rowPitch, long slicePitch) {
this.buffer = buffer;
this.rowPitch = rowPitch;
this.slicePitch = slicePitch;
this.event = null;
}
}
/**
* Fills the image with the specified color.
* Does <b>only</b> work if the image channel is {@link ImageChannelType#FLOAT}
* or {@link ImageChannelType#HALF_FLOAT}.
* @param queue
* @param origin
* @param region
* @param color
* @return
*/
Event fillAsync(CommandQueue queue, long[] origin, long[] region, ColorRGBA color);
/**
* Fills the image with the specified color given as four integer variables.
* Does <b>not</b> work if the image channel is {@link ImageChannelType#FLOAT}
* or {@link ImageChannelType#HALF_FLOAT}.
* @param queue
* @param origin
* @param region
* @param color
* @return
*/
Event fillIntegerAsync(CommandQueue queue, long[] origin, long[] region, int[] color);
Event copyToBufferAsync(CommandQueue queue, Buffer dest, long[] srcOrigin, long[] srcRegion, long destOffset);
}

@ -103,6 +103,8 @@ public abstract class Kernel {
public abstract void setArg(int index, Buffer t);
public abstract void setArg(int index, Image i);
public abstract void setArg(int index, byte b);
public abstract void setArg(int index, short s);

@ -40,6 +40,8 @@ import com.jme3.system.AppSettings;
import com.jme3.util.BufferUtils;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.Arrays;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -78,6 +80,7 @@ public class HelloOpenCL extends SimpleApplication {
str.append("\nTests:");
str.append("\n Buffers: ").append(testBuffer(clContext, clQueue));
str.append("\n Kernel: ").append(testKernel(clContext, clQueue));
str.append("\n Images: ").append(testImages(clContext, clQueue));
BitmapText txt1 = new BitmapText(fnt);
txt1.setText(str.toString());
@ -85,6 +88,31 @@ public class HelloOpenCL extends SimpleApplication {
guiNode.attachChild(txt1);
}
private static void assertEquals(byte expected, byte actual, String message) {
if (expected != actual) {
System.err.println(message+": expected="+expected+", actual="+actual);
throw new AssertionError();
}
}
private static void assertEquals(long expected, long actual, String message) {
if (expected != actual) {
System.err.println(message+": expected="+expected+", actual="+actual);
throw new AssertionError();
}
}
private static void assertEquals(double expected, double actual, String message) {
if (Math.abs(expected - actual) >= 0.00001) {
System.err.println(message+": expected="+expected+", actual="+actual);
throw new AssertionError();
}
}
private static void assertEquals(Object expected, Object actual, String message) {
if (!Objects.equals(expected, actual)) {
System.err.println(message+": expected="+expected+", actual="+actual);
throw new AssertionError();
}
}
private boolean testBuffer(Context clContext, CommandQueue clQueue) {
try {
//create two buffers
@ -110,10 +138,7 @@ public class HelloOpenCL extends SimpleApplication {
h1.rewind();
for (int i=0; i<256; ++i) {
byte b = h1.get();
if (b != (byte)i) {
System.err.println("Wrong byte read: expected="+i+", actual="+b);
return false;
}
assertEquals((byte) i, b, "Wrong byte read");
}
//read buffer with offset
@ -125,12 +150,12 @@ public class HelloOpenCL extends SimpleApplication {
h1.position(5);
for (int i=0; i<high-low; ++i) {
byte b = h1.get();
if (b != (byte)(i+low)) {
System.err.println("Wrong byte read: expected="+(i+low)+", actual="+b);
return false;
}
assertEquals((byte) (i+low), b, "Wrong byte read");
}
} catch (AssertionError ex) {
LOG.log(Level.SEVERE, "Buffer test failed with an assertion error");
return false;
} catch (Exception ex) {
LOG.log(Level.SEVERE, "Buffer test failed with:", ex);
return false;
@ -163,16 +188,46 @@ public class HelloOpenCL extends SimpleApplication {
FloatBuffer buff = buf.asFloatBuffer();
for (int i=0; i<size; ++i) {
float v = buff.get(i);
if (v != value) {
System.err.println("Buffer filled with the wrong value at index "+i+": expected="+value+", actual="+v);
assertEquals(value, v, "Buffer filled with the wrong value at index "+i);
}
buffer.unmap(clQueue, buf);
} catch (AssertionError ex) {
LOG.log(Level.SEVERE, "kernel test failed with an assertion error");
return false;
} catch (Exception ex) {
LOG.log(Level.SEVERE, "kernel test failed with:", ex);
return false;
}
return true;
}
buffer.unmap(clQueue, buf);
private boolean testImages(Context clContext, CommandQueue clQueue) {
try {
//query supported formats
for (MemoryAccess ma : MemoryAccess.values()) {
for (Image.ImageType type : Image.ImageType.values()) {
System.out.println("Formats for "+ma+" and "+type+": "+Arrays.toString(clContext.querySupportedFormats(ma, type)));
}
}
//create an image
Image.ImageFormat format = new Image.ImageFormat(Image.ImageChannelOrder.RGBA, Image.ImageChannelType.FLOAT);
Image.ImageDescriptor descr = new Image.ImageDescriptor(Image.ImageType.IMAGE_2D, 1920, 1080, 0, 0, 0, 0);
Image image = clContext.createImage(MemoryAccess.READ_WRITE, format, descr, null);
System.out.println("image created");
//check queries
assertEquals(descr.type, image.getImageType(), "Wrong image type");
assertEquals(format, image.getImageFormat(), "Wrong image format");
assertEquals(descr.width, image.getWidth(), "Wrong width");
assertEquals(descr.height, image.getHeight(), "Wrong height");
} catch (AssertionError ex) {
LOG.log(Level.SEVERE, "image test failed with an assertion error");
return false;
} catch (Exception ex) {
LOG.log(Level.SEVERE, "kernel test failed with:", ex);
LOG.log(Level.SEVERE, "image test failed with:", ex);
return false;
}
return true;

@ -33,16 +33,13 @@ package com.jme3.opencl.lwjgl;
import com.jme3.opencl.*;
import java.nio.ByteBuffer;
import org.lwjgl.opencl.CL10;
import org.lwjgl.opencl.CLCommandQueue;
import org.lwjgl.opencl.CLEvent;
import org.lwjgl.opencl.CLMem;
import org.lwjgl.opencl.*;
/**
*
* @author Sebastian Weiss
*/
public class LwjglBuffer implements Buffer {
public class LwjglBuffer extends Buffer {
private final CLMem buffer;
@ -72,16 +69,6 @@ public class LwjglBuffer implements Buffer {
Utils.checkError(ret, "clEnqueueReadBuffer");
}
@Override
public void read(CommandQueue queue, ByteBuffer dest, int size) {
read(queue, dest, size, 0);
}
@Override
public void read(CommandQueue queue, ByteBuffer dest) {
read(queue, dest, getSize());
}
@Override
public Event readAsync(CommandQueue queue, ByteBuffer dest, int size, int offset) {
//Note: LWJGL does not support the size parameter, I have to set the buffer limit
@ -94,16 +81,6 @@ public class LwjglBuffer implements Buffer {
return new LwjglEvent(q.getCLEvent(event));
}
@Override
public Event readAsync(CommandQueue queue, ByteBuffer dest, int size) {
return readAsync(queue, dest, size, 0);
}
@Override
public Event readAsync(CommandQueue queue, ByteBuffer dest) {
return readAsync(queue, dest, getSize());
}
@Override
public void write(CommandQueue queue, ByteBuffer src, int size, int offset) {
//Note: LWJGL does not support the size parameter, I have to set the buffer limit
@ -113,16 +90,6 @@ public class LwjglBuffer implements Buffer {
Utils.checkError(ret, "clEnqueueWriteBuffer");
}
@Override
public void write(CommandQueue queue, ByteBuffer src, int size) {
write(queue, src, size, 0);
}
@Override
public void write(CommandQueue queue, ByteBuffer src) {
write(queue, src, getSize());
}
@Override
public Event writeAsync(CommandQueue queue, ByteBuffer src, int size, int offset) {
//Note: LWJGL does not support the size parameter, I have to set the buffer limit
@ -135,16 +102,6 @@ public class LwjglBuffer implements Buffer {
return new LwjglEvent(q.getCLEvent(event));
}
@Override
public Event writeAsync(CommandQueue queue, ByteBuffer src, int size) {
return writeAsync(queue, src, size, 0);
}
@Override
public Event writeAsync(CommandQueue queue, ByteBuffer src) {
return writeAsync(queue, src, getSize());
}
@Override
public void copyTo(CommandQueue queue, Buffer dest, int size, int srcOffset, int destOffset) {
CLCommandQueue q = ((LwjglCommandQueue)queue).getQueue();
@ -156,16 +113,6 @@ public class LwjglBuffer implements Buffer {
Utils.checkError(ret, "clWaitForEvents");
}
@Override
public void copyTo(CommandQueue queue, Buffer dest, int size) {
copyTo(queue, dest, size, 0, 0);
}
@Override
public void copyTo(CommandQueue queue, Buffer dest) {
copyTo(queue, dest, getSize());
}
@Override
public Event copyToAsync(CommandQueue queue, Buffer dest, int size, int srcOffset, int destOffset) {
CLCommandQueue q = ((LwjglCommandQueue)queue).getQueue();
@ -176,16 +123,6 @@ public class LwjglBuffer implements Buffer {
return new LwjglEvent(q.getCLEvent(event));
}
@Override
public Event copyToAsync(CommandQueue queue, Buffer dest, int size) {
return copyToAsync(queue, dest, size, 0, 0);
}
@Override
public Event copyToAsync(CommandQueue queue, Buffer dest) {
return copyToAsync(queue, dest, getSize());
}
@Override
public ByteBuffer map(CommandQueue queue, int size, int offset, MappingAccess access) {
CLCommandQueue q = ((LwjglCommandQueue) queue).getQueue();
@ -197,24 +134,51 @@ public class LwjglBuffer implements Buffer {
}
@Override
public ByteBuffer map(CommandQueue queue, int size, MappingAccess access) {
return map(queue, size, 0, access);
public void unmap(CommandQueue queue, ByteBuffer ptr) {
CLCommandQueue q = ((LwjglCommandQueue) queue).getQueue();
Utils.pointerBuffers[0].rewind();
int ret = CL10.clEnqueueUnmapMemObject(q, buffer, ptr, null, Utils.pointerBuffers[0]);
Utils.checkError(ret, "clEnqueueUnmapMemObject");
long event = Utils.pointerBuffers[0].get(0);
ret = CL10.clWaitForEvents(q.getCLEvent(event));
Utils.checkError(ret, "clWaitForEvents");
}
@Override
public ByteBuffer map(CommandQueue queue, MappingAccess access) {
return map(queue, getSize(), access);
public com.jme3.opencl.Buffer.AsyncMapping mapAsync(CommandQueue queue, int size, int offset, MappingAccess access) {
Utils.pointerBuffers[0].rewind();
Utils.errorBuffer.rewind();
CLCommandQueue q = ((LwjglCommandQueue) queue).getQueue();
long flags = Utils.getMappingAccessFlags(access);
ByteBuffer buf = CL10.clEnqueueMapBuffer(q, buffer, CL10.CL_FALSE, flags, offset, size, null, Utils.pointerBuffers[0], Utils.errorBuffer);
Utils.checkError(Utils.errorBuffer, "clEnqueueMapBuffer");
long event = Utils.pointerBuffers[0].get(0);
return new com.jme3.opencl.Buffer.AsyncMapping(new LwjglEvent(q.getCLEvent(event)), buf);
}
@Override
public void unmap(CommandQueue queue, ByteBuffer ptr) {
public Event fillAsync(CommandQueue queue, ByteBuffer pattern, int size, int offset) {
Utils.pointerBuffers[0].rewind();
CLCommandQueue q = ((LwjglCommandQueue) queue).getQueue();
int ret = CL12.clEnqueueFillBuffer(q, buffer, pattern, offset, size, null, Utils.pointerBuffers[0]);
Utils.checkError(ret, "clEnqueueFillBuffer");
long event = Utils.pointerBuffers[0].get(0);
return new LwjglEvent(q.getCLEvent(event));
}
@Override
public Event copyToImageAsync(CommandQueue queue, Image dest, long srcOffset, long[] destOrigin, long[] destRegion) {
Utils.pointerBuffers[0].rewind();
int ret = CL10.clEnqueueUnmapMemObject(q, buffer, ptr, null, Utils.pointerBuffers[0]);
Utils.checkError(ret, "clEnqueueUnmapMemObject");
Utils.pointerBuffers[1].rewind();
Utils.pointerBuffers[2].rewind();
Utils.pointerBuffers[1].put(destOrigin).position(0);
Utils.pointerBuffers[2].put(destRegion).position(0);
CLCommandQueue q = ((LwjglCommandQueue) queue).getQueue();
int ret = CL10.clEnqueueCopyBufferToImage(q, buffer, ((LwjglImage) dest).getImage(),
srcOffset, Utils.pointerBuffers[1], Utils.pointerBuffers[2], null, Utils.pointerBuffers[0]);
Utils.checkError(ret, "clEnqueueCopyBufferToImage");
long event = Utils.pointerBuffers[0].get(0);
ret = CL10.clWaitForEvents(q.getCLEvent(event));
Utils.checkError(ret, "clWaitForEvents");
return new LwjglEvent(q.getCLEvent(event));
}
}

@ -35,16 +35,20 @@ import com.jme3.asset.AssetInfo;
import com.jme3.asset.AssetKey;
import com.jme3.asset.AssetManager;
import com.jme3.opencl.*;
import com.jme3.opencl.Image.ImageDescriptor;
import com.jme3.opencl.Image.ImageFormat;
import com.jme3.scene.VertexBuffer;
import com.jme3.scene.mesh.IndexBuffer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.lwjgl.BufferUtils;
import org.lwjgl.opencl.*;
import sun.misc.IOUtils;
@ -101,7 +105,52 @@ public class LwjglContext extends Context {
@Override
public Image createImage(MemoryAccess access, ImageFormat format, ImageDescriptor descr, ByteBuffer hostPtr) {
throw new UnsupportedOperationException("Not supported yet.");
long memFlags = Utils.getMemoryAccessFlags(access);
Utils.errorBuffer.rewind();
//fill image format
Utils.tempBuffers[0].b16i.rewind();
Utils.tempBuffers[0].b16i.put(LwjglImage.decodeImageChannelOrder(format.channelOrder))
.put(LwjglImage.decodeImageChannelType(format.channelType));
Utils.tempBuffers[0].b16.rewind();
//fill image desc
Utils.b80l.rewind();
Utils.b80l.put(LwjglImage.decodeImageType(descr.type))
.put(descr.width).put(descr.height).put(descr.depth)
.put(descr.arraySize).put(descr.rowPitch).put(descr.slicePitch)
.put(0).put(0).put(0);
Utils.b80.rewind();
//create image
CLMem mem = CL12.clCreateImage(context, memFlags, Utils.tempBuffers[0].b16, Utils.b80, hostPtr, Utils.errorBuffer);
Utils.checkError(Utils.errorBuffer, "clCreateImage");
return new LwjglImage(mem);
}
@Override
public ImageFormat[] querySupportedFormats(MemoryAccess access, Image.ImageType type) {
long memFlags = Utils.getMemoryAccessFlags(access);
int typeFlag = LwjglImage.decodeImageType(type);
Utils.tempBuffers[0].b16i.rewind();
//query count
int ret = CL10.clGetSupportedImageFormats(context, memFlags, typeFlag, null, Utils.tempBuffers[0].b16i);
Utils.checkError(ret, "clGetSupportedImageFormats");
int count = Utils.tempBuffers[0].b16i.get(0);
if (count == 0) {
return new ImageFormat[0];
}
//get formats
ByteBuffer formatsB = BufferUtils.createByteBuffer(count * 8);
ret = CL10.clGetSupportedImageFormats(context, memFlags, typeFlag, formatsB, null);
Utils.checkError(ret, "clGetSupportedImageFormats");
//convert formats
ImageFormat[] formats = new ImageFormat[count];
IntBuffer formatsBi = formatsB.asIntBuffer();
formatsBi.rewind();
for (int i=0; i<count; ++i) {
Image.ImageChannelOrder channelOrder = LwjglImage.encodeImageChannelOrder(formatsBi.get());
Image.ImageChannelType channelType = LwjglImage.encodeImageChannelType(formatsBi.get());
formats[i] = new ImageFormat(channelOrder, channelType);
}
return formats;
}
@Override

@ -0,0 +1,351 @@
/*
* 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.ColorRGBA;
import com.jme3.opencl.*;
import java.nio.ByteBuffer;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.lwjgl.opencl.CL10;
import org.lwjgl.opencl.CL11;
import org.lwjgl.opencl.CL12;
import org.lwjgl.opencl.CLMem;
import org.lwjgl.opencl.api.CLImageFormat;
/**
*
* @author Sebastian Weiss
*/
public class LwjglImage implements Image {
private static final Logger LOG = Logger.getLogger(LwjglImage.class.getName());
private final CLMem image;
public LwjglImage(CLMem image) {
this.image = image;
}
public CLMem getImage() {
return image;
}
public static int decodeImageChannelOrder(ImageChannelOrder order) {
switch (order) {
case A:
return CL10.CL_A;
case ARGB:
return CL10.CL_ARGB;
case BGRA:
return CL10.CL_BGRA;
case INTENSITY:
return CL10.CL_INTENSITY;
case LUMINANCE:
return CL10.CL_LUMINANCE;
case R:
return CL10.CL_R;
case RA:
return CL10.CL_RA;
case RG:
return CL10.CL_RG;
case RGB:
return CL10.CL_RGB;
case RGBA:
return CL10.CL_RGBA;
case RGBx:
return CL11.CL_RGBx;
case RGx:
return CL11.CL_RGx;
case Rx:
return CL11.CL_Rx;
default:
throw new IllegalArgumentException("unknown image channel order: " + order);
}
}
public static ImageChannelOrder encodeImageChannelOrder(int order) {
switch (order) {
case CL10.CL_A:
return ImageChannelOrder.A;
case CL10.CL_ARGB:
return ImageChannelOrder.ARGB;
case CL10.CL_BGRA:
return ImageChannelOrder.BGRA;
case CL10.CL_INTENSITY:
return ImageChannelOrder.INTENSITY;
case CL10.CL_LUMINANCE:
return ImageChannelOrder.LUMINANCE;
case CL10.CL_R:
return ImageChannelOrder.R;
case CL10.CL_RA:
return ImageChannelOrder.RA;
case CL10.CL_RG:
return ImageChannelOrder.RG;
case CL10.CL_RGB:
return ImageChannelOrder.RGB;
case CL10.CL_RGBA:
return ImageChannelOrder.RGBA;
case CL11.CL_RGBx:
return ImageChannelOrder.RGBx;
case CL11.CL_RGx:
return ImageChannelOrder.RGx;
case CL11.CL_Rx:
return ImageChannelOrder.Rx;
default:
//throw new OpenCLException("unknown image channel order id: " + order);
LOG.log(Level.WARNING, "Unknown image channel order id: {0}", order);
return null;
}
}
public static int decodeImageChannelType(ImageChannelType type) {
switch (type) {
case FLOAT:
return CL10.CL_FLOAT;
case HALF_FLOAT:
return CL10.CL_HALF_FLOAT;
case SIGNED_INT16:
return CL10.CL_SIGNED_INT16;
case SIGNED_INT32:
return CL10.CL_SIGNED_INT32;
case SIGNED_INT8:
return CL10.CL_SIGNED_INT8;
case SNORM_INT16:
return CL10.CL_SNORM_INT16;
case SNORM_INT8:
return CL10.CL_SNORM_INT8;
case UNORM_INT8:
return CL10.CL_UNORM_INT8;
case UNORM_INT_101010:
return CL10.CL_UNORM_INT_101010;
case UNORM_INT16:
return CL10.CL_UNORM_INT16;
case UNORM_SHORT_565:
return CL10.CL_UNORM_SHORT_565;
case UNORM_SHORT_555:
return CL10.CL_UNORM_SHORT_555;
case UNSIGNED_INT16:
return CL10.CL_UNSIGNED_INT16;
case UNSIGNED_INT32:
return CL10.CL_UNSIGNED_INT32;
case UNSIGNED_INT8:
return CL10.CL_UNSIGNED_INT8;
default:
throw new IllegalArgumentException("Unknown image channel type: " + type);
}
}
public static ImageChannelType encodeImageChannelType(int type) {
switch (type) {
case CL10.CL_FLOAT:
return ImageChannelType.FLOAT;
case CL10.CL_HALF_FLOAT:
return ImageChannelType.HALF_FLOAT;
case CL10.CL_SIGNED_INT16:
return ImageChannelType.SIGNED_INT16;
case CL10.CL_SIGNED_INT32:
return ImageChannelType.SIGNED_INT32;
case CL10.CL_SIGNED_INT8:
return ImageChannelType.SIGNED_INT8;
case CL10.CL_SNORM_INT16:
return ImageChannelType.SNORM_INT16;
case CL10.CL_SNORM_INT8:
return ImageChannelType.SNORM_INT8;
case CL10.CL_UNORM_INT8:
return ImageChannelType.UNORM_INT8;
case CL10.CL_UNORM_INT16:
return ImageChannelType.UNORM_INT16;
case CL10.CL_UNORM_INT_101010:
return ImageChannelType.UNORM_INT_101010;
case CL10.CL_UNORM_SHORT_555:
return ImageChannelType.UNORM_SHORT_555;
case CL10.CL_UNORM_SHORT_565:
return ImageChannelType.UNORM_SHORT_565;
case CL10.CL_UNSIGNED_INT16:
return ImageChannelType.UNSIGNED_INT16;
case CL10.CL_UNSIGNED_INT32:
return ImageChannelType.UNSIGNED_INT32;
case CL10.CL_UNSIGNED_INT8:
return ImageChannelType.UNSIGNED_INT8;
default:
//throw new OpenCLException("unknown image channel type id: " + type);
LOG.log(Level.WARNING, "Unknown image channel type id: {0}", type);
return null;
}
}
public static int decodeImageType(ImageType type) {
switch (type) {
case IMAGE_1D:
return CL12.CL_MEM_OBJECT_IMAGE1D;
case IMAGE_1D_ARRAY:
return CL12.CL_MEM_OBJECT_IMAGE1D_ARRAY;
case IMAGE_1D_BUFFER:
return CL12.CL_MEM_OBJECT_IMAGE1D_BUFFER;
case IMAGE_2D:
return CL10.CL_MEM_OBJECT_IMAGE2D;
case IMAGE_2D_ARRAY:
return CL12.CL_MEM_OBJECT_IMAGE2D_ARRAY;
case IMAGE_3D:
return CL10.CL_MEM_OBJECT_IMAGE3D;
default:
throw new IllegalArgumentException("Unknown image type: " + type);
}
}
public static ImageType encodeImageType(int type) {
switch (type) {
case CL12.CL_MEM_OBJECT_IMAGE1D:
return ImageType.IMAGE_1D;
case CL12.CL_MEM_OBJECT_IMAGE1D_ARRAY:
return ImageType.IMAGE_1D_ARRAY;
case CL12.CL_MEM_OBJECT_IMAGE1D_BUFFER:
return ImageType.IMAGE_1D_BUFFER;
case CL10.CL_MEM_OBJECT_IMAGE2D:
return ImageType.IMAGE_2D;
case CL12.CL_MEM_OBJECT_IMAGE2D_ARRAY:
return ImageType.IMAGE_2D_ARRAY;
case CL10.CL_MEM_OBJECT_IMAGE3D:
return ImageType.IMAGE_3D;
default:
throw new OpenCLException("Unknown image type id: " + type);
}
}
@Override
public long getWidth() {
return image.getInfoSize(CL10.CL_IMAGE_WIDTH);
}
@Override
public long getHeight() {
return image.getInfoSize(CL10.CL_IMAGE_HEIGHT);
}
@Override
public long getDepth() {
return image.getInfoSize(CL10.CL_IMAGE_DEPTH);
}
@Override
public long getRowPitch() {
return image.getInfoSize(CL10.CL_IMAGE_ROW_PITCH);
}
@Override
public long getSlicePitch() {
return image.getInfoSize(CL10.CL_IMAGE_SLICE_PITCH);
}
@Override
public long getArraySize() {
return image.getInfoSize(CL12.CL_IMAGE_ARRAY_SIZE);
}
@Override
public ImageFormat getImageFormat() {
CLImageFormat format = image.getImageFormat();
return new ImageFormat(encodeImageChannelOrder(format.getChannelOrder()), encodeImageChannelType(format.getChannelType()));
}
@Override
public ImageType getImageType() {
int type = image.getInfoInt(CL10.CL_MEM_TYPE);
return encodeImageType(type);
}
@Override
public int getElementSize() {
return (int) image.getInfoSize(CL10.CL_IMAGE_ELEMENT_SIZE);
}
@Override
public void readImage(CommandQueue queue, ByteBuffer dest, long[] origin, long[] region, long rowPitch, long slicePitch) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Event readImageAsync(CommandQueue queue, ByteBuffer dest, long[] origin, long[] region, long rowPitch, long slicePitch) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void writeImage(CommandQueue queue, ByteBuffer dest, long[] origin, long[] region, long rowPitch, long slicePitch) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Event writeImageAsync(CommandQueue queue, ByteBuffer dest, long[] origin, long[] region, long rowPitch, long slicePitch) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void copyTo(CommandQueue queue, Image dest, long[] srcOrigin, long[] destOrigin, long[] region) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Event copyToAsync(CommandQueue queue, Image dest, long[] srcOrigin, long[] destOrigin, long[] region) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ImageMapping map(CommandQueue queue, long[] origin, long[] region, MappingAccess access) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public ImageMapping mapAsync(CommandQueue queue, long[] origin, long[] region, MappingAccess access) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public void unmap(CommandQueue queue, ImageMapping mapping) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Event fillAsync(CommandQueue queue, long[] origin, long[] region, ColorRGBA color) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Event fillIntegerAsync(CommandQueue queue, long[] origin, long[] region, int[] color) {
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
public Event copyToBufferAsync(CommandQueue queue, Buffer dest, long[] srcOrigin, long[] srcRegion, long destOffset) {
throw new UnsupportedOperationException("Not supported yet.");
}
}

@ -86,6 +86,12 @@ public class LwjglKernel extends Kernel {
Utils.checkError(ret, "clSetKernelArg");
}
@Override
public void setArg(int index, Image i) {
int ret = CL10.clSetKernelArg(kernel, index, ((LwjglImage) i).getImage());
Utils.checkError(ret, "clSetKernelArg");
}
@Override
public void setArg(int index, byte b) {
ByteBuffer buf = Utils.tempBuffers[0].b16;

@ -76,14 +76,18 @@ public class Utils {
b16d = b16.asDoubleBuffer();
}
}
public static TempBuffer[] tempBuffers = new TempBuffer[8];
public static PointerBuffer[] pointerBuffers = new PointerBuffer[8];
public static final ByteBuffer b80; //needed for ImageDescriptor
public static final LongBuffer b80l;
public static final TempBuffer[] tempBuffers = new TempBuffer[8];
public static final PointerBuffer[] pointerBuffers = new PointerBuffer[8];
static {
for (int i=0; i<8; ++i) {
tempBuffers[i] = new TempBuffer();
pointerBuffers[i] = PointerBuffer.allocateDirect(4);
}
errorBuffer = BufferUtils.createIntBuffer(1);
b80 = BufferUtils.createByteBuffer(80);
b80l = b80.asLongBuffer();
}
public static IntBuffer errorBuffer;

Loading…
Cancel
Save