summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-08-07 15:21:09 +0200
committerMichael Bien <[email protected]>2010-08-07 15:21:09 +0200
commitb32190b0b899e4806e85625e7b0d1e242fdf0f05 (patch)
tree2c375fee04e4d8b45095f1911830c09be2fb94bd /test
parent2f1035db067feef9111ac3cd28c6d1256efa9a18 (diff)
added a few CLImage junit tests.
Diffstat (limited to 'test')
-rw-r--r--test/com/jogamp/opencl/CLImageTest.java153
-rw-r--r--test/com/jogamp/opencl/HighLevelBindingTest.java30
-rw-r--r--test/com/jogamp/opencl/jogamp.pngbin0 -> 7882 bytes
3 files changed, 153 insertions, 30 deletions
diff --git a/test/com/jogamp/opencl/CLImageTest.java b/test/com/jogamp/opencl/CLImageTest.java
new file mode 100644
index 00000000..dc80b9e1
--- /dev/null
+++ b/test/com/jogamp/opencl/CLImageTest.java
@@ -0,0 +1,153 @@
+package com.jogamp.opencl;
+
+
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.nio.IntBuffer;
+import javax.imageio.ImageIO;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import static org.junit.Assert.*;
+import static java.lang.System.*;
+import static com.jogamp.common.nio.Buffers.*;
+import static com.jogamp.opencl.CLImageFormat.ChannelOrder.*;
+import static com.jogamp.opencl.CLImageFormat.ChannelType.*;
+
+/**
+ * Test testing CLImage API.
+ * @author Michael Bien
+ */
+public class CLImageTest {
+
+ private static int[] pixels;
+
+ @BeforeClass
+ public static void init() throws IOException {
+ BufferedImage bi = ImageIO.read(CLImageTest.class.getResourceAsStream("jogamp.png"));
+ pixels = new int[128*128*4];
+ bi.getData().getPixels(0, 0, 128, 128, pixels);
+ }
+
+ public CLDevice getCompatibleDevice() {
+
+ CLPlatform[] platforms = CLPlatform.listCLPlatforms();
+ for (CLPlatform platform : platforms) {
+ CLDevice[] devices = platform.listCLDevices();
+
+ for (CLDevice device : devices) {
+ if(device.isImageSupportAvailable()) {
+ return device;
+ }
+ }
+ }
+
+ return null;
+ }
+
+
+ @Test
+ public void supportedImageFormatsTest() {
+ CLDevice device = getCompatibleDevice();
+ if(device == null) {
+ out.println("WARNING: can not test image api.");
+ return;
+ }
+ CLContext context = CLContext.create(device);
+
+ try{
+ CLImageFormat[] formats = context.getSupportedImage2dFormats();
+ assertTrue(formats.length > 0);
+ out.println("sample image format: "+formats[0]);
+// for (CLImageFormat format : formats) {
+// out.println(format);
+// }
+ }finally{
+ context.release();
+ }
+
+ }
+
+ @Test
+ public void image2dCopyTest() throws IOException {
+
+ CLDevice device = getCompatibleDevice();
+ if(device == null) {
+ out.println("WARNING: can not test image api.");
+ return;
+ }
+ CLContext context = CLContext.create(device);
+
+ CLCommandQueue queue = device.createCommandQueue();
+
+ try{
+
+ CLImageFormat format = new CLImageFormat(RGBA, UNSIGNED_INT32);
+
+ CLImage2d<IntBuffer> imageA = context.createImage2d(newDirectIntBuffer(pixels), 128, 128, format);
+ CLImage2d<IntBuffer> imageB = context.createImage2d(newDirectIntBuffer(pixels.length), 128, 128, format);
+
+ queue.putWriteImage(imageA, false)
+ .putCopyImage(imageA, imageB)
+ .putReadImage(imageB, true);
+
+ IntBuffer bufferA = imageA.getBuffer();
+ IntBuffer bufferB = imageB.getBuffer();
+
+ while(bufferA.hasRemaining()) {
+ assertEquals(bufferA.get(), bufferB.get());
+ }
+
+ }finally{
+ context.release();
+ }
+
+ }
+
+ @Test
+ public void image2dKernelCopyTest() throws IOException {
+
+ CLDevice device = getCompatibleDevice();
+ if(device == null) {
+ out.println("WARNING: can not test image api.");
+ return;
+ }
+ CLContext context = CLContext.create(device);
+
+ String src =
+ "constant sampler_t imageSampler = CLK_NORMALIZED_COORDS_FALSE | CLK_ADDRESS_CLAMP | CLK_FILTER_NEAREST; \n" +
+ "kernel void image2dCopy(read_only image2d_t input, write_only image2d_t output) { \n" +
+ " int2 coord = (int2)(get_global_id(0), get_global_id(1)); \n" +
+ " uint4 temp = read_imageui(input, imageSampler, coord); \n" +
+ " write_imageui(output, coord, temp); \n" +
+ "} \n";
+
+ CLKernel kernel = context.createProgram(src).build().createCLKernel("image2dCopy");
+
+ CLCommandQueue queue = device.createCommandQueue();
+
+ try{
+
+ CLImageFormat format = new CLImageFormat(RGBA, UNSIGNED_INT32);
+
+ CLImage2d<IntBuffer> imageA = context.createImage2d(newDirectIntBuffer(pixels), 128, 128, format);
+ CLImage2d<IntBuffer> imageB = context.createImage2d(newDirectIntBuffer(pixels.length), 128, 128, format);
+
+ kernel.putArgs(imageA, imageB);
+ queue.putWriteImage(imageA, false)
+ .put2DRangeKernel(kernel, 0, 0, 128, 128, 0, 0)
+ .putReadImage(imageB, true);
+
+ IntBuffer bufferA = imageA.getBuffer();
+ IntBuffer bufferB = imageB.getBuffer();
+
+ while(bufferA.hasRemaining()) {
+ assertEquals(bufferA.get(), bufferB.get());
+ }
+
+ }finally{
+ context.release();
+ }
+
+ }
+
+}
diff --git a/test/com/jogamp/opencl/HighLevelBindingTest.java b/test/com/jogamp/opencl/HighLevelBindingTest.java
index 884e22ee..e927f1fa 100644
--- a/test/com/jogamp/opencl/HighLevelBindingTest.java
+++ b/test/com/jogamp/opencl/HighLevelBindingTest.java
@@ -321,35 +321,5 @@ public class HighLevelBindingTest {
context.release();
}
-
- @Test
- public void supportedImageFormatsTest() {
-
- CLDevice[] devices = CLPlatform.getDefault().listCLDevices();
-
- CLDevice theChosenOne = null;
- for (CLDevice device : devices) {
- if(device.isImageSupportAvailable()) {
- theChosenOne = device;
- break;
- }
- }
-
- if(theChosenOne == null) {
- out.println("can not test image api.");
- return;
- }
-
- CLContext context = CLContext.create(theChosenOne);
-
- try{
- CLImageFormat[] formats = context.getSupportedImage2dFormats();
- assertTrue(formats.length > 0);
- out.println("sample image format: "+formats[0]);
- }finally{
- context.release();
- }
-
- }
}
diff --git a/test/com/jogamp/opencl/jogamp.png b/test/com/jogamp/opencl/jogamp.png
new file mode 100644
index 00000000..0a1d4901
--- /dev/null
+++ b/test/com/jogamp/opencl/jogamp.png
Binary files differ