refactor: Factoring out attribtues
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user