katra-core 0.1.0

Katra3D core: shared vocabulary, error model, event model, IDs, and policy types.
Documentation
//! Typed identifiers. Newtype wrappers keep the type system honest: a
//! `RequestId` cannot be silently passed where a `Seq` is expected.

use serde::{Deserialize, Serialize};

macro_rules! id_type {
    ($name:ident, $doc:literal) => {
        #[doc = $doc]
        #[derive(
            Copy,
            Clone,
            Debug,
            Default,
            PartialEq,
            Eq,
            Hash,
            PartialOrd,
            Ord,
            Serialize,
            Deserialize,
        )]
        #[serde(transparent)]
        pub struct $name(pub u64);

        impl $name {
            /// The raw value.
            pub fn get(self) -> u64 {
                self.0
            }
        }

        impl From<u64> for $name {
            fn from(v: u64) -> Self {
                $name(v)
            }
        }

        impl From<$name> for u64 {
            fn from(v: $name) -> Self {
                v.0
            }
        }
    };
}

id_type!(Seq, "Global monotonic event sequence number within a trace session.");
id_type!(RequestId, "Correlation id for a logical request (an asset load, a frame, ...).");
id_type!(SpanId, "Id of a begin/end span (pair of events).");
id_type!(FileKey, "Hash of a file identity (path or object id).");
id_type!(Epoch, "Lifetime/recycling epoch. Higher = later.");
id_type!(OpId, "Id of an in-flight I/O or asynchronous operation.");
id_type!(AllocId, "Id of an allocation in a staging arena.");
id_type!(ArenaId, "Id of a staging arena.");

/// A `(domain, id)` reference to a resource (buffer, queue, descriptor heap,
/// pipeline, ...). `domain` selects the namespace; `id` is opaque.
pub type ResourceRef = (u32, u64);

/// Well-known resource domains for [`ResourceRef`].
pub mod resource_domain {
    /// A file.
    pub const FILE: u32 = 1;
    /// A D3D12 resource.
    pub const D3D12_RESOURCE: u32 = 2;
    /// A D3D12 queue.
    pub const D3D12_QUEUE: u32 = 3;
    /// A Vulkan buffer/image.
    pub const VK_OBJECT: u32 = 4;
    /// A Katra staging arena.
    pub const KATRA_ARENA: u32 = 5;
    /// A descriptor heap / descriptor set.
    pub const DESCRIPTOR_HEAP: u32 = 6;
    /// A pipeline / PSO.
    pub const PIPELINE: u32 = 7;
    /// A fence.
    pub const FENCE: u32 = 8;
}