Commit: 33d4a44dbb556e2d81d83a0c56bb16d8fa749b2e
Parent: 1b9d11f38cb94fb5b055538b2f6471217fbbc6ad
Author: Randy Palamar
Date: Tue, 8 Apr 2025 20:34:32 -0600
das: bake uniform locations into program
Why waste space storing these at runtime. We already generate the
header anyways
Diffstat:
5 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/beamformer.c b/beamformer.c
@@ -10,8 +10,8 @@
#include "beamformer.h"
#include "beamformer_work_queue.c"
-static f32 dt_for_frame;
-static u32 cycle_t;
+global f32 dt_for_frame;
+global u32 cycle_t;
#ifndef _DEBUG
#define start_renderdoc_capture(...)
@@ -335,6 +335,8 @@ do_compute_shader(BeamformerCtx *ctx, Arena arena, BeamformComputeFrame *frame,
glBindImageTexture(1, csctx->sparse_elements_texture, 0, GL_FALSE, 0, GL_READ_ONLY, GL_R16I);
glBindImageTexture(2, csctx->focal_vectors_texture, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RG32F);
+ glUniform1ui(DAS_CYCLE_T_UNIFORM_LOC, cycle_t++);
+
#if 1
/* TODO(rnp): compute max_points_per_dispatch based on something like a
* transmit_count * channel_count product */
@@ -349,7 +351,7 @@ do_compute_shader(BeamformerCtx *ctx, Arena arena, BeamformComputeFrame *frame,
csctx->processing_progress += percent_per_step;
/* IMPORTANT(rnp): prevents OS from coalescing and killing our shader */
glFinish();
- glUniform3iv(csctx->voxel_offset_id, 1, offset.E);
+ glUniform3iv(DAS_VOXEL_OFFSET_UNIFORM_LOC, 1, offset.E);
glDispatchCompute(cursor.dispatch.x, cursor.dispatch.y, cursor.dispatch.z);
}
#else
@@ -465,6 +467,9 @@ push_compute_shader_header(Arena *a, ComputeShaderID shader)
"local_size_y = " str(DAS_LOCAL_SIZE_Y) ", "
"local_size_z = " str(DAS_LOCAL_SIZE_Z) ") "
"in;\n\n"));
+
+ push_s8(a, s8("layout(location = " str(DAS_VOXEL_OFFSET_UNIFORM_LOC) ") uniform ivec3 u_voxel_offset;\n"));
+ push_s8(a, s8("layout(location = " str(DAS_CYCLE_T_UNIFORM_LOC) ") uniform uint u_cycle_t;\n\n"));
#define X(type, id, pretty, fixed_tx) push_s8(a, s8("#define DAS_ID_" #type " " #id "\n"));
DAS_TYPES
#undef X
@@ -632,9 +637,6 @@ complete_queue(BeamformerCtx *ctx, BeamformWorkQueue *q, Arena arena, iptr gl_co
start_renderdoc_capture(gl_context);
BeamformComputeFrame *frame = work->frame;
- if (cs->programs[CS_DAS])
- glProgramUniform1ui(cs->programs[CS_DAS], cs->cycle_t_id, cycle_t++);
-
uv3 try_dim = make_valid_test_dim(bp->output_points.xyz);
if (!uv3_equal(try_dim, frame->frame.dim))
alloc_beamform_frame(&ctx->gl, &frame->frame, &frame->stats, try_dim,
diff --git a/beamformer.h b/beamformer.h
@@ -63,8 +63,6 @@ typedef struct {
#include "beamformer_parameters.h"
#define CS_UNIFORMS \
- X(CS_DAS, voxel_offset) \
- X(CS_DAS, cycle_t) \
X(CS_MIN_MAX, mips_level) \
X(CS_SUM, sum_prescale)
diff --git a/beamformer_parameters.h b/beamformer_parameters.h
@@ -52,6 +52,9 @@ typedef enum {
#define DAS_LOCAL_SIZE_Y 1
#define DAS_LOCAL_SIZE_Z 32
+#define DAS_VOXEL_OFFSET_UNIFORM_LOC 2
+#define DAS_CYCLE_T_UNIFORM_LOC 3
+
#define MAX_BEAMFORMED_SAVED_FRAMES 16
/* TODO(rnp): actually use a substruct but generate a header compatible with MATLAB */
diff --git a/shaders/das.glsl b/shaders/das.glsl
@@ -7,9 +7,6 @@ layout(rg32f, binding = 0) writeonly restrict uniform image3D u_out_data_tex;
layout(r16i, binding = 1) readonly restrict uniform iimage1D sparse_elements;
layout(rg32f, binding = 2) readonly restrict uniform image1D focal_vectors;
-layout(location = 2) uniform ivec3 u_voxel_offset;
-layout(location = 3) uniform uint u_cycle_t;
-
#define C_SPLINE 0.5
#define TX_ROWS 0
diff --git a/util.h b/util.h
@@ -37,6 +37,10 @@
#define INVALID_CODE_PATH ASSERT(0)
+#define function static
+#define global static
+#define local_persist static
+
#define static_assert _Static_assert
/* NOTE: garbage to get the prepocessor to properly stringize the value of a macro */