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

/// Per-frame camera and projection descriptor consumed by `TsrUpscaler::upscale_rgba`.
#[derive(Clone, Copy, Data, Debug)]
pub struct TsrFrameParams {
    /// Internal rasterized source width in pixels.
    #[get(type(copy))]
    pub(crate) src_width: usize,
    /// Internal rasterized source height in pixels.
    #[get(type(copy))]
    pub(crate) src_height: usize,
    /// Target native display output width in pixels.
    #[get(type(copy))]
    pub(crate) dst_width: usize,
    /// Target native display output height in pixels.
    #[get(type(copy))]
    pub(crate) dst_height: usize,
    /// Current camera world position.
    #[get(type(copy))]
    pub(crate) camera_position: Vec3,
    /// Current camera unit forward vector.
    #[get(type(copy))]
    pub(crate) camera_forward: Vec3,
    /// Current camera right basis scaled by `half_w`.
    #[get(type(copy))]
    pub(crate) camera_right_scaled: Vec3,
    /// Current camera up basis scaled by `half_h`.
    #[get(type(copy))]
    pub(crate) camera_up_scaled: Vec3,
    /// Current frame view-projection matrix.
    #[get(type(copy))]
    pub(crate) view_projection: Mat4,
    /// Halton(2, 3) subpixel jitter offset `(jx, jy)` applied to the internal render.
    #[get(type(copy))]
    pub(crate) jitter_offset: (f32, f32),
    /// RCAS contrast-adaptive sharpening strength in `[0.0, 0.5]`.
    #[get(type(copy))]
    pub(crate) sharpness: f32,
}

/// UE5 Temporal Super Resolution (TSR) upscaler with analytical motion vectors, YCoCg 3x3 variance clipping, depth disocclusion rejection, and RCAS sharpening.
#[derive(Clone, Data, Debug)]
pub struct TsrUpscaler {
    /// Cached history output width in pixels.
    #[get(type(copy))]
    pub(crate) history_width: usize,
    /// Cached history output height in pixels.
    #[get(type(copy))]
    pub(crate) history_height: usize,
    /// Whether `history_rgba` and `history_inv_w` contain valid previous-frame data.
    #[get(type(copy))]
    pub(crate) has_history: bool,
    /// Previous frame view-projection matrix used for analytical 2D motion vector reprojection.
    #[get(type(copy))]
    pub(crate) prev_view_projection: Mat4,
    /// Total frames successfully accumulated with valid temporal history.
    #[get(type(copy))]
    pub(crate) accumulated_frames: u64,
    /// Persistent full-output-resolution RGBA8 temporal history buffer.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) history_rgba: Vec<u8>,
    /// Persistent double-buffered RGBA8 scratch swapped into `history_rgba` in O(1) without single-threaded memcpy.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) next_history_rgba: Vec<u8>,
    /// Persistent full-output-resolution reverse-Z `1/w` depth history for disocclusion rejection.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) history_inv_w: Vec<f32>,
    /// Persistent swap scratch buffer storing current reverse-Z depth at output resolution.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) next_inv_w: Vec<f32>,
}

/// Real-time telemetry emitted by `AdaptiveFrameGovernor` for HUD and observability diagnostics.
#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
pub struct FramePacingTelemetry3D {
    /// Active target frame budget in milliseconds (`1000.0 / target_hz`).
    #[get(type(copy))]
    pub(crate) budget_ms: f32,
    /// Exponential moving average frame time in milliseconds.
    #[get(type(copy))]
    pub(crate) ema_frame_ms: f32,
    /// Fast-attack slow-decay high-percentile frame time estimate in milliseconds.
    #[get(type(copy))]
    pub(crate) p99_est_ms: f32,
    /// Ratio of `ema_frame_ms / budget_ms`.
    #[get(type(copy))]
    pub(crate) budget_utilization: f32,
    /// Current TSR/DRS internal resolution scale applied by the governor.
    #[get(type(copy))]
    pub(crate) effective_resolution_scale: f32,
    /// Current additive RT probe stride bias (`0..=3`) under heavy GPU/CPU load.
    #[get(type(copy))]
    pub(crate) effective_rt_stride_bias: usize,
    /// Current Nanite LOD bias multiplier applied by the governor.
    #[get(type(copy))]
    pub(crate) effective_lod_bias: f32,
    /// Normalized frame stability score in `[0.0, 1.0]` (`1.0` = rock-solid zero jitter).
    #[get(type(copy))]
    pub(crate) stability_score: f32,
}

/// Closed-loop damped PI + asymmetric hysteresis frame-budget governor stabilizing FPS across 60/120/144/240/360/480Hz targets.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct AdaptiveFrameGovernor {
    /// Target refresh cadence in Hertz (`30.0..=1000.0`).
    #[get(type(copy))]
    pub(crate) target_hz: f32,
    /// Minimum permissible TSR/DRS internal scale (`0.40..=1.0`).
    #[get(type(copy))]
    pub(crate) min_scale: f32,
    /// Maximum permissible TSR/DRS internal scale (`0.50..=1.25`).
    #[get(type(copy))]
    pub(crate) max_scale: f32,
    /// Active quantized resolution scale.
    #[get(type(copy))]
    pub(crate) current_scale: f32,
    /// Active additive coarse RT probe stride bias (`0..=3`).
    #[get(type(copy))]
    pub(crate) rt_stride_bias: usize,
    /// Active Nanite LOD bias multiplier (`0.75..=1.80`).
    #[get(type(copy))]
    pub(crate) lod_bias: f32,
    /// Exponential moving average frame duration in milliseconds.
    #[get(type(copy))]
    pub(crate) ema_frame_ms: f32,
    /// Exponential moving average absolute frame-to-frame jitter in milliseconds.
    #[get(type(copy))]
    pub(crate) ema_jitter_ms: f32,
    /// High-percentile envelope tracker (`p99` estimate) in milliseconds.
    #[get(type(copy))]
    pub(crate) p99_est_ms: f32,
    /// Previous raw frame duration in milliseconds for frame-to-frame delta jitter.
    #[get(type(copy))]
    pub(crate) last_frame_ms: f32,
    /// Consecutive frames comfortably below budget before allowing step-up.
    #[get(type(copy))]
    pub(crate) under_budget_streak: u32,
    /// Consecutive frames exceeding budget triggering graduated fallback.
    #[get(type(copy))]
    pub(crate) over_budget_streak: u32,
    /// Hysteresis frame count required before stepping resolution back up.
    #[get(type(copy))]
    pub(crate) hysteresis_frames: u32,
    /// Total frames observed by this governor.
    #[get(type(copy))]
    pub(crate) total_frames: u64,
}