ogl_beamforming

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

Commit: 18e839563d4934253196d777b6a8b26f4df9aa20
Parent: be078df83f891b28012954efef2f25cfe3e8638f
Author: Randy Palamar
Date:   Mon,  9 Dec 2024 21:29:38 -0700

avoid flickering from unnecessary ui driven texture clears

Diffstat:
Mbeamformer.c | 23+++++++++++++++++++++++
Mbeamformer.h | 8++++++++
Mui.c | 18++++++++++--------
3 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/beamformer.c b/beamformer.c @@ -22,6 +22,29 @@ make_valid_test_dim(uv4 in) return result; } +static BeamformFrameIterator +beamform_frame_iterator(BeamformerCtx *ctx) +{ + BeamformFrameIterator result; + result.frames = ctx->beamform_frames; + result.offset = ctx->displayed_frame_index; + result.capacity = ARRAY_COUNT(ctx->beamform_frames); + result.cursor = 0; + result.needed_frames = ORONE(ctx->params->raw.output_points.w); + return result; +} + +static BeamformFrame * +frame_next(BeamformFrameIterator *bfi) +{ + BeamformFrame *result = 0; + if (bfi->cursor != bfi->needed_frames) { + u32 index = (bfi->offset - bfi->cursor++) % bfi->capacity; + result = bfi->frames + index; + } + return result; +} + static void alloc_beamform_frame(GLParams *gp, BeamformFrame *out, uv4 out_dim, u32 frame_index, s8 name) { diff --git a/beamformer.h b/beamformer.h @@ -254,6 +254,14 @@ typedef struct { b32 did_compute_this_frame; } BeamformWorkQueue; +typedef struct { + BeamformFrame *frames; + u32 capacity; + u32 offset; + u32 cursor; + u32 needed_frames; +} BeamformFrameIterator; + typedef struct BeamformerCtx { GLParams gl; diff --git a/ui.c b/ui.c @@ -617,11 +617,14 @@ ui_start_compute(BeamformerCtx *ctx) { /* NOTE: we do not allow ui to start a work if no work was previously completed */ Arena a = {0}; - beamform_work_queue_push(ctx, &a, BW_RECOMPUTE); - for (u32 i = 0; i < ARRAY_COUNT(ctx->beamform_frames); i++) { - BeamformFrame *frame = ctx->beamform_frames + i; - if (frame->dim.w && frame->textures[frame->dim.w - 1]) - glClearTexImage(frame->textures[frame->dim.w - 1], 0, GL_RED, GL_FLOAT, 0); + if (ctx->beamform_work_queue.compute_in_flight == 0) { + beamform_work_queue_push(ctx, &a, BW_RECOMPUTE); + BeamformFrameIterator bfi = beamform_frame_iterator(ctx); + for (BeamformFrame *frame = frame_next(&bfi); frame; frame = frame_next(&bfi)) { + if (frame->dim.w && frame->textures[frame->dim.w - 1]) + glClearTexImage(frame->textures[frame->dim.w - 1], 0, + GL_RED, GL_FLOAT, 0); + } } ctx->params->upload = 1; } @@ -776,7 +779,7 @@ draw_ui(BeamformerCtx *ctx, BeamformerInput *input) end_temp_arena(ui->frame_temporary_arena); ui->frame_temporary_arena = begin_temp_arena(&ui->arena_for_frame); - /* NOTE: process interactions first because the used interacted with + /* NOTE: process interactions first because the user interacted with * the ui that was presented last frame */ ui_interact(ctx, input); @@ -859,8 +862,7 @@ draw_ui(BeamformerCtx *ctx, BeamformerInput *input) if (hover_text(mouse, tick_rect, txt_colour_t + i, 1)) { f32 scale[2] = {0.5e-3, 1e-3}; f32 size_delta = GetMouseWheelMove() * scale[i]; - /* TODO: smooth scroll this? */ - if (coord_idx== 0) + if (coord_idx == 0) bp->output_min_coordinate.E[coord_idx] -= size_delta; bp->output_max_coordinate.E[coord_idx] += size_delta; if (size_delta)