Commit: ea9d5a0270e873fd7ad2e8e06f154671a291ba20
Parent: 1aa75e3d87324935b92e6470438c45af9662d46c
Author: Randy Palamar
Date: Tue, 13 Aug 2024 20:03:08 -0600
enable GL_DEBUG output and cleanup warnings
Diffstat:
2 files changed, 33 insertions(+), 7 deletions(-)
diff --git a/beamformer.c b/beamformer.c
@@ -74,7 +74,7 @@ alloc_shader_storage(BeamformerCtx *ctx, Arena a)
glBindBuffer(GL_SHADER_STORAGE_BUFFER, cs->raw_data_ssbo);
glBufferStorage(GL_SHADER_STORAGE_BUFFER, ARRAY_COUNT(cs->raw_data_fences) * rf_raw_size,
- 0, GL_DYNAMIC_STORAGE_BIT|GL_MAP_WRITE_BIT);
+ 0, GL_MAP_WRITE_BIT);
for (u32 i = 0; i < ARRAY_COUNT(cs->rf_data_ssbos); i++) {
glBindBuffer(GL_SHADER_STORAGE_BUFFER, cs->rf_data_ssbos[i]);
@@ -523,7 +523,7 @@ do_beamformer(BeamformerCtx *ctx, Arena arena)
}
/* NOTE: Store the compute time for the last frame. */
- {
+ if (ctx->csctx.timer_fence) {
i32 timer_status, _unused;
glGetSynciv(ctx->csctx.timer_fence, GL_SYNC_STATUS, 4, &_unused, &timer_status);
if (timer_status == GL_SIGNALED) {
@@ -546,11 +546,14 @@ do_beamformer(BeamformerCtx *ctx, Arena arena)
i32 raw_index = ctx->csctx.raw_data_index;
/* NOTE: if this times out it means the command queue is more than 3 frames behind.
* In that case we need to re-evaluate the buffer size */
- i32 result = glClientWaitSync(ctx->csctx.raw_data_fences[raw_index], 0, 10000);
- if (result == GL_TIMEOUT_EXPIRED) {
- //ASSERT(0);
+ if (ctx->csctx.raw_data_fences[raw_index]) {
+ i32 result = glClientWaitSync(ctx->csctx.raw_data_fences[raw_index], 0, 10000);
+ if (result == GL_TIMEOUT_EXPIRED) {
+ //ASSERT(0);
+ }
+ glDeleteSync(ctx->csctx.raw_data_fences[raw_index]);
+ ctx->csctx.raw_data_fences[raw_index] = NULL;
}
- glDeleteSync(ctx->csctx.raw_data_fences[raw_index]);
uv2 rf_raw_dim = ctx->csctx.rf_raw_dim;
size rf_raw_size = rf_raw_dim.x * rf_raw_dim.y * sizeof(i16);
diff --git a/main.c b/main.c
@@ -66,6 +66,22 @@ do_debug(void)
#endif /* _DEBUG */
+static void
+gl_debug_logger(u32 src, u32 type, u32 id, u32 lvl, i32 len, const char *msg, const void *userctx)
+{
+ (void)src; (void)type; (void)id; (void)userctx;
+ fputs("[GL DEBUG ", stderr);
+ switch (lvl) {
+ case GL_DEBUG_SEVERITY_HIGH: fputs("HIGH]: ", stderr); break;
+ case GL_DEBUG_SEVERITY_MEDIUM: fputs("MEDIUM]: ", stderr); break;
+ case GL_DEBUG_SEVERITY_LOW: fputs("LOW]: ", stderr); break;
+ case GL_DEBUG_SEVERITY_NOTIFICATION: fputs("NOTIFICATION]: ", stderr); break;
+ default: fputs("INVALID]: ", stderr); break;
+ }
+ fwrite(msg, 1, len, stderr);
+ fputc('\n', stderr);
+}
+
static u32
compile_shader(Arena a, u32 type, s8 shader)
{
@@ -169,10 +185,17 @@ main(void)
ctx.params->raw.output_points = ctx.out_data_dim;
+
+ /* NOTE: set up OpenGL debug logging */
+ glDebugMessageCallback(gl_debug_logger, NULL);
+#ifdef _DEBUG
+ glEnable(GL_DEBUG_OUTPUT);
+#endif
+
/* NOTE: allocate space for Uniform Buffer Object but don't send anything yet */
glGenBuffers(1, &ctx.csctx.shared_ubo);
glBindBuffer(GL_UNIFORM_BUFFER, ctx.csctx.shared_ubo);
- glBufferData(GL_UNIFORM_BUFFER, sizeof(BeamformerParameters), 0, GL_STATIC_DRAW);
+ glBufferStorage(GL_UNIFORM_BUFFER, sizeof(BeamformerParameters), 0, GL_MAP_WRITE_BIT);
glGenQueries(CS_LAST, ctx.csctx.timer_ids);