From 95b8b5f708764276bd68a0c046501938014324f4 Mon Sep 17 00:00:00 2001 From: Personed Date: Wed, 25 Nov 2026 03:11:48 -0300 Subject: [PATCH 1/2] Bound mesh-compute raw buffer addresses --- .../victory-shader/src/emit/mesh_compute.rs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/victory-shader/src/emit/mesh_compute.rs b/crates/victory-shader/src/emit/mesh_compute.rs index f3ace74..f5314e0 100644 --- a/crates/victory-shader/src/emit/mesh_compute.rs +++ b/crates/victory-shader/src/emit/mesh_compute.rs @@ -134,12 +134,18 @@ pub fn mesh_compute_layout( /// Computes the output-buffer allocation and non-indexed draw count for /// `groups` workgroups. Returns `None` if the allocation overflows `u64` or -/// the draw count cannot be represented by D3D12's `DrawInstanced` arguments. +/// exceeds the 32-bit byte-offset address space of a D3D12 raw buffer, or the +/// draw count cannot be represented by D3D12's `DrawInstanced` arguments. pub fn mesh_compute_dispatch( layout: &MeshComputeLayout, groups: u32, ) -> Option { let output_bytes = layout.slot_bytes.checked_mul(u64::from(groups))?; + // ByteAddressBuffer/RWByteAddressBuffer offsets are 32-bit. A buffer may + // occupy 2^32 bytes: its final aligned dword is still at u32::MAX - 3. + if output_bytes > u64::from(u32::MAX) + 1 { + return None; + } let draw_vertices = u64::from(groups) .checked_mul(u64::from(layout.max_primitives))? .checked_mul(3)?; @@ -229,4 +235,18 @@ mod tests { let layout = mesh_compute_layout(1, u32::MAX, 0, 0, &[], &[]).unwrap(); assert!(mesh_compute_dispatch(&layout, 1).is_none()); } + + #[test] + fn enforces_the_raw_buffer_byte_offset_limit() { + let mut layout = mesh_compute_layout(1, 0, 0, 0, &[], &[]).unwrap(); + layout.slot_bytes = u64::from(u32::MAX) + 1; + assert_eq!( + mesh_compute_dispatch(&layout, 1).unwrap().output_bytes, + u64::from(u32::MAX) + 1 + ); + assert!(mesh_compute_dispatch(&layout, 2).is_none()); + + layout.slot_bytes = (u64::from(u32::MAX) + 1) / 2 + 1; + assert!(mesh_compute_dispatch(&layout, 2).is_none()); + } } From 3cff7ea90bf94b920664420c59eaa099b3287b07 Mon Sep 17 00:00:00 2001 From: Personed Date: Wed, 25 Nov 2026 03:15:53 -0300 Subject: [PATCH 2/2] Use div_ceil in mesh-compute boundary test --- crates/victory-shader/src/emit/mesh_compute.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/victory-shader/src/emit/mesh_compute.rs b/crates/victory-shader/src/emit/mesh_compute.rs index f5314e0..94e8558 100644 --- a/crates/victory-shader/src/emit/mesh_compute.rs +++ b/crates/victory-shader/src/emit/mesh_compute.rs @@ -246,7 +246,7 @@ mod tests { ); assert!(mesh_compute_dispatch(&layout, 2).is_none()); - layout.slot_bytes = (u64::from(u32::MAX) + 1) / 2 + 1; + layout.slot_bytes = u64::from(u32::MAX).div_ceil(2) + 1; assert!(mesh_compute_dispatch(&layout, 2).is_none()); } }