diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/com/jogamp/opencl/CLCommandQueue.java | 26 | ||||
-rw-r--r-- | src/com/jogamp/opencl/CLEventList.java | 35 |
2 files changed, 51 insertions, 10 deletions
diff --git a/src/com/jogamp/opencl/CLCommandQueue.java b/src/com/jogamp/opencl/CLCommandQueue.java index 2f83464f..b97466d4 100644 --- a/src/com/jogamp/opencl/CLCommandQueue.java +++ b/src/com/jogamp/opencl/CLCommandQueue.java @@ -1351,13 +1351,16 @@ public class CLCommandQueue extends CLObject implements CLResource { */ public CLCommandQueue putWaitForEvent(CLEventList list, int index, boolean blockingWait) { - NativeSizeBuffer ids = NativeSizeBuffer.wrap(list.IDs.getBuffer().duplicate()).position(index); - - int ret = blockingWait ? cl.clWaitForEvents(1, ids) - : cl.clEnqueueWaitForEvents(ID, 1, ids); - if(ret != CL_SUCCESS) { - throw newException(ret, "can not "+ (blockingWait?"blocking": "") +" wait for event #" + index+ " in "+list); + if(blockingWait) { + list.waitForEvent(index); + }else{ + NativeSizeBuffer ids = list.getEventBuffer(index); + int ret = cl.clEnqueueWaitForEvents(ID, 1, ids); + if(ret != CL_SUCCESS) { + throw newException(ret, "can not "+ (blockingWait?"blocking": "") +" wait for event #" + index+ " in "+list); + } } + return this; } @@ -1365,10 +1368,13 @@ public class CLCommandQueue extends CLObject implements CLResource { * Calls {@native clWaitForEvents} if blockingWait equals true otherwise {@native clEnqueueWaitForEvents}. */ public CLCommandQueue putWaitForEvents(CLEventList list, boolean blockingWait) { - int ret = blockingWait ? cl.clWaitForEvents(list.size, list.IDsView) - : cl.clEnqueueWaitForEvents(ID, list.size, list.IDsView); - if(ret != CL_SUCCESS) { - throw newException(ret, "can not "+ (blockingWait?"blocking": "") +" wait for events " + list); + if(blockingWait) { + list.waitForEvents(); + }else{ + int ret = cl.clEnqueueWaitForEvents(ID, list.size, list.IDsView); + if(ret != CL_SUCCESS) { + throw newException(ret, "can not "+ (blockingWait?"blocking": "") +" wait for events " + list); + } } return this; } diff --git a/src/com/jogamp/opencl/CLEventList.java b/src/com/jogamp/opencl/CLEventList.java index 8c09f60f..53d59d41 100644 --- a/src/com/jogamp/opencl/CLEventList.java +++ b/src/com/jogamp/opencl/CLEventList.java @@ -98,6 +98,41 @@ public final class CLEventList implements CLResource, AutoCloseable, Iterable<CL events[size] = new CLEvent(context, IDs.get()); size++; } + + NativeSizeBuffer getEventBuffer(int index) { + return NativeSizeBuffer.wrap(IDs.getBuffer().duplicate()).position(index); + } + + /** + * Waits for all events in this list to occur. + * If this list is empty this method won't do anything. + */ + public void waitForEvents() { + if(size > 0) { + events[0].getPlatform().getEventBinding().clWaitForEvents(size, IDsView); + } + } + + /** + * Waits for all events of the specified region in this list to occur. + * Will throw IndexOutOfBoundsException if indices are out of bounds. + */ + public void waitForEvents(int start, int range) { + if(start+range < size || range <= 0) { + throw new IndexOutOfBoundsException("args: [start: "+start+" range: "+range+"], eventcount: "+size); + } + + NativeSizeBuffer view = getEventBuffer(start); + getEvent(start).getPlatform().getEventBinding().clWaitForEvents(range, view); + } + + /** + * Waits for the event with the given index in this list to occur. + */ + public void waitForEvent(int index) { + NativeSizeBuffer view = getEventBuffer(index); + getEvent(index).getPlatform().getEventBinding().clWaitForEvents(1, view); + } /** * Releases all CLEvents in this list. |