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    /// Optional index into `smooth_tris` (`u32::MAX` selects the flat legacy fast path).
180    pub(crate) smooth_idx: u32,
181}
182
183/// Perspective-correct per-vertex triangle attribute record enabling smooth normal/tangent/UV/color interpolation and full Blender Principled BSDF shading.
184#[derive(Clone, Copy, Debug)]
185pub(crate) struct GSmoothTri {
186    /// Clipped screen-space X coordinates `[sx0, sx1, sx2]`.
187    pub(crate) screen_x: [f32; 3],
188    /// Clipped screen-space Y coordinates `[sy0, sy1, sy2]`.
189    pub(crate) screen_y: [f32; 3],
190    /// Reciprocal clip W values `[inv_w0, inv_w1, inv_w2]` for perspective-correct interpolation.
191    pub(crate) inv_w: [f32; 3],
192    /// Reciprocal twice signed screen area `1.0 / area`.
193    pub(crate) inv_area: f32,
194    /// Per-vertex world-space unit surface normals.
195    pub(crate) normals: [Vec3; 3],
196    /// Per-vertex world-space tangent vectors `[tx, ty, tz, handedness_sign]`.
197    pub(crate) tangents: [[f32; 4]; 3],
198    /// Per-vertex primary UV coordinates (`TEXCOORD_0`).
199    pub(crate) uv0: [[f32; 2]; 3],
200    /// Per-vertex secondary UV coordinates (`TEXCOORD_1`).
201    pub(crate) uv1: [[f32; 2]; 3],
202    /// Per-vertex unpacked linear RGBA vertex colors (`COLOR_0`).
203    pub(crate) color0: [[f32; 4]; 3],
204    /// Optional index into `World3D::principled_materials` (`u32::MAX` uses legacy `PbrMaterial` with smooth normals).
205    pub(crate) principled_material_id: u32,
206    /// Whether back-facing fragments invert the interpolated normal (`double_sided`).
207    pub(crate) double_sided: bool,
208}
209
210/// Clipped near-plane triangle vertex carrying clip position, world position, and original triangle barycentric weights.
211#[derive(Clone, Copy, Debug)]
212pub(crate) struct ClippedBaryVert {
213    /// Homogeneous clip-space position `(x, y, z, w)`.
214    pub(crate) clip_pos: [f32; 4],
215    /// Interpolated world-space position.
216    pub(crate) world_pos: Vec3,
217    /// Original source-triangle barycentric weights `[b0, b1, b2]`.
218    pub(crate) bary: [f32; 3],
219}
220
221/// Structure-of-Arrays coarse deferred ray-tracing probe grid enabling contiguous SIMD bilateral denoise and upsampling.
222#[derive(Clone, Debug, Default)]
223pub(crate) struct RtProbeGridSoa {
224    /// Sun visibility factor per probe (`1.0` lit, `0.22` shadowed).
225    pub(crate) shadow: Vec<f32>,
226    /// Traced reflection linear red radiance.
227    pub(crate) refl_r: Vec<f32>,
228    /// Traced reflection linear green radiance.
229    pub(crate) refl_g: Vec<f32>,
230    /// Traced reflection linear blue radiance.
231    pub(crate) refl_b: Vec<f32>,
232    /// Colored indirect Lumen GI bounce red radiance.
233    pub(crate) gi_r: Vec<f32>,
234    /// Colored indirect Lumen GI bounce green radiance.
235    pub(crate) gi_g: Vec<f32>,
236    /// Colored indirect Lumen GI bounce blue radiance.
237    pub(crate) gi_b: Vec<f32>,
238    /// Ambient occlusion factor in `[0.42, 1.0]`.
239    pub(crate) ao: Vec<f32>,
240    /// Camera-space linear depth at probe center.
241    pub(crate) depth: Vec<f32>,
242    /// Surface normal X for bilateral edge stopping.
243    pub(crate) nx: Vec<f32>,
244    /// Surface normal Y for bilateral edge stopping.
245    pub(crate) ny: Vec<f32>,
246    /// Surface normal Z for bilateral edge stopping.
247    pub(crate) nz: Vec<f32>,
248    /// World-space surface X coordinate for temporal probe reprojection validation.
249    pub(crate) world_x: Vec<f32>,
250    /// World-space surface Y coordinate for temporal probe reprojection validation.
251    pub(crate) world_y: Vec<f32>,
252    /// World-space surface Z coordinate for temporal probe reprojection validation.
253    pub(crate) world_z: Vec<f32>,
254    /// Non-zero when this probe sits on valid scene geometry.
255    pub(crate) valid: Vec<u8>,
256}
257
258/// Fixed-capacity L1-stack single-row SoA probe buffer (`gw <= PROBE_ROW_STACK_CAP`) enabling zero-allocation streaming bilateral denoising inside `shade_deferred_band`.
259#[derive(Clone, Debug)]
260pub(crate) struct RtProbeRowStack {
261    /// Sun visibility factor across one probe row.
262    pub(crate) shadow: [f32; PROBE_ROW_STACK_CAP],
263    /// Reflection linear red radiance across one probe row.
264    pub(crate) refl_r: [f32; PROBE_ROW_STACK_CAP],
265    /// Reflection linear green radiance across one probe row.
266    pub(crate) refl_g: [f32; PROBE_ROW_STACK_CAP],
267    /// Reflection linear blue radiance across one probe row.
268    pub(crate) refl_b: [f32; PROBE_ROW_STACK_CAP],
269    /// Colored Lumen GI red radiance across one probe row.
270    pub(crate) gi_r: [f32; PROBE_ROW_STACK_CAP],
271    /// Colored Lumen GI green radiance across one probe row.
272    pub(crate) gi_g: [f32; PROBE_ROW_STACK_CAP],
273    /// Colored Lumen GI blue radiance across one probe row.
274    pub(crate) gi_b: [f32; PROBE_ROW_STACK_CAP],
275    /// Ambient occlusion factor across one probe row.
276    pub(crate) ao: [f32; PROBE_ROW_STACK_CAP],
277    /// Linear probe depth across one probe row.
278    pub(crate) depth: [f32; PROBE_ROW_STACK_CAP],
279    /// Surface normal X across one probe row.
280    pub(crate) nx: [f32; PROBE_ROW_STACK_CAP],
281    /// Surface normal Y across one probe row.
282    pub(crate) ny: [f32; PROBE_ROW_STACK_CAP],
283    /// Surface normal Z across one probe row.
284    pub(crate) nz: [f32; PROBE_ROW_STACK_CAP],
285    /// Validity flags (`0` sky, `1` geometry) across one probe row.
286    pub(crate) valid: [u8; PROBE_ROW_STACK_CAP],
287}
288
289/// 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.
290#[derive(Clone, Debug)]
291pub(crate) struct RtProbeRowScratch {
292    /// Monotonic frame generation tag invalidating cached rows across frames.
293    pub(crate) frame_gen: u64,
294    /// Probe row index cached in `buf_a` (`usize::MAX` if invalid).
295    pub(crate) cached_gy_a: usize,
296    /// Probe row index cached in `buf_b` (`usize::MAX` if invalid).
297    pub(crate) cached_gy_b: usize,
298    /// First L1-hot denoised probe row buffer.
299    pub(crate) buf_a: RtProbeRowStack,
300    /// Second L1-hot denoised probe row buffer.
301    pub(crate) buf_b: RtProbeRowStack,
302}
303
304/// Zero-copy borrowed view over one contiguous row of SoA RT probes (stack-denoised or wide pre-denoised).
305#[derive(Clone, Copy)]
306pub(crate) struct RtProbeRowView<'a> {
307    /// Sun visibility slice for this row.
308    pub(crate) shadow: &'a [f32],
309    /// Reflection red slice.
310    pub(crate) refl_r: &'a [f32],
311    /// Reflection green slice.
312    pub(crate) refl_g: &'a [f32],
313    /// Reflection blue slice.
314    pub(crate) refl_b: &'a [f32],
315    /// Lumen GI red slice.
316    pub(crate) gi_r: &'a [f32],
317    /// Lumen GI green slice.
318    pub(crate) gi_g: &'a [f32],
319    /// Lumen GI blue slice.
320    pub(crate) gi_b: &'a [f32],
321    /// Ambient occlusion slice.
322    pub(crate) ao: &'a [f32],
323    /// Linear depth slice.
324    pub(crate) depth: &'a [f32],
325    /// Normal X slice.
326    pub(crate) nx: &'a [f32],
327    /// Normal Y slice.
328    pub(crate) ny: &'a [f32],
329    /// Normal Z slice.
330    pub(crate) nz: &'a [f32],
331    /// Validity flags slice.
332    pub(crate) valid: &'a [u8],
333}
334
335/// 16-byte-aligned 2x2 bilinear probe cell packed into 4-lane SIMD arrays and cached across consecutive horizontal pixels sharing `(gx0, gx1, tid)`.
336#[repr(C, align(16))]
337#[derive(Clone, Copy)]
338pub(crate) struct CachedProbeCell {
339    /// Four corner linear depths `[p00, p10, p01, p11]`.
340    pub(crate) depth: [f32; 4],
341    /// Four corner sun visibility factors.
342    pub(crate) shadow: [f32; 4],
343    /// Four corner reflection linear red samples.
344    pub(crate) refl_r: [f32; 4],
345    /// Four corner reflection linear green samples.
346    pub(crate) refl_g: [f32; 4],
347    /// Four corner reflection linear blue samples.
348    pub(crate) refl_b: [f32; 4],
349    /// Four corner GI linear red samples.
350    pub(crate) gi_r: [f32; 4],
351    /// Four corner GI linear green samples.
352    pub(crate) gi_g: [f32; 4],
353    /// Four corner GI linear blue samples.
354    pub(crate) gi_b: [f32; 4],
355    /// Four corner ambient occlusion samples.
356    pub(crate) ao: [f32; 4],
357    /// Four corner bilateral depth tolerance scale (`0.58` high-agreement, `0.20` low-agreement).
358    pub(crate) tol_scale: [f32; 4],
359    /// Four corner bilateral depth tolerance bias (`2.4` high-agreement, `0.75` low-agreement).
360    pub(crate) tol_bias: [f32; 4],
361    /// Four corner SIMD validity bitmasks (`0xFFFF_FFFF` when corner passes normal test, else `0`).
362    pub(crate) valid_u32: [u32; 4],
363    /// Compact 4-bit corner validity mask (`0` triggers immediate edge fallback).
364    pub(crate) vmask: u8,
365}
366
367/// 16-byte-aligned 32-pixel L1-hot Structure-of-Arrays run scratch decoupling probe bilateral upsampling from zero-spill specialized PBR shading kernels.
368#[repr(C, align(16))]
369#[derive(Clone, Copy)]
370pub(crate) struct RunScratch32 {
371    /// Linear camera depth for up to 32 contiguous pixels of one triangle.
372    pub(crate) depths: [f32; 32],
373    /// Interpolated sun shadow factor for up to 32 pixels.
374    pub(crate) shadow: [f32; 32],
375    /// Interpolated reflection linear red for up to 32 pixels.
376    pub(crate) refl_r: [f32; 32],
377    /// Interpolated reflection linear green for up to 32 pixels.
378    pub(crate) refl_g: [f32; 32],
379    /// Interpolated reflection linear blue for up to 32 pixels.
380    pub(crate) refl_b: [f32; 32],
381    /// Interpolated Lumen GI linear red for up to 32 pixels.
382    pub(crate) gi_r: [f32; 32],
383    /// Interpolated Lumen GI linear green for up to 32 pixels.
384    pub(crate) gi_g: [f32; 32],
385    /// Interpolated Lumen GI linear blue for up to 32 pixels.
386    pub(crate) gi_b: [f32; 32],
387    /// Interpolated ambient occlusion for up to 32 pixels.
388    pub(crate) ao: [f32; 32],
389}
390
391/// Writable 4-pixel scanline slice targets and optional quarter-res HDR bloom slot for `shade_span_4x_specialized`.
392pub(crate) struct SpanShadeOut<'a> {
393    /// 16-byte RGBA8 destination span.
394    pub(crate) rgba: &'a mut [u8],
395    /// 4-byte Rec.601 luma destination span.
396    pub(crate) luma: &'a mut [u8],
397    /// Optional `(lane_index, bloom_cell)` HDR excess radiance slot.
398    pub(crate) bloom: Option<(usize, &'a mut [f32; 4])>,
399}
400
401/// Writable full-scanline color, luma, and quarter-res bloom buffers passed to 32-pixel run shaders.
402pub(crate) struct RunRowOut<'a> {
403    /// Full scanline RGBA8 output slice.
404    pub(crate) color: &'a mut [u8],
405    /// Full scanline Rec.601 luma output slice.
406    pub(crate) luma: &'a mut [u8],
407    /// Whether bloom extraction is active on this scanline (`(py & 3) == 0`).
408    pub(crate) write_bloom: bool,
409    /// Starting index of this scanline's bloom row inside `bloom_band`.
410    pub(crate) bloom_off: usize,
411    /// Writable quarter-resolution HDR bloom band slice.
412    pub(crate) bloom_band: &'a mut [[f32; 4]],
413    /// Pre-baked hemi-octahedral atmospheric sky dome LUT for animated ocean reflections.
414    pub(crate) sky_lut: &'a [[f32; 3]],
415    /// Precomputed L1-resident ACES filmic + sRGB gamma LUT (`ACES3D_LUT_SIZE`).
416    pub(crate) aces_lut: &'a [u8],
417}
418
419/// Shared read-only probe rows and horizontal bilinear stepping context for `upsample_run_probes_32` and `shade_tri_run_4x`.
420#[derive(Clone, Copy)]
421pub(crate) struct ProbeBandContext<'a> {
422    /// Top denoised probe row view `gy0`.
423    pub(crate) top_row: &'a RtProbeRowView<'a>,
424    /// Bottom denoised probe row view `gy1`.
425    pub(crate) bottom_row: &'a RtProbeRowView<'a>,
426    /// Vertical bilinear weight for `r0`.
427    pub(crate) wy0: f32,
428    /// Vertical bilinear weight for `r1`.
429    pub(crate) wy1: f32,
430    /// Maximum valid coarse probe column index `gw - 1`.
431    pub(crate) gw_max: usize,
432    /// Doubled integer probe stride `rt_step * 2`.
433    pub(crate) step2_i32: i32,
434    /// Precomputed fractional horizontal lookup table indexed by `sub_x`.
435    pub(crate) fx_lut: &'a [f32; 16],
436}
437
438/// Raw writable base addresses for lock-free disjoint-tile writes into `RtProbeGridSoa`.
439#[derive(Clone, Copy, Debug)]
440pub(crate) struct RtProbeGridMutPtrs {
441    /// Base pointer for `shadow`.
442    pub(crate) shadow: usize,
443    /// Base pointer for `refl_r`.
444    pub(crate) refl_r: usize,
445    /// Base pointer for `refl_g`.
446    pub(crate) refl_g: usize,
447    /// Base pointer for `refl_b`.
448    pub(crate) refl_b: usize,
449    /// Base pointer for `gi_r`.
450    pub(crate) gi_r: usize,
451    /// Base pointer for `gi_g`.
452    pub(crate) gi_g: usize,
453    /// Base pointer for `gi_b`.
454    pub(crate) gi_b: usize,
455    /// Base pointer for `ao`.
456    pub(crate) ao: usize,
457    /// Base pointer for `depth`.
458    pub(crate) depth: usize,
459    /// Base pointer for `nx`.
460    pub(crate) nx: usize,
461    /// Base pointer for `ny`.
462    pub(crate) ny: usize,
463    /// Base pointer for `nz`.
464    pub(crate) nz: usize,
465    /// Base pointer for `world_x`.
466    pub(crate) world_x: usize,
467    /// Base pointer for `world_y`.
468    pub(crate) world_y: usize,
469    /// Base pointer for `world_z`.
470    pub(crate) world_z: usize,
471    /// Base pointer for `valid`.
472    pub(crate) valid: usize,
473}
474
475/// Shared read-only inputs for fused Barrier 1 tiled rasterization and L1-hot coherent 2x2 probe packet tracing.
476pub(crate) struct TileRasterProbeInputs<'a> {
477    /// Screen-space triangle setup records.
478    pub(crate) raster_tris: &'a [RasterTri2D],
479    /// Flat CSR prefix offsets per tile (`len == total_tiles + 1`).
480    pub(crate) tile_offsets: &'a [u32],
481    /// Binned triangle indices into `raster_tris`.
482    pub(crate) tile_tri_indices: &'a [u32],
483    /// Precomputed GGX triangle shading records.
484    pub(crate) shaded_tris: &'a [GShadeTri],
485    /// Static world BVH4/BVH8 acceleration structure.
486    pub(crate) static_bvh: &'a Bvh3D,
487    /// Active object-space dynamic raytracing instances.
488    pub(crate) dyn_instances: &'a [DynamicRayInstance],
489    /// Local-space BVH4/BVH8 cache indexed by `mesh_id`.
490    pub(crate) local_bvhs: &'a [Option<Bvh3D>],
491    /// Previous frame coarse RT probe grid for world-space-validated temporal checkerboard reuse.
492    pub(crate) prev_probes: Option<&'a RtProbeGridSoa>,
493    /// Previous frame view-projection matrix for analytical motion-vector probe reprojection.
494    pub(crate) prev_view_proj: Mat4,
495    /// Previous frame internal framebuffer `(width, height)` for motion-vector reprojection.
496    pub(crate) prev_render_dims: (usize, usize),
497    /// Previous frame coarse RT probe stride.
498    pub(crate) prev_rt_step: usize,
499    /// Previous frame coarse RT probe grid width.
500    pub(crate) prev_gw: usize,
501    /// Previous frame coarse RT probe grid height.
502    pub(crate) prev_gh: usize,
503    /// Optional read-only world-space Lumen Radiance Cache for O(1) multi-bounce indirect GI lookups.
504    pub(crate) lumen_cache: Option<&'a LumenRadianceCache>,
505    /// Optional read-only Clustered Deferred local light grid evaluated per coarse probe.
506    pub(crate) light_clusters: Option<&'a LightClusterGrid3D>,
507    /// Optional read-only Virtual Shadow Map for zero-BVH-ray distant shadow sampling.
508    pub(crate) vsm: Option<&'a VirtualShadowMap>,
509    /// Enables O(1) VSM lookup for distant probes (`depth > 42m`) instead of long-range BVH shadow rays.
510    pub(crate) use_vsm_far_shadows: bool,
511    /// Alternating checkerboard parity (`0` or `1`) selecting which 2x2 probe blocks refresh vs reuse.
512    pub(crate) probe_checker_parity: usize,
513    /// Whether the camera projection, dimensions, and RT probe stride match the previous frame identically.
514    pub(crate) same_camera_pose: bool,
515    /// Tile edge dimension in pixels (`<= 64`, multiple of `rt_step` when RT active).
516    pub(crate) tile_px: usize,
517    /// Number of tiles horizontally.
518    pub(crate) tiles_x: usize,
519    /// Pre-baked hemi-octahedral atmospheric sky dome LUT for clouded/starry reflection hits.
520    pub(crate) sky_lut: &'a [[f32; 3]],
521}
522
523/// Shared read-only inputs for fused Barrier 2 streaming bilateral denoise and vectorized deferred PBR shading.
524pub(crate) struct ShadeBandInputs<'a> {
525    /// Reverse-Z `1/w` depth buffer.
526    pub(crate) depth_buf: &'a [f32],
527    /// Deferred G-Buffer triangle IDs.
528    pub(crate) g_tri_idx: &'a [u32],
529    /// Precomputed GGX triangle shading records.
530    pub(crate) shaded_tris: &'a [GShadeTri],
531    /// Perspective-correct smooth vertex attribute records indexed by `GShadeTri::smooth_idx`.
532    pub(crate) smooth_tris: &'a [GSmoothTri],
533    /// Blender Principled BSDF materials from `World3D`.
534    pub(crate) principled_materials: &'a [PrincipledMaterial3D],
535    /// Mipmapped 2D texture pool from `World3D`.
536    pub(crate) textures: &'a [Texture2D3D],
537    /// Active Blender rectangular and disk area lights.
538    pub(crate) area_lights: &'a [AreaLight3D],
539    /// Optional 3D clustered point/spot light grid for per-pixel Principled shading.
540    pub(crate) light_clusters: Option<&'a LightClusterGrid3D>,
541    /// Optional 4-cascade CSM shadow map for direct per-pixel Vogel-disk PCF visibility.
542    pub(crate) vsm: Option<&'a VirtualShadowMap>,
543    /// Optional precomputed SH9 + octahedral specular + BRDF LUT environment IBL.
544    pub(crate) environment_ibl: Option<&'a EnvironmentIbl3D>,
545    /// Whether Blender AgX (`true`) or ACES Filmic (`false`) tonemapping is active.
546    pub(crate) use_agx_tonemap: bool,
547    /// Raw coarse RT probe SoA grid written by Barrier 1.
548    pub(crate) raw_probes: &'a RtProbeGridSoa,
549    /// Optional pre-denoised full probe grid used only when `gw > 256` (e.g. 4K viewports).
550    pub(crate) wide_denoised_probes: &'a RtProbeGridSoa,
551    /// Whether bilateral 3x3 probe denoising is active during row streaming (`gw <= 256`).
552    pub(crate) denoise_probes: bool,
553    /// Whether GI/AO channels require 3x3 bilateral denoising (`true` for `FullPathTracedGi`, `false` for analytic clustered local lights).
554    pub(crate) denoise_gi_channels: bool,
555    /// Static world BVH4/BVH8 acceleration structure.
556    pub(crate) static_bvh: &'a Bvh3D,
557    /// Active object-space dynamic raytracing instances.
558    pub(crate) dyn_instances: &'a [DynamicRayInstance],
559    /// Local-space BVH4/BVH8 cache indexed by `mesh_id`.
560    pub(crate) local_bvhs: &'a [Option<Bvh3D>],
561    /// Atomic bitset marking quarter-resolution bloom rows that received non-zero HDR radiance (`576` bits -> `bh <= 576`).
562    pub(crate) bloom_row_bits: &'a [AtomicU64; 9],
563    /// Pre-baked hemi-octahedral atmospheric sky dome LUT for primary sky and edge reflection hits.
564    pub(crate) sky_lut: &'a [[f32; 3]],
565    /// Precomputed L1-resident ACES filmic + sRGB gamma LUT (`ACES3D_LUT_SIZE`).
566    pub(crate) aces_lut: &'a [u8],
567}
568
569/// Shared read-only inputs for Barrier 3 vectorized FXAA/MLAA/TAA and bilinear HDR bloom compositing.
570pub(crate) struct PostProcessInputs<'a> {
571    /// Tone-mapped RGBA8 intermediate framebuffer.
572    pub(crate) color_src: &'a [u8],
573    /// Rec.601 luma buffer populated during deferred shading.
574    pub(crate) luma: &'a [u8],
575    /// Deferred G-Buffer triangle IDs for geometry-aware AA edge detection.
576    pub(crate) g_tri_idx: &'a [u32],
577    /// Blurred quarter-resolution HDR bloom buffer (`[r, g, b, 0]`).
578    pub(crate) bloom: &'a [[f32; 4]],
579    /// Active bloom tile mask (`1` where bloom contributes `>= 1` RGB LSB).
580    pub(crate) bloom_tile_active: &'a [u8],
581    /// Previous frame RGBA8 TAA temporal history buffer.
582    pub(crate) taa_history: &'a [u8],
583}
584
585/// Immutable per-frame camera, lighting, volumetric, and ray-tracing configuration shared across worker threads.
586#[derive(Clone, Copy, Debug)]
587pub(crate) struct DeferredFrameContext {
588    /// Framebuffer width in pixels.
589    pub(crate) width: usize,
590    /// Framebuffer height in pixels.
591    pub(crate) height: usize,
592    /// Coarse RT grid width in probes.
593    pub(crate) grid_width: usize,
594    /// Coarse RT grid height in probes.
595    pub(crate) grid_height: usize,
596    /// Quarter-res HDR bloom width.
597    pub(crate) bloom_width: usize,
598    /// Pixel stride per coarse RT probe.
599    pub(crate) raytrace_step: usize,
600    /// Reciprocal framebuffer width.
601    pub(crate) inv_width: f32,
602    /// Reciprocal framebuffer height.
603    pub(crate) inv_height: f32,
604    /// Camera world position.
605    pub(crate) camera_position: Vec3,
606    /// Camera unit forward basis.
607    pub(crate) camera_forward: Vec3,
608    /// Camera right basis scaled by `half_w`.
609    pub(crate) camera_right_scaled: Vec3,
610    /// Camera up basis scaled by `half_h`.
611    pub(crate) camera_up_scaled: Vec3,
612    /// Active directional sun & sky parameters.
613    pub(crate) sun: DirectionalLight3D,
614    /// Precomputed safe reciprocal sun direction for fast shadow BVH traversal.
615    pub(crate) inv_sun_dir: Vec3,
616    /// Precomputed 16-tap Vogel-disk blue-noise soft-shadow `(dir, inv_dir)` ray table hoisted once per frame.
617    pub(crate) soft_shadow_rays: [(Vec3, Vec3); 16],
618    /// Monotonic frame index driving deterministic blue-noise temporal rotation across TSR/TAA frames.
619    pub(crate) frame_index: usize,
620    /// Active ray-tracing quality tier.
621    pub(crate) raytrace_mode: RayTracingMode,
622    /// Maximum reflection/GI bounce depth (`0..=3`).
623    pub(crate) reflection_bounces: u8,
624    /// Whether volumetric height/distance fog and crepuscular sun-shafts are enabled.
625    pub(crate) fog_on: bool,
626    /// Precomputed inverse fog attenuation distance.
627    pub(crate) inv_fog_distance: f32,
628    /// Exposure scale derived from physically based camera EV100.
629    pub(crate) exposure_scale: f32,
630    /// Whether quarter-res emissive/specular bloom extraction is active.
631    pub(crate) bloom_on: bool,
632    /// Whether dynamic local point/spot lights are active in `LightClusterGrid3D` and injected into the GI probe channels.
633    pub(crate) has_clustered_lights: bool,
634    /// Monotonic frame generation tag for per-thread probe denoise scratch cache invalidation.
635    pub(crate) probe_frame_generation: u64,
636    /// Monotonic world simulation time in seconds driving animated 3D ocean waves, caustics, and shoreline foam.
637    pub(crate) world_time_secs: f32,
638}
639
640/// Per-chunk reusable scratch buffers eliminating heap allocations in the 8-way parallel geometry front-end.
641#[derive(Clone, Debug, Default)]
642pub(crate) struct GeomChunkScratch {
643    /// Per-chunk precomputed GGX shading triangle records.
644    pub(crate) shaded_tris: Vec<GShadeTri>,
645    /// Per-chunk perspective-correct smooth vertex attribute records.
646    pub(crate) smooth_tris: Vec<GSmoothTri>,
647    /// Per-chunk precomputed screen-space rasterization setup records.
648    pub(crate) raster_tris: Vec<RasterTri2D>,
649    /// Per-chunk transformed vertex scratch `(clip_pos, world_pos)`.
650    pub(crate) projected_verts: Vec<([f32; 4], Vec3)>,
651    /// Per-chunk visible meshlet triangle ranges.
652    pub(crate) cluster_ranges: Vec<(usize, usize)>,
653    /// Per-chunk visible object count.
654    pub(crate) visible_objects: usize,
655    /// Per-chunk Hi-Z occluded object count.
656    pub(crate) hiz_culled_objects: usize,
657    /// Per-chunk simplified LOD object count.
658    pub(crate) lod_simplified_objects: usize,
659    /// Per-chunk drawn meshlet count.
660    pub(crate) meshlets_drawn: usize,
661    /// Per-chunk culled meshlet count.
662    pub(crate) meshlets_culled: usize,
663    /// Per-chunk unique mesh IDs for instanced batch telemetry.
664    pub(crate) mesh_ids: Vec<usize>,
665}
666
667/// Shared read-only scene, frustum, Hi-Z, Nanite DAG, and lighting state passed to per-object geometry front-end projection.
668pub(crate) struct GeomPassContext<'a> {
669    /// All scene objects in the world.
670    pub(crate) objects: &'a [SceneObject3D],
671    /// Mesh LOD chain library indexed by `mesh_id`.
672    pub(crate) mesh_lib: &'a [MeshLodChain],
673    /// Optional per-object live deformed meshes (morphed/skinned).
674    pub(crate) deformed_meshes: &'a [Option<Mesh3D>],
675    /// Blender Principled BSDF materials from `World3D`.
676    pub(crate) principled_materials: &'a [PrincipledMaterial3D],
677    /// Cached `NaniteClusterDag` hierarchy per `mesh_id` for screen-error cluster LOD cuts.
678    pub(crate) nanite_dags: &'a [Option<NaniteClusterDag>],
679    /// Conservative Hi-Z depth pyramid for occlusion queries.
680    pub(crate) hiz_pyramid: &'a HiZPyramid,
681    /// Flags marking near pre-pass occluders (`1` = stamped occluder).
682    pub(crate) hiz_occluder_flags: &'a [u8],
683    /// Active view frustum planes.
684    pub(crate) frustum: Frustum3D,
685    /// Current frame view-projection matrix.
686    pub(crate) view_proj: Mat4,
687    /// Camera world-space position.
688    pub(crate) cam_pos: Vec3,
689    /// Normalized directional sun vector.
690    pub(crate) sun_dir: Vec3,
691    /// Linear HDR horizon sky color.
692    pub(crate) sky_horizon: Vec3,
693    /// Linear HDR zenith sky color.
694    pub(crate) sky_zenith: Vec3,
695    /// Vertical projection focal length in pixels.
696    pub(crate) focal_px: f32,
697    /// LOD distance bias multiplier.
698    pub(crate) lod_bias: f32,
699    /// Clamped near clip plane distance.
700    pub(crate) near_plane: f32,
701    /// Render viewport width in pixels as `f32`.
702    pub(crate) w_f: f32,
703    /// Render viewport height in pixels as `f32`.
704    pub(crate) h_f: f32,
705    /// Maximum valid pixel X coordinate (`width - 1`).
706    pub(crate) w_max_i: i32,
707    /// Maximum valid pixel Y coordinate (`height - 1`).
708    pub(crate) h_max_i: i32,
709    /// Subpixel temporal jitter X in pixels.
710    pub(crate) jitter_x: f32,
711    /// Subpixel temporal jitter Y in pixels.
712    pub(crate) jitter_y: f32,
713    /// Whether frustum and meshlet culling are active.
714    pub(crate) frustum_on: bool,
715    /// Whether Hi-Z occlusion culling is active.
716    pub(crate) hiz_active: bool,
717    /// Whether ray-traced reflections are enabled.
718    pub(crate) use_rt_refl: bool,
719    /// Whether Blender AgX tonemapping is active (forces smooth shading path for Principled parity).
720    pub(crate) use_agx_tonemap: bool,
721}
722
723/// Writable per-pass or per-chunk geometry buffers and counters updated by `process_visible_object_geom`.
724pub(crate) struct GeomPassOut<'a> {
725    /// Destination precomputed GGX triangle shading list.
726    pub(crate) shaded_tris: &'a mut Vec<GShadeTri>,
727    /// Destination perspective-correct smooth vertex attribute list.
728    pub(crate) smooth_tris: &'a mut Vec<GSmoothTri>,
729    /// Destination 2D screen-space raster setup list.
730    pub(crate) raster_tris: &'a mut Vec<RasterTri2D>,
731    /// Reusable per-object transformed vertex buffer.
732    pub(crate) projected_verts: &'a mut Vec<([f32; 4], Vec3)>,
733    /// Reusable per-object visible meshlet triangle ranges.
734    pub(crate) cluster_ranges: &'a mut Vec<(usize, usize)>,
735    /// Optional mesh ID accumulator for parallel chunks (`None` when writing directly to `unique_meshes`).
736    pub(crate) mesh_ids: Option<&'a mut Vec<usize>>,
737    /// Optional direct unique mesh set for sequential processing.
738    pub(crate) unique_meshes: Option<&'a mut HashSet<usize>>,
739    /// Visible object count accumulator.
740    pub(crate) visible_objects: usize,
741    /// Hi-Z occluded object count accumulator.
742    pub(crate) hiz_culled_objects: usize,
743    /// Simplified LOD object count accumulator.
744    pub(crate) lod_simplified_objects: usize,
745    /// Drawn meshlet count accumulator.
746    pub(crate) meshlets_drawn: usize,
747    /// Culled meshlet count accumulator.
748    pub(crate) meshlets_culled: usize,
749}
750
751/// Zero-allocation UE5-class Deferred GGX PBR + Persistent Multi-Core SIMD BVH4/BVH8 + Nanite Hi-Z + Lumen GI + VSM + Clustered Lighting + TSR 3D renderer.
752#[derive(Clone, Data, Debug)]
753pub struct Renderer3D {
754    /// Pre-allocated RGBA8 tone-mapped intermediate pixel buffer.
755    pub(crate) color_buffer: Vec<u8>,
756    /// Pre-allocated RGBA8 temporal history buffer for variance-clamped TAA.
757    pub(crate) aa_buffer: Vec<u8>,
758    /// Pre-allocated floating-point linear `1/w` reverse-Z depth buffer (`0.0` = sky).
759    pub(crate) depth_buffer: Vec<f32>,
760    /// Deferred G-Buffer triangle index per pixel (`u32::MAX` = sky).
761    #[get(skip)]
762    #[get_mut(skip)]
763    #[set(skip)]
764    pub(crate) g_tri_idx: Vec<u32>,
765    /// Single-byte per-pixel Rec.601 luma buffer populated during deferred shading for fast morphological AA.
766    #[get(skip)]
767    #[get_mut(skip)]
768    #[set(skip)]
769    pub(crate) luma_buffer: Vec<u8>,
770    /// Per-frame precomputed GGX triangle shading records.
771    #[get(skip)]
772    #[get_mut(skip)]
773    #[set(skip)]
774    pub(crate) shaded_tris: Vec<GShadeTri>,
775    /// Per-frame perspective-correct smooth vertex attribute records for Principled BSDF parity.
776    #[get(skip)]
777    #[get_mut(skip)]
778    #[set(skip)]
779    pub(crate) smooth_tris: Vec<GSmoothTri>,
780    /// Lazily populated `NaniteClusterDag` hierarchy cache indexed by `World3D::mesh_library` ID.
781    #[get(skip)]
782    #[get_mut(skip)]
783    #[set(skip)]
784    pub(crate) nanite_dags_cache: Vec<Option<NaniteClusterDag>>,
785    /// Cached compiled render-graph schedule executed actively during frame rendering.
786    #[get(skip)]
787    #[get_mut(skip)]
788    #[set(skip)]
789    pub(crate) cached_rdg_schedule: RenderGraphSchedule3D,
790    /// Viewport and quality key validating `cached_rdg_schedule` without per-frame recompilation.
791    #[get(skip)]
792    #[get_mut(skip)]
793    #[set(skip)]
794    pub(crate) cached_rdg_key: u64,
795    /// Number of active `RenderGraph3D` passes executed during the most recent frame.
796    #[get(type(copy))]
797    pub(crate) last_executed_rdg_passes: usize,
798    /// Persistent reusable RGBA8 final output buffer eliminating per-frame allocations in `render_world_rgba`.
799    #[get(skip)]
800    #[get_mut(skip)]
801    #[set(skip)]
802    pub(crate) rgba_scratch: Vec<u8>,
803    /// Structure-of-Arrays coarse coherent ray-tracing probe grid.
804    #[get(skip)]
805    #[get_mut(skip)]
806    #[set(skip)]
807    pub(crate) rt_probes: RtProbeGridSoa,
808    /// Previous frame coarse RT probe grid swapped in O(1) for temporal checkerboard probe reuse.
809    #[get(skip)]
810    #[get_mut(skip)]
811    #[set(skip)]
812    pub(crate) prev_rt_probes: RtProbeGridSoa,
813    /// Whether `prev_rt_probes` holds valid history matching `(prev_probe_gw, prev_probe_gh, prev_probe_rt_mode)`.
814    #[get(skip)]
815    #[get_mut(skip)]
816    #[set(skip)]
817    pub(crate) has_probe_history: bool,
818    /// Coarse probe width stored in `prev_rt_probes`.
819    #[get(skip)]
820    #[get_mut(skip)]
821    #[set(skip)]
822    pub(crate) prev_probe_gw: usize,
823    /// Coarse probe height stored in `prev_rt_probes`.
824    #[get(skip)]
825    #[get_mut(skip)]
826    #[set(skip)]
827    pub(crate) prev_probe_gh: usize,
828    /// Ray-tracing mode stored in `prev_rt_probes`.
829    #[get(skip)]
830    #[get_mut(skip)]
831    #[set(skip)]
832    pub(crate) prev_probe_rt_mode: RayTracingMode,
833    /// Previous frame directional sun vector for invalidating temporal probes on lighting changes.
834    #[get(skip)]
835    #[get_mut(skip)]
836    #[set(skip)]
837    pub(crate) prev_sun_dir: Vec3,
838    /// Fallback full-grid denoised SoA probe buffer used only when `gw > 256` (4K+).
839    #[get(skip)]
840    #[get_mut(skip)]
841    #[set(skip)]
842    pub(crate) rt_probes_wide_denoised: RtProbeGridSoa,
843    /// Quarter-res 16-byte-aligned HDR bloom extraction and vertical blur buffer.
844    #[get(skip)]
845    #[get_mut(skip)]
846    #[set(skip)]
847    pub(crate) bloom_a: Vec<[f32; 4]>,
848    /// Quarter-res 16-byte-aligned HDR bloom horizontal blur scratch buffer.
849    #[get(skip)]
850    #[get_mut(skip)]
851    #[set(skip)]
852    pub(crate) bloom_b: Vec<[f32; 4]>,
853    /// Quarter-res active-bloom tile mask (`1` when any bilinear corner contributes `>= 1` RGB LSB) skipping dark tiles in post-processing.
854    #[get(skip)]
855    #[get_mut(skip)]
856    #[set(skip)]
857    pub(crate) bloom_tile_active: Vec<u8>,
858    /// Reusable front-to-back object sorting scratch buffer.
859    #[get(skip)]
860    #[get_mut(skip)]
861    #[set(skip)]
862    pub(crate) visible_scratch: Vec<(f32, usize)>,
863    /// Reusable meshlet triangle-range scratch buffer eliminating per-object heap allocations.
864    #[get(skip)]
865    #[get_mut(skip)]
866    #[set(skip)]
867    pub(crate) cluster_ranges_scratch: Vec<(usize, usize)>,
868    /// Reusable per-object transformed vertex cache `(clip_pos, world_pos)` avoiding redundant vertex transforms.
869    #[get(skip)]
870    #[get_mut(skip)]
871    #[set(skip)]
872    pub(crate) projected_verts_scratch: Vec<([f32; 4], Vec3)>,
873    /// Reusable unique mesh-id set for instancing telemetry.
874    #[get(skip)]
875    #[get_mut(skip)]
876    #[set(skip)]
877    pub(crate) unique_meshes_scratch: HashSet<usize>,
878    /// Reusable saved dynamic-object transforms for zero-allocation interpolated rendering.
879    #[get(skip)]
880    #[get_mut(skip)]
881    #[set(skip)]
882    pub(crate) saved_objs_scratch: Vec<(usize, Transform3D, AxisAlignedBox3D)>,
883    /// Reusable screen-space triangle setup list for parallel tiled rasterization.
884    #[get(skip)]
885    #[get_mut(skip)]
886    #[set(skip)]
887    pub(crate) raster_tris_scratch: Vec<RasterTri2D>,
888    /// Reusable per-tile triangle count array for flat CSR binning.
889    #[get(skip)]
890    #[get_mut(skip)]
891    #[set(skip)]
892    pub(crate) tile_counts_scratch: Vec<u32>,
893    /// Reusable flat CSR prefix-sum offset array (`total_tiles + 1`).
894    #[get(skip)]
895    #[get_mut(skip)]
896    #[set(skip)]
897    pub(crate) tile_offsets_scratch: Vec<u32>,
898    /// Reusable per-tile insertion cursor array for flat CSR binning.
899    #[get(skip)]
900    #[get_mut(skip)]
901    #[set(skip)]
902    pub(crate) tile_cursors_scratch: Vec<u32>,
903    /// Reusable flat array of binned triangle indices across all screen tiles.
904    #[get(skip)]
905    #[get_mut(skip)]
906    #[set(skip)]
907    pub(crate) tile_tri_indices_scratch: Vec<u32>,
908    /// Optional shared-device GPU composite target for zero-readback single-pass UI+3D compositing.
909    #[get(skip)]
910    #[get_mut(skip)]
911    #[set(skip)]
912    pub(crate) gpu_target: GpuCompositeTarget,
913    /// Whether `aa_buffer` holds a valid previous frame compatible with temporal anti-aliasing.
914    #[get(skip)]
915    #[get_mut(skip)]
916    #[set(skip)]
917    pub(crate) has_taa_history: bool,
918    /// Previous frame view-projection fingerprint used to detect camera cuts for TAA.
919    #[get(skip)]
920    #[get_mut(skip)]
921    #[set(skip)]
922    pub(crate) prev_vp_m0: f32,
923    /// Full previous frame view-projection matrix driving analytical motion-vector probe reprojection and TSR.
924    #[get(skip)]
925    #[get_mut(skip)]
926    #[set(skip)]
927    pub(crate) prev_view_proj: Mat4,
928    /// Whether `prev_view_proj` contains a valid previous frame transform.
929    #[get(skip)]
930    #[get_mut(skip)]
931    #[set(skip)]
932    pub(crate) has_prev_vp: bool,
933    /// Previous frame internal render dimensions `(width, height)`.
934    #[get(skip)]
935    #[get_mut(skip)]
936    #[set(skip)]
937    pub(crate) prev_render_dims: (usize, usize),
938    /// Previous frame coarse RT probe stride.
939    #[get(skip)]
940    #[get_mut(skip)]
941    #[set(skip)]
942    pub(crate) prev_rt_step: usize,
943    /// Conservative reverse-Z hierarchical depth pyramid for Nanite-style occlusion culling.
944    #[get(skip)]
945    #[get_mut(skip)]
946    #[set(skip)]
947    pub(crate) hiz_pyramid: HiZPyramid,
948    /// Reusable occluder pre-pass flags marking stamped near occluders (`len == visible_scratch.len()`).
949    #[get(skip)]
950    #[get_mut(skip)]
951    #[set(skip)]
952    pub(crate) hiz_occluder_flags_scratch: Vec<u8>,
953    /// Persistent 2-cascade world-space Lumen Radiance Cache enabling O(1) multi-bounce indirect GI.
954    #[get(skip)]
955    #[get_mut(skip)]
956    #[set(skip)]
957    pub(crate) lumen_cache: LumenRadianceCache,
958    /// Pre-allocated 16x9x16 logarithmic-Z froxel grid for UE5 Clustered Deferred local lighting.
959    #[get(skip)]
960    #[get_mut(skip)]
961    #[set(skip)]
962    pub(crate) light_clusters: LightClusterGrid3D,
963    /// Two-cascade texel-snapped Virtual Shadow Map with static page caching and 4-tap PCF.
964    #[get(skip)]
965    #[get_mut(skip)]
966    #[set(skip)]
967    pub(crate) virtual_shadow_map: VirtualShadowMap,
968    /// UE5 Temporal Super Resolution upscaler reconstructing sub-native frames with motion vectors and RCAS.
969    #[get(skip)]
970    #[get_mut(skip)]
971    #[set(skip)]
972    pub(crate) tsr_upscaler: TsrUpscaler,
973    /// Reusable intermediate RGBA8 scratch buffer for sub-native TSR upscaling and bloom-to-TSR handoff.
974    #[get(skip)]
975    #[get_mut(skip)]
976    #[set(skip)]
977    pub(crate) tsr_internal_scratch: Vec<u8>,
978    /// Damped PI frame-pacing governor preventing FPS oscillation across variable GPU/CPU workloads.
979    pub(crate) frame_governor: AdaptiveFrameGovernor,
980    /// Compile-once UE5 Render Dependency Graph describing frame pass order and transient memory aliasing.
981    pub(crate) render_graph: RenderGraph3D,
982    /// Optional additive RT probe stride bias (`0..=2`) modulated by `AdaptiveFrameGovernor` under heavy load.
983    #[get(type(copy))]
984    pub(crate) rt_stride_bias: usize,
985    /// Persistent reusable per-chunk buffers for deterministic 8-way parallel geometry front-end processing in dense worlds.
986    #[get(skip)]
987    #[get_mut(skip)]
988    #[set(skip)]
989    pub(crate) geom_chunks_scratch: Vec<GeomChunkScratch>,
990    /// Smoothly adapted UE5-style eye-adaptation exposure multiplier (`1.0` on frame 0).
991    #[get(type(copy))]
992    pub(crate) adapted_exposure: f32,
993    /// Monotonic frame counter driving Halton(2, 3) temporal subpixel jitter.
994    #[get(skip)]
995    #[get_mut(skip)]
996    #[set(skip)]
997    pub(crate) frame_index: u32,
998    /// Last rendered `World3D::world_revision` enabling HUD-only dirty frames to reuse the cached 3D frame.
999    #[get(type(copy))]
1000    pub(crate) last_world_revision: u64,
1001    /// Quality and viewport configuration fingerprint paired with `last_world_revision`.
1002    #[get(skip)]
1003    #[get_mut(skip)]
1004    #[set(skip)]
1005    pub(crate) last_quality_fingerprint: u64,
1006    /// Number of consecutive static-world TAA accumulation frames completed since the last world change.
1007    #[get(type(copy))]
1008    pub(crate) taa_accumulated_frames: u32,
1009    /// Total HUD-only dirty frames satisfied from the cached 3D framebuffer without re-rasterizing.
1010    #[get(type(copy))]
1011    pub(crate) cached_world_reuses: u64,
1012    /// Last rendered internal width.
1013    #[get(type(copy))]
1014    pub(crate) width: u32,
1015    /// Last rendered internal height.
1016    #[get(type(copy))]
1017    pub(crate) height: u32,
1018    /// Telemetry from the most recent frame.
1019    #[get(type(copy))]
1020    pub(crate) last_stats: RenderStats3D,
1021    /// Pre-baked hemi-octahedral 3D atmospheric sky+cloud+star radiance LUT (`SKY3D_LUT_W * SKY3D_LUT_H`).
1022    #[get(skip)]
1023    #[get_mut(skip)]
1024    #[set(skip)]
1025    pub(crate) sky_lut: Vec<[f32; 3]>,
1026    /// Fingerprint of the `DirectionalLight3D` baked into `sky_lut` (`0` = uninitialized).
1027    #[get(skip)]
1028    #[get_mut(skip)]
1029    #[set(skip)]
1030    pub(crate) sky_lut_key: u64,
1031    /// Precomputed L1-resident ACES filmic + sRGB gamma LUT (`ACES3D_LUT_SIZE`).
1032    #[get(skip)]
1033    #[get_mut(skip)]
1034    #[set(skip)]
1035    pub(crate) aces_lut: Vec<u8>,
1036    /// High-water scene object count for which steady-state scratch buffers are pre-reserved.
1037    #[get(skip)]
1038    #[get_mut(skip)]
1039    #[set(skip)]
1040    pub(crate) reserved_object_cap: usize,
1041    /// High-water mesh library count for which steady-state scratch buffers are pre-reserved.
1042    #[get(skip)]
1043    #[get_mut(skip)]
1044    #[set(skip)]
1045    pub(crate) reserved_mesh_cap: usize,
1046}