aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmily Leiviskä <[email protected]>2016-11-16 17:10:00 +0100
committerEmily Leiviskä <[email protected]>2016-11-16 17:10:00 +0100
commit01f69625995299262c11ae6bcbf345119c7b892f (patch)
tree9bd719adc485a6749704ffa823c8c4102eb53bed
parentcf5340c0bfc1914073ea1f4fc3ccad83f50dc57d (diff)
Changing CLBuffer#create to respect the limit instead of capacity on the direct buffer that the CLBuffer is being created for as this more closely represents the users intention about the buffer size.
-rw-r--r--src/com/jogamp/opencl/CLBuffer.java2
-rw-r--r--test/com/jogamp/opencl/CLBufferTest.java20
2 files changed, 21 insertions, 1 deletions
diff --git a/src/com/jogamp/opencl/CLBuffer.java b/src/com/jogamp/opencl/CLBuffer.java
index 065de079..81e036fc 100644
--- a/src/com/jogamp/opencl/CLBuffer.java
+++ b/src/com/jogamp/opencl/CLBuffer.java
@@ -82,7 +82,7 @@ public class CLBuffer<B extends Buffer> extends CLMemory<B> {
final CL binding = context.getPlatform().getCLBinding();
final int[] result = new int[1];
- final int size = Buffers.sizeOfBufferElem(directBuffer) * directBuffer.capacity();
+ final int size = Buffers.sizeOfBufferElem(directBuffer) * directBuffer.limit();
final long id = binding.clCreateBuffer(context.ID, flags, size, host_ptr, result, 0);
CLException.checkForError(result[0], "can not create cl buffer");
diff --git a/test/com/jogamp/opencl/CLBufferTest.java b/test/com/jogamp/opencl/CLBufferTest.java
index de71dfe1..0c6e1d11 100644
--- a/test/com/jogamp/opencl/CLBufferTest.java
+++ b/test/com/jogamp/opencl/CLBufferTest.java
@@ -65,6 +65,26 @@ 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