ogl_beamforming

Ultrasound Beamforming Implemented with OpenGL
git clone anongit@rnpnr.xyz:ogl_beamforming.git
Log | Files | Refs | Feed | Submodules | LICENSE

Commit: 93803cff3e12a40e8ed360420fad222c6df3b764
Parent: 4759af3eb6a60f3cfc6d1db995d49f0ebb273879
Author: Randy Palamar
Date:   Fri,  6 Dec 2024 10:11:04 -0700

use X macro to simplify the addition of new shaders

Diffstat:
Mbeamformer_parameters.h | 21++++++++++++++-------
Mstatic.c | 12+++++-------
Mui.c | 10+++-------
3 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/beamformer_parameters.h b/beamformer_parameters.h @@ -1,12 +1,19 @@ /* See LICENSE for license details. */ + +/* X(enumarant, number, shader file name, needs header, pretty name) */ +#define COMPUTE_SHADERS \ + X(CUDA_DECODE, 0, "", 0, "CUDA Decoding") \ + X(CUDA_HILBERT, 1, "", 0, "CUDA Hilbert") \ + X(DAS, 2, "das", 1, "DAS") \ + X(DEMOD, 3, "demod", 1, "Demodulation") \ + X(HADAMARD, 4, "hadamard", 1, "Decoding") \ + X(MIN_MAX, 5, "min_max", 0, "Min/Max") \ + X(SUM, 6, "sum", 0, "Sum") + enum compute_shaders { - CS_CUDA_DECODE = 0, - CS_CUDA_HILBERT = 1, - CS_DAS = 2, - CS_DEMOD = 3, - CS_HADAMARD = 4, - CS_MIN_MAX = 5, - CS_SUM = 6, + #define X(e, n, s, h, pn) CS_ ##e = n, + COMPUTE_SHADERS + #undef X CS_LAST }; diff --git a/static.c b/static.c @@ -4,11 +4,9 @@ static struct { s8 path; b32 needs_header; } compute_shaders[CS_LAST] = { - [CS_HADAMARD] = {s8("Hadamard"), s8("shaders/hadamard.glsl"), 1}, - [CS_DAS] = {s8("DAS"), s8("shaders/das.glsl"), 1}, - [CS_DEMOD] = {s8("Demod"), s8("shaders/demod.glsl"), 1}, - [CS_MIN_MAX] = {s8("Min/Max"), s8("shaders/min_max.glsl"), 0}, - [CS_SUM] = {s8("Sum"), s8("shaders/sum.glsl"), 0}, + #define X(e, n, s, h, pn) [CS_##e] = {s8(#e), s8("shaders/" s ".glsl"), h}, + COMPUTE_SHADERS + #undef X }; #ifndef _DEBUG @@ -176,11 +174,11 @@ reload_shaders(BeamformerCtx *ctx, Arena a) ComputeShaderCtx *csctx = &ctx->csctx; s8 header_in_arena = push_s8(&a, s8(COMPUTE_SHADER_HEADER)); for (u32 i = 0; i < ARRAY_COUNT(csctx->programs); i++) { - if (!compute_shaders[i].path.len) + FileStats fs = os_get_file_stats((char *)compute_shaders[i].path.data); + if (fs.filesize <= 0) continue; Arena tmp = a; - FileStats fs = os_get_file_stats((char *)compute_shaders[i].path.data); s8 shader_text = os_read_file(&tmp, (char *)compute_shaders[i].path.data, fs.filesize); if (shader_text.len == -1) { stream_append_s8(&ctx->error_stream, s8("failed to read shader: ")); diff --git a/ui.c b/ui.c @@ -450,13 +450,9 @@ static void draw_debug_overlay(BeamformerCtx *ctx, Arena arena, Rect r) { static s8 labels[CS_LAST] = { - [CS_CUDA_DECODE] = s8("CUDA Decoding:"), - [CS_CUDA_HILBERT] = s8("CUDA Hilbert:"), - [CS_DAS] = s8("DAS:"), - [CS_DEMOD] = s8("Demodulation:"), - [CS_HADAMARD] = s8("Decoding:"), - [CS_MIN_MAX] = s8("Min/Max:"), - [CS_SUM] = s8("Sum:"), + #define X(e, n, s, h, pn) [CS_##e] = s8(pn ":"), + COMPUTE_SHADERS + #undef X }; BeamformerUI *ui = ctx->ui;