From a81e907b30364b1abc2a75d446772f066fbf74ff Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Mon, 5 Jul 2010 00:10:15 +0200 Subject: finished CLSubBuffer, added junit testcase, perf improvements and cleanup. CLMemory methods contain now NIO infix for nio buffer specific queries and CL infix for memory object queries. --- test/com/jogamp/opencl/CLBufferTest.java | 70 ++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'test/com') diff --git a/test/com/jogamp/opencl/CLBufferTest.java b/test/com/jogamp/opencl/CLBufferTest.java index d0c8c2f9..f2d2d609 100644 --- a/test/com/jogamp/opencl/CLBufferTest.java +++ b/test/com/jogamp/opencl/CLBufferTest.java @@ -4,6 +4,7 @@ import com.jogamp.opencl.CLMemory.Mem; import com.jogamp.opencl.CLMemory.Map; import com.jogamp.common.nio.Buffers; import java.nio.ByteBuffer; +import java.nio.FloatBuffer; import org.junit.Test; import static org.junit.Assert.*; @@ -145,5 +146,74 @@ public class CLBufferTest { context.release(); } + + @Test + public void subBufferTest() { + + CLPlatform[] platforms = CLPlatform.listCLPlatforms(); + CLPlatform theChosenOne = null; + for (CLPlatform platform : platforms) { + if(platform.isAtLeast(CLVersion.CL_1_1)) { + theChosenOne = platform; + break; + } + } + + if(theChosenOne == null) { + out.println("aborting subBufferTest"); + return; + } + + CLContext context = CLContext.create(theChosenOne); + try{ + final int subelements = 5; + // device only + { + CLBuffer buffer = context.createBuffer(64); + + assertFalse(buffer.isSubBuffer()); + assertNotNull(buffer.getSubBuffers()); + assertTrue(buffer.getSubBuffers().isEmpty()); + + CLSubBuffer subBuffer = buffer.createSubBuffer(10, subelements); + + assertTrue(subBuffer.isSubBuffer()); + assertEquals(subelements, subBuffer.getCLSize()); + assertEquals(10, subBuffer.getOffset()); + assertEquals(10, subBuffer.getCLOffset()); + assertEquals(buffer, subBuffer.getParent()); + assertEquals(1, buffer.getSubBuffers().size()); + + subBuffer.release(); + assertEquals(0, buffer.getSubBuffers().size()); + } + + // device + direct buffer + { + CLBuffer buffer = context.createFloatBuffer(64); + assertFalse(buffer.isSubBuffer()); + assertNotNull(buffer.getSubBuffers()); + assertTrue(buffer.getSubBuffers().isEmpty()); + + CLSubBuffer subBuffer = buffer.createSubBuffer(10, subelements); + + assertTrue(subBuffer.isSubBuffer()); + assertEquals(subelements, subBuffer.getBuffer().capacity()); + assertEquals(10, subBuffer.getOffset()); + assertEquals(40, subBuffer.getCLOffset()); + assertEquals(buffer, subBuffer.getParent()); + assertEquals(1, buffer.getSubBuffers().size()); + + assertEquals(subBuffer.getCLCapacity(), subBuffer.getBuffer().capacity()); + + subBuffer.release(); + assertEquals(0, buffer.getSubBuffers().size()); + } + + }finally{ + context.release(); + } + + } } -- cgit v1.2.3