started with the OpenCL api for jme3

define_list_fix
shamanDevel 9 years ago
parent 091b8664ad
commit ab15f5c57c
  1. 130
      jme3-core/src/main/java/com/jme3/opencl/Buffer.java
  2. 129
      jme3-core/src/main/java/com/jme3/opencl/CommandQueue.java
  3. 164
      jme3-core/src/main/java/com/jme3/opencl/Context.java
  4. 52
      jme3-core/src/main/java/com/jme3/opencl/Event.java
  5. 183
      jme3-core/src/main/java/com/jme3/opencl/Kernel.java
  6. 71
      jme3-core/src/main/java/com/jme3/opencl/LocalMem.java
  7. 71
      jme3-core/src/main/java/com/jme3/opencl/LocalMemPerElement.java
  8. 43
      jme3-core/src/main/java/com/jme3/opencl/MappingAccess.java
  9. 43
      jme3-core/src/main/java/com/jme3/opencl/MemoryAccess.java
  10. 56
      jme3-core/src/main/java/com/jme3/opencl/Program.java
  11. 111
      jme3-core/src/main/java/com/jme3/opencl/WorkSize.java
  12. 38
      jme3-core/src/main/java/com/jme3/opencl/package-info.java

@ -0,0 +1,130 @@
/*
* 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.ByteBuffer;
/**
*
* @author Sebastian Weiss
*/
public class Buffer {
private final long buffer;
public Buffer(long buffer) {
this.buffer = buffer;
}
public int getSize() {
throw new UnsupportedOperationException("not supported yet");
}
public MemoryAccess getMemoryAccessFlags() {
throw new UnsupportedOperationException("not supported yet");
}
public void read(CommandQueue queue, Buffer src, ByteBuffer dest, int size, int offset) {
queue.read(src, dest, size, offset);
}
public void read(CommandQueue queue, Buffer src, ByteBuffer dest, int size) {
queue.read(src, dest, size);
}
public void read(CommandQueue queue, Buffer src, ByteBuffer dest) {
queue.read(src, dest);
}
public Event readAsync(CommandQueue queue, Buffer src, ByteBuffer dest, int size, int offset) {
return queue.readAsync(src, dest, size, offset);
}
public Event readAsync(CommandQueue queue, Buffer src, ByteBuffer dest, int size) {
return queue.readAsync(src, dest, size);
}
public Event readAsync(CommandQueue queue, Buffer src, ByteBuffer dest) {
return queue.readAsync(src, dest);
}
public void write(CommandQueue queue, ByteBuffer src, Buffer dest, int size, int offset) {
queue.write(src, dest, size, offset);
}
public void write(CommandQueue queue, ByteBuffer src, Buffer dest, int size) {
queue.write(src, dest, size);
}
public void write(CommandQueue queue, ByteBuffer src, Buffer dest) {
queue.write(src, dest);
}
public Event writeAsync(CommandQueue queue, ByteBuffer src, Buffer dest, int size, int offset) {
return queue.writeAsync(src, dest, size, offset);
}
public Event writeAsync(CommandQueue queue, ByteBuffer src, Buffer dest, int size) {
return queue.writeAsync(src, dest, size);
}
public Event writeAsync(CommandQueue queue, ByteBuffer src, Buffer dest) {
return queue.writeAsync(src, dest);
}
public void copyTo(CommandQueue queue, Buffer src, Buffer dest, int size, int srcOffset, int destOffset) {
queue.copyTo(src, dest, size, srcOffset, destOffset);
}
public void copyTo(CommandQueue queue, Buffer src, Buffer dest, int size) {
queue.copyTo(src, dest, size);
}
public void copyTo(CommandQueue queue, Buffer src, Buffer dest) {
queue.copyTo(src, dest);
}
public Event copyToAsync(CommandQueue queue, Buffer src, Buffer dest, int size, int srcOffset, int destOffset) {
return queue.copyToAsync(src, dest, size, srcOffset, destOffset);
}
public Event copyToAsync(CommandQueue queue, Buffer src, Buffer dest, int size) {
return queue.copyToAsync(src, dest, size);
}
public Event copyToAsync(CommandQueue queue, Buffer src, Buffer dest) {
return queue.copyToAsync(src, dest);
}
public ByteBuffer map(CommandQueue queue, Buffer src, int size, int offset, MappingAccess access) {
return queue.map(src, size, offset, access);
}
public ByteBuffer map(CommandQueue queue, Buffer src, int size, MappingAccess access) {
return queue.map(src, size, access);
}
public ByteBuffer map(CommandQueue queue, Buffer src, MappingAccess access) {
return queue.map(src, access);
}
public void unmap(CommandQueue queue, Buffer src, ByteBuffer ptr) {
queue.unmap(src, ptr);
}
//TODO: async mapping
}

@ -0,0 +1,129 @@
/*
* 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.ByteBuffer;
/**
*
* @author Sebastian Weiss
*/
public final class CommandQueue {
private final long queue;
public CommandQueue(long queue) {
this.queue = queue;
}
public void read(Buffer src, ByteBuffer dest, int size, int offset) {
throw new UnsupportedOperationException("not supported yet");
}
public void read(Buffer src, ByteBuffer dest, int size) {
read(src, dest, size, 0);
}
public void read(Buffer src, ByteBuffer dest) {
read(src, dest, src.getSize(), 0);
}
public Event readAsync(Buffer src, ByteBuffer dest, int size, int offset) {
throw new UnsupportedOperationException("not supported yet");
}
public Event readAsync(Buffer src, ByteBuffer dest, int size) {
return readAsync(src, dest, size, 0);
}
public Event readAsync(Buffer src, ByteBuffer dest) {
return readAsync(src, dest, src.getSize());
}
public void write(ByteBuffer src, Buffer dest, int size, int offset) {
throw new UnsupportedOperationException("not supported yet");
}
public void write(ByteBuffer src, Buffer dest, int size) {
write(src, dest, size, 0);
}
public void write(ByteBuffer src, Buffer dest) {
write(src, dest, dest.getSize());
}
public Event writeAsync(ByteBuffer src, Buffer dest, int size, int offset) {
throw new UnsupportedOperationException("not supported yet");
}
public Event writeAsync(ByteBuffer src, Buffer dest, int size) {
return writeAsync(src, dest, size, 0);
}
public Event writeAsync(ByteBuffer src, Buffer dest) {
return writeAsync(src, dest, dest.getSize());
}
public void copyTo(Buffer src, Buffer dest, int size, int srcOffset, int destOffset) {
throw new UnsupportedOperationException("not supported yet");
}
public void copyTo(Buffer src, Buffer dest, int size) {
copyTo(src, dest, size, 0, 0);
}
public void copyTo(Buffer src, Buffer dest) {
copyTo(src, dest, src.getSize());
}
public Event copyToAsync(Buffer src, Buffer dest, int size, int srcOffset, int destOffset) {
throw new UnsupportedOperationException("not supported yet");
}
public Event copyToAsync(Buffer src, Buffer dest, int size) {
return copyToAsync(src, dest, size, 0, 0);
}
public Event copyToAsync(Buffer src, Buffer dest) {
return copyToAsync(src, dest, src.getSize());
}
public ByteBuffer map(Buffer src, int size, int offset, MappingAccess access) {
throw new UnsupportedOperationException("not supported yet");
}
public ByteBuffer map(Buffer src, int size, MappingAccess access) {
return map(src, size, 0, access);
}
public ByteBuffer map(Buffer src, MappingAccess access) {
return map(src, src.getSize(), access);
}
public void unmap(Buffer src, ByteBuffer ptr) {
throw new UnsupportedOperationException("not supported yet");
}
//TODO: async mapping
public void flush() {
throw new UnsupportedOperationException("not supported yet");
}
public void finish() {
throw new UnsupportedOperationException("not supported yet");
}
}

@ -0,0 +1,164 @@
/*
* 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 com.jme3.scene.VertexBuffer;
import com.jme3.scene.mesh.IndexBuffer;
import com.jme3.scene.mesh.IndexByteBuffer;
import com.jme3.scene.mesh.IndexIntBuffer;
import com.jme3.scene.mesh.IndexShortBuffer;
import com.jme3.texture.Image;
import java.nio.ByteBuffer;
import java.util.List;
/**
* The central OpenCL context. Every actions start from here.
* @author Sebastian Weiss
*/
public final class Context {
private final long context;
public Context(long context) {
this.context = context;
}
public CommandQueue createQueue() {
throw new UnsupportedOperationException("not supported yet");
}
//TODO: constructor with specific device and properties
public Buffer createBuffer(int size, MemoryAccess access) {
throw new UnsupportedOperationException("not supported yet");
}
public Buffer createBuffer(int size) {
return createBuffer(size, MemoryAccess.READ_WRITE);
}
public Buffer useHostBuffer(ByteBuffer data, int size, MemoryAccess access) {
throw new UnsupportedOperationException("not supported yet");
}
public Buffer useHostBuffer(ByteBuffer data, int size) {
return useHostBuffer(data, size, 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 Buffer createImage(MemoryAccess access, ImageFormat format, ImageDescriptor descr, ByteBuffer hostPtr) {
throw new UnsupportedOperationException("not supported yet");
}
//TODO: add simplified methods for 1D, 2D, 3D textures
//Interop
public Buffer bindVertexBuffer(VertexBuffer vb) {
throw new UnsupportedOperationException("not supported yet");
}
public Buffer bindIndexBuffer(IndexBuffer ib) {
if (!(ib instanceof IndexByteBuffer)
&& !(ib instanceof IndexShortBuffer)
&& !(ib instanceof IndexIntBuffer)) {
throw new IllegalArgumentException("Index buffer must be an IndexByteBuffer, IndexShortBuffer or IndexIntBuffer");
}
throw new UnsupportedOperationException("not supported yet");
}
public Buffer bindImage(Image image) {
throw new UnsupportedOperationException("not supported yet");
}
public Program createProgramFromSourceCode(String sourceCode) {
throw new UnsupportedOperationException("not supported yet");
}
public Program createProgramFromSourceFilesWithInclude(
String include, String... resources) {
//TODO: load resources
throw new UnsupportedOperationException("not implemented yet");
}
public Program createProgramFormSourcesWithInclude(String include, List<String> resources) {
return createProgramFromSourceFilesWithInclude(include, resources.toArray(new String[resources.size()]));
}
public Program createProgramFromSources(String... resources) {
return createProgramFromSourceFilesWithInclude(null, resources);
}
public Program createProgramFromSources(List<String> resources) {
return createProgramFormSourcesWithInclude(null, resources);
}
}

@ -0,0 +1,52 @@
/*
* 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;
/**
*
* @author Sebastian Weiss
*/
public final class Event {
private final long event;
public Event(long event) {
this.event = event;
}
public void waitForFinished() {
throw new UnsupportedOperationException("not supported yet");
}
public boolean isCompleted() {
throw new UnsupportedOperationException("not supported yet");
}
}

@ -0,0 +1,183 @@
/*
* 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 com.jme3.math.Quaternion;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector4f;
/**
*
* @author Sebastian Weiss
*/
public final class Kernel {
private final WorkSize globalWorkSize;
private final WorkSize workGroupSize;
private final long kernel;
public Kernel(long kernel) {
this.kernel = kernel;
this.globalWorkSize = new WorkSize(0);
this.workGroupSize = new WorkSize(0);
}
public String getName() {
throw new UnsupportedOperationException("not supported yet");
}
public int getArgCount() {
throw new UnsupportedOperationException("not supported yet");
}
public WorkSize getGlobalWorkSize() {
return globalWorkSize;
}
public void setGlobalWorkSize(WorkSize ws) {
globalWorkSize.set(ws);
}
public void setGlobalWorkSize(int size) {
globalWorkSize.set(1, size);
}
public void setGlobalWorkSize(int width, int height) {
globalWorkSize.set(2, width, height);
}
public void setGlobalWorkSize(int width, int height, int depth) {
globalWorkSize.set(3, width, height, depth);
}
public WorkSize getWorkGroupSize() {
return workGroupSize;
}
public void setWorkGroupSize(WorkSize ws) {
workGroupSize.set(ws);
}
public void setWorkGroupSize(int size) {
workGroupSize.set(1, size);
}
public void setWorkGroupSize(int width, int height) {
workGroupSize.set(2, width, height);
}
public void setWorkGroupSize(int width, int height, int depth) {
workGroupSize.set(3, width, height, depth);
}
public void setWorkGroupSizeToNull() {
workGroupSize.set(1, 0);
}
public void setArg(int index, LocalMemPerElement t) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, LocalMem t) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, Buffer t) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, byte b) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, short s) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, int i) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, long l) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, float f) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, double d) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, Vector2f v) {
throw new UnsupportedOperationException("not supported yet");
}
//Vector3f not supported because cl_float3 is the same as a float4
public void setArg(int index, Vector4f v) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, Quaternion q) {
throw new UnsupportedOperationException("not supported yet");
}
public void setArg(int index, Object arg) {
if (arg instanceof Byte) {
setArg(index, (byte) arg);
} else if (arg instanceof Short) {
setArg(index, (short) arg);
} else if (arg instanceof Integer) {
setArg(index, (int) arg);
} else if (arg instanceof Long) {
setArg(index, (long) arg);
} else if (arg instanceof Float) {
setArg(index, (float) arg);
} else if (arg instanceof Double) {
setArg(index, (double) arg);
} else if (arg instanceof Vector2f) {
setArg(index, (Vector2f) arg);
} else if (arg instanceof Vector4f) {
setArg(index, (Vector4f) arg);
} else if (arg instanceof Quaternion) {
setArg(index, (Quaternion) arg);
} else if (arg instanceof LocalMemPerElement) {
setArg(index, (LocalMemPerElement) arg);
} else if (arg instanceof LocalMem) {
setArg(index, (LocalMem) arg);
} else if (arg instanceof Buffer) {
setArg(index, (Buffer) arg);
} else {
throw new IllegalArgumentException("unknown kernel argument type: "+arg);
}
}
private void setArgs(Object... args) {
for (int i=0; i<args.length; ++i) {
setArg(i, args[i]);
}
}
public Event Run(CommandQueue queue) {
throw new UnsupportedOperationException("not supported yet");
}
public Event Run1(CommandQueue queue, WorkSize globalWorkSize, Object... args) {
setGlobalWorkSize(globalWorkSize);
setWorkGroupSizeToNull();
setArgs(args);
return Run(queue);
}
public Event Run2(CommandQueue queue, WorkSize globalWorkSize,
WorkSize workGroupSize, Object... args) {
setGlobalWorkSize(globalWorkSize);
setWorkGroupSize(workGroupSize);
setArgs(args);
return Run(queue);
}
}

@ -0,0 +1,71 @@
/*
* 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;
/**
* A placeholder for kernel launches representing local kernel memory
* @author Sebastian Weiss
*/
public final class LocalMem {
private int size;
public LocalMem(int size) {
this.size = size;
}
public int getSize() {
return size;
}
@Override
public int hashCode() {
int hash = 3;
hash = 79 * hash + this.size;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final LocalMem other = (LocalMem) obj;
if (this.size != other.size) {
return false;
}
return true;
}
}

@ -0,0 +1,71 @@
/*
* 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;
/**
* A placeholder for kernel launches representing local kernel memory per thread
* @author Sebastian Weiss
*/
public final class LocalMemPerElement {
private int size;
public LocalMemPerElement(int size) {
this.size = size;
}
public int getSize() {
return size;
}
@Override
public int hashCode() {
int hash = 3;
hash = 79 * hash + this.size;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final LocalMemPerElement other = (LocalMemPerElement) obj;
if (this.size != other.size) {
return false;
}
return true;
}
}

@ -0,0 +1,43 @@
/*
* 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;
/**
* Specifies the access flags when mapping a {@link Buffer} object.
* @author Sebastian Weiss
*/
public enum MappingAccess {
MAP_READ_ONLY,
MAP_WRITE_ONLY,
MAP_READ_WRITE,
MAP_WRITE_INVALIDATE
}

@ -0,0 +1,43 @@
/*
* 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;
/**
* Specifies how a buffer object can be accessed
* @author Sebastian Weiss
* @see Buffer
*/
public enum MemoryAccess {
READ_WRITE,
WRITE_ONLY,
READ_ONLY
}

@ -0,0 +1,56 @@
/*
* 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;
/**
*
* @author Sebastian Weiss
*/
public final class Program {
private final long program;
public Program(long program) {
this.program = program;
}
public void build(String args) {
throw new UnsupportedOperationException("not supported yet");
}
public void build() {
build(null);
}
public Kernel createKernel(String name) {
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;
import java.util.Arrays;
/**
* The work size (global and local) for executing a kernel
* @author Sebastian Weiss
*/
public final class WorkSize {
private int dimension;
private int[] sizes;
public WorkSize(int dimension, int... sizes)
{
set(dimension, sizes);
}
public WorkSize() {
this(1, 1, 1, 1);
}
public WorkSize(int size) {
this(1, size, 1, 1);
}
public WorkSize(int width, int height) {
this(2, width, height, 1);
}
public WorkSize(int width, int height, int depth) {
this(3, width, height, depth);
}
public int getDimension() {
return dimension;
}
public int[] getSizes() {
return sizes;
}
public void set(int dimension, int... sizes) {
if (sizes==null || sizes.length!=3) {
throw new IllegalArgumentException("sizes must be an array of length 3");
}
if (dimension<=0 || dimension>3) {
throw new IllegalArgumentException("dimension must be between 1 and 3");
}
this.dimension = dimension;
this.sizes = sizes;
}
public void set(WorkSize ws) {
this.dimension = ws.dimension;
this.sizes = ws.sizes;
}
@Override
public int hashCode() {
int hash = 5;
hash = 47 * hash + this.dimension;
hash = 47 * hash + Arrays.hashCode(this.sizes);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final WorkSize other = (WorkSize) obj;
if (this.dimension != other.dimension) {
return false;
}
if (!Arrays.equals(this.sizes, other.sizes)) {
return false;
}
return true;
}
}

@ -0,0 +1,38 @@
/*
* 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.
*/
/**
* This package contains an API for using OpenCL together with jME3.
*/
package com.jme3.opencl;
//TODO: add profiling to Kernel, CommandQueue
Loading…
Cancel
Save