radbin: compress sections wide, deduplicate work

This commit is contained in:
Ryan Fleury
2025-10-13 13:07:37 -07:00
parent ec39cefc9e
commit b688c69f13
2 changed files with 22 additions and 10 deletions
+10 -5
View File
@@ -775,7 +775,7 @@ rb_thread_entry_point(void *p)
//- rjf: bake
RDIM_BakeResults bake_results = {0};
if(convert_done) ProfScope("bake")
ProfScope("bake")
{
bake_results = rdim_bake(arena, bake_params);
}
@@ -789,14 +789,19 @@ rb_thread_entry_point(void *p)
case OutputKind_RDI:
{
// rjf: serialize
RDIM_SerializedSectionBundle serialized_section_bundle = {0};
ProfScope("serialize") serialized_section_bundle = rdim_serialized_section_bundle_from_bake_results(&bake_results);
RDIM_SerializedSectionBundle *serialized_section_bundle = 0;
ProfScope("serialize") if(lane_idx() == 0)
{
serialized_section_bundle = push_array(arena, RDIM_SerializedSectionBundle, 1);
serialized_section_bundle[0] = rdim_serialized_section_bundle_from_bake_results(&bake_results);
}
lane_sync_u64(&serialized_section_bundle, 0);
// rjf: compress
RDIM_SerializedSectionBundle serialized_section_bundle__compressed = serialized_section_bundle;
RDIM_SerializedSectionBundle serialized_section_bundle__compressed = serialized_section_bundle[0];
if(cmd_line_has_flag(cmdline, str8_lit("compress"))) ProfScope("compress")
{
serialized_section_bundle__compressed = rdim_compress(arena, &serialized_section_bundle);
serialized_section_bundle__compressed = rdim_compress(arena, serialized_section_bundle);
}
// rjf: serialize
+12 -5
View File
@@ -2969,18 +2969,23 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params)
internal RDIM_SerializedSectionBundle
rdim_compress(Arena *arena, RDIM_SerializedSectionBundle *in)
{
RDIM_SerializedSectionBundle out = {0};
Temp scratch = scratch_begin(&arena, 1);
RDIM_SerializedSectionBundle out_ = {0};
RDIM_SerializedSectionBundle *out = &out_;
lane_sync_u64(&out, 0);
//- rjf: set up compression context
rr_lzb_simple_context ctx = {0};
ctx.m_tableSizeBits = 14;
ctx.m_hashTable = push_array(arena, U16, 1<<ctx.m_tableSizeBits);
ctx.m_hashTable = push_array(scratch.arena, U16, 1<<ctx.m_tableSizeBits);
//- rjf: compress, or just copy, all sections
for EachEnumVal(RDI_SectionKind, k)
Rng1U64 range = lane_range(RDI_SectionKind_COUNT);
for EachInRange(idx, range)
{
RDI_SectionKind k = (RDI_SectionKind)idx;
RDIM_SerializedSection *src = &in->sections[k];
RDIM_SerializedSection *dst = &out.sections[k];
RDIM_SerializedSection *dst = &out->sections[k];
MemoryCopyStruct(dst, src);
if(src->encoded_size != 0)
{
@@ -2991,6 +2996,8 @@ rdim_compress(Arena *arena, RDIM_SerializedSectionBundle *in)
dst->encoding = RDI_SectionEncoding_LZB;
}
}
lane_sync();
return out;
scratch_end(scratch);
return *out;
}