Commit: 0e231e7e6da0fc742c6cdff2443b00376b43f3ea
Parent: 194f69d32610d1f756d501da60c1b7a3aec0d791
Author: Randy Palamar
Date: Wed, 9 Oct 2024 06:42:33 -0600
use X macro for compute shader uniforms
Diffstat:
3 files changed, 17 insertions(+), 22 deletions(-)
diff --git a/beamformer.h b/beamformer.h
@@ -81,7 +81,7 @@ CUDA_DECODE_FN(cuda_decode_stub) {}
typedef CUDA_HILBERT_FN(cuda_hilbert_fn);
CUDA_HILBERT_FN(cuda_hilbert_stub) {}
-#define CUDA_LIB_FNS \
+#define CUDA_LIB_FNS \
X(cuda_decode) \
X(cuda_hilbert) \
X(init_cuda_configuration) \
@@ -103,6 +103,14 @@ typedef struct {
b32 upload;
} BeamformerParametersFull;
+#define CS_UNIFORMS \
+ X(CS_HERCULES, volume_export_dim_offset) \
+ X(CS_HERCULES, volume_export_pass) \
+ X(CS_MIN_MAX, mips_level) \
+ X(CS_SUM, sum_prescale) \
+ X(CS_UFORCES, xdc_index) \
+ X(CS_UFORCES, xdc_transform)
+
typedef struct {
u32 programs[CS_LAST];
@@ -142,13 +150,9 @@ typedef struct {
uv4 dec_data_dim;
uv2 rf_raw_dim;
- i32 mips_level_id;
- i32 volume_export_pass_id;
- i32 volume_export_dim_offset_id;
- i32 xdc_transform_id;
- i32 xdc_index_id;
-
- i32 sum_prescale_id;
+ #define X(idx, name) i32 name ## _id;
+ CS_UNIFORMS
+ #undef X
} ComputeShaderCtx;
typedef struct {
diff --git a/shaders/sum.glsl b/shaders/sum.glsl
@@ -4,11 +4,11 @@ layout(local_size_x = 32, local_size_y = 1, local_size_z = 32) in;
layout(rg32f, binding = 0) uniform image3D u_out_img;
layout(rg32f, binding = 1) readonly uniform image3D u_in_img;
-layout(location = 1) uniform float u_prescale = 1.0;
+layout(location = 1) uniform float u_sum_prescale = 1.0;
void main()
{
ivec3 voxel = ivec3(gl_GlobalInvocationID);
- vec4 sum = imageLoad(u_out_img, voxel) + u_prescale * imageLoad(u_in_img, voxel);
+ vec4 sum = imageLoad(u_out_img, voxel) + u_sum_prescale * imageLoad(u_in_img, voxel);
imageStore(u_out_img, voxel, sum);
}
diff --git a/static.c b/static.c
@@ -188,18 +188,9 @@ reload_shaders(BeamformerCtx *ctx, Arena a)
glDeleteShader(shader_id);
}
- csctx->volume_export_pass_id = glGetUniformLocation(csctx->programs[CS_HERCULES],
- "u_volume_export_pass");
- csctx->volume_export_dim_offset_id = glGetUniformLocation(csctx->programs[CS_HERCULES],
- "u_volume_export_dim_offset");
- csctx->xdc_transform_id = glGetUniformLocation(csctx->programs[CS_UFORCES],
- "u_xdc_transform");
- csctx->xdc_index_id = glGetUniformLocation(csctx->programs[CS_UFORCES],
- "u_xdc_index");
-
- csctx->mips_level_id = glGetUniformLocation(csctx->programs[CS_MIN_MAX], "u_mip_map");
-
- csctx->sum_prescale_id = glGetUniformLocation(csctx->programs[CS_SUM], "u_prescale");
+ #define X(idx, name) csctx->name##_id = glGetUniformLocation(csctx->programs[idx], "u_" #name);
+ CS_UNIFORMS
+ #undef X
Shader updated_fs = LoadShader(NULL, "shaders/render.glsl");
if (updated_fs.id != rlGetShaderIdDefault()) {