Skip to main content

euv_core/platform/backend/
struct.rs

1use super::*;
2
3/// One lit 3D origami paper boat triangle vertex in NDC space for direct GPU ocean compositing (`32` bytes).
4#[repr(C)]
5#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
6pub struct GpuOceanBoatVertex {
7    /// Clip/NDC vertex position `[ndc_x, ndc_y, depth, 1.0]`.
8    #[get(type(copy))]
9    pub(crate) pos_ndc: [f32; 4],
10    /// Lit sRGB RGBA facet color `[r, g, b, a]`.
11    #[get(type(copy))]
12    pub(crate) color: [f32; 4],
13}
14
15/// Self-contained hardware GPU ocean and origami boat scene pass descriptor (`1:1` physical resolution, zero CPU pixel rasterization).
16#[derive(Clone, Data, Debug, Default, PartialEq)]
17pub struct GpuOceanScenePass {
18    /// Target physical surface width in device pixels.
19    #[get(type(copy))]
20    pub(crate) target_width: u32,
21    /// Target physical surface height in device pixels.
22    #[get(type(copy))]
23    pub(crate) target_height: u32,
24    /// Monotonic simulation time in seconds driving Gerstner wave phases.
25    #[get(type(copy))]
26    pub(crate) sim_time: f32,
27    /// Wave agitation multiplier derived from live PBF kinetic energy.
28    #[get(type(copy))]
29    pub(crate) agitation: f32,
30    /// Normalized vertical horizon line coordinate in `[0.46, 0.62]`.
31    #[get(type(copy))]
32    pub(crate) horizon_v: f32,
33    /// Cosine of vessel roll tilt angle.
34    #[get(type(copy))]
35    pub(crate) roll_cos: f32,
36    /// Sine of vessel roll tilt angle.
37    #[get(type(copy))]
38    pub(crate) roll_sin: f32,
39    /// Exact unclamped physical aspect ratio `target_width / target_height`.
40    #[get(type(copy))]
41    pub(crate) aspect: f32,
42    /// Normalized 3D sun direction `[x, y, z]`.
43    #[get(type(copy))]
44    pub(crate) sun_dir: [f32; 3],
45    /// Normalized boat waterline UV `[u, v]` for waterline contact shadow and reflection.
46    #[get(type(copy))]
47    pub(crate) boat_uv: [f32; 2],
48    /// PBF wake texture width in texels (`96`).
49    #[get(type(copy))]
50    pub(crate) wake_width: u32,
51    /// PBF wake texture height in texels (`72`).
52    #[get(type(copy))]
53    pub(crate) wake_height: u32,
54    /// True when interactive pointer/tilt PBF wake energy is non-zero.
55    #[get(type(copy))]
56    pub(crate) has_active_wake: bool,
57    /// Packed RGBA8 PBF wake field (`R = flow_u`, `G = flow_v`, `B = foam`, `A = 255`).
58    pub(crate) wake_rgba8: Vec<u8>,
59    /// Depth-sorted back-to-front 3D origami paper boat triangle vertices (`18 * 3`).
60    pub(crate) boat_vertices: Vec<GpuOceanBoatVertex>,
61}
62
63/// Compact 48-byte `#[repr(C)]` vertex record for hardware Metal and WebGL2 3D PBR open-world rendering.
64#[repr(C)]
65#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
66pub struct GpuWorld3dVertex {
67    /// Local-space 3D vertex position `[x, y, z, 1.0]`.
68    #[get(type(copy))]
69    pub(crate) position: [f32; 4],
70    /// Local-space unit surface normal `[nx, ny, nz, 0.0]`.
71    #[get(type(copy))]
72    pub(crate) normal: [f32; 4],
73    /// Sub-material linear RGB override (`w = 1.0` overrides instance albedo, `w = 0.0` multiplies instance albedo).
74    #[get(type(copy))]
75    pub(crate) color_submat: [f32; 4],
76}
77
78/// Compact 96-byte `#[repr(C)]` instanced object payload for hardware Metal and WebGL2 3D PBR rendering.
79#[repr(C)]
80#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
81pub struct GpuWorld3dInstance {
82    /// Column-major `4x4` object-to-world model matrix.
83    #[get(type(copy))]
84    pub(crate) model: [f32; 16],
85    /// Primary linear albedo RGB and metallic factor `[r, g, b, metallic]`.
86    #[get(type(copy))]
87    pub(crate) albedo_metallic: [f32; 4],
88    /// HDR emissive glow RGB and surface roughness `[er, eg, eb, roughness]`.
89    #[get(type(copy))]
90    pub(crate) emissive_roughness: [f32; 4],
91}
92
93/// Per-mesh instanced draw batch range indexing into `GpuWorld3dMeshBuffer::vertices` and `GpuWorld3dScenePass::instances`.
94#[repr(C)]
95#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
96pub struct GpuWorld3dMeshRange {
97    /// Starting vertex index inside the resident static mesh vertex buffer.
98    #[get(type(copy))]
99    pub(crate) vertex_start: u32,
100    /// Number of non-indexed triangle vertices for this prototype mesh.
101    #[get(type(copy))]
102    pub(crate) vertex_count: u32,
103    /// Starting instance index inside the per-frame instance buffer.
104    #[get(type(copy))]
105    pub(crate) instance_start: u32,
106    /// Number of visible instances drawn in this instanced call.
107    #[get(type(copy))]
108    pub(crate) instance_count: u32,
109}
110
111/// Immutable `Arc`-shared static 3D mesh library vertex buffer uploaded once per revision to GPU VRAM.
112#[derive(Clone, Data, Debug, Default, PartialEq)]
113pub struct GpuWorld3dMeshBuffer {
114    /// Monotonic revision incremented only when meshes are built or imported.
115    #[get(type(copy))]
116    pub(crate) revision: u64,
117    /// Packed non-indexed triangle vertices across all prototype meshes in the scene library.
118    pub(crate) vertices: Vec<GpuWorld3dVertex>,
119}
120
121/// Self-contained hardware GPU 3D PBR open-world scene pass descriptor (`1:1` physical resolution, hardware Z-buffer).
122#[derive(Clone, Data, Debug, Default, PartialEq)]
123pub struct GpuWorld3dScenePass {
124    /// Target physical surface width in device pixels.
125    #[get(type(copy))]
126    pub(crate) target_width: u32,
127    /// Target physical surface height in device pixels.
128    #[get(type(copy))]
129    pub(crate) target_height: u32,
130    /// Column-major combined `projection * view` matrix.
131    #[get(type(copy))]
132    pub(crate) view_proj: [f32; 16],
133    /// Camera world position and exposure `[cx, cy, cz, exposure]`.
134    #[get(type(copy))]
135    pub(crate) camera_pos: [f32; 4],
136    /// Normalized sun direction and fog density `[sx, sy, sz, fog_density]`.
137    #[get(type(copy))]
138    pub(crate) sun_dir_fog: [f32; 4],
139    /// Linear HDR sun color and ambient strength `[sr, sg, sb, ambient]`.
140    #[get(type(copy))]
141    pub(crate) sun_color_ambient: [f32; 4],
142    /// Atmospheric horizon RGB and time-of-day `[hr, hg, hb, tod]`.
143    #[get(type(copy))]
144    pub(crate) sky_horizon_tod: [f32; 4],
145    /// Atmospheric zenith RGB and aspect ratio `[zr, zg, zb, aspect]`.
146    #[get(type(copy))]
147    pub(crate) sky_zenith_aspect: [f32; 4],
148    /// Immutable `Arc`-shared static mesh vertex buffer uploaded once per revision.
149    pub(crate) mesh_buffer: Arc<GpuWorld3dMeshBuffer>,
150    /// Frustum-culled visible per-object instance payloads for this frame.
151    pub(crate) instances: Vec<GpuWorld3dInstance>,
152    /// Ordered per-mesh instanced draw ranges referencing `mesh_buffer` and `instances`.
153    pub(crate) draw_batches: Vec<GpuWorld3dMeshRange>,
154}
155
156/// Self-contained direct-GPU frame submission passed from `AppRunner` to `PlatformBackend::present_gpu_frame`.
157#[derive(Clone, Data, Debug, Default, PartialEq)]
158pub struct GpuFrameSubmission {
159    /// Authoritative physical surface width in pixels.
160    #[get(type(copy))]
161    pub(crate) width: u32,
162    /// Authoritative physical surface height in pixels.
163    #[get(type(copy))]
164    pub(crate) height: u32,
165    /// Active display scale factor (`[0.25, 16.0]`).
166    #[get(type(copy))]
167    pub(crate) scale_factor: f32,
168    /// Surface background clear color.
169    #[get(type(copy))]
170    pub(crate) clear_color: Color,
171    /// Order-preserving 64-byte `GpuPrimitiveInstance` draw batches.
172    pub(crate) batches: Vec<GpuBatch>,
173    /// Active Dual-Kawase backdrop blur regions for Pass 3.
174    pub(crate) blur_passes: Vec<GpuBackdropBlurPass>,
175    /// Optional external 3D/Fluid GPU texture handle (`0` when absent).
176    #[get(type(copy))]
177    pub(crate) external_texture_handle: usize,
178    /// Optional hardware GPU offscreen scene pass rendered into `external_tex` before UI compositing.
179    #[get(skip)]
180    #[get_mut(skip)]
181    #[set(skip)]
182    pub(crate) gpu_scene_pass: Option<DirectGpuScenePass>,
183    /// Optional incremental R8 glyph atlas upload payload for direct GPU text rendering.
184    #[get(skip)]
185    #[get_mut(skip)]
186    #[set(skip)]
187    pub(crate) glyph_atlas_r8: Option<DirectGpuAtlasUpload>,
188    /// Dirty sub-rectangles inside `glyph_atlas_r8` pending incremental GPU upload.
189    pub(crate) glyph_dirty_rects: Vec<PixelDirtyRect>,
190    /// Optional packed RGBA8 image atlas payload for direct GPU image quad rendering.
191    #[get(skip)]
192    #[get_mut(skip)]
193    #[set(skip)]
194    pub(crate) image_atlas_rgba8: Option<DirectGpuAtlasUpload>,
195    /// Dirty sub-rectangles inside `image_atlas_rgba8` pending incremental GPU upload.
196    pub(crate) image_dirty_rects: Vec<PixelDirtyRect>,
197}
198
199/// Hardware presentation telemetry and fault status returned by `PlatformBackend::present_gpu_frame`.
200#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
201pub struct GpuPresentReceipt {
202    /// True when the platform backend executed native direct GPU presentation without CPU RGBA mirroring.
203    #[get(type(copy))]
204    pub(crate) presented: bool,
205    /// Number of hardware GPU draw calls submitted during presentation.
206    #[get(type(copy))]
207    pub(crate) draw_calls: usize,
208    /// Number of 64-byte primitive instances uploaded to GPU memory.
209    #[get(type(copy))]
210    pub(crate) uploaded_instances: usize,
211    /// Hardware presentation timestamp in nanoseconds (`0` when unobservable).
212    #[get(type(copy))]
213    pub(crate) presented_time_ns: u64,
214    /// Measured GPU execution duration in nanoseconds (`0` when unobservable).
215    #[get(type(copy))]
216    pub(crate) gpu_exec_ns: u64,
217    /// True when the GPU device or presentation surface was lost and requires automatic recovery.
218    #[get(type(copy))]
219    pub(crate) device_lost: bool,
220}