ogl_beamforming

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

Commit: c6f25ad89a2e480feae755d19978ccee18133dc9
Parent: c1fc9f588a69f5e27675ac95834e07010d465f28
Author: Randy Palamar
Date:   Mon, 13 Oct 2025 18:50:57 -0600

lib: fix compute timings export

size check was inverted and flush shouldn't cause a failure like
the case above

Diffstat:
Mhelpers/ogl_beamformer_lib.c | 37++++++++++++++++++-------------------
1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/helpers/ogl_beamformer_lib.c b/helpers/ogl_beamformer_lib.c @@ -550,17 +550,24 @@ beamformer_export_buffer(BeamformerExportContext export_context) } function b32 -beamformer_read_output(void *out, iz size, i32 timeout_ms) +beamformer_export(BeamformerExportContext export, void *out, i32 timeout_ms) { b32 result = 0; - if (lib_try_lock(BeamformerSharedMemoryLockKind_ExportSync, timeout_ms)) { - if (lib_try_lock(BeamformerSharedMemoryLockKind_ScratchSpace, 0)) { - Arena scratch = beamformer_shared_memory_scratch_arena(g_beamformer_library_context.bp); - mem_copy(out, scratch.beg, (uz)size); - lib_release_lock(BeamformerSharedMemoryLockKind_ScratchSpace); - result = 1; + if (beamformer_export_buffer(export)) { + /* NOTE(rnp): if this fails it just means that the work from push_data hasn't + * started yet. This is here to catch the other case where the work started + * and finished before we finished queuing the export work item */ + beamformer_flush_commands(0); + + if (lib_try_lock(BeamformerSharedMemoryLockKind_ExportSync, timeout_ms)) { + if (lib_try_lock(BeamformerSharedMemoryLockKind_ScratchSpace, 0)) { + Arena scratch = beamformer_shared_memory_scratch_arena(g_beamformer_library_context.bp); + mem_copy(out, scratch.beg, export.size); + lib_release_lock(BeamformerSharedMemoryLockKind_ScratchSpace); + result = 1; + } + lib_release_lock(BeamformerSharedMemoryLockKind_ExportSync); } - lib_release_lock(BeamformerSharedMemoryLockKind_ExportSync); } return result; } @@ -593,14 +600,7 @@ beamformer_beamform_data(BeamformerSimpleParameters *bp, void *data, uint32_t da BeamformerExportContext export; export.kind = BeamformerExportKind_BeamformedData; export.size = (u32)output_size; - if (beamformer_export_buffer(export)) { - /* NOTE(rnp): if this fails it just means that the work from push_data hasn't - * started yet. This is here to catch the other case where the work started - * and finished before we finished queuing the export work item */ - beamformer_flush_commands(0); - - result = beamformer_read_output(out_data, output_size, timeout_ms); - } + result = beamformer_export(export, out_data, timeout_ms); } } return result; @@ -615,12 +615,11 @@ beamformer_compute_timings(BeamformerComputeStatsTable *output, i32 timeout_ms) b32 result = 0; if (check_shared_memory()) { Arena scratch = beamformer_shared_memory_scratch_arena(g_beamformer_library_context.bp); - if (lib_error_check(arena_capacity(&scratch, u8) <= (iz)sizeof(*output), BF_LIB_ERR_KIND_EXPORT_SPACE_OVERFLOW)) { + if (lib_error_check((iz)sizeof(*output) <= arena_capacity(&scratch, u8), BF_LIB_ERR_KIND_EXPORT_SPACE_OVERFLOW)) { BeamformerExportContext export; export.kind = BeamformerExportKind_Stats; export.size = sizeof(*output); - if (beamformer_export_buffer(export) && beamformer_flush_commands(0)) - result = beamformer_read_output(output, sizeof(*output), timeout_ms); + result = beamformer_export(export, output, timeout_ms); } } return result;