euv-core 0.46.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::*;

/// One bounded staging buffer slot tracked by fence completion inside `GpuResourceRing`.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
pub struct GpuStagingSlot {
    /// Zero-based ring slot index.
    #[get(type(copy))]
    pub(crate) slot_index: usize,
    /// Unified resource handle backing this staging buffer slot.
    #[get(type(copy))]
    pub(crate) handle: RenderResourceHandle,
    /// Allocated byte capacity of this slot.
    #[get(type(copy))]
    pub(crate) capacity_bytes: usize,
    /// Payload bytes occupied by the latest submission in this slot.
    #[get(type(copy))]
    pub(crate) used_bytes: usize,
    /// Fence identifier guarding reuse until `completed_fence_id >= fence_id`.
    #[get(type(copy))]
    pub(crate) fence_id: u64,
    /// True while the GPU still holds a reference to this slot's buffer contents.
    #[get(type(copy))]
    pub(crate) in_flight: bool,
    /// Cumulative number of submissions served by reusing this slot without reallocating.
    #[get(type(copy))]
    pub(crate) reuse_count: u64,
}

/// Content-and-scale-addressed lookup key for a persistent GPU scroll tile texture.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct GpuScrollTileKey {
    /// Scene node arena index owning the scroll layer.
    #[get(type(copy))]
    pub(crate) layer_node_index: u32,
    /// Scene node generation preventing reuse across recycled node slots.
    #[get(type(copy))]
    pub(crate) layer_node_gen: u32,
    /// Horizontal tile coordinate in tile grid space.
    #[get(type(copy))]
    pub(crate) tile_x: i32,
    /// Vertical tile coordinate in tile grid space.
    #[get(type(copy))]
    pub(crate) tile_y: i32,
    /// IEEE-754 bit pattern of active DPI scale factor.
    #[get(type(copy))]
    pub(crate) dpr_bits: u32,
    /// Deterministic hash of tile content, styles, and font revision.
    #[get(type(copy))]
    pub(crate) content_hash: u64,
}

/// Cached persistent GPU scroll tile texture tracked by LRU age and in-flight GPU fence.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
pub struct GpuScrollTileEntry {
    /// Lookup key binding this tile to a layer generation, grid cell, DPI, and content hash.
    #[get(type(copy))]
    pub(crate) key: GpuScrollTileKey,
    /// Unified GPU texture handle for this cached tile.
    #[get(type(copy))]
    pub(crate) handle: RenderResourceHandle,
    /// Physical tile width in pixels.
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Physical tile height in pixels.
    #[get(type(copy))]
    pub(crate) height: u32,
    /// Resident GPU memory footprint in bytes (`width * height * 4`).
    #[get(type(copy))]
    pub(crate) byte_size: usize,
    /// Monotonic LRU access tick updated whenever this tile is sampled.
    #[get(type(copy))]
    pub(crate) last_used_tick: u64,
    /// Highest GPU fence referencing this tile texture.
    #[get(type(copy))]
    pub(crate) last_fence_id: u64,
    /// True when this tile is visible in the active viewport (protected from cold eviction).
    #[get(type(copy))]
    pub(crate) visible_this_frame: bool,
}

/// Evicted GPU texture or buffer awaiting GPU fence completion before final memory reclamation.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct DeferredGpuReclaim {
    /// Evicted unified resource handle awaiting retirement.
    #[get(type(copy))]
    pub(crate) handle: RenderResourceHandle,
    /// GPU fence identifier that must complete before releasing backing memory.
    #[get(type(copy))]
    pub(crate) retire_fence_id: u64,
    /// Reclaimable byte footprint held until `retire_fence_id` completes.
    #[get(type(copy))]
    pub(crate) byte_size: usize,
}

/// Bounded cross-frame GPU staging ring, persistent scroll tile cache, and fence-deferred reclamation tracker.
#[derive(Clone, Data, Debug)]
pub struct GpuResourceRing {
    /// Maximum bounded number of staging slots in the ring.
    #[get(type(copy))]
    pub(crate) max_slots: usize,
    /// Maximum aggregate byte ceiling across all staging slots.
    #[get(type(copy))]
    pub(crate) max_total_bytes: usize,
    /// Bounded staging slots reused across frames once their fence completes.
    pub(crate) slots: Vec<GpuStagingSlot>,
    /// Next monotonic GPU fence identifier to issue.
    #[get(type(copy))]
    pub(crate) next_fence_id: u64,
    /// Highest GPU fence identifier confirmed complete by the graphics queue.
    #[get(type(copy))]
    pub(crate) completed_fence_id: u64,
    /// Monotonic resource handle counter.
    #[get(type(copy))]
    pub(crate) next_handle_id: u64,
    /// Round-robin probe cursor into `slots`.
    #[get(type(copy))]
    pub(crate) cursor: usize,
    /// Cumulative number of staging buffer allocations or grows.
    #[get(type(copy))]
    pub(crate) total_allocations: u64,
    /// Cumulative number of zero-allocation staging slot reuses.
    #[get(type(copy))]
    pub(crate) total_reuses: u64,
    /// Cumulative number of optional prefetch uploads dropped because the ring was full.
    #[get(type(copy))]
    pub(crate) dropped_prefetch_uploads: u64,
    /// Cumulative number of required frame uploads deferred because all slots were in flight.
    #[get(type(copy))]
    pub(crate) deferred_frame_uploads: u64,
    /// Configured resident VRAM budget in bytes for persistent scroll tiles.
    #[get(type(copy))]
    pub(crate) tile_budget_bytes: usize,
    /// Current resident VRAM bytes occupied by live scroll tile textures.
    #[get(type(copy))]
    pub(crate) tile_resident_bytes: usize,
    /// Monotonic logical LRU clock for persistent scroll tile eviction.
    #[get(type(copy))]
    pub(crate) tile_clock: u64,
    /// Cumulative scroll tile cache hits.
    #[get(type(copy))]
    pub(crate) tile_hits: u64,
    /// Cumulative scroll tile cache misses.
    #[get(type(copy))]
    pub(crate) tile_misses: u64,
    /// Cumulative cold scroll tiles evicted under budget.
    #[get(type(copy))]
    pub(crate) tile_evictions: u64,
    /// Active persistent scroll tile texture entries.
    pub(crate) tiles: Vec<GpuScrollTileEntry>,
    /// Evicted GPU handles waiting for in-flight fences to complete before final reclamation.
    pub(crate) pending_reclaim: Vec<DeferredGpuReclaim>,
    /// Total bytes currently waiting in `pending_reclaim`.
    #[get(type(copy))]
    pub(crate) pending_reclaim_bytes: usize,
    /// Cumulative count of deferred GPU resources reclaimed after fence completion.
    #[get(type(copy))]
    pub(crate) reclaimed_count: u64,
}