refactor: cleaner request path + raytracing code
This commit is contained in:
+20
-17
@@ -93,11 +93,12 @@ Implemented and wired into the running demo:
|
||||
- WGSL cache-management shaders, specialised at runtime with generated
|
||||
constants.
|
||||
- Procedural fixtures (`SdfGenerator`, `TerrainGenerator`, `BallGenerator`) and
|
||||
a blocking host request-fulfilment loop in `main.rs`.
|
||||
a blocking host request-fulfilment loop in `main.rs` built on `RequestQueue`,
|
||||
`Producer`/`ProducedNode`, and `CacheInsertionData::upload`.
|
||||
|
||||
Not wired in: the `production/` subsystem, `tree.rs`, the older
|
||||
`host_production.rs` trait, and `VoxelGiPipeline` (module compiles but is never
|
||||
instantiated). See the module map below.
|
||||
Not wired in: the terrain/ball fixtures, `tree.rs`, and `VoxelGiPipeline`
|
||||
(module compiles but is never instantiated). The demo uses `TreeProducer` and
|
||||
the production subsystem's queue. See the module map below.
|
||||
|
||||
---
|
||||
|
||||
@@ -147,7 +148,9 @@ Both loops share the same request-buffer implementation and host download path.
|
||||
- write position/albedo/normal G-buffers;
|
||||
- update per-page usage timestamps;
|
||||
- increment request counters for missing children.
|
||||
3. **GI pass** (`gi.slang`) — currently a stub that copies albedo.
|
||||
3. **GI / AO pass** (`gi.slang`) — reads the world-space G-buffer, traces a few
|
||||
short hemisphere rays per pixel with `any_hit` and a finite `t_max`, and
|
||||
multiplies albedo by the AO term.
|
||||
4. **Blit / UI** — copy the selected debug texture, draw egui, download a usage
|
||||
histogram for the plot.
|
||||
5. **Encode request gathering** for both the cache and the structure table
|
||||
@@ -202,10 +205,8 @@ Consequences agents should keep in mind:
|
||||
| `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, `Producer`/`ProducedNode` | 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-production/src/tree_locator.rs` | Compact N-tree locator encoding | Active via `RequestKey::node_locator` and `TreeProducer` |
|
||||
| `crates/vxls-production/src/request_queue.rs` | Bounded, deduplicating, priority-ordered request queue | Active in the demo driver, unit-tested |
|
||||
| `crates/vxls/src/sparse_tree.rs` | CPU `NTree` prototype, packed color helper and node locator used by producers | Active via `main.rs`/`producers.rs` |
|
||||
|
||||
The workspace uses edition 2024. Crates that use const-generic expressions enable
|
||||
@@ -232,10 +233,12 @@ mantissas to derive tree levels.
|
||||
`scale_exp`, so the tree is effectively spatially indexed by float bit
|
||||
patterns. This is why the tracer can descend without explicit bounding boxes.
|
||||
|
||||
`VoxelTraceStack` in `voxel_cache.slang` is a 5-entry stack indexed by
|
||||
`10 - scale_exp/2`. That hardcodes the maximum supported depth and the
|
||||
branching factor. It also assumes `chunk_power = 5`; changing chunk depth without
|
||||
updating the stack breaks tracing.
|
||||
The trace stack is caller-owned through `ITraceStack`. The local
|
||||
implementation (`LocalTraceStack` in `voxel_tracing.slang`) is a 5-entry stack
|
||||
indexed by `10 - scale_exp/2`. That hardcodes the maximum supported depth and
|
||||
the branching factor. It also assumes `chunk_power = 5`; changing chunk depth
|
||||
without updating the stack breaks tracing. A groupshared-backed implementation
|
||||
is a front-end change and needs no trace-core edits.
|
||||
|
||||
The toroidal table is a dense 3D grid of chunk root pointers. It wraps with
|
||||
`imod`, so moving the camera across a chunk boundary invalidates the departing
|
||||
@@ -300,9 +303,9 @@ demo; the UI plots both a frame timer and a ray-march timer.
|
||||
|---|---|---|---|
|
||||
| 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. |
|
||||
| The caller-owned trace stack (`LocalTraceStack`, or a groupshared-backed `ITraceStack`) is 5 entries and indexes `entries[10 - scale_exp/2]`, assuming `N = 4` and `chunk_power = 5`. | `shaders/voxel_tracing.slang`, `shaders/voxel_cache.slang` | 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`, `crates/vxls/src/main.rs` | Works only because the declared bindings are unused; misleading as an example. | High. |
|
||||
| `gi.slang` is a simple AO pass (4 fixed hemisphere rays, no denoiser), not a full GI solution. | `shaders/gi.slang` | Noisy, view-dependent AO; it exists as a secondary-ray smoke test. | 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. |
|
||||
| Several subsystems are present but not wired into the binary (see module map). | `crates/vxls/src/gi_pipeline.rs`, terrain/ball fixtures | Dead code can be mistaken for current architecture; it does not compile into the binary unless declared. | High. |
|
||||
| The demo worker thread still lives in `main.rs`, so scheduling and producer ownership are not reusable. | `crates/vxls/src/main.rs` | Production types are durable; the host service around them is playground code. | Medium. |
|
||||
|
||||
+128
-136
@@ -144,101 +144,95 @@ corrupting the tree.
|
||||
|
||||
## 3. The durable producer shape
|
||||
|
||||
`crates/vxls/src/producers.rs` defines:
|
||||
The durable interface is `vxls-production::Producer`, and the demo driver uses
|
||||
it through `TreeProducer` in `crates/vxls/src/producers.rs`:
|
||||
|
||||
```rust
|
||||
pub trait ChunkedProducer<const N: usize>
|
||||
pub trait Producer<const N: usize, A: Attributes>
|
||||
where [(); N * N * N]:,
|
||||
{
|
||||
fn produce_node(
|
||||
fn produce(
|
||||
&self,
|
||||
depth: usize,
|
||||
nx: usize,
|
||||
ny: usize,
|
||||
nz: usize,
|
||||
chunk_pos: (usize, usize, usize),
|
||||
) -> ProducedChunk<N>;
|
||||
anchor: StructureAnchor,
|
||||
locator: StructureLocator,
|
||||
) -> ProducedNode<N, A>;
|
||||
}
|
||||
|
||||
pub struct ProducedChunk<const N: usize> {
|
||||
pub children: [ChildInformation; N * N * N],
|
||||
pub colors: [u32; N * N * N], // packed RGBA
|
||||
pub normals: [[f32; 3]; N * N * N],
|
||||
pub struct ProducedNode<const N: usize, A: Attributes>
|
||||
where [(); N * N * N]:,
|
||||
{
|
||||
pub insertion: InsertionInformation<N>,
|
||||
pub attributes: [A; N * N * N],
|
||||
}
|
||||
```
|
||||
|
||||
`locator` is the content-local path of the node to produce, obtained from the
|
||||
request with `RequestKey::node_locator::<N>()`. The producer does not need to
|
||||
know whether the request was a structure root or an internal child: the locator
|
||||
already names the node, and the cache derives the matching `LocationPage` from
|
||||
the same key.
|
||||
|
||||
The cache owns identity, so `ProducedNode` deliberately carries no producer id,
|
||||
anchor, table slot, or location. The host/queue adds those when it builds an
|
||||
`InsertionEntry`.
|
||||
|
||||
The older `ChunkedProducer` / `ProducedChunk` shape in
|
||||
`crates/vxls/src/producers.rs` is retained only for the unused terrain/ball
|
||||
fixtures. It is not the interface new producers should implement.
|
||||
|
||||
Interpretation:
|
||||
|
||||
- `depth` is the node depth inside a chunk (root = 0).
|
||||
- `(nx, ny, nz)` is the node's position in the depth-specific coordinate space
|
||||
(`0 .. N^depth`), i.e. the node's grid coordinate at that depth, not a voxel
|
||||
coordinate.
|
||||
- `chunk_pos` is the chunk's grid position in the world.
|
||||
- The producer must fill one entry per child. Each child says whether it can be
|
||||
subdivided further and whether it is occupied, and supplies its attribute
|
||||
words.
|
||||
- A leaf is `subdividable = false`. A node that should be refined later is
|
||||
`subdividable = true`. Occupancy controls hit testing and coarse skipping.
|
||||
|
||||
This shape is independent of the cache layout only up to the attribute buffers:
|
||||
the demo's `colors` / `normals` arrays correspond exactly to the two configured
|
||||
attributes. A general design should produce `word_count` words per attribute per
|
||||
child instead of hardcoding color/normal.
|
||||
- The producer fills one entry per child of the requested node, plus the
|
||||
attributes for those children.
|
||||
- `anchor` is the content identity. A producer must derive world position from
|
||||
it and never from a table slot.
|
||||
|
||||
### 3.1 Fulfilling a request
|
||||
|
||||
The demo's `fullfill_request` (`crates/vxls/src/main.rs`) does:
|
||||
`TreeProducer` (`crates/vxls/src/producers.rs`) does:
|
||||
|
||||
1. Decode the table-defined anchor with
|
||||
`ToroidalStructureTable::position_for_anchor` to get an absolute chunk
|
||||
coordinate.
|
||||
2. Add the playground offset `+5000` to x and z and take `abs()` of y.
|
||||
3. If `request_meta.page_index == 0xFFFFFFFF` (an external table request),
|
||||
produce the chunk root at depth 0, emit the root locator, and emit
|
||||
`InsertionParent::external(producer_id, anchor, table_slot)`.
|
||||
4. Otherwise (an internal child request):
|
||||
- decode the parent `NTreeNodeLocator<4>` from `node_id`;
|
||||
- decode `children_index` into `(child_x, child_y, child_z)` with x fastest;
|
||||
- compute the child locator;
|
||||
- produce the child node at `parent_depth + 1` with the child's node
|
||||
coordinates;
|
||||
- emit the child locator as the new `LocationPage.node_id`;
|
||||
- emit `InsertionParent::internal(meta, node_id, producer_id, anchor)`.
|
||||
1. Decode `locator` with `TreeLocator::<N>::from`.
|
||||
2. If the node is not subdivided, emit a constant page: every child has the
|
||||
node's attribute and `ChildInformation::new(false, occupied)`.
|
||||
3. Otherwise iterate `locator.children()` and emit each child's
|
||||
`ChildInformation` and `VoxelAttributes`.
|
||||
4. Return a `ProducedNode`; no location or parent is produced here.
|
||||
|
||||
The root/child test must use `RequestMeta.page_index`, not `node_id`: child 0
|
||||
of the root also has `node_id = 0`.
|
||||
The request path is:
|
||||
|
||||
The `+5000` offset and the hardcoded `<4>` are playground artifacts. They assume
|
||||
chunk dimensions of 20×20×20 and a 4-ary tree.
|
||||
1. `RequestQueue` yields a `WorkItem` with a `RequestKey`.
|
||||
2. The worker calls `producer.produce(key.anchor, key.node_locator::<4>())`.
|
||||
3. On drain, `ReadyItem::insertion_entry()` combines the payload with
|
||||
`ReadyItem::insertion_parent()` and `ReadyItem::location_page()`.
|
||||
4. `CacheInsertionData::upload` writes the batch.
|
||||
|
||||
### 3.2 Locators
|
||||
|
||||
Two locator implementations exist:
|
||||
`TreeLocator<N>` (`crates/vxls-production/src/tree_locator.rs`) is the locator
|
||||
used by the request queue and the demo producer. 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. `StructureLocator` is a flat interleaved form.
|
||||
|
||||
- **`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>`** (`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.
|
||||
`StructureLocator` is a flat interleaved form.
|
||||
|
||||
Both encode "path from root" and can be converted to/from application-level
|
||||
coordinates. Whichever is used, it must round-trip through the 32-bit
|
||||
`node_id`.
|
||||
`NTree<N>` in `crates/vxls/src/sparse_tree.rs` is keyed by the same locator, so
|
||||
a `RequestKey` can name a produced node directly. Locators must round-trip
|
||||
through the 32-bit `node_id`.
|
||||
|
||||
---
|
||||
|
||||
## 4. The current driver, step by step
|
||||
|
||||
Relevant code: `State::render` and `fullfill_request` in `crates/vxls/src/main.rs`.
|
||||
Relevant code: `State::render` and `TreeProducer` in `crates/vxls/src/main.rs` /
|
||||
`crates/vxls/src/producers.rs`.
|
||||
|
||||
1. **Render** writes G-buffers and request counters.
|
||||
2. **Gather** encodes both request pipelines (cache + table) into the same
|
||||
command buffer, then submits and presents.
|
||||
3. **Download** starts three asynchronous reads per request buffer (count,
|
||||
informations, meta).
|
||||
informations, meta). Each callback only ingests the wire requests into the
|
||||
shared `RequestQueue`; it does not drain or upload.
|
||||
4. **Busy-wait**:
|
||||
|
||||
```rust
|
||||
@@ -249,19 +243,26 @@ Relevant code: `State::render` and `fullfill_request` in `crates/vxls/src/main.r
|
||||
```
|
||||
|
||||
`finished` counts completed callbacks (one cache, one table), so completion
|
||||
does not require all six reads to land independently.
|
||||
5. **Produce** on the CPU with rayon: one `fullfill_request` per
|
||||
`(RequestInformation, RequestMeta)` pair. The results are copied into dense
|
||||
vectors, then uploaded with `queue.write_buffer` into:
|
||||
- `insertion_information_buffer()`
|
||||
- `location_pages_buffer()`
|
||||
- `insertion_parents_buffer()`
|
||||
- `attributes_buffers()[0]` (color)
|
||||
- `attributes_buffers()[1]` (normal)
|
||||
- `destination_indices_buffer()` (pre-filled with `0xFFFFFFFF`)
|
||||
- `valid_count_buffer()` (`0`)
|
||||
- `page_count_buffer()`
|
||||
6. **Insert** encodes:
|
||||
does not require all six reads to land independently. Each callback
|
||||
increments it only after ingesting.
|
||||
5. **Drain** the queue once both downloads have landed:
|
||||
|
||||
```rust
|
||||
let children = queue.drain_ready_matching(
|
||||
frame_id, cache_insertion.capacity(), |key| !key.is_root());
|
||||
let roots = queue.drain_ready_matching(
|
||||
frame_id, structure_table_insertion.capacity(), |key| key.is_root());
|
||||
```
|
||||
|
||||
`frame_id` is a host-owned monotonic counter, not the cache timestamp word.
|
||||
6. **Produce** on the worker thread with rayon, one `Producer::produce` call per
|
||||
`WorkItem`. Each result is a `ProducedNode<N, A>` keyed by
|
||||
`RequestKey::node_locator::<N>()`. On drain,
|
||||
`ReadyItem::insertion_entry()` attaches the parent and location, and
|
||||
`CacheInsertionData::upload` writes the whole batch (structure, location,
|
||||
parent, attributes, `valid_count`, `page_count`). `destination_indices` is
|
||||
reset by the validation shaders, not by the host.
|
||||
7. **Insert** encodes:
|
||||
|
||||
```rust
|
||||
cache.insert(&device, &mut encoder, &mut [
|
||||
@@ -277,7 +278,7 @@ Relevant code: `State::render` and `fullfill_request` in `crates/vxls/src/main.r
|
||||
preparation is shared by both page allocations. It orders pages by timestamp
|
||||
first (least recently used first) and depth second (deepest first among equal
|
||||
timestamps).
|
||||
7. **Submit** and read back the insertion profile.
|
||||
8. **Submit** and read back the insertion profile.
|
||||
|
||||
Because the external insertion is processed first, newly produced chunk roots
|
||||
are resident before the internal child insertion links them. The table insertion
|
||||
@@ -285,14 +286,16 @@ then points the slot at the root page.
|
||||
|
||||
### 4.1 Problems this creates
|
||||
|
||||
- The render thread blocks on the CPU producer; there is no overlap between
|
||||
production and rendering.
|
||||
- The render thread blocks waiting for downloads before it can drain results, so
|
||||
production does not overlap with rendering.
|
||||
- Request buffers are read back every frame even when empty.
|
||||
- `finished >= 2` is a coarse synchronization; it assumes exactly two buffers
|
||||
and no retries.
|
||||
- The producer runs on the same thread that owns the event loop, so a slow
|
||||
producer directly reduces frame rate.
|
||||
- The worker thread is spawned from the playground, so scheduling and producer
|
||||
ownership are not reusable outside `main.rs`.
|
||||
- No backpressure or prioritisation beyond the top-K request cap.
|
||||
- Rejected insertions (`destination_indices == 0xFFFFFFFF`) are still not
|
||||
reported back to the producer.
|
||||
|
||||
These are acceptable for a playground and are the first things to redesign for a
|
||||
real engine.
|
||||
@@ -306,9 +309,10 @@ stable.
|
||||
|
||||
| Generator | Status | What it does |
|
||||
|---|---|---|
|
||||
| `SdfGenerator<N>` | Used by the demo | Signed-distance field from FBM simplex noise plus procedural "trees"; derives normal by finite differences; packs color from normal. |
|
||||
| `TerrainGenerator<N>` | Supported but commented out | Loads a TIFF heightmap and a JPEG/PNG colormap; builds low-resolution mips; produces nodes from min/max height spans. |
|
||||
| `BallGenerator<N>` | Unused | Implements the older `Producer<N>` trait (not `ChunkedProducer`), draws a sphere; useful as a minimal example. |
|
||||
| `TreeProducer<N>` | Used by the demo | Implements the durable `vxls_production::Producer` over an in-memory `NTree`; the request's `node_locator` selects the node. |
|
||||
| `SdfGenerator<N>` | Fixture, unused | Signed-distance field from FBM simplex noise plus procedural "trees"; derives normal by finite differences; packs color from normal. |
|
||||
| `TerrainGenerator<N>` | Fixture, unused | Loads a TIFF heightmap and a JPEG/PNG colormap; builds low-resolution mips; produces nodes from min/max height spans. |
|
||||
| `BallGenerator<N>` | Fixture, unused | Implements the local playground `producers::Producer<N>` trait, not the durable one. |
|
||||
|
||||
`TerrainGenerator` is the closest thing to a realistic producer, but it is
|
||||
single-threaded at load time and uses hardcoded mip factors (8×). It also has
|
||||
@@ -325,9 +329,10 @@ branching logic based on `depth <= 2`.
|
||||
|
||||
## 6. The production subsystem
|
||||
|
||||
`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.
|
||||
`crates/vxls-production/src/lib.rs` and its children are compiled, and the demo
|
||||
driver now uses its durable `Producer` / `ProducedNode` / `RequestQueue` types.
|
||||
The `main.rs` producer remains a playground fixture, but it implements the
|
||||
durable interface.
|
||||
|
||||
### 6.1 `crates/vxls-production/src/lib.rs`
|
||||
|
||||
@@ -362,16 +367,18 @@ The cache-facing side is:
|
||||
```rust
|
||||
let layout = CacheLayout::from_attributes(&A::LAYOUT, &[]);
|
||||
let insertion = CacheInsertionData::new(&device, max_entries, &layout);
|
||||
let entry_count = insertion.write_attributes(&queue, node.attributes())?;
|
||||
let entries: Vec<InsertionEntry<N>> = ...;
|
||||
insertion.upload(&queue, &entries, &voxels)?;
|
||||
```
|
||||
|
||||
Differences from the demo interface:
|
||||
Differences from the legacy `ChunkedProducer` fixture interface:
|
||||
|
||||
- A node carries a `producer_id`, so one cache can mix multiple producers.
|
||||
- Attributes are abstracted behind `Attributes`, avoiding hardcoded
|
||||
color/normal buffers.
|
||||
- The producer receives a `StructureLocator` rather than depth + coordinates,
|
||||
pushing locator arithmetic into the producer.
|
||||
- `ProducedNode` carries no identity: the request key supplies producer, anchor,
|
||||
parent, and `LocationPage` when the entry is staged.
|
||||
- `anchor` is the content identity. A producer must derive world position from
|
||||
it and never from a table slot.
|
||||
|
||||
@@ -389,12 +396,11 @@ 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 `crates/vxls-production/src/host_production.rs`
|
||||
### 6.2 Host production helper (not present)
|
||||
|
||||
`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.
|
||||
There is no `crates/vxls-production/src/host_production.rs` in this tree. The
|
||||
worker thread and `RequestQueue` in `crates/vxls/src/main.rs` are the current
|
||||
host-side implementation.
|
||||
|
||||
### 6.3 `crates/vxls-production/src/tree_locator.rs`
|
||||
|
||||
@@ -440,32 +446,25 @@ Properties:
|
||||
queued/in-flight/ready jobs. Invalidation is a cancellation/cleanup hint,
|
||||
**not** a correctness mechanism: the GPU rejects stale insertions by checking
|
||||
the current anchor/slot.
|
||||
- `RequestKey::node_locator::<N>()` derives the locator of the requested node
|
||||
(root or child) from the key, so producers and `LocationPage` agree.
|
||||
- `ReadyItem::insertion_parent()` builds the `InsertionParent` for the insertion
|
||||
batch from the key and the latest `RequestMeta` (which carries `table_slot`).
|
||||
- `ReadyItem::location_page::<N>()` builds the `LocationPage` from the key, not
|
||||
from the producer payload or the table slot.
|
||||
- `ReadyItem::insertion_entry()` combines the payload's `InsertionInformation`
|
||||
with those two into a cache-facing `InsertionEntry`.
|
||||
|
||||
The queue is unit-tested without a GPU (`cargo test -p vxls-production request_queue`).
|
||||
|
||||
### 6.5 `crates/vxls/src/host_production.rs`
|
||||
|
||||
An older, simpler trait:
|
||||
|
||||
```rust
|
||||
pub trait ChunkVoxelProducer {
|
||||
fn produce_voxel(&mut self, depth, chunk_position, voxel_position);
|
||||
}
|
||||
```
|
||||
|
||||
It has no return value and no cache insertion types; it predates the current
|
||||
request/response pipeline.
|
||||
|
||||
### 6.6 `crates/vxls/src/sparse_tree.rs`
|
||||
### 6.5 `crates/vxls/src/sparse_tree.rs`
|
||||
|
||||
A CPU `NTree<N>` prototype backed by a `HashMap<TreeLocator<N>, NTreeNode>`,
|
||||
with `constant`, `get`, `set`, array conversion, and explicit-structure export.
|
||||
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 `crates/vxls/src/gi_pipeline.rs` + `sparse_set.rs`
|
||||
### 6.6 `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`
|
||||
@@ -478,36 +477,34 @@ code.
|
||||
|
||||
Minimum viable path with the current demo interface:
|
||||
|
||||
1. Implement `ChunkedProducer<N>`:
|
||||
1. Implement the durable `vxls_production::Producer<N, A>`:
|
||||
|
||||
```rust
|
||||
impl ChunkedProducer<4> for MyProducer {
|
||||
fn produce_node(&self, depth, nx, ny, nz, chunk_pos) -> ProducedChunk<4> { ... }
|
||||
impl Producer<4, MyAttributes> for MyProducer {
|
||||
fn produce(
|
||||
&self,
|
||||
anchor: StructureAnchor,
|
||||
locator: StructureLocator,
|
||||
) -> ProducedNode<4, MyAttributes> { ... }
|
||||
}
|
||||
```
|
||||
|
||||
2. For each child, compute:
|
||||
2. Decode `locator` with `TreeLocator::<N>::from` if the producer needs node
|
||||
coordinates.
|
||||
3. For each child of the requested node, compute:
|
||||
- `subdividable`: can this child be refined?
|
||||
- `occupied`: can it produce a hit?
|
||||
- attribute words in the cache layout order.
|
||||
3. Wire the producer into `fullfill_request` (or replace that function).
|
||||
Request → coordinates:
|
||||
- external (`RequestMeta.page_index == 0xFFFFFFFF`), produce chunk root;
|
||||
- internal: decode `node_id`, decode `children_index`, produce child at
|
||||
`depth + 1`.
|
||||
4. Emit a `LocationPage` matching the produced node. For internal requests,
|
||||
it must be `parent.child(child_x, child_y, child_z)`.
|
||||
5. Emit an `InsertionParent`:
|
||||
- external: `InsertionParent::external(producer_id, anchor, table_slot)`;
|
||||
- internal: `InsertionParent::internal(meta, node_id, producer_id, anchor)`.
|
||||
6. Set `page_count_buffer` to the number of entries. Order does not matter, but
|
||||
every entry must have matching information, location, parent, and attributes.
|
||||
7. Update the size passed to `CacheInsertionData::new` if the maximum batch can
|
||||
exceed `max_requests`.
|
||||
4. Return a `ProducedNode` with `InsertionInformation` and the attribute array.
|
||||
Do not emit a `LocationPage` or `InsertionParent`; those are derived from the
|
||||
`RequestKey` when the result is drained.
|
||||
5. Replace `TreeProducer` in `crates/vxls/src/main.rs` with the new producer.
|
||||
6. Keep `CacheInsertionData::new` capacity at least as large as the maximum
|
||||
number of entries the queue can drain in one frame.
|
||||
|
||||
A production-ready producer should additionally:
|
||||
|
||||
- use the `Producer`/`Attributes` abstraction so attributes are not hardcoded;
|
||||
- use the `Attributes` abstraction so attributes are not hardcoded;
|
||||
- run through `RequestQueue` on a worker thread and stream results across frames
|
||||
without blocking the render loop;
|
||||
- handle `destination_indices == 0xFFFFFFFF` by retrying the request;
|
||||
@@ -522,14 +519,9 @@ A production-ready producer should additionally:
|
||||
| Symptom | Location | Impact | Confidence |
|
||||
|---|---|---|---|
|
||||
| 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 |
|
||||
| The demo driver is still synchronous: it downloads, produces, and inserts in one frame. | `crates/vxls/src/main.rs` (`render`), `crates/vxls-production/src/request_queue.rs` | No overlap between production and rendering in the demo. The queue is on the live path but the scheduler is still frame-blocking. | 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. | `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 |
|
||||
| `TerrainGenerator` uses hardcoded mip factor 8 and `depth <= 2` special cases. | `crates/vxls/src/producers.rs` | Not robust to different chunk resolutions. | High |
|
||||
| `BallGenerator` implements the local playground `producers::Producer<N>` trait, not the durable `vxls_production::Producer`. | `crates/vxls/src/producers.rs` | Copying it as a template will not work with the current driver. | High |
|
||||
| The worker thread is owned by `main.rs` rather than `vxls-production`, so queue scheduling and producers are not reusable yet. | `crates/vxls/src/main.rs` | Durable producer types exist, but the host service around them does not. | Medium |
|
||||
|
||||
+141
-37
@@ -64,23 +64,31 @@ module creation fails.
|
||||
flowchart TD
|
||||
V[voxel.slang<br/>ray_march_compute] --> VC[voxel_cache.slang<br/>VoxelCacheTracer]
|
||||
V --> VT[voxel_tracing.slang<br/>Tracer / interfaces]
|
||||
V --> BVH[bvh.slang<br/>Bvh]
|
||||
V --> TST[toroidal_structure_table.slang<br/>ToroidalStructureTableTracer]
|
||||
V --> LOD[lod_policies.slang<br/>PixelFootprintLod]
|
||||
V -. unused import .-> FST[fixed_structure_table.slang]
|
||||
G[gi.slang<br/>AO pass] --> VC
|
||||
G --> VT
|
||||
G --> BVH
|
||||
G --> LOD
|
||||
VC --> VT
|
||||
TST --> VT
|
||||
TST --> VC
|
||||
BVH --> VT
|
||||
BVH --> VC
|
||||
```
|
||||
|
||||
| File | Role |
|
||||
|---|---|
|
||||
| `voxel_tracing.slang` | `Ray`, `Span`, `Cell`, `Hit`; `IStructure`, `IVoxelCache`, `ILodPolicy`; generic `Tracer`. |
|
||||
| `voxel_cache.slang` | `StructurePointer`, `StructureElement`, `VoxelCacheParameters`, `VoxelTraceStack`, `VoxelCacheTracer`, attribute helpers. |
|
||||
| `voxel_tracing.slang` | `Ray`, `Cell`, `Hit`, `TraceSettings`, `ITraceStack`/`LocalTraceStack`; `IStructure`, `IVoxelCache`, `ILodPolicy`; generic `Tracer`. |
|
||||
| `voxel_cache.slang` | `StructurePointer`, `StructureElement`, `VoxelCacheParameters`, `VoxelCacheTracer`, `ColorHit`, attribute helpers. |
|
||||
| `bvh.slang` | `Bvh` structure: restart-trail traversal, object transforms, bounded distance (`max_t`) for secondary rays. |
|
||||
| `toroidal_structure_table.slang` | Dense wrapped chunk grid; produces cache entry cells. |
|
||||
| `lod_policies.slang` | `PixelFootprintLod`. |
|
||||
| `fixed_structure_table.slang` | Non-wrapping chunk grid; imported by `voxel.slang` but not used. |
|
||||
| `voxel.slang` | Push constants, G-buffer bindings, `ColorHit`, `ray_march_compute`. |
|
||||
| `gi.slang` | Stub GI pass (copies albedo). |
|
||||
| `voxel.slang` | Push constants, G-buffer bindings, `ray_march_compute`. |
|
||||
| `gi.slang` | Screen-space AO: reads the world-space G-buffer and traces short hemisphere rays with the shared tracer. |
|
||||
| `compaction.slang`, `radix_sort.slang`, `radix_reduce.slang` | GPU utility kernels. |
|
||||
|
||||
---
|
||||
@@ -118,8 +126,11 @@ ParameterBlock<ToroidalStructureTable> table_parameters; // group 1
|
||||
|
||||
### Group 2 — G-buffers
|
||||
|
||||
Three `rgba32f` storage textures written by the main pass; `gi.slang` binds
|
||||
target + position + albedo + normal instead.
|
||||
Three `rgba32f` storage textures written by the main pass. Position and normal
|
||||
are **world space**: the tracer maps the cache's unit-cube hit through
|
||||
`Cell::cube_to_world` / `Cell::world_origin`, and rotates local attribute
|
||||
normals with `Hit::normal_to_world`. `gi.slang` binds target + position +
|
||||
albedo + normal and uses the world-space position/normal as AO ray origins.
|
||||
|
||||
### Push constants / immediates
|
||||
|
||||
@@ -155,14 +166,14 @@ pages were touched this frame.
|
||||
```slang
|
||||
public interface IStructure {
|
||||
associatedtype Cursor;
|
||||
Cursor begin(Ray worldRay, Span s);
|
||||
Cursor begin(Ray worldRay);
|
||||
bool next(inout Cursor c, out Cell cell);
|
||||
}
|
||||
|
||||
public interface IVoxelCache {
|
||||
associatedtype GroupSharedData;
|
||||
bool trace<L : ILodPolicy>(
|
||||
uint32_t root, inout GroupSharedData data, Ray r, L lod, float offset_t, out Hit v);
|
||||
bool trace<L : ILodPolicy, St : ITraceStack>(
|
||||
uint32_t root, Ray r, L lod, TraceSettings settings,
|
||||
float offset_t, inout St stack, out Hit v);
|
||||
}
|
||||
|
||||
public interface ILodPolicy {
|
||||
@@ -171,7 +182,8 @@ public interface ILodPolicy {
|
||||
|
||||
public struct Tracer<S : IStructure, C : IVoxelCache, L : ILodPolicy> {
|
||||
S structure; C cache; L lod;
|
||||
bool trace(inout C.GroupSharedData gsData, out Hit h, Ray r, Span s);
|
||||
bool trace<St : ITraceStack>(
|
||||
out Hit h, Ray r, TraceSettings settings, inout St stack);
|
||||
}
|
||||
```
|
||||
|
||||
@@ -179,6 +191,24 @@ public struct Tracer<S : IStructure, C : IVoxelCache, L : ILodPolicy> {
|
||||
interface can be replaced without touching the others; this is the main
|
||||
extensibility point on the render side.
|
||||
|
||||
`TraceSettings` is the per-ray policy shared by primary and secondary rays:
|
||||
|
||||
```slang
|
||||
public struct TraceSettings {
|
||||
float t_min; // start of the search interval
|
||||
float t_max; // end (exclusive); FLT_MAX for unbounded
|
||||
uint32_t max_cells; // structure cells visited
|
||||
uint32_t max_steps; // DDA iterations inside one cache cell
|
||||
bool any_hit; // first acceptable hit instead of nearest
|
||||
bool report_usage; // refresh LRU timestamps
|
||||
bool report_requests; // emit cache detail requests
|
||||
}
|
||||
```
|
||||
|
||||
The same tracer therefore serves the primary pass (closest hit, camera LOD,
|
||||
usage + requests) and shadow/visibility rays (`any_hit`, a finite `t_max`,
|
||||
requests off) without a separate code path.
|
||||
|
||||
---
|
||||
|
||||
## 5. `VoxelCacheTracer` algorithm
|
||||
@@ -216,18 +246,20 @@ world-space node size from the exponent/mantissa.
|
||||
|
||||
### 5.3 Main loop
|
||||
|
||||
Per iteration (max 500):
|
||||
Per iteration (`settings.max_steps`, 500 for primary rays):
|
||||
|
||||
1. Read the current child pointer.
|
||||
2. **Descend** while the pointer is `subdivided_valid()` (bits 31 and 30 set)
|
||||
1. If `offset_t + t >= settings.t_max`, stop: the rest of the ray is outside the
|
||||
requested interval.
|
||||
2. Read the current child pointer.
|
||||
3. **Descend** while the pointer is `subdivided_valid()` (bits 31 and 30 set)
|
||||
and the LOD policy says the node is still too large:
|
||||
- `scale_exp -= 2`, `current_node_index = pointer()`, push onto the
|
||||
`VoxelTraceStack`, report usage.
|
||||
3. **Request** if the LOD still wants detail, the pointer is subdividable, and
|
||||
it is not resident:
|
||||
trace stack, report usage when `settings.report_usage`.
|
||||
4. **Request** if `settings.report_requests`, the LOD still wants detail, the
|
||||
pointer is subdividable, and it is not resident:
|
||||
`requests[current_node_index][child_index] += 1`.
|
||||
4. **Hit test** using the occupancy mask and `IVoxelHit::shouldHit`.
|
||||
5. **DDA step**:
|
||||
5. **Hit test** using the occupancy mask and `IVoxelHit::shouldHit`.
|
||||
6. **DDA step**:
|
||||
- If the coarser 2×2×2 neighbourhood is empty
|
||||
(`(occupancy >> (child_index & 0b101010)) & 0x00330033 == 0`), advance one
|
||||
extra level (`adv_scale_exp++`) to skip empty space.
|
||||
@@ -236,26 +268,60 @@ Per iteration (max 500):
|
||||
- Find the most common ancestor of old and new positions via XOR and
|
||||
`firstbithigh`, then restore `scale_exp` and pop the stack to that level.
|
||||
|
||||
`Tracer::trace` bounds the structure walk with `settings.max_cells`. It skips
|
||||
cells that start at or beyond `t_max` or (for closest-hit traces) the best hit
|
||||
so far. Structure cells are not distance ordered, so it never breaks on those
|
||||
conditions.
|
||||
|
||||
### 5.4 Stack
|
||||
|
||||
```slang
|
||||
public struct VoxelTraceStack { public uint32_t stack[5]; }
|
||||
public interface ITraceStack {
|
||||
uint32_t get(uint32_t depth);
|
||||
[mutating] void set(uint32_t depth, uint32_t node);
|
||||
}
|
||||
|
||||
public struct LocalTraceStack : ITraceStack {
|
||||
public uint32_t entries[5];
|
||||
// get/set index entries[depth]
|
||||
}
|
||||
```
|
||||
|
||||
`voxel.slang` allocates one per thread in groupshared memory:
|
||||
The stack is **caller-owned**, so the tracer has no module-scope storage and no
|
||||
dependency on the dispatch shape. `voxel.slang` keeps one per thread as a local
|
||||
(`LocalTraceStack stack;`), which the driver can promote to registers or spill
|
||||
to per-thread scratch. If the primary pass regresses, the front-end can switch
|
||||
to groupshared storage without touching the trace core: implement `ITraceStack`
|
||||
over a module-scope groupshared array plus a per-thread base slot, and pass that
|
||||
handle instead.
|
||||
|
||||
```slang
|
||||
groupshared VoxelTraceStack stacks[256]; // 16x16 workgroup
|
||||
groupshared uint32_t trace_stacks[5 * 256];
|
||||
|
||||
public struct GroupsharedTraceStack : ITraceStack {
|
||||
public uint32_t base; // slot * 5
|
||||
|
||||
public uint32_t get(uint32_t depth) { return trace_stacks[base + depth]; }
|
||||
[mutating]
|
||||
public void set(uint32_t depth, uint32_t node) { trace_stacks[base + depth] = node; }
|
||||
}
|
||||
|
||||
// entry point
|
||||
GroupsharedTraceStack stack;
|
||||
stack.base = (local_location.x + local_location.y * 16) * 5;
|
||||
```
|
||||
|
||||
The index `stack[10 - scale_exp / 2]` hardcodes the supported depth. With
|
||||
Both variants compile from the same primary entry point; only the implementation
|
||||
type and its construction change.
|
||||
|
||||
The index `depth = 10 - scale_exp / 2` hardcodes the supported trace depth. With
|
||||
`N = 4` and `chunk_power = 5`, the deepest level used is 5, so the stack must
|
||||
hold entries for levels 1..5. Changing the branching factor or chunk depth
|
||||
requires changing both the stack size and this index formula.
|
||||
|
||||
### 5.5 Hit test
|
||||
|
||||
`voxel.slang` defines `ColorHit<2>`:
|
||||
`voxel_cache.slang` defines `ColorHit<2>` (shared by the primary and AO passes):
|
||||
|
||||
```slang
|
||||
bool shouldHit(VoxelCacheParameters<N> cache, uint32_t node_index, uint32_t child_index) {
|
||||
@@ -301,6 +367,23 @@ A non-wrapping version of the same idea. It is imported by `voxel.slang` but not
|
||||
instantiated; the Rust `FixedStructureTable` is used through the toroidal
|
||||
wrapper instead.
|
||||
|
||||
### 6.3 `bvh.slang` (active demo path)
|
||||
|
||||
`Bvh` walks a top-level BVH of transformed unit-cube objects and emits a `Cell`
|
||||
for each object the ray can enter. Traversal uses a restart trail instead of a
|
||||
stack, so the cells are **not** distance ordered (the tracer accumulates the
|
||||
nearest hit and skips rather than breaks).
|
||||
|
||||
`Bvh::max_t` bounds the traversal: nodes and objects whose entry distance is
|
||||
beyond it are culled. Primary rays set `FLT_MAX`; secondary passes (the AO pass)
|
||||
set their ray length, which avoids walking the infinite ray through every object
|
||||
behind the surface. The field assumes rigid rotation/translation transforms, so
|
||||
local and world distances match.
|
||||
|
||||
Each emitted cell carries `world_origin` and `cube_to_world`; `Tracer::trace`
|
||||
uses them to turn the cache's unit-cube hit into a world-space `Hit` and to
|
||||
rotate local attribute normals.
|
||||
|
||||
---
|
||||
|
||||
## 7. LOD
|
||||
@@ -344,18 +427,16 @@ Interpretation:
|
||||
```slang
|
||||
[shader("compute")]
|
||||
[numthreads(16,16,1)]
|
||||
void ray_march_compute(uint32_t3 location : SV_DispatchThreadID,
|
||||
uint32_t3 local_location : SV_GroupThreadID)
|
||||
void ray_march_compute(uint32_t3 location : SV_DispatchThreadID)
|
||||
```
|
||||
|
||||
1. Bounds-check against `constants.width/height`.
|
||||
2. Build a `VoxelCacheTracer<2, ColorHit<2>>` with usage + request reporting and
|
||||
the frame timestamp.
|
||||
3. Build a `ToroidalStructureTableTracer` with
|
||||
`extent = (chunk_width, chunk_alt, chunk_width)`.
|
||||
4. Build a `Tracer` and call `trace` with the per-thread stack.
|
||||
5. On hit, fetch normal and color from attribute pools and store position,
|
||||
normal, and albedo G-buffers.
|
||||
2. Build a `VoxelCacheTracer<2, ColorHit<2>>` with the frame timestamp.
|
||||
3. Fill in `TraceSettings` (unbounded closest-hit, 500 DDA steps, usage and
|
||||
requests on) and declare the per-ray `LocalTraceStack`.
|
||||
4. Build a `Tracer` (currently over `Bvh`) and call `trace` with the stack.
|
||||
5. On hit, store the world-space hit position, the world-space normal
|
||||
(`Hit::normal_to_world` rotates the local attribute normal), and albedo.
|
||||
6. On miss, store zero albedo.
|
||||
|
||||
`fetch_color` and `fetch_normal` hardcode the demo layout:
|
||||
@@ -368,6 +449,29 @@ attributes_pool[1][node * 64*3 + child*3 + 0..2] // normal
|
||||
This is the most important cross-language contract in the repo. If you reorder
|
||||
or resize attributes in `CacheLayout`, update these functions and `ColorHit`.
|
||||
|
||||
### 8.1 AO pass (`gi.slang`)
|
||||
|
||||
The AO pass is the secondary-ray smoke test. It reuses the same tracer, hit
|
||||
predicate, structure (`Bvh`) and LOD policy as the primary pass:
|
||||
|
||||
```slang
|
||||
TraceSettings settings;
|
||||
settings.t_min = 0.01; // skip the surface itself
|
||||
settings.t_max = 0.25; // short, local occlusion
|
||||
settings.max_cells = 64;
|
||||
settings.max_steps = 64;
|
||||
settings.any_hit = true; // visibility, not nearest
|
||||
settings.report_usage = true;
|
||||
settings.report_requests = false; // secondaries do not drive detail
|
||||
```
|
||||
|
||||
Per pixel it reconstructs a world-space origin/normal from the G-buffer, then
|
||||
traces four cosine-weighted hemisphere samples rotated by a per-pixel hash. The
|
||||
AO term is `1 - occluded / 4`, softened before multiplying albedo. The pass is
|
||||
incoherent by nature; the caller-owned `LocalTraceStack` is reused sequentially
|
||||
across the four rays, which is exactly why the stack is not tied to the
|
||||
workgroup shape.
|
||||
|
||||
---
|
||||
|
||||
## 9. WGSL cache shaders
|
||||
@@ -494,7 +598,7 @@ Do not do this casually. Required changes include:
|
||||
|
||||
- `VoxelCache<N>` / producer `N` and all 64-element assumptions;
|
||||
- `get_children_index` (`*4`, `*16`) and the child-mirror shifts;
|
||||
- `VoxelTraceStack` size and `10 - scale_exp/2` indexing;
|
||||
- `LocalTraceStack` size and `10 - scale_exp/2` indexing;
|
||||
- `StructureElement.pointers[64]`;
|
||||
- `fetch_color`/`fetch_normal` strides (`*64`, `*64*3`);
|
||||
- generated WGSL `CHILDREN_COUNT`;
|
||||
@@ -518,12 +622,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`, `crates/vxls/src/main.rs:563-611` | Works only because the mismatched bindings are unused. Any real GI work will hit validation errors. | High |
|
||||
| `gi.slang` is a simple AO pass, not a full GI solution (no bounces, no denoiser, 4 fixed hemisphere samples). | `shaders/gi.slang` | AO is noisy and view-dependent; it is a secondary-ray smoke test, not production lighting. | 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 |
|
||||
| `LocalTraceStack` size and indexing assume `N = 4` and `chunk_power = 5`. | `shaders/voxel_tracing.slang` (`ITraceStack`/`LocalTraceStack`), `shaders/voxel_cache.slang` | 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`). | `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`, `crates/vxls/src/main.rs:477-498` | Layout/limit errors appear as driver errors, not friendly validation messages. | Medium |
|
||||
| `voxel.slang` uses `create_shader_module_passthrough`, so wgpu validation is bypassed for the render pipeline. | `crates/vxls/src/main.rs:477-498` | Layout/limit errors appear as driver errors, not friendly validation messages. | Medium |
|
||||
|
||||
+36
-19
@@ -75,11 +75,12 @@ struct LocationPage {
|
||||
```
|
||||
|
||||
The cache never interprets these values; they are copied from insertion data and
|
||||
returned in requests so the producer knows which node is missing. In the demo,
|
||||
`node_id` is an `NTreeNodeLocator` and `anchor` is the toroidal table's world
|
||||
position plus a version word. The anchor is the structure identity, so child
|
||||
requests inherit it from their parent page and producers never need a host-side
|
||||
identity directory. `LocationPage` is 24 bytes.
|
||||
returned in requests so the producer knows which node is missing. On the Rust
|
||||
side, `node_id` is a `StructureLocator` encoded through `TreeLocator<N>`. In the
|
||||
demo the active BVH table uses zeroed anchors; the toroidal table variant uses
|
||||
world position plus a version word. The anchor is the structure identity, so
|
||||
child requests inherit it from their parent page and producers never need a
|
||||
host-side identity directory. `LocationPage` is 24 bytes.
|
||||
|
||||
On the Rust side, `node_id` and `producer_id` are the typed
|
||||
`StructureLocator` and `ProducerId` newtypes (both `#[repr(transparent)]`
|
||||
@@ -294,7 +295,7 @@ correctness requirement.
|
||||
| `insertion_parents` | dense `InsertionParent` per entry |
|
||||
| `destination_indices` | reset to `0xFFFFFFFF` by the validation pass; the insertion pass writes the destination page for accepted entries |
|
||||
| `valid_indices` | filled by the validation pass: compacted indices of valid entries |
|
||||
| `valid_count` | host writes `0`; the validation pass fills the amount of valid entries |
|
||||
| `valid_count` | `CacheInsertionData::upload` writes `0`; the validation pass fills the amount of valid entries |
|
||||
| attribute buffers | dense per-entry attribute payloads |
|
||||
|
||||
Build the layout from a producer payload with
|
||||
@@ -302,12 +303,24 @@ Build the layout from a producer payload with
|
||||
`CacheAttributeInit::External` and come first, `extras` are appended for
|
||||
GPU-only data.
|
||||
|
||||
Upload producer voxels with `CacheInsertionData::write_attributes(&queue, voxels)`.
|
||||
It accepts a slice in `[entry][child]` order (the child order is
|
||||
`x + 4*y + 16*z`), validates that `A::LAYOUT` is an `External` prefix of the
|
||||
cache layout with matching word counts and labels, and writes one buffer per
|
||||
attribute. It returns the entry count to write to `page_count_buffer`. The
|
||||
`DontTouch` attributes after the producer prefix are left untouched.
|
||||
Upload a complete batch with
|
||||
|
||||
```rust
|
||||
let entries: Vec<InsertionEntry<N>> = ...;
|
||||
insertion.upload(&queue, &entries, &voxels)?;
|
||||
```
|
||||
|
||||
`InsertionEntry` bundles the produced page's `InsertionInformation`, its
|
||||
`InsertionParent`, and its `LocationPage`. `voxels` is a slice in
|
||||
`[entry][child]` order (child order is `x + 4*y + 16*z`) and must contain
|
||||
exactly `entries.len() * N^3` elements. `upload` writes the structure, location,
|
||||
and parent arrays, resets `valid_count`, sets `page_count`, and delegates the
|
||||
attribute payloads to `write_attributes`. It does not pre-fill
|
||||
`destination_indices`; both validation shaders reset every entry they process.
|
||||
|
||||
`write_attributes` validates that `A::LAYOUT` matches the cache layout and writes
|
||||
one buffer per attribute. The `DontTouch` attributes after the producer prefix
|
||||
are left untouched.
|
||||
|
||||
`InsertionInformation<N>` is just `children: [ChildInformation; 64]`, where each
|
||||
`ChildInformation` uses the four-state encoding below.
|
||||
@@ -441,7 +454,10 @@ collapse them.
|
||||
`&request_informations[0..count]` and `&request_meta[0..count]`.
|
||||
|
||||
The callback is asynchronous by API, but the demo blocks on it with a
|
||||
`device.poll` loop. See [`pipeline-and-producers.md`](./pipeline-and-producers.md).
|
||||
`device.poll` loop. The callback only ingests the wire requests into the
|
||||
`RequestQueue`; the demo drains produced results and uploads the insertion batch
|
||||
after both request buffers have landed. See
|
||||
[`pipeline-and-producers.md`](./pipeline-and-producers.md).
|
||||
|
||||
### 5.4 What a producer receives
|
||||
|
||||
@@ -449,10 +465,10 @@ For an **internal** request:
|
||||
|
||||
- `node_id` and `anchor` identify the **parent** node.
|
||||
- `children_index` identifies which child is missing.
|
||||
- The producer must generate that child node and emit a `LocationPage` for the
|
||||
child (typically `parent_locator.child(x, y, z)`) with the same anchor.
|
||||
- It must also emit an internal `InsertionParent` carrying the parent page,
|
||||
child index, depth, parent identity, and anchor.
|
||||
- The producer generates that child node as a `ProducedNode`. It does not emit a
|
||||
`LocationPage` or `InsertionParent`: `RequestKey::node_locator::<N>()` names
|
||||
the produced node, and `ReadyItem::insertion_entry()` derives both from the
|
||||
request key.
|
||||
|
||||
For an **external** (structure-table) request:
|
||||
|
||||
@@ -460,8 +476,9 @@ For an **external** (structure-table) request:
|
||||
table currently points.
|
||||
- `node_id` and `children_index` are 0, and `RequestMeta.page_index` is
|
||||
`0xFFFFFFFF`.
|
||||
- The producer must generate a chunk root and emit its `LocationPage` plus an
|
||||
external `InsertionParent` with `producer_id`, `anchor`, and `table_slot`.
|
||||
- The producer generates a chunk root as a `ProducedNode`; the queue derives the
|
||||
root `LocationPage` and an external `InsertionParent` with `producer_id`,
|
||||
`anchor`, and `table_slot`.
|
||||
|
||||
There is no output-order requirement. Each insertion is attached to its parent
|
||||
by its own `InsertionParent`.
|
||||
|
||||
Reference in New Issue
Block a user