Commit: 0a42c2d2ed960097061dcf3508596ddebfcdddbf
Parent: 40d5ce336c21de32630b6ad427aaaf84040d9573
Author: Randy Palamar
Date: Sun, 4 May 2025 19:33:40 -0600
build/lib: construct single helper lib header
Diffstat:
5 files changed, 73 insertions(+), 54 deletions(-)
diff --git a/beamformer_parameters.h b/beamformer_parameters.h
@@ -1,4 +1,5 @@
/* See LICENSE for license details. */
+#include <stdint.h>
/* TODO(rnp):
* [ ]: Have a method for the library caller to take ownership of a "compute context"
diff --git a/build.c b/build.c
@@ -574,7 +574,27 @@ build_helper_library(Arena *arena, CommandList *cc)
if (!result) fprintf(stderr, "failed to build: %s\n", library);
/////////////
- // TODO(rnp): header
+ // header
+ char *lib_header_out = OUTPUT("ogl_beamformer_lib.h");
+
+ b32 rebuild_lib_header = needs_rebuild(lib_header_out, "beamformer_parameters.h",
+ "helpers/ogl_beamformer_lib_base.h");
+ if (rebuild_lib_header) {
+ TempArena temp = begin_temp_arena(arena);
+ s8 parameters_header = os_read_whole_file(arena, "beamformer_parameters.h");
+ s8 base_header = os_read_whole_file(arena, "helpers/ogl_beamformer_lib_base.h");
+ if (parameters_header.len != 0 && base_header.len != 0 &&
+ parameters_header.data + parameters_header.len == base_header.data)
+ {
+ s8 output_file = parameters_header;
+ output_file.len += base_header.len;
+ os_write_new_file(lib_header_out, output_file);
+ } else {
+ result = 0;
+ fprintf(stderr, "failed to build: %s\n", lib_header_out);
+ }
+ end_temp_arena(temp);
+ }
return result;
}
@@ -582,7 +602,7 @@ build_helper_library(Arena *arena, CommandList *cc)
i32
main(i32 argc, char *argv[])
{
- Arena arena = os_alloc_arena((Arena){0}, MB(2));
+ Arena arena = os_alloc_arena((Arena){0}, MB(8));
check_rebuild_self(arena, argc, argv);
Options options = parse_options(argc, argv);
diff --git a/helpers/ogl_beamformer_lib.c b/helpers/ogl_beamformer_lib.c
@@ -1,6 +1,7 @@
/* See LICENSE for license details. */
#include "../util.h"
-#include "ogl_beamformer_lib.h"
+#include "../beamformer_parameters.h"
+#include "ogl_beamformer_lib_base.h"
#include "../beamformer_work_queue.c"
#define PIPE_RETRY_PERIOD_MS (100ULL)
diff --git a/helpers/ogl_beamformer_lib.h b/helpers/ogl_beamformer_lib.h
@@ -1,51 +0,0 @@
-/* See LICENSE for license details. */
-#include <stdint.h>
-#include "../beamformer_parameters.h"
-
-#if defined(_WIN32)
-#define LIB_FN __declspec(dllexport)
-#else
-#define LIB_FN
-#endif
-
-#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")
-
-#define X(type, num, string) BF_LIB_ERR_KIND_ ##type = num,
-typedef enum {BEAMFORMER_LIB_ERRORS} BeamformerLibErrorKind;
-#undef X
-
-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);
-
-/* IMPORTANT: timeout of -1 will block forever */
-
-LIB_FN uint32_t set_beamformer_parameters(BeamformerParametersV0 *);
-LIB_FN uint32_t set_beamformer_pipeline(int32_t *stages, int32_t stages_count);
-LIB_FN uint32_t send_data(void *data, uint32_t data_size);
-/* NOTE: sends data and waits for (complex) beamformed data to be returned.
- * out_data: must be allocated by the caller as 2 floats per output point. */
-LIB_FN uint32_t beamform_data_synchronized(void *data, uint32_t data_size, uint32_t output_points[3],
- float *out_data, int32_t timeout_ms);
-
-LIB_FN uint32_t beamformer_start_compute(uint32_t image_plane_tag);
-
-/* NOTE: these functions only queue an upload; you must flush (old data functions or start_compute) */
-LIB_FN uint32_t beamformer_push_data(void *data, uint32_t size, int32_t timeout_ms);
-LIB_FN uint32_t beamformer_push_channel_mapping(int16_t *mapping, uint32_t count, int32_t timeout_ms);
-LIB_FN uint32_t beamformer_push_sparse_elements(int16_t *elements, uint32_t count, int32_t timeout_ms);
-LIB_FN uint32_t beamformer_push_focal_vectors(float *vectors, uint32_t count, int32_t timeout_ms);
-
-LIB_FN uint32_t beamformer_push_parameters(BeamformerParameters *, int32_t timeout_ms);
-LIB_FN uint32_t beamformer_push_parameters_ui(BeamformerUIParameters *, int32_t timeout_ms);
-LIB_FN uint32_t beamformer_push_parameters_head(BeamformerParametersHead *, int32_t timeout_ms);
diff --git a/helpers/ogl_beamformer_lib_base.h b/helpers/ogl_beamformer_lib_base.h
@@ -0,0 +1,48 @@
+/* See LICENSE for license details. */
+#if defined(_WIN32)
+#define LIB_FN __declspec(dllexport)
+#else
+#define LIB_FN
+#endif
+
+#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")
+
+#define X(type, num, string) BF_LIB_ERR_KIND_ ##type = num,
+typedef enum {BEAMFORMER_LIB_ERRORS} BeamformerLibErrorKind;
+#undef X
+
+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);
+
+/* IMPORTANT: timeout of -1 will block forever */
+
+LIB_FN uint32_t set_beamformer_parameters(BeamformerParametersV0 *);
+LIB_FN uint32_t set_beamformer_pipeline(int32_t *stages, int32_t stages_count);
+LIB_FN uint32_t send_data(void *data, uint32_t data_size);
+/* NOTE: sends data and waits for (complex) beamformed data to be returned.
+ * out_data: must be allocated by the caller as 2 floats per output point. */
+LIB_FN uint32_t beamform_data_synchronized(void *data, uint32_t data_size, uint32_t output_points[3],
+ float *out_data, int32_t timeout_ms);
+
+LIB_FN uint32_t beamformer_start_compute(uint32_t image_plane_tag);
+
+/* NOTE: these functions only queue an upload; you must flush (old data functions or start_compute) */
+LIB_FN uint32_t beamformer_push_data(void *data, uint32_t size, int32_t timeout_ms);
+LIB_FN uint32_t beamformer_push_channel_mapping(int16_t *mapping, uint32_t count, int32_t timeout_ms);
+LIB_FN uint32_t beamformer_push_sparse_elements(int16_t *elements, uint32_t count, int32_t timeout_ms);
+LIB_FN uint32_t beamformer_push_focal_vectors(float *vectors, uint32_t count, int32_t timeout_ms);
+
+LIB_FN uint32_t beamformer_push_parameters(BeamformerParameters *, int32_t timeout_ms);
+LIB_FN uint32_t beamformer_push_parameters_ui(BeamformerUIParameters *, int32_t timeout_ms);
+LIB_FN uint32_t beamformer_push_parameters_head(BeamformerParametersHead *, int32_t timeout_ms);