summaryrefslogtreecommitdiffstats
path: root/test/com/jogamp/opencl/CLBufferTest.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2023-07-12 01:49:31 +0200
committerSven Gothel <[email protected]>2023-07-12 01:49:31 +0200
commit791eb1b2ae3001f04d59a61f634161e21d96ef6d (patch)
tree24be59b1a6bcbbec4e09c972d461ae2fe69078b9 /test/com/jogamp/opencl/CLBufferTest.java
parentdc1424050e47cd239ad26c4f12fb3a0e4289d682 (diff)
parent2ad07a7e3e8cf1fc29fe7cbb3256c4c2cda27d02 (diff)
Merge remote-tracking branch 'wwalker/master'v2.5.0
Diffstat (limited to 'test/com/jogamp/opencl/CLBufferTest.java')
-rw-r--r--test/com/jogamp/opencl/CLBufferTest.java68
1 files changed, 67 insertions, 1 deletions
diff --git a/test/com/jogamp/opencl/CLBufferTest.java b/test/com/jogamp/opencl/CLBufferTest.java
index d5995903..0c6e1d11 100644
--- a/test/com/jogamp/opencl/CLBufferTest.java
+++ b/test/com/jogamp/opencl/CLBufferTest.java
@@ -30,7 +30,6 @@ package com.jogamp.opencl;
import com.jogamp.opencl.CLMemory.Mem;
import com.jogamp.opencl.CLMemory.Map;
-import com.jogamp.opencl.test.util.MiscUtils;
import com.jogamp.opencl.test.util.UITestCase;
import com.jogamp.common.nio.Buffers;
import com.jogamp.common.util.Bitstream;
@@ -38,6 +37,7 @@ import com.jogamp.common.util.Bitstream;
import java.io.IOException;
import java.nio.Buffer;
import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
import java.nio.DoubleBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
@@ -65,6 +65,72 @@ import static com.jogamp.opencl.CLVersion.*;
public class CLBufferTest extends UITestCase {
@Test
+ public void createBufferFromLimitedBuffer() {
+ final int elements = NUM_ELEMENTS;
+ final int padding = 19*SIZEOF_INT*2; // Totally arbitrary number > 0 divisible by 2*SIZEOF_INT
+ final CLContext context = CLContext.create();
+
+ // Make a buffer that is offset relative to the originally allocated position and has a
+ // limit that is
+ // not equal to the capacity to test whether all these attributes are correctly handled.
+ ByteBuffer byteBuffer = ByteBuffer.allocateDirect(elements*SIZEOF_INT + padding);
+ byteBuffer.position(padding / 2); // Offset the original buffer
+ IntBuffer intBuffer = byteBuffer.slice().order(ByteOrder.nativeOrder()).asIntBuffer(); // Slice it to have a new buffer that starts at the offset
+ intBuffer.limit(elements);
+
+ final CLBuffer<IntBuffer> deviceBuffer = context.createBuffer(intBuffer);
+ assertEquals(elements, deviceBuffer.getCLCapacity());
+ assertEquals(elements * SIZEOF_INT, deviceBuffer.getNIOSize());
+ assertEquals(elements, deviceBuffer.getNIOCapacity());
+ }
+
+ @Test
+ public void cloneWithLimitedBufferTest() {
+ final int elements = NUM_ELEMENTS;
+ final int padding = 312; // Arbitrary number
+ final CLContext context = CLContext.create();
+
+ final IntBuffer hostBuffer = ByteBuffer.allocateDirect((elements + padding)*SIZEOF_INT).asIntBuffer();
+ hostBuffer.limit(elements);
+
+ final CLBuffer<?> deviceBuffer = context.createBuffer(elements*SIZEOF_INT).cloneWith(hostBuffer);
+ assertEquals(elements, deviceBuffer.getCLCapacity());
+ assertEquals(elements*SIZEOF_INT, deviceBuffer.getNIOSize());
+ assertEquals(elements, deviceBuffer.getNIOCapacity());
+
+ context.release();
+ }
+
+ @Test
+ public void copyLimitedSlicedBuffersTest() {
+ final int size = 4200*SIZEOF_INT; // Arbitrary number that is a multiple of SIZEOF_INT;
+ final int padding = 307; // Totally arbitrary number > 0
+ final CLContext context = CLContext.create();
+ final CLCommandQueue queue = context.getDevices()[0].createCommandQueue();
+
+ // Make a buffer that is offset relative to the originally allocated position and has a limit that is
+ // not equal to the capacity to test whether all these attributes are correctly handled.
+ ByteBuffer hostBuffer = ByteBuffer.allocateDirect(size + padding);
+ hostBuffer.position(padding/2); // Offset the original buffer
+ hostBuffer = hostBuffer.slice(); // Slice it to have a new buffer that starts at the offset
+ hostBuffer.limit(size);
+ hostBuffer.order(ByteOrder.nativeOrder()); // Necessary for comparisons to work later on.
+ fillBuffer(hostBuffer, 12345);
+
+ final CLBuffer<ByteBuffer> bufferA = context.createBuffer(size).cloneWith(hostBuffer);
+ final CLBuffer<ByteBuffer> bufferB = context.createByteBuffer(size);
+
+ queue.putWriteBuffer(bufferA, false)
+ .putCopyBuffer(bufferA, bufferB, bufferA.getNIOSize())
+ .putReadBuffer(bufferB, true).finish();
+
+ hostBuffer.rewind();
+ bufferB.buffer.rewind();
+ checkIfEqual(hostBuffer, bufferB.buffer, size/SIZEOF_INT);
+ context.release();
+ }
+
+ @Test
public void createBufferTest() {
out.println(" - - - highLevelTest; create buffer test - - - ");