ogl_beamforming

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

Commit: f1cf968138c9e14e4053a73639708c76a59b3349
Parent: 07096573cd81e79b63ec063f543b4ecf6d6e4973
Author: Randy Palamar
Date:   Mon, 17 Aug 2026 18:54:34 -0700

coherency_weighting: remove 3D dimesions in shader

The shader does not care about this at all. It just needs a 1D
number of voxels and the existing constant properties about the
total number of threads.

Diffstat:
Mbeamformer.meta | 4+---
Mbeamformer_core.c | 6++----
Mgenerated/beamformer.c | 12+++---------
Mshaders/coherency_weighting.glsl | 18+++++++-----------
4 files changed, 13 insertions(+), 27 deletions(-)

diff --git a/beamformer.meta b/beamformer.meta @@ -496,9 +496,7 @@ { [IncoherentSum U64] [Scale F32] - [OutputSizeX U32] - [OutputSizeY U32] - [OutputSizeZ U32] + [OutputVoxels U32] } } diff --git a/beamformer_core.c b/beamformer_core.c @@ -861,10 +861,8 @@ plan_compute_pipeline(BeamformerComputePlan *cp, BeamformerParameterBlock *pb, A sd->dispatch = dispatch_for_output(sd->layout, cp->output_points); BeamformerCoherencyWeightingBakeParameters *cw = &sd->bake.CoherencyWeighting; - cw->Scale = 1.0f, - cw->OutputSizeX = cp->output_points.x, - cw->OutputSizeY = cp->output_points.y, - cw->OutputSizeZ = cp->output_points.z, + cw->Scale = 1.f; + cw->OutputVoxels = cp->output_points.x * cp->output_points.y * cp->output_points.z; cw->IncoherentSum = incoherent_buffer; }break; diff --git a/generated/beamformer.c b/generated/beamformer.c @@ -235,9 +235,7 @@ typedef struct { typedef struct { u64 IncoherentSum; f32 Scale; - u32 OutputSizeX; - u32 OutputSizeY; - u32 OutputSizeZ; + u32 OutputVoxels; } BeamformerCoherencyWeightingBakeParameters; typedef struct { @@ -681,8 +679,6 @@ read_only global MetaStructMember *meta_struct_members_by_id[] = { {17, 0, 1, 0}, {8, 8, 1, 0}, {18, 12, 1, 0}, - {18, 16, 1, 0}, - {18, 20, 1, 0}, }, (MetaStructMember []){ {18, 0, 1, 0}, @@ -754,9 +750,7 @@ read_only global str8 *meta_struct_member_names_by_id[] = { (str8 []){ str8_comp("IncoherentSum"), str8_comp("Scale"), - str8_comp("OutputSizeX"), - str8_comp("OutputSizeY"), - str8_comp("OutputSizeZ"), + str8_comp("OutputVoxels"), }, (str8 []){ str8_comp("SizeX"), @@ -775,7 +769,7 @@ read_only global MetaStructInfo meta_struct_info_by_id[] = { {str8_comp("DecodeBakeParameters"), 11, 48, 0}, {str8_comp("FilterBakeParameters"), 13, 56, 0}, {str8_comp("DASBakeParameters"), 23, 100, 0}, - {str8_comp("CoherencyWeightingBakeParameters"), 5, 24, 0}, + {str8_comp("CoherencyWeightingBakeParameters"), 3, 16, 0}, {str8_comp("ReshapeBakeParameters"), 9, 36, 0}, }; diff --git a/shaders/coherency_weighting.glsl b/shaders/coherency_weighting.glsl @@ -25,17 +25,13 @@ layout(std430, buffer_reference, buffer_reference_align = 8) restrict buffer Flo #error DataKind unsupported for CoherencyWeighting #endif -u32 output_index(const u32 x, const u32 y, const u32 z) -{ - u32 result = OutputSizeX * OutputSizeY * z + OutputSizeX * y + x; - return result; -} - void main() { - uvec3 out_voxel = gl_GlobalInvocationID; - if (!all(lessThan(out_voxel, uvec3(OutputSizeX, OutputSizeY, OutputSizeZ)))) - return; - u32 index = output_index(out_voxel.x, out_voxel.y, out_voxel.z); - COHERENT_SAMPLE(index) *= Scale * COHERENT_SAMPLE(index) / INCOHERENT_SAMPLE(index); + const uvec3 total_threads = gl_WorkGroupSize * gl_NumWorkGroups; + u32 index = gl_GlobalInvocationID.z * total_threads.x * total_threads.y + + gl_GlobalInvocationID.y * total_threads.x + + gl_GlobalInvocationID.x; + + if (index < OutputVoxels) + COHERENT_SAMPLE(index) *= Scale * COHERENT_SAMPLE(index) / INCOHERENT_SAMPLE(index); }