Skip to content
Merged
Show file tree
Hide file tree
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
27 changes: 18 additions & 9 deletions crates/xcl/tests/console_heap_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@

use xcl::hle::d3d12x::console_heap::{self, Slot};

/// The unified memory, or a counted skip.
fn uma() -> Option<&'static xcl::gpu::uma::Uma> {
let u = xcl::gpu::uma::get();
if u.is_none() {
xcl::gpu::recomp::runner::skip_test("no unified memory");
}
u
}

fn rel(u: &xcl::gpu::uma::Uma, p: u64) -> u32 {
(p as usize - u.base()) as u32
}

#[test]
fn view_heap_slots_window_zero_and_release() {
let Some(u) = xcl::gpu::uma::get() else { return };
let Some(u) = uma() else { return };
assert!(console_heap::register(0xC001, 4, 0x2000, 0x5000, 32, false, false, true));
let v = console_heap::start(0xC001).unwrap();
assert_eq!(u.window_of(v as usize), Some(0), "view heap must live in window 0 (32-bit table addressing)");
Expand Down Expand Up @@ -42,7 +51,7 @@ fn view_heap_slots_window_zero_and_release() {

#[test]
fn view_heap_indexing_is_per_page_slot_number() {
let Some(u) = xcl::gpu::uma::get() else { return };
let Some(u) = uma() else { return };
assert!(console_heap::register(0xC002, 4, 0x3000, 0x6000, 32, false, false, true));
let v = console_heap::start(0xC002).unwrap();
// 4 slots: 0..3, each 32 bytes apart, k = (addr - base) / 32
Expand All @@ -61,7 +70,7 @@ fn view_heap_indexing_is_per_page_slot_number() {

#[test]
fn sampler_heap_slots_and_copy() {
let Some(u) = xcl::gpu::uma::get() else { return };
let Some(u) = uma() else { return };
assert!(console_heap::register(0xC003, 2, 0x9000, 0, 16, true, false, true));
let sm = console_heap::start(0xC003).unwrap();
assert_eq!(u.window_of(sm as usize), Some(0), "sampler heap must live in window 0");
Expand Down Expand Up @@ -91,7 +100,7 @@ fn sampler_heap_slots_and_copy() {

#[test]
fn image_copy_renumbers_word_0_and_buffer_copy_keeps_address() {
let Some(u) = xcl::gpu::uma::get() else { return };
let Some(u) = uma() else { return };
assert!(console_heap::register(0xC004, 4, 0x1000, 0x5000, 32, false, false, true));
let v = console_heap::start(0xC004).unwrap();
let s1 = console_heap::slot(v + 32).unwrap();
Expand Down Expand Up @@ -121,7 +130,7 @@ fn image_copy_renumbers_word_0_and_buffer_copy_keeps_address() {

#[test]
fn words_at_reads_the_console_address_space() {
let Some(u) = xcl::gpu::uma::get() else { return };
let Some(u) = uma() else { return };
assert!(console_heap::register(0xC005, 2, 0x4000, 0x7000, 32, false, false, true));
let v = console_heap::start(0xC005).unwrap();
let s0 = console_heap::slot(v).unwrap();
Expand All @@ -142,7 +151,7 @@ fn words_at_reads_the_console_address_space() {
fn heap_not_window_zero_is_still_registered_but_reported_elsewhere() {
// a heap registered here is in window 0 by construction; the release path is what this
// pins: after unregister, words_at reports None and the heap is forgotten
let Some(u) = xcl::gpu::uma::get() else { return };
let Some(u) = uma() else { return };
assert!(console_heap::register(0xC006, 1, 0x5000, 0x8000, 32, false, false, true));
let v = console_heap::start(0xC006).unwrap();
assert!(console_heap::words_at(rel(u, v)).is_some());
Expand All @@ -153,7 +162,7 @@ fn heap_not_window_zero_is_still_registered_but_reported_elsewhere() {

#[test]
fn non_shader_visible_heap_reports_no_gpu_uav() {
let Some(u) = xcl::gpu::uma::get() else { return };
let Some(u) = uma() else { return };
// pc_gpu = 0: the title made the heap CPU-only; slots report pc_gpu_uav == 0
assert!(console_heap::register(0xC007, 2, 0x6000, 0, 32, false, false, false));
let v = console_heap::start(0xC007).unwrap();
Expand All @@ -169,7 +178,7 @@ fn non_shader_visible_heap_reports_no_gpu_uav() {
fn copy_words_of_a_view_to_a_buffer_slot_does_not_crash_on_short_words() {
// copy_words reads exactly the source's word count and writes exactly 8 (a view slot);
// a source slot written with only 4 words must not be read past the slot
let Some(u) = xcl::gpu::uma::get() else { return };
let Some(u) = uma() else { return };
assert!(console_heap::register(0xC008, 2, 0x7000, 0x9000, 32, false, false, true));
let v = console_heap::start(0xC008).unwrap();
let s0 = console_heap::slot(v).unwrap();
Expand All @@ -187,7 +196,7 @@ fn copy_words_of_a_view_to_a_buffer_slot_does_not_crash_on_short_words() {

#[test]
fn start_is_stable_across_slot_calls() {
let Some(u) = xcl::gpu::uma::get() else { return };
let Some(u) = uma() else { return };
assert!(console_heap::register(0xC009, 2, 0x8100, 0x9100, 32, false, false, true));
let v = console_heap::start(0xC009).unwrap();
let _s = console_heap::slot(v).unwrap();
Expand Down
9 changes: 7 additions & 2 deletions crates/xcl/tests/d3d12_command_objects_and_root_sig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ fn create_command_queue_and_allocator_match_host_driver() {
let (mut p_hook, mut p_host) = (std::ptr::null_mut(), std::ptr::null_mut());
let hr_hook = q_hook(dev, &bad, &q_iid, &mut p_hook);
let hr_host = q_host(dev, &bad, &q_iid, &mut p_host);
assert!(hr_hook < 0 && hr_host < 0, "expected queue failure: hook={hr_hook:#x}, host={hr_host:#x}");
assert!(p_hook.is_null() && p_host.is_null());
assert_eq!(hr_hook, hr_host, "HRESULT mismatch for {bad:?}");
assert_eq!((p_hook.is_null(), p_host.is_null()), (hr_hook < 0, hr_host < 0), "output for {bad:?}");
// The PC runtime refuses these; vkd3d-proton (under Wine) accepts some of them.
assert!(hr_host < 0 || xcl::util::under_wine(), "expected queue failure: host={hr_host:#x}");
for p in [p_hook, p_host].into_iter().filter(|p| !p.is_null()) {
drop(ID3D12CommandQueue::from_raw(p));
}
}

let q_console_iid = GUID::from_u128(0x11223344_5566_7788_99aa_bbccddeeff06);
Expand Down
9 changes: 7 additions & 2 deletions crates/xcl/tests/d3d12_create_committed_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,13 @@ fn committed_resources_match_host_driver_desc_and_status() {
let (mut p_host, mut p_hook) = (std::ptr::null_mut(), std::ptr::null_mut());
let hr_host = host(dev, &props, D3D12_HEAP_FLAG_NONE, &desc.pc, D3D12_RESOURCE_STATE_COMMON, std::ptr::null(), riid, &mut p_host);
let hr_hook = hooked(dev, &props, D3D12_HEAP_FLAG_NONE, &desc.pc, D3D12_RESOURCE_STATE_COMMON, std::ptr::null(), riid, &mut p_hook);
assert!(hr_host < 0 && p_host.is_null(), "{label}: expected host failure, got {hr_host:#x}");
assert!(hr_hook < 0 && p_hook.is_null(), "{label}: expected hooked failure, got {hr_hook:#x}");
assert_eq!(hr_hook < 0, hr_host < 0, "{label}: hooked {hr_hook:#x}, host {hr_host:#x}");
assert_eq!((p_hook.is_null(), p_host.is_null()), (hr_hook < 0, hr_host < 0), "{label}: output");
// The PC runtime refuses these; vkd3d-proton (under Wine) accepts some of them.
assert!(hr_host < 0 || xcl::util::under_wine(), "{label}: expected host failure, got {hr_host:#x}");
for p in [p_hook, p_host].into_iter().filter(|p| !p.is_null()) {
drop(ID3D12Resource::from_raw(p));
}
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions crates/xcl/tests/d3d12_create_placed_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,15 @@ fn create_placed_errors_and_console_iid_fallback() {
assert!(p_hook.is_null() && p_host.is_null());
}

// Null desc returns error without dereferencing.
let (mut p_hook, mut p_host) = (std::ptr::null_mut(), std::ptr::null_mut());
let hr_hook = hooked(dev, heap.as_raw(), 0, std::ptr::null(), D3D12_RESOURCE_STATE_COMMON, std::ptr::null(), &iid, &mut p_hook);
let hr_host = host(dev, heap.as_raw(), 0, std::ptr::null(), D3D12_RESOURCE_STATE_COMMON, std::ptr::null(), &iid, &mut p_host);
assert!(hr_hook < 0 && hr_host < 0, "expected failure on null desc: hook={hr_hook:#x}, host={hr_host:#x}");
assert!(p_hook.is_null() && p_host.is_null());
// Null desc returns error without dereferencing. (vkd3d-proton, under Wine, dereferences it and
// the process ends.)
if !xcl::util::under_wine() {
let (mut p_hook, mut p_host) = (std::ptr::null_mut(), std::ptr::null_mut());
let hr_hook = hooked(dev, heap.as_raw(), 0, std::ptr::null(), D3D12_RESOURCE_STATE_COMMON, std::ptr::null(), &iid, &mut p_hook);
let hr_host = host(dev, heap.as_raw(), 0, std::ptr::null(), D3D12_RESOURCE_STATE_COMMON, std::ptr::null(), &iid, &mut p_host);
assert!(hr_hook < 0 && hr_host < 0, "expected failure on null desc: hook={hr_hook:#x}, host={hr_host:#x}");
assert!(p_hook.is_null() && p_host.is_null());
}

// Unknown console IID fails on host with E_NOINTERFACE; XCL falls back to ID3D12Resource.
let console_iid = GUID::from_u128(0x11223344_5566_7788_99aa_bbccddeeff03);
Expand Down
18 changes: 14 additions & 4 deletions crates/xcl/tests/d3d12_query_and_command_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@ fn create_query_heap_matches_host_driver() {
let (mut p_hook, mut p_host) = (std::ptr::null_mut(), std::ptr::null_mut());
let hr_hook = hooked(dev, &bad, &iid, &mut p_hook);
let hr_host = host(dev, &bad, &iid, &mut p_host);
assert!(hr_hook < 0 && hr_host < 0, "expected failure for {bad:?}: hook={hr_hook:#x}, host={hr_host:#x}");
assert!(p_hook.is_null() && p_host.is_null());
assert_eq!(hr_hook, hr_host, "HRESULT mismatch for {bad:?}");
assert_eq!((p_hook.is_null(), p_host.is_null()), (hr_hook < 0, hr_host < 0), "output for {bad:?}");
// The PC runtime refuses these; vkd3d-proton (under Wine) accepts some of them.
assert!(hr_host < 0 || xcl::util::under_wine(), "expected failure for {bad:?}: host={hr_host:#x}");
for p in [p_hook, p_host].into_iter().filter(|p| !p.is_null()) {
drop(ID3D12QueryHeap::from_raw(p));
}
}

// Unknown console IID fails on host with E_NOINTERFACE; XCL falls back to ID3D12QueryHeap.
Expand Down Expand Up @@ -123,8 +128,13 @@ fn create_command_signature_matches_host_driver() {
let (mut p_hook, mut p_host) = (std::ptr::null_mut(), std::ptr::null_mut());
let hr_hook = hooked(dev, &desc, std::ptr::null_mut(), &iid, &mut p_hook);
let hr_host = host(dev, &desc, std::ptr::null_mut(), &iid, &mut p_host);
assert!(hr_hook < 0 && hr_host < 0, "expected failure: hook={hr_hook:#x}, host={hr_host:#x}");
assert!(p_hook.is_null() && p_host.is_null());
assert_eq!(hr_hook, hr_host, "HRESULT mismatch for an invalid signature");
assert_eq!((p_hook.is_null(), p_host.is_null()), (hr_hook < 0, hr_host < 0), "output for an invalid signature");
// The PC runtime refuses these; vkd3d-proton (under Wine) accepts some of them.
assert!(hr_host < 0 || xcl::util::under_wine(), "expected failure: host={hr_host:#x}");
for p in [p_hook, p_host].into_iter().filter(|p| !p.is_null()) {
drop(ID3D12CommandSignature::from_raw(p));
}
}

// Unknown console IID fails on host with E_NOINTERFACE; XCL falls back to ID3D12CommandSignature.
Expand Down
Loading