euv_core/game/engine3d/rhi/struct.rs
1use super::*;
2
3/// Transient GPU/CPU render-target resource declared inside `RenderGraph3D` for automatic lifetime aliasing.
4#[derive(Clone, Data, Debug, PartialEq)]
5pub struct RenderGraphResource3D {
6 /// Numeric transient resource identifier (`0..resource_count`).
7 #[get(type(copy))]
8 pub(crate) resource_id: usize,
9 /// Human-readable resource label (e.g., `gbuffer_depth`, `lumen_probes`).
10 pub(crate) name: String,
11 /// Estimated byte footprint of this render target or storage buffer.
12 #[get(type(copy))]
13 pub(crate) size_bytes: usize,
14 /// Whether this resource is an external final output that anchors pass liveness.
15 #[get(type(copy))]
16 pub(crate) is_external_output: bool,
17}
18
19/// Declarative render pass node inside `RenderGraph3D` declaring read/write resource dependencies.
20#[derive(Clone, Data, Debug, PartialEq)]
21pub struct RenderGraphPass3D {
22 /// Numeric pass identifier (`0..pass_count`).
23 #[get(type(copy))]
24 pub(crate) pass_id: usize,
25 /// Canonical UE5 render pass category.
26 #[get(type(copy))]
27 pub(crate) kind: RenderPassKind3D,
28 /// Human-readable diagnostic pass name.
29 pub(crate) name: String,
30 /// Resource IDs consumed as read-only inputs by this pass.
31 pub(crate) reads: Vec<usize>,
32 /// Resource IDs written or produced by this pass.
33 pub(crate) writes: Vec<usize>,
34 /// Last measured execution time of this pass in microseconds.
35 #[get(type(copy))]
36 pub(crate) last_duration_us: u64,
37}
38
39/// Compiled execution schedule and transient memory aliasing report produced by `RenderGraph3D::compile`.
40#[derive(Clone, Data, Debug, Default, PartialEq)]
41pub struct RenderGraphSchedule3D {
42 /// Topologically ordered active pass IDs surviving dead-pass culling.
43 pub(crate) ordered_passes: Vec<usize>,
44 /// Total pass count eliminated by dead-pass culling.
45 #[get(type(copy))]
46 pub(crate) culled_pass_count: usize,
47 /// Unaliased sum of all active transient resource byte sizes.
48 #[get(type(copy))]
49 pub(crate) unaliased_bytes: usize,
50 /// Peak aliased transient memory footprint after greedy lifetime packing.
51 #[get(type(copy))]
52 pub(crate) aliased_peak_bytes: usize,
53 /// Physical memory pool slot assigned to each transient resource ID (`usize::MAX` if unused).
54 pub(crate) resource_pool_slots: Vec<usize>,
55}
56
57/// UE5 Render Dependency Graph (RDG) managing declarative pass scheduling, automatic dead-pass culling, and transient buffer aliasing.
58#[derive(Clone, Data, Debug, Default)]
59pub struct RenderGraph3D {
60 /// Declared transient and external frame resources.
61 pub(crate) resources: Vec<RenderGraphResource3D>,
62 /// Declared frame render passes.
63 pub(crate) passes: Vec<RenderGraphPass3D>,
64}
65
66/// 112-byte GPU-aligned instanced 3D object payload matching `WGSL`/`MSL`/`GLSL`/`HLSL` `InstanceData` layouts.
67#[repr(C, align(16))]
68#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
69pub struct GpuInstanceData3D {
70 /// Column-major 4x4 model matrix elements.
71 #[get(type(copy))]
72 pub(crate) model_matrix: [f32; 16],
73 /// Linear base albedo RGB and metallic factor in `.w`.
74 #[get(type(copy))]
75 pub(crate) albedo_metallic: [f32; 4],
76 /// Linear HDR emissive RGB and roughness factor in `.w`.
77 #[get(type(copy))]
78 pub(crate) emissive_roughness: [f32; 4],
79 /// Material slot, bone palette offset, morph weight offset, and instance flags `[mat_id, skin_off, morph_off, flags]`.
80 #[get(type(copy))]
81 pub(crate) material_skin_morph_flags: [u32; 4],
82}
83
84/// Deduplicated GPU instanced mesh draw batch emitted from `World3D` for hardware RHI submission.
85#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
86pub struct GpuMeshDrawBatch3D {
87 /// Registered mesh identifier in `World3D::mesh_library`.
88 #[get(type(copy))]
89 pub(crate) mesh_id: usize,
90 /// Selected LOD tier index (`0..=2`).
91 #[get(type(copy))]
92 pub(crate) lod_index: usize,
93 /// First instance index inside `GpuFramePacket3D::instances`.
94 #[get(type(copy))]
95 pub(crate) first_instance: u32,
96 /// Number of consecutive instanced objects sharing this mesh/LOD batch.
97 #[get(type(copy))]
98 pub(crate) instance_count: u32,
99 /// Triangle count per single instance of this mesh LOD.
100 #[get(type(copy))]
101 pub(crate) triangles_per_instance: u32,
102}
103
104/// Reusable sorting scratch arena enabling zero-allocation `GpuFramePacket3D::build_from_world_into` updates.
105#[derive(Clone, Data, Debug, Default)]
106pub struct GpuFramePacketScratch3D {
107 /// Reusable instance sort key table `(mesh_id, lod_idx, tri_count, instance_data)`.
108 #[get(skip)]
109 #[get_mut(skip)]
110 #[set(skip)]
111 pub(crate) keyed_instances: Vec<(usize, usize, u32, GpuInstanceData3D)>,
112 /// Reusable skin matrix evaluation workspace.
113 pub(crate) skin_scratch: SkinPaletteScratch3D,
114}
115
116/// Zero-readback GPU 3D frame submission packet packing camera uniforms, Principled materials, 4-cascade CSM, IBL SH9, bone palettes, and sorted instanced batches.
117#[derive(Clone, Data, Debug)]
118pub struct GpuFramePacket3D {
119 /// Active frame view-projection matrix.
120 #[get(type(copy))]
121 pub(crate) view_projection: Mat4,
122 /// Previous frame view-projection matrix for GPU TSR velocity vectors.
123 #[get(type(copy))]
124 pub(crate) prev_view_projection: Mat4,
125 /// Active camera world position.
126 #[get(type(copy))]
127 pub(crate) camera_position: Vec3,
128 /// Active directional sun light parameters.
129 #[get(type(copy))]
130 pub(crate) sun: DirectionalLight3D,
131 /// Contiguous GPU-aligned instance buffer ordered by `(mesh_id, lod_index)`.
132 pub(crate) instances: Vec<GpuInstanceData3D>,
133 /// Deduplicated instanced draw call descriptors referencing slices of `instances`.
134 pub(crate) batches: Vec<GpuMeshDrawBatch3D>,
135 /// Packed 160-byte std140 Principled BSDF material buffer uploaded to GPU storage memory.
136 pub(crate) materials: Vec<GpuMaterialData3D>,
137 /// Four Practical-Split directional CSM light view-projection matrices.
138 #[get(type(copy))]
139 pub(crate) csm_matrices: [Mat4; VSM_CASCADE_COUNT],
140 /// Camera-space far split depth bounds for the 4 CSM cascades.
141 #[get(type(copy))]
142 pub(crate) csm_split_depths: [f32; VSM_CASCADE_COUNT],
143 /// Precomputed L2 9-band Spherical Harmonics diffuse IBL irradiance coefficients.
144 #[get(type(copy))]
145 pub(crate) ibl_sh: [[f32; 3]; 9],
146 /// Flattened contiguous bone skinning matrices across all active skinned meshes.
147 pub(crate) bone_matrices: Vec<Mat4>,
148 /// Whether Blender AgX (`true`) or ACES Filmic (`false`) tonemapping is active.
149 #[get(type(copy))]
150 pub(crate) use_agx_tonemap: bool,
151 /// Number of active render-graph passes scheduled for this frame.
152 #[get(type(copy))]
153 pub(crate) active_pass_count: usize,
154 /// Total hardware instanced triangles queued for submission.
155 #[get(type(copy))]
156 pub(crate) total_triangles: usize,
157}