ogl_beamforming

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

Commit: 43593c65eb752b8f9099452176c531465c26a7c8
Parent: e5608036a5a39af2f5d24a7a3f8e9b3b0b8849f4
Author: Randy Palamar
Date:   Sun,  6 Apr 2025 21:36:52 -0600

lib: add non-flushing push_data command

Diffstat:
Mhelpers/ogl_beamformer_lib.c | 44++++++++++++++++++++++----------------------
Mhelpers/ogl_beamformer_lib.h | 3++-
2 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/helpers/ogl_beamformer_lib.c b/helpers/ogl_beamformer_lib.c @@ -288,6 +288,24 @@ BEAMFORMER_UPLOAD_FNS #undef X b32 +beamformer_push_data(char *shm_name, void *data, u32 data_size, i32 timeout_ms) +{ + b32 result = data_size <= BEAMFORMER_MAX_RF_DATA_SIZE && check_shared_memory(shm_name); + if (result) { + BeamformWork *work = beamform_work_queue_push(&g_bp->external_work_queue); + result = work && try_wait_sync(&g_bp->raw_data_sync, timeout_ms, os_wait_on_value); + if (result) { + work->type = BW_UPLOAD_RF_DATA; + work->completion_barrier = offsetof(BeamformerSharedMemory, raw_data_sync); + mem_copy((u8 *)g_bp + BEAMFORMER_RF_DATA_OFF, data, data_size); + g_bp->raw_data_size = data_size; + beamform_work_queue_push_commit(&g_bp->external_work_queue); + } + } + return result; +} + +b32 beamformer_push_parameters(char *shm_name, BeamformerParameters *bp, i32 timeout_ms) { b32 result = check_shared_memory(shm_name); @@ -323,29 +341,11 @@ set_beamformer_parameters(char *shm_name, BeamformerParametersV0 *new_bp) b32 send_data(char *pipe_name, char *shm_name, void *data, u32 data_size) { - b32 result = check_shared_memory(shm_name) && data_size <= BEAMFORMER_MAX_RF_DATA_SIZE; + b32 result = beamformer_push_data(shm_name, data, data_size, 0); if (result) { - BeamformWork *work = beamform_work_queue_push(&g_bp->external_work_queue); - if (work) { - i32 current = atomic_load(&g_bp->raw_data_sync); - if (current) { - atomic_swap(&g_bp->raw_data_sync, 0); - work->type = BW_UPLOAD_RF_DATA; - work->completion_barrier = offsetof(BeamformerSharedMemory, raw_data_sync); - mem_copy((u8 *)g_bp + BEAMFORMER_RF_DATA_OFF, data, data_size); - g_bp->raw_data_size = data_size; - - beamform_work_queue_push_commit(&g_bp->external_work_queue); - - beamformer_start_compute(shm_name, 0); - - /* TODO(rnp): set timeout on acquiring the lock instead of this */ - os_wait_on_value(&g_bp->raw_data_sync, 0, -1); - } else { - warning_msg("failed to acquire raw data lock"); - result = 0; - } - } + beamformer_start_compute(shm_name, 0); + /* TODO(rnp): should we just set timeout on acquiring the lock instead of this? */ + os_wait_on_value(&g_bp->raw_data_sync, 0, -1); } return result; } diff --git a/helpers/ogl_beamformer_lib.h b/helpers/ogl_beamformer_lib.h @@ -33,7 +33,8 @@ LIB_FN b32 beamform_data_synchronized(char *pipe_name, char *shm_name, void *dat LIB_FN b32 beamformer_start_compute(char *shm_name, u32 image_plane_tag); -/* NOTE: these functions only queue an upload; you must flush (data functions or start_compute) */ +/* NOTE: these functions only queue an upload; you must flush (old data functions or start_compute) */ +LIB_FN b32 beamformer_push_data(char *shm_name, void *data, u32 data_size, i32 timeout_ms); LIB_FN b32 beamformer_push_channel_mapping(char *shm_name, i16 *mapping, u32 count, i32 timeout_ms); LIB_FN b32 beamformer_push_sparse_elements(char *shm_name, i16 *elements, u32 count, i32 timeout_ms); LIB_FN b32 beamformer_push_focal_vectors(char *shm_name, f32 *vectors, u32 count, i32 timeout_ms);