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

/// Complete configuration descriptor for a reusable `RaytraceSession`.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct RaytraceConfig {
    /// Viewport width in pixels.
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Viewport height in pixels.
    #[get(type(copy))]
    pub(crate) height: u32,
    /// Active ray-tracing integrator mode.
    #[get(type(copy))]
    pub(crate) integrator: RtIntegratorMode,
    /// Display tone-mapping view transform.
    #[get(type(copy))]
    pub(crate) tonemap: RtTonemapMode,
    /// Linear HDR exposure multiplier applied before tone mapping.
    #[get(type(copy))]
    pub(crate) exposure: f32,
    /// Square tile edge size in pixels for progressive budgeted stepping.
    #[get(type(copy))]
    pub(crate) tile_size: u32,
    /// Enables multi-pass À-Trous SVGF spatial denoising on the accumulated HDR buffer.
    #[get(type(copy))]
    pub(crate) enable_denoiser: bool,
    /// Whitted integrator settings.
    #[get(type(copy))]
    pub(crate) whitted: WhittedIntegrator,
    /// Monte Carlo PBR path-tracer settings.
    #[get(type(copy))]
    pub(crate) path_trace: PathTraceIntegrator,
    /// Ray-Traced Ambient Occlusion settings.
    #[get(type(copy))]
    pub(crate) rtao: RtaoIntegrator,
    /// Fast 1-spp interactive hybrid preview settings.
    #[get(type(copy))]
    pub(crate) hybrid_preview: HybridPreviewIntegrator,
    /// SVGF denoiser edge-stopping parameters.
    #[get(type(copy))]
    pub(crate) svgf: SvgfConfig,
    /// Deterministic RNG base seed.
    #[get(type(copy))]
    pub(crate) seed: u32,
}

/// Real-time ray-tracing telemetry reported by `RaytraceSession` after each progressive step or pass.
#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
pub struct RaytraceStats {
    /// Average accumulated samples per pixel across the viewport.
    #[get(type(copy))]
    pub(crate) samples_per_pixel: f32,
    /// Number of complete full-frame passes accumulated since the last reset.
    #[get(type(copy))]
    pub(crate) completed_passes: u32,
    /// Cumulative primary camera rays cast since the last reset.
    #[get(type(copy))]
    pub(crate) primary_rays: u64,
    /// Cumulative shadow and ambient-occlusion rays cast since the last reset.
    #[get(type(copy))]
    pub(crate) shadow_rays: u64,
    /// Cumulative secondary reflection, refraction, and indirect bounce rays cast since the last reset.
    #[get(type(copy))]
    pub(crate) bounce_rays: u64,
    /// Cumulative total rays cast since the last reset.
    #[get(type(copy))]
    pub(crate) total_rays: u64,
    /// Rays cast during the most recent `render_progressive_step` call.
    #[get(type(copy))]
    pub(crate) last_step_rays: u64,
    /// Wall-clock duration in milliseconds of the most recent step (`0.0` on wasm32 without host clock).
    #[get(type(copy))]
    pub(crate) last_step_ms: f32,
    /// Effective throughput in millions of rays per second (`MRays/sec`) for the most recent step.
    #[get(type(copy))]
    pub(crate) mrays_per_sec: f32,
    /// Wall-clock duration in milliseconds spent in SVGF denoising on the most recent step.
    #[get(type(copy))]
    pub(crate) denoise_ms: f32,
    /// Pixels traced so far in the current progressive frame pass.
    #[get(type(copy))]
    pub(crate) pixels_traced_in_pass: u32,
    /// Total pixel count (`width * height`) of the viewport.
    #[get(type(copy))]
    pub(crate) total_pixels: u32,
}

/// Zero-steady-state-allocation reusable ray-tracing session owning persistent HDR accumulation, G-buffers, SVGF denoiser, and tone-mapped RGBA8 output.
#[derive(Clone, Data, Debug)]
pub struct RaytraceSession {
    /// Active session configuration.
    #[get(type(copy))]
    pub(crate) config: RaytraceConfig,
    /// Progressive temporal radiance and variance moment accumulator.
    pub(crate) accumulator: TemporalAccumulator,
    /// Primary G-buffer storing world normals, linear depth, albedo, and geometry hit masks.
    pub(crate) gbuffer: RtGBuffer,
    /// Multi-pass edge-stopping À-Trous SVGF denoiser.
    pub(crate) denoiser: SvgfDenoiser,
    /// Pre-allocated per-pixel luminance variance scratch buffer feeding SVGF.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) variance_scratch: Vec<f32>,
    /// Persistent denoised (or raw accumulated) linear HDR output buffer.
    pub(crate) denoised_hdr: Vec<Vec3>,
    /// Persistent tone-mapped sRGB RGBA8 output framebuffer (`len == width * height * 4`).
    pub(crate) rgba8_output: Vec<u8>,
    /// Latest session telemetry snapshot.
    #[get(type(copy))]
    pub(crate) stats: RaytraceStats,
    /// Current progressive tile cursor within `[0, total_tiles)`.
    #[get(type(copy))]
    pub(crate) tile_cursor: u32,
    /// Current full-frame pass index used for quasi-random jitter and RNG decorrelation.
    #[get(type(copy))]
    pub(crate) pass_index: u32,
}

/// Cross-platform monotonic timer token wrapping `Instant` on native targets and a zero-cost placeholder on `wasm32`.
#[derive(Clone, Copy, Debug)]
pub(crate) struct RtTimer {
    /// Captured native monotonic start timestamp.
    #[cfg(not(target_arch = "wasm32"))]
    pub(crate) start: Instant,
    /// Zero-cost placeholder token on `wasm32`.
    #[cfg(target_arch = "wasm32")]
    pub(crate) start: u8,
}