From 69b8e04fcc8b18da163e01413633b6525a8ad4cd Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Wed, 13 Nov 2024 10:17:40 -0500 Subject: don't share event between cl contexts --- balls.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/balls.c b/balls.c index 24f2f1a..19adc34 100644 --- a/balls.c +++ b/balls.c @@ -533,7 +533,6 @@ setKernelArgs(void) { void animate(int v) { - cl_event readEvent; int err; clock_t tstart, elapsed; unsigned int nextFrame; @@ -544,20 +543,18 @@ animate(int v) { collideBalls(); collideWalls(); - /* Copy new positions from CPU to host asynchronously. */ - err = clEnqueueReadBuffer(cpuQueue, positionsCpuBuf, CL_FALSE, 0, nBalls*2*sizeof(float), positionsHostBuf, 0, NULL, &readEvent); + display(); + + /* Copy new positions from CPU to host. */ + err = clEnqueueReadBuffer(cpuQueue, positionsCpuBuf, CL_TRUE, 0, nBalls*2*sizeof(float), positionsHostBuf, 0, NULL, NULL); if (err < 0) sysfatal("Failed to copy positions from CPU to host.\n"); - display(); - /* Copy new positions from host to GPU. */ - err = clEnqueueWriteBuffer(gpuQueue, positionsGpuBuf, CL_TRUE, 0, nBalls*2*sizeof(float), positionsHostBuf, 1, &readEvent, NULL); + err = clEnqueueWriteBuffer(gpuQueue, positionsGpuBuf, CL_TRUE, 0, nBalls*2*sizeof(float), positionsHostBuf, 0, NULL, NULL); if (err < 0) sysfatal("Failed to copy positions from host to GPU.\n"); - clReleaseEvent(readEvent); - elapsed = (clock() - tstart) / (CLOCKS_PER_SEC / MS_PER_S); nextFrame = (elapsed > FRAME_TIME_MS) ? 0 : FRAME_TIME_MS-elapsed; glutTimerFunc(nextFrame, animate, 0); -- cgit v1.2.3