use super::*;
#[cfg(not(target_arch = "wasm32"))]
#[repr(align(128))]
#[derive(Debug, Default)]
pub(crate) struct Engine3dWorkerSlot {
pub(crate) epoch: AtomicUsize,
pub(crate) parked: AtomicUsize,
pub(crate) lock: Mutex<()>,
pub(crate) wake: Condvar,
}
#[cfg(not(target_arch = "wasm32"))]
#[repr(align(128))]
#[derive(Debug)]
pub(crate) struct Engine3dPoolShared {
pub(crate) active_job: AtomicUsize,
pub(crate) active_workers: AtomicUsize,
pub(crate) caller_parked: AlignedAtomicUsize,
pub(crate) caller_lock: Mutex<()>,
pub(crate) wake_caller: Condvar,
pub(crate) slots: Vec<Engine3dWorkerSlot>,
}
#[cfg(not(target_arch = "wasm32"))]
#[repr(align(128))]
#[derive(Debug)]
pub(crate) struct Engine3dJob {
pub(crate) trampoline: fn(usize, usize, usize),
pub(crate) ctx_ptr: usize,
pub(crate) total_items: usize,
pub(crate) chunk_size: usize,
pub(crate) total_chunks: usize,
pub(crate) next_chunk: AlignedAtomicUsize,
pub(crate) workers_done: AlignedAtomicUsize,
}
#[cfg(not(target_arch = "wasm32"))]
#[derive(Debug)]
pub(crate) struct Engine3dWorkerPool {
pub(crate) worker_count: usize,
pub(crate) dispatch_lock: Mutex<()>,
pub(crate) shared: Arc<Engine3dPoolShared>,
}
#[derive(Clone, Copy, Data, Debug, Default, PartialEq)]
pub struct RenderStats3D {
#[get(type(copy))]
pub(crate) render_width: u32,
#[get(type(copy))]
pub(crate) render_height: u32,
#[get(type(copy))]
pub(crate) visible_objects: usize,
#[get(type(copy))]
pub(crate) culled_objects: usize,
#[get(type(copy))]
pub(crate) instanced_batches: usize,
#[get(type(copy))]
pub(crate) triangles_drawn: usize,
#[get(type(copy))]
pub(crate) rays_traced: usize,
#[get(type(copy))]
pub(crate) bvh_nodes: usize,
#[get(type(copy))]
pub(crate) lod_simplified_objects: usize,
#[get(type(copy))]
pub(crate) meshlets_drawn: usize,
#[get(type(copy))]
pub(crate) meshlets_culled: usize,
#[get(type(copy))]
pub(crate) hiz_culled_objects: usize,
#[get(type(copy))]
pub(crate) lumen_cache_cells: usize,
#[get(type(copy))]
pub(crate) active_local_lights: usize,
#[get(type(copy))]
pub(crate) particles_drawn: usize,
#[get(type(copy))]
pub(crate) probe_reproj_hits: usize,
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct RasterTri2D {
pub(crate) min_y: i32,
pub(crate) max_y: i32,
pub(crate) min_x: i32,
pub(crate) span_max: i32,
pub(crate) tri_id: u32,
pub(crate) slopes: [f32; 3],
pub(crate) neg_inv_slopes: [f32; 3],
pub(crate) dw_dy: [f32; 3],
pub(crate) w_start: [f32; 3],
pub(crate) inv_w_start: f32,
pub(crate) d_inv_w_dx: f32,
pub(crate) d_inv_w_dy: f32,
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct GShadeTri {
pub(crate) shade_n: Vec3,
pub(crate) mat_base: Vec3,
pub(crate) mat_emissive: Vec3,
pub(crate) ambient_sky: Vec3,
pub(crate) f0: Vec3,
pub(crate) n_dot_l: f32,
pub(crate) alpha2: f32,
pub(crate) diffuse_scale: f32,
pub(crate) mat_refl: f32,
pub(crate) metallic: f32,
pub(crate) do_refl: bool,
pub(crate) surface_detail: SurfaceDetailMode,
}
#[derive(Clone, Debug, Default)]
pub(crate) struct RtProbeGridSoa {
pub(crate) shadow: Vec<f32>,
pub(crate) refl_r: Vec<f32>,
pub(crate) refl_g: Vec<f32>,
pub(crate) refl_b: Vec<f32>,
pub(crate) gi_r: Vec<f32>,
pub(crate) gi_g: Vec<f32>,
pub(crate) gi_b: Vec<f32>,
pub(crate) ao: Vec<f32>,
pub(crate) depth: Vec<f32>,
pub(crate) nx: Vec<f32>,
pub(crate) ny: Vec<f32>,
pub(crate) nz: Vec<f32>,
pub(crate) world_x: Vec<f32>,
pub(crate) world_y: Vec<f32>,
pub(crate) world_z: Vec<f32>,
pub(crate) valid: Vec<u8>,
}
#[derive(Clone, Debug)]
pub(crate) struct RtProbeRowStack {
pub(crate) shadow: [f32; PROBE_ROW_STACK_CAP],
pub(crate) refl_r: [f32; PROBE_ROW_STACK_CAP],
pub(crate) refl_g: [f32; PROBE_ROW_STACK_CAP],
pub(crate) refl_b: [f32; PROBE_ROW_STACK_CAP],
pub(crate) gi_r: [f32; PROBE_ROW_STACK_CAP],
pub(crate) gi_g: [f32; PROBE_ROW_STACK_CAP],
pub(crate) gi_b: [f32; PROBE_ROW_STACK_CAP],
pub(crate) ao: [f32; PROBE_ROW_STACK_CAP],
pub(crate) depth: [f32; PROBE_ROW_STACK_CAP],
pub(crate) nx: [f32; PROBE_ROW_STACK_CAP],
pub(crate) ny: [f32; PROBE_ROW_STACK_CAP],
pub(crate) nz: [f32; PROBE_ROW_STACK_CAP],
pub(crate) valid: [u8; PROBE_ROW_STACK_CAP],
}
#[derive(Clone, Debug)]
pub(crate) struct RtProbeRowScratch {
pub(crate) frame_gen: u64,
pub(crate) cached_gy_a: usize,
pub(crate) cached_gy_b: usize,
pub(crate) buf_a: RtProbeRowStack,
pub(crate) buf_b: RtProbeRowStack,
}
#[derive(Clone, Copy)]
pub(crate) struct RtProbeRowView<'a> {
pub(crate) shadow: &'a [f32],
pub(crate) refl_r: &'a [f32],
pub(crate) refl_g: &'a [f32],
pub(crate) refl_b: &'a [f32],
pub(crate) gi_r: &'a [f32],
pub(crate) gi_g: &'a [f32],
pub(crate) gi_b: &'a [f32],
pub(crate) ao: &'a [f32],
pub(crate) depth: &'a [f32],
pub(crate) nx: &'a [f32],
pub(crate) ny: &'a [f32],
pub(crate) nz: &'a [f32],
pub(crate) valid: &'a [u8],
}
#[repr(C, align(16))]
#[derive(Clone, Copy)]
pub(crate) struct CachedProbeCell {
pub(crate) depth: [f32; 4],
pub(crate) shadow: [f32; 4],
pub(crate) refl_r: [f32; 4],
pub(crate) refl_g: [f32; 4],
pub(crate) refl_b: [f32; 4],
pub(crate) gi_r: [f32; 4],
pub(crate) gi_g: [f32; 4],
pub(crate) gi_b: [f32; 4],
pub(crate) ao: [f32; 4],
pub(crate) tol_scale: [f32; 4],
pub(crate) tol_bias: [f32; 4],
pub(crate) valid_u32: [u32; 4],
pub(crate) vmask: u8,
}
#[repr(C, align(16))]
#[derive(Clone, Copy)]
pub(crate) struct RunScratch32 {
pub(crate) depths: [f32; 32],
pub(crate) shadow: [f32; 32],
pub(crate) refl_r: [f32; 32],
pub(crate) refl_g: [f32; 32],
pub(crate) refl_b: [f32; 32],
pub(crate) gi_r: [f32; 32],
pub(crate) gi_g: [f32; 32],
pub(crate) gi_b: [f32; 32],
pub(crate) ao: [f32; 32],
}
pub(crate) struct SpanShadeOut<'a> {
pub(crate) rgba: &'a mut [u8],
pub(crate) luma: &'a mut [u8],
pub(crate) bloom: Option<(usize, &'a mut [f32; 4])>,
}
pub(crate) struct RunRowOut<'a> {
pub(crate) color: &'a mut [u8],
pub(crate) luma: &'a mut [u8],
pub(crate) write_bloom: bool,
pub(crate) bloom_off: usize,
pub(crate) bloom_band: &'a mut [[f32; 4]],
}
#[derive(Clone, Copy)]
pub(crate) struct ProbeBandContext<'a> {
pub(crate) top_row: &'a RtProbeRowView<'a>,
pub(crate) bottom_row: &'a RtProbeRowView<'a>,
pub(crate) wy0: f32,
pub(crate) wy1: f32,
pub(crate) gw_max: usize,
pub(crate) step2_i32: i32,
pub(crate) fx_lut: &'a [f32; 16],
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct RtProbeGridMutPtrs {
pub(crate) shadow: usize,
pub(crate) refl_r: usize,
pub(crate) refl_g: usize,
pub(crate) refl_b: usize,
pub(crate) gi_r: usize,
pub(crate) gi_g: usize,
pub(crate) gi_b: usize,
pub(crate) ao: usize,
pub(crate) depth: usize,
pub(crate) nx: usize,
pub(crate) ny: usize,
pub(crate) nz: usize,
pub(crate) world_x: usize,
pub(crate) world_y: usize,
pub(crate) world_z: usize,
pub(crate) valid: usize,
}
pub(crate) struct TileRasterProbeInputs<'a> {
pub(crate) raster_tris: &'a [RasterTri2D],
pub(crate) tile_offsets: &'a [u32],
pub(crate) tile_tri_indices: &'a [u32],
pub(crate) shaded_tris: &'a [GShadeTri],
pub(crate) static_bvh: &'a Bvh3D,
pub(crate) dyn_instances: &'a [DynamicRayInstance],
pub(crate) local_bvhs: &'a [Option<Bvh3D>],
pub(crate) prev_probes: Option<&'a RtProbeGridSoa>,
pub(crate) prev_view_proj: Mat4,
pub(crate) prev_render_dims: (usize, usize),
pub(crate) prev_rt_step: usize,
pub(crate) prev_gw: usize,
pub(crate) prev_gh: usize,
pub(crate) lumen_cache: Option<&'a LumenRadianceCache>,
pub(crate) light_clusters: Option<&'a LightClusterGrid3D>,
pub(crate) vsm: Option<&'a VirtualShadowMap>,
pub(crate) use_vsm_far_shadows: bool,
pub(crate) probe_checker_parity: usize,
pub(crate) tile_px: usize,
pub(crate) tiles_x: usize,
}
pub(crate) struct ShadeBandInputs<'a> {
pub(crate) depth_buf: &'a [f32],
pub(crate) g_tri_idx: &'a [u32],
pub(crate) shaded_tris: &'a [GShadeTri],
pub(crate) raw_probes: &'a RtProbeGridSoa,
pub(crate) wide_denoised_probes: &'a RtProbeGridSoa,
pub(crate) denoise_probes: bool,
pub(crate) denoise_gi_channels: bool,
pub(crate) static_bvh: &'a Bvh3D,
pub(crate) dyn_instances: &'a [DynamicRayInstance],
pub(crate) local_bvhs: &'a [Option<Bvh3D>],
pub(crate) bloom_row_bits: &'a [AtomicU64; 9],
}
pub(crate) struct PostProcessInputs<'a> {
pub(crate) color_src: &'a [u8],
pub(crate) luma: &'a [u8],
pub(crate) g_tri_idx: &'a [u32],
pub(crate) bloom: &'a [[f32; 4]],
pub(crate) bloom_tile_active: &'a [u8],
pub(crate) taa_history: &'a [u8],
}
#[derive(Clone, Copy, Debug)]
pub(crate) struct DeferredFrameContext {
pub(crate) width: usize,
pub(crate) height: usize,
pub(crate) grid_width: usize,
pub(crate) grid_height: usize,
pub(crate) bloom_width: usize,
pub(crate) raytrace_step: usize,
pub(crate) inv_width: f32,
pub(crate) inv_height: f32,
pub(crate) camera_position: Vec3,
pub(crate) camera_forward: Vec3,
pub(crate) camera_right_scaled: Vec3,
pub(crate) camera_up_scaled: Vec3,
pub(crate) sun: DirectionalLight3D,
pub(crate) inv_sun_dir: Vec3,
pub(crate) soft_shadow_rays: [(Vec3, Vec3); 16],
pub(crate) frame_index: usize,
pub(crate) raytrace_mode: RayTracingMode,
pub(crate) reflection_bounces: u8,
pub(crate) fog_on: bool,
pub(crate) inv_fog_distance: f32,
pub(crate) exposure_scale: f32,
pub(crate) bloom_on: bool,
pub(crate) has_clustered_lights: bool,
pub(crate) probe_frame_generation: u64,
}
#[derive(Clone, Debug, Default)]
pub(crate) struct GeomChunkScratch {
pub(crate) shaded_tris: Vec<GShadeTri>,
pub(crate) raster_tris: Vec<RasterTri2D>,
pub(crate) projected_verts: Vec<([f32; 4], Vec3)>,
pub(crate) cluster_ranges: Vec<(usize, usize)>,
pub(crate) visible_objects: usize,
pub(crate) hiz_culled_objects: usize,
pub(crate) lod_simplified_objects: usize,
pub(crate) meshlets_drawn: usize,
pub(crate) meshlets_culled: usize,
pub(crate) mesh_ids: Vec<usize>,
}
pub(crate) struct GeomPassContext<'a> {
pub(crate) objects: &'a [SceneObject3D],
pub(crate) mesh_lib: &'a [MeshLodChain],
pub(crate) hiz_pyramid: &'a HiZPyramid,
pub(crate) hiz_occluder_flags: &'a [u8],
pub(crate) frustum: Frustum3D,
pub(crate) view_proj: Mat4,
pub(crate) cam_pos: Vec3,
pub(crate) sun_dir: Vec3,
pub(crate) sky_horizon: Vec3,
pub(crate) sky_zenith: Vec3,
pub(crate) focal_px: f32,
pub(crate) lod_bias: f32,
pub(crate) near_plane: f32,
pub(crate) w_f: f32,
pub(crate) h_f: f32,
pub(crate) w_max_i: i32,
pub(crate) h_max_i: i32,
pub(crate) jitter_x: f32,
pub(crate) jitter_y: f32,
pub(crate) frustum_on: bool,
pub(crate) hiz_active: bool,
pub(crate) use_rt_refl: bool,
}
pub(crate) struct GeomPassOut<'a> {
pub(crate) shaded_tris: &'a mut Vec<GShadeTri>,
pub(crate) raster_tris: &'a mut Vec<RasterTri2D>,
pub(crate) projected_verts: &'a mut Vec<([f32; 4], Vec3)>,
pub(crate) cluster_ranges: &'a mut Vec<(usize, usize)>,
pub(crate) mesh_ids: Option<&'a mut Vec<usize>>,
pub(crate) unique_meshes: Option<&'a mut HashSet<usize>>,
pub(crate) visible_objects: usize,
pub(crate) hiz_culled_objects: usize,
pub(crate) lod_simplified_objects: usize,
pub(crate) meshlets_drawn: usize,
pub(crate) meshlets_culled: usize,
}
#[derive(Clone, Data, Debug)]
pub struct Renderer3D {
pub(crate) color_buffer: Vec<u8>,
pub(crate) aa_buffer: Vec<u8>,
pub(crate) depth_buffer: Vec<f32>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) g_tri_idx: Vec<u32>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) luma_buffer: Vec<u8>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) shaded_tris: Vec<GShadeTri>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) rgba_scratch: Vec<u8>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) rt_probes: RtProbeGridSoa,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) prev_rt_probes: RtProbeGridSoa,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) has_probe_history: bool,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) prev_probe_gw: usize,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) prev_probe_gh: usize,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) prev_probe_rt_mode: RayTracingMode,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) prev_sun_dir: Vec3,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) rt_probes_wide_denoised: RtProbeGridSoa,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) bloom_a: Vec<[f32; 4]>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) bloom_b: Vec<[f32; 4]>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) bloom_tile_active: Vec<u8>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) visible_scratch: Vec<(f32, usize)>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) cluster_ranges_scratch: Vec<(usize, usize)>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) projected_verts_scratch: Vec<([f32; 4], Vec3)>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) unique_meshes_scratch: HashSet<usize>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) saved_objs_scratch: Vec<(usize, Transform3D, AxisAlignedBox3D)>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) raster_tris_scratch: Vec<RasterTri2D>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) tile_counts_scratch: Vec<u32>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) tile_offsets_scratch: Vec<u32>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) tile_cursors_scratch: Vec<u32>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) tile_tri_indices_scratch: Vec<u32>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) gpu_target: GpuCompositeTarget,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) has_taa_history: bool,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) prev_vp_m0: f32,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) prev_view_proj: Mat4,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) has_prev_vp: bool,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) prev_render_dims: (usize, usize),
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) prev_rt_step: usize,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) hiz_pyramid: HiZPyramid,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) hiz_occluder_flags_scratch: Vec<u8>,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) lumen_cache: LumenRadianceCache,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) light_clusters: LightClusterGrid3D,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) virtual_shadow_map: VirtualShadowMap,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) tsr_upscaler: TsrUpscaler,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) tsr_internal_scratch: Vec<u8>,
pub(crate) frame_governor: AdaptiveFrameGovernor,
pub(crate) render_graph: RenderGraph3D,
#[get(type(copy))]
pub(crate) rt_stride_bias: usize,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) geom_chunks_scratch: Vec<GeomChunkScratch>,
#[get(type(copy))]
pub(crate) adapted_exposure: f32,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) frame_index: u32,
#[get(type(copy))]
pub(crate) last_world_revision: u64,
#[get(skip)]
#[get_mut(skip)]
#[set(skip)]
pub(crate) last_quality_fingerprint: u64,
#[get(type(copy))]
pub(crate) taa_accumulated_frames: u32,
#[get(type(copy))]
pub(crate) cached_world_reuses: u64,
#[get(type(copy))]
pub(crate) width: u32,
#[get(type(copy))]
pub(crate) height: u32,
#[get(type(copy))]
pub(crate) last_stats: RenderStats3D,
}