Skip to main content

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/// 96-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}
80
81/// Deduplicated GPU instanced mesh draw batch emitted from `World3D` for hardware RHI submission.
82#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
83pub struct GpuMeshDrawBatch3D {
84    /// Registered mesh identifier in `World3D::mesh_library`.
85    #[get(type(copy))]
86    pub(crate) mesh_id: usize,
87    /// Selected LOD tier index (`0..=2`).
88    #[get(type(copy))]
89    pub(crate) lod_index: usize,
90    /// First instance index inside `GpuFramePacket3D::instances`.
91    #[get(type(copy))]
92    pub(crate) first_instance: u32,
93    /// Number of consecutive instanced objects sharing this mesh/LOD batch.
94    #[get(type(copy))]
95    pub(crate) instance_count: u32,
96    /// Triangle count per single instance of this mesh LOD.
97    #[get(type(copy))]
98    pub(crate) triangles_per_instance: u32,
99}
100
101/// Zero-readback GPU 3D frame submission packet packing camera uniforms, sorted instanced batches, and shader targets.
102#[derive(Clone, Data, Debug)]
103pub struct GpuFramePacket3D {
104    /// Active frame view-projection matrix.
105    #[get(type(copy))]
106    pub(crate) view_projection: Mat4,
107    /// Previous frame view-projection matrix for GPU TSR velocity vectors.
108    #[get(type(copy))]
109    pub(crate) prev_view_projection: Mat4,
110    /// Active camera world position.
111    #[get(type(copy))]
112    pub(crate) camera_position: Vec3,
113    /// Active directional sun light parameters.
114    #[get(type(copy))]
115    pub(crate) sun: DirectionalLight3D,
116    /// Contiguous GPU-aligned instance buffer ordered by `(mesh_id, lod_index)`.
117    pub(crate) instances: Vec<GpuInstanceData3D>,
118    /// Deduplicated instanced draw call descriptors referencing slices of `instances`.
119    pub(crate) batches: Vec<GpuMeshDrawBatch3D>,
120    /// Total hardware instanced triangles queued for submission.
121    #[get(type(copy))]
122    pub(crate) total_triangles: usize,
123}