upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/device_proxy_test.cpp
diff options
context:
space:
mode:
authorJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 18:23:04 -0500
committerJan Trencansky <jan.trencansky@protonmail.com>2026-11-24 18:23:04 -0500
commit7234bcd7a54eb9aa06c97389e8322ced26c54e6d (patch)
tree011799aea6b051ec9362552e606d73653c6a61f4 /runtime/test/device_proxy_test.cpp
parentac73a84127ee49b5ecf9702bed16603b34b7f7ec (diff)
parent2376e7d56bc61bf17f9767e21d651071fe74ee6e (diff)
Merge main into RT-SLOT108-REBASE (#727)
Three files conflicted; in each, both sides had added something and both are kept. runtime/shims/d3d12_xs_device.cpp: this branch still had the Xbox device slot routes inline, followed by its fixed handlers for slots 86, 101 and 108; main has since moved the same six routes into route_xbox_device_slot() (#385). The generic path now calls the helper and then the three fixed handlers, so a configured route still wins over them, as this branch's second commit intends. device_slot_overridden() has main's list plus 86, 101 and 108. runtime/shims/d3d12_xs_device.h: the comment lists both sides' slots. runtime/test/xs_proxy_mock_test.cpp: the mock device keeps main's case 13 (CheckFeatureSupport) and this branch's case 68 (GetResourceAllocationInfo2); check_xbox_slots keeps main's slot 41 and 61 cases, one combined list of handled slots, and this branch's slot 86, 101 and 108 cases. 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.cpp72
1 files changed, 71 insertions, 1 deletions
diff --git a/runtime/test/device_proxy_test.cpp b/runtime/test/device_proxy_test.cpp
index 1c68dc5da..1c1707243 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
@@ -228,7 +229,11 @@ int main(int argc, char** argv) {
228 const D3D12_RESOURCE_DESC desc = buffer_desc(); 229 const D3D12_RESOURCE_DESC desc = buffer_desc();
229 D3D12_RESOURCE_ALLOCATION_INFO got{~0ull, ~0ull}; 230 D3D12_RESOURCE_ALLOCATION_INFO got{~0ull, ~0ull};
230 D3D12_RESOURCE_ALLOCATION_INFO* returned = get_alloc_info(&got, device.Get(), 0, 1, &desc); 231 D3D12_RESOURCE_ALLOCATION_INFO* returned = get_alloc_info(&got, device.Get(), 0, 1, &desc);
231 const D3D12_RESOURCE_ALLOCATION_INFO want = real->GetResourceAllocationInfo(0, 1, &desc); 232 // The proxy cleans the console layout word and flag bits before the PC call (stop 16), so the expected answer is
233 // the PC device's for the cleaned description (the raw 0x101 layout makes WARP answer UINT64_MAX).
234 const D3D12_RESOURCE_DESC clean = rt::d3d12_xs::pc_resource_desc(desc);
235 const D3D12_RESOURCE_ALLOCATION_INFO want = real->GetResourceAllocationInfo(0, 1, &clean);
236 check(want.SizeInBytes != UINT64_MAX, "WARP accepts the normalized slot-25 buffer description");
232 check(returned == &got, "slot 25 returns the caller's buffer in RAX"); 237 check(returned == &got, "slot 25 returns the caller's buffer in RAX");
233 check(got.SizeInBytes == want.SizeInBytes && got.Alignment == want.Alignment, 238 check(got.SizeInBytes == want.SizeInBytes && got.Alignment == want.Alignment,
234 "slot 25 (C ABI) writes the PC device's GetResourceAllocationInfo into the caller's buffer"); 239 "slot 25 (C ABI) writes the PC device's GetResourceAllocationInfo into the caller's buffer");
@@ -675,6 +680,71 @@ int main(int argc, char** argv) {
675 } 680 }
676 } 681 }
677 682
683 // Title-exported __XMemAllocationHooks__ backing for CreateDescriptorHeap (slot 14) + CPU handle translation
684 // against the real WARP D3D12 runtime.
685 {
686 struct HookState {
687 alignas(64) std::uint8_t backing[4096]{};
688 std::size_t alloc_size = 0;
689 std::uint64_t alloc_attr = 0;
690 void* freed_ptr = nullptr;
691 std::uint64_t freed_attr = 0;
692 int alloc_count = 0;
693 int free_count = 0;
694 };
695 static HookState hook_state;
696 hook_state = {};
697 struct HookCallbacks {
698 static void* __stdcall alloc(std::size_t size, std::uint64_t attr) {
699 ++hook_state.alloc_count;
700 hook_state.alloc_size = size;
701 hook_state.alloc_attr = attr;
702 if ((attr & 0x3FFFull) == 4 && size <= sizeof(hook_state.backing)) return hook_state.backing;
703 return nullptr;
704 }
705 static void __stdcall free(void* ptr, std::uint64_t attr) {
706 ++hook_state.free_count;
707 hook_state.freed_ptr = ptr;
708 hook_state.freed_attr = attr;
709 }
710 };
711 const rt::shims::XMemAllocationHooks title_hooks{&HookCallbacks::alloc, &HookCallbacks::free};
712 rt::shims::add_xmem_allocation_hooks(&title_hooks, &title_hooks);
713
714 D3D12_DESCRIPTOR_HEAP_DESC hooked_desc{};
715 hooked_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
716 hooked_desc.NumDescriptors = 4;
717 hooked_desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
718 const UINT inc = device->GetDescriptorHandleIncrementSize(hooked_desc.Type);
719 ComPtr<ID3D12DescriptorHeap> hooked_heap;
720 hr = device->CreateDescriptorHeap(&hooked_desc, IID_PPV_ARGS(hooked_heap.GetAddressOf()));
721 check(SUCCEEDED(hr) && hooked_heap != nullptr, "hooked slot 14 creates a descriptor heap");
722 check(hook_state.alloc_count == 1 && hook_state.alloc_size == hooked_desc.NumDescriptors * inc &&
723 hook_state.alloc_attr == rt::d3d12_xs::kXmemDescriptorHeapAttributes,
724 "slot 14 invokes __XMemAllocationHooks__ with heap byte size and D3D descriptor-heap attributes");
725 if (hooked_heap) {
726 void** hooked_vtbl = *reinterpret_cast<void***>(hooked_heap.Get());
727 const auto hooked_cpu = reinterpret_cast<GetCpuHandleFn>(hooked_vtbl[9])(hooked_heap.Get());
728 const auto hooked_gpu = reinterpret_cast<GetGpuHandleFn>(hooked_vtbl[10])(hooked_heap.Get());
729 const auto expected_base = reinterpret_cast<SIZE_T>(hook_state.backing);
730 check(hooked_cpu.ptr == expected_base,
731 "hooked heap slot 9 returns the title-supplied CPU descriptor base");
732 check(hooked_gpu.ptr != 0, "hooked heap slot 10 returns a valid GPU descriptor start");
733
734 // Create a CBV at slot 1 of the title-backed heap; WARP validates the translated real handle.
735 D3D12_CONSTANT_BUFFER_VIEW_DESC cbv{};
736 cbv.BufferLocation = 0;
737 cbv.SizeInBytes = 256;
738 device->CreateConstantBufferView(&cbv, D3D12_CPU_DESCRIPTOR_HANDLE{expected_base + inc});
739 check(true, "CreateConstantBufferView translates a title-backed CPU descriptor handle on WARP");
740 }
741 hooked_heap.Reset();
742 check(hook_state.free_count == 1 && hook_state.freed_ptr == hook_state.backing &&
743 hook_state.freed_attr == rt::d3d12_xs::kXmemDescriptorHeapAttributes,
744 "releasing the hooked heap frees its backing through __XMemAllocationHooks__");
745 rt::shims::remove_xmem_allocation_hooks(&title_hooks);
746 }
747
678 // Hold a reference to the PC device so the final check can prove the proxy's Release balances its own. 748 // Hold a reference to the PC device so the final check can prove the proxy's Release balances its own.
679 if (real) real->AddRef(); 749 if (real) real->AddRef();
680 // Drop every device child before the proxy so the PC device is not released first. 750 // Drop every device child before the proxy so the PC device is not released first.