From 2a88b8852a608fef84fc2f5ef294f1a125071bcd Mon Sep 17 00:00:00 2001 From: Sam <13449963+SamG-Coder@users.noreply.github.com> Date: Fri, 13 Nov 2026 20:38:19 +1100 Subject: [PATCH 1/2] Fix spreading invalid lighting and reduce movement, streaming, and page costs --- crates/solstice-builder/src/paging.rs | 163 ++++++++- crates/solstice-import/src/streamed.rs | 37 +- crates/solstice-render/examples/cpu_stress.rs | 116 +++++++ .../solstice-render/examples/page_stress.rs | 112 ++++++ .../examples/streaming_stress.rs | 126 +++++++ .../solstice-render/shaders/common/math.wgsl | 10 + .../shaders/gi/probe_integrate.wgsl | 8 +- .../shaders/gi/probe_project.wgsl | 12 +- .../shaders/gi/probe_trace.wgsl | 13 +- .../shaders/gi/reflections.wgsl | 19 +- .../shaders/gi/screen_history.wgsl | 13 +- crates/solstice-render/shaders/post/taa.wgsl | 44 ++- crates/solstice-render/shaders/vg/cull.wgsl | 13 +- .../shaders/vg/cull_control.wgsl | 6 +- .../solstice-render/shaders/vg/resolve.wgsl | 27 +- crates/solstice-render/src/motion.rs | 118 +++++-- crates/solstice-render/src/post.rs | 4 + crates/solstice-render/src/post_stress.rs | 327 ++++++++++++++++++ .../src/streaming/residency.rs | 79 ++++- crates/solstice-render/src/vg/culling.rs | 8 +- .../solstice-render/src/vg/culling_stress.rs | 172 +++++++++ crates/solstice-render/src/vg/resolve.rs | 3 + .../solstice-render/src/vg/resolve_stress.rs | 107 ++++++ docs/performance-audit.md | 207 +++++++++++ docs/performance-results/cpu-baseline.csv | 13 + docs/performance-results/cpu-final.csv | 13 + docs/performance-results/page-baseline.csv | 3 + docs/performance-results/page-fixed.csv | 3 + .../streaming-baseline.csv | 3 + docs/performance-results/streaming-fixed.csv | 3 + 30 files changed, 1663 insertions(+), 119 deletions(-) create mode 100644 crates/solstice-render/examples/cpu_stress.rs create mode 100644 crates/solstice-render/examples/page_stress.rs create mode 100644 crates/solstice-render/examples/streaming_stress.rs create mode 100644 crates/solstice-render/src/post_stress.rs create mode 100644 crates/solstice-render/src/vg/culling_stress.rs create mode 100644 crates/solstice-render/src/vg/resolve_stress.rs create mode 100644 docs/performance-audit.md create mode 100644 docs/performance-results/cpu-baseline.csv create mode 100644 docs/performance-results/cpu-final.csv create mode 100644 docs/performance-results/page-baseline.csv create mode 100644 docs/performance-results/page-fixed.csv create mode 100644 docs/performance-results/streaming-baseline.csv create mode 100644 docs/performance-results/streaming-fixed.csv diff --git a/crates/solstice-builder/src/paging.rs b/crates/solstice-builder/src/paging.rs index bd9341d..d2271d2 100644 --- a/crates/solstice-builder/src/paging.rs +++ b/crates/solstice-builder/src/paging.rs @@ -4,6 +4,7 @@ //! set's parents always come from a later round, so page dependencies can't form a cycle, and //! they always point at a lower id. +use rustc_hash::FxHashMap; use solstice_asset::{ gpu::{CLUSTER_CHILDREN_MISSING, NODE_LEAF}, paged::{ @@ -12,6 +13,77 @@ use solstice_asset::{ }, PackedNode, PackedVertex, SceneAsset, TextureLayer, VirtualMesh, }; +use std::ops::Range; + +/// Identical payloads may share an offset within a page. Keys compare every byte, so this +/// preserves quantized positions, attributes, skin weights and triangle order exactly. +#[derive(Default)] +struct PageRecords { + data: ClusterRecords, + vertices: FxHashMap, u32>, + triangles: FxHashMap, u32>, + clusters: usize, +} + +// External cluster tables reserve the largest page's record count for every pool slot. +// Sharing a tiny payload must not pack unbounded metadata into one otherwise empty page. +const MAX_PAGE_CLUSTERS: usize = PAGE_BYTES / std::mem::size_of::(); + +struct PageCluster { + id: u32, + vertices: Range, + triangles: Range, +} + +impl PageRecords { + fn append(&mut self, source: &ClusterRecords, ranges: &[PageCluster], out: &mut PagedScene) { + self.clusters += ranges.len(); + for range in ranges { + let vertices = &source.vertices[range.vertices.clone()]; + let vertex_key: &[u8] = bytemuck::cast_slice(vertices); + let vertex_offset = match self.vertices.get(vertex_key) { + Some(&offset) => offset, + None => { + let offset = self.data.vertices.len() as u32; + self.data.vertices.extend_from_slice(vertices); + self.vertices.insert(vertex_key.to_vec(), offset); + offset + } + }; + let triangles = &source.triangles[range.triangles.clone()]; + let triangle_offset = match self.triangles.get(triangles) { + Some(&offset) => offset, + None => { + let offset = self.data.triangles.len() as u32; + self.data.triangles.extend_from_slice(triangles); + self.triangles.insert(triangles.to_vec(), offset); + offset + } + }; + let cluster = &mut out.clusters[range.id as usize]; + cluster.vertex_offset = vertex_offset; + cluster.triangle_offset = triangle_offset; + } + } + + fn rollback(&mut self, vertices: usize, triangles: usize, clusters: usize) { + self.clusters = clusters; + self.data.vertices.truncate(vertices); + self.data.triangles.truncate(triangles); + self.vertices + .retain(|_, offset| (*offset as usize) < vertices); + self.triangles + .retain(|_, offset| (*offset as usize) < triangles); + } + + fn clear(&mut self) { + self.clusters = 0; + self.data.vertices.clear(); + self.data.triangles.clear(); + self.vertices.clear(); + self.triangles.clear(); + } +} /// One set on its way into a page. struct Item { @@ -164,7 +236,9 @@ pub fn paginate_from( // Coarsest first. The roots lead, as `ROOT_ROUND` is the largest round. items.sort_by_key(|item| (std::cmp::Reverse(item.round), item.mesh, item.curve)); - let mut records = ClusterRecords::default(); + let mut records = PageRecords::default(); + let mut incoming = ClusterRecords::default(); + let mut ranges = Vec::new(); let mut current = PageInfo::default(); let mut current_round = None; for item in &items { @@ -184,21 +258,20 @@ pub fn paginate_from( "a sibling set must fit in a page" ); - let raw = PageInfo { - vertex_count: current.vertex_count + extra_vertices, - triangle_count: current.triangle_count + extra_triangles, - ..Default::default() - }; - if current_round.is_some_and(|round| round != item.round) || raw.raw_bytes() > PAGE_BYTES { + if current_round.is_some_and(|round| round != item.round) + || records.clusters + range.len() > MAX_PAGE_CLUSTERS + { finish_page(&mut out, &mut records, &mut current, current_round, sink)?; } current_round = Some(item.round); + incoming.vertices.clear(); + incoming.triangles.clear(); + ranges.clear(); for c in range { let cluster = *local(c); - let packed = &mut out.clusters[c as usize]; - packed.vertex_offset = records.vertices.len() as u32; - packed.triangle_offset = records.triangles.len() as u32; + let vertex_start = incoming.vertices.len(); + let triangle_start = incoming.triangles.len(); store.read( item.mesh, ClusterRange { @@ -207,11 +280,29 @@ pub fn paginate_from( first_triangle: cluster.triangle_offset as usize, triangles: cluster.triangle_count() as usize, }, - &mut records, + &mut incoming, ); + ranges.push(PageCluster { + id: c, + vertices: vertex_start..incoming.vertices.len(), + triangles: triangle_start..incoming.triangles.len(), + }); } - current.vertex_count = records.vertices.len() as u32; - current.triangle_count = records.triangles.len() as u32; + // Try the whole sibling set before closing a page: shared payloads can make it fit + // where its unshared size would not. An overflowing set moves intact to the next page. + let previous_clusters = records.clusters; + records.append(&incoming, &ranges, &mut out); + if records.data.vertices.len() * 16 + records.data.triangles.len() * 4 > PAGE_BYTES { + records.rollback( + current.vertex_count as usize, + current.triangle_count as usize, + previous_clusters, + ); + finish_page(&mut out, &mut records, &mut current, current_round, sink)?; + records.append(&incoming, &ranges, &mut out); + } + current.vertex_count = records.data.vertices.len() as u32; + current.triangle_count = records.data.triangles.len() as u32; current.set_count += 1; out.sets.push(ClusterSet { page: out.pages.len() as u32, @@ -238,14 +329,14 @@ pub fn paginate_from( fn finish_page( out: &mut PagedScene, - records: &mut ClusterRecords, + records: &mut PageRecords, current: &mut PageInfo, round: Option, sink: &mut dyn FnMut(Vec) -> Result<(), E>, ) -> Result<(), E> { let mut bytes = Vec::with_capacity(current.raw_bytes()); - bytes.extend_from_slice(bytemuck::cast_slice(&records.vertices)); - bytes.extend_from_slice(bytemuck::cast_slice(&records.triangles)); + bytes.extend_from_slice(bytemuck::cast_slice(&records.data.vertices)); + bytes.extend_from_slice(bytemuck::cast_slice(&records.data.triangles)); // The roots lead, so pinned pages are the first of them. if round == Some(ROOT_ROUND) { out.pinned_data.extend_from_slice(&bytes); @@ -255,8 +346,7 @@ fn finish_page( current.first_set = out.sets.len() as u32 - current.set_count; out.pages.push(*current); *current = PageInfo::default(); - records.vertices.clear(); - records.triangles.clear(); + records.clear(); Ok(()) } @@ -363,6 +453,43 @@ mod tests { } } + #[test] + fn identical_payloads_share_storage_but_different_attributes_do_not() { + let mut source = scene(&[0, 0]); + let loaded = paginate(&source); + assert_eq!(loaded.scene.pages.len(), 1); + let [first, second] = loaded.scene.clusters.as_slice() else { + panic!("each simple mesh should make one cluster"); + }; + assert_eq!(first.vertex_offset, second.vertex_offset); + assert_eq!(first.triangle_offset, second.triangle_offset); + assert_eq!(loaded.scene.pages[0].vertex_count, first.vertex_count()); + assert_eq!(loaded.scene.pages[0].triangle_count, first.triangle_count()); + // One bit of a packed normal must prevent vertex sharing. Topology can still share. + source.meshes[1].vertices[0].data[3] ^= 1; + let loaded = paginate(&source); + let first = &loaded.scene.clusters[0]; + let second = &loaded.scene.clusters[1]; + assert_ne!(first.vertex_offset, second.vertex_offset); + assert_eq!(first.triangle_offset, second.triangle_offset); + assert_eq!(loaded.scene.pages[0].vertex_count, first.vertex_count() * 2); + let encoded = solstice_asset::file::encode(&loaded); + let decoded = solstice_asset::file::decode(&encoded).unwrap(); + assert_eq!(decoded.scene.clusters, loaded.scene.clusters); + assert_eq!(decoded.scene.pinned_data, loaded.scene.pinned_data); + } + + #[test] + fn sharing_payloads_does_not_make_a_pages_cluster_table_unbounded() { + let mut source = scene(&[0]); + source + .meshes + .resize(MAX_PAGE_CLUSTERS + 1, source.meshes[0].clone()); + let loaded = paginate(&source); + assert_eq!(loaded.scene.pages.len(), 2); + assert!(loaded.scene.max_page_clusters() as usize <= MAX_PAGE_CLUSTERS); + } + #[test] fn a_skinned_cluster_keeps_its_skins_behind_its_vertices_in_its_page() { use solstice_asset::PackedSkin; diff --git a/crates/solstice-import/src/streamed.rs b/crates/solstice-import/src/streamed.rs index 5f962b0..63588f0 100644 --- a/crates/solstice-import/src/streamed.rs +++ b/crates/solstice-import/src/streamed.rs @@ -155,17 +155,32 @@ fn free_bytes(path: &Path) -> Option { let absolute = std::path::absolute(path).ok()?; #[cfg(windows)] { - let root = absolute.components().next()?; - let drive = root.as_os_str().to_str()?.trim_end_matches(':').to_owned(); - let output = std::process::Command::new("powershell") - .args([ - "-NoProfile", - "-Command", - &format!("(Get-PSDrive -Name '{drive}').Free"), - ]) - .output() - .ok()?; - String::from_utf8_lossy(&output.stdout).trim().parse().ok() + use std::os::windows::ffi::OsStrExt; + #[link(name = "kernel32")] + unsafe extern "system" { + fn GetDiskFreeSpaceExW( + directory: *const u16, + available: *mut u64, + total: *mut u64, + free: *mut u64, + ) -> i32; + } + // The output may not exist yet. Query its nearest existing directory, which also + // handles UNC paths and volume mount points without parsing a drive letter. + let directory = absolute.ancestors().find(|p| p.is_dir())?; + let directory: Vec = directory.as_os_str().encode_wide().chain([0]).collect(); + let mut available = 0; + // SAFETY: directory is a terminated UTF-16 string and available is a writable u64. + // The optional total/free outputs are null, as allowed by the Windows API. + let ok = unsafe { + GetDiskFreeSpaceExW( + directory.as_ptr(), + &mut available, + std::ptr::null_mut(), + std::ptr::null_mut(), + ) + }; + (ok != 0).then_some(available) } #[cfg(not(windows))] { diff --git a/crates/solstice-render/examples/cpu_stress.rs b/crates/solstice-render/examples/cpu_stress.rs new file mode 100644 index 0000000..0c0dd61 --- /dev/null +++ b/crates/solstice-render/examples/cpu_stress.rs @@ -0,0 +1,116 @@ +//! Repeatable CPU scaling measurements, with no quality settings or GPU involved. +//! Run: cargo run --release -p solstice-render --example cpu_stress + +use bytemuck::Zeroable; +use glam::{Mat4, Vec3}; +use solstice_render::{motion::InstanceTable, scene::GpuInstance, streaming::residency::Residency}; +use std::{hint::black_box, time::Instant}; + +fn table(count: u32) -> InstanceTable { + let mut table = InstanceTable::new( + vec![GpuInstance::zeroed(); count as usize], + (0..count).map(Some).collect(), + vec![(Vec3::ZERO, 1.0); count as usize], + ); + // Initialise the transforms through the same public API used by the renderer. + for i in 0..count { + table.set_transform(i, Mat4::IDENTITY, true); + } + table.advance(); + table +} + +fn report(case: &str, count: u32, mut samples: Vec, checksum: u64) { + samples.sort_by(f64::total_cmp); + println!( + "{case},{count},{:.6},{:.6},{checksum}", + samples[samples.len() / 2], + samples[samples.len() - 1] + ); +} + +fn hash(bytes: &[u8]) -> u64 { + bytes.iter().fold(0xcbf29ce484222325, |h, &b| { + (h ^ u64::from(b)).wrapping_mul(0x100000001b3) + }) +} + +fn main() { + println!("case,count,median_ms,max_ms,checksum"); + for count in [1_024, 8_192, 32_768] { + let mut table = table(count); + let mut reads = Vec::new(); + let mut updates = Vec::new(); + for round in 0..7 { + let start = Instant::now(); + for i in 0..count { + // A common game loop: read an object's current transform, then move it. + let mut transform = table.transform(black_box(i)).unwrap(); + transform.w_axis.x += 1.0; + table.set_transform(i, transform, false); + } + if round > 0 { + reads.push(start.elapsed().as_secs_f64() * 1_000.0); + } + let start = Instant::now(); + black_box(table.advance()); + if round > 0 { + updates.push(start.elapsed().as_secs_f64() * 1_000.0); + } + } + for i in 0..count { + assert_eq!(table.transform(i).unwrap().w_axis.x, 7.0); + } + let checksum = hash(bytemuck::cast_slice(table.gpu_data(0..count as usize))); + report("read_move", count, reads, checksum); + report("advance", count, updates, checksum); + } + for count in [1_024, 8_192, 32_768] { + let mut table = table(count); + let mut samples = Vec::new(); + for round in 0..7 { + let start = Instant::now(); + // Multiple simulation ticks before drawing, submitted in reverse instance order. + for tick in 0..8 { + for i in (0..count).rev() { + table.set_transform( + i, + Mat4::from_translation(Vec3::new(i as f32, tick as f32, 0.0)), + tick == 7, + ); + } + } + black_box(table.advance()); + if round > 0 { + samples.push(start.elapsed().as_secs_f64() * 1_000.0); + } + } + let checksum = hash(bytemuck::cast_slice(table.gpu_data(0..count as usize))); + report("eight_updates", count, samples, checksum); + } + for count in [4_096u32, 65_536, 1_048_576] { + let mut dependencies = vec![vec![0]; count as usize]; + dependencies[0].clear(); + let mut residency = Residency::new(dependencies, 1, 512); + let requests: Vec = (0..count) + .map(|i| { + if i % 8 == 0 { + 2 + i.wrapping_mul(2654435761) % 1024 + } else { + 0 + } + }) + .collect(); + let mut samples = Vec::new(); + let mut checksum = 0; + for frame in 0..21 { + let start = Instant::now(); + let fetched = residency.plan(frame, black_box(&requests), 32); + if frame > 0 { + samples.push(start.elapsed().as_secs_f64() * 1_000.0); + } + checksum ^= hash(bytemuck::cast_slice(&fetched)); + } + report("stream_plan", count, samples, checksum); + } +} diff --git a/crates/solstice-render/examples/page_stress.rs b/crates/solstice-render/examples/page_stress.rs new file mode 100644 index 0000000..357624f --- /dev/null +++ b/crates/solstice-render/examples/page_stress.rs @@ -0,0 +1,112 @@ +//! Lossless page-packing measurements on connected and disconnected geometry. +//! Run: cargo run --release -p solstice-render --example page_stress +use glam::{Mat4, Vec2, Vec3}; +use solstice_asset::{Instance, Material, SceneAsset}; +use solstice_builder::{build_virtual_mesh, paginate, BuildOptions, Mesh, Vertex}; +use std::time::Instant; + +fn grid(side: u32) -> Mesh { + let mut mesh = Mesh::default(); + for z in 0..=side { + for x in 0..=side { + let (x, z) = (x as f32, z as f32); + mesh.vertices.push(Vertex { + position: Vec3::new(x, (x * 0.07).sin() * (z * 0.05).cos(), z), + normal: Vec3::Y, + uv: Vec2::new(x, z) / side as f32, + }); + } + } + for z in 0..side { + for x in 0..side { + let a = z * (side + 1) + x; + let b = a + side + 1; + mesh.indices + .extend_from_slice(&[a, b, a + 1, a + 1, b, b + 1]); + } + } + mesh +} + +fn blades(count: u32) -> Mesh { + let mut mesh = Mesh::default(); + for i in 0..count { + let x = (i % 128) as f32 * 0.15; + let z = (i / 128) as f32 * 0.15; + let start = mesh.vertices.len() as u32; + for (p, uv) in [ + (Vec3::new(x, 0.0, z), Vec2::ZERO), + (Vec3::new(x + 0.05, 0.0, z), Vec2::X), + (Vec3::new(x + 0.03, 0.5 + (i % 7) as f32 * 0.01, z), Vec2::Y), + ] { + mesh.vertices.push(Vertex { + position: p, + normal: Vec3::Z, + uv, + }); + } + mesh.indices + .extend_from_slice(&[start, start + 1, start + 2]); + } + mesh +} + +fn main() { + println!("case,source_triangles,clusters,pages,raw_bytes,deflated_bytes,pool_bytes,packing_ms"); + for (name, mesh) in [("terrain", grid(192)), ("foliage", blades(32_768))] { + let scene = SceneAsset { + meshes: vec![build_virtual_mesh(&mesh, &BuildOptions::default())], + materials: vec![Material::default()], + instances: vec![Instance { + mesh: 0, + material: 0, + transform: Mat4::IDENTITY, + }], + ..Default::default() + }; + let start = Instant::now(); + let loaded = paginate(&scene); + let packing_ms = start.elapsed().as_secs_f64() * 1_000.0; + let mut raw = 0; + let mut deflated = 0; + for page in 0..loaded.scene.pages.len() as u32 { + let bytes = loaded.page(page); + raw += bytes.len(); + deflated += solstice_asset::file::deflate_page(bytes).len(); + } + // Every cluster must still decode to exactly the original packed values, including + // triangle ordering. This checks the thing the GPU consumes, not just byte counts. + for set in &loaded.scene.sets { + let info = &loaded.scene.pages[set.page as usize]; + let bytes = loaded.page(set.page); + for c in set.first_cluster..set.first_cluster + set.cluster_count { + let before = &scene.meshes[0].clusters[c as usize]; + let after = &loaded.scene.clusters[c as usize]; + let vs = before.vertex_count() as usize; + let ts = before.triangle_count() as usize; + let vertex_at = after.vertex_offset as usize * 16; + let triangle_at = + info.vertex_count as usize * 16 + after.triangle_offset as usize * 4; + let source_vertices = + &scene.meshes[0].vertices[before.vertex_offset as usize..][..vs]; + let source_triangles = + &scene.meshes[0].triangles[before.triangle_offset as usize..][..ts]; + assert_eq!( + &bytes[vertex_at..][..vs * 16], + bytemuck::cast_slice(source_vertices) + ); + assert_eq!( + &bytes[triangle_at..][..ts * 4], + bytemuck::cast_slice(source_triangles) + ); + } + } + println!( + "{name},{},{},{},{raw},{deflated},{},{packing_ms:.3}", + mesh.indices.len() / 3, + loaded.scene.clusters.len(), + loaded.scene.pages.len(), + loaded.scene.pages.len() * solstice_asset::paged::PAGE_BYTES + ); + } +} diff --git a/crates/solstice-render/examples/streaming_stress.rs b/crates/solstice-render/examples/streaming_stress.rs new file mode 100644 index 0000000..f76ac6e --- /dev/null +++ b/crates/solstice-render/examples/streaming_stress.rs @@ -0,0 +1,126 @@ +//! Deterministic streaming soak: changing views, delayed/failed requests, held views and +//! small pools. Every install and eviction checks dependency and slot invariants. +use solstice_render::streaming::residency::{Residency, Step}; + +fn random(state: &mut u64) -> u64 { + *state ^= *state << 13; + *state ^= *state >> 7; + *state ^= *state << 17; + *state +} + +fn hash(state: &mut u64, value: u32) { + *state = (*state ^ u64::from(value)).wrapping_mul(0x100000001b3); +} + +fn main() { + const COUNT: usize = 16_384; + const PINNED: u32 = 8; + const FETCHES: u32 = 64; + let dependencies: Vec> = (0..COUNT as u32) + .map(|page| { + if page < PINNED { + vec![] + } else { + vec![page / 8] + } + }) + .collect(); + println!("bands,frames,fetches,installs,evictions,trace_hash"); + for slots in [vec![256], vec![64, 64, 128]] { + let bands = if slots.len() == 1 { + vec![0; COUNT] + } else { + (0..COUNT) + .map(|page| { + if page < 64 { + 2 + } else if page < 512 { + 1 + } else { + 0 + } + }) + .collect() + }; + let mut residency = Residency::with_bands(dependencies.clone(), PINNED, bands, &slots); + let mut placed = vec![None; COUNT]; + for page in 0..PINNED { + placed[page as usize] = Some(residency.install_now(page)); + } + let mut random_state = 0x2545_f491_4f6c_dd1d; + let mut checksum = 0xcbf29ce484222325; + let mut flying = Vec::new(); + let (mut fetched, mut installs, mut evictions) = (0, 0, 0); + for frame in 1..=1_500 { + let mut requests = vec![0; COUNT]; + let mut held = vec![0u32; COUNT / 32]; + let focus = (random(&mut random_state) % COUNT as u64) as usize; + for n in 0..96 { + let page = (focus + (random(&mut random_state) % 512) as usize) % COUNT; + requests[page] = if n % 7 == 0 { 1 } else { 2 + n * 7 }; + if frame % 19 == 0 { + held[page / 32] |= 1 << (page % 32); + } + } + let started = residency.plan_holding(frame, &requests, &[&held], FETCHES); + fetched += started.len(); + for &page in &started { + hash(&mut checksum, page); + } + flying.extend(started); + // Complete in arbitrary order, with failures and enough delay to leave requests + // from an old camera view in flight while the next view is requested. + for _ in 0..48 { + if flying.is_empty() { + break; + } + let at = random(&mut random_state) as usize % flying.len(); + let page = flying.swap_remove(at); + if random(&mut random_state).is_multiple_of(17) { + residency.failed(page); + } else { + assert!(residency.arrived(page)); + } + } + let started = residency.refill(FETCHES); + fetched += started.len(); + for &page in &started { + hash(&mut checksum, page); + } + flying.extend(started); + for step in residency.install_ready(frame, 32) { + match step { + Step::Evict(page) => { + assert!(page >= PINNED); + assert!(placed[page as usize].take().is_some()); + assert!(!dependencies + .iter() + .enumerate() + .any(|(p, deps)| placed[p].is_some() && deps.contains(&page))); + hash(&mut checksum, page | (1 << 31)); + evictions += 1; + } + Step::Install { page, slot } => { + assert!(dependencies[page as usize] + .iter() + .all(|&d| placed[d as usize].is_some())); + assert!(!placed.contains(&Some(slot))); + placed[page as usize] = Some(slot); + hash(&mut checksum, page); + hash(&mut checksum, slot); + installs += 1; + } + } + } + assert!(flying.len() <= FETCHES as usize); + assert!(residency.installed_count() <= slots.iter().sum()); + hash(&mut checksum, residency.starved()); + hash(&mut checksum, u32::from(residency.take_awaited_arrival())); + } + println!( + "{},1500,{fetched},{installs},{evictions},{checksum}", + slots.len() + ); + } +} diff --git a/crates/solstice-render/shaders/common/math.wgsl b/crates/solstice-render/shaders/common/math.wgsl index a0ba919..606dbe1 100644 --- a/crates/solstice-render/shaders/common/math.wgsl +++ b/crates/solstice-render/shaders/common/math.wgsl @@ -3,6 +3,16 @@ const PI: f32 = 3.14159265359; const TAU: f32 = 6.28318530718; +// Inspect the exponent bits: floating-point comparisons with NaN may be folded by +// shader optimizers. Invalid lighting must never enter a spatial or temporal filter. +fn finite3(v: vec3f) -> bool { + return all((bitcast(v) & vec3u(0x7f800000u)) != vec3u(0x7f800000u)); +} + +fn finite4(v: vec4f) -> bool { + return all((bitcast(v) & vec4u(0x7f800000u)) != vec4u(0x7f800000u)); +} + // Decodes a signed octahedral vector in [-1, 1]^2 to a unit vector. fn oct_decode(e: vec2f) -> vec3f { var v = vec3f(e.x, e.y, 1.0 - abs(e.x) - abs(e.y)); diff --git a/crates/solstice-render/shaders/gi/probe_integrate.wgsl b/crates/solstice-render/shaders/gi/probe_integrate.wgsl index 32aaf11..173379d 100644 --- a/crates/solstice-render/shaders/gi/probe_integrate.wgsl +++ b/crates/solstice-render/shaders/gi/probe_integrate.wgsl @@ -237,9 +237,15 @@ fn main(@builtin(global_invocation_id) id: vec3u) { // Where this surface would lie at that texel's centre, a fraction of a pixel away. let there = expected + dot(gradient, vec2f(texel) + vec2f(0.5) - previous_uv * frame.viewport); if abs(remembered - there) <= tolerance { + let sample = textureLoad(history_tex, texel, 0); + // A single NaN otherwise grows into a larger patch every frame through + // this four-tap gather, even after its original source disappears. + if !finite4(sample) { + continue; + } let side = select(vec2f(1.0) - part, part, vec2i(dx, dy) == vec2i(1)); let weight = max(side.x * side.y, 1.0e-3); - history += textureLoad(history_tex, texel, 0) * weight; + history += sample * weight; found += weight; } } diff --git a/crates/solstice-render/shaders/gi/probe_project.wgsl b/crates/solstice-render/shaders/gi/probe_project.wgsl index afc941f..818beac 100644 --- a/crates/solstice-render/shaders/gi/probe_project.wgsl +++ b/crates/solstice-render/shaders/gi/probe_project.wgsl @@ -50,21 +50,27 @@ fn project(@builtin(global_invocation_id) id: vec3u) { // hemisphere carrying the average radiance. A pixel whose bumped normal leans away from // the probe's normal then reads something sensible. var mean = vec3f(0.0); + var valid_rays = 0.0; for (var y = 0u; y < PROBE_RAYS; y++) { for (var x = 0u; x < PROBE_RAYS; x++) { let texel = tile * PROBE_RAYS + vec2u(x, y); - mean += textureLoad(traced, vec2i(texel), 0).rgb; + let radiance = textureLoad(traced, vec2i(texel), 0).rgb; + if finite3(radiance) { + mean += radiance; + valid_rays += 1.0; + } } } let ray_count = f32(PROBE_RAYS * PROBE_RAYS); - mean /= ray_count; + mean /= max(valid_rays, 1.0); // Each ray stands for an equal part of the 2 pi steradian hemisphere. let weight = TAU / ray_count; for (var y = 0u; y < PROBE_RAYS; y++) { for (var x = 0u; x < PROBE_RAYS; x++) { let texel = tile * PROBE_RAYS + vec2u(x, y); - let radiance = textureLoad(traced, vec2i(texel), 0).rgb; + let sample = textureLoad(traced, vec2i(texel), 0).rgb; + let radiance = select(mean, sample, finite3(sample)); let direction = probe_ray_direction(tile, vec2u(x, y), normal, frame.frame_index); let mirrored = direction - 2.0 * dot(direction, normal) * normal; var basis_up = sh_basis(direction); diff --git a/crates/solstice-render/shaders/gi/probe_trace.wgsl b/crates/solstice-render/shaders/gi/probe_trace.wgsl index 72be385..2dd75b0 100644 --- a/crates/solstice-render/shaders/gi/probe_trace.wgsl +++ b/crates/solstice-render/shaders/gi/probe_trace.wgsl @@ -41,8 +41,13 @@ fn main(@builtin(global_invocation_id) id: vec3u) { let direction = probe_ray_direction(tile, ray, normal, frame.frame_index); let screen = trace_screen(world + normal * 0.03, direction, SCREEN_DISTANCE, SCREEN_STEPS, SCREEN_THICKNESS); - if screen.hit && screen.weight >= 1.0 { - textureStore(output, id.xy, vec4f(screen_hit_radiance(screen.uv), screen.t)); + var seen = vec4f(0.0); + if screen.hit { + seen = screen_hit_radiance(screen.uv); + } + let screen_weight = screen.weight * seen.a; + if screen_weight >= 1.0 { + textureStore(output, id.xy, vec4f(seen.rgb, screen.t)); return; } @@ -55,8 +60,8 @@ fn main(@builtin(global_invocation_id) id: vec3u) { var t = select(1000.0, hit.t, hit.hit); if screen.hit { // Near the screen edge, blend towards the volume so probes do not pop. - radiance = mix(radiance, screen_hit_radiance(screen.uv), screen.weight); - t = mix(t, screen.t, screen.weight); + radiance = mix(radiance, seen.rgb, screen_weight); + t = mix(t, screen.t, screen_weight); } textureStore(output, id.xy, vec4f(radiance, t)); } diff --git a/crates/solstice-render/shaders/gi/reflections.wgsl b/crates/solstice-render/shaders/gi/reflections.wgsl index 53c0b4f..b150b69 100644 --- a/crates/solstice-render/shaders/gi/reflections.wgsl +++ b/crates/solstice-render/shaders/gi/reflections.wgsl @@ -116,7 +116,7 @@ fn trace_refined(origin: vec3f, direction: vec3f, start: f32) -> VolumeHit { } let edge = min(min(p.x, 1.0 - p.x), min(p.y, 1.0 - p.y)); let seen = screen_hit_radiance(p.xy); - return VolumeHit(true, hit.t, mix(hit.radiance, seen, smoothstep(0.0, SCREEN_EDGE_FADE, edge)), 0.0); + return VolumeHit(true, hit.t, mix(hit.radiance, seen.rgb, seen.a * smoothstep(0.0, SCREEN_EDGE_FADE, edge)), 0.0); } // Every hit was somewhere the camera sees past, so the ray is still skimming the voxels of // something. That thing's light is a far better guess than the sky's, which it would be @@ -165,10 +165,13 @@ fn main(@builtin(global_invocation_id) id: vec3u) { let screen = trace_screen(world + normal * 0.02, direction, SCREEN_DISTANCE, SCREEN_STEPS, SCREEN_THICKNESS); var radiance = vec3f(0.0); + var screen_weight = 0.0; if screen.hit { - radiance = screen_hit_radiance(screen.uv); + let seen = screen_hit_radiance(screen.uv); + radiance = seen.rgb; + screen_weight = screen.weight * seen.a; } - if screen.weight < 1.0 { + if screen_weight < 1.0 { let level = min(volume_level_at(world, 0u), VOLUME_LEVELS - 1u); let voxel = volume_params.levels[level].w; // Voxels are coarse, so a sharp reflection of them shows their blocks. A smooth surface @@ -188,7 +191,7 @@ fn main(@builtin(global_invocation_id) id: vec3u) { let hit_point = world + direction * hit.t; let found = select(miss_radiance(hit, direction, sky), hit.radiance, hit.hit); let far = mix(sky, found, volume_edge_fade(hit_point) * volume_edge_fade(world)); - radiance = mix(far, radiance, screen.weight); + radiance = mix(far, radiance, screen_weight); } // Fireflies would otherwise persist through the temporal filter. At night the limit stays @@ -204,9 +207,13 @@ fn main(@builtin(global_invocation_id) id: vec3u) { let motion = textureLoad(motion_tex, vec2i(pixel), 0).xy; let previous_uv = center * frame.inv_viewport + motion; var history = vec4f(0.0); - let remembered = all(previous_uv > vec2f(0.0)) && all(previous_uv < vec2f(1.0)) && frame.frame_index > 0u; + var remembered = all(previous_uv > vec2f(0.0)) && all(previous_uv < vec2f(1.0)) && frame.frame_index > 0u; if remembered { history = textureSampleLevel(reflection_history, clamp_sampler, previous_uv, 0.0); + if !finite4(history) { + history = vec4f(0.0); + remembered = false; + } } { // A rough surface's rays scatter, and one in many finds something far brighter than the @@ -219,7 +226,7 @@ fn main(@builtin(global_invocation_id) id: vec3u) { // What the screen shows is exact. The volume is coarse, with gaps where walls are // thin, so what comes from it or from the sky beyond is trusted as a rough // surface's rays are, however smooth this one is. - let smooth_reach = mix(ROUGH_REACH, SMOOTH_REACH, screen.weight); + let smooth_reach = mix(ROUGH_REACH, SMOOTH_REACH, screen_weight); let reach = mix(smooth_reach, ROUGH_REACH, smoothstep(0.08, 0.4, roughness)); let brightest = max(result.x, max(result.y, result.z)); let ambient = luminance(textureLoad(irradiance_tex, vec2i(pixel), 0).rgb) * frame.gi_intensity / PI; diff --git a/crates/solstice-render/shaders/gi/screen_history.wgsl b/crates/solstice-render/shaders/gi/screen_history.wgsl index fbf8a09..1d96951 100644 --- a/crates/solstice-render/shaders/gi/screen_history.wgsl +++ b/crates/solstice-render/shaders/gi/screen_history.wgsl @@ -6,8 +6,17 @@ // Last frame's lit colour at a hit, found through the hit pixel's motion so that it stays // put while the camera moves. -fn screen_hit_radiance(uv: vec2f) -> vec3f { +// Alpha is validity. A missing/invalid history sample must fall back to the volume, +// not seed the radiance probes with black or non-finite light. +fn screen_hit_radiance(uv: vec2f) -> vec4f { let pixel = min(vec2i(uv * frame.viewport), vec2i(frame.viewport) - vec2i(1)); let previous = uv + textureLoad(motion_tex, pixel, 0).xy; - return textureSampleLevel(scene_history, clamp_sampler, clamp(previous, vec2f(0.0), vec2f(1.0)), 0.0).rgb; + if frame.frame_index == 0u || !all(previous >= vec2f(0.0)) || !all(previous <= vec2f(1.0)) { + return vec4f(0.0); + } + let color = textureSampleLevel(scene_history, clamp_sampler, previous, 0.0).rgb; + if !finite3(color) { + return vec4f(0.0); + } + return vec4f(color, 1.0); } diff --git a/crates/solstice-render/shaders/post/taa.wgsl b/crates/solstice-render/shaders/post/taa.wgsl index 9dd2880..2fe7b12 100644 --- a/crates/solstice-render/shaders/post/taa.wgsl +++ b/crates/solstice-render/shaders/post/taa.wgsl @@ -44,7 +44,7 @@ fn from_ycocg(c: vec3f) -> vec3f { // Five-tap Catmull-Rom: nearly bicubic history sampling, which is the main thing keeping // reprojection from blurring the image over time. -fn sample_history(uv: vec2f) -> vec3f { +fn sample_history(uv: vec2f, fallback: vec3f) -> vec3f { let size = vec2f(textureDimensions(history)); let position = uv * size; let center = floor(position - vec2f(0.5)) + vec2f(0.5); @@ -70,8 +70,14 @@ fn sample_history(uv: vec2f) -> vec3f { var total = 0.0; for (var i = 0; i < 5; i++) { let tap = taps[i]; - sum += textureSampleLevel(history, linear_sampler, tap.xy, 0.0).rgb * tap.z; - total += tap.z; + let color = textureSampleLevel(history, linear_sampler, tap.xy, 0.0).rgb; + if finite3(color) { + sum += color * tap.z; + total += tap.z; + } + } + if total <= 1.0e-4 || !finite3(sum) { + return fallback; } return sum / max(total, 1.0e-4); } @@ -93,6 +99,7 @@ fn main(@builtin(global_invocation_id) id: vec3u) { // foreground's motion, and the variance, which bounds what history is believable. var mean = vec3f(0.0); var second_moment = vec3f(0.0); + var sample_count = 0.0; var filtered = vec3f(0.0); var filter_total = 0.0; var closest_depth = 0.0; @@ -104,10 +111,20 @@ fn main(@builtin(global_invocation_id) id: vec3u) { for (var dy = -1; dy <= 1; dy++) { for (var dx = -1; dx <= 1; dx++) { let p = clamp(nearest + vec2i(dx, dy), vec2i(0), scene_size - vec2i(1)); - let color = compress(textureLoad(scene, p, 0).rgb); + let depth = textureLoad(depth_tex, p, 0).r; + if depth > closest_depth { + closest_depth = depth; + closest_pixel = p; + } + let sample = textureLoad(scene, p, 0).rgb; + if !finite3(sample) { + continue; + } + let color = compress(max(sample, vec3f(0.0))); let ycocg = to_ycocg(color); mean += ycocg; second_moment += ycocg * ycocg; + sample_count += 1.0; // A Gaussian centred on this output pixel, using where the sample really landed. let sample_position = vec2f(p) + vec2f(0.5) + jitter_pixels; @@ -116,15 +133,10 @@ fn main(@builtin(global_invocation_id) id: vec3u) { filtered += color * weight; filter_total += weight; - let depth = textureLoad(depth_tex, p, 0).r; - if depth > closest_depth { - closest_depth = depth; - closest_pixel = p; - } } } - mean /= 9.0; - second_moment /= 9.0; + mean /= max(sample_count, 1.0); + second_moment /= max(sample_count, 1.0); let deviation = sqrt(max(second_moment - mean * mean, vec3f(0.0))); let current = filtered / max(filter_total, 1.0e-4); @@ -143,7 +155,13 @@ fn main(@builtin(global_invocation_id) id: vec3u) { var result = current; let on_screen = all(previous_uv > vec2f(0.0)) && all(previous_uv < vec2f(1.0)); if on_screen && frame.frame_index > 0u && frame.temporal_accumulation != 0u { - let previous = compress(max(sample_history(previous_uv), vec3f(0.0))); + let history_color = max(sample_history(previous_uv, decompress(current)), vec3f(0.0)); + // If the whole neighbourhood is invalid, keep valid history until lighting recovers. + if sample_count == 0.0 { + textureStore(output, id.xy, vec4f(min(history_color, vec3f(65504.0)), 1.0)); + return; + } + let previous = compress(history_color); // Clip history against the current neighbourhood's colour distribution: anything far // outside it is a disocclusion or lighting change, not a useful earlier sample. @@ -164,5 +182,5 @@ fn main(@builtin(global_invocation_id) id: vec3u) { let blend = max(clamp(0.06 * render_ratio + moved * 0.012, 0.04, 0.3), reactive * REACTIVE_BLEND); result = mix(from_ycocg(clipped), current, blend); } - textureStore(output, id.xy, vec4f(decompress(max(result, vec3f(0.0))), 1.0)); + textureStore(output, id.xy, vec4f(min(decompress(max(result, vec3f(0.0))), vec3f(65504.0)), 1.0)); } diff --git a/crates/solstice-render/shaders/vg/cull.wgsl b/crates/solstice-render/shaders/vg/cull.wgsl index 24a53a4..dadc255 100644 --- a/crates/solstice-render/shaders/vg/cull.wgsl +++ b/crates/solstice-render/shaders/vg/cull.wgsl @@ -392,15 +392,18 @@ fn view_draws(instance: Instance) -> bool { // Queues the hierarchy root of every instance the view draws. @compute @workgroup_size(64) -fn seed(@builtin(global_invocation_id) id: vec3u) { - if id.x < arrayLength(&instances) && view_draws(instances[id.x]) { - push_queue(QueueEntry(id.x, instances[id.x].root_node)); +fn seed(@builtin(global_invocation_id) id: vec3u, @builtin(num_workgroups) groups: vec3u) { + let index = id.x + id.y * groups.x * 64u; + if index < arrayLength(&instances) && view_draws(instances[index]) { + push_queue(QueueEntry(index, instances[index].root_node)); } } @compute @workgroup_size(32) -fn process(@builtin(global_invocation_id) id: vec3u) { - let slot = state.read_begin + id.x; +fn process(@builtin(global_invocation_id) id: vec3u, @builtin(num_workgroups) groups: vec3u) { + // A level can contain more than 65535 workgroups. Continue in Y without dropping + // entries or increasing the local workgroup size (which hurts smaller levels). + let slot = state.read_begin + id.x + id.y * groups.x * 32u; if slot >= state.read_end || slot >= arrayLength(&queue) { return; } diff --git a/crates/solstice-render/shaders/vg/cull_control.wgsl b/crates/solstice-render/shaders/vg/cull_control.wgsl index 65dded3..10bc442 100644 --- a/crates/solstice-render/shaders/vg/cull_control.wgsl +++ b/crates/solstice-render/shaders/vg/cull_control.wgsl @@ -64,8 +64,10 @@ fn groups_for(count: u32, size: u32) -> u32 { fn advance() { state.read_begin = state.read_end; state.read_end = atomicLoad(&state.write_head); - args.queue_x = groups_for(state.read_end - state.read_begin, PROCESS_GROUP_SIZE); - args.queue_y = 1u; + let groups = groups_for(state.read_end - state.read_begin, PROCESS_GROUP_SIZE); + args.queue_y = max(groups_for(groups, MAX_GROUPS), 1u); + // Balance rows so crossing the X limit does not launch a nearly empty second row. + args.queue_x = groups_for(groups, args.queue_y); args.queue_z = 1u; } diff --git a/crates/solstice-render/shaders/vg/resolve.wgsl b/crates/solstice-render/shaders/vg/resolve.wgsl index 92c2e46..56b28f8 100644 --- a/crates/solstice-render/shaders/vg/resolve.wgsl +++ b/crates/solstice-render/shaders/vg/resolve.wgsl @@ -102,19 +102,20 @@ fn sample_material(tier: u32, uv: vec2f, layer: i32, dx: vec2f, dy: vec2f) -> ve // Perspective-correct barycentrics of a pixel inside a triangle. fn barycentrics(clip: array, ndc: vec2f) -> vec3f { - let inv_w = vec3f(1.0 / clip[0].w, 1.0 / clip[1].w, 1.0 / clip[2].w); - let p0 = clip[0].xy * inv_w.x; - let p1 = clip[1].xy * inv_w.y; - let p2 = clip[2].xy * inv_w.z; - let e0 = p1 - p0; - let e1 = p2 - p0; - let d = ndc - p0; - let inv_det = 1.0 / (e0.x * e1.y - e0.y * e1.x); - let screen_b = (d.x * e1.y - d.y * e1.x) * inv_det; - let screen_c = (e0.x * d.y - e0.y * d.x) * inv_det; - let screen = vec3f(1.0 - screen_b - screen_c, screen_b, screen_c); - let weighted = screen * inv_w; - return weighted / (weighted.x + weighted.y + weighted.z); + // Solve in homogeneous coordinates. Dividing each vertex by w first produces + // NaNs when a triangle crosses the eye plane with a vertex exactly on it. + let x = vec3f(clip[0].x, clip[1].x, clip[2].x) - ndc.x * vec3f(clip[0].w, clip[1].w, clip[2].w); + let y = vec3f(clip[0].y, clip[1].y, clip[2].y) - ndc.y * vec3f(clip[0].w, clip[1].w, clip[2].w); + let weighted = cross(x, y); + let total = weighted.x + weighted.y + weighted.z; + if abs(total) > 1.0e-30 { + let b = weighted / total; + if finite3(b) { + return b; + } + } + // Degenerate projection (including an extrapolated derivative at infinity). + return vec3f(1.0, 0.0, 0.0); } fn interp2(b: vec3f, a0: vec2f, a1: vec2f, a2: vec2f) -> vec2f { diff --git a/crates/solstice-render/src/motion.rs b/crates/solstice-render/src/motion.rs index 0d66e5e..b99d67c 100644 --- a/crates/solstice-render/src/motion.rs +++ b/crates/solstice-render/src/motion.rs @@ -29,9 +29,10 @@ pub struct InstanceTable { gpu_index: Vec>, /// Each instance's object-space bounding sphere, by position in `data`. spheres: Vec<(Vec3, f32)>, - /// New transforms for the next frame, by position in `data`, in the order they were set, - /// and whether each is a jump rather than a motion. + /// One pending transform per changed instance, and whether it is a jump rather than a motion. moves: Vec<(u32, Mat4, bool)>, + /// Each instance's entry in `moves`, or `u32::MAX` when it has no pending move. + pending_move: Vec, /// What moved last frame, whose previous transform must catch up this frame. moved_last_frame: Vec, /// What has changed in other ways since the last upload. @@ -68,6 +69,7 @@ impl InstanceTable { .filter(|&i| data[i as usize].has_flag(INSTANCE_MOVABLE)) .collect(); Self { + pending_move: vec![u32::MAX; data.len()], data, gpu_index, spheres, @@ -105,7 +107,13 @@ impl InstanceTable { return false; }; self.make_movable(i, true); - self.moves.push((i as u32, world, jump)); + let slot = self.pending_move[i]; + if slot == u32::MAX { + self.pending_move[i] = self.moves.len() as u32; + self.moves.push((i as u32, world, jump)); + } else { + self.moves[slot as usize] = (i as u32, world, jump); + } true } @@ -199,7 +207,7 @@ impl InstanceTable { /// Where an instance will be drawn next frame: its latest move, or where it is. pub fn transform(&self, instance: u32) -> Option { let i = self.index(instance)?; - let pending = self.moves.iter().rev().find(|m| m.0 as usize == i); + let pending = self.moves.get(self.pending_move[i] as usize); Some(pending.map_or_else(|| self.data[i].worlds().0, |m| m.1)) } @@ -232,20 +240,15 @@ impl InstanceTable { /// reports what to upload. pub fn advance(&mut self) -> FrameChanges { let mut touched = std::mem::take(&mut self.changed); - for i in std::mem::take(&mut self.moved_last_frame) { + for i in self.moved_last_frame.drain(..) { self.data[i as usize].settle(); touched.push(i); } - // A stable sort keeps each instance's moves in the order they were made, so the last of - // each run is the one that counts. - let mut moves = std::mem::take(&mut self.moves); - moves.sort_by_key(|m| m.0); - let mut moved = Vec::new(); - for (k, &(i, world, jump)) in moves.iter().enumerate() { - if moves.get(k + 1).is_some_and(|next| next.0 == i) { - continue; - } + // Repeated writes already replaced the pending entry. Instances are independent, so + // applying them needs no sort, and a simulation tick cannot grow duplicate work. + for &(i, world, jump) in &self.moves { + self.pending_move[i as usize] = u32::MAX; let instance = &mut self.data[i as usize]; instance.settle(); instance.set_world(world); @@ -254,16 +257,16 @@ impl InstanceTable { // Already caught up: it shows no motion. instance.settle(); } else { - moved.push(i); + self.moved_last_frame.push(i); } } - self.moved_last_frame = moved; - // Reuse the allocation for the next frame's moves. - moves.clear(); - self.moves = moves; + self.moves.clear(); + let ranges = runs(&mut touched); + touched.clear(); + self.changed = touched; FrameChanges { - ranges: runs(touched), + ranges, shadows_changed: std::mem::take(&mut self.shadows_changed), gi_changed: std::mem::take(&mut self.gi_changed), } @@ -276,11 +279,10 @@ impl InstanceTable { } /// Sorts indices into runs to upload, merging runs separated by small gaps. -fn runs(mut indices: Vec) -> Vec> { +fn runs(indices: &mut [u32]) -> Vec> { indices.sort_unstable(); - indices.dedup(); let mut ranges: Vec> = Vec::new(); - for i in indices.into_iter().map(|i| i as usize) { + for i in indices.iter().map(|&i| i as usize) { match ranges.last_mut() { Some(last) if i <= last.end + MERGE_GAP => last.end = i + 1, _ => ranges.push(i..i + 1), @@ -358,6 +360,68 @@ mod tests { assert_eq!(worlds(&table, 2).0, Vec3::X * 7.0); } + #[test] + fn many_interleaved_moves_match_a_frame_by_frame_reference() { + const COUNT: usize = 513; + let mut table = InstanceTable::new( + (0..COUNT).map(|i| instance_at(i as f32)).collect(), + (0..COUNT as u32).map(Some).collect(), + vec![(Vec3::ZERO, 1.0); COUNT], + ); + let mut current: Vec = (0..COUNT).map(|i| at(i as f32)).collect(); + let mut previous = current.clone(); + let mut pending = vec![None; COUNT]; + let mut random = 0x1234_5678u32; + for frame in 0..160 { + // Empty frames, sparse updates and several updates per instance, interleaved. + let changes = match frame % 4 { + 0 => 0, + 1 => 11, + _ => COUNT * 8, + }; + for n in 0..changes { + random = random.wrapping_mul(1664525).wrapping_add(1013904223); + let i = random as usize % COUNT; + let world = Mat4::from_scale_rotation_translation( + Vec3::new(1.0, 2.0, 0.5), + glam::Quat::from_rotation_y(n as f32 * 0.01), + Vec3::new(i as f32, frame as f32, n as f32), + ); + let jump = n % 3 == 0; + table.set_transform(i as u32, world, jump); + pending[i] = Some((world, jump)); + assert_eq!(table.transform(i as u32), Some(world)); + } + let old_previous = previous.clone(); + let old_current = current.clone(); + for i in 0..COUNT { + previous[i] = current[i]; + if let Some((world, jump)) = pending[i].take() { + current[i] = world; + if jump { + previous[i] = world; + } + } + } + let changes = table.advance(); + for i in 0..COUNT { + let (now, before) = table.data[i].worlds(); + assert_eq!( + (now, before), + (current[i], previous[i]), + "frame {frame}, instance {i}" + ); + assert_eq!(table.transform(i as u32), Some(current[i])); + if old_current[i] != current[i] || old_previous[i] != previous[i] { + assert!( + changes.ranges.iter().any(|range| range.contains(&i)), + "changed instance {i} was not uploaded at frame {frame}" + ); + } + } + } + } + #[test] fn instances_without_geometry_or_out_of_range_are_refused() { let mut table = table(); @@ -491,10 +555,10 @@ mod tests { #[test] fn nearby_changes_upload_together_and_distant_ones_apart() { - assert_eq!(runs(vec![4, 1, 2, 2]), vec![1..5]); - assert_eq!(runs(vec![0, 20]), vec![0..1, 20..21]); - assert_eq!(runs(vec![0, 9]), vec![0..10]); - assert_eq!(runs(vec![0, 10]), vec![0..1, 10..11]); + assert_eq!(runs(&mut [4, 1, 2, 2]), vec![1..5]); + assert_eq!(runs(&mut [0, 20]), vec![0..1, 20..21]); + assert_eq!(runs(&mut [0, 9]), vec![0..10]); + assert_eq!(runs(&mut [0, 10]), vec![0..1, 10..11]); } #[test] diff --git a/crates/solstice-render/src/post.rs b/crates/solstice-render/src/post.rs index 3acd6d3..45b9f72 100644 --- a/crates/solstice-render/src/post.rs +++ b/crates/solstice-render/src/post.rs @@ -6,6 +6,10 @@ use bytemuck::{Pod, Zeroable}; use glam::Vec2; const FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rgba16Float; + +#[cfg(test)] +#[path = "post_stress.rs"] +mod stress; /// Matches `BLOOM_LEVELS` in `post/tonemap.wgsl`. const BLOOM_LEVELS: u32 = 6; diff --git a/crates/solstice-render/src/post_stress.rs b/crates/solstice-render/src/post_stress.rs new file mode 100644 index 0000000..a63b1a0 --- /dev/null +++ b/crates/solstice-render/src/post_stress.rs @@ -0,0 +1,327 @@ +use super::*; +use crate::frame::FrameUniform; +use glam::Mat4; + +#[test] +fn diffuse_history_rejects_invalid_samples_instead_of_spreading_them() { + let Some(gpu) = gpu() else { return }; + const SIZE: u32 = 32; + let make = |name, format| { + Target::new( + &gpu, + name, + (SIZE, SIZE), + format, + wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::COPY_SRC, + ) + }; + let normal = make("GI stress normal", FORMAT); + let depth = make("GI stress depth", wgpu::TextureFormat::R32Float); + let motion = make("GI stress motion", wgpu::TextureFormat::Rg32Float); + let out_depth = make("GI stress output depth", wgpu::TextureFormat::R32Float); + let history = [ + make("GI stress history 0", FORMAT), + make("GI stress history 1", FORMAT), + ]; + let layout = LayoutBuilder::new() + .texture() + .texture_unfilterable() + .texture_unfilterable() + .texture() + .storage_read() + .storage_texture(FORMAT) + .texture_unfilterable() + .storage_texture(wgpu::TextureFormat::R32Float) + .build(&gpu, "GI stress"); + let frame_layout = LayoutBuilder::new() + .uniform() + .build(&gpu, "GI stress frame"); + let module = shaders::module(&gpu.device, "gi/probe_integrate.wgsl"); + let pipeline = gpu.compute_pipeline("GI stress", &module, "main", &[&layout, &frame_layout]); + let frame_buffer = gpu.uniform_buffer( + "GI stress frame", + std::mem::size_of::() as u64, + ); + let frame_group = gpu.bind_group( + "GI stress frame", + &frame_layout, + &[frame_buffer.as_entire_binding()], + ); + let probes = gpu.storage_buffer_init("GI stress probes", &[0.0f32; 4 * 44]); + let groups: Vec<_> = (0..2) + .map(|p| { + gpu.bind_group( + "GI stress", + &layout, + &[ + wgpu::BindingResource::TextureView(&normal.view), + wgpu::BindingResource::TextureView(&depth.view), + wgpu::BindingResource::TextureView(&motion.view), + wgpu::BindingResource::TextureView(&history[1 - p].view), + probes.as_entire_binding(), + wgpu::BindingResource::TextureView(&history[p].view), + wgpu::BindingResource::TextureView(&depth.view), + wgpu::BindingResource::TextureView(&out_depth.view), + ], + ) + }) + .collect(); + write( + &gpu, + &depth, + bytemuck::cast_slice(&vec![1.0f32; (SIZE * SIZE) as usize]), + 4, + SIZE, + ); + let white = vec![0x3c00u16; (SIZE * SIZE * 4) as usize]; + let mut frame = FrameUniform::zeroed(); + frame.viewport = Vec2::splat(SIZE as f32); + frame.inv_viewport = frame.viewport.recip(); + frame.inv_view_proj = Mat4::IDENTITY; + frame.prev_view_proj = Mat4::IDENTITY; + frame.near = 1.0; + frame.frame_seconds = 1.0 / 60.0; + let mut failures = Vec::new(); + for bad in [0x7e00u16, 0x7c00, 0xfc00] { + for target in &history { + write(&gpu, target, bytemuck::cast_slice(&white), 8, SIZE); + } + let mut damaged = white.clone(); + damaged[((SIZE / 2 * SIZE + SIZE / 2) * 4) as usize] = bad; + write(&gpu, &history[1], bytemuck::cast_slice(&damaged), 8, SIZE); + let mut counts = Vec::new(); + for tick in 0..12 { + frame.frame_index = tick + 1; + gpu.queue + .write_buffer(&frame_buffer, 0, bytemuck::bytes_of(&frame)); + let mut encoder = gpu.device.create_command_encoder(&Default::default()); + { + let mut pass = encoder.begin_compute_pass(&Default::default()); + pass.set_pipeline(&pipeline); + pass.set_bind_group(0, &groups[tick as usize % 2], &[]); + pass.set_bind_group(1, &frame_group, &[]); + pass.dispatch_workgroups(SIZE.div_ceil(8), SIZE.div_ceil(8), 1); + } + gpu.queue.submit([encoder.finish()]); + let pixels = read(&gpu, &history[tick as usize % 2], SIZE); + counts.push( + pixels + .chunks_exact(4) + .filter(|p| p.iter().any(|v| v & 0x7c00 == 0x7c00)) + .count(), + ); + } + eprintln!("diffuse bad={bad:#x}, invalid pixels: {counts:?}"); + failures.extend(counts); + } + assert!( + failures.iter().all(|&n| n == 0), + "GI history must recover on the first healthy frame" + ); +} + +fn gpu() -> Option { + let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { + backends: wgpu::Backends::PRIMARY, + ..wgpu::InstanceDescriptor::new_without_display_handle() + }); + pollster::block_on(Gpu::request( + &instance, + None, + wgpu::PowerPreference::HighPerformance, + )) + .map_err(|error| eprintln!("skipping GPU stress test: {error}")) + .ok() +} + +fn write(gpu: &Gpu, target: &Target, bytes: &[u8], bytes_per_pixel: u32, size: u32) { + gpu.queue.write_texture( + target.texture.as_image_copy(), + bytes, + wgpu::TexelCopyBufferLayout { + offset: 0, + bytes_per_row: Some(size * bytes_per_pixel), + rows_per_image: Some(size), + }, + wgpu::Extent3d { + width: size, + height: size, + depth_or_array_layers: 1, + }, + ); +} + +fn read(gpu: &Gpu, target: &Target, size: u32) -> Vec { + let row = (size * 8).next_multiple_of(256); + let staging = gpu.device.create_buffer(&wgpu::BufferDescriptor { + label: Some("HDR stress readback"), + size: u64::from(row * size), + usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST, + mapped_at_creation: false, + }); + let mut encoder = gpu.device.create_command_encoder(&Default::default()); + encoder.copy_texture_to_buffer( + target.texture.as_image_copy(), + wgpu::TexelCopyBufferInfo { + buffer: &staging, + layout: wgpu::TexelCopyBufferLayout { + offset: 0, + bytes_per_row: Some(row), + rows_per_image: Some(size), + }, + }, + wgpu::Extent3d { + width: size, + height: size, + depth_or_array_layers: 1, + }, + ); + gpu.queue.submit([encoder.finish()]); + staging + .slice(..) + .map_async(wgpu::MapMode::Read, |r| r.unwrap()); + gpu.device + .poll(wgpu::PollType::wait_indefinitely()) + .unwrap(); + let bytes = staging.slice(..).get_mapped_range().unwrap(); + bytes + .chunks_exact(row as usize) + .flat_map(|line| { + bytemuck::cast_slice::(&line[..size as usize * 8]) + .iter() + .copied() + }) + .collect() +} + +#[test] +fn an_invalid_hdr_pixel_does_not_spread_through_temporal_history() { + let Some(gpu) = gpu() else { return }; + const SIZE: u32 = 32; + let make = |name, format| { + Target::new( + &gpu, + name, + (SIZE, SIZE), + format, + wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::COPY_SRC, + ) + }; + let scene = make("stress scene", FORMAT); + let depth = make("stress depth", wgpu::TextureFormat::R32Float); + let motion = make("stress motion", wgpu::TextureFormat::Rg32Float); + let reactive = make("stress reactive", wgpu::TextureFormat::Rgba16Float); + let history = [ + make("stress history 0", FORMAT), + make("stress history 1", FORMAT), + ]; + let post = PostProcess::new(&gpu, wgpu::TextureFormat::Rgba8Unorm); + let frame_buffer = + gpu.uniform_buffer("stress frame", std::mem::size_of::() as u64); + let groups: Vec<_> = (0..2) + .map(|parity| { + gpu.bind_group( + "stress TAA", + &post.taa_layout, + &[ + frame_buffer.as_entire_binding(), + wgpu::BindingResource::TextureView(&scene.view), + wgpu::BindingResource::TextureView(&depth.view), + wgpu::BindingResource::TextureView(&motion.view), + wgpu::BindingResource::TextureView(&history[1 - parity].view), + wgpu::BindingResource::Sampler(&post.linear_sampler), + wgpu::BindingResource::TextureView(&history[parity].view), + wgpu::BindingResource::TextureView(&reactive.view), + ], + ) + }) + .collect(); + write( + &gpu, + &depth, + bytemuck::cast_slice(&vec![1.0f32; (SIZE * SIZE) as usize]), + 4, + SIZE, + ); + let white = vec![0x3c00u16; (SIZE * SIZE * 4) as usize]; + let mut frame = FrameUniform::zeroed(); + frame.viewport = Vec2::splat(SIZE as f32); + frame.inv_viewport = frame.viewport.recip(); + frame.inv_view_proj = Mat4::IDENTITY; + frame.prev_view_proj = Mat4::IDENTITY; + frame.temporal_accumulation = 1; + // Both new lighting and old history can carry a non-finite half-float. Each must recover. + for (bad, in_history, whole_image) in [ + (0x7e00u16, false, false), + (0x7c00, false, false), + (0xfc00, false, false), + (0x7e00, true, false), + (0x7c00, true, false), + (0xfc00, true, false), + (0x7e00, false, true), + (0x7e00, true, true), + ] { + write(&gpu, &scene, bytemuck::cast_slice(&white), 8, SIZE); + for target in &history { + write(&gpu, target, bytemuck::cast_slice(&white), 8, SIZE); + } + let mut damaged = white.clone(); + damaged[((SIZE / 2 * SIZE + SIZE / 2) * 4) as usize] = bad; + if whole_image { + for pixel in damaged.chunks_exact_mut(4) { + pixel[0] = bad; + } + } + write( + &gpu, + if in_history { &history[1] } else { &scene }, + bytemuck::cast_slice(&damaged), + 8, + SIZE, + ); + let mut invalid_per_frame = Vec::new(); + let mut dark_per_frame = Vec::new(); + let mut final_pixels = Vec::new(); + for tick in 0..12 { + frame.frame_index = tick + 1; + gpu.queue + .write_buffer(&frame_buffer, 0, bytemuck::bytes_of(&frame)); + let parity = tick as usize % 2; + let mut encoder = gpu.device.create_command_encoder(&Default::default()); + { + let mut pass = encoder.begin_compute_pass(&Default::default()); + pass.set_pipeline(&post.taa); + pass.set_bind_group(0, &groups[parity], &[]); + pass.dispatch_workgroups(SIZE.div_ceil(8), SIZE.div_ceil(8), 1); + } + gpu.queue.submit([encoder.finish()]); + final_pixels = read(&gpu, &history[parity], SIZE); + invalid_per_frame.push( + final_pixels + .chunks_exact(4) + .filter(|p| p[..3].iter().any(|v| v & 0x7c00 == 0x7c00)) + .count(), + ); + dark_per_frame.push( + final_pixels + .chunks_exact(4) + .filter(|p| p[..3].iter().any(|&v| v < 0x3b00 || v & 0x8000 != 0)) + .count(), + ); + // Only the first frame is damaged; every subsequent lighting input is healthy. + write(&gpu, &scene, bytemuck::cast_slice(&white), 8, SIZE); + } + eprintln!("bad={bad:#x}, in_history={in_history}, whole_image={whole_image}, non-finite: {invalid_per_frame:?}, dark: {dark_per_frame:?}"); + assert!( + invalid_per_frame + .iter() + .chain(&dark_per_frame) + .all(|&n| n == 0), + "an invalid sample must not contaminate the white scene" + ); + assert!( + final_pixels.iter().all(|&v| (0x3bf0..=0x3c10).contains(&v)), + "the white scene must recover without a spreading dark patch" + ); + } +} diff --git a/crates/solstice-render/src/streaming/residency.rs b/crates/solstice-render/src/streaming/residency.rs index 4f4c8d4..f65719e 100644 --- a/crates/solstice-render/src/streaming/residency.rs +++ b/crates/solstice-render/src/streaming/residency.rs @@ -4,7 +4,57 @@ //! it depends on, and only leaves after every page depending on it. A page's dependencies hold //! the parents of its clusters, so a parent is always there to draw until its children are. -use std::collections::BTreeSet; +use std::cmp::Reverse; +use std::collections::{BTreeSet, BinaryHeap}; +use std::ops::Index; + +/// A page graph stored in two contiguous arrays instead of a heap allocation per page. +/// Its topology is fixed when the baked scene opens; frames only read slices of it. +struct PageLinks { + offsets: Vec, + entries: Vec, +} + +impl PageLinks { + fn new(lists: Vec>) -> Self { + let mut offsets = Vec::with_capacity(lists.len() + 1); + let mut entries = Vec::with_capacity(lists.iter().map(Vec::len).sum()); + offsets.push(0); + for list in lists { + entries.extend(list); + offsets.push(entries.len()); + } + Self { offsets, entries } + } + + fn reversed(&self) -> Self { + let mut offsets = vec![0; self.offsets.len()]; + for &page in &self.entries { + offsets[page as usize + 1] += 1; + } + for i in 1..offsets.len() { + offsets[i] += offsets[i - 1]; + } + let mut next = offsets.clone(); + let mut entries = vec![0; self.entries.len()]; + for page in 0..self.offsets.len() - 1 { + for &dependency in &self[page] { + let at = &mut next[dependency as usize]; + entries[*at] = page as u32; + *at += 1; + } + } + Self { offsets, entries } + } +} + +impl Index for PageLinks { + type Output = [u32]; + + fn index(&self, page: usize) -> &Self::Output { + &self.entries[self.offsets[page]..self.offsets[page + 1]] + } +} /// In the request array, a page that was seen but occluded: worth keeping, not worth loading. pub const REQUEST_KEEP: u32 = 1; @@ -95,8 +145,8 @@ pub struct Install { /// Tracks every page's state, and owns the allocation of pool slots. pub struct Residency { - dependencies: Vec>, - dependants: Vec>, + dependencies: PageLinks, + dependants: PageLinks, pinned: u32, states: Vec, /// The installed pages, so that a look over them costs what's installed, not the whole scene. @@ -119,8 +169,9 @@ pub struct Residency { fetching: u32, /// Pages that wanted loading but found no room in the pool at the last plan. starved: u32, - /// What the last plan wanted and could not start yet, most wanted last. - queue: Vec, + /// What the last plan wanted and could not start yet: highest priority, then lowest id. + /// Heap construction is linear; a frame needn't sort a million pages to fetch thirty-two. + queue: BinaryHeap<(u32, Reverse)>, /// Slots the last plan found reclaimable in each band, which is slow to work out. Each /// eviction spends one. reclaimable_at_plan: Vec, @@ -189,13 +240,13 @@ impl Residency { pinned_by_band.iter().zip(band_slots).all(|(p, s)| p <= s), "the pool must hold the pinned pages" ); - let mut dependants = vec![Vec::new(); count]; for (page, list) in dependencies.iter().enumerate() { for &dependency in list { assert!((dependency as usize) < page, "dependencies point coarser"); - dependants[dependency as usize].push(page as u32); } } + let dependencies = PageLinks::new(dependencies); + let dependants = dependencies.reversed(); let mut first = 0; let free_slots = band_slots .iter() @@ -226,7 +277,7 @@ impl Residency { arrived: BTreeSet::new(), fetching: 0, starved: 0, - queue: Vec::new(), + queue: BinaryHeap::new(), reclaimable_at_plan: vec![0; band_slots.len()], victims: vec![Vec::new(); band_slots.len()], victims_frame: None, @@ -407,8 +458,6 @@ impl Residency { _ => {} } } - wanted.sort_by_key(|&page| (std::cmp::Reverse(priority[page as usize]), page)); - self.plans = self.plans.wrapping_add(1).max(1); self.reclaimable_at_plan = self.reclaimable(frame); coming.extend(wanted.iter().map(|&page| priority[page as usize])); @@ -417,8 +466,12 @@ impl Residency { self.victims_frame = None; let room: u32 = self.room().1.iter().sum(); self.starved = (wanted.len() as u32).saturating_sub(room); - wanted.reverse(); - self.queue = wanted; + self.queue = BinaryHeap::from( + wanted + .into_iter() + .map(|page| (priority[page as usize], Reverse(page))) + .collect::>(), + ); self.refill(max_fetching) } @@ -439,7 +492,7 @@ impl Residency { }; let mut started = Vec::new(); while (started.len() as u32) < can_fetch { - let Some(page) = self.queue.pop() else { + let Some((_, Reverse(page))) = self.queue.pop() else { break; }; if self.states[page as usize] != State::Absent { diff --git a/crates/solstice-render/src/vg/culling.rs b/crates/solstice-render/src/vg/culling.rs index b688ba0..e199fac 100644 --- a/crates/solstice-render/src/vg/culling.rs +++ b/crates/solstice-render/src/vg/culling.rs @@ -257,6 +257,10 @@ const STATE_SIZE: u64 = 72; /// Where in `CullState` the opaque lists' end is. A frame's clear stops short of it. const STATE_OPAQUE_END_OFFSET: u64 = 68; +#[cfg(test)] +#[path = "culling_stress.rs"] +mod stress; + /// Which occlusion phase a cull runs. See the module docs of [`crate::vg`]. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum CullPhase { @@ -639,7 +643,9 @@ impl CullPipelines { pass.set_pipeline(&self.seed); pass.set_bind_group(0, scene_group, &offset); pass.set_bind_group(1, work_group, &[]); - pass.dispatch_workgroups(groups_for(scene.gpu_instance_count, 64), 1, 1); + let groups = groups_for(scene.gpu_instance_count, 64); + let rows = groups.div_ceil(65_535).max(1); + pass.dispatch_workgroups(groups.div_ceil(rows), rows, 1); } CullPhase::Second => { pass.set_pipeline(&self.begin_second_phase); diff --git a/crates/solstice-render/src/vg/culling_stress.rs b/crates/solstice-render/src/vg/culling_stress.rs new file mode 100644 index 0000000..6bb5b2c --- /dev/null +++ b/crates/solstice-render/src/vg/culling_stress.rs @@ -0,0 +1,172 @@ +//! Exercises the real traversal and control shaders beyond one dispatch dimension. +use super::*; +use crate::scene::GpuInstance; +use solstice_asset::{PackedCluster, PackedNode}; + +fn read_words(gpu: &Gpu, buffer: &wgpu::Buffer, bytes: u64) -> Vec { + let staging = gpu.device.create_buffer(&wgpu::BufferDescriptor { + label: Some("cull stress readback"), + size: bytes, + usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ, + mapped_at_creation: false, + }); + let mut encoder = gpu.device.create_command_encoder(&Default::default()); + encoder.copy_buffer_to_buffer(buffer, 0, &staging, 0, bytes); + gpu.queue.submit([encoder.finish()]); + staging + .slice(..) + .map_async(wgpu::MapMode::Read, |r| r.unwrap()); + gpu.device + .poll(wgpu::PollType::wait_indefinitely()) + .unwrap(); + bytemuck::cast_slice(&staging.slice(..).get_mapped_range().unwrap()).to_vec() +} + +#[test] +fn traversal_visits_every_entry_beyond_one_dispatch_dimension() { + let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { + backends: wgpu::Backends::PRIMARY, + ..wgpu::InstanceDescriptor::new_without_display_handle() + }); + let gpu = match pollster::block_on(Gpu::request( + &instance, + None, + wgpu::PowerPreference::HighPerformance, + )) { + Ok(gpu) => gpu, + Err(error) => { + eprintln!("skipping GPU stress test: {error}"); + return; + } + }; + eprintln!("cull stress adapter: {:?}", gpu.adapter_info); + let pipelines = CullPipelines::new(&gpu, shaders::Deform::default(), None); + let state = gpu.storage_buffer( + "stress state", + STATE_SIZE, + wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::COPY_SRC, + ); + let args = gpu.storage_buffer( + "stress args", + ARGS_SIZE, + wgpu::BufferUsages::INDIRECT | wgpu::BufferUsages::COPY_SRC, + ); + let control = gpu.bind_group( + "stress control", + &pipelines.control_layout, + &[state.as_entire_binding(), args.as_entire_binding()], + ); + + let slots = ViewSlots::new(&gpu, 1); + slots.write( + &gpu, + 0, + &PassView::orthographic(Mat4::IDENTITY, Vec3::ZERO, Vec2::splat(16.0), 1.0, 1.0), + ); + let mut placed = GpuInstance::zeroed(); + placed.set_world(Mat4::IDENTITY); + placed.set_bones(crate::skin::NO_BONES); + let instances = gpu.storage_buffer_init("stress instance", &[placed]); + // Each input appends exactly one entry. No rasterization or giant scene is needed to + // prove that the actual process shader visits the entire input, including its tail. + let nodes = gpu.storage_buffer_init( + "stress node", + &[PackedNode { + radius: 1.0, + max_parent_error: solstice_asset::gpu::ROOT_PARENT_ERROR, + count: 1, + ..Default::default() + }], + ); + let clusters = gpu.storage_buffer_init("stress cluster", &[PackedCluster::zeroed()]); + let texture = |format| { + gpu.device + .create_texture(&wgpu::TextureDescriptor { + label: Some("stress placeholder"), + size: wgpu::Extent3d { + width: 1, + height: 1, + depth_or_array_layers: 1, + }, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format, + usage: wgpu::TextureUsages::TEXTURE_BINDING, + view_formats: &[], + }) + .create_view(&Default::default()) + }; + let float_view = texture(wgpu::TextureFormat::Rgba32Float); + let uint_view = texture(wgpu::TextureFormat::Rgba32Uint); + let scene = gpu.bind_group( + "stress scene", + &pipelines.scene_layout, + &[ + slots.binding(), + instances.as_entire_binding(), + nodes.as_entire_binding(), + clusters.as_entire_binding(), + wgpu::BindingResource::TextureView(&float_view), + wgpu::BindingResource::TextureView(&float_view), + wgpu::BindingResource::TextureView(&uint_view), + ], + ); + let queue = gpu.storage_buffer( + "stress queue", + ((1 << 22) * 2 + 64) * 8, + wgpu::BufferUsages::empty(), + ); + let scratch = gpu.storage_buffer("stress scratch", 16, wgpu::BufferUsages::empty()); + // Separate buffers avoid writable binding aliasing. + let visible = gpu.storage_buffer("stress visible", 16, wgpu::BufferUsages::empty()); + let requests = gpu.storage_buffer("stress requests", 16, wgpu::BufferUsages::empty()); + let work = gpu.bind_group( + "stress work", + &pipelines.work_layout, + &[ + state.as_entire_binding(), + queue.as_entire_binding(), + scratch.as_entire_binding(), + visible.as_entire_binding(), + requests.as_entire_binding(), + ], + ); + for count in [0, 1, 31, 32, 33, 65_535 * 32, 65_535 * 32 + 1, 1 << 22] { + for begin in [0, 37] { + let mut words = [0u32; STATE_SIZE as usize / 4]; + words[1] = begin; + words[2] = begin + count; + gpu.queue + .write_buffer(&state, 0, bytemuck::cast_slice(&words)); + let mut encoder = gpu.device.create_command_encoder(&Default::default()); + { + let mut pass = encoder.begin_compute_pass(&Default::default()); + pass.set_pipeline(&pipelines.advance); + pass.set_bind_group(0, &control, &[]); + pass.dispatch_workgroups(1, 1, 1); + } + gpu.queue.submit([encoder.finish()]); + let dispatch = read_words(&gpu, &args, 12); + assert!( + dispatch.iter().all(|&n| n <= 65_535), + "{count} queued entries produced an invalid WebGPU dispatch: {dispatch:?}" + ); + let needed = count.div_ceil(32); + assert!(dispatch[0] * dispatch[1] >= needed); + assert!(dispatch[0] * dispatch[1] < needed + dispatch[1]); + let mut encoder = gpu.device.create_command_encoder(&Default::default()); + { + let mut pass = encoder.begin_compute_pass(&Default::default()); + pass.set_pipeline(&pipelines.process); + pass.set_bind_group(0, &scene, &[0]); + pass.set_bind_group(1, &work, &[]); + pass.dispatch_workgroups_indirect(&args, 0); + } + gpu.queue.submit([encoder.finish()]); + let result = read_words(&gpu, &state, STATE_SIZE); + assert_eq!(result[2], begin + count * 2, "count={count}, begin={begin}"); + assert_eq!(result[9], 0, "no entry should be dropped"); + } + } +} diff --git a/crates/solstice-render/src/vg/resolve.rs b/crates/solstice-render/src/vg/resolve.rs index b8db02e..a052024 100644 --- a/crates/solstice-render/src/vg/resolve.rs +++ b/crates/solstice-render/src/vg/resolve.rs @@ -1,6 +1,9 @@ //! Converts the visibility buffer into a G-buffer. use super::culling::CullWork; +#[cfg(test)] +#[path = "resolve_stress.rs"] +mod stress; use super::raster::VisibilityBuffer; use crate::gpu::{groups_for, Gpu, LayoutBuilder, Target}; use crate::regions::RegionPlan; diff --git a/crates/solstice-render/src/vg/resolve_stress.rs b/crates/solstice-render/src/vg/resolve_stress.rs new file mode 100644 index 0000000..6e3a391 --- /dev/null +++ b/crates/solstice-render/src/vg/resolve_stress.rs @@ -0,0 +1,107 @@ +//! Exercise the production interpolation on triangles crossing the eye plane. +use crate::gpu::{Gpu, LayoutBuilder}; +use glam::{Vec3, Vec4}; + +#[test] +fn barycentrics_stay_finite_when_a_vertex_is_on_the_eye_plane() { + let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { + backends: wgpu::Backends::PRIMARY, + ..wgpu::InstanceDescriptor::new_without_display_handle() + }); + let Ok(gpu) = pollster::block_on(Gpu::request( + &instance, + None, + wgpu::PowerPreference::HighPerformance, + )) else { + eprintln!("skipping interpolation test: no GPU"); + return; + }; + // Compile the exact function used by the G-buffer resolve, not a reimplementation. + let source = include_str!("../../shaders/vg/resolve.wgsl"); + let start = source.find("fn barycentrics(").unwrap(); + let end = start + source[start..].find("\n}").unwrap() + 2; + let source = format!( + "{}\n{}\n{}", + include_str!("../../shaders/common/math.wgsl"), + &source[start..end], + r#" +struct Case { clip: array, ndc: vec4f }; +@group(0) @binding(0) var cases: array; +@group(0) @binding(1) var results: array; +@compute @workgroup_size(1) +fn main(@builtin(global_invocation_id) id: vec3u) { + results[id.x] = vec4f(barycentrics(cases[id.x].clip, cases[id.x].ndc.xy), 1.0); +} +"# + ); + let module = gpu + .device + .create_shader_module(wgpu::ShaderModuleDescriptor { + label: Some("production barycentrics stress"), + source: wgpu::ShaderSource::Wgsl(source.into()), + }); + let layout = LayoutBuilder::new() + .storage_read() + .storage_write() + .build(&gpu, "barycentric stress"); + let pipeline = gpu.compute_pipeline("barycentric stress", &module, "main", &[&layout]); + let mut data = Vec::::new(); + let mut expected = Vec::new(); + for w in [1.0, 0.0, -0.25, 1.0e-20, 10.0] { + let clip = [ + Vec4::new(-1.0, -1.0, 0.1, w), + Vec4::new(1.0, -1.0, 0.1, 2.0), + Vec4::new(0.0, 1.0, 0.1, 1.0), + ]; + for b in [ + Vec3::new(0.2, 0.3, 0.5), + Vec3::new(0.01, 0.01, 0.98), + Vec3::new(-0.01, 0.5, 0.51), + ] { + let p = clip[0] * b.x + clip[1] * b.y + clip[2] * b.z; + data.extend(clip); + data.push(p / p.w); + expected.push(b); + } + } + // A zero-area triangle cannot supply interpolation, but must not poison later lighting. + data.extend([Vec4::ONE; 4]); + expected.push(Vec3::X); + let input = gpu.storage_buffer_init("barycentric cases", &data); + let size = expected.len() as u64 * 16; + let output = gpu.storage_buffer("barycentric results", size, wgpu::BufferUsages::COPY_SRC); + let group = gpu.bind_group( + "barycentric stress", + &layout, + &[input.as_entire_binding(), output.as_entire_binding()], + ); + let staging = gpu.device.create_buffer(&wgpu::BufferDescriptor { + label: None, + size, + usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::MAP_READ, + mapped_at_creation: false, + }); + let mut encoder = gpu.device.create_command_encoder(&Default::default()); + { + let mut pass = encoder.begin_compute_pass(&Default::default()); + pass.set_pipeline(&pipeline); + pass.set_bind_group(0, &group, &[]); + pass.dispatch_workgroups(expected.len() as u32, 1, 1); + } + encoder.copy_buffer_to_buffer(&output, 0, &staging, 0, size); + gpu.queue.submit([encoder.finish()]); + staging + .slice(..) + .map_async(wgpu::MapMode::Read, |r| r.unwrap()); + gpu.device + .poll(wgpu::PollType::wait_indefinitely()) + .unwrap(); + let mapping = staging.slice(..).get_mapped_range().unwrap(); + let results: &[Vec4] = bytemuck::cast_slice(&mapping); + for (i, (result, wanted)) in results.iter().zip(expected).enumerate() { + assert!( + result.is_finite() && (result.truncate() - wanted).abs().max_element() < 2.0e-5, + "case {i}: expected {wanted}, got {result}" + ); + } +} diff --git a/docs/performance-audit.md b/docs/performance-audit.md new file mode 100644 index 0000000..63f72be --- /dev/null +++ b/docs/performance-audit.md @@ -0,0 +1,207 @@ +# Performance and temporal-history audit + +Local audit of `765343c`, 13 November 2026. Windows, Rust 1.95.0, release profile, +AMD Ryzen 7 9800X3D, NVIDIA GeForce RTX 5080, Vulkan, driver 616.64. Measurements below compare the +original sources against the changes in this checkout. They are component +benchmarks, not claims about a game's overall FPS. + +## Spreading black surfaces + +The production diffuse-GI temporal shader reproduces the reported spreading +behaviour without a large scene. Injecting one NaN, positive infinity, or negative +infinity into its history, then supplying healthy inputs for twelve frames, +produces these counts of invalid pixels: + +| Frame | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | +| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | +| Original | 4 | 9 | 16 | 25 | 36 | 49 | 64 | 81 | 100 | 121 | 144 | 169 | +| Fixed | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | + +Each frame's four-tap history gather was blending invalid values into neighbouring +pixels, then storing them for the next frame. Turning the camera away rejects +history, consistent with the user's observation that rotating clears the black +area. This proves a propagation mechanism in the library; it does not prove which +input first became invalid in the user's running street scene. + +A second production-shader test identifies a concrete source of invalid values: +the visibility resolve divided each triangle vertex by its clip-space `w`. A +visible triangle can cross the eye plane with one vertex at `w = 0`. The old +function returned three NaNs for a case whose correct interpolation weights are +`(0.2, 0.3, 0.5)`. The replacement solves the same perspective interpolation in +homogeneous coordinates, avoiding those per-vertex divisions. Degenerate +projections have a finite fallback. Tests cover positive, zero, negative, and very +small vertex `w`, extrapolated samples used for derivatives, and zero-area input. + +The fix also rejects invalid samples before the diffuse and reflection history +filters, probe projection, and TAA. Invalid screen-space lighting falls back to +volume tracing. A standalone TAA test showed one bad current pixel making a 3x3 +black patch in the original shader. The fixed shader excludes that sample and +normalizes the remaining valid weights. It can also recover from damaged history. +Finite-value checks inspect exponent bits, rather than relying on `x == x` under +shader floating-point optimizations. TAA output is bounded to the representable +half-float maximum to avoid creating infinity at its storage boundary. + +No GI, reflection, anti-aliasing, resolution, ray count, or LOD quality setting is +reduced. The running application must be rebuilt with these shaders; existing +scene bakes do not need changing for this fix. + +## Avoidable per-frame CPU work + +The movement table searched pending moves backwards every time a caller read an +instance transform. Reading and then moving every object therefore became +quadratic. Repeated moves also accumulated duplicate records that were sorted at +the end of the frame. A per-instance pending index now provides direct lookup and +replaces a previous update in place. Frame upload ranges still merge nearby +changes, with last-update-wins and previous-frame transforms preserved. + +Streaming sorted all requested pages even when a frame would fetch only a small +number. A linear-time heap build and bounded extraction preserve the exact +priority and page-ID tie ordering. Immutable dependency and dependant lists use +contiguous offsets and entries, rather than a `Vec` header per page per direction. + +`cpu_stress` performs one warm-up and reports the median of six measured rounds: + +| Workload | Original median, ms | Fixed median, ms | +| --- | ---: | ---: | +| Read/move 1,024 objects | 0.2166 | 0.0048 | +| Read/move 8,192 objects | 17.1014 | 0.0394 | +| Read/move 32,768 objects | 308.5094 | 0.1608 | +| Finish frame, 32,768 moves | 1.5900 | 0.9312 | +| Eight updates/object, 32,768 objects | 6.1798 | 1.1508 | +| Plan requests, 4,096 pages | 0.0165 | 0.0063 | +| Plan requests, 65,536 pages | 0.3733 | 0.1177 | +| Plan requests, 1,048,576 pages | 8.9409 | 2.8114 | + +All movement/upload checksums and fetch-order checksums match the original. +The compressed graph removes about 32 bytes of list headers per page on a 64-bit +host, or 16 bytes on wasm32, before allocator overhead. Those are layout savings, +not measured reductions in total application memory; the priority heap uses a +larger entry than the former page-ID queue. The graph is prepared once at scene +load, not rebuilt each frame. + +A deterministic streaming soak runs 1,500 frames for each of a single pool and +three LOD pools, with 16,384 pages, dependencies, delayed arrivals, failed fetches, +changing views, protected pages, and eviction. The original and changed code +produce identical trace hashes: + +| Pool arrangement | Fetches | Installs | Evictions | Trace hash | +| --- | ---: | ---: | ---: | ---: | +| Single pool | 955 | 866 | 618 | 14859531676831798266 | +| Three pools | 1639 | 1497 | 1249 | 12381328480948452750 | + +## More objects and deep traversal + +Traversal queues allow 4,194,304 entries, but the old 32-thread indirect dispatch +exceeded the guaranteed 65,535-workgroup X limit at 2,097,121 entries. The stress +test reproduced the invalid `[65536, 1, 1]` dispatch. Work now extends into Y and +the shader flattens both dimensions. Instance seeding follows the same rule. + +The GPU regression exercises the actual control and traversal shaders at 0, 1, +31, 32, 33, 2,097,120, 2,097,121, and 4,194,304 entries, including a nonzero queue +start. It checks dispatch legality and complete processing. This removes a limit +below the allocated capacity; it does not make queues or visible-cluster buffers +unbounded. Capacity overflow still needs explicit diagnostics and a considered +fallback before claiming arbitrary scene sizes are supported. + +## Smaller geometry pages without requantization + +Page packing now shares byte-identical cluster vertex payloads and triangle runs +within the same page. It includes all vertex attributes and skinning records in +the comparison. Different normals or UVs cannot accidentally alias. Each incoming +sibling set remains intact, and page order remains spatial and coarse-to-fine. +A metadata-count cap prevents extremely repetitive payloads concentrating an +unbounded cluster table into one page. + +The page capacity remains 128 KiB. This reduces payload and sometimes page count; +it does not reduce each GPU pool slot's fixed capacity. The binary schema and GPU +decode stay compatible. Existing baked files still load; re-bake assets to gain +the packing savings. + +| Fixture | Metric | Original | Fixed | +| --- | --- | ---: | ---: | +| Connected terrain, 73,728 source triangles | Pages | 23 | 23 | +| | Raw geometry bytes | 2,191,488 | 2,190,976 | +| | Deflated geometry bytes | 1,015,543 | 1,015,535 | +| Disconnected foliage, 32,768 source triangles | Pages | 35 | 33 | +| | Raw geometry bytes | 3,402,100 | 3,159,988 | +| | Deflated geometry bytes | 761,959 | 759,240 | +| | All-pages geometry slot capacity, bytes | 4,587,520 | 4,325,376 | + +For this foliage fixture the raw payload is 7.12% smaller and the geometry slot +capacity is 5.71% smaller. Deflated bytes improve only 0.36%, because compression +already handles repetition well. These totals exclude textures, cluster metadata, +and other GPU buffers. Savings depend strongly on the asset. One-shot packing +measurements increased from about 1.01 to 1.21 ms for terrain and 1.03 to 1.14 ms +for foliage; deduplication adds some bake work. The harness compares every packed +vertex and triangle against the original cluster data, byte for byte. + +## What can move into the bake + +The library already bakes cluster bounding spheres, parent LOD errors/bounds, +spatial hierarchies, UV density, and page dependencies. Runtime culling uses those +summaries; it does not rediscover them by scanning all triangles every frame. +It also uses depth-pyramid occlusion and retains occluded pages without demanding +that they be fetched just for that occluded view. + +There are further options, but they require their own quality and performance +validation: + +* Conservative normal cones can reject an entire single-sided static cluster when + all its triangles face away. They need an extent-aware perspective test, and + must be disabled or conservatively expanded for two-sided materials, animation, + wind deformation, and unsuitable transforms. The current bake has no such cone. +* A static scene can bake potentially-visible sets for spatial cells. They must be + conservative and account for movable occluders; their storage and bake cost can + exceed their benefit in open scenes. +* Page-local vertex remapping and a compact three-byte triangle stream may reduce + data further, but they change decode/upload work and need a format/version plan. + Current vertices already occupy 16 bytes, triangle indices fit in three bytes + of a four-byte word, and clusters allow 128 triangles and 255 vertices. +* The planner still scans page-sized arrays each plan. A sparse changed-request + set could reduce that cost further, provided retention, cached-view requests, + and deterministic priority semantics are preserved. + +The current frustum depends on the live camera and cannot simply be baked away. +A page outside that frustum may still cast a visible shadow or supply GI or a +reflection, and a nearby page may be deliberately prefetched before a turn. +An angle-only page blacklist would therefore discard valid contributions. The +existing per-view request logic must remain part of any baked visibility scheme. + +There is also a separate correctness concern in `vg/vis_write.wgsl`: winning depth +and triangle ID are written with separate atomics. A farther writer can win depth, +pause, and store its ID after a nearer writer has won and stored its own ID. The +source already acknowledges this race, but its claim that TAA always hides it is +not a correctness guarantee. This audit did not reproduce or redesign that path. +An exact solution needs ordered phases or a suitable combined atomic scheme; a +per-pixel spinlock is not an appropriate shortcut. The history checks contain +invalid lighting, but do not fix mismatched finite depth/ID values. + +## Additional reproduced failure + +The original Windows disk-space guard failed its existing low-space bake test in +this environment because its PowerShell subprocess did not return a usable free +space value. The Windows path now uses `GetDiskFreeSpaceExW` on the nearest existing +output directory, avoiding subprocess startup and handling mount points and UNC +paths through the native API. Its existing regression passes. + +## Reproduction + +Run from the repository root with Rust 1.95.0. GPU checks require a supported +adapter and print a skip message if none is available. + +```text +cargo run --release -p solstice-render --example cpu_stress +cargo run --release -p solstice-render --example page_stress +cargo run --release -p solstice-render --example streaming_stress +cargo test --release -p solstice-render --lib stress -- --nocapture +cargo test --workspace --release +cargo clippy --workspace --all-targets --release -- -D warnings +cargo fmt --all -- --check +``` + +The benchmark examples can also be compiled against the original library sources +to reproduce the baseline. Raw component measurements are in +[`performance-results`](performance-results/). Full local run logs, including the +intentional failing baseline regressions, are retained under `target/performance`. +The user's running street application has not been rebuilt or visually verified +with this checkout; that remains separate from the reproduced shader defects. diff --git a/docs/performance-results/cpu-baseline.csv b/docs/performance-results/cpu-baseline.csv new file mode 100644 index 0000000..ce84145 --- /dev/null +++ b/docs/performance-results/cpu-baseline.csv @@ -0,0 +1,13 @@ +case,count,median_ms,max_ms,checksum +read_move,1024,0.216600,0.218700,4488975366999434021 +advance,1024,0.049400,0.053400,4488975366999434021 +read_move,8192,17.101400,19.167900,2145466807575126821 +advance,8192,0.381100,1.862800,2145466807575126821 +read_move,32768,308.509400,315.532400,1958079272899453733 +advance,32768,1.590000,1.728900,1958079272899453733 +eight_updates,1024,0.123800,0.126000,17969969747901055205 +eight_updates,8192,1.493300,1.670100,8122806200533918437 +eight_updates,32768,6.179800,6.383500,11201317558116910821 +stream_plan,4096,0.016500,0.024400,8824206731530570048 +stream_plan,65536,0.373300,0.399400,8274004950052490030 +stream_plan,1048576,8.940900,10.811400,8274004950052490030 diff --git a/docs/performance-results/cpu-final.csv b/docs/performance-results/cpu-final.csv new file mode 100644 index 0000000..7b53cf7 --- /dev/null +++ b/docs/performance-results/cpu-final.csv @@ -0,0 +1,13 @@ +case,count,median_ms,max_ms,checksum +read_move,1024,0.004800,0.004800,4488975366999434021 +advance,1024,0.024300,0.025400,4488975366999434021 +read_move,8192,0.039400,0.039600,2145466807575126821 +advance,8192,0.218800,0.225500,2145466807575126821 +read_move,32768,0.160800,0.161000,1958079272899453733 +advance,32768,0.931200,0.941600,1958079272899453733 +eight_updates,1024,0.033800,0.033800,17969969747901055205 +eight_updates,8192,0.275800,0.282500,8122806200533918437 +eight_updates,32768,1.150800,1.443800,11201317558116910821 +stream_plan,4096,0.006300,0.010000,8824206731530570048 +stream_plan,65536,0.117700,0.190400,8274004950052490030 +stream_plan,1048576,2.811400,3.203900,8274004950052490030 diff --git a/docs/performance-results/page-baseline.csv b/docs/performance-results/page-baseline.csv new file mode 100644 index 0000000..eaccc3f --- /dev/null +++ b/docs/performance-results/page-baseline.csv @@ -0,0 +1,3 @@ +case,source_triangles,clusters,pages,raw_bytes,deflated_bytes,pool_bytes,packing_ms +terrain,73728,1164,23,2191488,1015543,3014656,1.006 +foliage,32768,800,35,3402100,761959,4587520,1.026 diff --git a/docs/performance-results/page-fixed.csv b/docs/performance-results/page-fixed.csv new file mode 100644 index 0000000..e0b51d4 --- /dev/null +++ b/docs/performance-results/page-fixed.csv @@ -0,0 +1,3 @@ +case,source_triangles,clusters,pages,raw_bytes,deflated_bytes,pool_bytes,packing_ms +terrain,73728,1164,23,2190976,1015535,3014656,1.210 +foliage,32768,800,33,3159988,759240,4325376,1.141 diff --git a/docs/performance-results/streaming-baseline.csv b/docs/performance-results/streaming-baseline.csv new file mode 100644 index 0000000..294bbf5 --- /dev/null +++ b/docs/performance-results/streaming-baseline.csv @@ -0,0 +1,3 @@ +bands,frames,fetches,installs,evictions,trace_hash +1,1500,955,866,618,14859531676831798266 +3,1500,1639,1497,1249,12381328480948452750 diff --git a/docs/performance-results/streaming-fixed.csv b/docs/performance-results/streaming-fixed.csv new file mode 100644 index 0000000..294bbf5 --- /dev/null +++ b/docs/performance-results/streaming-fixed.csv @@ -0,0 +1,3 @@ +bands,frames,fetches,installs,evictions,trace_hash +1,1500,955,866,618,14859531676831798266 +3,1500,1639,1497,1249,12381328480948452750 From a07a4b48487cf8c1f907e7e6935a7b634793a8df Mon Sep 17 00:00:00 2001 From: Sam <13449963+SamG-Coder@users.noreply.github.com> Date: Fri, 13 Nov 2026 20:41:15 +1100 Subject: [PATCH 2/2] Record completed validation and clarify existing overflow counters --- docs/performance-audit.md | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/performance-audit.md b/docs/performance-audit.md index 63f72be..c039d97 100644 --- a/docs/performance-audit.md +++ b/docs/performance-audit.md @@ -100,8 +100,9 @@ The GPU regression exercises the actual control and traversal shaders at 0, 1, 31, 32, 33, 2,097,120, 2,097,121, and 4,194,304 entries, including a nonzero queue start. It checks dispatch legality and complete processing. This removes a limit below the allocated capacity; it does not make queues or visible-cluster buffers -unbounded. Capacity overflow still needs explicit diagnostics and a considered -fallback before claiming arbitrary scene sizes are supported. +unbounded. `FrameStats` already reports dropped entries for the main view and +shadows; a considered fallback is still needed before claiming arbitrary scene +sizes are supported. ## Smaller geometry pages without requantization @@ -184,6 +185,19 @@ space value. The Windows path now uses `GetDiskFreeSpaceExW` on the nearest exis output directory, avoiding subprocess startup and handling mount points and UNC paths through the native API. Its existing regression passes. +## Validation completed + +The local native suites passed 1,009 tests: 630 outside the renderer, 286 renderer +unit tests, and 93 full GPU integration tests. Three existing tests were ignored. +The final integration run used the completed fixes on the RTX 5080 and finished +in 354.39 seconds. The focused fault-injection and full-capacity traversal tests +also passed after the last shader changes. + +Workspace/all-target native Clippy with warnings denied, formatting, and diff +whitespace checks passed. The WASM viewer built and passed Clippy for minimal, +default, and editor configurations; the browser baker also built and passed +Clippy. The JavaScript page tests and Python crate-selection tests passed. + ## Reproduction Run from the repository root with Rust 1.95.0. GPU checks require a supported