Skip to main content

katra_core/
ids.rs

1//! Typed identifiers. Newtype wrappers keep the type system honest: a
2//! `RequestId` cannot be silently passed where a `Seq` is expected.
3
4use serde::{Deserialize, Serialize};
5
6macro_rules! id_type {
7    ($name:ident, $doc:literal) => {
8        #[doc = $doc]
9        #[derive(
10            Copy,
11            Clone,
12            Debug,
13            Default,
14            PartialEq,
15            Eq,
16            Hash,
17            PartialOrd,
18            Ord,
19            Serialize,
20            Deserialize,
21        )]
22        #[serde(transparent)]
23        pub struct $name(pub u64);
24
25        impl $name {
26            /// The raw value.
27            pub fn get(self) -> u64 {
28                self.0
29            }
30        }
31
32        impl From<u64> for $name {
33            fn from(v: u64) -> Self {
34                $name(v)
35            }
36        }
37
38        impl From<$name> for u64 {
39            fn from(v: $name) -> Self {
40                v.0
41            }
42        }
43    };
44}
45
46id_type!(Seq, "Global monotonic event sequence number within a trace session.");
47id_type!(RequestId, "Correlation id for a logical request (an asset load, a frame, ...).");
48id_type!(SpanId, "Id of a begin/end span (pair of events).");
49id_type!(FileKey, "Hash of a file identity (path or object id).");
50id_type!(Epoch, "Lifetime/recycling epoch. Higher = later.");
51id_type!(OpId, "Id of an in-flight I/O or asynchronous operation.");
52id_type!(AllocId, "Id of an allocation in a staging arena.");
53id_type!(ArenaId, "Id of a staging arena.");
54
55/// A `(domain, id)` reference to a resource (buffer, queue, descriptor heap,
56/// pipeline, ...). `domain` selects the namespace; `id` is opaque.
57pub type ResourceRef = (u32, u64);
58
59/// Well-known resource domains for [`ResourceRef`].
60pub mod resource_domain {
61    /// A file.
62    pub const FILE: u32 = 1;
63    /// A D3D12 resource.
64    pub const D3D12_RESOURCE: u32 = 2;
65    /// A D3D12 queue.
66    pub const D3D12_QUEUE: u32 = 3;
67    /// A Vulkan buffer/image.
68    pub const VK_OBJECT: u32 = 4;
69    /// A Katra staging arena.
70    pub const KATRA_ARENA: u32 = 5;
71    /// A descriptor heap / descriptor set.
72    pub const DESCRIPTOR_HEAP: u32 = 6;
73    /// A pipeline / PSO.
74    pub const PIPELINE: u32 = 7;
75    /// A fence.
76    pub const FENCE: u32 = 8;
77}