euv-core 0.53.0

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::*;

/// Cached glyph placement inside the persistent incremental R8 GPU glyph atlas.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct GpuGlyphPlacement {
    /// Left texel coordinate inside the persistent R8 atlas texture.
    #[get(type(copy))]
    pub(crate) x: u32,
    /// Top texel coordinate inside the persistent R8 atlas texture.
    #[get(type(copy))]
    pub(crate) y: u32,
    /// Glyph coverage bitmap width in texels.
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Glyph coverage bitmap height in texels.
    #[get(type(copy))]
    pub(crate) height: u32,
    /// Pre-encoded normalized UV rectangle `[u0, v0, u1, v1]` in `[0..=65535]`.
    #[get(type(copy))]
    pub(crate) uv_rect: [u16; 4],
}

/// Persistent incremental shelf-packed R8 glyph atlas that tracks newly added glyph dirty sub-rects for GPU upload.
#[derive(Clone, Data, Debug)]
pub struct IncrementalGpuGlyphAtlas {
    /// Backing R8 atlas texture width in texels.
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Backing R8 atlas texture height in texels.
    #[get(type(copy))]
    pub(crate) height: u32,
    /// Backing single-channel R8 pixel storage aligned to `width * height`.
    pub(crate) pixels: Vec<u8>,
    /// Current shelf packing X cursor in texels.
    #[get(type(copy))]
    pub(crate) cursor_x: u32,
    /// Current shelf packing Y cursor in texels.
    #[get(type(copy))]
    pub(crate) cursor_y: u32,
    /// Tallest glyph height in the active shelf row.
    #[get(type(copy))]
    pub(crate) shelf_height: u32,
    /// Per-glyph atlas placements indexed by `GlyphKey`.
    pub(crate) placements: HashMap<GlyphKey, GpuGlyphPlacement>,
    /// Pending dirty sub-rectangles waiting to upload via `upload_texture_dirty_rect`.
    pub(crate) pending_dirty_rects: Vec<PixelDirtyRect>,
    /// Pending dirty sub-rectangles queued exclusively for `GpuFrameSubmission` platform swapchain uploads.
    pub(crate) submission_dirty_rects: Vec<PixelDirtyRect>,
    /// Last `GlyphAtlas::revision` synchronized into this GPU atlas.
    #[get(type(copy))]
    pub(crate) synced_revision: u64,
    /// Number of entries synchronized at `synced_revision` to detect evictions/clears.
    #[get(type(copy))]
    pub(crate) synced_entry_count: usize,
    /// True when the backing GPU texture was resized and requires a full upload once.
    #[get(type(copy))]
    pub(crate) needs_full_upload: bool,
    /// True when platform direct-GPU submission still requires an initial or post-resize full atlas upload.
    #[get(type(copy))]
    pub(crate) submission_needs_full_upload: bool,
    /// Cumulative R8 bytes uploaded to the GPU glyph texture across all frames.
    #[get(type(copy))]
    pub(crate) total_uploaded_bytes: u64,
}

/// Cached RGBA8 image placement inside the persistent incremental GPU image atlas.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct GpuImagePlacement {
    /// Left texel coordinate inside the persistent RGBA8 atlas texture.
    #[get(type(copy))]
    pub(crate) x: u32,
    /// Top texel coordinate inside the persistent RGBA8 atlas texture.
    #[get(type(copy))]
    pub(crate) y: u32,
    /// Packed image width in texels.
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Packed image height in texels.
    #[get(type(copy))]
    pub(crate) height: u32,
    /// Pre-encoded normalized UV rectangle `[u0, v0, u1, v1]` in `[0..=65535]`.
    #[get(type(copy))]
    pub(crate) uv_rect: [u16; 4],
}

/// Persistent shelf-packed RGBA8 GPU image atlas with content-hash caching and incremental dirty sub-rectangle tracking.
#[derive(Clone, Data, Debug)]
pub struct IncrementalGpuImageAtlas {
    /// Backing RGBA8 atlas texture width in texels.
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Backing RGBA8 atlas texture height in texels.
    #[get(type(copy))]
    pub(crate) height: u32,
    /// Backing RGBA8 pixel storage aligned to `width * height * 4`.
    pub(crate) pixels: Vec<u8>,
    /// Current shelf packing X cursor in texels.
    #[get(type(copy))]
    pub(crate) cursor_x: u32,
    /// Current shelf packing Y cursor in texels.
    #[get(type(copy))]
    pub(crate) cursor_y: u32,
    /// Tallest image height in the active shelf row.
    #[get(type(copy))]
    pub(crate) shelf_height: u32,
    /// Per-image atlas placements indexed by fast content hash.
    pub(crate) placements: HashMap<u64, GpuImagePlacement>,
    /// Pending dirty sub-rectangles waiting for direct-GPU platform swapchain upload.
    pub(crate) submission_dirty_rects: Vec<PixelDirtyRect>,
    /// True when the backing RGBA8 atlas texture requires a full upload on next submission.
    #[get(type(copy))]
    pub(crate) submission_needs_full_upload: bool,
    /// Monotonic revision incremented whenever image pixels are packed or repacked.
    #[get(type(copy))]
    pub(crate) revision: u64,
}

/// Scheduled render-graph frame plan listing the active passes and resource requirements for one frame.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct RenderGraphFramePlan {
    /// Ordered GPU passes scheduled for execution in this frame.
    pub(crate) passes: Vec<RenderGraphPassKind>,
    /// Physical surface width in pixels.
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Physical surface height in pixels.
    #[get(type(copy))]
    pub(crate) height: u32,
    /// Number of coalesced dirty buffer spans scheduled for Pass 1 upload.
    #[get(type(copy))]
    pub(crate) dirty_span_count: usize,
    /// Number of dirty glyph/image atlas rectangles scheduled for Pass 1 upload.
    #[get(type(copy))]
    pub(crate) atlas_dirty_rect_count: usize,
    /// Number of Dual-Kawase blur regions scheduled for Pass 3.
    #[get(type(copy))]
    pub(crate) blur_pass_count: usize,
    /// External GPU texture handle scheduled for Pass 2 (`0` when unused).
    #[get(type(copy))]
    pub(crate) external_texture_handle: usize,
}

/// Execution telemetry receipt returned by `RenderGraph::execute_frame`.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct RenderGraphExecutionReceipt {
    /// Ordered passes actually executed for this frame.
    pub(crate) executed_passes: Vec<RenderGraphPassKind>,
    /// Monotonic GPU fence identifier assigned to this submission.
    #[get(type(copy))]
    pub(crate) submitted_fence_id: u64,
    /// Highest completed GPU fence observed without blocking before submission.
    #[get(type(copy))]
    pub(crate) observed_completed_fence_id: u64,
    /// Coalesced primitive bytes uploaded during Pass 1.
    #[get(type(copy))]
    pub(crate) dirty_upload_bytes: usize,
    /// Full uncoalesced primitive byte size for upload-savings measurement.
    #[get(type(copy))]
    pub(crate) full_upload_bytes: usize,
    /// Incremental glyph/image atlas bytes uploaded during Pass 1.
    #[get(type(copy))]
    pub(crate) atlas_upload_bytes: usize,
    /// Number of Dual-Kawase `blur_down` + `blur_up` blur regions executed during Pass 3.
    #[get(type(copy))]
    pub(crate) blur_passes_executed: usize,
    /// Total hardware draw calls executed across Pass 3 and Pass 4.
    #[get(type(copy))]
    pub(crate) draw_calls: usize,
    /// Measured GPU compute duration in nanoseconds (`LAST_GPU_COMPUTE_NS`).
    #[get(type(copy))]
    pub(crate) gpu_compute_ns: u64,
    /// Measured GPU render duration in nanoseconds (`LAST_GPU_RENDER_NS`).
    #[get(type(copy))]
    pub(crate) gpu_render_ns: u64,
}

/// Surface target and auxiliary pass configuration supplied to `RenderGraph::plan_frame` and `RenderGraph::execute_frame`.
#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
pub struct RenderGraphFrameTarget {
    /// Physical surface width in pixels.
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Physical surface height in pixels.
    #[get(type(copy))]
    pub(crate) height: u32,
    /// Surface background clear color.
    #[get(type(copy))]
    pub(crate) clear_color: Color,
    /// Optional external 3D/Fluid GPU texture handle scheduled for Pass 2 (`0` when absent).
    #[get(type(copy))]
    pub(crate) external_texture_handle: usize,
}

/// Pass workload counts supplied to `RenderGraph::plan_frame`.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct RenderGraphPlanCounts {
    /// Whether Pass 0 GPU compute layout is active.
    #[get(type(copy))]
    pub(crate) has_compute_layout: bool,
    /// Number of coalesced dirty primitive spans scheduled for Pass 1.
    #[get(type(copy))]
    pub(crate) dirty_span_count: usize,
    /// Number of dirty glyph/image atlas rectangles scheduled for Pass 1.
    #[get(type(copy))]
    pub(crate) atlas_dirty_rect_count: usize,
    /// Number of Dual-Kawase backdrop blur regions scheduled for Pass 3.
    #[get(type(copy))]
    pub(crate) blur_pass_count: usize,
}

/// Unified render-graph scheduler coordinating Pass 0..4, dirty-span uploads, incremental glyph atlas sync, and pipelined fences.
#[derive(Clone, Data, Debug)]
pub struct RenderGraph {
    /// Configured maximum frames in flight (`2` default for CPU/GPU pipelined overlap).
    #[get(type(copy))]
    pub(crate) max_frames_in_flight: u32,
    /// Coalesced dirty-range uploader for retained 64-byte UI primitives.
    pub(crate) dirty_coalescer: DirtySpanCoalescer,
    /// Persistent incremental R8 glyph atlas synchronized via dirty sub-rects.
    pub(crate) gpu_glyph_atlas: IncrementalGpuGlyphAtlas,
    /// Most recent scheduled frame plan.
    pub(crate) last_plan: RenderGraphFramePlan,
    /// Most recent execution telemetry receipt.
    pub(crate) last_receipt: RenderGraphExecutionReceipt,
    /// Cumulative frames executed through this render graph.
    #[get(type(copy))]
    pub(crate) executed_frames: u64,
}