diff options
Diffstat (limited to 'test/com/jogamp/opencl/CLBufferTest.java')
-rw-r--r-- | test/com/jogamp/opencl/CLBufferTest.java | 94 |
1 files changed, 62 insertions, 32 deletions
diff --git a/test/com/jogamp/opencl/CLBufferTest.java b/test/com/jogamp/opencl/CLBufferTest.java index 3ac1fffe..50820d4e 100644 --- a/test/com/jogamp/opencl/CLBufferTest.java +++ b/test/com/jogamp/opencl/CLBufferTest.java @@ -33,6 +33,7 @@ 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; import java.io.IOException; import java.nio.Buffer; @@ -256,7 +257,7 @@ public class CLBufferTest extends UITestCase { } @Test - public void subBufferTest() { + public void subBufferTest01ByteBuffer() { out.println(" - - - subBufferTest - - - "); if(MiscUtils.isOpenCLUnavailable()) @@ -271,48 +272,77 @@ public class CLBufferTest extends UITestCase { CLContext context = CLContext.create(platform); try{ final int subelements = 5; + final long lMaxAlignment = context.getMaxMemBaseAddrAlign(); + final int iMaxAlignment = Bitstream.uint32LongToInt(lMaxAlignment); + System.err.println("XXX: maxAlignment "+lMaxAlignment+", 0x"+Long.toHexString(lMaxAlignment)+", (int)"+iMaxAlignment+", (int)0x"+Integer.toHexString(iMaxAlignment)); + if( -1 == iMaxAlignment ) { + throw new RuntimeException("Cannot handle MaxMemBaseAddrAlign > MAX_INT, has 0x"+Long.toHexString(lMaxAlignment)); + } // device only - { - CLBuffer<?> buffer = context.createBuffer(64); + CLBuffer<?> buffer = context.createBuffer(iMaxAlignment+subelements); - assertFalse(buffer.isSubBuffer()); - assertNotNull(buffer.getSubBuffers()); - assertTrue(buffer.getSubBuffers().isEmpty()); + assertFalse(buffer.isSubBuffer()); + assertNotNull(buffer.getSubBuffers()); + assertTrue(buffer.getSubBuffers().isEmpty()); - CLSubBuffer<?> subBuffer = buffer.createSubBuffer(10, subelements); + CLSubBuffer<?> subBuffer = buffer.createSubBuffer(iMaxAlignment, 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()); + assertTrue(subBuffer.isSubBuffer()); + assertEquals(subelements, subBuffer.getCLSize()); + assertEquals(iMaxAlignment, subBuffer.getOffset()); + assertEquals(iMaxAlignment, subBuffer.getCLOffset()); + assertEquals(buffer, subBuffer.getParent()); + assertEquals(1, buffer.getSubBuffers().size()); - subBuffer.release(); - assertEquals(0, buffer.getSubBuffers().size()); - } + subBuffer.release(); + assertEquals(0, buffer.getSubBuffers().size()); + }finally{ + context.release(); + } - // device + direct buffer - { - CLBuffer<FloatBuffer> buffer = context.createFloatBuffer(64); - assertFalse(buffer.isSubBuffer()); - assertNotNull(buffer.getSubBuffers()); - assertTrue(buffer.getSubBuffers().isEmpty()); + } - CLSubBuffer<FloatBuffer> subBuffer = buffer.createSubBuffer(10, subelements); + @Test + public void subBufferTest02FloatBuffer() { - 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()); + out.println(" - - - subBufferTest - - - "); - assertEquals(subBuffer.getCLCapacity(), subBuffer.getBuffer().capacity()); + CLPlatform platform = CLPlatform.getDefault(version(CL_1_1)); + if(platform == null) { + out.println("aborting subBufferTest"); + return; + } - subBuffer.release(); - assertEquals(0, buffer.getSubBuffers().size()); + CLContext context = CLContext.create(platform); + try{ + final int subelements = 5; + final long lMaxAlignment = context.getMaxMemBaseAddrAlign(); + final int iMaxAlignment = Bitstream.uint32LongToInt(lMaxAlignment); + System.err.println("XXX: maxAlignment "+lMaxAlignment+", 0x"+Long.toHexString(lMaxAlignment)+", (int)"+iMaxAlignment+", (int)0x"+Integer.toHexString(iMaxAlignment)); + if( -1 == iMaxAlignment ) { + throw new RuntimeException("Cannot handle MaxMemBaseAddrAlign > MAX_INT, has 0x"+Long.toHexString(lMaxAlignment)); } + // FIXME: See Bug 979: Offset/Alignment via offset calculation per element-count is faulty! + final int floatsPerAlignment = iMaxAlignment / Buffers.SIZEOF_FLOAT; + // device + direct buffer + CLBuffer<FloatBuffer> buffer = context.createFloatBuffer(floatsPerAlignment+subelements); + assertFalse(buffer.isSubBuffer()); + assertNotNull(buffer.getSubBuffers()); + assertTrue(buffer.getSubBuffers().isEmpty()); + + CLSubBuffer<FloatBuffer> subBuffer = buffer.createSubBuffer(floatsPerAlignment, subelements); + + assertTrue(subBuffer.isSubBuffer()); + assertEquals(subelements, subBuffer.getBuffer().capacity()); + assertEquals(floatsPerAlignment, subBuffer.getOffset()); + assertEquals(iMaxAlignment, 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(); |