refactor: fixing type inconsistencies in cache types

This commit is contained in:
2026-11-18 00:01:47 +01:00
parent 95a45a57d7
commit b65632aab3
6 changed files with 54 additions and 46 deletions
+3 -14
View File
@@ -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`])
+8 -8
View File
@@ -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<T> ReadyItem<T>
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<T> ReadyItem<T>
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);
}
+23 -11
View File
@@ -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,
+10 -10
View File
@@ -1876,8 +1876,8 @@ fn fullfill_request_tree<const N: usize>(
children: [ChildInformation::new(false, root.color.3 != 0.); N * N * N],
},
LocationPage {
node_id: StructureLocator::from(TreeLocator::<N>::root()).0,
producer_id: 0,
node_id: StructureLocator::from(TreeLocator::<N>::root()),
producer_id: ProducerId(0),
anchor: StructureAnchor::zeroed(),
},
)
@@ -1902,8 +1902,8 @@ fn fullfill_request_tree<const N: usize>(
children: std::array::from_fn(|i| children[i]),
},
LocationPage {
node_id: StructureLocator::from(TreeLocator::<N>::root()).0,
producer_id: 0,
node_id: StructureLocator::from(TreeLocator::<N>::root()),
producer_id: ProducerId(0),
anchor: StructureAnchor::zeroed(),
},
)
@@ -1939,8 +1939,8 @@ fn fullfill_request_tree<const N: usize>(
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::<N>::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,
};
}