diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2024-11-13 10:17:40 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2024-11-13 10:17:40 -0500 |
| commit | 69b8e04fcc8b18da163e01413633b6525a8ad4cd (patch) | |
| tree | 95d246bca8af2644a7c5a13156256f58f4dc4f6c | |
| parent | 282e53f974dbfb53ba67351fcd2fa3e37258fcb2 (diff) | |
| download | balls-69b8e04fcc8b18da163e01413633b6525a8ad4cd.zip | |
don't share event between cl contexts
| -rw-r--r-- | balls.c | 13 |
1 files changed, 5 insertions, 8 deletions
@@ -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); |