summaryrefslogtreecommitdiffstats
path: root/src/com/mbien/opencl
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2010-01-15 16:49:17 +0100
committerMichael Bien <[email protected]>2010-01-15 16:49:17 +0100
commit5193eb3c98bfa14ca8eb5767452c8e97f9f495c6 (patch)
tree7b4d6d29a0218a62ea76e9ae63c2a629a3b7c7a5 /src/com/mbien/opencl
parent64f212c105fd0f23e8116307b64ee4b87928823d (diff)
improved QueueBarrier added constructor to restrict barriers to certain queues.
temporary added getGLObjectType to CLGLContext.
Diffstat (limited to 'src/com/mbien/opencl')
-rw-r--r--src/com/mbien/opencl/CLGLContext.java38
-rw-r--r--src/com/mbien/opencl/QueueBarrier.java37
2 files changed, 74 insertions, 1 deletions
diff --git a/src/com/mbien/opencl/CLGLContext.java b/src/com/mbien/opencl/CLGLContext.java
index abfe4b05..f3edae7f 100644
--- a/src/com/mbien/opencl/CLGLContext.java
+++ b/src/com/mbien/opencl/CLGLContext.java
@@ -10,7 +10,7 @@ import java.nio.LongBuffer;
import javax.media.nativewindow.DefaultGraphicsConfiguration;
import javax.media.opengl.GLContext;
-import static com.mbien.opencl.CL.*;
+import static com.mbien.opencl.CLGLI.*;
/**
*
@@ -85,4 +85,40 @@ public final class CLGLContext extends CLContext {
buffers.add(buffer);
return buffer;
}
+
+ // TODO move somewhere else
+ public GLObjectType getGLObjectType(CLBuffer<?> buffer) {
+ int[] array = new int[1];
+ int ret = ((CLGLI)cl).clGetGLObjectInfo(buffer.ID, array, 0, null, 0);
+ CLException.checkForError(ret, "error while asking for gl object info");
+ return GLObjectType.valueOf(array[0]);
+ }
+
+ public enum GLObjectType {
+
+ GL_OBJECT_BUFFER(CL_GL_OBJECT_BUFFER),
+ GL_OBJECT_TEXTURE2D(CL_GL_OBJECT_TEXTURE2D),
+ GL_OBJECT_TEXTURE3D(CL_GL_OBJECT_TEXTURE3D),
+ GL_OBJECT_RENDERBUFFER(CL_GL_OBJECT_RENDERBUFFER);
+
+ public final int TYPE;
+
+ private GLObjectType(int type) {
+ this.TYPE = type;
+ }
+
+ public static GLObjectType valueOf(int type) {
+ if(type == CL_GL_OBJECT_BUFFER)
+ return GL_OBJECT_BUFFER;
+ else if(type == CL_GL_OBJECT_TEXTURE2D)
+ return GL_OBJECT_TEXTURE2D;
+ else if(type == CL_GL_OBJECT_TEXTURE3D)
+ return GL_OBJECT_TEXTURE3D;
+ else if(type == CL_GL_OBJECT_RENDERBUFFER)
+ return GL_OBJECT_RENDERBUFFER;
+ return null;
+ }
+ }
+
+
}
diff --git a/src/com/mbien/opencl/QueueBarrier.java b/src/com/mbien/opencl/QueueBarrier.java
index 247ede7a..d3a5ab2e 100644
--- a/src/com/mbien/opencl/QueueBarrier.java
+++ b/src/com/mbien/opencl/QueueBarrier.java
@@ -1,5 +1,8 @@
package com.mbien.opencl;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -10,9 +13,34 @@ import java.util.concurrent.TimeUnit;
public class QueueBarrier {
private final CountDownLatch latch;
+ private final Set<CLCommandQueue> queues;
public QueueBarrier(int queueCount) {
this.latch = new CountDownLatch(queueCount);
+ this.queues = null;
+ }
+
+ public QueueBarrier(CLCommandQueue... allowedQueues) {
+ this.latch = new CountDownLatch(allowedQueues.length);
+
+ HashSet<CLCommandQueue> set = new HashSet<CLCommandQueue>(allowedQueues.length);
+ for (CLCommandQueue queue : allowedQueues) {
+ set.add(queue);
+ }
+ this.queues = Collections.unmodifiableSet(set);
+ }
+
+ /**
+ * Blocks the current Thread until all commands on the CLCommandQueue finished excecution.
+ * This method may be invoked concurrently without synchronization on the QueueBarrier object
+ * as long each Thread passes a distinct CLCommandQueue as parameter to this method.
+ */
+ public QueueBarrier waitFor(CLCommandQueue queue) {
+ checkQueue(queue);
+
+ queue.putBarrier();
+ latch.countDown();
+ return this;
}
/**
@@ -21,6 +49,8 @@ public class QueueBarrier {
* as long each Thread passes a distinct CLCommandQueue as parameter to this method.
*/
public QueueBarrier waitFor(CLCommandQueue queue, CLEventList events) {
+ checkQueue(queue);
+
queue.putWaitForEvents(events);
latch.countDown();
return this;
@@ -35,6 +65,7 @@ public class QueueBarrier {
latch.await();
return this;
}
+
/**
* @see {@link #await()}
* @param timeout the maximum time to wait
@@ -45,4 +76,10 @@ public class QueueBarrier {
return this;
}
+ private final void checkQueue(CLCommandQueue queue) throws IllegalArgumentException {
+ if (queues != null && !queues.contains(queue)) {
+ throw new IllegalArgumentException(queue + " is not in the allowedQueues Set: " + queues);
+ }
+ }
+
}