euv-core 0.53.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 lit 3D origami paper boat triangle vertex in NDC space for direct GPU ocean compositing (`32` bytes).
#[repr(C)]
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct GpuOceanBoatVertex {
    /// Clip/NDC vertex position `[ndc_x, ndc_y, depth, 1.0]`.
    #[get(type(copy))]
    pub(crate) pos_ndc: [f32; 4],
    /// Lit sRGB RGBA facet color `[r, g, b, a]`.
    #[get(type(copy))]
    pub(crate) color: [f32; 4],
}

/// Self-contained hardware GPU ocean and origami boat scene pass descriptor (`1:1` physical resolution, zero CPU pixel rasterization).
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct GpuOceanScenePass {
    /// Target physical surface width in device pixels.
    #[get(type(copy))]
    pub(crate) target_width: u32,
    /// Target physical surface height in device pixels.
    #[get(type(copy))]
    pub(crate) target_height: u32,
    /// Monotonic simulation time in seconds driving Gerstner wave phases.
    #[get(type(copy))]
    pub(crate) sim_time: f32,
    /// Wave agitation multiplier derived from live PBF kinetic energy.
    #[get(type(copy))]
    pub(crate) agitation: f32,
    /// Normalized vertical horizon line coordinate in `[0.46, 0.62]`.
    #[get(type(copy))]
    pub(crate) horizon_v: f32,
    /// Cosine of vessel roll tilt angle.
    #[get(type(copy))]
    pub(crate) roll_cos: f32,
    /// Sine of vessel roll tilt angle.
    #[get(type(copy))]
    pub(crate) roll_sin: f32,
    /// Exact unclamped physical aspect ratio `target_width / target_height`.
    #[get(type(copy))]
    pub(crate) aspect: f32,
    /// Normalized 3D sun direction `[x, y, z]`.
    #[get(type(copy))]
    pub(crate) sun_dir: [f32; 3],
    /// Normalized boat waterline UV `[u, v]` for waterline contact shadow and reflection.
    #[get(type(copy))]
    pub(crate) boat_uv: [f32; 2],
    /// PBF wake texture width in texels (`96`).
    #[get(type(copy))]
    pub(crate) wake_width: u32,
    /// PBF wake texture height in texels (`72`).
    #[get(type(copy))]
    pub(crate) wake_height: u32,
    /// True when interactive pointer/tilt PBF wake energy is non-zero.
    #[get(type(copy))]
    pub(crate) has_active_wake: bool,
    /// Packed RGBA8 PBF wake field (`R = flow_u`, `G = flow_v`, `B = foam`, `A = 255`).
    pub(crate) wake_rgba8: Vec<u8>,
    /// Depth-sorted back-to-front 3D origami paper boat triangle vertices (`18 * 3`).
    pub(crate) boat_vertices: Vec<GpuOceanBoatVertex>,
}

/// Compact 48-byte `#[repr(C)]` vertex record for hardware Metal and WebGL2 3D PBR open-world rendering.
#[repr(C)]
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct GpuWorld3dVertex {
    /// Local-space 3D vertex position `[x, y, z, 1.0]`.
    #[get(type(copy))]
    pub(crate) position: [f32; 4],
    /// Local-space unit surface normal `[nx, ny, nz, 0.0]`.
    #[get(type(copy))]
    pub(crate) normal: [f32; 4],
    /// Sub-material linear RGB override (`w = 1.0` overrides instance albedo, `w = 0.0` multiplies instance albedo).
    #[get(type(copy))]
    pub(crate) color_submat: [f32; 4],
}

/// Compact 96-byte `#[repr(C)]` instanced object payload for hardware Metal and WebGL2 3D PBR rendering.
#[repr(C)]
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct GpuWorld3dInstance {
    /// Column-major `4x4` object-to-world model matrix.
    #[get(type(copy))]
    pub(crate) model: [f32; 16],
    /// Primary linear albedo RGB and metallic factor `[r, g, b, metallic]`.
    #[get(type(copy))]
    pub(crate) albedo_metallic: [f32; 4],
    /// HDR emissive glow RGB and surface roughness `[er, eg, eb, roughness]`.
    #[get(type(copy))]
    pub(crate) emissive_roughness: [f32; 4],
}

/// Per-mesh instanced draw batch range indexing into `GpuWorld3dMeshBuffer::vertices` and `GpuWorld3dScenePass::instances`.
#[repr(C)]
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct GpuWorld3dMeshRange {
    /// Starting vertex index inside the resident static mesh vertex buffer.
    #[get(type(copy))]
    pub(crate) vertex_start: u32,
    /// Number of non-indexed triangle vertices for this prototype mesh.
    #[get(type(copy))]
    pub(crate) vertex_count: u32,
    /// Starting instance index inside the per-frame instance buffer.
    #[get(type(copy))]
    pub(crate) instance_start: u32,
    /// Number of visible instances drawn in this instanced call.
    #[get(type(copy))]
    pub(crate) instance_count: u32,
}

/// Immutable `Arc`-shared static 3D mesh library vertex buffer uploaded once per revision to GPU VRAM.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct GpuWorld3dMeshBuffer {
    /// Monotonic revision incremented only when meshes are built or imported.
    #[get(type(copy))]
    pub(crate) revision: u64,
    /// Packed non-indexed triangle vertices across all prototype meshes in the scene library.
    pub(crate) vertices: Vec<GpuWorld3dVertex>,
}

/// Self-contained hardware GPU 3D PBR open-world scene pass descriptor (`1:1` physical resolution, hardware Z-buffer).
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct GpuWorld3dScenePass {
    /// Target physical surface width in device pixels.
    #[get(type(copy))]
    pub(crate) target_width: u32,
    /// Target physical surface height in device pixels.
    #[get(type(copy))]
    pub(crate) target_height: u32,
    /// Column-major combined `projection * view` matrix.
    #[get(type(copy))]
    pub(crate) view_proj: [f32; 16],
    /// Camera world position and exposure `[cx, cy, cz, exposure]`.
    #[get(type(copy))]
    pub(crate) camera_pos: [f32; 4],
    /// Normalized sun direction and fog density `[sx, sy, sz, fog_density]`.
    #[get(type(copy))]
    pub(crate) sun_dir_fog: [f32; 4],
    /// Linear HDR sun color and ambient strength `[sr, sg, sb, ambient]`.
    #[get(type(copy))]
    pub(crate) sun_color_ambient: [f32; 4],
    /// Atmospheric horizon RGB and time-of-day `[hr, hg, hb, tod]`.
    #[get(type(copy))]
    pub(crate) sky_horizon_tod: [f32; 4],
    /// Atmospheric zenith RGB and aspect ratio `[zr, zg, zb, aspect]`.
    #[get(type(copy))]
    pub(crate) sky_zenith_aspect: [f32; 4],
    /// Immutable `Arc`-shared static mesh vertex buffer uploaded once per revision.
    pub(crate) mesh_buffer: Arc<GpuWorld3dMeshBuffer>,
    /// Frustum-culled visible per-object instance payloads for this frame.
    pub(crate) instances: Vec<GpuWorld3dInstance>,
    /// Ordered per-mesh instanced draw ranges referencing `mesh_buffer` and `instances`.
    pub(crate) draw_batches: Vec<GpuWorld3dMeshRange>,
}

/// Self-contained direct-GPU frame submission passed from `AppRunner` to `PlatformBackend::present_gpu_frame`.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct GpuFrameSubmission {
    /// Authoritative physical surface width in pixels.
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Authoritative physical surface height in pixels.
    #[get(type(copy))]
    pub(crate) height: u32,
    /// Active display scale factor (`[0.25, 16.0]`).
    #[get(type(copy))]
    pub(crate) scale_factor: f32,
    /// Surface background clear color.
    #[get(type(copy))]
    pub(crate) clear_color: Color,
    /// Order-preserving 64-byte `GpuPrimitiveInstance` draw batches.
    pub(crate) batches: Vec<GpuBatch>,
    /// Active Dual-Kawase backdrop blur regions for Pass 3.
    pub(crate) blur_passes: Vec<GpuBackdropBlurPass>,
    /// Optional external 3D/Fluid GPU texture handle (`0` when absent).
    #[get(type(copy))]
    pub(crate) external_texture_handle: usize,
    /// Optional hardware GPU offscreen scene pass rendered into `external_tex` before UI compositing.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) gpu_scene_pass: Option<DirectGpuScenePass>,
    /// Optional incremental R8 glyph atlas upload payload for direct GPU text rendering.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) glyph_atlas_r8: Option<DirectGpuAtlasUpload>,
    /// Dirty sub-rectangles inside `glyph_atlas_r8` pending incremental GPU upload.
    pub(crate) glyph_dirty_rects: Vec<PixelDirtyRect>,
    /// Optional packed RGBA8 image atlas payload for direct GPU image quad rendering.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) image_atlas_rgba8: Option<DirectGpuAtlasUpload>,
    /// Dirty sub-rectangles inside `image_atlas_rgba8` pending incremental GPU upload.
    pub(crate) image_dirty_rects: Vec<PixelDirtyRect>,
}

/// Hardware presentation telemetry and fault status returned by `PlatformBackend::present_gpu_frame`.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct GpuPresentReceipt {
    /// True when the platform backend executed native direct GPU presentation without CPU RGBA mirroring.
    #[get(type(copy))]
    pub(crate) presented: bool,
    /// Number of hardware GPU draw calls submitted during presentation.
    #[get(type(copy))]
    pub(crate) draw_calls: usize,
    /// Number of 64-byte primitive instances uploaded to GPU memory.
    #[get(type(copy))]
    pub(crate) uploaded_instances: usize,
    /// Hardware presentation timestamp in nanoseconds (`0` when unobservable).
    #[get(type(copy))]
    pub(crate) presented_time_ns: u64,
    /// Measured GPU execution duration in nanoseconds (`0` when unobservable).
    #[get(type(copy))]
    pub(crate) gpu_exec_ns: u64,
    /// True when the GPU device or presentation surface was lost and requires automatic recovery.
    #[get(type(copy))]
    pub(crate) device_lost: bool,
}