From ecac034d692345fdf7e13c24103f9cb1239a95ba Mon Sep 17 00:00:00 2001 From: Pipodi Date: Mon, 30 Nov 2026 04:11:19 +0100 Subject: [PATCH] Tests: a root constants write past the last parameter keeps the part that fits A retail title's BVH builder writes 4 dwords into compute parameter 3, the last parameter of a 9-dword table (3 fit). Before the clip, bind::put_in dropped the whole write, so the radix pass read a null BVH header and the refit's box stores corrupted vertex and index lists. With the clip alone (r262) L24 went 80 -> 0 and de5c's bad parent loads 30.7M -> 1. The clip's own test covers a write that overruns a mid-table parameter. These cover the shape of that title: 5 values into a parameter of 4 keep 1..4, and 4 values at the last parameter of three views + 3 constants write bytes 24-35 and leave the views alone, for the compute and the graphics argument table. All three fail with the put_in change reverted (zeros in the table). The console-list replay arm has no test: its table is a local of close(), visible only through a translated dispatch, so it needs a GPU title run. Co-Authored-By: Claude Sonnet 5.5 --- crates/xcl/src/hle/d3d12x/bind.rs | 72 +++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/crates/xcl/src/hle/d3d12x/bind.rs b/crates/xcl/src/hle/d3d12x/bind.rs index 0c064f8f93..f811f6af95 100644 --- a/crates/xcl/src/hle/d3d12x/bind.rs +++ b/crates/xcl/src/hle/d3d12x/bind.rs @@ -5751,6 +5751,78 @@ void main(uint t : SV_GroupIndex) { ); } + #[test] + fn a_write_past_the_last_parameter_keeps_the_part_that_fits() { + let list = 0x7100_0F31usize as *mut c_void; + let rs = 0x7100_0F32usize; + console_list::note_root_signature(rs, &test_rts0_blob()); + unsafe { + set_compute_root_signature(list, rs as *mut c_void); + // 5 dwords into a parameter of 4: the first 4 stay + let vals = [1u32, 2, 3, 4, 5]; + set_compute_root_constants(list, 0, vals.len() as u32, vals.as_ptr(), 0); + } + let (_, _, args, _, _) = reset_state_for_test(list); + remove_state_for_test(list); + let want: Vec = [1u32, 2, 3, 4].iter().flat_map(|w| w.to_le_bytes()).collect(); + assert_eq!(args, want, "the 4 dwords that fit are kept"); + } + + /// three root views and 3 constants, as the retail title's BVH builder sets them: 4 dwords + /// into the 3 of the last parameter (a table of 9 dwords) + fn three_views_and_three_constants() -> Vec { + let words: [u32; 30] = [ + 2, 4, 24, 0, 0, 0, + 4, 0, 72, 4, 0, 84, 4, 0, 96, 1, 0, 108, // parameters: three UAVs, constants + 0, 0, 0, 0, 0, 0, 0, 0, 0, // payloads of the UAVs + 0, 0, 3, // payload of the constants: 3 values + ]; + words.iter().flat_map(|w| w.to_le_bytes()).collect() + } + + #[test] + fn four_constants_at_the_last_of_three_views_and_three_constants_write_bytes_24_to_35() { + four_constants_at_the_last_parameter(false); + } + + #[test] + fn graphics_four_constants_at_the_last_of_three_views_and_three_constants_write_bytes_24_to_35() { + four_constants_at_the_last_parameter(true); + } + + fn four_constants_at_the_last_parameter(gfx: bool) { + let blob = three_views_and_three_constants(); + let list = (0x7100_0F33 + gfx as usize * 4) as *mut c_void; + let rs = (0x7100_0F34 + gfx as usize * 4) as usize; + console_list::note_root_signature(rs, &blob); + let vals = [0xA1u32, 0xA2, 0xA3, 0xA4]; + unsafe { + if gfx { + set_graphics_root_signature(list, rs as *mut c_void); + for k in 0..3 { + set_graphics_root_descriptor(list, k, 0x1111_1111_0000_0000 + k as u64); + } + set_graphics_root_constants(list, 3, 4, vals.as_ptr(), 0); + } else { + set_compute_root_signature(list, rs as *mut c_void); + for k in 0..3 { + set_compute_root_descriptor(list, k, 0x1111_1111_0000_0000 + k as u64); + } + set_compute_root_constants(list, 3, 4, vals.as_ptr(), 0); + } + } + let (_, _, compute, graphics, _) = reset_state_for_test(list); + remove_state_for_test(list); + let (args, other) = if gfx { (graphics, compute) } else { (compute, graphics) }; + assert!(other.is_empty(), "the other list kind has no arguments (gfx {gfx})"); + assert_eq!(args.len(), 36, "gfx {gfx}"); + for k in 0..3usize { + assert_eq!(&args[8 * k..8 * k + 8], &(0x1111_1111_0000_0000u64 + k as u64).to_le_bytes(), "view {k} (gfx {gfx})"); + } + let want: Vec = vals[..3].iter().flat_map(|w| w.to_le_bytes()).collect(); + assert_eq!(&args[24..36], &want[..], "the 3 dwords that fit are kept (gfx {gfx})"); + } + #[test] fn reset_and_clear_state_track_initial_pso_and_clear_root_args() { let list = 0x7100_0001usize as *mut c_void;