refactor: Factoring out attribtues

This commit is contained in:
2026-11-22 16:28:52 +01:00
parent bbf9c4d0a8
commit 42f85757d5
20 changed files with 767 additions and 85 deletions
+4 -2
View File
@@ -186,7 +186,9 @@ Consequences agents should keep in mind:
| `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-attributes/src/attributes.rs` | Producer-facing `Attribute`/`Attributes` traits and static attribute layouts | Active, durable |
| `crates/vxls-attributes-derive/src/lib.rs` | `#[derive(Attributes)]` layout generator | Active, durable |
| `crates/vxls-voxel-cache/src/layout.rs` | `CacheAttribute`/`CacheLayout`, bridge from `AttributesLayout`, 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 |
@@ -199,7 +201,7 @@ Consequences agents should keep in mind:
| `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/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 |
+27 -16
View File
@@ -331,32 +331,44 @@ production types are the durable contract; the driver is still the playground.
### 6.1 `crates/vxls-production/src/lib.rs`
Defines a more ambitious interface:
Defines the producer-facing attribute vocabulary and the production interface.
The attribute traits and layouts live in `vxls-attributes` and are re-exported
here:
```rust
// Identity types live in vxls-voxel-cache::schema and are re-exported here.
pub use voxel_cache::schema::{ProducerId, StructureAnchor, StructureLocator};
pub use vxls_attributes::{Attribute, AttributeDescriptor, Attributes, AttributesLayout};
pub use vxls_voxel_cache::schema::{ProducerId, StructureAnchor, StructureLocator};
pub trait VoxelAttributes<const N: usize> {
fn attribute_count() -> usize;
fn attribute(&self, attribute_index: usize) -> &[u32];
pub trait Attributes: Attribute {
const LAYOUT: AttributesLayout;
fn get_attr(&self, index: usize) -> &[u8];
fn get_attr_mut(&mut self, index: usize) -> &mut [u8];
}
pub trait VoxelProducer<const N: usize> {
type Output: VoxelAttributes<N>;
fn produce(
&self,
producer_id: ProducerId,
anchor: StructureAnchor,
locator: StructureLocator,
) -> (InsertionInformation<N>, [Self::Output; N * N * N]);
pub trait Producer<const N: usize, A: Attributes> {
fn produce(&self, anchor: StructureAnchor, locator: StructureLocator)
-> ProducedNode<N, A>;
}
pub struct ProducedNode<const N: usize, A: Attributes> {
pub insertion: InsertionInformation<N>,
pub attributes: [A; N * N * N],
}
```
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())?;
```
Differences from the demo interface:
- A node carries a `producer_id`, so one cache can mix multiple producers.
- Attributes are abstracted behind `VoxelAttributes`, avoiding hardcoded
- 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.
@@ -495,8 +507,7 @@ Minimum viable path with the current demo interface:
A production-ready producer should additionally:
- use the `VoxelProducer`/`VoxelAttributes` abstraction (or an equivalent) so
attributes are not hardcoded;
- use the `Producer`/`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;
+12
View File
@@ -297,6 +297,18 @@ correctness requirement.
| `valid_count` | host 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
`CacheLayout::from_attributes(&A::LAYOUT, &extras)`: producer attributes become
`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.
`InsertionInformation<N>` is just `children: [ChildInformation; 64]`, where each
`ChildInformation` uses the four-state encoding below.