Skip to content

Commit

Permalink
use glClientWaitSync with timeout=0 instead of glGetSynciv
Browse files Browse the repository at this point in the history
- fixes GPU stalls when transferring data from GPU to CPU
  • Loading branch information
mrDIMAS committed Aug 31, 2024
1 parent 2c38dc3 commit be4c357
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions fyrox-impl/src/renderer/framework/pixel_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,15 @@ impl<T> PixelBuffer<T> {
PixelPackData::BufferOffset(0),
);

state.gl.bind_buffer(glow::PIXEL_PACK_BUFFER, None);

self.request = Some(ReadRequest {
fence: state
.gl
.fence_sync(glow::SYNC_GPU_COMMANDS_COMPLETE, 0)
.unwrap(),
});

state.gl.bind_buffer(glow::PIXEL_PACK_BUFFER, None);

Ok(())
}
}
Expand All @@ -183,7 +183,10 @@ impl<T> PixelBuffer<T> {
let mut buffer = vec![T::default(); self.pixel_count];

unsafe {
if state.gl.get_sync_status(request.fence) == glow::SIGNALED {
// For some reason, glGetSynciv still blocks execution and produces GPU stall, ruining
// the performance. glClientWaitSync with timeout=0 does not have this issue.
let fence_state = state.gl.client_wait_sync(request.fence, 0, 0);
if fence_state != glow::TIMEOUT_EXPIRED && fence_state != glow::WAIT_FAILED {
self.read_internal(state, &mut buffer);

state.gl.delete_sync(request.fence);
Expand Down

0 comments on commit be4c357

Please sign in to comment.