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
+36 -35
View File
@@ -7,10 +7,10 @@ product vision that motivates it. For implementation-level detail see:
- [`shaders.md`](./shaders.md) — Slang/WGSL shader architecture and compilation.
- [`pipeline-and-producers.md`](./pipeline-and-producers.md) — how data gets into the cache.
> **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 durable system is `src/voxel_cache/*`
> examples of intended concurrency. The durable system is `crates/vxls-voxel-cache/src/*`
> and `shaders/`.
---
@@ -138,7 +138,7 @@ Both loops share the same request-buffer implementation and host download path.
## 4. Frame lifecycle (what the current driver does)
`State::render` in `src/main.rs` is the only driver. One iteration does roughly:
`State::render` in `crates/vxls/src/main.rs` is the only driver. One iteration does roughly:
1. **Move the toroidal table** to the camera position. Chunks leaving the block
are invalidated; chunks entering are marked as needing a root pointer.
@@ -182,32 +182,33 @@ Consequences agents should keep in mind:
| Path | Role | Status |
|---|---|---|
| `src/main.rs` | Window, wgpu setup, frame loop, host fulfilment | **Temporary playground** |
| `src/producers.rs` | `ChunkedProducer` + procedural fixtures | **Temporary playground** (trait is the useful part) |
| `src/voxel_cache.rs` | `VoxelCache` orchestrator, public API, raytrace bind group | Active, durable |
| `src/voxel_cache/schema.rs` | Pointer bits, page structs, request structs | Active, durable |
| `src/voxel_cache/layout.rs` | Attribute descriptors and generated WGSL constants | Active, durable |
| `src/voxel_cache/attributes.rs` | Attribute page buffers and bind group | Active, durable |
| `src/voxel_cache/structure.rs` | Pointer/location/depth page buffers | Active, durable |
| `src/voxel_cache/requests.rs` | Request counters, request buffer, top-K/sort, host download | Active, durable |
| `src/voxel_cache/insertion.rs` | `CacheInsertionData` upload buffers | Active, durable |
| `src/voxel_cache/eviction.rs` | Timestamp buffer and eviction ordering | Active, durable |
| `src/voxel_cache/pipelines.rs` | Write-requests, insertion, invalidation, write-pointers passes | Active, durable |
| `src/voxel_cache/tables.rs` | `FixedStructureTable` (dense root pointers) | Active, durable |
| `src/terrain.rs` | `ToroidalStructureTable` wrapper around the fixed table | Active, durable (name is misleading) |
| `src/gpu/` | Radix sort, top-K, indirect dispatch, compaction helpers | Active infrastructure |
| `src/gpu_profiler/` | Timestamp profiling and memory accounting wrappers | Active infrastructure |
| `src/gi_pipeline.rs` (+ `sparse_set.rs`) | Planned GI pipeline using cache attribute sets | **Compiled but never instantiated** |
| `src/production.rs` | Producer ID, `StructureAnchor` re-export, `VoxelProducer` trait | Compiled; durable contract |
| `src/production/host_production.rs` | Rayon-based `HostRequestHandler` | Compiled; `fullfill` still a stub |
| `src/production/tree_locator.rs` | Compact N-tree locator encoding | Compiled; inactive |
| `src/production/request_queue.rs` | Bounded, deduplicating, priority-ordered request queue | Compiled, unit-tested; not yet on the live async path |
| `src/host_production.rs` | Legacy `ChunkVoxelProducer` trait | **Inactive** |
| `src/tree.rs` | CPU N-tree prototype | **Inactive** |
| `src/sparse_tree.rs` | Packed color helper and node locator used by producers | Active via `main.rs`/`producers.rs` |
| `crates/vxls/src/main.rs` | Window, wgpu setup, frame loop, host fulfilment | **Temporary playground** |
| `crates/vxls/src/producers.rs` | `ChunkedProducer` + procedural fixtures | **Temporary playground** (trait is the useful part) |
| `crates/vxls-voxel-cache/src/lib.rs` | `VoxelCache` orchestrator, public API, raytrace bind group | Active, durable |
| `crates/vxls-voxel-cache/src/schema.rs` | Pointer bits, page structs, request structs | Active, durable |
| `crates/vxls-voxel-cache/src/layout.rs` | Attribute descriptors and generated WGSL constants | Active, durable |
| `crates/vxls-voxel-cache/src/attributes.rs` | Attribute page buffers and bind group | Active, durable |
| `crates/vxls-voxel-cache/src/structure.rs` | Pointer/location/depth page buffers | Active, durable |
| `crates/vxls-voxel-cache/src/requests.rs` | Request counters, request buffer, top-K/sort, host download | Active, durable |
| `crates/vxls-voxel-cache/src/insertion.rs` | `CacheInsertionData` upload buffers | Active, durable |
| `crates/vxls-voxel-cache/src/eviction.rs` | Timestamp buffer and eviction ordering | Active, durable |
| `crates/vxls-voxel-cache/src/pipelines.rs` | Write-requests, insertion, invalidation, write-pointers passes | Active, durable |
| `crates/vxls-voxel-cache/src/tables.rs` | `FixedStructureTable` (dense root pointers) | Active, durable |
| `crates/vxls-terrain/src/lib.rs` | `ToroidalStructureTable` wrapper around the fixed table | Active, durable (name is misleading) |
| `crates/vxls-bvh/src/lib.rs` (+ `aabb`, `build`, `debug`, `gpu`) | CPU BVH2 build, GPU buffers, and debug render | Active infrastructure |
| `crates/vxls-gpu/src/` | Radix sort, top-K, indirect dispatch, compaction helpers | Active infrastructure |
| `crates/vxls-profiler/src/` | Timestamp profiling and memory accounting wrappers | Active infrastructure |
| `crates/vxls/src/gi_pipeline.rs` (+ `sparse_set.rs`) | Planned GI pipeline using cache attribute sets | **Compiled but never instantiated** |
| `crates/vxls-production/src/lib.rs` | Producer ID, `StructureAnchor` re-export, `VoxelProducer` trait | Compiled; durable contract |
| `crates/vxls-production/src/host_production.rs` | Rayon-based `HostRequestHandler` | Compiled; `fullfill` still a stub |
| `crates/vxls-production/src/tree_locator.rs` | Compact N-tree locator encoding | Compiled; inactive |
| `crates/vxls-production/src/request_queue.rs` | Bounded, deduplicating, priority-ordered request queue | Compiled, unit-tested; not yet on the live async path |
| `crates/vxls/src/host_production.rs` | Legacy `ChunkVoxelProducer` trait | **Inactive** |
| `crates/vxls/src/sparse_tree.rs` | CPU `NTree` prototype, packed color helper and node locator used by producers | Active via `main.rs`/`producers.rs` |
`Cargo.toml` uses edition 2024 and nightly features (`generic_const_exprs`,
`float_algebraic`). Building requires a nightly toolchain.
The workspace uses edition 2024. Crates that use const-generic expressions enable
`generic_const_exprs` (voxel cache, production, BVH, terrain, app); `float_algebraic`
is only used by the app crate. Building requires a nightly toolchain.
---
@@ -254,7 +255,7 @@ There are two independent shader worlds, described fully in
- **Slang** (`shaders/*.slang`) for rendering. Built offline with `slangc` into
checked-in `shaders/out/*.spv`, embedded with `include_spirv_source!`, and
loaded as passthrough modules.
- **WGSL** (`src/voxel_cache/shaders/*.wgsl`) for cache management. Concatenated
- **WGSL** (`crates/vxls-voxel-cache/src/shaders/*.wgsl`) for cache management. Concatenated
at runtime with generated constants (`CHILDREN_COUNT`, `PAGE_COUNT`, attribute
metadata) and compiled with `include_wgsl!`-style module creation.
@@ -295,11 +296,11 @@ demo; the UI plots both a frame timer and a ray-march timer.
| Symptom | Location | Impact | Confidence |
|---|---|---|---|
| Location pages are sized with `size_of::<StructurePage<N>>()` (264 B at N=4) instead of `LocationPage` (28 B). | `src/voxel_cache/structure.rs:44` | ~39.6 MB allocated where ~4.2 MB is needed. | High — direct code read. |
| The host request path busy-waits on `device.poll`, making a callback design behave synchronously. | `src/main.rs` around the `loop { ... poll ... }` after request downloads | Stalls the CPU on the render thread; prevents real pipelining/streaming. | High. |
| Location pages are sized with `size_of::<StructurePage<N>>()` (264 B at N=4) instead of `LocationPage` (28 B). | `crates/vxls-voxel-cache/src/structure.rs:44` | ~39.6 MB allocated where ~4.2 MB is needed. | High — direct code read. |
| The host request path busy-waits on `device.poll`, making a callback design behave synchronously. | `crates/vxls/src/main.rs` around the `loop { ... poll ... }` after request downloads | Stalls the CPU on the render thread; prevents real pipelining/streaming. | High. |
| `VoxelTraceStack` is 5 entries and indexes `stack[10 - scale_exp/2]`, assuming `N = 4` and `chunk_power = 5`. | `shaders/voxel_cache.slang:93-96,177,189,257` | Changing branching or chunk depth silently corrupts tracing. | High. |
| Slang hardcodes `64` children per node and attribute meanings (0 = packed color, 1 = 3-word normal). | `shaders/voxel_cache.slang`, `shaders/voxel.slang` | Any cache layout change must be mirrored in Slang; mismatches are not caught at compile time. | High. |
| `gi.slang` is a stub that copies albedo and declares legacy bindings that do not match the Rust GI bind group. | `shaders/gi.slang`, `src/main.rs` | Works only because the declared bindings are unused; misleading as an example. | High. |
| `FixedStructureTable` / `ToroidalStructureTable` naming: the toroidal wrapper delegates to the fixed table, and `fixed_structure_table.slang` is imported but unused by `voxel.slang`. | `src/terrain.rs`, `shaders/fixed_structure_table.slang`, `shaders/voxel.slang:3` | Readers may look for toroidal logic in the wrong shader/module. | High. |
| Several subsystems are present but not wired into the binary (see module map). | `src/production/*`, `src/tree.rs`, `src/host_production.rs`, `src/gi_pipeline.rs` | Dead code can be mistaken for current architecture; it does not compile into the binary unless declared. | High. |
| `fullfill_request` hardcodes `NTreeNodeLocator<4>` and a `+5000` chunk offset. | `src/main.rs:1762-1838` | Not generic over the cache branching factor; offsets are demo-specific. | High. |
| `gi.slang` is a stub that copies albedo and declares legacy bindings that do not match the Rust GI bind group. | `shaders/gi.slang`, `crates/vxls/src/main.rs` | Works only because the declared bindings are unused; misleading as an example. | High. |
| `FixedStructureTable` / `ToroidalStructureTable` naming: the toroidal wrapper delegates to the fixed table, and `fixed_structure_table.slang` is imported but unused by `voxel.slang`. | `crates/vxls-terrain/src/lib.rs`, `shaders/fixed_structure_table.slang`, `shaders/voxel.slang:3` | Readers may look for toroidal logic in the wrong shader/module. | High. |
| Several subsystems are present but not wired into the binary (see module map). | `crates/vxls-production/src/*`, `crates/vxls/src/host_production.rs`, `crates/vxls/src/gi_pipeline.rs` | Dead code can be mistaken for current architecture; it does not compile into the binary unless declared. | High. |
| `fullfill_request` hardcodes `NTreeNodeLocator<4>` and a `+5000` chunk offset. | `crates/vxls/src/main.rs:1762-1838` | Not generic over the cache branching factor; offsets are demo-specific. | High. |