improve format and rm trailing whitespace (10 files in com.jme3.opencl)

master
Stephen Gold 5 years ago
parent a5e0213b01
commit 7212f9b2b2
  1. 17
      jme3-core/src/main/java/com/jme3/opencl/Buffer.java
  2. 6
      jme3-core/src/main/java/com/jme3/opencl/CommandQueue.java
  3. 34
      jme3-core/src/main/java/com/jme3/opencl/Context.java
  4. 54
      jme3-core/src/main/java/com/jme3/opencl/Device.java
  5. 4
      jme3-core/src/main/java/com/jme3/opencl/Event.java
  6. 41
      jme3-core/src/main/java/com/jme3/opencl/Image.java
  7. 42
      jme3-core/src/main/java/com/jme3/opencl/Kernel.java
  8. 6
      jme3-core/src/main/java/com/jme3/opencl/KernelCompilationException.java
  9. 5
      jme3-core/src/main/java/com/jme3/opencl/OpenCLException.java
  10. 12
      jme3-core/src/main/java/com/jme3/opencl/Program.java

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009-2016 jMonkeyEngine * Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -75,6 +75,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* Performs a blocking read of the buffer. * Performs a blocking read of the buffer.
* The target buffer must have at least {@code size} bytes remaining. * The target buffer must have at least {@code size} bytes remaining.
* This method may set the limit to the last byte read. * This method may set the limit to the last byte read.
*
* @param queue the command queue * @param queue the command queue
* @param dest the target buffer * @param dest the target buffer
* @param size the size in bytes being read * @param size the size in bytes being read
@ -102,6 +103,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* Performs an async/non-blocking read of the buffer. * Performs an async/non-blocking read of the buffer.
* The target buffer must have at least {@code size} bytes remaining. * The target buffer must have at least {@code size} bytes remaining.
* This method may set the limit to the last byte read. * This method may set the limit to the last byte read.
*
* @param queue the command queue * @param queue the command queue
* @param dest the target buffer * @param dest the target buffer
* @param size the size in bytes being read * @param size the size in bytes being read
@ -130,6 +132,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* Performs a blocking write to the buffer. * Performs a blocking write to the buffer.
* The target buffer must have at least {@code size} bytes remaining. * The target buffer must have at least {@code size} bytes remaining.
* This method may set the limit to the last byte that will be written. * This method may set the limit to the last byte that will be written.
*
* @param queue the command queue * @param queue the command queue
* @param src the source buffer, its data is written to this buffer * @param src the source buffer, its data is written to this buffer
* @param size the size in bytes to write * @param size the size in bytes to write
@ -157,6 +160,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* Performs an async/non-blocking write to the buffer. * Performs an async/non-blocking write to the buffer.
* The target buffer must have at least {@code size} bytes remaining. * The target buffer must have at least {@code size} bytes remaining.
* This method may set the limit to the last byte that will be written. * This method may set the limit to the last byte that will be written.
*
* @param queue the command queue * @param queue the command queue
* @param src the source buffer, its data is written to this buffer * @param src the source buffer, its data is written to this buffer
* @param size the size in bytes to write * @param size the size in bytes to write
@ -183,6 +187,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
/** /**
* Performs a blocking copy operation from this buffer to the specified buffer. * Performs a blocking copy operation from this buffer to the specified buffer.
*
* @param queue the command queue * @param queue the command queue
* @param dest the target buffer * @param dest the target buffer
* @param size the size in bytes to copy * @param size the size in bytes to copy
@ -209,6 +214,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
/** /**
* Performs an async/non-blocking copy operation from this buffer to the specified buffer. * Performs an async/non-blocking copy operation from this buffer to the specified buffer.
*
* @param queue the command queue * @param queue the command queue
* @param dest the target buffer * @param dest the target buffer
* @param size the size in bytes to copy * @param size the size in bytes to copy
@ -240,6 +246,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* provides the memory.<br> * provides the memory.<br>
* <b>Important:</b> The mapped memory MUST be released by calling * <b>Important:</b> The mapped memory MUST be released by calling
* {@link #unmap(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer) }. * {@link #unmap(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer) }.
*
* @param queue the command queue * @param queue the command queue
* @param size the size in bytes to map * @param size the size in bytes to map
* @param offset the offset into this buffer * @param offset the offset into this buffer
@ -272,6 +279,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* Unmaps a previously mapped memory. * Unmaps a previously mapped memory.
* This releases the native resources and for WRITE_ONLY or READ_WRITE access, * This releases the native resources and for WRITE_ONLY or READ_WRITE access,
* the memory content is sent back to the GPU. * the memory content is sent back to the GPU.
*
* @param queue the command queue * @param queue the command queue
* @param ptr the buffer that was previously mapped * @param ptr the buffer that was previously mapped
*/ */
@ -283,6 +291,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* provides the memory.<br> * provides the memory.<br>
* <b>Important:</b> The mapped memory MUST be released by calling * <b>Important:</b> The mapped memory MUST be released by calling
* {@link #unmap(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer) }. * {@link #unmap(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer) }.
*
* @param queue the command queue * @param queue the command queue
* @param size the size in bytes to map * @param size the size in bytes to map
* @param offset the offset into this buffer * @param offset the offset into this buffer
@ -291,6 +300,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* and the event indicating when the buffer contents are available * and the event indicating when the buffer contents are available
*/ */
public abstract AsyncMapping mapAsync(CommandQueue queue, long size, long offset, MappingAccess access); public abstract AsyncMapping mapAsync(CommandQueue queue, long size, long offset, MappingAccess access);
/** /**
* Alternative version of {@link #mapAsync(com.jme3.opencl.CommandQueue, long, long, com.jme3.opencl.MappingAccess) }, * Alternative version of {@link #mapAsync(com.jme3.opencl.CommandQueue, long, long, com.jme3.opencl.MappingAccess) },
* sets {@code offset} to zero. * sets {@code offset} to zero.
@ -300,6 +310,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
public AsyncMapping mapAsync(CommandQueue queue, long size, MappingAccess access) { public AsyncMapping mapAsync(CommandQueue queue, long size, MappingAccess access) {
return mapAsync(queue, size, 0, access); return mapAsync(queue, size, 0, access);
} }
/** /**
* Alternative version of {@link #mapAsync(com.jme3.opencl.CommandQueue, long, com.jme3.opencl.MappingAccess) }, * Alternative version of {@link #mapAsync(com.jme3.opencl.CommandQueue, long, com.jme3.opencl.MappingAccess) },
* sets {@code size} to {@link #getSize() }. * sets {@code size} to {@link #getSize() }.
@ -313,6 +324,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
/** /**
* Enqueues a fill operation. This method can be used to initialize or clear * Enqueues a fill operation. This method can be used to initialize or clear
* a buffer with a certain value. * a buffer with a certain value.
*
* @param queue the command queue * @param queue the command queue
* @param pattern the buffer containing the filling pattern. * @param pattern the buffer containing the filling pattern.
* The remaining bytes specify the pattern length * The remaining bytes specify the pattern length
@ -379,6 +391,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* done, the buffer must be released by calling * done, the buffer must be released by calling
* {@link #releaseBufferForSharingAsync(com.jme3.opencl.CommandQueue) } * {@link #releaseBufferForSharingAsync(com.jme3.opencl.CommandQueue) }
* so that OpenGL can use the VertexBuffer again. * so that OpenGL can use the VertexBuffer again.
*
* @param queue the command queue * @param queue the command queue
* @return the event object * @return the event object
*/ */
@ -411,6 +424,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
* Call this method after the buffer object was acquired by * Call this method after the buffer object was acquired by
* {@link #acquireBufferForSharingAsync(com.jme3.opencl.CommandQueue) } * {@link #acquireBufferForSharingAsync(com.jme3.opencl.CommandQueue) }
* to hand the control back to OpenGL. * to hand the control back to OpenGL.
*
* @param queue the command queue * @param queue the command queue
* @return the event object * @return the event object
*/ */
@ -434,5 +448,4 @@ public abstract class Buffer extends AbstractOpenCLObject {
public String toString() { public String toString() {
return "Buffer (" + getSize() + "B)"; return "Buffer (" + getSize() + "B)";
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009-2016 jMonkeyEngine * Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -40,10 +40,10 @@ package com.jme3.opencl;
* Each command queue is associtated with exactly one device: that device * Each command queue is associtated with exactly one device: that device
* is specified on creation ({@link Context#createQueue(com.jme3.opencl.Device) }) * is specified on creation ({@link Context#createQueue(com.jme3.opencl.Device) })
* and all commands are sent to this device. * and all commands are sent to this device.
*
* @author shaman * @author shaman
*/ */
public abstract class CommandQueue extends AbstractOpenCLObject { public abstract class CommandQueue extends AbstractOpenCLObject {
protected Device device; protected Device device;
protected CommandQueue(ObjectReleaser releaser, Device device) { protected CommandQueue(ObjectReleaser releaser, Device device) {
@ -61,6 +61,7 @@ public abstract class CommandQueue extends AbstractOpenCLObject {
* Returns the device associated with this command queue. * Returns the device associated with this command queue.
* It can be used to query properties of the device that is used to execute * It can be used to query properties of the device that is used to execute
* the commands issued to this command queue. * the commands issued to this command queue.
*
* @return the associated device * @return the associated device
*/ */
public Device getDevice() { public Device getDevice() {
@ -83,5 +84,4 @@ public abstract class CommandQueue extends AbstractOpenCLObject {
* processed and completed. Finish is also a synchronization point. * processed and completed. Finish is also a synchronization point.
*/ */
public abstract void finish(); public abstract void finish();
} }

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009-2019 jMonkeyEngine * Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -63,6 +63,7 @@ import java.util.logging.Logger;
* <li>Created buffers and images shared with OpenGL vertex buffers, textures and renderbuffers</li> * <li>Created buffers and images shared with OpenGL vertex buffers, textures and renderbuffers</li>
* <li>Create program objects from source code and source files</li> * <li>Create program objects from source code and source files</li>
* </ul> * </ul>
*
* @author shaman * @author shaman
*/ */
public abstract class Context extends AbstractOpenCLObject { public abstract class Context extends AbstractOpenCLObject {
@ -87,6 +88,7 @@ public abstract class Context extends AbstractOpenCLObject {
* memory size and so on, are queried over the Device instances. * memory size and so on, are queried over the Device instances.
* <br> * <br>
* The available devices were specified by a {@link PlatformChooser}. * The available devices were specified by a {@link PlatformChooser}.
*
* @return a list of devices * @return a list of devices
*/ */
public abstract List<? extends Device> getDevices(); public abstract List<? extends Device> getDevices();
@ -94,14 +96,17 @@ public abstract class Context extends AbstractOpenCLObject {
/** /**
* Alternative version of {@link #createQueue(com.jme3.opencl.Device) }, * Alternative version of {@link #createQueue(com.jme3.opencl.Device) },
* just uses the first device returned by {@link #getDevices() }. * just uses the first device returned by {@link #getDevices() }.
*
* @return the command queue * @return the command queue
*/ */
public CommandQueue createQueue() { public CommandQueue createQueue() {
return createQueue(getDevices().get(0)); return createQueue(getDevices().get(0));
} }
/** /**
* Creates a command queue sending commands to the specified device. * Creates a command queue sending commands to the specified device.
* The device must be an entry of {@link #getDevices() }. * The device must be an entry of {@link #getDevices() }.
*
* @param device the target device * @param device the target device
* @return the command queue * @return the command queue
*/ */
@ -109,14 +114,17 @@ public abstract class Context extends AbstractOpenCLObject {
/** /**
* Allocates a new buffer of the specific size and access type on the device. * Allocates a new buffer of the specific size and access type on the device.
*
* @param size the size of the buffer in bytes * @param size the size of the buffer in bytes
* @param access the allowed access of this buffer from kernel code * @param access the allowed access of this buffer from kernel code
* @return the new buffer * @return the new buffer
*/ */
public abstract Buffer createBuffer(long size, MemoryAccess access); public abstract Buffer createBuffer(long size, MemoryAccess access);
/** /**
* Alternative version of {@link #createBuffer(long, com.jme3.opencl.MemoryAccess) }, * Alternative version of {@link #createBuffer(long, com.jme3.opencl.MemoryAccess) },
* creates a buffer with read and write access. * creates a buffer with read and write access.
*
* @param size the size of the buffer in bytes * @param size the size of the buffer in bytes
* @return the new buffer * @return the new buffer
*/ */
@ -129,14 +137,17 @@ public abstract class Context extends AbstractOpenCLObject {
* specified by a ByteBuffer can then be used directly by kernel code, * specified by a ByteBuffer can then be used directly by kernel code,
* although the access might be slower than with native buffers * although the access might be slower than with native buffers
* created by {@link #createBuffer(long, com.jme3.opencl.MemoryAccess) }. * created by {@link #createBuffer(long, com.jme3.opencl.MemoryAccess) }.
*
* @param data the host buffer to use * @param data the host buffer to use
* @param access the allowed access of this buffer from kernel code * @param access the allowed access of this buffer from kernel code
* @return the new buffer * @return the new buffer
*/ */
public abstract Buffer createBufferFromHost(ByteBuffer data, MemoryAccess access); public abstract Buffer createBufferFromHost(ByteBuffer data, MemoryAccess access);
/** /**
* Alternative version of {@link #createBufferFromHost(java.nio.ByteBuffer, com.jme3.opencl.MemoryAccess) }, * Alternative version of {@link #createBufferFromHost(java.nio.ByteBuffer, com.jme3.opencl.MemoryAccess) },
* creates a buffer with read and write access. * creates a buffer with read and write access.
*
* @param data the host buffer to use * @param data the host buffer to use
* @return the new buffer * @return the new buffer
*/ */
@ -152,6 +163,7 @@ public abstract class Context extends AbstractOpenCLObject {
* with row and slice pitches. This buffer is then used to store the image. * with row and slice pitches. This buffer is then used to store the image.
* If no ByteBuffer is specified, a new buffer is allocated (this is the * If no ByteBuffer is specified, a new buffer is allocated (this is the
* normal behaviour). * normal behaviour).
*
* @param access the allowed access of this image from kernel code * @param access the allowed access of this image from kernel code
* @param format the image format * @param format the image format
* @param descr the image descriptor * @param descr the image descriptor
@ -168,6 +180,7 @@ public abstract class Context extends AbstractOpenCLObject {
* where {@code ImageChannelType} or {@code ImageChannelOrder} are {@code null} * where {@code ImageChannelType} or {@code ImageChannelOrder} are {@code null}
* (or both). This is the case when the device supports new formats that * (or both). This is the case when the device supports new formats that
* are not included in this wrapper yet. * are not included in this wrapper yet.
*
* @param access the memory access type * @param access the memory access type
* @param type the image type (1D, 2D, 3D, ...) * @param type the image type (1D, 2D, 3D, ...)
* @return an array of all supported image formats * @return an array of all supported image formats
@ -188,6 +201,7 @@ public abstract class Context extends AbstractOpenCLObject {
* by {@link Buffer#acquireBufferForSharingAsync(com.jme3.opencl.CommandQueue) } * by {@link Buffer#acquireBufferForSharingAsync(com.jme3.opencl.CommandQueue) }
* and after modifying it, released by {@link Buffer#releaseBufferForSharingAsync(com.jme3.opencl.CommandQueue) }. * and after modifying it, released by {@link Buffer#releaseBufferForSharingAsync(com.jme3.opencl.CommandQueue) }.
* This is needed so that OpenGL and OpenCL operations do not interfere with each other. * This is needed so that OpenGL and OpenCL operations do not interfere with each other.
*
* @param vb the vertex buffer to share * @param vb the vertex buffer to share
* @param access the memory access for the kernel * @param access the memory access for the kernel
* @return the new buffer * @return the new buffer
@ -216,6 +230,7 @@ public abstract class Context extends AbstractOpenCLObject {
* @return the OpenCL image * @return the OpenCL image
*/ */
public abstract Image bindImage(com.jme3.texture.Image image, Texture.Type textureType, int miplevel, MemoryAccess access); public abstract Image bindImage(com.jme3.texture.Image image, Texture.Type textureType, int miplevel, MemoryAccess access);
/** /**
* Creates a shared image object from a jME3 texture. * Creates a shared image object from a jME3 texture.
* The returned image shares the same memory with the jME3 texture, changes * The returned image shares the same memory with the jME3 texture, changes
@ -242,9 +257,11 @@ public abstract class Context extends AbstractOpenCLObject {
public Image bindImage(Texture texture, int miplevel, MemoryAccess access) { public Image bindImage(Texture texture, int miplevel, MemoryAccess access) {
return bindImage(texture.getImage(), texture.getType(), miplevel, access); return bindImage(texture.getImage(), texture.getType(), miplevel, access);
} }
/** /**
* Alternative version to {@link #bindImage(com.jme3.texture.Texture, int, com.jme3.opencl.MemoryAccess) }, * Alternative version to {@link #bindImage(com.jme3.texture.Texture, int, com.jme3.opencl.MemoryAccess) },
* uses {@code miplevel=0}. * uses {@code miplevel=0}.
*
* @param texture the jME3 texture * @param texture the jME3 texture
* @param access the allowed memory access for kernels * @param access the allowed memory access for kernels
* @return the OpenCL image * @return the OpenCL image
@ -252,6 +269,7 @@ public abstract class Context extends AbstractOpenCLObject {
public Image bindImage(Texture texture, MemoryAccess access) { public Image bindImage(Texture texture, MemoryAccess access) {
return bindImage(texture, 0, access); return bindImage(texture, 0, access);
} }
/** /**
* Creates a shared image object from a jME3 render buffer. * Creates a shared image object from a jME3 render buffer.
* The returned image shares the same memory with the jME3 render buffer, changes * The returned image shares the same memory with the jME3 render buffer, changes
@ -279,6 +297,7 @@ public abstract class Context extends AbstractOpenCLObject {
return bindImage(buffer.getTexture(), access); return bindImage(buffer.getTexture(), access);
} }
} }
protected abstract Image bindPureRenderBuffer(FrameBuffer.RenderBuffer buffer, MemoryAccess access); protected abstract Image bindPureRenderBuffer(FrameBuffer.RenderBuffer buffer, MemoryAccess access);
/** /**
@ -295,6 +314,7 @@ public abstract class Context extends AbstractOpenCLObject {
* and delegates the combined source code to * and delegates the combined source code to
* {@link #createProgramFromSourceCode(java.lang.String) }. * {@link #createProgramFromSourceCode(java.lang.String) }.
* Important: only absolute paths are allowed. * Important: only absolute paths are allowed.
*
* @param sourceCode the original source code * @param sourceCode the original source code
* @param assetManager the asset manager to load the files * @param assetManager the asset manager to load the files
* @return the created program object * @return the created program object
@ -310,6 +330,7 @@ public abstract class Context extends AbstractOpenCLObject {
} }
return createProgramFromSourceCode(builder.toString()); return createProgramFromSourceCode(builder.toString());
} }
private void buildSourcesRec(BufferedReader reader, StringBuilder builder, AssetManager assetManager) throws IOException { private void buildSourcesRec(BufferedReader reader, StringBuilder builder, AssetManager assetManager) throws IOException {
String ln; String ln;
while ((ln = reader.readLine()) != null) { while ((ln = reader.readLine()) != null) {
@ -319,11 +340,11 @@ public abstract class Context extends AbstractOpenCLObject {
ln = ln.substring(1); ln = ln.substring(1);
} }
if (ln.endsWith("\"")) { if (ln.endsWith("\"")) {
ln = ln.substring(0, ln.length()-1); ln = ln.substring(0, ln.length() - 1);
} }
AssetInfo info = assetManager.locateAsset(new AssetKey<String>(ln)); AssetInfo info = assetManager.locateAsset(new AssetKey<String>(ln));
if (info == null) { if (info == null) {
throw new AssetNotFoundException("Unable to load source file \""+ln+"\""); throw new AssetNotFoundException("Unable to load source file \"" + ln + "\"");
} }
try (BufferedReader r = new BufferedReader(new InputStreamReader(info.openStream()))) { try (BufferedReader r = new BufferedReader(new InputStreamReader(info.openStream()))) {
builder.append("//-- begin import ").append(ln).append(" --\n"); builder.append("//-- begin import ").append(ln).append(" --\n");
@ -390,7 +411,7 @@ public abstract class Context extends AbstractOpenCLObject {
for (String res : resources) { for (String res : resources) {
AssetInfo info = assetManager.locateAsset(new AssetKey<String>(res)); AssetInfo info = assetManager.locateAsset(new AssetKey<String>(res));
if (info == null) { if (info == null) {
throw new AssetNotFoundException("Unable to load source file \""+res+"\""); throw new AssetNotFoundException("Unable to load source file \"" + res + "\"");
} }
try (BufferedReader reader = new BufferedReader(new InputStreamReader(info.openStream()))) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(info.openStream()))) {
while (true) { while (true) {
@ -401,7 +422,7 @@ public abstract class Context extends AbstractOpenCLObject {
str.append(line).append('\n'); str.append(line).append('\n');
} }
} catch (IOException ex) { } catch (IOException ex) {
LOG.log(Level.WARNING, "unable to load source file '"+res+"'", ex); LOG.log(Level.WARNING, "unable to load source file '" + res + "'", ex);
} }
} }
return createProgramFromSourceCodeWithDependencies(str.toString(), assetManager); return createProgramFromSourceCodeWithDependencies(str.toString(), assetManager);
@ -410,6 +431,7 @@ public abstract class Context extends AbstractOpenCLObject {
/** /**
* Alternative version of {@link #createProgramFromSourceFilesWithInclude(com.jme3.asset.AssetManager, java.lang.String, java.lang.String...) } * Alternative version of {@link #createProgramFromSourceFilesWithInclude(com.jme3.asset.AssetManager, java.lang.String, java.lang.String...) }
* with an empty include string * with an empty include string
*
* @throws AssetNotFoundException if a file could not be loaded * @throws AssetNotFoundException if a file could not be loaded
*/ */
public Program createProgramFromSourceFiles(AssetManager assetManager, String... resources) { public Program createProgramFromSourceFiles(AssetManager assetManager, String... resources) {
@ -419,6 +441,7 @@ public abstract class Context extends AbstractOpenCLObject {
/** /**
* Alternative version of {@link #createProgramFromSourceFilesWithInclude(com.jme3.asset.AssetManager, java.lang.String, java.util.List) } * Alternative version of {@link #createProgramFromSourceFilesWithInclude(com.jme3.asset.AssetManager, java.lang.String, java.util.List) }
* with an empty include string * with an empty include string
*
* @throws AssetNotFoundException if a file could not be loaded * @throws AssetNotFoundException if a file could not be loaded
*/ */
public Program createProgramFromSourceFiles(AssetManager assetManager, List<String> resources) { public Program createProgramFromSourceFiles(AssetManager assetManager, List<String> resources) {
@ -447,5 +470,4 @@ public abstract class Context extends AbstractOpenCLObject {
public String toString() { public String toString() {
return "Context (" + getDevices() + ')'; return "Context (" + getDevices() + ')';
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009-2019 jMonkeyEngine * Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -45,12 +45,10 @@ import java.util.Collection;
* @author shaman * @author shaman
*/ */
public interface Device { public interface Device {
/** /**
* @return the platform associated with this device * @return the platform associated with this device
*/ */
Platform getPlatform(); Platform getPlatform();
/** /**
* The device type * The device type
*/ */
@ -61,16 +59,20 @@ public interface Device {
ACCELEARTOR, ACCELEARTOR,
ALL ALL
} }
/** /**
* @return queries the device type * @return queries the device type
*/ */
DeviceType getDeviceType(); DeviceType getDeviceType();
/** /**
* @return the vendor id * @return the vendor id
*/ */
int getVendorId(); int getVendorId();
/** /**
* checks if this device is available at all, must always be tested * checks if this device is available at all, must always be tested
*
* @return checks if this device is available at all, must always be tested * @return checks if this device is available at all, must always be tested
*/ */
boolean isAvailable(); boolean isAvailable();
@ -79,42 +81,53 @@ public interface Device {
* @return if this device has a compiler for kernel code * @return if this device has a compiler for kernel code
*/ */
boolean hasCompiler(); boolean hasCompiler();
/** /**
* @return supports double precision floats (64 bit) * @return supports double precision floats (64 bit)
*/ */
boolean hasDouble(); boolean hasDouble();
/** /**
* @return supports half precision floats (16 bit) * @return supports half precision floats (16 bit)
*/ */
boolean hasHalfFloat(); boolean hasHalfFloat();
/** /**
* @return supports error correction for every access to global or constant memory * @return supports error correction for every access to global or constant memory
*/ */
boolean hasErrorCorrectingMemory(); boolean hasErrorCorrectingMemory();
/** /**
* @return supports unified virtual memory (OpenCL 2.0) * @return supports unified virtual memory (OpenCL 2.0)
*/ */
boolean hasUnifiedMemory(); boolean hasUnifiedMemory();
/** /**
* @return supports images * @return supports images
*/ */
boolean hasImageSupport(); boolean hasImageSupport();
/** /**
* @return supports writes to 3d images (this is an extension) * @return supports writes to 3d images (this is an extension)
*/ */
boolean hasWritableImage3D(); boolean hasWritableImage3D();
/** /**
* @return supports sharing with OpenGL * @return supports sharing with OpenGL
*/ */
boolean hasOpenGLInterop(); boolean hasOpenGLInterop();
/** /**
* Explictly tests for the availability of the specified extension * Explictly tests for the availability of the specified extension
*
* @param extension the name of the extension * @param extension the name of the extension
* @return {@code true} iff this extension is supported * @return {@code true} iff this extension is supported
*/ */
boolean hasExtension(String extension); boolean hasExtension(String extension);
/** /**
* Lists all available extensions * Lists all available extensions
*
* @return all available extensions * @return all available extensions
*/ */
Collection<? extends String> getExtensions(); Collection<? extends String> getExtensions();
@ -129,18 +142,22 @@ public interface Device {
* @see #getMaximumWorkItemSizes() * @see #getMaximumWorkItemSizes()
*/ */
int getComputeUnits(); int getComputeUnits();
/** /**
* @return maximum clock frequency of the device in MHz * @return maximum clock frequency of the device in MHz
*/ */
int getClockFrequency(); int getClockFrequency();
/** /**
* Returns the default compute device address space * Returns the default compute device address space
* size specified as an unsigned integer value * size specified as an unsigned integer value
* in bits. Currently supported values are 32 * in bits. Currently supported values are 32
* or 64 bits. * or 64 bits.
*
* @return the size of an address * @return the size of an address
*/ */
int getAddressBits(); int getAddressBits();
/** /**
* @return {@code true} if this device is little endian * @return {@code true} if this device is little endian
*/ */
@ -150,21 +167,26 @@ public interface Device {
* The maximum dimension that specify the local and global work item ids. * The maximum dimension that specify the local and global work item ids.
* You can always assume to be this at least 3. * You can always assume to be this at least 3.
* Therefore, the ids are always three integers x,y,z. * Therefore, the ids are always three integers x,y,z.
*
* @return the maximum dimension of work item ids * @return the maximum dimension of work item ids
*/ */
long getMaximumWorkItemDimensions(); long getMaximumWorkItemDimensions();
/** /**
* Maximum number of work-items that can be specified in each dimension of the * Maximum number of work-items that can be specified in each dimension of the
* work-group to {@link Kernel#Run2(com.jme3.opencl.CommandQueue, com.jme3.opencl.Kernel.WorkSize, com.jme3.opencl.Kernel.WorkSize, java.lang.Object...)}. * work-group to {@link Kernel#Run2(com.jme3.opencl.CommandQueue, com.jme3.opencl.Kernel.WorkSize, com.jme3.opencl.Kernel.WorkSize, java.lang.Object...)}.
* The array has a length of at least 3. * The array has a length of at least 3.
*
* @return the maximum size of the work group in each dimension * @return the maximum size of the work group in each dimension
*/ */
long[] getMaximumWorkItemSizes(); long[] getMaximumWorkItemSizes();
/** /**
* Maximum number of work-items in a * Maximum number of work-items in a
* work-group executing a kernel on a single * work-group executing a kernel on a single
* compute unit, using the data parallel * compute unit, using the data parallel
* execution model. * execution model.
*
* @return maximum number of work-items in a work-group * @return maximum number of work-items in a work-group
*/ */
long getMaxiumWorkItemsPerGroup(); long getMaxiumWorkItemsPerGroup();
@ -173,21 +195,27 @@ public interface Device {
* @return the maximum number of samples that can be used in a kernel * @return the maximum number of samples that can be used in a kernel
*/ */
int getMaximumSamplers(); int getMaximumSamplers();
/** /**
* @return the maximum number of images that can be used for reading in a kernel * @return the maximum number of images that can be used for reading in a kernel
*/ */
int getMaximumReadImages(); int getMaximumReadImages();
/** /**
* @return the maximum number of images that can be used for writing in a kernel * @return the maximum number of images that can be used for writing in a kernel
*/ */
int getMaximumWriteImages(); int getMaximumWriteImages();
/** /**
* Queries the maximal size of a 2D image * Queries the maximal size of a 2D image
*
* @return an array of length 2 with the maximal size of a 2D image * @return an array of length 2 with the maximal size of a 2D image
*/ */
long[] getMaximumImage2DSize(); long[] getMaximumImage2DSize();
/** /**
* Queries the maximal size of a 3D image * Queries the maximal size of a 3D image
*
* @return an array of length 3 with the maximal size of a 3D image * @return an array of length 3 with the maximal size of a 3D image
*/ */
long[] getMaximumImage3DSize(); long[] getMaximumImage3DSize();
@ -196,14 +224,17 @@ public interface Device {
* @return the maximal size of a memory object (buffer and image) in bytes * @return the maximal size of a memory object (buffer and image) in bytes
*/ */
long getMaximumAllocationSize(); long getMaximumAllocationSize();
/** /**
* @return the total available global memory in bytes * @return the total available global memory in bytes
*/ */
long getGlobalMemorySize(); long getGlobalMemorySize();
/** /**
* @return the total available local memory in bytes * @return the total available local memory in bytes
*/ */
long getLocalMemorySize(); long getLocalMemorySize();
/** /**
* Returns the maximal size of a constant buffer. * Returns the maximal size of a constant buffer.
* <br> * <br>
@ -214,6 +245,7 @@ public interface Device {
* @return the maximal size of a constant buffer * @return the maximal size of a constant buffer
*/ */
long getMaximumConstantBufferSize(); long getMaximumConstantBufferSize();
/** /**
* @return the maximal number of constant buffer arguments in a kernel call * @return the maximal number of constant buffer arguments in a kernel call
*/ */
@ -231,6 +263,7 @@ public interface Device {
* @return the profile string * @return the profile string
*/ */
String getProfile(); String getProfile();
/** /**
* OpenCL version string. Returns the OpenCL version supported by the * OpenCL version string. Returns the OpenCL version supported by the
* device. This version string has the following format: OpenCL space * device. This version string has the following format: OpenCL space
@ -241,14 +274,18 @@ public interface Device {
* @return the version string * @return the version string
*/ */
String getVersion(); String getVersion();
/** /**
* Extracts the major version from the version string * Extracts the major version from the version string
*
* @return the major version * @return the major version
* @see #getVersion() * @see #getVersion()
*/ */
int getVersionMajor(); int getVersionMajor();
/** /**
* Extracts the minor version from the version string * Extracts the minor version from the version string
*
* @return the minor version * @return the minor version
* @see #getVersion() } * @see #getVersion() }
*/ */
@ -269,31 +306,40 @@ public interface Device {
* @return the compiler version * @return the compiler version
*/ */
String getCompilerVersion(); String getCompilerVersion();
/** /**
* Extracts the major version from the compiler version * Extracts the major version from the compiler version
*
* @return the major compiler version * @return the major compiler version
* @see #getCompilerVersion() * @see #getCompilerVersion()
*/ */
int getCompilerVersionMajor(); int getCompilerVersionMajor();
/** /**
* Extracts the minor version from the compiler version * Extracts the minor version from the compiler version
*
* @return the minor compiler version * @return the minor compiler version
* @see #getCompilerVersion() * @see #getCompilerVersion()
*/ */
int getCompilerVersionMinor(); int getCompilerVersionMinor();
/** /**
* @return the OpenCL software driver version string in the form * @return the OpenCL software driver version string in the form
* major_number.minor_number * major_number.minor_number
*/ */
String getDriverVersion(); String getDriverVersion();
/** /**
* Extracts the major version from the driver version * Extracts the major version from the driver version
*
* @return the major driver version * @return the major driver version
* @see #getDriverVersion() * @see #getDriverVersion()
*/ */
int getDriverVersionMajor(); int getDriverVersionMajor();
/** /**
* Extracts the minor version from the driver version * Extracts the minor version from the driver version
*
* @return the minor driver version * @return the minor driver version
* @see #getDriverVersion() * @see #getDriverVersion()
*/ */
@ -303,9 +349,9 @@ public interface Device {
* @return the device name * @return the device name
*/ */
String getName(); String getName();
/** /**
* @return the vendor * @return the vendor
*/ */
String getVendor(); String getVendor();
} }

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009-2016 jMonkeyEngine * Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -36,6 +36,7 @@ package com.jme3.opencl;
* Events are returned from kernel launches and all asynchronous operations. * Events are returned from kernel launches and all asynchronous operations.
* They allow to test if the action has completed and to block until the operation * They allow to test if the action has completed and to block until the operation
* is done. * is done.
*
* @author shaman * @author shaman
*/ */
public abstract class Event extends AbstractOpenCLObject { public abstract class Event extends AbstractOpenCLObject {
@ -59,6 +60,7 @@ public abstract class Event extends AbstractOpenCLObject {
/** /**
* Tests if the action is completed. * Tests if the action is completed.
* If the action is completed, the event is released. * If the action is completed, the event is released.
*
* @return {@code true} if the action is completed * @return {@code true} if the action is completed
*/ */
public abstract boolean isCompleted(); public abstract boolean isCompleted();

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009-2019 jMonkeyEngine * Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -75,7 +75,6 @@ import java.util.Objects;
* @author shaman * @author shaman
*/ */
public abstract class Image extends AbstractOpenCLObject { public abstract class Image extends AbstractOpenCLObject {
/** /**
* {@code ImageChannelType} describes the size of the channel data type. * {@code ImageChannelType} describes the size of the channel data type.
*/ */
@ -99,7 +98,7 @@ public abstract class Image extends AbstractOpenCLObject {
/** /**
* {@code ImageChannelOrder} specifies the number of channels and the channel layout i.e. the * {@code ImageChannelOrder} specifies the number of channels and the channel layout i.e. the
memory layout in which channels are stored in the image. * memory layout in which channels are stored in the image.
*/ */
public static enum ImageChannelOrder { public static enum ImageChannelOrder {
R, Rx, A, R, Rx, A,
@ -157,7 +156,6 @@ memory layout in which channels are stored in the image.
} }
return true; return true;
} }
} }
/** /**
@ -200,6 +198,7 @@ memory layout in which channels are stored in the image.
/** /**
* Used to specify an image with the provided ByteBuffer as soruce * Used to specify an image with the provided ByteBuffer as soruce
*
* @param type the image type * @param type the image type
* @param width the width * @param width the width
* @param height the height, unused for image types {@code ImageType.IMAGE_1D*} * @param height the height, unused for image types {@code ImageType.IMAGE_1D*}
@ -219,9 +218,11 @@ memory layout in which channels are stored in the image.
this.slicePitch = slicePitch; this.slicePitch = slicePitch;
this.hostPtr = hostPtr; this.hostPtr = hostPtr;
} }
/** /**
* Specifies an image without a host buffer, a new chunk of memory * Specifies an image without a host buffer, a new chunk of memory
* will be allocated. * will be allocated.
*
* @param type the image type * @param type the image type
* @param width the width * @param width the width
* @param height the height, unused for image types {@code ImageType.IMAGE_1D*} * @param height the height, unused for image types {@code ImageType.IMAGE_1D*}
@ -243,7 +244,6 @@ memory layout in which channels are stored in the image.
public String toString() { public String toString() {
return "ImageDescriptor{" + "type=" + type + ", width=" + width + ", height=" + height + ", depth=" + depth + ", arraySize=" + arraySize + ", rowPitch=" + rowPitch + ", slicePitch=" + slicePitch + '}'; return "ImageDescriptor{" + "type=" + type + ", width=" + width + ", height=" + height + ", depth=" + depth + ", arraySize=" + arraySize + ", rowPitch=" + rowPitch + ", slicePitch=" + slicePitch + '}';
} }
} }
protected Image(ObjectReleaser releaser) { protected Image(ObjectReleaser releaser) {
@ -260,36 +260,44 @@ memory layout in which channels are stored in the image.
* @return the width of the image * @return the width of the image
*/ */
public abstract long getWidth(); public abstract long getWidth();
/** /**
* @return the height of the image * @return the height of the image
*/ */
public abstract long getHeight(); public abstract long getHeight();
/** /**
* @return the depth of the image * @return the depth of the image
*/ */
public abstract long getDepth(); public abstract long getDepth();
/** /**
* @return the row pitch when the image was created from a host buffer * @return the row pitch when the image was created from a host buffer
*/ */
public abstract long getRowPitch(); public abstract long getRowPitch();
/** /**
* @return the slice pitch when the image was created from a host buffer * @return the slice pitch when the image was created from a host buffer
*/ */
public abstract long getSlicePitch(); public abstract long getSlicePitch();
/** /**
* @return the number of elements in the image array * @return the number of elements in the image array
* @see ImageType#IMAGE_1D_ARRAY * @see ImageType#IMAGE_1D_ARRAY
* @see ImageType#IMAGE_2D_ARRAY * @see ImageType#IMAGE_2D_ARRAY
*/ */
public abstract long getArraySize(); public abstract long getArraySize();
/** /**
* @return the image format * @return the image format
*/ */
public abstract ImageFormat getImageFormat(); public abstract ImageFormat getImageFormat();
/** /**
* @return the image type * @return the image type
*/ */
public abstract ImageType getImageType(); public abstract ImageType getImageType();
/** /**
* @return the number of bytes per pixel * @return the number of bytes per pixel
*/ */
@ -297,6 +305,7 @@ memory layout in which channels are stored in the image.
/** /**
* Performs a blocking read of the image into the specified byte buffer. * Performs a blocking read of the image into the specified byte buffer.
*
* @param queue the command queue * @param queue the command queue
* @param dest the target byte buffer * @param dest the target byte buffer
* @param origin the image origin location, see class description for the format * @param origin the image origin location, see class description for the format
@ -307,8 +316,10 @@ memory layout in which channels are stored in the image.
* If set to 0 for 3D images, the slice pitch is calculated as {@code rowPitch * height} * If set to 0 for 3D images, the slice pitch is calculated as {@code rowPitch * height}
*/ */
public abstract void readImage(CommandQueue queue, ByteBuffer dest, long[] origin, long[] region, long rowPitch, long slicePitch); public abstract void readImage(CommandQueue queue, ByteBuffer dest, long[] origin, long[] region, long rowPitch, long slicePitch);
/** /**
* Performs an async/non-blocking read of the image into the specified byte buffer. * Performs an async/non-blocking read of the image into the specified byte buffer.
*
* @param queue the command queue * @param queue the command queue
* @param dest the target byte buffer * @param dest the target byte buffer
* @param origin the image origin location, see class description for the format * @param origin the image origin location, see class description for the format
@ -323,6 +334,7 @@ memory layout in which channels are stored in the image.
/** /**
* Performs a blocking write from the specified byte buffer into the image. * Performs a blocking write from the specified byte buffer into the image.
*
* @param queue the command queue * @param queue the command queue
* @param src the source buffer * @param src the source buffer
* @param origin the image origin location, see class description for the format * @param origin the image origin location, see class description for the format
@ -333,8 +345,10 @@ memory layout in which channels are stored in the image.
* If set to 0 for 3D images, the slice pitch is calculated as {@code rowPitch * height} * If set to 0 for 3D images, the slice pitch is calculated as {@code rowPitch * height}
*/ */
public abstract void writeImage(CommandQueue queue, ByteBuffer src, long[] origin, long[] region, long rowPitch, long slicePitch); public abstract void writeImage(CommandQueue queue, ByteBuffer src, long[] origin, long[] region, long rowPitch, long slicePitch);
/** /**
* Performs an async/non-blocking write from the specified byte buffer into the image. * Performs an async/non-blocking write from the specified byte buffer into the image.
*
* @param queue the command queue * @param queue the command queue
* @param src the source buffer * @param src the source buffer
* @param origin the image origin location, see class description for the format * @param origin the image origin location, see class description for the format
@ -350,6 +364,7 @@ memory layout in which channels are stored in the image.
/** /**
* Performs a blocking copy operation from one image to another. * Performs a blocking copy operation from one image to another.
* <b>Important:</b> Both images must have the same format! * <b>Important:</b> Both images must have the same format!
*
* @param queue the command queue * @param queue the command queue
* @param dest the target image * @param dest the target image
* @param srcOrigin the source image origin, see class description for the format * @param srcOrigin the source image origin, see class description for the format
@ -357,9 +372,11 @@ memory layout in which channels are stored in the image.
* @param region the copied region, see class description for the format * @param region the copied region, see class description for the format
*/ */
public abstract void copyTo(CommandQueue queue, Image dest, long[] srcOrigin, long[] destOrigin, long[] region); public abstract void copyTo(CommandQueue queue, Image dest, long[] srcOrigin, long[] destOrigin, long[] region);
/** /**
* Performs an async/non-blocking copy operation from one image to another. * Performs an async/non-blocking copy operation from one image to another.
* <b>Important:</b> Both images must have the same format! * <b>Important:</b> Both images must have the same format!
*
* @param queue the command queue * @param queue the command queue
* @param dest the target image * @param dest the target image
* @param srcOrigin the source image origin, see class description for the format * @param srcOrigin the source image origin, see class description for the format
@ -374,6 +391,7 @@ memory layout in which channels are stored in the image.
* The returned structure contains the mapped byte buffer and row and slice pitch. * The returned structure contains the mapped byte buffer and row and slice pitch.
* The event object is set to {@code null}, it is needed for the asnyc * The event object is set to {@code null}, it is needed for the asnyc
* version {@link #mapAsync(com.jme3.opencl.CommandQueue, long[], long[], com.jme3.opencl.MappingAccess) }. * version {@link #mapAsync(com.jme3.opencl.CommandQueue, long[], long[], com.jme3.opencl.MappingAccess) }.
*
* @param queue the command queue * @param queue the command queue
* @param origin the image origin, see class description for the format * @param origin the image origin, see class description for the format
* @param region the mapped region, see class description for the format * @param region the mapped region, see class description for the format
@ -382,6 +400,7 @@ memory layout in which channels are stored in the image.
* @see #unmap(com.jme3.opencl.CommandQueue, com.jme3.opencl.Image.ImageMapping) * @see #unmap(com.jme3.opencl.CommandQueue, com.jme3.opencl.Image.ImageMapping)
*/ */
public abstract ImageMapping map(CommandQueue queue, long[] origin, long[] region, MappingAccess access); public abstract ImageMapping map(CommandQueue queue, long[] origin, long[] region, MappingAccess access);
/** /**
* Non-blocking version of {@link #map(com.jme3.opencl.CommandQueue, long[], long[], com.jme3.opencl.MappingAccess) }. * Non-blocking version of {@link #map(com.jme3.opencl.CommandQueue, long[], long[], com.jme3.opencl.MappingAccess) }.
* The returned structure contains the mapped byte buffer and row and slice pitch. * The returned structure contains the mapped byte buffer and row and slice pitch.
@ -394,8 +413,10 @@ memory layout in which channels are stored in the image.
* @see #unmap(com.jme3.opencl.CommandQueue, com.jme3.opencl.Image.ImageMapping) * @see #unmap(com.jme3.opencl.CommandQueue, com.jme3.opencl.Image.ImageMapping)
*/ */
public abstract ImageMapping mapAsync(CommandQueue queue, long[] origin, long[] region, MappingAccess access); public abstract ImageMapping mapAsync(CommandQueue queue, long[] origin, long[] region, MappingAccess access);
/** /**
* Unmaps the mapped memory * Unmaps the mapped memory
*
* @param queue the command queue * @param queue the command queue
* @param mapping the mapped memory * @param mapping the mapped memory
*/ */
@ -421,6 +442,7 @@ memory layout in which channels are stored in the image.
public final long slicePitch; public final long slicePitch;
/** /**
* The event object used to detect when the memory is available. * The event object used to detect when the memory is available.
*
* @see #mapAsync(com.jme3.opencl.CommandQueue, long[], long[], com.jme3.opencl.MappingAccess) * @see #mapAsync(com.jme3.opencl.CommandQueue, long[], long[], com.jme3.opencl.MappingAccess)
*/ */
public final Event event; public final Event event;
@ -431,19 +453,20 @@ memory layout in which channels are stored in the image.
this.slicePitch = slicePitch; this.slicePitch = slicePitch;
this.event = event; this.event = event;
} }
public ImageMapping(ByteBuffer buffer, long rowPitch, long slicePitch) { public ImageMapping(ByteBuffer buffer, long rowPitch, long slicePitch) {
this.buffer = buffer; this.buffer = buffer;
this.rowPitch = rowPitch; this.rowPitch = rowPitch;
this.slicePitch = slicePitch; this.slicePitch = slicePitch;
this.event = null; this.event = null;
} }
} }
/** /**
* Fills the image with the specified color. * Fills the image with the specified color.
* Does <b>only</b> work if the image channel is {@link ImageChannelType#FLOAT} * Does <b>only</b> work if the image channel is {@link ImageChannelType#FLOAT}
* or {@link ImageChannelType#HALF_FLOAT}. * or {@link ImageChannelType#HALF_FLOAT}.
*
* @param queue the command queue * @param queue the command queue
* @param origin the image origin, see class description for the format * @param origin the image origin, see class description for the format
* @param region the size of the region, see class description for the format * @param region the size of the region, see class description for the format
@ -455,6 +478,7 @@ memory layout in which channels are stored in the image.
* Fills the image with the specified color given as four integer variables. * 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} * Does <b>not</b> work if the image channel is {@link ImageChannelType#FLOAT}
* or {@link ImageChannelType#HALF_FLOAT}. * or {@link ImageChannelType#HALF_FLOAT}.
*
* @param queue the command queue * @param queue the command queue
* @param origin the image origin, see class description for the format * @param origin the image origin, see class description for the format
* @param region the size of the region, see class description for the format * @param region the size of the region, see class description for the format
@ -467,6 +491,7 @@ memory layout in which channels are stored in the image.
* Copies this image into the specified buffer, no format conversion is done. * Copies this image into the specified buffer, no format conversion is done.
* This is the dual function to * This is the dual function to
* {@link Buffer#copyToImageAsync(com.jme3.opencl.CommandQueue, com.jme3.opencl.Image, long, long[], long[]) }. * {@link Buffer#copyToImageAsync(com.jme3.opencl.CommandQueue, com.jme3.opencl.Image, long, long[], long[]) }.
*
* @param queue the command queue * @param queue the command queue
* @param dest the target buffer * @param dest the target buffer
* @param srcOrigin the image origin, see class description for the format * @param srcOrigin the image origin, see class description for the format
@ -485,6 +510,7 @@ memory layout in which channels are stored in the image.
* done, the image must be released by calling * done, the image must be released by calling
* {@link #releaseImageForSharingAsync(com.jme3.opencl.CommandQueue) } * {@link #releaseImageForSharingAsync(com.jme3.opencl.CommandQueue) }
* so that OpenGL can use the image/texture/renderbuffer again. * so that OpenGL can use the image/texture/renderbuffer again.
*
* @param queue the command queue * @param queue the command queue
* @return the event object * @return the event object
*/ */
@ -518,6 +544,7 @@ memory layout in which channels are stored in the image.
* Call this method after the image object was acquired by * Call this method after the image object was acquired by
* {@link #acquireImageForSharingAsync(com.jme3.opencl.CommandQueue) } * {@link #acquireImageForSharingAsync(com.jme3.opencl.CommandQueue) }
* to hand the control back to OpenGL. * to hand the control back to OpenGL.
*
* @param queue the command queue * @param queue the command queue
* @return the event object * @return the event object
*/ */
@ -530,6 +557,7 @@ memory layout in which channels are stored in the image.
* to hand the control back to OpenGL. * to hand the control back to OpenGL.
* The generated event object is directly released, resulting in * The generated event object is directly released, resulting in
* performance improvements. * performance improvements.
*
* @param queue the command queue * @param queue the command queue
*/ */
public void releaseImageForSharingNoEvent(CommandQueue queue) { public void releaseImageForSharingNoEvent(CommandQueue queue) {
@ -557,5 +585,4 @@ memory layout in which channels are stored in the image.
str.append(')'); str.append(')');
return str.toString(); return str.toString();
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009-2018 jMonkeyEngine * Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -122,6 +122,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/** /**
* Sets the global work size. * Sets the global work size.
*
* @param ws the work size to set * @param ws the work size to set
*/ */
public void setGlobalWorkSize(WorkSize ws) { public void setGlobalWorkSize(WorkSize ws) {
@ -130,6 +131,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/** /**
* Sets the global work size to a 1D grid * Sets the global work size to a 1D grid
*
* @param size the size in 1D * @param size the size in 1D
*/ */
public void setGlobalWorkSize(int size) { public void setGlobalWorkSize(int size) {
@ -138,6 +140,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/** /**
* Sets the global work size to be a 2D grid * Sets the global work size to be a 2D grid
*
* @param width the width * @param width the width
* @param height the height * @param height the height
*/ */
@ -147,6 +150,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/** /**
* Sets the global work size to be a 3D grid * Sets the global work size to be a 3D grid
*
* @param width the width * @param width the width
* @param height the height * @param height the height
* @param depth the depth * @param depth the depth
@ -164,6 +168,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/** /**
* Sets the work group size * Sets the work group size
*
* @param ws the work group size to set * @param ws the work group size to set
*/ */
public void setWorkGroupSize(WorkSize ws) { public void setWorkGroupSize(WorkSize ws) {
@ -172,6 +177,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/** /**
* Sets the work group size to be a 1D grid * Sets the work group size to be a 1D grid
*
* @param size the size to set * @param size the size to set
*/ */
public void setWorkGroupSize(int size) { public void setWorkGroupSize(int size) {
@ -180,6 +186,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/** /**
* Sets the work group size to be a 2D grid * Sets the work group size to be a 2D grid
*
* @param width the width * @param width the width
* @param height the height * @param height the height
*/ */
@ -189,6 +196,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/** /**
* Sets the work group size to be a 3D grid * Sets the work group size to be a 3D grid
*
* @param width the width * @param width the width
* @param height the height * @param height the height
* @param depth the depth * @param depth the depth
@ -211,6 +219,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/** /**
* Returns the maximal work group size when this kernel is executed on * Returns the maximal work group size when this kernel is executed on
* the specified device * the specified device
*
* @param device the device * @param device the device
* @return the maximal work group size * @return the maximal work group size
*/ */
@ -249,8 +258,8 @@ public abstract class Kernel extends AbstractOpenCLObject {
try { try {
Matrix4f m = vars.tempMat4; Matrix4f m = vars.tempMat4;
m.zero(); m.zero();
for (int i=0; i<3; ++i) { for (int i = 0; i < 3; ++i) {
for (int j=0; j<3; ++j) { for (int j = 0; j < 3; ++j) {
m.set(i, j, mat.get(i, j)); m.set(i, j, mat.get(i, j));
} }
} }
@ -266,6 +275,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
* argument. The size in bytes must match exactly the argument size * argument. The size in bytes must match exactly the argument size
* as defined in the kernel code. * as defined in the kernel code.
* Use this method to send custom structures to the kernel * Use this method to send custom structures to the kernel
*
* @param index the index of the argument * @param index the index of the argument
* @param buffer the raw buffer * @param buffer the raw buffer
* @param size the size in bytes * @param size the size in bytes
@ -279,6 +289,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
* long, float, double, Vector2f, Vector4f, Quaternion, Matrix3f, Matrix4f}. * long, float, double, Vector2f, Vector4f, Quaternion, Matrix3f, Matrix4f}.
* <br> * <br>
* Note: Matrix3f and Matrix4f will be mapped to a {@code float16} (row major). * Note: Matrix3f and Matrix4f will be mapped to a {@code float16} (row major).
*
* @param index the index of the argument, from 0 to {@link #getArgCount()}-1 * @param index the index of the argument, from 0 to {@link #getArgCount()}-1
* @param arg the argument * @param arg the argument
* @throws IllegalArgumentException if the argument type is not one of the listed ones * @throws IllegalArgumentException if the argument type is not one of the listed ones
@ -331,6 +342,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
* If the returned event object is not needed and would otherwise be * If the returned event object is not needed and would otherwise be
* released immediately, {@link #RunNoEvent(com.jme3.opencl.CommandQueue) } * released immediately, {@link #RunNoEvent(com.jme3.opencl.CommandQueue) }
* might bring a better performance. * might bring a better performance.
*
* @param queue the command queue * @param queue the command queue
* @return an event object indicating when the kernel is finished * @return an event object indicating when the kernel is finished
* @see #setGlobalWorkSize(com.jme3.opencl.Kernel.WorkSize) * @see #setGlobalWorkSize(com.jme3.opencl.Kernel.WorkSize)
@ -345,6 +357,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
* The generated event is directly released. Therefore, the performance * The generated event is directly released. Therefore, the performance
* is better, but there is no way to detect when the kernel execution * is better, but there is no way to detect when the kernel execution
* has finished. For this purpose, use {@link #Run(com.jme3.opencl.CommandQueue) }. * has finished. For this purpose, use {@link #Run(com.jme3.opencl.CommandQueue) }.
*
* @param queue the command queue * @param queue the command queue
* @see #setGlobalWorkSize(com.jme3.opencl.Kernel.WorkSize) * @see #setGlobalWorkSize(com.jme3.opencl.Kernel.WorkSize)
* @see #setWorkGroupSize(com.jme3.opencl.Kernel.WorkSize) * @see #setWorkGroupSize(com.jme3.opencl.Kernel.WorkSize)
@ -361,6 +374,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
* size is automatically determined by the driver. * size is automatically determined by the driver.
* Each object in the argument array is sent to the kernel by * Each object in the argument array is sent to the kernel by
* {@link #setArg(int, java.lang.Object) }. * {@link #setArg(int, java.lang.Object) }.
*
* @param queue the command queue * @param queue the command queue
* @param globalWorkSize the global work size * @param globalWorkSize the global work size
* @param args the kernel arguments * @param args the kernel arguments
@ -384,6 +398,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
* is better, but there is no way to detect when the kernel execution * is better, but there is no way to detect when the kernel execution
* has finished. For this purpose, use * has finished. For this purpose, use
* {@link #Run1(com.jme3.opencl.CommandQueue, com.jme3.opencl.Kernel.WorkSize, java.lang.Object...) }. * {@link #Run1(com.jme3.opencl.CommandQueue, com.jme3.opencl.Kernel.WorkSize, java.lang.Object...) }.
*
* @param queue the command queue * @param queue the command queue
* @param globalWorkSize the global work size * @param globalWorkSize the global work size
* @param args the kernel arguments * @param args the kernel arguments
@ -398,6 +413,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/** /**
* Sets the work sizes and arguments in one call and launches the kernel. * Sets the work sizes and arguments in one call and launches the kernel.
*
* @param queue the command queue * @param queue the command queue
* @param globalWorkSize the global work size * @param globalWorkSize the global work size
* @param workGroupSize the work group size * @param workGroupSize the work group size
@ -418,6 +434,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
* is better, but there is no way to detect when the kernel execution * is better, but there is no way to detect when the kernel execution
* has finished. For this purpose, use * has finished. For this purpose, use
* {@link #Run2(com.jme3.opencl.CommandQueue, com.jme3.opencl.Kernel.WorkSize, com.jme3.opencl.Kernel.WorkSize, java.lang.Object...) }. * {@link #Run2(com.jme3.opencl.CommandQueue, com.jme3.opencl.Kernel.WorkSize, com.jme3.opencl.Kernel.WorkSize, java.lang.Object...) }.
*
* @param queue the command queue * @param queue the command queue
* @param globalWorkSize the global work size * @param globalWorkSize the global work size
* @param workGroupSize the work group size * @param workGroupSize the work group size
@ -437,16 +454,16 @@ public abstract class Kernel extends AbstractOpenCLObject {
} }
/** /**
* A placeholder for kernel arguments representing local kernel memory. * A placeholder for kernel arguments representing local kernel memory. This
* This defines the size of available shared memory of a {@code __shared} kernel * defines the size of available shared memory of a {@code __shared} kernel
* argument * argument
*/ */
public static final class LocalMem { public static final class LocalMem {
private int size; private int size;
/** /**
* Creates a new LocalMem instance * Creates a new LocalMem instance
*
* @param size the size of the available shared memory in bytes * @param size the size of the available shared memory in bytes
*/ */
public LocalMem(int size) { public LocalMem(int size) {
@ -498,11 +515,11 @@ public abstract class Kernel extends AbstractOpenCLObject {
* (e.g. by {@link #setWorkGroupSizeToNull()} or {@link #Run1(com.jme3.opencl.CommandQueue, com.jme3.opencl.Kernel.WorkSize, java.lang.Object...) }. * (e.g. by {@link #setWorkGroupSizeToNull()} or {@link #Run1(com.jme3.opencl.CommandQueue, com.jme3.opencl.Kernel.WorkSize, java.lang.Object...) }.
*/ */
public static final class LocalMemPerElement { public static final class LocalMemPerElement {
private int size; private int size;
/** /**
* Creates a new LocalMemPerElement instance * Creates a new LocalMemPerElement instance
*
* @param size the number of bytes available for each thread within * @param size the number of bytes available for each thread within
* a work group * a work group
*/ */
@ -546,6 +563,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/** /**
* The work size (global and local) for executing a kernel * The work size (global and local) for executing a kernel
*
* @author shaman * @author shaman
*/ */
public static final class WorkSize { public static final class WorkSize {
@ -555,6 +573,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/** /**
* Creates a new work size object * Creates a new work size object
*
* @param dimension the dimension (1,2,3) * @param dimension the dimension (1,2,3)
* @param sizes the sizes in each dimension, the length must match the specified dimension * @param sizes the sizes in each dimension, the length must match the specified dimension
*/ */
@ -572,6 +591,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/** /**
* Creates a 1D work size of the specified extend * Creates a 1D work size of the specified extend
*
* @param size the size * @param size the size
*/ */
public WorkSize(long size) { public WorkSize(long size) {
@ -580,6 +600,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/** /**
* Creates a 2D work size of the specified extend * Creates a 2D work size of the specified extend
*
* @param width the width * @param width the width
* @param height the height * @param height the height
*/ */
@ -589,6 +610,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
/** /**
* Creates a 3D work size of the specified extend. * Creates a 3D work size of the specified extend.
*
* @param width the width * @param width the width
* @param height the height * @param height the height
* @param depth the depth * @param depth the depth
@ -651,8 +673,8 @@ public abstract class Kernel extends AbstractOpenCLObject {
public String toString() { public String toString() {
StringBuilder str = new StringBuilder(); StringBuilder str = new StringBuilder();
str.append("WorkSize["); str.append("WorkSize[");
for (int i=0; i<dimension; ++i) { for (int i = 0; i < dimension; ++i) {
if (i>0) { if (i > 0) {
str.append(", "); str.append(", ");
} }
str.append(sizes[i]); str.append(sizes[i]);
@ -660,7 +682,5 @@ public abstract class Kernel extends AbstractOpenCLObject {
str.append(']'); str.append(']');
return str.toString(); return str.toString();
} }
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009-2019 jMonkeyEngine * Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -36,10 +36,10 @@ package com.jme3.opencl;
* when the compilation failed. * when the compilation failed.
* The error log returned by {@link #getLog() } contains detailed information * The error log returned by {@link #getLog() } contains detailed information
* where the error occurred. * where the error occurred.
*
* @author shaman * @author shaman
*/ */
public class KernelCompilationException extends OpenCLException { public class KernelCompilationException extends OpenCLException {
private final String log; private final String log;
public KernelCompilationException(String msg, int errorCode, String log) { public KernelCompilationException(String msg, int errorCode, String log) {
@ -49,10 +49,10 @@ public class KernelCompilationException extends OpenCLException {
/** /**
* The output of the compiler * The output of the compiler
*
* @return the output text * @return the output text
*/ */
public String getLog() { public String getLog() {
return log; return log;
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009-2016 jMonkeyEngine * Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -36,6 +36,7 @@ package com.jme3.opencl;
* The error code and its name is reported in the message string as well as the OpenCL call that * The error code and its name is reported in the message string as well as the OpenCL call that
* causes this exception. Please refer to the official OpenCL specification * causes this exception. Please refer to the official OpenCL specification
* to see what might cause this exception. * to see what might cause this exception.
*
* @author shaman * @author shaman
*/ */
public class OpenCLException extends RuntimeException { public class OpenCLException extends RuntimeException {
@ -73,6 +74,4 @@ public class OpenCLException extends RuntimeException {
public int getErrorCode() { public int getErrorCode() {
return errorCode; return errorCode;
} }
} }

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2009-2019 jMonkeyEngine * Copyright (c) 2009-2020 jMonkeyEngine
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -71,8 +71,10 @@ public abstract class Program extends AbstractOpenCLObject {
* @see #build() * @see #build()
*/ */
public abstract void build(String args, Device... devices) throws KernelCompilationException; public abstract void build(String args, Device... devices) throws KernelCompilationException;
/** /**
* Builds this program without additional arguments * Builds this program without additional arguments
*
* @throws KernelCompilationException if the compilation fails * @throws KernelCompilationException if the compilation fails
*/ */
public void build() throws KernelCompilationException { public void build() throws KernelCompilationException {
@ -81,16 +83,18 @@ public abstract class Program extends AbstractOpenCLObject {
/** /**
* Creates the kernel with the specified name. * Creates the kernel with the specified name.
*
* @param name the name of the kernel as defined in the source code * @param name the name of the kernel as defined in the source code
* @return the kernel object * @return the kernel object
* @throws OpenCLException if the kernel was not found or some other * @throws OpenCLException if the kernel was not found or some other error
* error occurred * occurred
*/ */
public abstract Kernel createKernel(String name); public abstract Kernel createKernel(String name);
/** /**
* Creates all available kernels in this program. * Creates all available kernels in this program.
* The names of the kernels can then by queried by {@link Kernel#getName() }. * The names of the kernels can then by queried by {@link Kernel#getName() }.
*
* @return an array of all kernels * @return an array of all kernels
*/ */
public abstract Kernel[] createAllKernels(); public abstract Kernel[] createAllKernels();
@ -100,10 +104,10 @@ public abstract class Program extends AbstractOpenCLObject {
* device. This binary can then be used e.g. in the next application launch * device. This binary can then be used e.g. in the next application launch
* to create the program from the binaries and not from the sources. * to create the program from the binaries and not from the sources.
* This saves time. * This saves time.
*
* @param device the device from which the binaries are taken * @param device the device from which the binaries are taken
* @return the binaries * @return the binaries
* @see Context#createProgramFromBinary(java.nio.ByteBuffer, com.jme3.opencl.Device) * @see Context#createProgramFromBinary(java.nio.ByteBuffer, com.jme3.opencl.Device)
*/ */
public abstract ByteBuffer getBinary(Device device); public abstract ByteBuffer getBinary(Device device);
} }

Loading…
Cancel
Save