Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions crates/xcl/src/hle/d3d12x/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8> = [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<u8> {
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<u8> = 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;
Expand Down
Loading