Commit: b3c9e90173f7ce8b1134d6449ca222a6d9c43c27
Parent: efd1b742e36a88a49d48cef56fe8dae05dfc0ef6
Author: Randy Palamar
Date: Tue, 11 Nov 2025 21:02:48 -0700
core: add emission kind and parameters to interface
Diffstat:
4 files changed, 100 insertions(+), 54 deletions(-)
diff --git a/beamformer.meta b/beamformer.meta
@@ -120,6 +120,12 @@
[decimation_rate U32]
}
+@Table([name c_type m_type m_size]) ParametersExtra
+{
+ [emission_kind BeamformerEmissionKind uint32 1]
+ [emission_parameters BeamformerEmissionParameters uint8 12]
+}
+
// TODO(rnp): definable constants in meta code (or at least references to enum values)
@Table([name type elements]) ParametersSimple
{
@@ -141,9 +147,22 @@
@Emit
{
+ `typedef union {`
+ ` struct {`
+ @Expand(SineParameters) ` $(%type)$(|)$(name);`
+ ` } sine;`
+ ` struct {`
+ @Expand(SineAMParameters) ` $(%type)$(|)$(name);`
+ ` } sine_am;`
+ ` struct {`
+ @Expand(ChirpParameters) ` $(%type)$(|)$(name);`
+ ` } chirp;`
+ `} BeamformerEmissionParameters;`
+ ``
`typedef struct {`
- @Expand(ParametersHead) ` $(%type)$(|)$(name);`
- @Expand(ParametersUI) ` $(%type)$(|)$(name);`
+ @Expand(ParametersHead) ` $(%type)$(|)$(name);`
+ @Expand(ParametersUI) ` $(%type)$(|)$(name);`
+ @Expand(ParametersExtra) ` $(c_type)$(|)$(name);`
`} BeamformerParameters;`
``
`typedef struct {`
@@ -155,27 +174,13 @@
`} BeamformerUIParameters;`
``
`typedef struct {`
- @Expand(ParametersHead) ` $(%type)$(|)$(name);`
- @Expand(ParametersUI) ` $(%type)$(|)$(name);`
- @Expand(ParametersSimple) ` $(%type)$(|)$(name)$(elements > 1 -> "[" elements "]");`
+ @Expand(ParametersHead) ` $(%type)$(|)$(name);`
+ @Expand(ParametersUI) ` $(%type)$(|)$(name);`
+ @Expand(ParametersExtra) ` $(c_type)$(|)$(name);`
+ @Expand(ParametersSimple) ` $(%type)$(|)$(name)$(elements > 1 -> "[" elements "]");`
`} BeamformerSimpleParameters;`
``
`typedef struct {`
- ` BeamformerEmissionKind kind;`
- ` union {`
- ` struct {`
- @Expand(SineParameters) ` $(%type)$(|)$(name);`
- ` } sine;`
- ` struct {`
- @Expand(SineAMParameters) ` $(%type)$(|)$(name);`
- ` } sine_am;`
- ` struct {`
- @Expand(ChirpParameters) ` $(%type)$(|)$(name);`
- ` } chirp;`
- ` };`
- `} BeamformerEmission;`
- ``
- `typedef struct {`
` BeamformerFilterKind kind;`
` union {`
` struct {`
@@ -307,9 +312,22 @@
@Emit(CLibrary)
{
+ `typedef union {`
+ ` struct {`
+ @Expand(SineParameters) ` $(%type)$(|)$(name);`
+ ` } sine;`
+ ` struct {`
+ @Expand(SineAMParameters) ` $(%type)$(|)$(name);`
+ ` } sine_am;`
+ ` struct {`
+ @Expand(ChirpParameters) ` $(%type)$(|)$(name);`
+ ` } chirp;`
+ `} BeamformerEmissionParameters;`
+ ``
`typedef struct {`
@Expand(ParametersHead) ` $(%type)$(|)$(name)$(#type > 1 -> "[" #type "]");`
@Expand(ParametersUI) ` $(%type)$(|)$(name)$(#type > 1 -> "[" #type "]");`
+ @Expand(ParametersExtra) ` $(c_type)$(|)$(name);`
@Expand(ParametersSimple) ` $(%type)$(|)$(name)$(elements > 1 -> "[" elements "]");`
`} BeamformerSimpleParameters;`
``
@@ -324,6 +342,7 @@
`typedef struct {`
@Expand(ParametersHead) ` $(%type)$(|)$(name)$(#type > 1 -> "[" #type "]");`
@Expand(ParametersUI) ` $(%type)$(|)$(name)$(#type > 1 -> "[" #type "]");`
+ @Expand(ParametersExtra) ` $(c_type)$(|)$(name);`
`} BeamformerParameters;`
``
}
@@ -335,9 +354,10 @@
{
`classdef OGLBeamformerParameters`
` properties`
- @Expand(ParametersHead) ` $(name)(1,$(#type))$(|)$(%type)`
+ @Expand(ParametersHead) ` $(name)(1,$(#type))$(|)$(%type)`
` % UI Parameters`
- @Expand(ParametersUI) ` $(name)(1,$(#type))$(|)$(%type)`
+ @Expand(ParametersUI) ` $(name)(1,$(#type))$(|)$(%type)`
+ @Expand(ParametersExtra) ` $(name)(1,$(m_size))$(|)$(m_type)`
` end`
`end`
}
@@ -366,6 +386,7 @@
` properties`
@Expand(ParametersHead) ` $(name)(1,$(#type)) $(%type)`
@Expand(ParametersUI) ` $(name)(1,$(#type)) $(%type)`
+ @Expand(ParametersExtra) ` $(name)(1,$(m_size))$(|)$(m_type)`
@Expand(ParametersSimple) ` $(name)(1,$(elements)) $(%type)`
` end`
`end`
diff --git a/beamformer_shared_memory.c b/beamformer_shared_memory.c
@@ -1,5 +1,5 @@
/* See LICENSE for license details. */
-#define BEAMFORMER_SHARED_MEMORY_VERSION (21UL)
+#define BEAMFORMER_SHARED_MEMORY_VERSION (22UL)
typedef struct BeamformerFrame BeamformerFrame;
diff --git a/build.c b/build.c
@@ -3339,17 +3339,13 @@ metagen_emit_helper_library_header(MetaContext *ctx, Arena arena)
meta_push_line(m, s8("// GENERATED CODE\n"));
meta_push_line(m, s8("#include <stdint.h>\n"));
- {
- iz index = meta_lookup_string_slow(ctx->enumeration_kinds.data, ctx->enumeration_kinds.count,
- s8("DataKind"));
- if (index != -1) {
- s8 enum_name = push_s8_from_parts(&m->scratch, s8(""), s8("Beamformer"), ctx->enumeration_kinds.data[index]);
- metagen_push_c_enum(m, m->scratch, enum_name, ctx->enumeration_members.data[index].data,
- ctx->enumeration_members.data[index].count);
- m->scratch = ctx->scratch;
- } else {
- build_log_failure("failed to find DataKind in meta info\n");
- }
+ /////////////////////////
+ // NOTE(rnp): enumarents
+ for (iz kind = 0; kind < ctx->enumeration_kinds.count; kind++) {
+ s8 enum_name = push_s8_from_parts(&m->scratch, s8(""), s8("Beamformer"), ctx->enumeration_kinds.data[kind]);
+ metagen_push_c_enum(m, m->scratch, enum_name, ctx->enumeration_members.data[kind].data,
+ ctx->enumeration_members.data[kind].count);
+ m->scratch = ctx->scratch;
}
{
@@ -3360,8 +3356,34 @@ metagen_emit_helper_library_header(MetaContext *ctx, Arena arena)
break;
}
}
+
if (index != -1) {
+ u64 offset = 0;
+ for (iz group = 0; group < index; group++)
+ offset += (u64)ctx->shader_groups.data[group].shaders.count;
+
MetaShaderGroup *sg = ctx->shader_groups.data + index;
+ s8 *columns[2];
+ columns[0] = push_array(&m->scratch, s8, sg->shaders.count);
+ columns[1] = push_array(&m->scratch, s8, sg->shaders.count);
+
+ Stream sb = arena_stream(m->scratch);
+ for (iz id = 0; id < sg->shaders.count; id++) {
+ stream_append_s8(&sb, s8("= "));
+ stream_append_u64(&sb, offset + (u64)id);
+
+ MetaShader *s = ctx->shaders.data + sg->shaders.data[id];
+ columns[0][id] = ctx->shader_names.data[s->name_id];
+ columns[1][id] = arena_stream_commit_and_reset(&m->scratch, &sb);
+ }
+
+ meta_begin_scope(m, s8("typedef enum {"));
+ metagen_push_table(m, m->scratch, s8("BeamformerShaderKind_"), s8(","), columns,
+ (uz)sg->shaders.count, 2);
+ meta_end_scope(m, s8("} BeamformerShaderKind;\n"));
+
+ m->scratch = ctx->scratch;
+
meta_begin_line(m, s8("#define BeamformerShaderKind_ComputeCount ("));
meta_push_u64(m, (u64)sg->shaders.count);
meta_end_line(m, s8(")\n"));
@@ -3372,6 +3394,8 @@ metagen_emit_helper_library_header(MetaContext *ctx, Arena arena)
metagen_run_emit_set(m, ctx, ctx->emit_sets + MetaEmitLang_CLibrary, meta_kind_base_c_types);
+ meta_push_line(m, s8("// END GENERATED CODE\n"));
+
meta_push(m, parameters_header, base_header);
result &= meta_write_and_reset(m, out);
diff --git a/generated/beamformer.meta.c b/generated/beamformer.meta.c
@@ -156,6 +156,23 @@ typedef struct {
u32 flags;
} BeamformerShaderBakeParameters;
+typedef union {
+ struct {
+ f32 cycles;
+ f32 frequency;
+ } sine;
+ struct {
+ f32 cycles;
+ f32 frequency;
+ u32 emissions;
+ } sine_am;
+ struct {
+ f32 duration;
+ f32 min_frequency;
+ f32 max_frequency;
+ } chirp;
+} BeamformerEmissionParameters;
+
typedef struct {
m4 xdc_transform;
v2 xdc_element_pitch;
@@ -183,6 +200,8 @@ typedef struct {
u32 coherency_weighting;
u32 beamform_plane;
u32 decimation_rate;
+ BeamformerEmissionKind emission_kind;
+ BeamformerEmissionParameters emission_parameters;
} BeamformerParameters;
typedef struct {
@@ -244,6 +263,8 @@ typedef struct {
u32 coherency_weighting;
u32 beamform_plane;
u32 decimation_rate;
+ BeamformerEmissionKind emission_kind;
+ BeamformerEmissionParameters emission_parameters;
i16 channel_mapping[256];
i16 sparse_elements[256];
u8 transmit_receive_orientations[256];
@@ -256,26 +277,6 @@ typedef struct {
} BeamformerSimpleParameters;
typedef struct {
- BeamformerEmissionKind kind;
- union {
- struct {
- f32 cycles;
- f32 frequency;
- } sine;
- struct {
- f32 cycles;
- f32 frequency;
- u32 emissions;
- } sine_am;
- struct {
- f32 duration;
- f32 min_frequency;
- f32 max_frequency;
- } chirp;
- };
-} BeamformerEmission;
-
-typedef struct {
BeamformerFilterKind kind;
union {
struct {