Skip to main content

euv_core/game/engine3d/renderer/
struct.rs

1use super::*;
2
3/// Per-worker atomic wakeup epoch and condition variable slot eliminating shared-mutex contention and cache-line false sharing in `Engine3dWorkerPool`.
4#[cfg(not(target_arch = "wasm32"))]
5#[repr(align(128))]
6#[derive(Debug, Default)]
7pub(crate) struct Engine3dWorkerSlot {
8    /// Monotonically incremented epoch signaling this worker to run the active job.
9    pub(crate) epoch: AtomicUsize,
10    /// Non-zero while this worker is parked on `wake` and requires condvar notification.
11    pub(crate) parked: AtomicUsize,
12    /// Private sleep mutex paired with `wake`.
13    pub(crate) lock: Mutex<()>,
14    /// Condition variable waking this worker when parked between frames.
15    pub(crate) wake: Condvar,
16}
17
18/// Shared lock-free dispatch state coordinating caller and persistent 3D background workers.
19#[cfg(not(target_arch = "wasm32"))]
20#[repr(align(128))]
21#[derive(Debug)]
22pub(crate) struct Engine3dPoolShared {
23    /// Raw pointer address of the caller-pinned `Engine3dJob` (`0` when idle).
24    pub(crate) active_job: AtomicUsize,
25    /// Number of background workers woken for the active dispatch.
26    pub(crate) active_workers: AtomicUsize,
27    /// Non-zero while the calling thread is parked waiting for workers to complete.
28    pub(crate) caller_parked: AlignedAtomicUsize,
29    /// Caller sleep mutex paired with `wake_caller`.
30    pub(crate) caller_lock: Mutex<()>,
31    /// Condition variable waking the calling thread once all active workers finish.
32    pub(crate) wake_caller: Condvar,
33    /// Per-worker wakeup slots (`len == worker_count`).
34    pub(crate) slots: Vec<Engine3dWorkerSlot>,
35}
36
37/// Active work-stealing range job executed synchronously across caller and persistent 3D worker threads with 128-byte isolated atomics.
38#[cfg(not(target_arch = "wasm32"))]
39#[repr(align(128))]
40#[derive(Debug)]
41pub(crate) struct Engine3dJob {
42    /// Type-erased chunk execution trampoline.
43    pub(crate) trampoline: fn(usize, usize, usize),
44    /// Caller-pinned closure reference encoded as `usize`.
45    pub(crate) ctx_ptr: usize,
46    /// Total logical items across all chunks.
47    pub(crate) total_items: usize,
48    /// Number of items per dynamic work-stealing chunk.
49    pub(crate) chunk_size: usize,
50    /// Total chunks to claim (`total_items.div_ceil(chunk_size)`).
51    pub(crate) total_chunks: usize,
52    /// Cache-line-isolated atomic cursor of the next unclaimed chunk index.
53    pub(crate) next_chunk: AlignedAtomicUsize,
54    /// Cache-line-isolated atomic count of background workers finished observing this epoch.
55    pub(crate) workers_done: AlignedAtomicUsize,
56}
57
58/// Persistent warm thread pool eliminating per-frame OS thread spawns in `Renderer3D`.
59#[cfg(not(target_arch = "wasm32"))]
60#[derive(Debug)]
61pub(crate) struct Engine3dWorkerPool {
62    /// Number of background worker threads (excluding the calling thread).
63    pub(crate) worker_count: usize,
64    /// Non-blocking re-entrancy guard serializing top-level dispatches cleanly.
65    pub(crate) dispatch_lock: Mutex<()>,
66    /// Shared lock-free atomic dispatch state and per-worker wakeup slots.
67    pub(crate) shared: Arc<Engine3dPoolShared>,
68}
69
70/// Per-frame telemetry emitted by `Renderer3D` for live FPS/RT/LOD/Nanite/culling diagnostics.
71#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
72pub struct RenderStats3D {
73    /// Internal rasterized framebuffer width in pixels.
74    #[get(type(copy))]
75    pub(crate) render_width: u32,
76    /// Internal rasterized framebuffer height in pixels.
77    #[get(type(copy))]
78    pub(crate) render_height: u32,
79    /// Active objects rendered inside frustum & chunk stream radius.
80    #[get(type(copy))]
81    pub(crate) visible_objects: usize,
82    /// Objects rejected by 6-plane frustum culling or chunk draw distance.
83    #[get(type(copy))]
84    pub(crate) culled_objects: usize,
85    /// Deduplicated GPU instancing draw batches.
86    #[get(type(copy))]
87    pub(crate) instanced_batches: usize,
88    /// Triangles rasterized after backface culling.
89    #[get(type(copy))]
90    pub(crate) triangles_drawn: usize,
91    /// BVH shadow/reflection/GI rays traced during this frame.
92    #[get(type(copy))]
93    pub(crate) rays_traced: usize,
94    /// Total BVH nodes active in the acceleration structure.
95    #[get(type(copy))]
96    pub(crate) bvh_nodes: usize,
97    /// Objects rendered at simplified distant LOD (`LOD1+`).
98    #[get(type(copy))]
99    pub(crate) lod_simplified_objects: usize,
100    /// Nanite-style meshlet clusters drawn this frame.
101    #[get(type(copy))]
102    pub(crate) meshlets_drawn: usize,
103    /// Nanite-style meshlet clusters culled by frustum or backface normal cones.
104    #[get(type(copy))]
105    pub(crate) meshlets_culled: usize,
106    /// Objects occluded by the conservative Hi-Z occlusion pyramid pre-pass.
107    #[get(type(copy))]
108    pub(crate) hiz_culled_objects: usize,
109    /// Active occupied cells inside the world-space Lumen Radiance Cache.
110    #[get(type(copy))]
111    pub(crate) lumen_cache_cells: usize,
112    /// Active point and spot lights binned into the 16x9x16 clustered froxel grid.
113    #[get(type(copy))]
114    pub(crate) active_local_lights: usize,
115    /// Depth-tested 3D Niagara particles composited this frame.
116    #[get(type(copy))]
117    pub(crate) particles_drawn: usize,
118    /// Coarse RT probes reused via analytical motion-vector temporal reprojection.
119    #[get(type(copy))]
120    pub(crate) probe_reproj_hits: usize,
121}
122
123/// Precomputed screen-space triangle rasterization setup record for parallel tiled G-Buffer rasterization.
124#[derive(Clone, Copy, Debug)]
125pub(crate) struct RasterTri2D {
126    /// Inclusive clamped top scanline index.
127    pub(crate) min_y: i32,
128    /// Inclusive clamped bottom scanline index.
129    pub(crate) max_y: i32,
130    /// Inclusive clamped left pixel coordinate.
131    pub(crate) min_x: i32,
132    /// Horizontal bounding-box span width (`max_x - min_x`).
133    pub(crate) span_max: i32,
134    /// Index into `shaded_tris`.
135    pub(crate) tri_id: u32,
136    /// Edge slopes `(dw0_dx, dw1_dx, dw2_dx)`.
137    pub(crate) slopes: [f32; 3],
138    /// Precomputed negative reciprocal edge slopes for span clipping.
139    pub(crate) neg_inv_slopes: [f32; 3],
140    /// Vertical barycentric step `(dw0_dy, dw1_dy, dw2_dy)`.
141    pub(crate) dw_dy: [f32; 3],
142    /// Barycentric coordinates evaluated at `(min_x + 0.5, min_y + 0.5)`.
143    pub(crate) w_start: [f32; 3],
144    /// Reverse-Z `1/w` evaluated at `(min_x + 0.5, min_y + 0.5)`.
145    pub(crate) inv_w_start: f32,
146    /// Horizontal `1/w` derivative per pixel.
147    pub(crate) d_inv_w_dx: f32,
148    /// Vertical `1/w` derivative per scanline.
149    pub(crate) d_inv_w_dy: f32,
150}
151
152/// Precomputed per-triangle Cook-Torrance GGX PBR shading record referenced by deferred G-Buffer indices.
153#[derive(Clone, Copy, Debug)]
154pub(crate) struct GShadeTri {
155    /// Camera-facing unit shading normal.
156    pub(crate) shade_n: Vec3,
157    /// Material linear base albedo.
158    pub(crate) mat_base: Vec3,
159    /// Material linear emissive radiance.
160    pub(crate) mat_emissive: Vec3,
161    /// Precomputed hemisphere sky ambient tint.
162    pub(crate) ambient_sky: Vec3,
163    /// Precomputed Schlick base specular reflectance `F0 = lerp(0.04, albedo, metallic)`.
164    pub(crate) f0: Vec3,
165    /// Clamped directional sun Lambertian term `max(N·L, 0)`.
166    pub(crate) n_dot_l: f32,
167    /// GGX roughness squared (`alpha^2 = roughness^4`).
168    pub(crate) alpha2: f32,
169    /// Energy-conserving diffuse scale `(1.0 - metallic)`.
170    pub(crate) diffuse_scale: f32,
171    /// Surface base reflectivity weight `[0.0, 1.0]`.
172    pub(crate) mat_refl: f32,
173    /// Surface metallic scalar `[0.0, 1.0]`.
174    pub(crate) metallic: f32,
175    /// Whether this surface traces specular reflections.
176    pub(crate) do_refl: bool,
177    /// Procedural surface detail mode attached to the triangle's material.
178    pub(crate) surface_detail: SurfaceDetailMode,
179}
180
181/// Structure-of-Arrays coarse deferred ray-tracing probe grid enabling contiguous SIMD bilateral denoise and upsampling.
182#[derive(Clone, Debug, Default)]
183pub(crate) struct RtProbeGridSoa {
184    /// Sun visibility factor per probe (`1.0` lit, `0.22` shadowed).
185    pub(crate) shadow: Vec<f32>,
186    /// Traced reflection linear red radiance.
187    pub(crate) refl_r: Vec<f32>,
188    /// Traced reflection linear green radiance.
189    pub(crate) refl_g: Vec<f32>,
190    /// Traced reflection linear blue radiance.
191    pub(crate) refl_b: Vec<f32>,
192    /// Colored indirect Lumen GI bounce red radiance.
193    pub(crate) gi_r: Vec<f32>,
194    /// Colored indirect Lumen GI bounce green radiance.
195    pub(crate) gi_g: Vec<f32>,
196    /// Colored indirect Lumen GI bounce blue radiance.
197    pub(crate) gi_b: Vec<f32>,
198    /// Ambient occlusion factor in `[0.42, 1.0]`.
199    pub(crate) ao: Vec<f32>,
200    /// Camera-space linear depth at probe center.
201    pub(crate) depth: Vec<f32>,
202    /// Surface normal X for bilateral edge stopping.
203    pub(crate) nx: Vec<f32>,
204    /// Surface normal Y for bilateral edge stopping.
205    pub(crate) ny: Vec<f32>,
206    /// Surface normal Z for bilateral edge stopping.
207    pub(crate) nz: Vec<f32>,
208    /// World-space surface X coordinate for temporal probe reprojection validation.
209    pub(crate) world_x: Vec<f32>,
210    /// World-space surface Y coordinate for temporal probe reprojection validation.
211    pub(crate) world_y: Vec<f32>,
212    /// World-space surface Z coordinate for temporal probe reprojection validation.
213    pub(crate) world_z: Vec<f32>,
214    /// Non-zero when this probe sits on valid scene geometry.
215    pub(crate) valid: Vec<u8>,
216}
217
218/// Fixed-capacity L1-stack single-row SoA probe buffer (`gw <= PROBE_ROW_STACK_CAP`) enabling zero-allocation streaming bilateral denoising inside `shade_deferred_band`.
219#[derive(Clone, Debug)]
220pub(crate) struct RtProbeRowStack {
221    /// Sun visibility factor across one probe row.
222    pub(crate) shadow: [f32; PROBE_ROW_STACK_CAP],
223    /// Reflection linear red radiance across one probe row.
224    pub(crate) refl_r: [f32; PROBE_ROW_STACK_CAP],
225    /// Reflection linear green radiance across one probe row.
226    pub(crate) refl_g: [f32; PROBE_ROW_STACK_CAP],
227    /// Reflection linear blue radiance across one probe row.
228    pub(crate) refl_b: [f32; PROBE_ROW_STACK_CAP],
229    /// Colored Lumen GI red radiance across one probe row.
230    pub(crate) gi_r: [f32; PROBE_ROW_STACK_CAP],
231    /// Colored Lumen GI green radiance across one probe row.
232    pub(crate) gi_g: [f32; PROBE_ROW_STACK_CAP],
233    /// Colored Lumen GI blue radiance across one probe row.
234    pub(crate) gi_b: [f32; PROBE_ROW_STACK_CAP],
235    /// Ambient occlusion factor across one probe row.
236    pub(crate) ao: [f32; PROBE_ROW_STACK_CAP],
237    /// Linear probe depth across one probe row.
238    pub(crate) depth: [f32; PROBE_ROW_STACK_CAP],
239    /// Surface normal X across one probe row.
240    pub(crate) nx: [f32; PROBE_ROW_STACK_CAP],
241    /// Surface normal Y across one probe row.
242    pub(crate) ny: [f32; PROBE_ROW_STACK_CAP],
243    /// Surface normal Z across one probe row.
244    pub(crate) nz: [f32; PROBE_ROW_STACK_CAP],
245    /// Validity flags (`0` sky, `1` geometry) across one probe row.
246    pub(crate) valid: [u8; PROBE_ROW_STACK_CAP],
247}
248
249/// Per-thread persistent L1-hot 2-row probe denoise scratch avoiding 25 KB per-band stack zero-initialization and reusing denoised boundary rows across contiguous chunks.
250#[derive(Clone, Debug)]
251pub(crate) struct RtProbeRowScratch {
252    /// Monotonic frame generation tag invalidating cached rows across frames.
253    pub(crate) frame_gen: u64,
254    /// Probe row index cached in `buf_a` (`usize::MAX` if invalid).
255    pub(crate) cached_gy_a: usize,
256    /// Probe row index cached in `buf_b` (`usize::MAX` if invalid).
257    pub(crate) cached_gy_b: usize,
258    /// First L1-hot denoised probe row buffer.
259    pub(crate) buf_a: RtProbeRowStack,
260    /// Second L1-hot denoised probe row buffer.
261    pub(crate) buf_b: RtProbeRowStack,
262}
263
264/// Zero-copy borrowed view over one contiguous row of SoA RT probes (stack-denoised or wide pre-denoised).
265#[derive(Clone, Copy)]
266pub(crate) struct RtProbeRowView<'a> {
267    /// Sun visibility slice for this row.
268    pub(crate) shadow: &'a [f32],
269    /// Reflection red slice.
270    pub(crate) refl_r: &'a [f32],
271    /// Reflection green slice.
272    pub(crate) refl_g: &'a [f32],
273    /// Reflection blue slice.
274    pub(crate) refl_b: &'a [f32],
275    /// Lumen GI red slice.
276    pub(crate) gi_r: &'a [f32],
277    /// Lumen GI green slice.
278    pub(crate) gi_g: &'a [f32],
279    /// Lumen GI blue slice.
280    pub(crate) gi_b: &'a [f32],
281    /// Ambient occlusion slice.
282    pub(crate) ao: &'a [f32],
283    /// Linear depth slice.
284    pub(crate) depth: &'a [f32],
285    /// Normal X slice.
286    pub(crate) nx: &'a [f32],
287    /// Normal Y slice.
288    pub(crate) ny: &'a [f32],
289    /// Normal Z slice.
290    pub(crate) nz: &'a [f32],
291    /// Validity flags slice.
292    pub(crate) valid: &'a [u8],
293}
294
295/// 16-byte-aligned 2x2 bilinear probe cell packed into 4-lane SIMD arrays and cached across consecutive horizontal pixels sharing `(gx0, gx1, tid)`.
296#[repr(C, align(16))]
297#[derive(Clone, Copy)]
298pub(crate) struct CachedProbeCell {
299    /// Four corner linear depths `[p00, p10, p01, p11]`.
300    pub(crate) depth: [f32; 4],
301    /// Four corner sun visibility factors.
302    pub(crate) shadow: [f32; 4],
303    /// Four corner reflection linear red samples.
304    pub(crate) refl_r: [f32; 4],
305    /// Four corner reflection linear green samples.
306    pub(crate) refl_g: [f32; 4],
307    /// Four corner reflection linear blue samples.
308    pub(crate) refl_b: [f32; 4],
309    /// Four corner GI linear red samples.
310    pub(crate) gi_r: [f32; 4],
311    /// Four corner GI linear green samples.
312    pub(crate) gi_g: [f32; 4],
313    /// Four corner GI linear blue samples.
314    pub(crate) gi_b: [f32; 4],
315    /// Four corner ambient occlusion samples.
316    pub(crate) ao: [f32; 4],
317    /// Four corner bilateral depth tolerance scale (`0.58` high-agreement, `0.20` low-agreement).
318    pub(crate) tol_scale: [f32; 4],
319    /// Four corner bilateral depth tolerance bias (`2.4` high-agreement, `0.75` low-agreement).
320    pub(crate) tol_bias: [f32; 4],
321    /// Four corner SIMD validity bitmasks (`0xFFFF_FFFF` when corner passes normal test, else `0`).
322    pub(crate) valid_u32: [u32; 4],
323    /// Compact 4-bit corner validity mask (`0` triggers immediate edge fallback).
324    pub(crate) vmask: u8,
325}
326
327/// 16-byte-aligned 32-pixel L1-hot Structure-of-Arrays run scratch decoupling probe bilateral upsampling from zero-spill specialized PBR shading kernels.
328#[repr(C, align(16))]
329#[derive(Clone, Copy)]
330pub(crate) struct RunScratch32 {
331    /// Linear camera depth for up to 32 contiguous pixels of one triangle.
332    pub(crate) depths: [f32; 32],
333    /// Interpolated sun shadow factor for up to 32 pixels.
334    pub(crate) shadow: [f32; 32],
335    /// Interpolated reflection linear red for up to 32 pixels.
336    pub(crate) refl_r: [f32; 32],
337    /// Interpolated reflection linear green for up to 32 pixels.
338    pub(crate) refl_g: [f32; 32],
339    /// Interpolated reflection linear blue for up to 32 pixels.
340    pub(crate) refl_b: [f32; 32],
341    /// Interpolated Lumen GI linear red for up to 32 pixels.
342    pub(crate) gi_r: [f32; 32],
343    /// Interpolated Lumen GI linear green for up to 32 pixels.
344    pub(crate) gi_g: [f32; 32],
345    /// Interpolated Lumen GI linear blue for up to 32 pixels.
346    pub(crate) gi_b: [f32; 32],
347    /// Interpolated ambient occlusion for up to 32 pixels.
348    pub(crate) ao: [f32; 32],
349}
350
351/// Writable 4-pixel scanline slice targets and optional quarter-res HDR bloom slot for `shade_span_4x_specialized`.
352pub(crate) struct SpanShadeOut<'a> {
353    /// 16-byte RGBA8 destination span.
354    pub(crate) rgba: &'a mut [u8],
355    /// 4-byte Rec.601 luma destination span.
356    pub(crate) luma: &'a mut [u8],
357    /// Optional `(lane_index, bloom_cell)` HDR excess radiance slot.
358    pub(crate) bloom: Option<(usize, &'a mut [f32; 4])>,
359}
360
361/// Writable full-scanline color, luma, and quarter-res bloom buffers passed to 32-pixel run shaders.
362pub(crate) struct RunRowOut<'a> {
363    /// Full scanline RGBA8 output slice.
364    pub(crate) color: &'a mut [u8],
365    /// Full scanline Rec.601 luma output slice.
366    pub(crate) luma: &'a mut [u8],
367    /// Whether bloom extraction is active on this scanline (`(py & 3) == 0`).
368    pub(crate) write_bloom: bool,
369    /// Starting index of this scanline's bloom row inside `bloom_band`.
370    pub(crate) bloom_off: usize,
371    /// Writable quarter-resolution HDR bloom band slice.
372    pub(crate) bloom_band: &'a mut [[f32; 4]],
373    /// Pre-baked hemi-octahedral atmospheric sky dome LUT for animated ocean reflections.
374    pub(crate) sky_lut: &'a [[f32; 3]],
375    /// Precomputed L1-resident ACES filmic + sRGB gamma LUT (`ACES3D_LUT_SIZE`).
376    pub(crate) aces_lut: &'a [u8],
377}
378
379/// Shared read-only probe rows and horizontal bilinear stepping context for `upsample_run_probes_32` and `shade_tri_run_4x`.
380#[derive(Clone, Copy)]
381pub(crate) struct ProbeBandContext<'a> {
382    /// Top denoised probe row view `gy0`.
383    pub(crate) top_row: &'a RtProbeRowView<'a>,
384    /// Bottom denoised probe row view `gy1`.
385    pub(crate) bottom_row: &'a RtProbeRowView<'a>,
386    /// Vertical bilinear weight for `r0`.
387    pub(crate) wy0: f32,
388    /// Vertical bilinear weight for `r1`.
389    pub(crate) wy1: f32,
390    /// Maximum valid coarse probe column index `gw - 1`.
391    pub(crate) gw_max: usize,
392    /// Doubled integer probe stride `rt_step * 2`.
393    pub(crate) step2_i32: i32,
394    /// Precomputed fractional horizontal lookup table indexed by `sub_x`.
395    pub(crate) fx_lut: &'a [f32; 16],
396}
397
398/// Raw writable base addresses for lock-free disjoint-tile writes into `RtProbeGridSoa`.
399#[derive(Clone, Copy, Debug)]
400pub(crate) struct RtProbeGridMutPtrs {
401    /// Base pointer for `shadow`.
402    pub(crate) shadow: usize,
403    /// Base pointer for `refl_r`.
404    pub(crate) refl_r: usize,
405    /// Base pointer for `refl_g`.
406    pub(crate) refl_g: usize,
407    /// Base pointer for `refl_b`.
408    pub(crate) refl_b: usize,
409    /// Base pointer for `gi_r`.
410    pub(crate) gi_r: usize,
411    /// Base pointer for `gi_g`.
412    pub(crate) gi_g: usize,
413    /// Base pointer for `gi_b`.
414    pub(crate) gi_b: usize,
415    /// Base pointer for `ao`.
416    pub(crate) ao: usize,
417    /// Base pointer for `depth`.
418    pub(crate) depth: usize,
419    /// Base pointer for `nx`.
420    pub(crate) nx: usize,
421    /// Base pointer for `ny`.
422    pub(crate) ny: usize,
423    /// Base pointer for `nz`.
424    pub(crate) nz: usize,
425    /// Base pointer for `world_x`.
426    pub(crate) world_x: usize,
427    /// Base pointer for `world_y`.
428    pub(crate) world_y: usize,
429    /// Base pointer for `world_z`.
430    pub(crate) world_z: usize,
431    /// Base pointer for `valid`.
432    pub(crate) valid: usize,
433}
434
435/// Shared read-only inputs for fused Barrier 1 tiled rasterization and L1-hot coherent 2x2 probe packet tracing.
436pub(crate) struct TileRasterProbeInputs<'a> {
437    /// Screen-space triangle setup records.
438    pub(crate) raster_tris: &'a [RasterTri2D],
439    /// Flat CSR prefix offsets per tile (`len == total_tiles + 1`).
440    pub(crate) tile_offsets: &'a [u32],
441    /// Binned triangle indices into `raster_tris`.
442    pub(crate) tile_tri_indices: &'a [u32],
443    /// Precomputed GGX triangle shading records.
444    pub(crate) shaded_tris: &'a [GShadeTri],
445    /// Static world BVH4/BVH8 acceleration structure.
446    pub(crate) static_bvh: &'a Bvh3D,
447    /// Active object-space dynamic raytracing instances.
448    pub(crate) dyn_instances: &'a [DynamicRayInstance],
449    /// Local-space BVH4/BVH8 cache indexed by `mesh_id`.
450    pub(crate) local_bvhs: &'a [Option<Bvh3D>],
451    /// Previous frame coarse RT probe grid for world-space-validated temporal checkerboard reuse.
452    pub(crate) prev_probes: Option<&'a RtProbeGridSoa>,
453    /// Previous frame view-projection matrix for analytical motion-vector probe reprojection.
454    pub(crate) prev_view_proj: Mat4,
455    /// Previous frame internal framebuffer `(width, height)` for motion-vector reprojection.
456    pub(crate) prev_render_dims: (usize, usize),
457    /// Previous frame coarse RT probe stride.
458    pub(crate) prev_rt_step: usize,
459    /// Previous frame coarse RT probe grid width.
460    pub(crate) prev_gw: usize,
461    /// Previous frame coarse RT probe grid height.
462    pub(crate) prev_gh: usize,
463    /// Optional read-only world-space Lumen Radiance Cache for O(1) multi-bounce indirect GI lookups.
464    pub(crate) lumen_cache: Option<&'a LumenRadianceCache>,
465    /// Optional read-only Clustered Deferred local light grid evaluated per coarse probe.
466    pub(crate) light_clusters: Option<&'a LightClusterGrid3D>,
467    /// Optional read-only Virtual Shadow Map for zero-BVH-ray distant shadow sampling.
468    pub(crate) vsm: Option<&'a VirtualShadowMap>,
469    /// Enables O(1) VSM lookup for distant probes (`depth > 42m`) instead of long-range BVH shadow rays.
470    pub(crate) use_vsm_far_shadows: bool,
471    /// Alternating checkerboard parity (`0` or `1`) selecting which 2x2 probe blocks refresh vs reuse.
472    pub(crate) probe_checker_parity: usize,
473    /// Whether the camera projection, dimensions, and RT probe stride match the previous frame identically.
474    pub(crate) same_camera_pose: bool,
475    /// Tile edge dimension in pixels (`<= 64`, multiple of `rt_step` when RT active).
476    pub(crate) tile_px: usize,
477    /// Number of tiles horizontally.
478    pub(crate) tiles_x: usize,
479    /// Pre-baked hemi-octahedral atmospheric sky dome LUT for clouded/starry reflection hits.
480    pub(crate) sky_lut: &'a [[f32; 3]],
481}
482
483/// Shared read-only inputs for fused Barrier 2 streaming bilateral denoise and vectorized deferred PBR shading.
484pub(crate) struct ShadeBandInputs<'a> {
485    /// Reverse-Z `1/w` depth buffer.
486    pub(crate) depth_buf: &'a [f32],
487    /// Deferred G-Buffer triangle IDs.
488    pub(crate) g_tri_idx: &'a [u32],
489    /// Precomputed GGX triangle shading records.
490    pub(crate) shaded_tris: &'a [GShadeTri],
491    /// Raw coarse RT probe SoA grid written by Barrier 1.
492    pub(crate) raw_probes: &'a RtProbeGridSoa,
493    /// Optional pre-denoised full probe grid used only when `gw > 256` (e.g. 4K viewports).
494    pub(crate) wide_denoised_probes: &'a RtProbeGridSoa,
495    /// Whether bilateral 3x3 probe denoising is active during row streaming (`gw <= 256`).
496    pub(crate) denoise_probes: bool,
497    /// Whether GI/AO channels require 3x3 bilateral denoising (`true` for `FullPathTracedGi`, `false` for analytic clustered local lights).
498    pub(crate) denoise_gi_channels: bool,
499    /// Static world BVH4/BVH8 acceleration structure.
500    pub(crate) static_bvh: &'a Bvh3D,
501    /// Active object-space dynamic raytracing instances.
502    pub(crate) dyn_instances: &'a [DynamicRayInstance],
503    /// Local-space BVH4/BVH8 cache indexed by `mesh_id`.
504    pub(crate) local_bvhs: &'a [Option<Bvh3D>],
505    /// Atomic bitset marking quarter-resolution bloom rows that received non-zero HDR radiance (`576` bits -> `bh <= 576`).
506    pub(crate) bloom_row_bits: &'a [AtomicU64; 9],
507    /// Pre-baked hemi-octahedral atmospheric sky dome LUT for primary sky and edge reflection hits.
508    pub(crate) sky_lut: &'a [[f32; 3]],
509    /// Precomputed L1-resident ACES filmic + sRGB gamma LUT (`ACES3D_LUT_SIZE`).
510    pub(crate) aces_lut: &'a [u8],
511}
512
513/// Shared read-only inputs for Barrier 3 vectorized FXAA/MLAA/TAA and bilinear HDR bloom compositing.
514pub(crate) struct PostProcessInputs<'a> {
515    /// Tone-mapped RGBA8 intermediate framebuffer.
516    pub(crate) color_src: &'a [u8],
517    /// Rec.601 luma buffer populated during deferred shading.
518    pub(crate) luma: &'a [u8],
519    /// Deferred G-Buffer triangle IDs for geometry-aware AA edge detection.
520    pub(crate) g_tri_idx: &'a [u32],
521    /// Blurred quarter-resolution HDR bloom buffer (`[r, g, b, 0]`).
522    pub(crate) bloom: &'a [[f32; 4]],
523    /// Active bloom tile mask (`1` where bloom contributes `>= 1` RGB LSB).
524    pub(crate) bloom_tile_active: &'a [u8],
525    /// Previous frame RGBA8 TAA temporal history buffer.
526    pub(crate) taa_history: &'a [u8],
527}
528
529/// Immutable per-frame camera, lighting, volumetric, and ray-tracing configuration shared across worker threads.
530#[derive(Clone, Copy, Debug)]
531pub(crate) struct DeferredFrameContext {
532    /// Framebuffer width in pixels.
533    pub(crate) width: usize,
534    /// Framebuffer height in pixels.
535    pub(crate) height: usize,
536    /// Coarse RT grid width in probes.
537    pub(crate) grid_width: usize,
538    /// Coarse RT grid height in probes.
539    pub(crate) grid_height: usize,
540    /// Quarter-res HDR bloom width.
541    pub(crate) bloom_width: usize,
542    /// Pixel stride per coarse RT probe.
543    pub(crate) raytrace_step: usize,
544    /// Reciprocal framebuffer width.
545    pub(crate) inv_width: f32,
546    /// Reciprocal framebuffer height.
547    pub(crate) inv_height: f32,
548    /// Camera world position.
549    pub(crate) camera_position: Vec3,
550    /// Camera unit forward basis.
551    pub(crate) camera_forward: Vec3,
552    /// Camera right basis scaled by `half_w`.
553    pub(crate) camera_right_scaled: Vec3,
554    /// Camera up basis scaled by `half_h`.
555    pub(crate) camera_up_scaled: Vec3,
556    /// Active directional sun & sky parameters.
557    pub(crate) sun: DirectionalLight3D,
558    /// Precomputed safe reciprocal sun direction for fast shadow BVH traversal.
559    pub(crate) inv_sun_dir: Vec3,
560    /// Precomputed 16-tap Vogel-disk blue-noise soft-shadow `(dir, inv_dir)` ray table hoisted once per frame.
561    pub(crate) soft_shadow_rays: [(Vec3, Vec3); 16],
562    /// Monotonic frame index driving deterministic blue-noise temporal rotation across TSR/TAA frames.
563    pub(crate) frame_index: usize,
564    /// Active ray-tracing quality tier.
565    pub(crate) raytrace_mode: RayTracingMode,
566    /// Maximum reflection/GI bounce depth (`0..=3`).
567    pub(crate) reflection_bounces: u8,
568    /// Whether volumetric height/distance fog and crepuscular sun-shafts are enabled.
569    pub(crate) fog_on: bool,
570    /// Precomputed inverse fog attenuation distance.
571    pub(crate) inv_fog_distance: f32,
572    /// Exposure scale derived from physically based camera EV100.
573    pub(crate) exposure_scale: f32,
574    /// Whether quarter-res emissive/specular bloom extraction is active.
575    pub(crate) bloom_on: bool,
576    /// Whether dynamic local point/spot lights are active in `LightClusterGrid3D` and injected into the GI probe channels.
577    pub(crate) has_clustered_lights: bool,
578    /// Monotonic frame generation tag for per-thread probe denoise scratch cache invalidation.
579    pub(crate) probe_frame_generation: u64,
580    /// Monotonic world simulation time in seconds driving animated 3D ocean waves, caustics, and shoreline foam.
581    pub(crate) world_time_secs: f32,
582}
583
584/// Per-chunk reusable scratch buffers eliminating heap allocations in the 8-way parallel geometry front-end.
585#[derive(Clone, Debug, Default)]
586pub(crate) struct GeomChunkScratch {
587    /// Per-chunk precomputed GGX shading triangle records.
588    pub(crate) shaded_tris: Vec<GShadeTri>,
589    /// Per-chunk precomputed screen-space rasterization setup records.
590    pub(crate) raster_tris: Vec<RasterTri2D>,
591    /// Per-chunk transformed vertex scratch `(clip_pos, world_pos)`.
592    pub(crate) projected_verts: Vec<([f32; 4], Vec3)>,
593    /// Per-chunk visible meshlet triangle ranges.
594    pub(crate) cluster_ranges: Vec<(usize, usize)>,
595    /// Per-chunk visible object count.
596    pub(crate) visible_objects: usize,
597    /// Per-chunk Hi-Z occluded object count.
598    pub(crate) hiz_culled_objects: usize,
599    /// Per-chunk simplified LOD object count.
600    pub(crate) lod_simplified_objects: usize,
601    /// Per-chunk drawn meshlet count.
602    pub(crate) meshlets_drawn: usize,
603    /// Per-chunk culled meshlet count.
604    pub(crate) meshlets_culled: usize,
605    /// Per-chunk unique mesh IDs for instanced batch telemetry.
606    pub(crate) mesh_ids: Vec<usize>,
607}
608
609/// Shared read-only scene, frustum, Hi-Z, and lighting state passed to per-object geometry front-end projection.
610pub(crate) struct GeomPassContext<'a> {
611    /// All scene objects in the world.
612    pub(crate) objects: &'a [SceneObject3D],
613    /// Mesh LOD chain library indexed by `mesh_id`.
614    pub(crate) mesh_lib: &'a [MeshLodChain],
615    /// Conservative Hi-Z depth pyramid for occlusion queries.
616    pub(crate) hiz_pyramid: &'a HiZPyramid,
617    /// Flags marking near pre-pass occluders (`1` = stamped occluder).
618    pub(crate) hiz_occluder_flags: &'a [u8],
619    /// Active view frustum planes.
620    pub(crate) frustum: Frustum3D,
621    /// Current frame view-projection matrix.
622    pub(crate) view_proj: Mat4,
623    /// Camera world-space position.
624    pub(crate) cam_pos: Vec3,
625    /// Normalized directional sun vector.
626    pub(crate) sun_dir: Vec3,
627    /// Linear HDR horizon sky color.
628    pub(crate) sky_horizon: Vec3,
629    /// Linear HDR zenith sky color.
630    pub(crate) sky_zenith: Vec3,
631    /// Vertical projection focal length in pixels.
632    pub(crate) focal_px: f32,
633    /// LOD distance bias multiplier.
634    pub(crate) lod_bias: f32,
635    /// Clamped near clip plane distance.
636    pub(crate) near_plane: f32,
637    /// Render viewport width in pixels as `f32`.
638    pub(crate) w_f: f32,
639    /// Render viewport height in pixels as `f32`.
640    pub(crate) h_f: f32,
641    /// Maximum valid pixel X coordinate (`width - 1`).
642    pub(crate) w_max_i: i32,
643    /// Maximum valid pixel Y coordinate (`height - 1`).
644    pub(crate) h_max_i: i32,
645    /// Subpixel temporal jitter X in pixels.
646    pub(crate) jitter_x: f32,
647    /// Subpixel temporal jitter Y in pixels.
648    pub(crate) jitter_y: f32,
649    /// Whether frustum and meshlet culling are active.
650    pub(crate) frustum_on: bool,
651    /// Whether Hi-Z occlusion culling is active.
652    pub(crate) hiz_active: bool,
653    /// Whether ray-traced reflections are enabled.
654    pub(crate) use_rt_refl: bool,
655}
656
657/// Writable per-pass or per-chunk geometry buffers and counters updated by `process_visible_object_geom`.
658pub(crate) struct GeomPassOut<'a> {
659    /// Destination precomputed GGX triangle shading list.
660    pub(crate) shaded_tris: &'a mut Vec<GShadeTri>,
661    /// Destination 2D screen-space raster setup list.
662    pub(crate) raster_tris: &'a mut Vec<RasterTri2D>,
663    /// Reusable per-object transformed vertex buffer.
664    pub(crate) projected_verts: &'a mut Vec<([f32; 4], Vec3)>,
665    /// Reusable per-object visible meshlet triangle ranges.
666    pub(crate) cluster_ranges: &'a mut Vec<(usize, usize)>,
667    /// Optional mesh ID accumulator for parallel chunks (`None` when writing directly to `unique_meshes`).
668    pub(crate) mesh_ids: Option<&'a mut Vec<usize>>,
669    /// Optional direct unique mesh set for sequential processing.
670    pub(crate) unique_meshes: Option<&'a mut HashSet<usize>>,
671    /// Visible object count accumulator.
672    pub(crate) visible_objects: usize,
673    /// Hi-Z occluded object count accumulator.
674    pub(crate) hiz_culled_objects: usize,
675    /// Simplified LOD object count accumulator.
676    pub(crate) lod_simplified_objects: usize,
677    /// Drawn meshlet count accumulator.
678    pub(crate) meshlets_drawn: usize,
679    /// Culled meshlet count accumulator.
680    pub(crate) meshlets_culled: usize,
681}
682
683/// Zero-allocation UE5-class Deferred GGX PBR + Persistent Multi-Core SIMD BVH4/BVH8 + Nanite Hi-Z + Lumen GI + VSM + Clustered Lighting + TSR 3D renderer.
684#[derive(Clone, Data, Debug)]
685pub struct Renderer3D {
686    /// Pre-allocated RGBA8 tone-mapped intermediate pixel buffer.
687    pub(crate) color_buffer: Vec<u8>,
688    /// Pre-allocated RGBA8 temporal history buffer for variance-clamped TAA.
689    pub(crate) aa_buffer: Vec<u8>,
690    /// Pre-allocated floating-point linear `1/w` reverse-Z depth buffer (`0.0` = sky).
691    pub(crate) depth_buffer: Vec<f32>,
692    /// Deferred G-Buffer triangle index per pixel (`u32::MAX` = sky).
693    #[get(skip)]
694    #[get_mut(skip)]
695    #[set(skip)]
696    pub(crate) g_tri_idx: Vec<u32>,
697    /// Single-byte per-pixel Rec.601 luma buffer populated during deferred shading for fast morphological AA.
698    #[get(skip)]
699    #[get_mut(skip)]
700    #[set(skip)]
701    pub(crate) luma_buffer: Vec<u8>,
702    /// Per-frame precomputed GGX triangle shading records.
703    #[get(skip)]
704    #[get_mut(skip)]
705    #[set(skip)]
706    pub(crate) shaded_tris: Vec<GShadeTri>,
707    /// Persistent reusable RGBA8 final output buffer eliminating per-frame allocations in `render_world_rgba`.
708    #[get(skip)]
709    #[get_mut(skip)]
710    #[set(skip)]
711    pub(crate) rgba_scratch: Vec<u8>,
712    /// Structure-of-Arrays coarse coherent ray-tracing probe grid.
713    #[get(skip)]
714    #[get_mut(skip)]
715    #[set(skip)]
716    pub(crate) rt_probes: RtProbeGridSoa,
717    /// Previous frame coarse RT probe grid swapped in O(1) for temporal checkerboard probe reuse.
718    #[get(skip)]
719    #[get_mut(skip)]
720    #[set(skip)]
721    pub(crate) prev_rt_probes: RtProbeGridSoa,
722    /// Whether `prev_rt_probes` holds valid history matching `(prev_probe_gw, prev_probe_gh, prev_probe_rt_mode)`.
723    #[get(skip)]
724    #[get_mut(skip)]
725    #[set(skip)]
726    pub(crate) has_probe_history: bool,
727    /// Coarse probe width stored in `prev_rt_probes`.
728    #[get(skip)]
729    #[get_mut(skip)]
730    #[set(skip)]
731    pub(crate) prev_probe_gw: usize,
732    /// Coarse probe height stored in `prev_rt_probes`.
733    #[get(skip)]
734    #[get_mut(skip)]
735    #[set(skip)]
736    pub(crate) prev_probe_gh: usize,
737    /// Ray-tracing mode stored in `prev_rt_probes`.
738    #[get(skip)]
739    #[get_mut(skip)]
740    #[set(skip)]
741    pub(crate) prev_probe_rt_mode: RayTracingMode,
742    /// Previous frame directional sun vector for invalidating temporal probes on lighting changes.
743    #[get(skip)]
744    #[get_mut(skip)]
745    #[set(skip)]
746    pub(crate) prev_sun_dir: Vec3,
747    /// Fallback full-grid denoised SoA probe buffer used only when `gw > 256` (4K+).
748    #[get(skip)]
749    #[get_mut(skip)]
750    #[set(skip)]
751    pub(crate) rt_probes_wide_denoised: RtProbeGridSoa,
752    /// Quarter-res 16-byte-aligned HDR bloom extraction and vertical blur buffer.
753    #[get(skip)]
754    #[get_mut(skip)]
755    #[set(skip)]
756    pub(crate) bloom_a: Vec<[f32; 4]>,
757    /// Quarter-res 16-byte-aligned HDR bloom horizontal blur scratch buffer.
758    #[get(skip)]
759    #[get_mut(skip)]
760    #[set(skip)]
761    pub(crate) bloom_b: Vec<[f32; 4]>,
762    /// Quarter-res active-bloom tile mask (`1` when any bilinear corner contributes `>= 1` RGB LSB) skipping dark tiles in post-processing.
763    #[get(skip)]
764    #[get_mut(skip)]
765    #[set(skip)]
766    pub(crate) bloom_tile_active: Vec<u8>,
767    /// Reusable front-to-back object sorting scratch buffer.
768    #[get(skip)]
769    #[get_mut(skip)]
770    #[set(skip)]
771    pub(crate) visible_scratch: Vec<(f32, usize)>,
772    /// Reusable meshlet triangle-range scratch buffer eliminating per-object heap allocations.
773    #[get(skip)]
774    #[get_mut(skip)]
775    #[set(skip)]
776    pub(crate) cluster_ranges_scratch: Vec<(usize, usize)>,
777    /// Reusable per-object transformed vertex cache `(clip_pos, world_pos)` avoiding redundant vertex transforms.
778    #[get(skip)]
779    #[get_mut(skip)]
780    #[set(skip)]
781    pub(crate) projected_verts_scratch: Vec<([f32; 4], Vec3)>,
782    /// Reusable unique mesh-id set for instancing telemetry.
783    #[get(skip)]
784    #[get_mut(skip)]
785    #[set(skip)]
786    pub(crate) unique_meshes_scratch: HashSet<usize>,
787    /// Reusable saved dynamic-object transforms for zero-allocation interpolated rendering.
788    #[get(skip)]
789    #[get_mut(skip)]
790    #[set(skip)]
791    pub(crate) saved_objs_scratch: Vec<(usize, Transform3D, AxisAlignedBox3D)>,
792    /// Reusable screen-space triangle setup list for parallel tiled rasterization.
793    #[get(skip)]
794    #[get_mut(skip)]
795    #[set(skip)]
796    pub(crate) raster_tris_scratch: Vec<RasterTri2D>,
797    /// Reusable per-tile triangle count array for flat CSR binning.
798    #[get(skip)]
799    #[get_mut(skip)]
800    #[set(skip)]
801    pub(crate) tile_counts_scratch: Vec<u32>,
802    /// Reusable flat CSR prefix-sum offset array (`total_tiles + 1`).
803    #[get(skip)]
804    #[get_mut(skip)]
805    #[set(skip)]
806    pub(crate) tile_offsets_scratch: Vec<u32>,
807    /// Reusable per-tile insertion cursor array for flat CSR binning.
808    #[get(skip)]
809    #[get_mut(skip)]
810    #[set(skip)]
811    pub(crate) tile_cursors_scratch: Vec<u32>,
812    /// Reusable flat array of binned triangle indices across all screen tiles.
813    #[get(skip)]
814    #[get_mut(skip)]
815    #[set(skip)]
816    pub(crate) tile_tri_indices_scratch: Vec<u32>,
817    /// Optional shared-device GPU composite target for zero-readback single-pass UI+3D compositing.
818    #[get(skip)]
819    #[get_mut(skip)]
820    #[set(skip)]
821    pub(crate) gpu_target: GpuCompositeTarget,
822    /// Whether `aa_buffer` holds a valid previous frame compatible with temporal anti-aliasing.
823    #[get(skip)]
824    #[get_mut(skip)]
825    #[set(skip)]
826    pub(crate) has_taa_history: bool,
827    /// Previous frame view-projection fingerprint used to detect camera cuts for TAA.
828    #[get(skip)]
829    #[get_mut(skip)]
830    #[set(skip)]
831    pub(crate) prev_vp_m0: f32,
832    /// Full previous frame view-projection matrix driving analytical motion-vector probe reprojection and TSR.
833    #[get(skip)]
834    #[get_mut(skip)]
835    #[set(skip)]
836    pub(crate) prev_view_proj: Mat4,
837    /// Whether `prev_view_proj` contains a valid previous frame transform.
838    #[get(skip)]
839    #[get_mut(skip)]
840    #[set(skip)]
841    pub(crate) has_prev_vp: bool,
842    /// Previous frame internal render dimensions `(width, height)`.
843    #[get(skip)]
844    #[get_mut(skip)]
845    #[set(skip)]
846    pub(crate) prev_render_dims: (usize, usize),
847    /// Previous frame coarse RT probe stride.
848    #[get(skip)]
849    #[get_mut(skip)]
850    #[set(skip)]
851    pub(crate) prev_rt_step: usize,
852    /// Conservative reverse-Z hierarchical depth pyramid for Nanite-style occlusion culling.
853    #[get(skip)]
854    #[get_mut(skip)]
855    #[set(skip)]
856    pub(crate) hiz_pyramid: HiZPyramid,
857    /// Reusable occluder pre-pass flags marking stamped near occluders (`len == visible_scratch.len()`).
858    #[get(skip)]
859    #[get_mut(skip)]
860    #[set(skip)]
861    pub(crate) hiz_occluder_flags_scratch: Vec<u8>,
862    /// Persistent 2-cascade world-space Lumen Radiance Cache enabling O(1) multi-bounce indirect GI.
863    #[get(skip)]
864    #[get_mut(skip)]
865    #[set(skip)]
866    pub(crate) lumen_cache: LumenRadianceCache,
867    /// Pre-allocated 16x9x16 logarithmic-Z froxel grid for UE5 Clustered Deferred local lighting.
868    #[get(skip)]
869    #[get_mut(skip)]
870    #[set(skip)]
871    pub(crate) light_clusters: LightClusterGrid3D,
872    /// Two-cascade texel-snapped Virtual Shadow Map with static page caching and 4-tap PCF.
873    #[get(skip)]
874    #[get_mut(skip)]
875    #[set(skip)]
876    pub(crate) virtual_shadow_map: VirtualShadowMap,
877    /// UE5 Temporal Super Resolution upscaler reconstructing sub-native frames with motion vectors and RCAS.
878    #[get(skip)]
879    #[get_mut(skip)]
880    #[set(skip)]
881    pub(crate) tsr_upscaler: TsrUpscaler,
882    /// Reusable intermediate RGBA8 scratch buffer for sub-native TSR upscaling and bloom-to-TSR handoff.
883    #[get(skip)]
884    #[get_mut(skip)]
885    #[set(skip)]
886    pub(crate) tsr_internal_scratch: Vec<u8>,
887    /// Damped PI frame-pacing governor preventing FPS oscillation across variable GPU/CPU workloads.
888    pub(crate) frame_governor: AdaptiveFrameGovernor,
889    /// Compile-once UE5 Render Dependency Graph describing frame pass order and transient memory aliasing.
890    pub(crate) render_graph: RenderGraph3D,
891    /// Optional additive RT probe stride bias (`0..=2`) modulated by `AdaptiveFrameGovernor` under heavy load.
892    #[get(type(copy))]
893    pub(crate) rt_stride_bias: usize,
894    /// Persistent reusable per-chunk buffers for deterministic 8-way parallel geometry front-end processing in dense worlds.
895    #[get(skip)]
896    #[get_mut(skip)]
897    #[set(skip)]
898    pub(crate) geom_chunks_scratch: Vec<GeomChunkScratch>,
899    /// Smoothly adapted UE5-style eye-adaptation exposure multiplier (`1.0` on frame 0).
900    #[get(type(copy))]
901    pub(crate) adapted_exposure: f32,
902    /// Monotonic frame counter driving Halton(2, 3) temporal subpixel jitter.
903    #[get(skip)]
904    #[get_mut(skip)]
905    #[set(skip)]
906    pub(crate) frame_index: u32,
907    /// Last rendered `World3D::world_revision` enabling HUD-only dirty frames to reuse the cached 3D frame.
908    #[get(type(copy))]
909    pub(crate) last_world_revision: u64,
910    /// Quality and viewport configuration fingerprint paired with `last_world_revision`.
911    #[get(skip)]
912    #[get_mut(skip)]
913    #[set(skip)]
914    pub(crate) last_quality_fingerprint: u64,
915    /// Number of consecutive static-world TAA accumulation frames completed since the last world change.
916    #[get(type(copy))]
917    pub(crate) taa_accumulated_frames: u32,
918    /// Total HUD-only dirty frames satisfied from the cached 3D framebuffer without re-rasterizing.
919    #[get(type(copy))]
920    pub(crate) cached_world_reuses: u64,
921    /// Last rendered internal width.
922    #[get(type(copy))]
923    pub(crate) width: u32,
924    /// Last rendered internal height.
925    #[get(type(copy))]
926    pub(crate) height: u32,
927    /// Telemetry from the most recent frame.
928    #[get(type(copy))]
929    pub(crate) last_stats: RenderStats3D,
930    /// Pre-baked hemi-octahedral 3D atmospheric sky+cloud+star radiance LUT (`SKY3D_LUT_W * SKY3D_LUT_H`).
931    #[get(skip)]
932    #[get_mut(skip)]
933    #[set(skip)]
934    pub(crate) sky_lut: Vec<[f32; 3]>,
935    /// Fingerprint of the `DirectionalLight3D` baked into `sky_lut` (`0` = uninitialized).
936    #[get(skip)]
937    #[get_mut(skip)]
938    #[set(skip)]
939    pub(crate) sky_lut_key: u64,
940    /// Precomputed L1-resident ACES filmic + sRGB gamma LUT (`ACES3D_LUT_SIZE`).
941    #[get(skip)]
942    #[get_mut(skip)]
943    #[set(skip)]
944    pub(crate) aces_lut: Vec<u8>,
945    /// High-water scene object count for which steady-state scratch buffers are pre-reserved.
946    #[get(skip)]
947    #[get_mut(skip)]
948    #[set(skip)]
949    pub(crate) reserved_object_cap: usize,
950    /// High-water mesh library count for which steady-state scratch buffers are pre-reserved.
951    #[get(skip)]
952    #[get_mut(skip)]
953    #[set(skip)]
954    pub(crate) reserved_mesh_cap: usize,
955}