Commit: b7df181594097003df46944043002938c9962a93
Parent: ac561658ee2e6877fdfed1c3a231b6d5be1dde12
Author: Randy Palamar
Date: Thu, 1 Oct 2026 06:22:54 -0700
base: switch read_only from attribute to const
the point of read_only is to produce a crash when someone writes
into one of these arrays/nils that was passed via a pointer. In C
this can be reliably achieved across compilers by simply using
const. In C++ you need something fancier because something might
be passed by reference and you can't simply cast the const away.
That doesn't apply here.
Diffstat:
12 files changed, 71 insertions(+), 124 deletions(-)
diff --git a/base_intrinsics.h b/base_intrinsics.h
@@ -23,6 +23,9 @@
#define force_inline __forceinline
#endif
+// NOTE(rnp): const is all that is needed for C and is compatible
+// with all major compilers. Only C++ needs extra care.
+#if 0
#if COMPILER_MSVC || (COMPILER_CLANG && OS_WINDOWS)
#pragma section(".rdata$", read)
#define read_only __declspec(allocate(".rdata$"))
@@ -33,6 +36,8 @@
* it doesn't cause a fault */
#define read_only
#endif
+#endif
+#define read_only const
#if !defined(countof)
#define countof(a) (i64)(sizeof(a) / sizeof(*a))
diff --git a/base_linux.c b/base_linux.c
@@ -182,19 +182,6 @@ os_memory_commit(void *base, u64 size)
return 1;
}
-BASE_EXPORT void
-os_memory_uncommit(void *base, u64 size)
-{
- madvise(base, size, MADV_DONTNEED);
- mprotect(base, size, PROT_NONE);
-}
-
-BASE_EXPORT void
-os_memory_seal(void *base, u64 size)
-{
- mprotect(base, size, PROT_READ);
-}
-
BASE_EXPORT str8
os_read_entire_file(Arena *arena, const char *file)
{
diff --git a/base_platform.h b/base_platform.h
@@ -61,8 +61,6 @@ BASE_EXPORT void no_return os_exit(i32 code);
BASE_EXPORT void * os_memory_reserve(u64 size);
BASE_EXPORT void os_memory_release(void *base, u64 size);
BASE_EXPORT u32 os_memory_commit(void *base, u64 size);
-BASE_EXPORT void os_memory_uncommit(void *base, u64 size);
-BASE_EXPORT void os_memory_seal(void *base, u64 size);
BASE_EXPORT u64 os_timer_count(void);
diff --git a/base_win32.c b/base_win32.c
@@ -135,7 +135,6 @@ W32(i32) WakeByAddressAll(void *);
W32(b32) WriteFile(iptr, u8 *, i32, i32 *, void *);
W32(void *) VirtualAlloc(u8 *, i64, u32, u32);
W32(b32) VirtualFree(void *, u64, u32);
-W32(b32) VirtualProtect(void *, u64, u32, u32 *);
enum {OSW32_FileWatchDirectoryBufferSize = KB(4)};
@@ -289,19 +288,6 @@ os_memory_commit(void *base, u64 size)
return result;
}
-BASE_EXPORT void
-os_memory_uncommit(void *base, u64 size)
-{
- VirtualFree(base, size, MEM_DECOMMIT);
-}
-
-BASE_EXPORT void
-os_memory_seal(void *base, u64 size)
-{
- u32 w32_dummy;
- VirtualProtect(base, size, PAGE_READONLY, &w32_dummy);
-}
-
BASE_EXPORT OSW32Semaphore
os_w32_create_semaphore(const char *name, i32 initial_count, i32 maximum_count)
{
diff --git a/beamformer_core.c b/beamformer_core.c
@@ -169,7 +169,7 @@ beamformer_panel_kind_from_string(str8 s)
function BeamformerFrame *
beamformer_frame_from_index(u64 index)
{
- BeamformerFrame *result = &beamformer_nil_frame;
+ BeamformerFrame *result = (BeamformerFrame *)&beamformer_nil_frame;
if (index < countof(beamformer_context->compute_context.backlog.frames)) {
BeamformerFrame *frame = beamformer_context->compute_context.backlog.frames + index;
if (frame->timeline_valid_value != 0)
@@ -1120,7 +1120,7 @@ stream_append_shader_header(Stream *s, i32 reloadable_index, u64 gpu_heap_pointe
"\n"));
i32 header_vector_length = beamformer_shader_header_vector_lengths[reloadable_index];
- i32 *header_vector = beamformer_shader_header_vectors[reloadable_index];
+ i32 *header_vector = (i32 *)beamformer_shader_header_vectors[reloadable_index];
for (i32 index = 0; index < header_vector_length; index++)
stream_append_str8(s, beamformer_shader_global_header_strings[header_vector[index]]);
@@ -1176,9 +1176,9 @@ stream_append_shader_header(Stream *s, i32 reloadable_index, u64 gpu_heap_pointe
i32 struct_id = beamformer_base_shader_to_bake_struct_id[reloadable_index];
if (struct_id != -1) {
- str8 *names = meta_struct_member_names_by_id[struct_id];
- MetaStructInfo *si = meta_struct_info_by_id + struct_id;
- MetaStructMember *sm = meta_struct_members_by_id[struct_id];
+ const str8 *names = meta_struct_member_names_by_id[struct_id];
+ const MetaStructInfo *si = meta_struct_info_by_id + struct_id;
+ const MetaStructMember *sm = meta_struct_members_by_id[struct_id];
for (u32 index = 0; index < si->member_count; index++) {
str8 type = meta_kind_glsl_types[sm[index].type_id];
stream_append_str8(s, str8("layout(constant_id = "));
diff --git a/build.c b/build.c
@@ -1274,7 +1274,7 @@ meta_error(void)
function void
meta_entry_print(MetaEntry *e, i32 indent, i32 caret)
{
- char *kind = meta_entry_kind_strings[e->kind];
+ const char *kind = meta_entry_kind_strings[e->kind];
if (e->kind == MetaEntryKind_BeginScope) kind = "{";
if (e->kind == MetaEntryKind_EndScope) kind = "}";
@@ -1306,7 +1306,7 @@ meta_entry_print(MetaEntry *e, i32 indent, i32 caret)
}
function i64
-meta_lookup_string_slow(str8 *strings, i64 string_count, str8 s)
+meta_lookup_string_slow(const str8 *strings, i64 string_count, str8 s)
{
// TODO(rnp): obviously this is slow
i64 result = -1;
@@ -2538,7 +2538,7 @@ meta_pack_table_begin(MetaEntry *e, MetaTable *t)
case MetaEntryKind_Flags:
{
read_only local_persist str8 enumeration_fields[] = {str8_comp("name")};
- t->fields = enumeration_fields;
+ t->fields = (str8 *)enumeration_fields;
t->field_count = countof(enumeration_fields);
}break;
@@ -2551,7 +2551,7 @@ meta_pack_table_begin(MetaEntry *e, MetaTable *t)
#define X(_i, name, ...) str8_comp(#name),
read_only local_persist str8 struct_fields[] = {META_STRUCT_FIELDS};
#undef X
- t->fields = struct_fields;
+ t->fields = (str8 *)struct_fields;
t->field_count = countof(struct_fields);
}break;
@@ -3216,7 +3216,7 @@ meta_expansion_part_conditional(MetaExpansionPart *p, u32 entry, str8 table_name
}
function void
-metagen_run_emit(MetaprogramContext *m, MetaContext *ctx, MetaEmitOperationList *ops, str8 *evaluation_table)
+metagen_run_emit(MetaprogramContext *m, MetaContext *ctx, MetaEmitOperationList *ops, const str8 *evaluation_table)
{
for (i64 opcode = 0; opcode < ops->count; opcode++) {
MetaEmitOperation *op = ops->data + opcode;
@@ -3319,7 +3319,7 @@ metagen_run_emit(MetaprogramContext *m, MetaContext *ctx, MetaEmitOperationList
function void
metagen_run_emit_set(MetaprogramContext *m, MetaContext *ctx, MetaEmitOperationListSet *emit_set,
- str8 *evaluation_table)
+ const str8 *evaluation_table)
{
for (i64 set = 0; set < emit_set->count; set++) {
MetaEmitOperationList *ops = emit_set->data + set;
@@ -3601,10 +3601,10 @@ meta_push_matlab_properties(MetaprogramContext *m, MetaContext *ctx, MetaStruct
.layout_style = MetaPushStructStyle_MATLAB,
.union_style = MetaPushStructStyle_MATLAB,
.element_count_style = MetaPushStructStyle_MATLAB,
- .base_types = meta_kind_matlab_types,
+ .base_types = (str8 *)meta_kind_matlab_types,
.suffix = str8(""),
.str_element_prefix = str8(MATLAB_NAMESPACE META_NAMESPACE_UPPER),
- .base_type_element_count_scales = meta_kind_elements,
+ .base_type_element_count_scales = (u8 *)meta_kind_elements,
});
}
}
@@ -3709,7 +3709,7 @@ meta_push_shader_reload_info(MetaprogramContext *m, MetaContext *ctx)
.layout_style = MetaPushStructStyle_C,
.union_style = MetaPushStructStyle_C,
.element_count_style = MetaPushStructStyle_C,
- .base_types = meta_kind_glsl_types,
+ .base_types = (str8 *)meta_kind_glsl_types,
.prefix = str8("\" "),
.suffix = str8(";\\n\""),
});
@@ -3719,7 +3719,7 @@ meta_push_shader_reload_info(MetaprogramContext *m, MetaContext *ctx)
.layout_style = MetaPushStructStyle_C,
.union_style = MetaPushStructStyle_C,
.element_count_style = MetaPushStructStyle_C,
- .base_types = meta_kind_glsl_types,
+ .base_types = (str8 *)meta_kind_glsl_types,
.prefix = str8("\" "),
.suffix = str8(";\\n\""),
});
@@ -3734,7 +3734,7 @@ meta_push_shader_reload_info(MetaprogramContext *m, MetaContext *ctx)
.layout_style = MetaPushStructStyle_C,
.union_style = MetaPushStructStyle_C,
.element_count_style = MetaPushStructStyle_C,
- .base_types = meta_kind_glsl_types,
+ .base_types = (str8 *)meta_kind_glsl_types,
.prefix = str8("\" "),
.suffix = str8(";\\n\""),
});
@@ -3820,7 +3820,7 @@ meta_push_shader_bake(MetaprogramContext *m, MetaContext *ctx)
meta_begin_line(m, str8("(str8 []){"));
}
- meta_push(m, str8("{.data = " META_NAMESPACE_LOWER "_shader_"));
+ meta_push(m, str8("{.data = (u8 *)" META_NAMESPACE_LOWER "_shader_"));
for (i64 i = 0; i < shader_name.length; i++)
stream_append_byte(&m->stream, ToLower(shader_name.data[i]));
@@ -3837,7 +3837,7 @@ meta_push_shader_bake(MetaprogramContext *m, MetaContext *ctx)
if (s->kind == MetaShaderKind_Render) {
meta_end_line(m, str8(","));
- meta_begin_line(m, str8("{.data = " META_NAMESPACE_LOWER "_shader_"));
+ meta_begin_line(m, str8("{.data = (u8 *)" META_NAMESPACE_LOWER "_shader_"));
for (i64 i = 0; i < shader_name.length; i++)
stream_append_byte(&m->stream, ToLower(shader_name.data[i]));
@@ -4072,7 +4072,7 @@ metagen_emit_c_code(MetaContext *ctx, Arena *arena)
.layout_style = MetaPushStructStyle_C,
.union_style = MetaPushStructStyle_C,
.element_count_style = MetaPushStructStyle_C,
- .base_types = meta_kind_c_types,
+ .base_types = (str8 *)meta_kind_c_types,
.suffix = str8(";"),
.str_element_prefix = str8(META_NAMESPACE_UPPER),
});
@@ -4727,10 +4727,10 @@ metagen_emit_helper_library_header(MetaContext *ctx, Arena *arena)
.layout_style = MetaPushStructStyle_C,
.union_style = MetaPushStructStyle_C,
.element_count_style = MetaPushStructStyle_C,
- .base_types = meta_kind_base_c_types,
+ .base_types = (str8 *)meta_kind_base_c_types,
.suffix = str8(";"),
.str_element_prefix = str8(META_NAMESPACE_UPPER),
- .base_type_element_count_scales = meta_kind_elements,
+ .base_type_element_count_scales = (u8 *)meta_kind_elements,
});
} meta_end_scope(m, str8("} " META_NAMESPACE_UPPER), ctx->entity_names.data[ids[it]], str8(";\n"));
}break;
@@ -4773,10 +4773,10 @@ metagen_emit_helper_library_header(MetaContext *ctx, Arena *arena)
.layout_style = MetaPushStructStyle_C,
.union_style = MetaPushStructStyle_MATLAB,
.element_count_style = MetaPushStructStyle_C,
- .base_types = meta_kind_base_c_types,
+ .base_types = (str8 *)meta_kind_base_c_types,
.suffix = str8(";"),
.str_element_prefix = str8(META_NAMESPACE_UPPER),
- .base_type_element_count_scales = meta_kind_elements,
+ .base_type_element_count_scales = (u8 *)meta_kind_elements,
});
} meta_end_scope(m, str8("} " META_NAMESPACE_UPPER), ctx->entity_names.data[ids[it]], str8(";\n"));
}break;
diff --git a/external/cephes.c b/external/cephes.c
@@ -7,9 +7,9 @@ Copyright 1984, 1987, 2000 by Stephen L. Moshier
* and so that it doesn't use pre-ANSI C declarations */
function f64
-cephes_chbevl(f64 x, f64 *coefficients, i32 n)
+cephes_chbevl(f64 x, const f64 *coefficients, i32 n)
{
- f64 *p = coefficients;
+ const f64 *p = coefficients;
f64 b0 = *p++, b1 = 0.0, b2;
for (i32 i = n - 1; i > 0; i--) {
diff --git a/lib/ogl_beamformer_lib.c b/lib/ogl_beamformer_lib.c
@@ -534,7 +534,7 @@ beamformer_push_data_base(void *data, u32 data_size, i32 timeout_ms, u32 block)
};
static_assert(BeamformerDataKind_Float16Complex == (BeamformerDataKind_Count - 1), "");
- read_only local_persist beamformer_reduce_a1s2_contrast_fn *reduce_a1s2_fn_table[] = {
+ local_persist beamformer_reduce_a1s2_contrast_fn *reduce_a1s2_fn_table[] = {
#define X(type, ...) beamformer_reduce_a1s2_contrast_##type,
BEAMFORMER_REDUCE_A1S2_CONTRAST_LIST
#undef X
diff --git a/math.c b/math.c
@@ -2,7 +2,7 @@
#include "external/cephes.c"
function void
-fill_kronecker_sub_matrix_f16(f16 *out, i32 out_stride, f16 scale, f16 *b, iv2 b_dim)
+fill_kronecker_sub_matrix_f16(f16 *out, i32 out_stride, f16 scale, const f16 *b, iv2 b_dim)
{
for (i32 i = 0; i < b_dim.y; i++) {
for (i32 j = 0; j < b_dim.x; j += 4, b += 4) {
@@ -17,7 +17,7 @@ fill_kronecker_sub_matrix_f16(f16 *out, i32 out_stride, f16 scale, f16 *b, iv2 b
/* NOTE: this won't check for valid space/etc and assumes row major order */
function void
-kronecker_product_f16(f16 *out, f16 *a, iv2 a_dim, f16 *b, iv2 b_dim)
+kronecker_product_f16(f16 *out, const f16 *a, iv2 a_dim, const f16 *b, iv2 b_dim)
{
iv2 out_dim = {{a_dim.x * b_dim.x, a_dim.y * b_dim.y}};
assert(out_dim.y % 4 == 0);
@@ -73,7 +73,6 @@ make_hadamard_transpose(Arena *arena, i32 dim, b32 row_major)
1, 1, -1, -1, 1, 1, -1, -1, -1, -1, 1, -1, 1, -1, 1, 1, 1, 1, -1, -1,
};
-
f16 *result = 0;
i32 order = dim;
@@ -113,7 +112,7 @@ make_hadamard_transpose(Arena *arena, i32 dim, b32 row_major)
}
#undef IND
- f16 *m2 = 0;
+ const f16 *m2 = 0;
iv2 m2_dim;
switch (base_dim) {
case 12:{ m2 = hadamard_12_12_transpose; m2_dim = (iv2){{12, 12}}; }break;
diff --git a/ui.c b/ui.c
@@ -334,7 +334,7 @@ struct V4Node {V4Node *next; v4 v;};
X(F32Node, border_thickness, f32, UI_BORDER_THICK) \
X(F32Node, text_outline_thickness, f32, 0) \
X(UINodeFlagsNode, flags, UINodeFlags, 0) \
- X(UIParentNode, parent, UINode *, (ui_context->nil_node)) \
+ X(UIParentNode, parent, UINode *, (&ui_node_nil)) \
X(UISizeNode, semantic_height, UISize, {0}) \
X(UISizeNode, semantic_width, UISize, {0}) \
X(UIAlignNode, alignment_y, UIAlign, 0) \
@@ -419,14 +419,6 @@ typedef struct {
UI_STACK_LIST
#undef X
- Arena *nil_arena;
- UINode *nil_node;
- struct {
- #define X(type, name, ...) type *name;
- UI_STACK_LIST
- #undef X
- } nil_nodes;
-
UINodeHashBucket node_hash_table[UI_HASH_TABLE_COUNT];
UITextInputState text_input_state;
@@ -459,7 +451,21 @@ typedef struct {
global BeamformerUI *ui_context;
global BeamformerInput *beamformer_input;
-#define ui_node_is_nil(n) ((n) == 0 || (n) == ui_context->nil_node)
+read_only global UINode ui_node_nil = {
+ .parent = (UINode *)&ui_node_nil,
+ .first_child = (UINode *)&ui_node_nil,
+ .last_child = (UINode *)&ui_node_nil,
+ .previous_sibling = (UINode *)&ui_node_nil,
+ .next_sibling = (UINode *)&ui_node_nil,
+};
+
+#define X(type, name, impl_type, impl) read_only global type ui_##name##_node_nil = {.v = (impl_type)impl};
+UI_STACK_LIST
+#undef X
+
+#define ui_node_is_nil(n) ((n) == 0 || (n) == &ui_node_nil)
+
+//#define ui_node_is_nil(n) ((n) == 0 || (n) == ui_context->nil_node)
#define ui_build_arena() (ui_context->build_arenas[(ui_context->current_frame_index % countof(ui_context->build_arenas))])
#define UIStackPushBody(name_upper, name_lower, type, new_value) \
@@ -474,7 +480,7 @@ global BeamformerInput *beamformer_input;
#define UIStackPopBody(name_upper, name_lower, type) \
name_upper *node = ui_context->name_lower##_node_stack.top; \
type result = node->v; \
- if (node != ui_context->nil_nodes.name_lower) { \
+ if (node != &ui_##name_lower##_node_nil) { \
node = SLLPop(ui_context->name_lower##_node_stack.top, next); \
SLLStackPush(ui_context->name_lower##_node_stack.free, node, next); \
} \
@@ -1393,7 +1399,7 @@ function UINode *
ui_node_from_key(UINodeKey key)
{
UINodeHashBucket *hb = ui_context->node_hash_table + (key.value % UI_HASH_TABLE_COUNT);
- UINode *result = ui_context->nil_node;
+ UINode *result = (UINode *)&ui_node_nil;
for (UINode *b = hb->first; !ui_node_is_nil(b); b = b->hash_next) {
if (ui_node_key_equal(b->key, key)) {
@@ -1974,14 +1980,14 @@ ui_build_node_from_key(UINodeFlags flags, UINodeKey key)
// NOTE(rnp): reassigned per frame
{
- result->parent = result->first_child = result->last_child = ui_context->nil_node;
- result->next_sibling = result->previous_sibling = ui_context->nil_node;
+ result->parent = result->first_child = result->last_child = (UINode *)&ui_node_nil;
+ result->next_sibling = result->previous_sibling = (UINode *)&ui_node_nil;
result->child_count = 0;
}
if (first_frame && !transient) {
UINodeHashBucket *hb = ui_context->node_hash_table + (key.value % UI_HASH_TABLE_COUNT);
- DLLInsert(ui_context->nil_node, hb->first, hb->last, result, hash_next, hash_prev);
+ DLLInsert((UINode *)&ui_node_nil, hb->first, hb->last, result, hash_next, hash_prev);
result->first_frame_active_index = ui_context->current_frame_index;
}
@@ -1994,7 +2000,7 @@ ui_build_node_from_key(UINodeFlags flags, UINodeKey key)
result->flags |= flags;
if (!ui_node_is_nil(result->parent)) {
- DLLInsertLast(ui_context->nil_node, result->parent->first_child, result->parent->last_child,
+ DLLInsertLast((UINode *)&ui_node_nil, result->parent->first_child, result->parent->last_child,
result, next_sibling, previous_sibling);
result->parent->child_count++;
}
@@ -3315,7 +3321,7 @@ ui_build_compute_stats(BeamformerComputePlan *cp, f32 broken_shader_t, Beamforme
if (beamformer_shader_compile_flag_counts[reloadable_index])
for EachIndex(beamformer_shader_compile_flag_counts[reloadable_index], bit) {
- str8 *flags = beamformer_shader_compile_flag_names[reloadable_index];
+ str8 *flags = (str8 *)beamformer_shader_compile_flag_names[reloadable_index];
b32 set = sd->compile_flags & (1u << bit);
UIParent(left) ui_label(flags[bit]);
UIParent(right) ui_label(push_str8_from_parts(ui_build_arena(), str8(""),
@@ -3325,9 +3331,9 @@ ui_build_compute_stats(BeamformerComputePlan *cp, f32 broken_shader_t, Beamforme
i32 struct_id = beamformer_base_shader_to_bake_struct_id[reloadable_index];
if (struct_id != -1) {
- str8 *names = meta_struct_member_names_by_id[struct_id];
- MetaStructInfo *si = meta_struct_info_by_id + struct_id;
- MetaStructMember *sm = meta_struct_members_by_id[struct_id];
+ const str8 *names = meta_struct_member_names_by_id[struct_id];
+ const MetaStructInfo *si = meta_struct_info_by_id + struct_id;
+ const MetaStructMember *sm = meta_struct_members_by_id[struct_id];
for EachIndex(si->member_count, member) {
Stream sb = arena_stream(ui_build_arena());
stream_append_struct_member(&sb, sm + member, &sd->bake);
@@ -3493,7 +3499,7 @@ ui_build_parameters_listing(BeamformerUIPanel *panel)
{str8_comp(" X:"), str8_comp(" Y:"), str8_comp(" Z:")},
{str8_comp(" Min:"), str8_comp(" Max:"), },
};
- str8 *strs = dimension == 2 ? axis_strings[1] : axis_strings[0];
+ const str8 *strs = dimension == 2 ? axis_strings[1] : axis_strings[0];
for EachIndex(value_count, it) {
UIParent(label_column) ui_labelf(" %.*s##label%u_%u",
(i32)strs[it].length, strs[it].data,
@@ -4043,7 +4049,7 @@ ui_panel_group_equip(UINode *node, BeamformerUIPanel *group)
UIPrefWidth(ui_children_sum(1.f))
for EachElement(beamformer_panel_infos, it)
{
- BeamformerPanelInfo *info = beamformer_panel_infos + it;
+ const BeamformerPanelInfo *info = beamformer_panel_infos + it;
b32 list = (info->flags & BeamformerPanelFlags_List) != 0;
b32 needs_frame = (info->flags & BeamformerPanelFlags_NeedsFrame) != 0;
if (list && (!needs_frame || beamformer_frame_valid(beamformer_registers()->frame))) {
@@ -4233,7 +4239,7 @@ ui_build_regions(UINode *root_node, BeamformerUIPanel *tree_root)
case BeamformerPanelKind_ComputeStats:{
u32 selected_plan = ui->selected_parameter_block % BeamformerMaxParameterBlocks;
BeamformerComputePlan *cp = beamformer_context->compute_context.compute_plans[selected_plan];
- if (!cp) cp = &beamformer_nil_compute_plan;
+ if (!cp) cp = (BeamformerComputePlan *)&beamformer_nil_compute_plan;
f32 t = beamformer_ui_blinker_update(&panel->u.compute_stats_broken_shader_blinker, BLINK_SPEED);
ui_build_compute_stats(cp, t, panel);
}break;
@@ -5074,27 +5080,9 @@ ui_init(BeamformerCtx *ctx, Arena *store)
ui = ui_context = ctx->ui = push_struct(store, typeof(*ui));
ui->arena = store;
- ui->nil_arena = arena_create(.commit_size = KB(4), .reserve_size = KB(16), .name = "UI Nil Arena");
- {
- ui->nil_node = push_struct(ui->nil_arena, UINode);
- *ui->nil_node = (UINode){
- .parent = ui->nil_node,
- .first_child = ui->nil_node,
- .last_child = ui->nil_node,
- .previous_sibling = ui->nil_node,
- .next_sibling = ui->nil_node,
- };
- #define X(type, name, value_type, impl, ...) \
- ui->nil_nodes.name = push_struct(ui->nil_arena, type);\
- ui->nil_nodes.name->v = (value_type)impl;
- UI_STACK_LIST
- #undef X
- }
- arena_seal(ui->nil_arena);
-
for EachElement(ui->build_arenas, it)
ui->build_arenas[it] = arena_create();
- ui->node_freelist = ui->nil_node;
+ ui->node_freelist = (UINode *)&ui_node_nil;
/* TODO(rnp): better font, this one is jank at small sizes */
ui->font = LoadFontFromMemory(".ttf", beamformer_base_font, sizeof(beamformer_base_font), 28, 0, 0);
@@ -5389,7 +5377,7 @@ beamformer_ui_frame(void)
// NOTE(rnp): reset last frame's build stacks
{
#define X(type, name, ...) \
- ui->name##_node_stack.top = ui_context->nil_nodes.name; \
+ ui->name##_node_stack.top = (type *)&ui_##name##_node_nil; \
ui->name##_node_stack.free = 0; \
ui->name##_node_stack.count = 0;
UI_STACK_LIST
@@ -5478,7 +5466,7 @@ beamformer_ui_frame(void)
if (ui_node_key_equal(ui->active_node_key[k], b->key))
ui->active_node_key[k] = ui_node_key_zero();
- DLLRemove(ui_context->nil_node, hb->first, hb->last, b, hash_next, hash_prev);
+ DLLRemove(&ui_node_nil, hb->first, hb->last, b, hash_next, hash_prev);
SLLStackPush(ui->node_freelist, b, next_sibling);
}
}
diff --git a/util.c b/util.c
@@ -187,22 +187,6 @@ arena_destroy(Arena *arena)
}
}
-function void
-arena_seal(Arena *arena)
-{
- assert(arena == arena->current);
- u64 position = round_up_to(arena->position, os_system_info()->page_size);
- if (arena->committed > position) {
- os_memory_uncommit((u8 *)arena + position, arena->committed - position);
- arena->committed = position;
- }
- if (arena->reserved > arena->committed) {
- os_memory_release((u8 *)arena + arena->committed, arena->reserved - arena->committed);
- arena->reserved = arena->committed;
- }
- os_memory_seal(arena, arena->reserved);
-}
-
#define arena_alloc(a, ...) arena_alloc_(a, (ArenaAllocateInfo){.align = 8, .count = 1, __VA_ARGS__})
#define push_array(a, t, n, ...) (t *)arena_alloc(a, .size = sizeof(t), .align = alignof(t), .count = n, __VA_ARGS__)
#define push_array_no_zero(a, t, n, ...) (t *)arena_alloc(a, .size = sizeof(t), .align = alignof(t), .count = n, .flags = ArenaAllocateFlags_NoZero, __VA_ARGS__)
@@ -649,7 +633,7 @@ stream_append_f64_e(Stream *s, f64 f)
}
function void
-stream_append_struct_member(Stream *s, MetaStructMember *m, void *struct_base)
+stream_append_struct_member(Stream *s, const MetaStructMember *m, const void *struct_base)
{
switch (m->type_id) {
InvalidDefaultCase;
diff --git a/vulkan.c b/vulkan.c
@@ -173,7 +173,7 @@ typedef struct {
i32 entity_lock;
} VulkanContext;
-read_only global const char *vk_required_instance_extensions[] = {
+read_only global char *vk_required_instance_extensions[] = {
};
#if OS_WINDOWS
@@ -604,8 +604,8 @@ function VkSpecializationMapEntry *
vk_specialization_map_from_struct_id(Arena *arena, i32 struct_id)
{
assert(struct_id >= 0);
- MetaStructInfo *si = meta_struct_info_by_id + struct_id;
- MetaStructMember *sm = meta_struct_members_by_id[struct_id];
+ const MetaStructInfo *si = meta_struct_info_by_id + struct_id;
+ const MetaStructMember *sm = meta_struct_members_by_id[struct_id];
VkSpecializationMapEntry *result = push_array(arena, VkSpecializationMapEntry, si->member_count);
for EachIndex(si->member_count, it) {
result[it].constantID = it;
@@ -648,7 +648,7 @@ vk_compute_pipeline_from_info(Arena *arena, VulkanPipelineCreateInfo *info, u32
VkSpecializationInfo specialization_info = {0};
if (info->specialization_data && info->specialization_struct_id >= 0) {
- MetaStructInfo *si = meta_struct_info_by_id + info->specialization_struct_id;
+ const MetaStructInfo *si = meta_struct_info_by_id + info->specialization_struct_id;
pipeline_create_info.stage.pSpecializationInfo = &specialization_info;
specialization_info.pMapEntries = vk_specialization_map_from_struct_id(arena, info->specialization_struct_id);
specialization_info.mapEntryCount = si->member_count;