refactor: Splitting into crates

This commit is contained in:
2026-11-15 20:36:43 +01:00
parent c13a04c8e2
commit 828806fbc8
68 changed files with 929 additions and 330 deletions
+29 -23
View File
@@ -13,18 +13,18 @@ the cache inserts them.
The durable system is:
- `src/voxel_cache.rs` and `src/voxel_cache/*` — cache API and GPU passes.
- `src/voxel_cache/shaders/*.wgsl` — runtime-specialised cache shaders.
- `src/gpu/*` — radix sort, top-K, indirect dispatch, compaction.
- `crates/vxls-voxel-cache/src/lib.rs` and `crates/vxls-voxel-cache/src/*` — cache API and GPU passes.
- `crates/vxls-voxel-cache/src/shaders/*.wgsl` — runtime-specialised cache shaders.
- `crates/vxls-gpu/src/*` — radix sort, top-K, indirect dispatch, compaction.
- `shaders/*.slang` — render-side ray marching, compiled ahead of time.
- `src/voxel_cache/tables.rs` + `src/terrain.rs` — structure tables
- `crates/vxls-voxel-cache/src/tables.rs` + `crates/vxls-terrain/src/lib.rs` — structure tables
(`FixedStructureTable`, the freelist-backed `DynamicStructureTable`, and the
shared `StructureTableCore`) and the toroidal world wrapper.
> **Temporary code:** `src/main.rs` and `src/producers.rs` are a playground/test
> **Temporary code:** `crates/vxls/src/main.rs` and `crates/vxls/src/producers.rs` are a playground/test
> harness built alongside the cache. They contain hardcoded parameters and
> blocking workarounds. Do not treat them as stable architecture, public API, or
> examples of intended concurrency. The real system is `src/voxel_cache/*` and
> examples of intended concurrency. The real system is `crates/vxls-voxel-cache/src/*` and
> `shaders/`.
## Build and run
@@ -33,11 +33,17 @@ Requirements: a **nightly** Rust toolchain (edition 2024, `generic_const_exprs`,
`float_algebraic`) and `slangc` if you modify Slang shaders.
```sh
make -C shaders # rebuild SPIR-V into shaders/out/ (checked in)
cargo run # window + egui overlay
cargo check # compile check
make -C shaders # rebuild SPIR-V into shaders/out/ (checked in)
cargo run -p vxls # window + egui overlay
cargo check --workspace # compile check for every crate
cargo test --workspace # unit tests (GPU tests need an adapter)
```
The repository is a virtual Cargo workspace: the binary lives in `crates/vxls`,
the durable engine is split across `crates/vxls-voxel-cache`, `crates/vxls-gpu`,
`crates/vxls-profiler`, `crates/vxls-production`, `crates/vxls-bvh`, and
`crates/vxls-terrain`. Use `cargo check -p <crate>` for a single crate.
SPIR-V files are embedded with `include_spirv_source!` / `include_spirv!` at
Rust compile time, so after rebuilding shaders you must also rebuild Rust.
@@ -100,16 +106,16 @@ Do not change these casually; they are contracts between Rust, WGSL, and Slang.
| Task | Start at |
|---|---|
| Change page/pointer layout | `src/voxel_cache/schema.rs`, `src/voxel_cache/shaders/cache_common.wgsl`, `src/voxel_cache/shaders/common.wgsl` |
| Add/change a cache attribute | `src/voxel_cache/layout.rs`, `src/voxel_cache/attributes.rs`, `src/voxel_cache/shaders/insertion.wgsl`, Slang `fetch_*` in `shaders/voxel.slang` |
| Change request prioritisation | `src/voxel_cache/requests.rs`, `src/gpu/top_k.rs`, `src/gpu/radix_sort.rs` |
| Change eviction | `src/voxel_cache/eviction.rs`, `src/voxel_cache/shaders/eviction.wgsl`, `src/voxel_cache/shaders/insertion.wgsl` |
| Change insertion semantics | `src/voxel_cache.rs` (`insert`), `src/voxel_cache/pipelines.rs`, `src/voxel_cache/shaders/insertion.wgsl`, `write_pointers.wgsl` |
| Change world/chunk lookup | `src/voxel_cache/tables.rs`, `src/terrain.rs`, `shaders/toroidal_structure_table.slang` |
| Add/change slot allocation or table growth | `src/voxel_cache/tables.rs` (`DynamicStructureTable`, `SlotAllocator`, `StructureTableCore`) |
| Change structure identity / anchors | `src/voxel_cache/schema.rs` (`StructureAnchor`, wire structs), `src/production/request_queue.rs`, `src/voxel_cache/tables.rs`, `src/voxel_cache/shaders/common.wgsl`, fixed-table shaders |
| Change page/pointer layout | `crates/vxls-voxel-cache/src/schema.rs`, `crates/vxls-voxel-cache/src/shaders/cache_common.wgsl`, `crates/vxls-voxel-cache/src/shaders/common.wgsl` |
| Add/change a cache attribute | `crates/vxls-voxel-cache/src/layout.rs`, `crates/vxls-voxel-cache/src/attributes.rs`, `crates/vxls-voxel-cache/src/shaders/insertion.wgsl`, Slang `fetch_*` in `shaders/voxel.slang` |
| Change request prioritisation | `crates/vxls-voxel-cache/src/requests.rs`, `crates/vxls-gpu/src/top_k.rs`, `crates/vxls-gpu/src/radix_sort.rs` |
| Change eviction | `crates/vxls-voxel-cache/src/eviction.rs`, `crates/vxls-voxel-cache/src/shaders/eviction.wgsl`, `crates/vxls-voxel-cache/src/shaders/insertion.wgsl` |
| Change insertion semantics | `crates/vxls-voxel-cache/src/lib.rs` (`insert`), `crates/vxls-voxel-cache/src/pipelines.rs`, `crates/vxls-voxel-cache/src/shaders/insertion.wgsl`, `write_pointers.wgsl` |
| Change world/chunk lookup | `crates/vxls-voxel-cache/src/tables.rs`, `crates/vxls-terrain/src/lib.rs`, `shaders/toroidal_structure_table.slang` |
| Add/change slot allocation or table growth | `crates/vxls-voxel-cache/src/tables.rs` (`DynamicStructureTable`, `SlotAllocator`, `StructureTableCore`) |
| Change structure identity / anchors | `crates/vxls-voxel-cache/src/schema.rs` (`StructureAnchor`, wire structs), `crates/vxls-production/src/request_queue.rs`, `crates/vxls-voxel-cache/src/tables.rs`, `crates/vxls-voxel-cache/src/shaders/common.wgsl`, fixed-table shaders |
| Change ray marching/LOD | `shaders/voxel.slang`, `shaders/voxel_cache.slang`, `shaders/lod_policies.slang` |
| Add a producer | `src/producers.rs` (interface), `src/main.rs` (`fullfill_request`), [`docs/pipeline-and-producers.md`](./docs/pipeline-and-producers.md) |
| Add a producer | `crates/vxls/src/producers.rs` (interface), `crates/vxls/src/main.rs` (`fullfill_request`), [`docs/pipeline-and-producers.md`](./docs/pipeline-and-producers.md) |
## Current demo configuration
@@ -138,8 +144,8 @@ The full tables live in the docs. The most important ones:
fulfilment blocks the render thread.
- **Insertion can silently drop pages** (`destination_indices == 0xFFFFFFFF`)
with no signal to the producer.
- **Several modules are not wired in:** `src/production/*`, `src/tree.rs`,
`src/host_production.rs`, and `VoxelGiPipeline`. Mark them as inactive rather
- **Several modules are not wired in:** `crates/vxls-production/src/*`,
`crates/vxls/src/host_production.rs`, and `VoxelGiPipeline`. Mark them as inactive rather
than treating them as current behaviour.
- **`gi.slang` is a stub** with legacy bindings that do not match the Rust GI
bind group.
@@ -154,11 +160,11 @@ The full tables live in the docs. The most important ones:
- **Preserve the Rust/WGSL/Slang contract.** If you change a layout, update all
three sides and the docs.
- **Measure before optimising.** Timestamp queries and the memory profiler are
already available (`src/gpu_profiler`).
already available (`crates/vxls-profiler/src`).
- **Do not "fix" dead code by assuming it is live.** Check `mod` declarations in
`src/main.rs` first.
`crates/vxls/src/main.rs` first.
- **Keep the playground separate from the engine.** New durable logic belongs in
`src/voxel_cache/*`, `src/gpu/*`, or `shaders/*`, not in `main.rs`.
`crates/vxls-voxel-cache/src/*`, `crates/vxls-gpu/src/*`, or `shaders/*`, not in `main.rs`.
- **Document discrepancies as observations.** If code and comments disagree,
state what the code does, what the comment claims, and your confidence.