euv-core 0.56.0

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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
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>,
}

/// Per-frame culling, LOD distribution, upload budget, and draw-call telemetry for `GpuPbrScenePass`.
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, New, PartialEq)]
pub struct GpuPbrCullStats {
    /// Total meshlet clusters tested against frustum and normal-cone bounds.
    #[get(type(copy))]
    pub(crate) meshlets_tested: u32,
    /// Number of meshlet clusters rejected by frustum or normal-cone backface culling.
    #[get(type(copy))]
    pub(crate) meshlets_culled: u32,
    /// Visible instance counts distributed across `[LOD0, LOD1, LOD2, LOD3]`.
    #[get(type(copy))]
    pub(crate) lod_instance_counts: [u32; 4],
    /// Total instanced GPU draw calls emitted for this frame.
    #[get(type(copy))]
    pub(crate) draw_call_count: u32,
    /// Total bytes uploaded to GPU buffers and textures during this frame.
    #[get(type(copy))]
    pub(crate) uploaded_bytes: usize,
    /// Total CPU microseconds spent staging GPU uploads during this frame.
    #[get(type(copy))]
    pub(crate) upload_time_us: u64,
}

/// Packed 64-byte `#[repr(C)]` GPU local light record supporting point, spot, and area lights in `GpuPbrScenePass`.
#[repr(C)]
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct GpuPackedLocalLight {
    /// World-space position `[x, y, z]` and attenuation range `w`.
    #[get(type(copy))]
    pub(crate) position_range: [f32; 4],
    /// Linear HDR RGB radiance and luminous intensity `w`.
    #[get(type(copy))]
    pub(crate) color_intensity: [f32; 4],
    /// Normalized light direction `[dx, dy, dz]` and packed light type (`0=Point, 1=Spot, 2=Area`).
    #[get(type(copy))]
    pub(crate) direction_kind: [f32; 4],
    /// Spot or area shape parameters `[inner_cos, outer_cos, width, height]`.
    #[get(type(copy))]
    pub(crate) cone_size_params: [f32; 4],
}

/// Single frame-budgeted incremental GPU texture mipmap level upload payload.
#[derive(Clone, Data, Debug, Default, Eq, PartialEq)]
pub struct GpuTextureMipUpload {
    /// Target bindless texture pool slot index.
    #[get(type(copy))]
    pub(crate) texture_slot: u32,
    /// Target mipmap level (`0` = full resolution, larger = coarser mip-tail).
    #[get(type(copy))]
    pub(crate) mip_level: u8,
    /// Total mipmap levels allocated for this texture resource.
    #[get(type(copy))]
    pub(crate) total_mip_levels: u8,
    /// True when texels are sRGB-encoded (albedo/emissive), false for linear data (normal/MR/AO).
    #[get(type(copy))]
    pub(crate) is_srgb: bool,
    /// Minimum resident mip level clamp (`minLodClamp` / `TEXTURE_BASE_LEVEL`) after this upload.
    #[get(type(copy))]
    pub(crate) min_lod_clamp: u8,
    /// Uploaded mip level width in texels.
    #[get(type(copy))]
    pub(crate) width: u32,
    /// Uploaded mip level height in texels.
    #[get(type(copy))]
    pub(crate) height: u32,
    /// Packed RGBA8 texel bytes for this mip level (`width * height * 4`).
    pub(crate) rgba8: Vec<u8>,
}

/// Immutable `Arc`-shared quantized 24-byte vertex, `u32` index, 16-byte skin sidecar, and morph delta geometry buffer for `GpuPbrScenePass`.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct GpuPbrMeshBuffer {
    /// Monotonic revision incremented only when mesh library geometry changes.
    #[get(type(copy))]
    pub(crate) revision: u64,
    /// Packed 24-byte quantized vertices shared across all baked LOD levels.
    pub(crate) vertices: Vec<QuantizedVertex3D>,
    /// Contiguous triangle vertex indices referencing `vertices`.
    pub(crate) indices: Vec<u32>,
    /// Optional 16-byte skeletal skinning sidecars aligned with skinned vertex ranges.
    pub(crate) skin_vertices: Vec<QuantizedSkinVertex3D>,
    /// Optional flattened `[dx, dy, dz, dn]` morph target vertex deltas.
    pub(crate) morph_deltas: Vec<[f32; 4]>,
    /// Optional secondary half-precision UV (`TEXCOORD_1`) sidecar aligned with `vertices`.
    pub(crate) uv1_f16: Vec<[u16; 2]>,
    /// Per-mesh quantization de-normalization minimum bounds `[x, y, z, 0.0]`.
    pub(crate) mesh_bounds_min: Vec<[f32; 4]>,
    /// Per-mesh quantization de-normalization extent `[sx, sy, sz, 0.0]`.
    pub(crate) mesh_bounds_extent: Vec<[f32; 4]>,
}

/// Compact `#[repr(C)]` material-sorted instanced object payload for `GpuPbrScenePass`.
#[repr(C)]
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct GpuPbrInstance3D {
    /// Column-major 4x4 object-to-world model matrix.
    #[get(type(copy))]
    pub(crate) model: [f32; 16],
    /// Local-space quantization AABB minimum `[min_x, min_y, min_z, object_id_bits]`.
    #[get(type(copy))]
    pub(crate) quant_origin_id: [f32; 4],
    /// Local-space quantization AABB extent `[ext_x, ext_y, ext_z, lod_bias]`.
    #[get(type(copy))]
    pub(crate) quant_extent_lod: [f32; 4],
    /// Material slot, bone matrix base offset, morph weight base offset, and instance flags `[mat, bone_off, morph_off, flags]`.
    #[get(type(copy))]
    pub(crate) material_skin_morph_flags: [u32; 4],
}

/// Indexed instanced draw range sorted by 64-bit `(alpha|pso|material|mesh|lod)` key for `GpuPbrScenePass`.
#[repr(C)]
#[derive(Clone, Copy, Data, Debug, Default, Eq, Hash, PartialEq)]
pub struct GpuPbrDrawBatch {
    /// Starting index offset inside `GpuPbrMeshBuffer::indices`.
    #[get(type(copy))]
    pub(crate) index_start: u32,
    /// Number of triangle indices drawn per instance.
    #[get(type(copy))]
    pub(crate) index_count: u32,
    /// Base vertex offset added to indices inside `GpuPbrMeshBuffer::vertices`.
    #[get(type(copy))]
    pub(crate) base_vertex: u32,
    /// Starting instance index inside `GpuPbrScenePass::instances`.
    #[get(type(copy))]
    pub(crate) instance_start: u32,
    /// Number of consecutive instances drawn in this batch.
    #[get(type(copy))]
    pub(crate) instance_count: u32,
    /// Material table index into `GpuPbrScenePass::materials`.
    #[get(type(copy))]
    pub(crate) material_index: u32,
    /// Pipeline state variant (`0=OpaquePbr, 1=SkinnedPbr, 2=AlphaBlendPbr`).
    #[get(type(copy))]
    pub(crate) pso_variant: u8,
    /// Selected geometric LOD tier (`0..=3`).
    #[get(type(copy))]
    pub(crate) lod_level: u8,
    /// Reserved alignment padding bytes.
    #[get(type(copy))]
    pub(crate) reserved: [u8; 2],
    /// 64-bit deterministic state sort key `(alpha | pso | material | mesh | lod | depth)`.
    #[get(type(copy))]
    pub(crate) sort_key: u64,
}

/// Hardware Z-buffered textured Principled BSDF PBR, GPU-skinned, morph-targeted, and meshlet-culled 3D scene pass descriptor.
#[derive(Clone, Data, Debug, Default, PartialEq)]
pub struct GpuPbrScenePass {
    /// 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],
    /// Previous frame column-major `projection * view` matrix for temporal velocity vectors.
    #[get(type(copy))]
    pub(crate) prev_view_proj: [f32; 16],
    /// Camera world position and exposure `[cx, cy, cz, exposure]`.
    #[get(type(copy))]
    pub(crate) camera_pos_exposure: [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 AgX tonemap toggle `[zr, zg, zb, use_agx]`.
    #[get(type(copy))]
    pub(crate) sky_zenith_agx: [f32; 4],
    /// L2 9-band Spherical Harmonics diffuse IBL irradiance coefficients `[r, g, b, pad]`.
    #[get(type(copy))]
    pub(crate) ibl_sh: [[f32; 4]; 9],
    /// Immutable `Arc`-shared quantized 24-byte mesh geometry, skin sidecar, and morph delta buffer.
    pub(crate) mesh_buffer: Arc<GpuPbrMeshBuffer>,
    /// Packed 160-byte std140 Principled BSDF materials uploaded to GPU storage memory.
    pub(crate) materials: Vec<GpuMaterialData3D>,
    /// Material/mesh/LOD-sorted instanced object payloads for this frame.
    pub(crate) instances: Vec<GpuPbrInstance3D>,
    /// Indexed instanced draw ranges sorted by PSO variant, material, mesh, and LOD.
    pub(crate) draw_batches: Vec<GpuPbrDrawBatch>,
    /// Flattened contiguous GPU skinning bone matrices (LBS/DQS).
    pub(crate) bone_matrices: Vec<[f32; 16]>,
    /// Flattened per-instance morph target blend weights.
    pub(crate) morph_weights: Vec<f32>,
    /// Up to 32 active local point, spot, and area lights.
    pub(crate) local_lights: Vec<GpuPackedLocalLight>,
    /// Budget-capped (`<= 4 MiB`, `<= 1.5 ms`) incremental texture mipmap uploads for this frame.
    pub(crate) texture_uploads: Vec<GpuTextureMipUpload>,
    /// Active debug shading visualization mode (`0=LitPBR, 1=Meshlets, 2=LodHeatmap, 3=MipResidency`).
    #[get(type(copy))]
    pub(crate) debug_view_mode: u8,
    /// Per-frame meshlet culling, LOD distribution, upload budget, and draw-call statistics.
    #[get(type(copy))]
    pub(crate) stats: GpuPbrCullStats,
}

/// 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,
}