Commit: af12ff47508553f07ce7c1f9785892c5248e99ad
Parent: 16c104c39dd46f04a190170a2755fd612685dafc
Author: Randy Palamar
Date: Thu, 15 Aug 2024 10:51:31 -0600
make sure there is a set of timers for each frame in flight
Diffstat:
3 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/beamformer.c b/beamformer.c
@@ -96,7 +96,7 @@ do_compute_shader(BeamformerCtx *ctx, enum compute_shaders shader)
uv2 rf_raw_dim = ctx->params->raw.rf_raw_dim;
size rf_raw_size = rf_raw_dim.x * rf_raw_dim.y * sizeof(i16);
- glBeginQuery(GL_TIME_ELAPSED, csctx->timer_ids[shader]);
+ glBeginQuery(GL_TIME_ELAPSED, csctx->timer_ids[csctx->timer_index][shader]);
glUseProgram(csctx->programs[shader]);
@@ -509,14 +509,13 @@ check_compute_timers(ComputeShaderCtx *cs)
if (!cs->timer_fences[last_idx])
return;
- i32 timer_status, _unused;
- glGetSynciv(cs->timer_fences[last_idx], GL_SYNC_STATUS, 4, &_unused, &timer_status);
- if (timer_status != GL_SIGNALED)
+ i32 status = glClientWaitSync(cs->timer_fences[last_idx], 0, 0);
+ if (status == GL_TIMEOUT_EXPIRED || status == GL_WAIT_FAILED)
return;
- for (u32 i = 0; i < ARRAY_COUNT(cs->timer_ids); i++) {
+ for (u32 i = 0; i < ARRAY_COUNT(cs->last_frame_time); i++) {
u64 ns = 0;
- glGetQueryObjectui64v(cs->timer_ids[i], GL_QUERY_RESULT, &ns);
+ glGetQueryObjectui64v(cs->timer_ids[last_idx][i], GL_QUERY_RESULT, &ns);
cs->last_frame_time[i] = (f32)ns / 1e9;
}
}
diff --git a/beamformer.h b/beamformer.h
@@ -94,12 +94,14 @@ typedef struct {
#error Unsupported Platform!
#endif
+#define MAX_FRAMES_IN_FLIGHT 3
+
typedef struct {
u32 programs[CS_LAST];
u32 timer_index;
- u32 timer_ids[CS_LAST];
- GLsync timer_fences[3];
+ u32 timer_ids[MAX_FRAMES_IN_FLIGHT][CS_LAST];
+ GLsync timer_fences[MAX_FRAMES_IN_FLIGHT];
f32 last_frame_time[CS_LAST];
/* NOTE: the raw_data_ssbo is allocated at 3x the required size to allow for tiled
@@ -108,7 +110,7 @@ typedef struct {
* for Intel or AMD and mapping the buffer is preferred. In either case incoming data can
* be written to the arena at the appropriate offset for the current raw_data_index. An
* additional BufferSubData is needed on NVIDIA to upload the data. */
- GLsync raw_data_fences[3];
+ GLsync raw_data_fences[MAX_FRAMES_IN_FLIGHT];
Arena raw_data_arena;
u32 raw_data_ssbo;
u32 raw_data_index;
diff --git a/main.c b/main.c
@@ -207,7 +207,7 @@ main(void)
glCreateBuffers(1, &ctx.csctx.shared_ubo);
glNamedBufferStorage(ctx.csctx.shared_ubo, sizeof(BeamformerParameters), 0, GL_DYNAMIC_STORAGE_BIT);
- glGenQueries(CS_LAST, ctx.csctx.timer_ids);
+ glGenQueries(ARRAY_COUNT(ctx.csctx.timer_fences) * CS_LAST, (u32 *)ctx.csctx.timer_ids);
/* NOTE: do not DO_COMPUTE on first frame */
reload_shaders(&ctx, temp_memory);