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

/// Generation-tagged backend-agnostic resource handle shared between CPU reference and GPU direct-draw backends.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct RenderResourceHandle {
    /// Monotonic resource identifier within the owning renderer.
    #[get(type(copy))]
    pub(crate) id: u64,
    /// Reuse generation counter rejecting stale handles after reclamation.
    #[get(type(copy))]
    pub(crate) generation: u32,
    /// Semantic kind of GPU/CPU render resource.
    #[get(type(copy))]
    pub(crate) kind: RenderResourceKind,
    /// Tracked byte footprint of this resource.
    #[get(type(copy))]
    pub(crate) byte_size: usize,
    /// Last GPU fence identifier referencing this handle (`0` when idle).
    #[get(type(copy))]
    pub(crate) fence_id: u64,
}

/// Immutable visual fidelity contract proving fallback never degrades shadows, blur, AA, clipping, color space, or resolution.
#[derive(Clone, Copy, Debug, Getter, New, PartialEq)]
pub struct RenderSemanticsContract {
    /// Active framebuffer color space shared by CPU and GPU backends.
    #[get(type(copy))]
    pub(crate) color_space: ColorSpace,
    /// Active anti-aliasing quality mode.
    #[get(type(copy))]
    pub(crate) antialiasing: AntialiasingMode,
    /// Whether premultiplied linear-light alpha blending is enforced.
    #[get(type(copy))]
    pub(crate) premultiplied_alpha: bool,
    /// Whether full box-shadow evaluation is enabled (must remain invariant across fallback).
    #[get(type(copy))]
    pub(crate) shadows_enabled: bool,
    /// Whether full backdrop-blur evaluation is enabled (must remain invariant across fallback).
    #[get(type(copy))]
    pub(crate) backdrop_blur_enabled: bool,
    /// Whether exact rounded and axis-aligned clipping is enabled (must remain invariant across fallback).
    #[get(type(copy))]
    pub(crate) clipping_enabled: bool,
    /// Active physical resolution scale factor (must remain invariant across fallback).
    #[get(type(copy))]
    pub(crate) resolution_scale: f32,
}

/// Tunable hysteresis, dwell-time, and bounded recovery policy settings for `FallbackPolicyEngine`.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct FallbackPolicyConfig {
    /// Minimum dwell time in milliseconds before another cadence transition is permitted.
    #[get(type(copy))]
    pub(crate) min_dwell_ms: u64,
    /// Number of consecutive over-budget frames required to step cadence down.
    #[get(type(copy))]
    pub(crate) overrun_streak_threshold: u32,
    /// Number of consecutive under-budget frames required to step cadence back up.
    #[get(type(copy))]
    pub(crate) recovery_streak_threshold: u32,
    /// Fraction of the next higher cadence tier's frame budget that must be met to recover upward.
    #[get(type(copy))]
    pub(crate) recovery_budget_ratio: f32,
    /// Maximum bounded GPU recovery attempts before permanently switching to CPU reference rendering.
    #[get(type(copy))]
    pub(crate) max_gpu_recovery_attempts: u32,
    /// Whether cadence stepping is permitted by platform and app policy.
    #[get(type(copy))]
    pub(crate) allow_cadence_step_down: bool,
}

/// Non-degrading runtime fallback controller governing cache trimming, hysteresis cadence stepping, and CPU reference fallback.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct FallbackPolicyEngine {
    /// Active policy thresholds and recovery limits.
    #[get(type(copy))]
    pub(crate) config: FallbackPolicyConfig,
    /// Native display refresh rate in Hertz.
    #[get(type(copy))]
    pub(crate) display_refresh_hz: f32,
    /// Currently selected presentation cadence in Hertz.
    #[get(type(copy))]
    pub(crate) active_cadence_hz: f32,
    /// Monotonic timestamp in milliseconds of the previous cadence transition.
    #[get(type(copy))]
    pub(crate) last_cadence_change_ms: u64,
    /// Whether a cadence transition has already occurred at least once.
    #[get(type(copy))]
    pub(crate) has_cadence_changed: bool,
    /// Consecutive over-budget rendered frame counter.
    #[get(type(copy))]
    pub(crate) overrun_streak: u32,
    /// Consecutive comfortably under-budget rendered frame counter.
    #[get(type(copy))]
    pub(crate) under_budget_streak: u32,
    /// Whether speculative offscreen route prefetching is currently permitted.
    #[get(type(copy))]
    pub(crate) prefetch_enabled: bool,
    /// Current cold-cache retention multiplier in `[0.25, 1.0]`.
    #[get(type(copy))]
    pub(crate) cache_retain_ratio: f32,
    /// Number of GPU device recovery attempts consumed so far.
    #[get(type(copy))]
    pub(crate) gpu_recovery_attempts: u32,
    /// Whether runtime policy has switched rendering to the full CPU reference backend.
    #[get(type(copy))]
    pub(crate) cpu_reference_forced: bool,
    /// Most recent fallback action emitted by this engine.
    #[get(type(copy))]
    pub(crate) last_action: FallbackAction,
    /// Current step along the 4-step non-degrading fallback ladder.
    #[get(type(copy))]
    pub(crate) active_ladder_step: FallbackLadderStep,
    /// Total number of presentation cadence adjustments performed.
    #[get(type(copy))]
    pub(crate) total_cadence_steps: u64,
    /// Total number of cache/prefetch trim actions triggered.
    #[get(type(copy))]
    pub(crate) total_cache_trims: u64,
    /// Total number of full CPU reference backend fallbacks triggered.
    #[get(type(copy))]
    pub(crate) total_cpu_fallbacks: u64,
    /// Baseline visual fidelity contract verified across every fallback decision.
    #[get(type(copy))]
    pub(crate) semantics_baseline: RenderSemanticsContract,
}

/// Surface generation and submission-outcome tracker retaining full pending frames across transient presentation failures.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
pub struct SurfacePresentState {
    /// Active monotonic OS surface generation (`0` before initial surface binding).
    #[get(type(copy))]
    pub(crate) surface_generation: u64,
    /// Outcome recorded by the most recent frame tick.
    #[get(type(copy))]
    pub(crate) last_outcome: FrameSubmitOutcome,
    /// Detailed present outcome recorded by the most recent frame tick.
    #[get(type(copy))]
    pub(crate) last_present_outcome: PresentOutcome,
    /// Surface generation on which a failed submission must be automatically retried.
    #[get(type(copy))]
    pub(crate) pending_retry_generation: u64,
    /// True when a complete frame is queued for automatic retry after `SubmitFailed`.
    #[get(type(copy))]
    pub(crate) has_pending_retry: bool,
    /// Consecutive retry count for the current failed submission.
    #[get(type(copy))]
    pub(crate) retry_attempts: u32,
    /// Cumulative count of `FrameSubmitOutcome::Submitted` frames.
    #[get(type(copy))]
    pub(crate) total_submitted: u64,
    /// Cumulative count of `FrameSubmitOutcome::SkippedNoDamage` ticks.
    #[get(type(copy))]
    pub(crate) total_skipped: u64,
    /// Cumulative count of `PresentOutcome::WaitInFlight` backpressure ticks.
    #[get(type(copy))]
    pub(crate) total_wait_in_flight: u64,
    /// Cumulative count of `FrameSubmitOutcome::SubmitFailed` presentations.
    #[get(type(copy))]
    pub(crate) total_failed: u64,
    /// Most recent monotonic present timestamp in nanoseconds (`0` when unavailable).
    #[get(type(copy))]
    pub(crate) last_present_timestamp_ns: u64,
    /// True when `last_present_timestamp_ns` holds a real presentation sample.
    #[get(type(copy))]
    pub(crate) has_present_timestamp: bool,
}