ogl_beamforming

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

Commit: 8afc73936fb9b950754ad8ed7aa424666ee89013
Parent: 96d6e6d05fad59e9b19d5fd455c00c9293bdd3ec
Author: Randy Palamar
Date:   Tue,  6 May 2025 06:42:50 -0600

lib: add and check beamformer parameters version number

We don't want somebody to accidentally use an old version of the
library with a new version host or vice versa. This does mean that
we need to remember to bump the version number whenever we change
something in the parameters struct.

Diffstat:
Mbeamformer_parameters.h | 2++
Mbeamformer_work_queue.h | 3++-
Mhelpers/ogl_beamformer_lib.c | 8++++++++
Mhelpers/ogl_beamformer_lib_base.h | 21++++++++++++---------
Mstatic.c | 2++
5 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/beamformer_parameters.h b/beamformer_parameters.h @@ -7,6 +7,8 @@ * programatically would be nice. */ +#define BEAMFORMER_PARAMETERS_VERSION (1UL) + /* X(enumarant, number, shader file name, needs header, pretty name) */ #define COMPUTE_SHADERS \ X(CUDA_DECODE, 0, "", 0, "CUDA Decoding") \ diff --git a/beamformer_work_queue.h b/beamformer_work_queue.h @@ -98,9 +98,10 @@ typedef struct { i32 dispatch_compute_sync; ImagePlaneTag current_image_plane; - /* TODO(rnp): these shouldn't be needed */ + /* TODO(rnp): this shouldn't be needed */ b32 export_next_frame; + u32 version; BeamformWorkQueue external_work_queue; } BeamformerSharedMemory; diff --git a/helpers/ogl_beamformer_lib.c b/helpers/ogl_beamformer_lib.c @@ -168,6 +168,9 @@ check_shared_memory(void) result = 0; g_lib_last_error = BF_LIB_ERR_KIND_SHARED_MEMORY; } + } else if (g_bp->version != BEAMFORMER_PARAMETERS_VERSION) { + g_lib_last_error = BF_LIB_ERR_KIND_VERSION_MISMATCH; + result = 0; } return result; } @@ -188,6 +191,11 @@ lib_try_wait_sync(i32 *sync, i32 timeout_ms, os_wait_on_value_fn *os_wait_on_val return result; } +u32 +beamformer_get_api_version(void) +{ + return BEAMFORMER_PARAMETERS_VERSION; +} const char * beamformer_error_string(BeamformerLibErrorKind kind) diff --git a/helpers/ogl_beamformer_lib_base.h b/helpers/ogl_beamformer_lib_base.h @@ -7,20 +7,23 @@ #define BEAMFORMER_LIB_ERRORS \ X(NONE, 0, "None") \ - X(COMPUTE_STAGE_OVERFLOW, 1, "compute stage overflow: maximum stages: " str(MAX_COMPUTE_SHADER_STAGES)) \ - X(INVALID_COMPUTE_STAGE, 2, "invalid compute shader stage") \ - X(INVALID_IMAGE_PLANE, 3, "invalid image plane") \ - X(BUFFER_OVERFLOW, 4, "passed buffer size exceeds available space") \ - X(WORK_QUEUE_FULL, 5, "work queue full") \ - X(OPEN_EXPORT_PIPE, 6, "failed to open export pipe") \ - X(READ_EXPORT_PIPE, 7, "failed to read full export data from pipe") \ - X(SHARED_MEMORY, 8, "failed to open shared memory region") \ - X(SYNC_VARIABLE, 9, "failed to acquire lock within timeout period") + X(VERSION_MISMATCH, 1, "host-library version mismatch") \ + X(COMPUTE_STAGE_OVERFLOW, 2, "compute stage overflow: maximum stages: " str(MAX_COMPUTE_SHADER_STAGES)) \ + X(INVALID_COMPUTE_STAGE, 3, "invalid compute shader stage") \ + X(INVALID_IMAGE_PLANE, 4, "invalid image plane") \ + X(BUFFER_OVERFLOW, 5, "passed buffer size exceeds available space") \ + X(WORK_QUEUE_FULL, 6, "work queue full") \ + X(OPEN_EXPORT_PIPE, 7, "failed to open export pipe") \ + X(READ_EXPORT_PIPE, 8, "failed to read full export data from pipe") \ + X(SHARED_MEMORY, 9, "failed to open shared memory region") \ + X(SYNC_VARIABLE, 10, "failed to acquire lock within timeout period") #define X(type, num, string) BF_LIB_ERR_KIND_ ##type = num, typedef enum {BEAMFORMER_LIB_ERRORS} BeamformerLibErrorKind; #undef X +LIB_FN uint32_t beamformer_get_api_version(void); + LIB_FN BeamformerLibErrorKind beamformer_get_last_error(void); LIB_FN const char *beamformer_get_last_error_string(void); LIB_FN const char *beamformer_error_string(BeamformerLibErrorKind kind); diff --git a/static.c b/static.c @@ -327,6 +327,8 @@ setup_beamformer(BeamformerCtx *ctx, Arena *memory) if (!ctx->shared_memory) os_fatal(s8("Get more ram lol\n")); mem_clear(ctx->shared_memory, 0, sizeof(*ctx->shared_memory)); + + ctx->shared_memory->version = BEAMFORMER_PARAMETERS_VERSION; /* TODO(rnp): refactor - this is annoying */ ctx->shared_memory->parameters_sync = 1; ctx->shared_memory->parameters_head_sync = 1;