euv-core 0.48.1

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Unique owner identity pairing ownership domain, owner identifier, and monotonic generation.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, Ord, PartialEq, PartialOrd)]
pub struct ResourceOwnerId {
    /// Ownership domain (`Page`, `Surface`, `DynamicModule`, etc.).
    #[get(type(copy))]
    pub(crate) kind: ResourceOwnerKind,
    /// Domain-local owner identifier (e.g. `page_id` or `surface_id`).
    #[get(type(copy))]
    pub(crate) owner_id: u64,
    /// Monotonic generation distinguishing recreated instances reusing the same `owner_id`.
    #[get(type(copy))]
    pub(crate) generation: u64,
}

/// Single-owner tracked allocation record keyed by `(kind, handle_id)` to prevent double-counting.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
pub(crate) struct TrackedResourceRecord {
    /// Single authoritative owner responsible for releasing this resource.
    #[get(type(copy))]
    pub(crate) owner: ResourceOwnerId,
    /// Tracked resource category.
    #[get(type(copy))]
    pub(crate) kind: TrackedResourceKind,
    /// Unique resource handle identifier within `kind`.
    #[get(type(copy))]
    pub(crate) handle_id: u64,
    /// Estimated memory/VRAM byte footprint.
    #[get(type(copy))]
    pub(crate) byte_size: usize,
    /// Retention classification (`Active`, `ExpectedRetained`, or `PendingFenceRelease`).
    #[get(type(copy))]
    pub(crate) retention: ResourceRetentionClass,
    /// GPU fence identifier that must complete before pending release is considered overdue (`0` when immediate).
    #[get(type(copy))]
    pub(crate) retire_fence_id: u64,
}

/// Diagnostic record identifying one resource still alive under a destroyed owner past its fence and grace period.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct LeakedResourceEntry {
    /// Destroyed owner still referenced by this resource.
    #[get(type(copy))]
    pub(crate) owner: ResourceOwnerId,
    /// Leaked resource category.
    #[get(type(copy))]
    pub(crate) kind: TrackedResourceKind,
    /// Resource handle identifier.
    #[get(type(copy))]
    pub(crate) handle_id: u64,
    /// Tracked leaked byte footprint.
    #[get(type(copy))]
    pub(crate) byte_size: usize,
    /// Monotonic timestamp in milliseconds when `owner` was destroyed.
    #[get(type(copy))]
    pub(crate) destroyed_at_ms: u64,
    /// Required GPU retirement fence identifier (`0` for non-GPU resources).
    #[get(type(copy))]
    pub(crate) retire_fence_id: u64,
}

/// Structured framework resource accounting snapshot separating `expected_retained` from `destroyed_owner.live_objects`.
#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
pub struct ResourceAccountingSnapshot {
    /// Live active page count.
    #[get(type(copy))]
    pub(crate) pages_active: usize,
    /// Live frozen page count within retention budget.
    #[get(type(copy))]
    pub(crate) pages_frozen: usize,
    /// Evicted cold page snapshot count.
    #[get(type(copy))]
    pub(crate) pages_evicted: usize,
    /// Cumulative explicitly destroyed page count.
    #[get(type(copy))]
    pub(crate) pages_destroyed: u64,
    /// Live tracked scene node count.
    #[get(type(copy))]
    pub(crate) scene_nodes: usize,
    /// Live tracked reactive effect count.
    #[get(type(copy))]
    pub(crate) reactive_effects: usize,
    /// Live tracked subscription count.
    #[get(type(copy))]
    pub(crate) subscriptions: usize,
    /// Live tracked timer count.
    #[get(type(copy))]
    pub(crate) timers: usize,
    /// Live tracked pending async task count.
    #[get(type(copy))]
    pub(crate) pending_async_tasks: usize,
    /// Live tracked dynamic module instance count.
    #[get(type(copy))]
    pub(crate) dynamic_instances: usize,
    /// Live tracked native OS handle count.
    #[get(type(copy))]
    pub(crate) os_handles: usize,
    /// Live tracked GPU texture handle count.
    #[get(type(copy))]
    pub(crate) gpu_textures: usize,
    /// Live tracked GPU buffer handle count.
    #[get(type(copy))]
    pub(crate) gpu_buffers: usize,
    /// Aggregate live GPU texture + buffer bytes.
    #[get(type(copy))]
    pub(crate) gpu_live_bytes: usize,
    /// Aggregate live bounded cache bytes.
    #[get(type(copy))]
    pub(crate) retained_cache_bytes: usize,
    /// Total intentionally retained objects (`ExpectedRetained` + non-overdue `PendingFenceRelease`).
    #[get(type(copy))]
    pub(crate) expected_retained_objects: usize,
    /// Total intentionally retained bytes (`ExpectedRetained` + non-overdue `PendingFenceRelease`).
    #[get(type(copy))]
    pub(crate) expected_retained_bytes: usize,
    /// Count of objects still live under a destroyed owner past its fence and grace period (`destroyed_owner.live_objects`).
    #[get(type(copy))]
    pub(crate) destroyed_owner_live_objects: usize,
    /// Total bytes still live under a destroyed owner past its fence and grace period.
    #[get(type(copy))]
    pub(crate) destroyed_owner_live_bytes: usize,
    /// Detailed owner-attributed leak entries for every object counted in `destroyed_owner_live_objects`.
    pub(crate) leaks: Vec<LeakedResourceEntry>,
}

/// Low-overhead single-owner framework resource ownership accountant.
#[derive(Clone, Data, Debug, Default)]
pub struct ResourceAccountant {
    /// Single-owner registry mapping `(TrackedResourceKind, handle_id)` to its live record.
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(skip)]
    pub(crate) live_resources: HashMap<(TrackedResourceKind, u64), TrackedResourceRecord>,
    /// Destroyed owners mapped to `(destroyed_at_ms, retire_fence_id)` for leak attribution.
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(skip)]
    pub(crate) destroyed_owners: HashMap<ResourceOwnerId, (u64, u64)>,
    /// Highest completed GPU submission fence identifier.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) completed_gpu_fence_id: u64,
    /// Last synced active page count.
    #[get(type(copy))]
    pub(crate) pages_active: usize,
    /// Last synced frozen page count.
    #[get(type(copy))]
    pub(crate) pages_frozen: usize,
    /// Last synced evicted page count.
    #[get(type(copy))]
    pub(crate) pages_evicted: usize,
    /// Cumulative explicitly destroyed page count.
    #[get(type(copy))]
    pub(crate) pages_destroyed: u64,
    /// Cumulative resource registrations accepted.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) total_registrations: u64,
    /// Cumulative resource releases completed.
    #[get(type(copy))]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) total_releases: u64,
}