improve format and rm trailing whitespace (10 files in com.jme3.opencl)
This commit is contained in:
parent
1fa283f06a
commit
a150deb8be
jme3-core/src/main/java/com/jme3/opencl
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2016 jMonkeyEngine
|
||||
* Copyright (c) 2009-2020 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -53,11 +53,11 @@ public abstract class Buffer extends AbstractOpenCLObject {
|
||||
super(releaser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Buffer register() {
|
||||
super.register();
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public Buffer register() {
|
||||
super.register();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the size of the buffer in bytes.
|
||||
@ -75,6 +75,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
|
||||
* Performs a blocking read of the buffer.
|
||||
* The target buffer must have at least {@code size} bytes remaining.
|
||||
* This method may set the limit to the last byte read.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param dest the target buffer
|
||||
* @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.
|
||||
* The target buffer must have at least {@code size} bytes remaining.
|
||||
* This method may set the limit to the last byte read.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param dest the target buffer
|
||||
* @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.
|
||||
* 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.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param src the source buffer, its data is written to this buffer
|
||||
* @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.
|
||||
* 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.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param src the source buffer, its data is written to this buffer
|
||||
* @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.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param dest the target buffer
|
||||
* @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.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param dest the target buffer
|
||||
* @param size the size in bytes to copy
|
||||
@ -240,6 +246,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
|
||||
* provides the memory.<br>
|
||||
* <b>Important:</b> The mapped memory MUST be released by calling
|
||||
* {@link #unmap(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer) }.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param size the size in bytes to map
|
||||
* @param offset the offset into this buffer
|
||||
@ -272,6 +279,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
|
||||
* Unmaps a previously mapped memory.
|
||||
* This releases the native resources and for WRITE_ONLY or READ_WRITE access,
|
||||
* the memory content is sent back to the GPU.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param ptr the buffer that was previously mapped
|
||||
*/
|
||||
@ -283,6 +291,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
|
||||
* provides the memory.<br>
|
||||
* <b>Important:</b> The mapped memory MUST be released by calling
|
||||
* {@link #unmap(com.jme3.opencl.CommandQueue, java.nio.ByteBuffer) }.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param size the size in bytes to map
|
||||
* @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
|
||||
*/
|
||||
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) },
|
||||
* sets {@code offset} to zero.
|
||||
@ -300,6 +310,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
|
||||
public AsyncMapping mapAsync(CommandQueue queue, long size, MappingAccess access) {
|
||||
return mapAsync(queue, size, 0, access);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative version of {@link #mapAsync(com.jme3.opencl.CommandQueue, long, com.jme3.opencl.MappingAccess) },
|
||||
* 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
|
||||
* a buffer with a certain value.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param pattern the buffer containing the filling pattern.
|
||||
* 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
|
||||
* {@link #releaseBufferForSharingAsync(com.jme3.opencl.CommandQueue) }
|
||||
* so that OpenGL can use the VertexBuffer again.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @return the event object
|
||||
*/
|
||||
@ -411,6 +424,7 @@ public abstract class Buffer extends AbstractOpenCLObject {
|
||||
* Call this method after the buffer object was acquired by
|
||||
* {@link #acquireBufferForSharingAsync(com.jme3.opencl.CommandQueue) }
|
||||
* to hand the control back to OpenGL.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @return the event object
|
||||
*/
|
||||
@ -430,9 +444,8 @@ public abstract class Buffer extends AbstractOpenCLObject {
|
||||
releaseBufferForSharingAsync(queue).release();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Buffer (" + getSize() + "B)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Buffer (" + getSize() + "B)";
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2016 jMonkeyEngine
|
||||
* Copyright (c) 2009-2020 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -40,32 +40,33 @@ package com.jme3.opencl;
|
||||
* Each command queue is associtated with exactly one device: that device
|
||||
* is specified on creation ({@link Context#createQueue(com.jme3.opencl.Device) })
|
||||
* and all commands are sent to this device.
|
||||
*
|
||||
* @author shaman
|
||||
*/
|
||||
public abstract class CommandQueue extends AbstractOpenCLObject {
|
||||
|
||||
protected Device device;
|
||||
protected Device device;
|
||||
|
||||
protected CommandQueue(ObjectReleaser releaser, Device device) {
|
||||
super(releaser);
|
||||
this.device = device;
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandQueue register() {
|
||||
super.register();
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public CommandQueue register() {
|
||||
super.register();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the device associated with this command queue.
|
||||
* It can be used to query properties of the device that is used to execute
|
||||
* the commands issued to this command queue.
|
||||
* @return the associated device
|
||||
*/
|
||||
public Device getDevice() {
|
||||
return device;
|
||||
}
|
||||
/**
|
||||
* Returns the device associated with this command queue.
|
||||
* It can be used to query properties of the device that is used to execute
|
||||
* the commands issued to this command queue.
|
||||
*
|
||||
* @return the associated device
|
||||
*/
|
||||
public Device getDevice() {
|
||||
return device;
|
||||
}
|
||||
|
||||
/**
|
||||
* Issues all previously queued OpenCL commands in command_queue to the
|
||||
@ -83,5 +84,4 @@ public abstract class CommandQueue extends AbstractOpenCLObject {
|
||||
* processed and completed. Finish is also a synchronization point.
|
||||
*/
|
||||
public abstract void finish();
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2019 jMonkeyEngine
|
||||
* Copyright (c) 2009-2020 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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>Create program objects from source code and source files</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author shaman
|
||||
*/
|
||||
public abstract class Context extends AbstractOpenCLObject {
|
||||
@ -72,11 +73,11 @@ public abstract class Context extends AbstractOpenCLObject {
|
||||
super(releaser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Context register() {
|
||||
super.register();
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public Context register() {
|
||||
super.register();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all available devices for this context.
|
||||
@ -87,6 +88,7 @@ public abstract class Context extends AbstractOpenCLObject {
|
||||
* memory size and so on, are queried over the Device instances.
|
||||
* <br>
|
||||
* The available devices were specified by a {@link PlatformChooser}.
|
||||
*
|
||||
* @return a list of devices
|
||||
*/
|
||||
public abstract List<? extends Device> getDevices();
|
||||
@ -94,29 +96,35 @@ public abstract class Context extends AbstractOpenCLObject {
|
||||
/**
|
||||
* Alternative version of {@link #createQueue(com.jme3.opencl.Device) },
|
||||
* just uses the first device returned by {@link #getDevices() }.
|
||||
*
|
||||
* @return the command queue
|
||||
*/
|
||||
public CommandQueue createQueue() {
|
||||
return createQueue(getDevices().get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a command queue sending commands to the specified device.
|
||||
* The device must be an entry of {@link #getDevices() }.
|
||||
*
|
||||
* @param device the target device
|
||||
* @return the command queue
|
||||
*/
|
||||
public abstract CommandQueue createQueue(Device device);
|
||||
public abstract CommandQueue createQueue(Device 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 access the allowed access of this buffer from kernel code
|
||||
* @return the new buffer
|
||||
*/
|
||||
public abstract Buffer createBuffer(long size, MemoryAccess access);
|
||||
|
||||
/**
|
||||
* Alternative version of {@link #createBuffer(long, com.jme3.opencl.MemoryAccess) },
|
||||
* creates a buffer with read and write access.
|
||||
*
|
||||
* @param size the size of the buffer in bytes
|
||||
* @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,
|
||||
* although the access might be slower than with native buffers
|
||||
* created by {@link #createBuffer(long, com.jme3.opencl.MemoryAccess) }.
|
||||
*
|
||||
* @param data the host buffer to use
|
||||
* @param access the allowed access of this buffer from kernel code
|
||||
* @return the new buffer
|
||||
*/
|
||||
public abstract Buffer createBufferFromHost(ByteBuffer data, MemoryAccess access);
|
||||
|
||||
/**
|
||||
* Alternative version of {@link #createBufferFromHost(java.nio.ByteBuffer, com.jme3.opencl.MemoryAccess) },
|
||||
* creates a buffer with read and write access.
|
||||
*
|
||||
* @param data the host buffer to use
|
||||
* @return the new buffer
|
||||
*/
|
||||
@ -152,13 +163,14 @@ public abstract class Context extends AbstractOpenCLObject {
|
||||
* 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
|
||||
* normal behaviour).
|
||||
*
|
||||
* @param access the allowed access of this image from kernel code
|
||||
* @param format the image format
|
||||
* @param descr the image descriptor
|
||||
* @return the new image object
|
||||
*/
|
||||
public abstract Image createImage(MemoryAccess access, ImageFormat format, ImageDescriptor descr);
|
||||
//TODO: add simplified methods for 1D, 2D, 3D textures
|
||||
//TODO: add simplified methods for 1D, 2D, 3D textures
|
||||
|
||||
/**
|
||||
* Queries all supported image formats for a specified memory access and
|
||||
@ -168,13 +180,14 @@ public abstract class Context extends AbstractOpenCLObject {
|
||||
* where {@code ImageChannelType} or {@code ImageChannelOrder} are {@code null}
|
||||
* (or both). This is the case when the device supports new formats that
|
||||
* are not included in this wrapper yet.
|
||||
*
|
||||
* @param access the memory access type
|
||||
* @param type the image type (1D, 2D, 3D, ...)
|
||||
* @return an array of all supported image formats
|
||||
*/
|
||||
public abstract ImageFormat[] querySupportedFormats(MemoryAccess access, ImageType type);
|
||||
|
||||
//Interop
|
||||
//Interop
|
||||
/**
|
||||
* Creates a shared buffer from a VertexBuffer.
|
||||
* The returned buffer and the vertex buffer operate on the same memory,
|
||||
@ -188,6 +201,7 @@ public abstract class Context extends AbstractOpenCLObject {
|
||||
* by {@link Buffer#acquireBufferForSharingAsync(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.
|
||||
*
|
||||
* @param vb the vertex buffer to share
|
||||
* @param access the memory access for the kernel
|
||||
* @return the new buffer
|
||||
@ -216,6 +230,7 @@ public abstract class Context extends AbstractOpenCLObject {
|
||||
* @return the OpenCL image
|
||||
*/
|
||||
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.
|
||||
* 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) {
|
||||
return bindImage(texture.getImage(), texture.getType(), miplevel, access);
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative version to {@link #bindImage(com.jme3.texture.Texture, int, com.jme3.opencl.MemoryAccess) },
|
||||
* uses {@code miplevel=0}.
|
||||
*
|
||||
* @param texture the jME3 texture
|
||||
* @param access the allowed memory access for kernels
|
||||
* @return the OpenCL image
|
||||
@ -252,6 +269,7 @@ public abstract class Context extends AbstractOpenCLObject {
|
||||
public Image bindImage(Texture texture, MemoryAccess access) {
|
||||
return bindImage(texture, 0, access);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a shared image object from a jME3 render buffer.
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
* {@link #createProgramFromSourceCode(java.lang.String) }.
|
||||
* Important: only absolute paths are allowed.
|
||||
*
|
||||
* @param sourceCode the original source code
|
||||
* @param assetManager the asset manager to load the files
|
||||
* @return the created program object
|
||||
@ -310,6 +330,7 @@ public abstract class Context extends AbstractOpenCLObject {
|
||||
}
|
||||
return createProgramFromSourceCode(builder.toString());
|
||||
}
|
||||
|
||||
private void buildSourcesRec(BufferedReader reader, StringBuilder builder, AssetManager assetManager) throws IOException {
|
||||
String ln;
|
||||
while ((ln = reader.readLine()) != null) {
|
||||
@ -319,11 +340,11 @@ public abstract class Context extends AbstractOpenCLObject {
|
||||
ln = ln.substring(1);
|
||||
}
|
||||
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));
|
||||
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()))) {
|
||||
builder.append("//-- begin import ").append(ln).append(" --\n");
|
||||
@ -390,7 +411,7 @@ public abstract class Context extends AbstractOpenCLObject {
|
||||
for (String res : resources) {
|
||||
AssetInfo info = assetManager.locateAsset(new AssetKey<String>(res));
|
||||
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()))) {
|
||||
while (true) {
|
||||
@ -401,7 +422,7 @@ public abstract class Context extends AbstractOpenCLObject {
|
||||
str.append(line).append('\n');
|
||||
}
|
||||
} 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);
|
||||
@ -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...) }
|
||||
* with an empty include string
|
||||
*
|
||||
* @throws AssetNotFoundException if a file could not be loaded
|
||||
*/
|
||||
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) }
|
||||
* with an empty include string
|
||||
*
|
||||
* @throws AssetNotFoundException if a file could not be loaded
|
||||
*/
|
||||
public Program createProgramFromSourceFiles(AssetManager assetManager, List<String> resources) {
|
||||
@ -443,9 +466,8 @@ public abstract class Context extends AbstractOpenCLObject {
|
||||
*/
|
||||
public abstract Program createProgramFromBinary(ByteBuffer binaries, Device device);
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Context (" + getDevices() + ')';
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Context (" + getDevices() + ')';
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2019 jMonkeyEngine
|
||||
* Copyright (c) 2009-2020 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -45,79 +45,92 @@ import java.util.Collection;
|
||||
* @author shaman
|
||||
*/
|
||||
public interface Device {
|
||||
|
||||
/**
|
||||
* @return the platform associated with this device
|
||||
*/
|
||||
Platform getPlatform();
|
||||
|
||||
/**
|
||||
* The device type
|
||||
*/
|
||||
public static enum DeviceType {
|
||||
DEFAULT,
|
||||
CPU,
|
||||
GPU,
|
||||
ACCELEARTOR,
|
||||
ALL
|
||||
}
|
||||
public static enum DeviceType {
|
||||
DEFAULT,
|
||||
CPU,
|
||||
GPU,
|
||||
ACCELEARTOR,
|
||||
ALL
|
||||
}
|
||||
|
||||
/**
|
||||
* @return queries the device type
|
||||
*/
|
||||
DeviceType getDeviceType();
|
||||
DeviceType getDeviceType();
|
||||
|
||||
/**
|
||||
* @return the vendor id
|
||||
*/
|
||||
int getVendorId();
|
||||
int getVendorId();
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* @return if this device has a compiler for kernel code
|
||||
*/
|
||||
boolean hasCompiler();
|
||||
boolean hasCompiler();
|
||||
|
||||
/**
|
||||
* @return supports double precision floats (64 bit)
|
||||
*/
|
||||
boolean hasDouble();
|
||||
boolean hasDouble();
|
||||
|
||||
/**
|
||||
* @return supports half precision floats (16 bit)
|
||||
*/
|
||||
boolean hasHalfFloat();
|
||||
boolean hasHalfFloat();
|
||||
|
||||
/**
|
||||
* @return supports error correction for every access to global or constant memory
|
||||
*/
|
||||
boolean hasErrorCorrectingMemory();
|
||||
boolean hasErrorCorrectingMemory();
|
||||
|
||||
/**
|
||||
* @return supports unified virtual memory (OpenCL 2.0)
|
||||
*/
|
||||
boolean hasUnifiedMemory();
|
||||
boolean hasUnifiedMemory();
|
||||
|
||||
/**
|
||||
* @return supports images
|
||||
*/
|
||||
boolean hasImageSupport();
|
||||
boolean hasImageSupport();
|
||||
|
||||
/**
|
||||
* @return supports writes to 3d images (this is an extension)
|
||||
*/
|
||||
boolean hasWritableImage3D();
|
||||
|
||||
/**
|
||||
* @return supports sharing with OpenGL
|
||||
*/
|
||||
boolean hasOpenGLInterop();
|
||||
|
||||
/**
|
||||
* Explictly tests for the availability of the specified extension
|
||||
*
|
||||
* @param extension the name of the extension
|
||||
* @return {@code true} iff this extension is supported
|
||||
*/
|
||||
boolean hasExtension(String extension);
|
||||
boolean hasExtension(String extension);
|
||||
|
||||
/**
|
||||
* Lists all available extensions
|
||||
*
|
||||
* @return all available extensions
|
||||
*/
|
||||
Collection<? extends String> getExtensions();
|
||||
Collection<? extends String> getExtensions();
|
||||
|
||||
/**
|
||||
* Returns the number of parallel compute units on
|
||||
@ -128,82 +141,100 @@ public interface Device {
|
||||
* @see #getMaximumWorkItemDimensions()
|
||||
* @see #getMaximumWorkItemSizes()
|
||||
*/
|
||||
int getComputeUnits();
|
||||
int getComputeUnits();
|
||||
|
||||
/**
|
||||
* @return maximum clock frequency of the device in MHz
|
||||
*/
|
||||
int getClockFrequency();
|
||||
int getClockFrequency();
|
||||
|
||||
/**
|
||||
* Returns the default compute device address space
|
||||
* size specified as an unsigned integer value
|
||||
* in bits. Currently supported values are 32
|
||||
* or 64 bits.
|
||||
*
|
||||
* @return the size of an address
|
||||
*/
|
||||
int getAddressBits();
|
||||
int getAddressBits();
|
||||
|
||||
/**
|
||||
* @return {@code true} if this device is little endian
|
||||
*/
|
||||
boolean isLittleEndian();
|
||||
boolean isLittleEndian();
|
||||
|
||||
/**
|
||||
* The maximum dimension that specify the local and global work item ids.
|
||||
* You can always assume to be this at least 3.
|
||||
* Therefore, the ids are always three integers x,y,z.
|
||||
*
|
||||
* @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
|
||||
* 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.
|
||||
*
|
||||
* @return the maximum size of the work group in each dimension
|
||||
*/
|
||||
long[] getMaximumWorkItemSizes();
|
||||
long[] getMaximumWorkItemSizes();
|
||||
|
||||
/**
|
||||
* Maximum number of work-items in a
|
||||
* work-group executing a kernel on a single
|
||||
* compute unit, using the data parallel
|
||||
* execution model.
|
||||
*
|
||||
* @return maximum number of work-items in a work-group
|
||||
*/
|
||||
long getMaxiumWorkItemsPerGroup();
|
||||
long getMaxiumWorkItemsPerGroup();
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
int getMaximumReadImages();
|
||||
int getMaximumReadImages();
|
||||
|
||||
/**
|
||||
* @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
|
||||
*
|
||||
* @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
|
||||
*
|
||||
* @return an array of length 3 with the maximal size of a 3D image
|
||||
*/
|
||||
long[] getMaximumImage3DSize();
|
||||
long[] getMaximumImage3DSize();
|
||||
|
||||
/**
|
||||
* @return the maximal size of a memory object (buffer and image) in bytes
|
||||
*/
|
||||
long getMaximumAllocationSize();
|
||||
|
||||
/**
|
||||
* @return the total available global memory in bytes
|
||||
*/
|
||||
long getGlobalMemorySize();
|
||||
|
||||
/**
|
||||
* @return the total available local memory in bytes
|
||||
*/
|
||||
long getLocalMemorySize();
|
||||
|
||||
/**
|
||||
* Returns the maximal size of a constant buffer.
|
||||
* <br>
|
||||
@ -214,12 +245,13 @@ public interface Device {
|
||||
* @return the maximal size of a constant buffer
|
||||
*/
|
||||
long getMaximumConstantBufferSize();
|
||||
|
||||
/**
|
||||
* @return the maximal number of constant buffer arguments in a kernel call
|
||||
*/
|
||||
int getMaximumConstantArguments();
|
||||
|
||||
//TODO: cache, prefered sizes properties
|
||||
//TODO: cache, prefered sizes properties
|
||||
/**
|
||||
* OpenCL profile string. Returns the profile name supported by the device.
|
||||
* The profile name returned can be one of the following strings:<br>
|
||||
@ -230,7 +262,8 @@ public interface Device {
|
||||
*
|
||||
* @return the profile string
|
||||
*/
|
||||
String getProfile();
|
||||
String getProfile();
|
||||
|
||||
/**
|
||||
* OpenCL version string. Returns the OpenCL version supported by the
|
||||
* device. This version string has the following format: OpenCL space
|
||||
@ -240,19 +273,23 @@ public interface Device {
|
||||
*
|
||||
* @return the version string
|
||||
*/
|
||||
String getVersion();
|
||||
String getVersion();
|
||||
|
||||
/**
|
||||
* Extracts the major version from the version string
|
||||
*
|
||||
* @return the major version
|
||||
* @see #getVersion()
|
||||
*/
|
||||
int getVersionMajor();
|
||||
int getVersionMajor();
|
||||
|
||||
/**
|
||||
* Extracts the minor version from the version string
|
||||
*
|
||||
* @return the minor version
|
||||
* @see #getVersion() }
|
||||
*/
|
||||
int getVersionMinor();
|
||||
int getVersionMinor();
|
||||
|
||||
/**
|
||||
* OpenCL C version string. Returns the highest OpenCL C version supported
|
||||
@ -268,44 +305,53 @@ public interface Device {
|
||||
*
|
||||
* @return the compiler version
|
||||
*/
|
||||
String getCompilerVersion();
|
||||
String getCompilerVersion();
|
||||
|
||||
/**
|
||||
* Extracts the major version from the compiler version
|
||||
*
|
||||
* @return the major compiler version
|
||||
* @see #getCompilerVersion()
|
||||
*/
|
||||
int getCompilerVersionMajor();
|
||||
int getCompilerVersionMajor();
|
||||
|
||||
/**
|
||||
* Extracts the minor version from the compiler version
|
||||
*
|
||||
* @return the minor compiler version
|
||||
* @see #getCompilerVersion()
|
||||
*/
|
||||
int getCompilerVersionMinor();
|
||||
int getCompilerVersionMinor();
|
||||
|
||||
/**
|
||||
* @return the OpenCL software driver version string in the form
|
||||
* major_number.minor_number
|
||||
*/
|
||||
String getDriverVersion();
|
||||
String getDriverVersion();
|
||||
|
||||
/**
|
||||
* Extracts the major version from the driver version
|
||||
*
|
||||
* @return the major driver version
|
||||
* @see #getDriverVersion()
|
||||
*/
|
||||
int getDriverVersionMajor();
|
||||
int getDriverVersionMajor();
|
||||
|
||||
/**
|
||||
* Extracts the minor version from the driver version
|
||||
*
|
||||
* @return the minor driver version
|
||||
* @see #getDriverVersion()
|
||||
*/
|
||||
int getDriverVersionMinor();
|
||||
int getDriverVersionMinor();
|
||||
|
||||
/**
|
||||
* @return the device name
|
||||
*/
|
||||
String getName();
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* @return the vendor
|
||||
*/
|
||||
String getVendor();
|
||||
|
||||
String getVendor();
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2016 jMonkeyEngine
|
||||
* Copyright (c) 2009-2020 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
* They allow to test if the action has completed and to block until the operation
|
||||
* is done.
|
||||
*
|
||||
* @author shaman
|
||||
*/
|
||||
public abstract class Event extends AbstractOpenCLObject {
|
||||
@ -44,22 +45,23 @@ public abstract class Event extends AbstractOpenCLObject {
|
||||
super(releaser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Event register() {
|
||||
super.register();
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public Event register() {
|
||||
super.register();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits until the action has finished (blocking).
|
||||
* This automatically releases the event.
|
||||
*/
|
||||
public abstract void waitForFinished();
|
||||
public abstract void waitForFinished();
|
||||
|
||||
/**
|
||||
* Tests if the action is completed.
|
||||
* If the action is completed, the event is released.
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -75,7 +75,6 @@ import java.util.Objects;
|
||||
* @author shaman
|
||||
*/
|
||||
public abstract class Image extends AbstractOpenCLObject {
|
||||
|
||||
/**
|
||||
* {@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
|
||||
memory layout in which channels are stored in the image.
|
||||
* memory layout in which channels are stored in the image.
|
||||
*/
|
||||
public static enum ImageChannelOrder {
|
||||
R, Rx, A,
|
||||
@ -157,7 +156,6 @@ memory layout in which channels are stored in the image.
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -193,13 +191,14 @@ memory layout in which channels are stored in the image.
|
||||
/*
|
||||
public int numMipLevels; //They must always be set to zero
|
||||
public int numSamples;
|
||||
*/
|
||||
*/
|
||||
|
||||
public ImageDescriptor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to specify an image with the provided ByteBuffer as soruce
|
||||
*
|
||||
* @param type the image type
|
||||
* @param width the width
|
||||
* @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.hostPtr = hostPtr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies an image without a host buffer, a new chunk of memory
|
||||
* will be allocated.
|
||||
*
|
||||
* @param type the image type
|
||||
* @param width the width
|
||||
* @param height the height, unused for image types {@code ImageType.IMAGE_1D*}
|
||||
@ -243,53 +244,60 @@ memory layout in which channels are stored in the image.
|
||||
public String toString() {
|
||||
return "ImageDescriptor{" + "type=" + type + ", width=" + width + ", height=" + height + ", depth=" + depth + ", arraySize=" + arraySize + ", rowPitch=" + rowPitch + ", slicePitch=" + slicePitch + '}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected Image(ObjectReleaser releaser) {
|
||||
super(releaser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image register() {
|
||||
super.register();
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public Image register() {
|
||||
super.register();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the width of the image
|
||||
*/
|
||||
public abstract long getWidth();
|
||||
|
||||
/**
|
||||
* @return the height of the image
|
||||
*/
|
||||
public abstract long getHeight();
|
||||
|
||||
/**
|
||||
* @return the depth of the image
|
||||
*/
|
||||
public abstract long getDepth();
|
||||
|
||||
/**
|
||||
* @return the row pitch when the image was created from a host buffer
|
||||
*/
|
||||
public abstract long getRowPitch();
|
||||
|
||||
/**
|
||||
* @return the slice pitch when the image was created from a host buffer
|
||||
*/
|
||||
public abstract long getSlicePitch();
|
||||
|
||||
/**
|
||||
* @return the number of elements in the image array
|
||||
* @see ImageType#IMAGE_1D_ARRAY
|
||||
* @see ImageType#IMAGE_2D_ARRAY
|
||||
*/
|
||||
public abstract long getArraySize();
|
||||
|
||||
/**
|
||||
* @return the image format
|
||||
*/
|
||||
public abstract ImageFormat getImageFormat();
|
||||
|
||||
/**
|
||||
* @return the image type
|
||||
*/
|
||||
public abstract ImageType getImageType();
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param dest the target byte buffer
|
||||
* @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}
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param dest the target byte buffer
|
||||
* @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.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param src the source buffer
|
||||
* @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}
|
||||
*/
|
||||
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.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param src the source buffer
|
||||
* @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.
|
||||
* <b>Important:</b> Both images must have the same format!
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param dest the target image
|
||||
* @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
|
||||
*/
|
||||
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.
|
||||
* <b>Important:</b> Both images must have the same format!
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param dest the target image
|
||||
* @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 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) }.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param origin the image origin, 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)
|
||||
*/
|
||||
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) }.
|
||||
* 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)
|
||||
*/
|
||||
public abstract ImageMapping mapAsync(CommandQueue queue, long[] origin, long[] region, MappingAccess access);
|
||||
|
||||
/**
|
||||
* Unmaps the mapped memory
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param mapping the mapped memory
|
||||
*/
|
||||
@ -421,6 +442,7 @@ memory layout in which channels are stored in the image.
|
||||
public final long slicePitch;
|
||||
/**
|
||||
* The event object used to detect when the memory is available.
|
||||
*
|
||||
* @see #mapAsync(com.jme3.opencl.CommandQueue, long[], long[], com.jme3.opencl.MappingAccess)
|
||||
*/
|
||||
public final Event event;
|
||||
@ -431,19 +453,20 @@ memory layout in which channels are stored in the image.
|
||||
this.slicePitch = slicePitch;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
public ImageMapping(ByteBuffer buffer, long rowPitch, long slicePitch) {
|
||||
this.buffer = buffer;
|
||||
this.rowPitch = rowPitch;
|
||||
this.slicePitch = slicePitch;
|
||||
this.event = null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills the image with the specified color.
|
||||
* Does <b>only</b> work if the image channel is {@link ImageChannelType#FLOAT}
|
||||
* or {@link ImageChannelType#HALF_FLOAT}.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param origin the image origin, 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.
|
||||
* Does <b>not</b> work if the image channel is {@link ImageChannelType#FLOAT}
|
||||
* or {@link ImageChannelType#HALF_FLOAT}.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param origin the image origin, 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.
|
||||
* This is the dual function to
|
||||
* {@link Buffer#copyToImageAsync(com.jme3.opencl.CommandQueue, com.jme3.opencl.Image, long, long[], long[]) }.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param dest the target buffer
|
||||
* @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
|
||||
* {@link #releaseImageForSharingAsync(com.jme3.opencl.CommandQueue) }
|
||||
* so that OpenGL can use the image/texture/renderbuffer again.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @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
|
||||
* {@link #acquireImageForSharingAsync(com.jme3.opencl.CommandQueue) }
|
||||
* to hand the control back to OpenGL.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @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.
|
||||
* The generated event object is directly released, resulting in
|
||||
* performance improvements.
|
||||
*
|
||||
* @param queue the command queue
|
||||
*/
|
||||
public void releaseImageForSharingNoEvent(CommandQueue queue) {
|
||||
@ -537,25 +565,24 @@ memory layout in which channels are stored in the image.
|
||||
releaseImageForSharingAsync(queue).release();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.append("Image (");
|
||||
ImageType t = getImageType();
|
||||
str.append(t);
|
||||
str.append(", w=").append(getWidth());
|
||||
if (t == ImageType.IMAGE_2D || t == ImageType.IMAGE_3D) {
|
||||
str.append(", h=").append(getHeight());
|
||||
}
|
||||
if (t == ImageType.IMAGE_3D) {
|
||||
str.append(", d=").append(getDepth());
|
||||
}
|
||||
if (t == ImageType.IMAGE_1D_ARRAY || t == ImageType.IMAGE_2D_ARRAY) {
|
||||
str.append(", arrays=").append(getArraySize());
|
||||
}
|
||||
str.append(", ").append(getImageFormat());
|
||||
str.append(')');
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.append("Image (");
|
||||
ImageType t = getImageType();
|
||||
str.append(t);
|
||||
str.append(", w=").append(getWidth());
|
||||
if (t == ImageType.IMAGE_2D || t == ImageType.IMAGE_3D) {
|
||||
str.append(", h=").append(getHeight());
|
||||
}
|
||||
if (t == ImageType.IMAGE_3D) {
|
||||
str.append(", d=").append(getDepth());
|
||||
}
|
||||
if (t == ImageType.IMAGE_1D_ARRAY || t == ImageType.IMAGE_2D_ARRAY) {
|
||||
str.append(", arrays=").append(getArraySize());
|
||||
}
|
||||
str.append(", ").append(getImageFormat());
|
||||
str.append(')');
|
||||
return str.toString();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2018 jMonkeyEngine
|
||||
* Copyright (c) 2009-2020 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -97,11 +97,11 @@ public abstract class Kernel extends AbstractOpenCLObject {
|
||||
this.workGroupSize = new WorkSize(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Kernel register() {
|
||||
super.register();
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public Kernel register() {
|
||||
super.register();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the kernel as defined in the program source code
|
||||
@ -122,6 +122,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
|
||||
|
||||
/**
|
||||
* Sets the global work size.
|
||||
*
|
||||
* @param ws the work size to set
|
||||
*/
|
||||
public void setGlobalWorkSize(WorkSize ws) {
|
||||
@ -130,6 +131,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
|
||||
|
||||
/**
|
||||
* Sets the global work size to a 1D grid
|
||||
*
|
||||
* @param size the size in 1D
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @param width the width
|
||||
* @param height the height
|
||||
*/
|
||||
@ -147,6 +150,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
|
||||
|
||||
/**
|
||||
* Sets the global work size to be a 3D grid
|
||||
*
|
||||
* @param width the width
|
||||
* @param height the height
|
||||
* @param depth the depth
|
||||
@ -164,6 +168,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
|
||||
|
||||
/**
|
||||
* Sets the work group size
|
||||
*
|
||||
* @param ws the work group size to set
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @param size the size to set
|
||||
*/
|
||||
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
|
||||
*
|
||||
* @param width the width
|
||||
* @param height the height
|
||||
*/
|
||||
@ -189,6 +196,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
|
||||
|
||||
/**
|
||||
* Sets the work group size to be a 3D grid
|
||||
*
|
||||
* @param width the width
|
||||
* @param height the height
|
||||
* @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
|
||||
* the specified device
|
||||
*
|
||||
* @param device the device
|
||||
* @return the maximal work group size
|
||||
*/
|
||||
@ -249,8 +258,8 @@ public abstract class Kernel extends AbstractOpenCLObject {
|
||||
try {
|
||||
Matrix4f m = vars.tempMat4;
|
||||
m.zero();
|
||||
for (int i=0; i<3; ++i) {
|
||||
for (int j=0; j<3; ++j) {
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 3; ++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
|
||||
* as defined in the kernel code.
|
||||
* Use this method to send custom structures to the kernel
|
||||
*
|
||||
* @param index the index of the argument
|
||||
* @param buffer the raw buffer
|
||||
* @param size the size in bytes
|
||||
@ -279,6 +289,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
|
||||
* long, float, double, Vector2f, Vector4f, Quaternion, Matrix3f, Matrix4f}.
|
||||
* <br>
|
||||
* 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 arg the argument
|
||||
* @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
|
||||
* released immediately, {@link #RunNoEvent(com.jme3.opencl.CommandQueue) }
|
||||
* might bring a better performance.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @return an event object indicating when the kernel is finished
|
||||
* @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
|
||||
* 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) }.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @see #setGlobalWorkSize(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.
|
||||
* Each object in the argument array is sent to the kernel by
|
||||
* {@link #setArg(int, java.lang.Object) }.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param globalWorkSize the global work size
|
||||
* @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
|
||||
* has finished. For this purpose, use
|
||||
* {@link #Run1(com.jme3.opencl.CommandQueue, com.jme3.opencl.Kernel.WorkSize, java.lang.Object...) }.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param globalWorkSize the global work size
|
||||
* @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.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param globalWorkSize the global work 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
|
||||
* 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...) }.
|
||||
*
|
||||
* @param queue the command queue
|
||||
* @param globalWorkSize the global work size
|
||||
* @param workGroupSize the work group size
|
||||
@ -431,22 +448,22 @@ public abstract class Kernel extends AbstractOpenCLObject {
|
||||
RunNoEvent(queue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Kernel (" + getName() + ")";
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Kernel (" + getName() + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* A placeholder for kernel arguments representing local kernel memory.
|
||||
* This defines the size of available shared memory of a {@code __shared} kernel
|
||||
* A placeholder for kernel arguments representing local kernel memory. This
|
||||
* defines the size of available shared memory of a {@code __shared} kernel
|
||||
* argument
|
||||
*/
|
||||
public static final class LocalMem {
|
||||
|
||||
private int size;
|
||||
|
||||
/**
|
||||
* Creates a new LocalMem instance
|
||||
*
|
||||
* @param size the size of the available shared memory in bytes
|
||||
*/
|
||||
public LocalMem(int size) {
|
||||
@ -480,10 +497,10 @@ public abstract class Kernel extends AbstractOpenCLObject {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LocalMem (" + size + "B)";
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LocalMem (" + size + "B)";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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...) }.
|
||||
*/
|
||||
public static final class LocalMemPerElement {
|
||||
|
||||
private int size;
|
||||
|
||||
/**
|
||||
* Creates a new LocalMemPerElement instance
|
||||
*
|
||||
* @param size the number of bytes available for each thread within
|
||||
* a work group
|
||||
*/
|
||||
@ -537,15 +554,16 @@ public abstract class Kernel extends AbstractOpenCLObject {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LocalMemPerElement (" + size + "B)";
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LocalMemPerElement (" + size + "B)";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The work size (global and local) for executing a kernel
|
||||
*
|
||||
* @author shaman
|
||||
*/
|
||||
public static final class WorkSize {
|
||||
@ -555,6 +573,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
|
||||
|
||||
/**
|
||||
* Creates a new work size object
|
||||
*
|
||||
* @param dimension the dimension (1,2,3)
|
||||
* @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
|
||||
*
|
||||
* @param size the size
|
||||
*/
|
||||
public WorkSize(long size) {
|
||||
@ -580,6 +600,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
|
||||
|
||||
/**
|
||||
* Creates a 2D work size of the specified extend
|
||||
*
|
||||
* @param width the width
|
||||
* @param height the height
|
||||
*/
|
||||
@ -589,6 +610,7 @@ public abstract class Kernel extends AbstractOpenCLObject {
|
||||
|
||||
/**
|
||||
* Creates a 3D work size of the specified extend.
|
||||
*
|
||||
* @param width the width
|
||||
* @param height the height
|
||||
* @param depth the depth
|
||||
@ -647,20 +669,18 @@ public abstract class Kernel extends AbstractOpenCLObject {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.append("WorkSize[");
|
||||
for (int i=0; i<dimension; ++i) {
|
||||
if (i>0) {
|
||||
str.append(", ");
|
||||
}
|
||||
str.append(sizes[i]);
|
||||
}
|
||||
str.append(']');
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.append("WorkSize[");
|
||||
for (int i = 0; i < dimension; ++i) {
|
||||
if (i > 0) {
|
||||
str.append(", ");
|
||||
}
|
||||
str.append(sizes[i]);
|
||||
}
|
||||
str.append(']');
|
||||
return str.toString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2019 jMonkeyEngine
|
||||
* Copyright (c) 2009-2020 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -36,23 +36,23 @@ package com.jme3.opencl;
|
||||
* when the compilation failed.
|
||||
* The error log returned by {@link #getLog() } contains detailed information
|
||||
* where the error occurred.
|
||||
*
|
||||
* @author shaman
|
||||
*/
|
||||
public class KernelCompilationException extends OpenCLException {
|
||||
private final String log;
|
||||
|
||||
private final String log;
|
||||
|
||||
public KernelCompilationException(String msg, int errorCode, String log) {
|
||||
super(msg, errorCode);
|
||||
this.log = log;
|
||||
}
|
||||
public KernelCompilationException(String msg, int errorCode, String log) {
|
||||
super(msg, errorCode);
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
/**
|
||||
* The output of the compiler
|
||||
*
|
||||
* @return the output text
|
||||
*/
|
||||
public String getLog() {
|
||||
return log;
|
||||
}
|
||||
|
||||
public String getLog() {
|
||||
return log;
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2016 jMonkeyEngine
|
||||
* Copyright (c) 2009-2020 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -36,43 +36,42 @@ package com.jme3.opencl;
|
||||
* 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
|
||||
* to see what might cause this exception.
|
||||
*
|
||||
* @author shaman
|
||||
*/
|
||||
public class OpenCLException extends RuntimeException {
|
||||
private static final long serialVersionUID = 8471229972153694848L;
|
||||
|
||||
private final int errorCode;
|
||||
private final int errorCode;
|
||||
|
||||
/**
|
||||
* Creates a new instance of <code>OpenCLExceptionn</code> without detail
|
||||
* message.
|
||||
*/
|
||||
public OpenCLException() {
|
||||
errorCode = 0;
|
||||
}
|
||||
/**
|
||||
* Creates a new instance of <code>OpenCLExceptionn</code> without detail
|
||||
* message.
|
||||
*/
|
||||
public OpenCLException() {
|
||||
errorCode = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of <code>OpenCLExceptionn</code> with the
|
||||
* specified detail message.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public OpenCLException(String msg) {
|
||||
super(msg);
|
||||
errorCode = 0;
|
||||
}
|
||||
/**
|
||||
* Constructs an instance of <code>OpenCLExceptionn</code> with the
|
||||
* specified detail message.
|
||||
*
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public OpenCLException(String msg) {
|
||||
super(msg);
|
||||
errorCode = 0;
|
||||
}
|
||||
|
||||
public OpenCLException(String msg, int errorCode) {
|
||||
super(msg);
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
public OpenCLException(String msg, int errorCode) {
|
||||
super(msg);
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the error code
|
||||
*/
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
|
||||
public int getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2009-2019 jMonkeyEngine
|
||||
* Copyright (c) 2009-2020 jMonkeyEngine
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -50,11 +50,11 @@ public abstract class Program extends AbstractOpenCLObject {
|
||||
super(releaser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Program register() {
|
||||
super.register();
|
||||
return this;
|
||||
}
|
||||
@Override
|
||||
public Program register() {
|
||||
super.register();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds this program with the specified argument string on the specified
|
||||
@ -70,40 +70,44 @@ public abstract class Program extends AbstractOpenCLObject {
|
||||
* @throws KernelCompilationException if the compilation fails
|
||||
* @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
|
||||
*
|
||||
* @throws KernelCompilationException if the compilation fails
|
||||
*/
|
||||
public void build() throws KernelCompilationException {
|
||||
public void build() throws KernelCompilationException {
|
||||
build("", (Device[]) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the kernel with the specified name.
|
||||
*
|
||||
* @param name the name of the kernel as defined in the source code
|
||||
* @return the kernel object
|
||||
* @throws OpenCLException if the kernel was not found or some other
|
||||
* error occurred
|
||||
* @throws OpenCLException if the kernel was not found or some other error
|
||||
* occurred
|
||||
*/
|
||||
public abstract Kernel createKernel(String name);
|
||||
public abstract Kernel createKernel(String name);
|
||||
|
||||
/**
|
||||
* Creates all available kernels in this program.
|
||||
* The names of the kernels can then by queried by {@link Kernel#getName() }.
|
||||
*
|
||||
* @return an array of all kernels
|
||||
*/
|
||||
public abstract Kernel[] createAllKernels();
|
||||
public abstract Kernel[] createAllKernels();
|
||||
|
||||
/**
|
||||
* Queries a compiled binary representation of this program for a particular
|
||||
* 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.
|
||||
* This saves time.
|
||||
*
|
||||
* @param device the device from which the binaries are taken
|
||||
* @return the binaries
|
||||
* @see Context#createProgramFromBinary(java.nio.ByteBuffer, com.jme3.opencl.Device)
|
||||
*/
|
||||
public abstract ByteBuffer getBinary(Device device);
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user