diff --git a/crates/vxls-production/src/producer.rs b/crates/vxls-production/src/producer.rs index e2f5798..d6809bc 100644 --- a/crates/vxls-production/src/producer.rs +++ b/crates/vxls-production/src/producer.rs @@ -1,24 +1,13 @@ //! Producers and the nodes they produce. -use bytemuck::Pod; -use bytemuck::Zeroable; use vxls_voxel_cache::schema::InsertionInformation; +pub use vxls_voxel_cache::schema::ProducerId; +pub use vxls_voxel_cache::schema::StructureLocator; + use crate::StructureAnchor; use crate::attributes::Attributes; -/// A cache might hold data owned by multiple different producers. To discriminate where to route the -/// request, a node is always tagged by a [`ProducerId`]. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Zeroable, Pod)] -#[repr(transparent)] -pub struct ProducerId(pub u32); - -/// A request can come from anywhere inside the structure. The producer can thus tag each node with -/// a locator, to know where the request was issued. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Zeroable, Pod)] -#[repr(transparent)] -pub struct StructureLocator(pub u32); - /// A node produced by a [`Producer`], ready to be inserted into the cache. /// /// The producer only provides the structure of the page ([`InsertionInformation`]) diff --git a/crates/vxls-production/src/request_queue.rs b/crates/vxls-production/src/request_queue.rs index 999c45c..e06b46b 100644 --- a/crates/vxls-production/src/request_queue.rs +++ b/crates/vxls-production/src/request_queue.rs @@ -158,7 +158,7 @@ impl IncomingRequest /// `node_id == 0` (which also describes child 0 of the root). pub fn from_wire(request: &RequestInformation, meta: &RequestMeta) -> Self { - let producer_id = ProducerId(request.producer_id); + let producer_id = request.producer_id; let anchor = request.anchor; let (key, priority) = if meta.page_index == NO_PARENT_PAGE @@ -174,7 +174,7 @@ impl IncomingRequest RequestKey::child( producer_id, anchor, - StructureLocator(request.node_id), + request.node_id, request.children_index, ), RequestPriority::child(request.demand, meta.depth), @@ -225,7 +225,7 @@ impl ReadyItem match self.key.target { RequestTarget::Root => InsertionParent::external( - self.key.producer_id.0, + self.key.producer_id, self.key.anchor, self.meta.table_slot, ), @@ -241,7 +241,7 @@ impl ReadyItem children_index, ..self.meta }; - InsertionParent::internal(&meta, parent.0, self.key.producer_id.0, self.key.anchor) + InsertionParent::internal(&meta, parent, self.key.producer_id, self.key.anchor) } } } @@ -856,9 +856,9 @@ mod tests { ( RequestInformation { - node_id: node, + node_id: StructureLocator(node), children_index: child, - producer_id: producer, + producer_id: ProducerId(producer), demand, anchor, }, @@ -969,7 +969,7 @@ mod tests let external = ready[0].insertion_parent(); assert!(external.is_external()); assert_eq!(external.page_index, NO_PARENT_PAGE); - assert_eq!(external.producer_id, PRODUCER.0); + assert_eq!(external.producer_id, PRODUCER); assert_eq!(external.anchor, ANCHOR); assert_eq!(external.table_slot, 5); @@ -978,7 +978,7 @@ mod tests assert_eq!(internal.page_index, 7); assert_eq!(internal.children_index, 2); assert_eq!(internal.depth, 3); - assert_eq!(internal.node_id, 4); + assert_eq!(internal.node_id, StructureLocator(4)); assert_eq!(internal.anchor, ANCHOR); assert_eq!(internal.table_slot, NO_TABLE_SLOT); } diff --git a/crates/vxls-voxel-cache/src/schema.rs b/crates/vxls-voxel-cache/src/schema.rs index 61f0c2c..05c736e 100644 --- a/crates/vxls-voxel-cache/src/schema.rs +++ b/crates/vxls-voxel-cache/src/schema.rs @@ -149,6 +149,18 @@ impl StructureAnchor } } +/// A cache might hold data owned by multiple different producers. To discriminate where to route the +/// request, a node is always tagged by a [`ProducerId`]. +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Zeroable, Pod)] +#[repr(transparent)] +pub struct ProducerId(pub u32); + +/// A request can come from anywhere inside the structure. The producer can thus tag each node with +/// a locator, to know where the request was issued. +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Zeroable, Pod)] +#[repr(transparent)] +pub struct StructureLocator(pub u32); + /// Data stored alongside cache structure so that application can locate a /// particular request #[derive(Debug, Clone, Copy, Zeroable, Pod)] @@ -156,10 +168,10 @@ impl StructureAnchor pub struct LocationPage { /// Identifier for locating this particular node within the structure - pub node_id: u32, + pub node_id: StructureLocator, /// Identifier of the producer that owns this node - pub producer_id: u32, + pub producer_id: ProducerId, /// Opaque content identity inherited from the root request. pub anchor: StructureAnchor, @@ -196,13 +208,13 @@ impl DepthPage pub struct RequestInformation { /// Identifier for locating this particular node within the structure - pub node_id: u32, + pub node_id: StructureLocator, /// The index of the children on which the request was issued pub children_index: u32, /// Identifier of the producer that owns the requesting node - pub producer_id: u32, + pub producer_id: ProducerId, /// The amount of times this request was emitted this frame. Higher means more urgent. pub demand: u32, @@ -274,11 +286,11 @@ pub struct InsertionParent /// Depth of the parent. [`NO_PARENT_PAGE`] for external roots. pub depth: u32, - /// Locator of the parent inside the structure. `0` for external roots. - pub node_id: u32, + /// Locator of the parent inside the structure. `StructureLocator(0)` for external roots. + pub node_id: StructureLocator, /// Producer that owns the parent. - pub producer_id: u32, + pub producer_id: ProducerId, /// Opaque content identity of the structure the parent belongs to. pub anchor: StructureAnchor, @@ -293,8 +305,8 @@ impl InsertionParent /// Parent information for a child of a resident cache page. pub fn internal( meta: &RequestMeta, - node_id: u32, - producer_id: u32, + node_id: StructureLocator, + producer_id: ProducerId, anchor: StructureAnchor, ) -> Self { @@ -311,14 +323,14 @@ impl InsertionParent } /// Parent information for the root of an external structure. - pub fn external(producer_id: u32, anchor: StructureAnchor, table_slot: u32) -> Self + pub fn external(producer_id: ProducerId, anchor: StructureAnchor, table_slot: u32) -> Self { Self { kind: InsertionParentKind::EXTERNAL.raw(), page_index: NO_PARENT_PAGE, children_index: 0, depth: NO_PARENT_PAGE, - node_id: 0, + node_id: StructureLocator(0), producer_id, anchor, table_slot, diff --git a/crates/vxls/src/main.rs b/crates/vxls/src/main.rs index ba43cce..bd95c4b 100644 --- a/crates/vxls/src/main.rs +++ b/crates/vxls/src/main.rs @@ -1876,8 +1876,8 @@ fn fullfill_request_tree( children: [ChildInformation::new(false, root.color.3 != 0.); N * N * N], }, LocationPage { - node_id: StructureLocator::from(TreeLocator::::root()).0, - producer_id: 0, + node_id: StructureLocator::from(TreeLocator::::root()), + producer_id: ProducerId(0), anchor: StructureAnchor::zeroed(), }, ) @@ -1902,8 +1902,8 @@ fn fullfill_request_tree( children: std::array::from_fn(|i| children[i]), }, LocationPage { - node_id: StructureLocator::from(TreeLocator::::root()).0, - producer_id: 0, + node_id: StructureLocator::from(TreeLocator::::root()), + producer_id: ProducerId(0), anchor: StructureAnchor::zeroed(), }, ) @@ -1939,8 +1939,8 @@ fn fullfill_request_tree( children: std::array::from_fn(|i| children[i]), }, LocationPage { - node_id: StructureLocator::from(loc).0, - producer_id: 0, + node_id: StructureLocator::from(loc), + producer_id: ProducerId(0), anchor: StructureAnchor::zeroed(), }, ) @@ -1993,8 +1993,8 @@ where node = generator.produce_node(0, 0, 0, 0, (chunk_x, chunk_y, chunk_z)); let locator: StructureLocator = TreeLocator::::root().into(); location = LocationPage { - node_id: locator.0, - producer_id: request.producer_id.0, + node_id: locator, + producer_id: request.producer_id, anchor, }; } @@ -2031,8 +2031,8 @@ where let st_loc: StructureLocator = child_locator.into(); location = LocationPage { - node_id: st_loc.0 as u32, - producer_id: request.producer_id.0, + node_id: st_loc, + producer_id: request.producer_id, anchor, }; } diff --git a/docs/pipeline-and-producers.md b/docs/pipeline-and-producers.md index 9c7c25a..f730241 100644 --- a/docs/pipeline-and-producers.md +++ b/docs/pipeline-and-producers.md @@ -84,6 +84,9 @@ struct RequestMeta { - `table_slot` is table-private placement and may change while the anchor stays the same. It is deliberately not part of a request key. +`node_id` and `producer_id` are `StructureLocator` and `ProducerId` on the Rust +side (transparent over `u32`); the layout above is the GPU wire layout. + ### 2.2 Response One `CacheInsertionData` entry per produced node. Entries do **not** have to be in @@ -331,9 +334,8 @@ production types are the durable contract; the driver is still the playground. Defines a more ambitious interface: ```rust -pub struct ProducerId(pub u32); -pub struct StructureLocator(pub u32); -pub use crate::voxel_cache::schema::StructureAnchor; +// Identity types live in vxls-voxel-cache::schema and are re-exported here. +pub use voxel_cache::schema::{ProducerId, StructureAnchor, StructureLocator}; pub trait VoxelAttributes { fn attribute_count() -> usize; diff --git a/docs/voxel-cache.md b/docs/voxel-cache.md index 8e51edc..8a228dd 100644 --- a/docs/voxel-cache.md +++ b/docs/voxel-cache.md @@ -81,6 +81,11 @@ 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)]` +over `u32`), so the on-GPU layout above is unchanged. The same applies to +`RequestInformation` and `InsertionParent`. + ### 2.3 Depth page ```rust