summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-05-14 19:09:39 +0200
committerskal <pascal.massimino@gmail.com>2026-05-14 19:11:28 +0200
commit6ef8f578817ee0134fd5867ca3b80590e3eb2368 (patch)
tree5550607e5c4a16ca237bfa4430ac1ef1f5d80c5d /cmake
parent4bcbe13dab5ffb64d93cc61956f07ee5168a84c9 (diff)
ans: order-0 rANS coder + WGSL asset compression
Adds src/util/ans.{h,cc}, a per-chunk-adaptive order-0 rANS entropy coder. Decoder is always built; encoder is gated on ANS_ENABLE_ENCODER (tools only). Both sides take an optional 256-entry initial_counts table to seed the adaptive model. The per-chunk initial state is (1 << kBits). Higher initial states (e.g. with a signature packed into the upper bits) force a renorm-emit at iter 0 that the decoder never consumes, corrupting multi-chunk streams once stats become skewed. Asset pipeline: - AssetRecord gains 'compression' and 'uncompressed_size' fields. - asset_packer scans every WGSL file to build a corpus-wide byte histogram, then ANS-encodes each shader using that histogram as the seed. Histogram and accessor are emitted alongside the asset table. Round-trip verification runs at pack time for every compressed asset; failures fall back to uncompressed storage. - asset_manager decompresses on first GetAsset(), caches the heap-allocated buffer, and DropAsset / ReloadAssetsFromFile free it along with the procedural cache. - Disk-load (dev) builds are unchanged: WGSL paths stay as filenames. Tests: - src/tests/util/test_ans.cc: roundtrip variants (empty, single byte, single-symbol run, all-zeros, random uniform/skewed, repeated ASCII), seeded-vs-uniform compression, rejection of mismatched counts / corruption / truncation, PeekUncompressedSize. - 37/37 dev, 36/36 STRIP_ALL. Compression observed: WGSL shaders shrink to ~0.62-0.71x in the main workspace (81 of 105 assets qualify). Docs: - doc/ANS.md (new): algorithm, bitstream, API, asset pipeline integration, compression numbers, limitations, tests. - doc/ASSET_SYSTEM.md: new Compression section + updated technical guarantees for compressed assets. - doc/COMPLETED.md: May 2026 entry. - PROJECT_CONTEXT.md: Build status line mentions WGSL ANS compression. - CLAUDE.md, GEMINI.md: tier-3 build doc list includes ANS.md.
Diffstat (limited to 'cmake')
-rw-r--r--cmake/DemoSourceLists.cmake2
-rw-r--r--cmake/DemoTests.cmake4
-rw-r--r--cmake/DemoTools.cmake5
3 files changed, 8 insertions, 3 deletions
diff --git a/cmake/DemoSourceLists.cmake b/cmake/DemoSourceLists.cmake
index 52278ee..ef297f8 100644
--- a/cmake/DemoSourceLists.cmake
+++ b/cmake/DemoSourceLists.cmake
@@ -26,7 +26,7 @@ set(AUDIO_SOURCES
set(PROCEDURAL_SOURCES src/procedural/generator.cc)
# Utility sources (unconditional)
-set(UTIL_SOURCES src/util/asset_manager.cc src/util/file_watcher.cc)
+set(UTIL_SOURCES src/util/asset_manager.cc src/util/file_watcher.cc src/util/ans.cc)
# Common effect sources (shared between headless and normal modes)
set(COMMON_GPU_EFFECTS
diff --git a/cmake/DemoTests.cmake b/cmake/DemoTests.cmake
index 59859c5..c6d8b7d 100644
--- a/cmake/DemoTests.cmake
+++ b/cmake/DemoTests.cmake
@@ -10,6 +10,10 @@ add_demo_test(test_maths MathUtilsTest util src/tests/util/test_maths.cc)
add_demo_test(test_file_watcher FileWatcherTest util src/tests/util/test_file_watcher.cc)
target_link_libraries(test_file_watcher PRIVATE util ${DEMO_LIBS})
+add_demo_test(test_ans AnsCoderTest util src/tests/util/test_ans.cc src/util/ans.cc)
+target_compile_definitions(test_ans PRIVATE ANS_ENABLE_ENCODER)
+target_link_libraries(test_ans PRIVATE ${DEMO_LIBS})
+
add_demo_test(test_synth SynthEngineTest audio src/tests/audio/test_synth.cc ${GEN_DEMO_CC})
target_link_libraries(test_synth PRIVATE audio util procedural ${DEMO_LIBS})
demo_add_asset_deps(test_synth audio)
diff --git a/cmake/DemoTools.cmake b/cmake/DemoTools.cmake
index e83a384..d61efc1 100644
--- a/cmake/DemoTools.cmake
+++ b/cmake/DemoTools.cmake
@@ -6,9 +6,10 @@ if(DEFINED ASSET_PACKER_PATH)
set(ASSET_PACKER_CMD ${ASSET_PACKER_PATH})
set(ASSET_PACKER_DEPENDS ${ASSET_PACKER_PATH})
else()
- add_executable(asset_packer tools/asset_packer.cc)
+ add_executable(asset_packer tools/asset_packer.cc src/util/ans.cc)
+ target_compile_definitions(asset_packer PRIVATE ANS_ENABLE_ENCODER)
target_link_libraries(asset_packer PRIVATE procedural)
- target_include_directories(asset_packer PRIVATE third_party)
+ target_include_directories(asset_packer PRIVATE third_party src)
set(ASSET_PACKER_CMD $<TARGET_FILE:asset_packer>)
set(ASSET_PACKER_DEPENDS asset_packer)
endif()