Commit: 591ed8370b13fc28bb791e4f239073b52a3840f5
Parent: 0632855794d515fc93675469b1bac2287c79fcbd
Author: Randy Palamar
Date: Thu, 3 Oct 2024 10:48:24 -0600
better handling of frame averaging over 0/1 frames
Diffstat:
2 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/beamformer.c b/beamformer.c
@@ -23,7 +23,7 @@ alloc_output_image(BeamformerCtx *ctx)
ctx->out_data_dim.x = CLAMP(round_down_power_of_2(ORONE(bp->output_points.x)), 1, max_3d_dim);
ctx->out_data_dim.y = CLAMP(round_down_power_of_2(ORONE(bp->output_points.y)), 1, max_3d_dim);
ctx->out_data_dim.z = CLAMP(round_down_power_of_2(ORONE(bp->output_points.z)), 1, max_3d_dim);
- ctx->out_data_dim.w = CLAMP(bp->output_points.w, 0, ARRAY_COUNT(cs->sum_textures));
+ ctx->out_data_dim.w = CLAMP(bp->output_points.w, 1, ARRAY_COUNT(cs->sum_textures));
bp->output_points = ctx->out_data_dim;
/* NOTE: allocate storage for beamformed output data;
@@ -39,10 +39,12 @@ alloc_output_image(BeamformerCtx *ctx)
glTexStorage3D(GL_TEXTURE_3D, ctx->out_texture_mips, GL_RG32F, odim.x, odim.y, odim.z);
glDeleteTextures(ARRAY_COUNT(cs->sum_textures), cs->sum_textures);
- glGenTextures(odim.w, cs->sum_textures);
- for (u32 i = 0; i < odim.w; i++) {
- glBindTexture(GL_TEXTURE_3D, cs->sum_textures[i]);
- glTexStorage3D(GL_TEXTURE_3D, ctx->out_texture_mips, GL_RG32F, odim.x, odim.y, odim.z);
+ if (odim.w > 1) {
+ glGenTextures(odim.w, cs->sum_textures);
+ for (u32 i = 0; i < odim.w; i++) {
+ glBindTexture(GL_TEXTURE_3D, cs->sum_textures[i]);
+ glTexStorage3D(GL_TEXTURE_3D, ctx->out_texture_mips, GL_RG32F, odim.x, odim.y, odim.z);
+ }
}
bp->array_count = CLAMP(bp->array_count, 1, ARRAY_COUNT(cs->array_textures));
@@ -277,7 +279,7 @@ do_compute_shader(BeamformerCtx *ctx, enum compute_shaders shader)
for (u32 i = 0; i < bp->array_count; i++) {
u32 texture;
if (bp->array_count == 1) {
- if (ctx->out_data_dim.w > 0) {
+ if (ctx->out_data_dim.w > 1) {
texture = csctx->sum_textures[csctx->sum_texture_index];
} else {
texture = ctx->out_texture;
@@ -300,19 +302,15 @@ do_compute_shader(BeamformerCtx *ctx, enum compute_shaders shader)
if (bp->array_count > 1) {
glUseProgram(csctx->programs[CS_SUM]);
glBindBufferBase(GL_UNIFORM_BUFFER, 0, csctx->shared_ubo);
- if (ctx->out_data_dim.w > 0) {
- do_sum_shader(csctx, csctx->array_textures, bp->array_count,
- csctx->sum_textures[csctx->sum_texture_index],
- ctx->out_data_dim);
- } else {
- do_sum_shader(csctx, csctx->array_textures, bp->array_count,
- ctx->out_texture, ctx->out_data_dim);
- }
+ u32 out;
+ if (ctx->out_data_dim.w > 1) out = csctx->sum_textures[csctx->sum_texture_index];
+ else out = ctx->out_texture;
+ do_sum_shader(csctx, csctx->array_textures, bp->array_count, out, ctx->out_data_dim);
}
} break;
case CS_SUM: {
u32 frame_count = ctx->out_data_dim.w;
- if (frame_count) {
+ if (frame_count > 1) {
do_sum_shader(csctx, csctx->sum_textures, frame_count, ctx->out_texture, ctx->out_data_dim);
csctx->sum_texture_index = (csctx->sum_texture_index + 1) % frame_count;
}
diff --git a/ui.c b/ui.c
@@ -5,8 +5,10 @@ static void
ui_start_compute(BeamformerCtx *ctx)
{
ctx->flags |= DO_COMPUTE;
- for (u32 i = 0; i < ctx->params->raw.output_points.w; i++)
- glClearTexImage(ctx->csctx.sum_textures[i], 0, GL_RED, GL_FLOAT, 0);
+ if (ctx->params->raw.output_points.w > 1) {
+ for (u32 i = 0; i < ctx->params->raw.output_points.w; i++)
+ glClearTexImage(ctx->csctx.sum_textures[i], 0, GL_RED, GL_FLOAT, 0);
+ }
ctx->params->upload = 1;
}