refactor: Splitting into crates
This commit is contained in:
+36
-35
@@ -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. |
|
||||
|
||||
@@ -4,7 +4,7 @@ This document follows data from a GPU-emitted request to a resident cache page,
|
||||
and describes the producer interface. It also marks which producer code is
|
||||
durable and which is throwaway.
|
||||
|
||||
> **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 `ChunkedProducer` shape and the
|
||||
@@ -141,7 +141,7 @@ corrupting the tree.
|
||||
|
||||
## 3. The durable producer shape
|
||||
|
||||
`src/producers.rs` defines:
|
||||
`crates/vxls/src/producers.rs` defines:
|
||||
|
||||
```rust
|
||||
pub trait ChunkedProducer<const N: usize>
|
||||
@@ -184,7 +184,7 @@ child instead of hardcoding color/normal.
|
||||
|
||||
### 3.1 Fulfilling a request
|
||||
|
||||
The demo's `fullfill_request` (`src/main.rs`) does:
|
||||
The demo's `fullfill_request` (`crates/vxls/src/main.rs`) does:
|
||||
|
||||
1. Decode the table-defined anchor with
|
||||
`ToroidalStructureTable::position_for_anchor` to get an absolute chunk
|
||||
@@ -212,10 +212,10 @@ chunk dimensions of 20×20×20 and a 4-ary tree.
|
||||
|
||||
Two locator implementations exist:
|
||||
|
||||
- **`NTreeNodeLocator<N>`** (`src/sparse_tree.rs`) — used by the demo. A packed
|
||||
- **`NTreeNodeLocator<N>`** (`crates/vxls/src/sparse_tree.rs`) — used by the demo. A packed
|
||||
`usize`; supports `root`, `from_usize`, `depth`, `child`, `node_location`,
|
||||
`as_usize`, `parent`, `children`.
|
||||
- **`TreeLocator<N>`** (`src/production/tree_locator.rs`) — the unwired
|
||||
- **`TreeLocator<N>`** (`crates/vxls-production/src/tree_locator.rs`) — the unwired
|
||||
production subsystem's version. Three base-N accumulators (`x`, `y`, `z`) with
|
||||
a leading `1` digit; root is `(1,1,1)`; `depth = ilog_N(x)`; `parent` divides
|
||||
each coordinate by `N`; `child` multiplies by `N` and adds the child digit.
|
||||
@@ -229,7 +229,7 @@ coordinates. Whichever is used, it must round-trip through the 32-bit
|
||||
|
||||
## 4. The current driver, step by step
|
||||
|
||||
Relevant code: `State::render` and `fullfill_request` in `src/main.rs`.
|
||||
Relevant code: `State::render` and `fullfill_request` in `crates/vxls/src/main.rs`.
|
||||
|
||||
1. **Render** writes G-buffers and request counters.
|
||||
2. **Gather** encodes both request pipelines (cache + table) into the same
|
||||
@@ -296,7 +296,7 @@ real engine.
|
||||
|
||||
---
|
||||
|
||||
## 5. Generators in `src/producers.rs`
|
||||
## 5. Generators in `crates/vxls/src/producers.rs`
|
||||
|
||||
All are fixtures. They exist to exercise the cache and should not be treated as
|
||||
stable.
|
||||
@@ -322,11 +322,11 @@ branching logic based on `depth <= 2`.
|
||||
|
||||
## 6. The production subsystem
|
||||
|
||||
`src/production.rs` and its children are compiled (`mod production;`), but the
|
||||
`crates/vxls-production/src/lib.rs` and its children are compiled (`mod production;`), but the
|
||||
demo driver in `main.rs` still uses its synchronous `fullfill_request` path. The
|
||||
production types are the durable contract; the driver is still the playground.
|
||||
|
||||
### 6.1 `src/production.rs`
|
||||
### 6.1 `crates/vxls-production/src/lib.rs`
|
||||
|
||||
Defines a more ambitious interface:
|
||||
|
||||
@@ -375,19 +375,19 @@ table keeps an anchor's identity while it stays in view and retires anchors that
|
||||
leave. An anchor must keep naming the same content if it later re-enters; bump
|
||||
its version word when content generation changes for the same coordinates.
|
||||
|
||||
### 6.2 `src/production/host_production.rs`
|
||||
### 6.2 `crates/vxls-production/src/host_production.rs`
|
||||
|
||||
`HostRequestHandler<N, P: VoxelProducer<N>>` owns a rayon `ThreadPool` and a
|
||||
producer, and is intended to fulfil requests on the CPU. Note that its
|
||||
`fullfill` method is a stub: it downloads the request buffer with an empty
|
||||
callback. `produce_requests` does the real parallel mapping.
|
||||
|
||||
### 6.3 `src/production/tree_locator.rs`
|
||||
### 6.3 `crates/vxls-production/src/tree_locator.rs`
|
||||
|
||||
`TreeLocator<N>` (described in §3.2) plus `From<StructureLocator>` /
|
||||
`Into<StructureLocator>` conversions.
|
||||
|
||||
### 6.4 `src/production/request_queue.rs`
|
||||
### 6.4 `crates/vxls-production/src/request_queue.rs`
|
||||
|
||||
A bounded, deduplicating, priority-ordered request queue. It is the durable
|
||||
answer to "the cache re-emits the same request every frame".
|
||||
@@ -429,9 +429,9 @@ Properties:
|
||||
- `ReadyItem::insertion_parent()` builds the `InsertionParent` for the insertion
|
||||
batch from the key and the latest `RequestMeta` (which carries `table_slot`).
|
||||
|
||||
The queue is unit-tested without a GPU (`cargo test production::request_queue`).
|
||||
The queue is unit-tested without a GPU (`cargo test -p vxls-production request_queue`).
|
||||
|
||||
### 6.5 `src/host_production.rs`
|
||||
### 6.5 `crates/vxls/src/host_production.rs`
|
||||
|
||||
An older, simpler trait:
|
||||
|
||||
@@ -444,13 +444,14 @@ pub trait ChunkVoxelProducer {
|
||||
It has no return value and no cache insertion types; it predates the current
|
||||
request/response pipeline.
|
||||
|
||||
### 6.6 `src/tree.rs`
|
||||
### 6.6 `crates/vxls/src/sparse_tree.rs`
|
||||
|
||||
A CPU `NTree<N>` prototype backed by a `HashMap<NTreeLocator<N>, NTreeNode<N>>`,
|
||||
A CPU `NTree<N>` prototype backed by a `HashMap<TreeLocator<N>, NTreeNode>`,
|
||||
with `constant`, `get`, `set`, array conversion, and explicit-structure export.
|
||||
Useful for understanding the tree, not used by the renderer.
|
||||
It also provides the packed `Color` helper and PLY loading. Useful for
|
||||
understanding the tree and used by the playground producers, not by the renderer.
|
||||
|
||||
### 6.7 `src/gi_pipeline.rs` + `sparse_set.rs`
|
||||
### 6.7 `crates/vxls/src/gi_pipeline.rs` + `sparse_set.rs`
|
||||
|
||||
Compiles (declared in `main.rs`) but `VoxelGiPipeline` is never instantiated. It
|
||||
adds `DontTouch` attributes for a leaf list and radiance, and a `GpuSparseSet`
|
||||
@@ -507,15 +508,15 @@ A production-ready producer should additionally:
|
||||
|
||||
| Symptom | Location | Impact | Confidence |
|
||||
|---|---|---|---|
|
||||
| The host request path busy-waits on `device.poll`; production blocks the render thread. | `src/main.rs` (`loop { ... poll ... }` in `render`) | No overlap, frame stalls, no streaming. | High |
|
||||
| `fullfill_request` hardcodes `NTreeNodeLocator<4>`, x/y/z child unpacking with `4` and `16`, and a `+5000` chunk offset. | `src/main.rs:1814-1905` | Not generic; offsets only make sense for the demo terrain. | High |
|
||||
| The demo driver is still synchronous: it downloads, produces, and inserts in one frame. The queue exists but `main.rs` does not schedule through it yet. | `src/main.rs` (`render`), `src/production/request_queue.rs` | No overlap between production and rendering in the demo. The durable contract is ready for an async scheduler. | High |
|
||||
| `page_count_buffer` is set to `request_informations.len()`, which may exceed `CacheInsertionData`'s `max_page_count` (1024) if `max_requests` is raised without resizing. | `src/main.rs` (write of `page_count_buffer`), `CacheInsertionData::new` | Buffer overrun / truncated production. | High |
|
||||
| The host request path busy-waits on `device.poll`; production blocks the render thread. | `crates/vxls/src/main.rs` (`loop { ... poll ... }` in `render`) | No overlap, frame stalls, no streaming. | High |
|
||||
| `fullfill_request` hardcodes `NTreeNodeLocator<4>`, x/y/z child unpacking with `4` and `16`, and a `+5000` chunk offset. | `crates/vxls/src/main.rs:1814-1905` | Not generic; offsets only make sense for the demo terrain. | High |
|
||||
| The demo driver is still synchronous: it downloads, produces, and inserts in one frame. The queue exists but `main.rs` does not schedule through it yet. | `crates/vxls/src/main.rs` (`render`), `crates/vxls-production/src/request_queue.rs` | No overlap between production and rendering in the demo. The durable contract is ready for an async scheduler. | High |
|
||||
| `page_count_buffer` is set to `request_informations.len()`, which may exceed `CacheInsertionData`'s `max_page_count` (1024) if `max_requests` is raised without resizing. | `crates/vxls/src/main.rs` (write of `page_count_buffer`), `CacheInsertionData::new` | Buffer overrun / truncated production. | High |
|
||||
| If `destination_indices[i] == 0xFFFFFFFF`, the producer is not told; the cache will re-request the node later. | `insertion.wgsl`, host callback | Wasted work and repeated requests; no metric for dropped pages. | High |
|
||||
| The external table insertion consumes the same eviction list as the cache insertion; if it inserts fewer roots than requested, the table has missing entries with no host-visible signal. | `VoxelCache::insert`, `fixed_table/insertion.wgsl` | Silent holes in the world. | Medium |
|
||||
| `TerrainGenerator` uses hardcoded mip factor 8 and `depth <= 2` special cases. | `src/producers.rs:207-263,330` | Not robust to different chunk resolutions. | High |
|
||||
| `BallGenerator` implements the old `Producer` trait, not `ChunkedProducer`. | `src/producers.rs:31-116` | Copying it as a template will not work with the current driver. | High |
|
||||
| The `production/` subsystem is compiled but not used by the demo driver. | `src/production.rs`, `src/production/*` | Agents may assume the queue is on the live path; it is the durable target, while `fullfill_request` is still the active playground path. | High |
|
||||
| `src/production/request_queue.rs` is new. | same | Its API may still change; `main.rs` does not depend on it yet. | Medium |
|
||||
| The demo uploads all attribute payloads with `bytemuck::cast_slice` of Rust arrays, so layout mismatches (padding, alignment) are not checked. | `src/main.rs` upload section | Silent corruption if the Rust struct layout diverges from the WGSL/Slang layout. | Medium |
|
||||
| The `+5000` offset plus `chunk_y.abs()` means negative chunk coordinates fold onto positive ones. | `src/main.rs:1785-1789` | Duplicate chunks / visual artifacts at negative y. | Medium |
|
||||
| `TerrainGenerator` uses hardcoded mip factor 8 and `depth <= 2` special cases. | `crates/vxls/src/producers.rs:207-263,330` | Not robust to different chunk resolutions. | High |
|
||||
| `BallGenerator` implements the old `Producer` trait, not `ChunkedProducer`. | `crates/vxls/src/producers.rs:31-116` | Copying it as a template will not work with the current driver. | High |
|
||||
| The `production/` subsystem is compiled but not used by the demo driver. | `crates/vxls-production/src/lib.rs`, `crates/vxls-production/src/*` | Agents may assume the queue is on the live path; it is the durable target, while `fullfill_request` is still the active playground path. | High |
|
||||
| `crates/vxls-production/src/request_queue.rs` is new. | same | Its API may still change; `main.rs` does not depend on it yet. | Medium |
|
||||
| The demo uploads all attribute payloads with `bytemuck::cast_slice` of Rust arrays, so layout mismatches (padding, alignment) are not checked. | `crates/vxls/src/main.rs` upload section | Silent corruption if the Rust struct layout diverges from the WGSL/Slang layout. | Medium |
|
||||
| The `+5000` offset plus `chunk_y.abs()` means negative chunk coordinates fold onto positive ones. | `crates/vxls/src/main.rs:1785-1789` | Duplicate chunks / visual artifacts at negative y. | Medium |
|
||||
|
||||
+9
-9
@@ -2,7 +2,7 @@
|
||||
|
||||
The project uses two shader languages for two different jobs:
|
||||
|
||||
| | Slang (`shaders/*.slang`) | WGSL (`src/voxel_cache/shaders/*.wgsl`) |
|
||||
| | Slang (`shaders/*.slang`) | WGSL (`crates/vxls-voxel-cache/src/shaders/*.wgsl`) |
|
||||
|---|---|---|
|
||||
| Used for | Rendering / ray marching | Cache management passes |
|
||||
| Compilation | Offline via `slangc`, SPIR-V checked in | Runtime via wgpu |
|
||||
@@ -10,9 +10,9 @@ The project uses two shader languages for two different jobs:
|
||||
| Embedded with | `include_spirv_source!` / `include_spirv!` | `include_str!` into a generated module |
|
||||
| Rust entry point | `main.rs` passthrough shader modules | `pipelines.rs`, `requests.rs`, `eviction.rs`, `tables.rs` |
|
||||
|
||||
> **Temporary code:** bind-group and pipeline setup in `src/main.rs` is part of
|
||||
> **Temporary code:** bind-group and pipeline setup in `crates/vxls/src/main.rs` is part of
|
||||
> the playground driver. Read shader contracts from the Rust cache/table
|
||||
> wrappers (`src/voxel_cache/*`) and this document, not from `main.rs` alone.
|
||||
> wrappers (`crates/vxls-voxel-cache/src/*`) and this document, not from `main.rs` alone.
|
||||
|
||||
---
|
||||
|
||||
@@ -48,8 +48,8 @@ them; edit the `.slang` source and rebuild.
|
||||
- `shaders/out/voxel.spv` → entry `ray_march_compute`, workgroup `(16,16,1)`
|
||||
- `shaders/out/gi.spv` → entry `gi`, workgroup `(16,16,1)`
|
||||
- Utility shaders are loaded with ordinary `include_spirv!`:
|
||||
- `shaders/out/radix_sort.spv` in `src/gpu/radix_sort.rs`
|
||||
- `shaders/out/compaction.spv` in `src/gpu/buffer_compactor.rs`
|
||||
- `shaders/out/radix_sort.spv` in `crates/vxls-gpu/src/radix_sort.rs`
|
||||
- `shaders/out/compaction.spv` in `crates/vxls-gpu/src/buffer_compactor.rs`
|
||||
- `radix_reduce.spv` is built by the Makefile but currently not referenced by
|
||||
Rust source.
|
||||
|
||||
@@ -504,7 +504,7 @@ Do not do this casually. Required changes include:
|
||||
|
||||
```sh
|
||||
make -C shaders # regenerates shaders/out/*.spv
|
||||
cargo run # wgpu embeds the checked-in SPIR-V at compile time
|
||||
cargo run -p vxls # wgpu embeds the checked-in SPIR-V at compile time
|
||||
```
|
||||
|
||||
Because SPIR-V is embedded with `include_*!`, changing `.spv` requires a Rust
|
||||
@@ -518,12 +518,12 @@ Makefile before building.
|
||||
| Symptom | Location | Impact | Confidence |
|
||||
|---|---|---|---|
|
||||
| `voxel.slang` imports `fixed_structure_table` but never uses it. | `shaders/voxel.slang:3` | Misleads readers; increases compile surface. | High |
|
||||
| `gi.slang` declares legacy bindings (`structure_pool`, `attributes_pool`, request/usage buffers, table buffers) that do not match the GI bind group Rust actually creates. | `shaders/gi.slang:17-45`, `src/main.rs:563-611` | Works only because the mismatched bindings are unused. Any real GI work will hit validation errors. | High |
|
||||
| `gi.slang` declares legacy bindings (`structure_pool`, `attributes_pool`, request/usage buffers, table buffers) that do not match the GI bind group Rust actually creates. | `shaders/gi.slang:17-45`, `crates/vxls/src/main.rs:563-611` | Works only because the mismatched bindings are unused. Any real GI work will hit validation errors. | High |
|
||||
| `PixelFootprintLod` demo parameters are hardcoded (100° FOV, 1080 px, threshold 2). | `shaders/voxel.slang:149` | LOD does not follow the window/FOV; resizing the window changes effective LOD. | High |
|
||||
| `VoxelTraceStack` size and indexing assume `N = 4` and `chunk_power = 5`. | `shaders/voxel_cache.slang:93-96,177,189,257` | Branching/depth changes silently break tracing. | High |
|
||||
| `fetch_color` / `fetch_normal` hardcode stride 64 and attribute indices 0/1. | `shaders/voxel.slang:68-79` | Cache layout changes break rendering with no compile-time error. | High |
|
||||
| The child-index and child-mirror arithmetic hardcodes `4` and `16`. | `shaders/voxel_cache.slang:103-108,154-165` | Not generic over branching factor. | High |
|
||||
| The toroidal tracer walks one unit cell per axis crossing with no empty-chunk skip. | `shaders/toroidal_structure_table.slang:62-101` | Cost scales with traversed grid cells, not just occupied chunks. | Medium |
|
||||
| `chunk_*` immediate field naming/order differs between Rust (`width, height, alt`) and the table extent (`width, alt, height`). | `src/main.rs:1049-1062`, `shaders/voxel.slang:140` | Hidden because the demo uses 20×20×20; non-cubic extents would mismatch. | Medium |
|
||||
| `chunk_*` immediate field naming/order differs between Rust (`width, height, alt`) and the table extent (`width, alt, height`). | `crates/vxls/src/main.rs:1049-1062`, `shaders/voxel.slang:140` | Hidden because the demo uses 20×20×20; non-cubic extents would mismatch. | Medium |
|
||||
| `radix_reduce.spv` is built and checked in but unused. | `shaders/Makefile:1` | Confusing build artifact. | High |
|
||||
| `voxel.slang` uses `groupshared VoxelTraceStack stacks[256]` but `create_shader_module_passthrough` bypasses wgpu validation. | `shaders/voxel.slang:118`, `src/main.rs:477-498` | Layout/limit errors appear as driver errors, not friendly validation messages. | Medium |
|
||||
| `voxel.slang` uses `groupshared VoxelTraceStack stacks[256]` but `create_shader_module_passthrough` bypasses wgpu validation. | `shaders/voxel.slang:118`, `crates/vxls/src/main.rs:477-498` | Layout/limit errors appear as driver errors, not friendly validation messages. | Medium |
|
||||
|
||||
+13
-13
@@ -1,12 +1,12 @@
|
||||
# Voxel cache
|
||||
|
||||
`src/voxel_cache.rs` and `src/voxel_cache/*` implement a GPU-resident sparse
|
||||
`crates/vxls-voxel-cache/src/lib.rs` and `crates/vxls-voxel-cache/src/*` implement a GPU-resident sparse
|
||||
voxel cache. This document covers the page model, pointer encoding, public API,
|
||||
request/insertion pipelines, eviction, and the structure tables that provide
|
||||
entry points into the cache.
|
||||
|
||||
> **Temporary caller:** the public `VoxelCache` surface is intended API;
|
||||
> `src/main.rs` is only one caller and currently uses it in a blocking,
|
||||
> `crates/vxls/src/main.rs` is only one caller and currently uses it in a blocking,
|
||||
> single-threaded playground way. See [`pipeline-and-producers.md`](./pipeline-and-producers.md).
|
||||
|
||||
---
|
||||
@@ -167,7 +167,7 @@ Rust API: `CachePointer::new(Option<Option<u32>>)`.
|
||||
| `Some(None)` | `0x80000000` | subdividable, unavailable |
|
||||
| `Some(Some(p))` | `0xC0000000 \| p` | subdividable, available at page `p` |
|
||||
|
||||
WGSL helpers in `src/voxel_cache/shaders/common.wgsl`:
|
||||
WGSL helpers in `crates/vxls-voxel-cache/src/shaders/common.wgsl`:
|
||||
|
||||
- `child_pointer_empty(subdivisible)`
|
||||
- `child_pointer_subdivided(pointer)`
|
||||
@@ -602,7 +602,7 @@ root page? Structure tables answer that and emit requests when it is missing.
|
||||
|
||||
### 8.1 `FixedStructureTable`
|
||||
|
||||
`src/voxel_cache/tables.rs`.
|
||||
`crates/vxls-voxel-cache/src/tables.rs`.
|
||||
|
||||
- Backing buffer: one `CachePointer` per slot, initialised to
|
||||
`subdividable, unavailable`.
|
||||
@@ -625,7 +625,7 @@ The table is dense: allocation is `slot_count * 4` bytes for pointers plus
|
||||
|
||||
### 8.2 `ToroidalStructureTable`
|
||||
|
||||
`src/terrain.rs`. Wraps `FixedStructureTable` with a movable block of chunks.
|
||||
`crates/vxls-terrain/src/lib.rs`. Wraps `FixedStructureTable` with a movable block of chunks.
|
||||
|
||||
- `extent = (x, y, z)` chunk counts.
|
||||
- Slot index from local coordinates:
|
||||
@@ -650,7 +650,7 @@ is imported by `voxel.slang` but unused.
|
||||
|
||||
### 8.3 `DynamicStructureTable`
|
||||
|
||||
`src/voxel_cache/tables.rs`. A table whose slots are allocated and released at
|
||||
`crates/vxls-voxel-cache/src/tables.rs`. A table whose slots are allocated and released at
|
||||
runtime. It shares the GPU scaffolding with `FixedStructureTable` through the
|
||||
private `StructureTableCore`; only the host-side slot management differs.
|
||||
|
||||
@@ -758,12 +758,12 @@ Memory example at 150k pages and 2 attributes is tabulated in
|
||||
|
||||
| Symptom | Location | Impact | Confidence |
|
||||
|---|---|---|---|
|
||||
| `CacheStructure::new` allocates `location_pages` with `size_of::<StructurePage<N>>()` instead of `size_of::<LocationPage>()`. | `src/voxel_cache/structure.rs:44` | At N=4, 264 B/page instead of 8 B/page: ~39.6 MB instead of ~1.2 MB for 150k pages. No correctness issue because shaders index by `LocationPage` stride. | High |
|
||||
| `StructurePage` (Rust, `u64` mask) and `PointerPage` (WGSL, two `u32`) are duplicated layout definitions. | `src/voxel_cache/schema.rs:89-100`, `src/voxel_cache/shaders/cache_common.wgsl:3-8` | Little-endian compatible today; any field reorder breaks silently. `StructurePage` is only used for sizing. | High |
|
||||
| `request_buffer_count` is written by every invocation of `write_requests.wgsl` with the same value. | `src/voxel_cache/shaders/write_requests.wgsl:50` | Benign data race (identical writes), but unnecessary and confusing. | Medium |
|
||||
| `CacheStructure::new` allocates `location_pages` with `size_of::<StructurePage<N>>()` instead of `size_of::<LocationPage>()`. | `crates/vxls-voxel-cache/src/structure.rs:44` | At N=4, 264 B/page instead of 8 B/page: ~39.6 MB instead of ~1.2 MB for 150k pages. No correctness issue because shaders index by `LocationPage` stride. | High |
|
||||
| `StructurePage` (Rust, `u64` mask) and `PointerPage` (WGSL, two `u32`) are duplicated layout definitions. | `crates/vxls-voxel-cache/src/schema.rs:89-100`, `crates/vxls-voxel-cache/src/shaders/cache_common.wgsl:3-8` | Little-endian compatible today; any field reorder breaks silently. `StructurePage` is only used for sizing. | High |
|
||||
| `request_buffer_count` is written by every invocation of `write_requests.wgsl` with the same value. | `crates/vxls-voxel-cache/src/shaders/write_requests.wgsl:50` | Benign data race (identical writes), but unnecessary and confusing. | Medium |
|
||||
| Insertion order no longer matters: each entry is validated against its `InsertionParent` and linked statelessly. | `insertion.wgsl`, `write_pointers.wgsl`, `fixed_table/insertion.wgsl` | A producer may reorder or filter results; unchanged request order is no longer a correctness requirement. | High |
|
||||
| `CacheInsertionPass` can silently insert fewer pages than requested (`0xFFFFFFFF` destinations) with no host feedback. | `src/voxel_cache/shaders/insertion.wgsl` | Producer believes data is resident; requests may repeat or data may be missing. | High |
|
||||
| The first `VoxelCache::insert` call inserts nothing: `new_timestamp = 1`, unused pages have timestamp 0, and the guard rejects `0 >= new_timestamp - 1` (`0 >= 0`). | `src/voxel_cache.rs:248`, `src/voxel_cache/shaders/insertion.wgsl:141-146` | One-frame startup delay; any external roots submitted in the first batch are dropped and must be re-requested. | High |
|
||||
| `CacheInsertionPass` can silently insert fewer pages than requested (`0xFFFFFFFF` destinations) with no host feedback. | `crates/vxls-voxel-cache/src/shaders/insertion.wgsl` | Producer believes data is resident; requests may repeat or data may be missing. | High |
|
||||
| The first `VoxelCache::insert` call inserts nothing: `new_timestamp = 1`, unused pages have timestamp 0, and the guard rejects `0 >= new_timestamp - 1` (`0 >= 0`). | `crates/vxls-voxel-cache/src/lib.rs:248`, `crates/vxls-voxel-cache/src/shaders/insertion.wgsl:141-146` | One-frame startup delay; any external roots submitted in the first batch are dropped and must be re-requested. | High |
|
||||
| Pointer/page-count limits are implicit (`< 2^30`, total elements `< 2^32`). | `schema.rs`, `requests.rs:82-85` | Large configurations fail via asserts or truncation. | High |
|
||||
| `CacheAttributeInit::DontTouch` attributes can become stale after a page is recycled; the cache deliberately does not clear them. | `src/voxel_cache/shaders/insertion.wgsl:164-178` | Any consumer of such an attribute must tolerate garbage for recycled pages. | Medium |
|
||||
| The cache exposes `usage_timestamps()` for debugging only; timestamps are also used internally for invalidation and eviction. | `src/voxel_cache.rs:445-449` | Easy to corrupt cache behaviour by writing to that buffer. | Medium |
|
||||
| `CacheAttributeInit::DontTouch` attributes can become stale after a page is recycled; the cache deliberately does not clear them. | `crates/vxls-voxel-cache/src/shaders/insertion.wgsl:164-178` | Any consumer of such an attribute must tolerate garbage for recycled pages. | Medium |
|
||||
| The cache exposes `usage_timestamps()` for debugging only; timestamps are also used internally for invalidation and eviction. | `crates/vxls-voxel-cache/src/lib.rs:445-449` | Easy to corrupt cache behaviour by writing to that buffer. | Medium |
|
||||
|
||||
Reference in New Issue
Block a user