diff options
| author | milk4sale <53350507+milk4sale@users.noreply.github.com> | 2026-11-24 16:31:06 -0600 |
|---|---|---|
| committer | milk4sale <53350507+milk4sale@users.noreply.github.com> | 2026-11-24 16:31:06 -0600 |
| commit | e040dce1f09d42f21a8fed75668c53c0d49fb57a (patch) | |
| tree | 3b254dec5ef8caf9a86f63abf4771913f24a2fbb /runtime/test/device_proxy_test.cpp | |
| parent | 60c2ed910b90aef3cf5af1df2366a28a25afbe64 (diff) | |
| parent | 68d1331e5fe9bb4c9d02deabeb5905e55c23b7c8 (diff) | |
Merge main into gpu-test/round-f64
Brings the branch up to date with main 68d1331e5. No conflicts; the merged tree was tested before the push (every standalone
test file under tests/ passes except tests/test_ci_registration.py, which fails on main alone since #930).
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Diffstat (limited to 'runtime/test/device_proxy_test.cpp')
| -rw-r--r-- | runtime/test/device_proxy_test.cpp | 72 |
1 files changed, 71 insertions, 1 deletions
diff --git a/runtime/test/device_proxy_test.cpp b/runtime/test/device_proxy_test.cpp index b3b3f0fc3..6242d1b52 100644 --- a/runtime/test/device_proxy_test.cpp +++ b/runtime/test/device_proxy_test.cpp | |||
| @@ -23,6 +23,7 @@ | |||
| 23 | #include <wrl/client.h> | 23 | #include <wrl/client.h> |
| 24 | 24 | ||
| 25 | #include "d3d12_trace.h" | 25 | #include "d3d12_trace.h" |
| 26 | #include "d3d12_xs_desc_clean.h" | ||
| 26 | #include "d3d12_xs_device.h" | 27 | #include "d3d12_xs_device.h" |
| 27 | #include "shims.h" | 28 | #include "shims.h" |
| 28 | 29 | ||
| @@ -225,7 +226,11 @@ int main(int argc, char** argv) { | |||
| 225 | const D3D12_RESOURCE_DESC desc = buffer_desc(); | 226 | const D3D12_RESOURCE_DESC desc = buffer_desc(); |
| 226 | D3D12_RESOURCE_ALLOCATION_INFO got{~0ull, ~0ull}; | 227 | D3D12_RESOURCE_ALLOCATION_INFO got{~0ull, ~0ull}; |
| 227 | D3D12_RESOURCE_ALLOCATION_INFO* returned = get_alloc_info(&got, device.Get(), 0, 1, &desc); | 228 | D3D12_RESOURCE_ALLOCATION_INFO* returned = get_alloc_info(&got, device.Get(), 0, 1, &desc); |
| 228 | const D3D12_RESOURCE_ALLOCATION_INFO want = real->GetResourceAllocationInfo(0, 1, &desc); | 229 | // The proxy cleans the console layout word and flag bits before the PC call (stop 16), so the expected answer is |
| 230 | // the PC device's for the cleaned description (the raw 0x101 layout makes WARP answer UINT64_MAX). | ||
| 231 | const D3D12_RESOURCE_DESC clean = rt::d3d12_xs::pc_resource_desc(desc); | ||
| 232 | const D3D12_RESOURCE_ALLOCATION_INFO want = real->GetResourceAllocationInfo(0, 1, &clean); | ||
| 233 | check(want.SizeInBytes != UINT64_MAX, "WARP accepts the normalized slot-25 buffer description"); | ||
| 229 | check(returned == &got, "slot 25 returns the caller's buffer in RAX"); | 234 | check(returned == &got, "slot 25 returns the caller's buffer in RAX"); |
| 230 | check(got.SizeInBytes == want.SizeInBytes && got.Alignment == want.Alignment, | 235 | check(got.SizeInBytes == want.SizeInBytes && got.Alignment == want.Alignment, |
| 231 | "slot 25 (C ABI) writes the PC device's GetResourceAllocationInfo into the caller's buffer"); | 236 | "slot 25 (C ABI) writes the PC device's GetResourceAllocationInfo into the caller's buffer"); |
| @@ -577,6 +582,71 @@ int main(int argc, char** argv) { | |||
| 577 | } | 582 | } |
| 578 | } | 583 | } |
| 579 | 584 | ||
| 585 | // Title-exported __XMemAllocationHooks__ backing for CreateDescriptorHeap (slot 14) + CPU handle translation | ||
| 586 | // against the real WARP D3D12 runtime. | ||
| 587 | { | ||
| 588 | struct HookState { | ||
| 589 | alignas(64) std::uint8_t backing[4096]{}; | ||
| 590 | std::size_t alloc_size = 0; | ||
| 591 | std::uint64_t alloc_attr = 0; | ||
| 592 | void* freed_ptr = nullptr; | ||
| 593 | std::uint64_t freed_attr = 0; | ||
| 594 | int alloc_count = 0; | ||
| 595 | int free_count = 0; | ||
| 596 | }; | ||
| 597 | static HookState hook_state; | ||
| 598 | hook_state = {}; | ||
| 599 | struct HookCallbacks { | ||
| 600 | static void* __stdcall alloc(std::size_t size, std::uint64_t attr) { | ||
| 601 | ++hook_state.alloc_count; | ||
| 602 | hook_state.alloc_size = size; | ||
| 603 | hook_state.alloc_attr = attr; | ||
| 604 | if ((attr & 0x3FFFull) == 4 && size <= sizeof(hook_state.backing)) return hook_state.backing; | ||
| 605 | return nullptr; | ||
| 606 | } | ||
| 607 | static void __stdcall free(void* ptr, std::uint64_t attr) { | ||
| 608 | ++hook_state.free_count; | ||
| 609 | hook_state.freed_ptr = ptr; | ||
| 610 | hook_state.freed_attr = attr; | ||
| 611 | } | ||
| 612 | }; | ||
| 613 | const rt::shims::XMemAllocationHooks title_hooks{&HookCallbacks::alloc, &HookCallbacks::free}; | ||
| 614 | rt::shims::add_xmem_allocation_hooks(&title_hooks, &title_hooks); | ||
| 615 | |||
| 616 | D3D12_DESCRIPTOR_HEAP_DESC hooked_desc{}; | ||
| 617 | hooked_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; | ||
| 618 | hooked_desc.NumDescriptors = 4; | ||
| 619 | hooked_desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE; | ||
| 620 | const UINT inc = device->GetDescriptorHandleIncrementSize(hooked_desc.Type); | ||
| 621 | ComPtr<ID3D12DescriptorHeap> hooked_heap; | ||
| 622 | hr = device->CreateDescriptorHeap(&hooked_desc, IID_PPV_ARGS(hooked_heap.GetAddressOf())); | ||
| 623 | check(SUCCEEDED(hr) && hooked_heap != nullptr, "hooked slot 14 creates a descriptor heap"); | ||
| 624 | check(hook_state.alloc_count == 1 && hook_state.alloc_size == hooked_desc.NumDescriptors * inc && | ||
| 625 | hook_state.alloc_attr == rt::d3d12_xs::kXmemDescriptorHeapAttributes, | ||
| 626 | "slot 14 invokes __XMemAllocationHooks__ with heap byte size and D3D descriptor-heap attributes"); | ||
| 627 | if (hooked_heap) { | ||
| 628 | void** hooked_vtbl = *reinterpret_cast<void***>(hooked_heap.Get()); | ||
| 629 | const auto hooked_cpu = reinterpret_cast<GetCpuHandleFn>(hooked_vtbl[9])(hooked_heap.Get()); | ||
| 630 | const auto hooked_gpu = reinterpret_cast<GetGpuHandleFn>(hooked_vtbl[10])(hooked_heap.Get()); | ||
| 631 | const auto expected_base = reinterpret_cast<SIZE_T>(hook_state.backing); | ||
| 632 | check(hooked_cpu.ptr == expected_base, | ||
| 633 | "hooked heap slot 9 returns the title-supplied CPU descriptor base"); | ||
| 634 | check(hooked_gpu.ptr != 0, "hooked heap slot 10 returns a valid GPU descriptor start"); | ||
| 635 | |||
| 636 | // Create a CBV at slot 1 of the title-backed heap; WARP validates the translated real handle. | ||
| 637 | D3D12_CONSTANT_BUFFER_VIEW_DESC cbv{}; | ||
| 638 | cbv.BufferLocation = 0; | ||
| 639 | cbv.SizeInBytes = 256; | ||
| 640 | device->CreateConstantBufferView(&cbv, D3D12_CPU_DESCRIPTOR_HANDLE{expected_base + inc}); | ||
| 641 | check(true, "CreateConstantBufferView translates a title-backed CPU descriptor handle on WARP"); | ||
| 642 | } | ||
| 643 | hooked_heap.Reset(); | ||
| 644 | check(hook_state.free_count == 1 && hook_state.freed_ptr == hook_state.backing && | ||
| 645 | hook_state.freed_attr == rt::d3d12_xs::kXmemDescriptorHeapAttributes, | ||
| 646 | "releasing the hooked heap frees its backing through __XMemAllocationHooks__"); | ||
| 647 | rt::shims::remove_xmem_allocation_hooks(&title_hooks); | ||
| 648 | } | ||
| 649 | |||
| 580 | // Hold a reference to the PC device so the final check can prove the proxy's Release balances its own. | 650 | // Hold a reference to the PC device so the final check can prove the proxy's Release balances its own. |
| 581 | if (real) real->AddRef(); | 651 | if (real) real->AddRef(); |
| 582 | // Drop every device child before the proxy so the PC device is not released first. | 652 | // Drop every device child before the proxy so the PC device is not released first. |