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

/// Transient GPU/CPU render-target resource declared inside `RenderGraph3D` for automatic lifetime aliasing.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct RenderGraphResource3D {
    /// Numeric transient resource identifier (`0..resource_count`).
    #[get(type(copy))]
    pub(crate) resource_id: usize,
    /// Human-readable resource label (e.g., `gbuffer_depth`, `lumen_probes`).
    pub(crate) name: String,
    /// Estimated byte footprint of this render target or storage buffer.
    #[get(type(copy))]
    pub(crate) size_bytes: usize,
    /// Whether this resource is an external final output that anchors pass liveness.
    #[get(type(copy))]
    pub(crate) is_external_output: bool,
}

/// Declarative render pass node inside `RenderGraph3D` declaring read/write resource dependencies.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct RenderGraphPass3D {
    /// Numeric pass identifier (`0..pass_count`).
    #[get(type(copy))]
    pub(crate) pass_id: usize,
    /// Canonical UE5 render pass category.
    #[get(type(copy))]
    pub(crate) kind: RenderPassKind3D,
    /// Human-readable diagnostic pass name.
    pub(crate) name: String,
    /// Resource IDs consumed as read-only inputs by this pass.
    pub(crate) reads: Vec<usize>,
    /// Resource IDs written or produced by this pass.
    pub(crate) writes: Vec<usize>,
    /// Last measured execution time of this pass in microseconds.
    #[get(type(copy))]
    pub(crate) last_duration_us: u64,
}

/// Compiled execution schedule and transient memory aliasing report produced by `RenderGraph3D::compile`.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct RenderGraphSchedule3D {
    /// Topologically ordered active pass IDs surviving dead-pass culling.
    pub(crate) ordered_passes: Vec<usize>,
    /// Total pass count eliminated by dead-pass culling.
    #[get(type(copy))]
    pub(crate) culled_pass_count: usize,
    /// Unaliased sum of all active transient resource byte sizes.
    #[get(type(copy))]
    pub(crate) unaliased_bytes: usize,
    /// Peak aliased transient memory footprint after greedy lifetime packing.
    #[get(type(copy))]
    pub(crate) aliased_peak_bytes: usize,
    /// Physical memory pool slot assigned to each transient resource ID (`usize::MAX` if unused).
    pub(crate) resource_pool_slots: Vec<usize>,
}

/// UE5 Render Dependency Graph (RDG) managing declarative pass scheduling, automatic dead-pass culling, and transient buffer aliasing.
#[derive(Clone, Data, Debug, Default)]
pub struct RenderGraph3D {
    /// Declared transient and external frame resources.
    pub(crate) resources: Vec<RenderGraphResource3D>,
    /// Declared frame render passes.
    pub(crate) passes: Vec<RenderGraphPass3D>,
}

/// 112-byte GPU-aligned instanced 3D object payload matching `WGSL`/`MSL`/`GLSL`/`HLSL` `InstanceData` layouts.
#[repr(C, align(16))]
#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
pub struct GpuInstanceData3D {
    /// Column-major 4x4 model matrix elements.
    #[get(type(copy))]
    pub(crate) model_matrix: [f32; 16],
    /// Linear base albedo RGB and metallic factor in `.w`.
    #[get(type(copy))]
    pub(crate) albedo_metallic: [f32; 4],
    /// Linear HDR emissive RGB and roughness factor in `.w`.
    #[get(type(copy))]
    pub(crate) emissive_roughness: [f32; 4],
    /// Material slot, bone palette offset, morph weight offset, and instance flags `[mat_id, skin_off, morph_off, flags]`.
    #[get(type(copy))]
    pub(crate) material_skin_morph_flags: [u32; 4],
}

/// Deduplicated GPU instanced mesh draw batch emitted from `World3D` for hardware RHI submission.
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct GpuMeshDrawBatch3D {
    /// Registered mesh identifier in `World3D::mesh_library`.
    #[get(type(copy))]
    pub(crate) mesh_id: usize,
    /// Selected LOD tier index (`0..=2`).
    #[get(type(copy))]
    pub(crate) lod_index: usize,
    /// First instance index inside `GpuFramePacket3D::instances`.
    #[get(type(copy))]
    pub(crate) first_instance: u32,
    /// Number of consecutive instanced objects sharing this mesh/LOD batch.
    #[get(type(copy))]
    pub(crate) instance_count: u32,
    /// Triangle count per single instance of this mesh LOD.
    #[get(type(copy))]
    pub(crate) triangles_per_instance: u32,
}

/// Reusable sorting scratch arena enabling zero-allocation `GpuFramePacket3D::build_from_world_into` updates.
#[derive(Clone, Data, Debug, Default)]
pub struct GpuFramePacketScratch3D {
    /// Reusable instance sort key table `(mesh_id, lod_idx, tri_count, instance_data)`.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) keyed_instances: Vec<(usize, usize, u32, GpuInstanceData3D)>,
    /// Reusable skin matrix evaluation workspace.
    pub(crate) skin_scratch: SkinPaletteScratch3D,
}

/// Zero-readback GPU 3D frame submission packet packing camera uniforms, Principled materials, 4-cascade CSM, IBL SH9, bone palettes, and sorted instanced batches.
#[derive(Clone, Data, Debug)]
pub struct GpuFramePacket3D {
    /// Active frame view-projection matrix.
    #[get(type(copy))]
    pub(crate) view_projection: Mat4,
    /// Previous frame view-projection matrix for GPU TSR velocity vectors.
    #[get(type(copy))]
    pub(crate) prev_view_projection: Mat4,
    /// Active camera world position.
    #[get(type(copy))]
    pub(crate) camera_position: Vec3,
    /// Active directional sun light parameters.
    #[get(type(copy))]
    pub(crate) sun: DirectionalLight3D,
    /// Contiguous GPU-aligned instance buffer ordered by `(mesh_id, lod_index)`.
    pub(crate) instances: Vec<GpuInstanceData3D>,
    /// Deduplicated instanced draw call descriptors referencing slices of `instances`.
    pub(crate) batches: Vec<GpuMeshDrawBatch3D>,
    /// Packed 160-byte std140 Principled BSDF material buffer uploaded to GPU storage memory.
    pub(crate) materials: Vec<GpuMaterialData3D>,
    /// Four Practical-Split directional CSM light view-projection matrices.
    #[get(type(copy))]
    pub(crate) csm_matrices: [Mat4; VSM_CASCADE_COUNT],
    /// Camera-space far split depth bounds for the 4 CSM cascades.
    #[get(type(copy))]
    pub(crate) csm_split_depths: [f32; VSM_CASCADE_COUNT],
    /// Precomputed L2 9-band Spherical Harmonics diffuse IBL irradiance coefficients.
    #[get(type(copy))]
    pub(crate) ibl_sh: [[f32; 3]; 9],
    /// Flattened contiguous bone skinning matrices across all active skinned meshes.
    pub(crate) bone_matrices: Vec<Mat4>,
    /// Whether Blender AgX (`true`) or ACES Filmic (`false`) tonemapping is active.
    #[get(type(copy))]
    pub(crate) use_agx_tonemap: bool,
    /// Number of active render-graph passes scheduled for this frame.
    #[get(type(copy))]
    pub(crate) active_pass_count: usize,
    /// Total hardware instanced triangles queued for submission.
    #[get(type(copy))]
    pub(crate) total_triangles: usize,
}