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:
authorsneylol <raczpepo@gmail.com>2026-11-23 16:32:28 +0100
committerMumogg <104529023+Mumogg@users.noreply.github.com>2026-11-23 21:54:29 -0600
commit91575fda3a07da811b93ddcfd65b33e21794262a (patch)
treecec7273cf5ff188242a12291167e06dacfaaba64 /runtime/test/device_proxy_test.cpp
parentf9d20bf9b045ebaf8c7165eef3ae72cff9ef1410 (diff)
d3d12_xs: device slots 25/26 take the title's C-ABI struct return
The retail executable calls GetCustomHeapProperties (device slot 26) with the C convention: the hidden return buffer in RCX and the device in RDX. The proxy's generic forwarder assumed the PC C++ form (this in RCX, buffer in RDX), took the buffer for the device and crashed on its vtable right after D3D12XboxCreateDevice. Slots 25 (GetResourceAllocationInfo, same rule, inferred) and 26 (measured) now get thunks that accept either form: whichever of the first two arguments is the device proxy is `this`. The runtime's own code still calls the proxy through d3d12.h in the PC form. device_proxy_test calls both slots in both forms against WARP. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> (cherry picked from commit 5dbc30bed79b399b527460501c0ee33f28712096) Adapted to main by Mumogg: slot 26 keeps the thunk it already has (86b8e04e4), so of this commit's two thunks only slot 25's is installed.
Diffstat (limited to 'runtime/test/device_proxy_test.cpp')
-rw-r--r--runtime/test/device_proxy_test.cpp42
1 files changed, 41 insertions, 1 deletions
diff --git a/runtime/test/device_proxy_test.cpp b/runtime/test/device_proxy_test.cpp
index 94bf428d2..3fb0ba1df 100644
--- a/runtime/test/device_proxy_test.cpp
+++ b/runtime/test/device_proxy_test.cpp
@@ -3,7 +3,7 @@
3// It creates the proxy through the registered d3d12_xs!D3D12XboxCreateDevice shim, then calls the measured Xbox 3// It creates the proxy through the registered d3d12_xs!D3D12XboxCreateDevice shim, then calls the measured Xbox
4// slots exactly as the guest would (raw function pointers, not the C++ interface): 4// slots exactly as the guest would (raw function pointers, not the C++ interface):
5// slot 14 CreateDescriptorHeap (returns a heap proxy) 5// slot 14 CreateDescriptorHeap (returns a heap proxy)
6// slot 26 GetCustomHeapProperties with the struct's buffer in RCX and the device in RDX 6// slot 25/26 GetResourceAllocationInfo/GetCustomHeapProperties in the title's C form (return buffer first)
7// heap 9/10 GetCPU/GetGPUDescriptorHandleForHeapStart (Xbox: 8-byte handle in RAX; the PC heap uses the 7// heap 9/10 GetCPU/GetGPUDescriptorHandleForHeapStart (Xbox: 8-byte handle in RAX; the PC heap uses the
8// hidden return pointer in RDX, so slot 14 wraps it) 8// hidden return pointer in RDX, so slot 14 wraps it)
9// slot 62 CreateComputePipelineState 9// slot 62 CreateComputePipelineState
@@ -200,6 +200,46 @@ int main(int argc, char** argv) {
200 const LUID real_luid = real ? real->GetAdapterLuid() : LUID{}; 200 const LUID real_luid = real ? real->GetAdapterLuid() : LUID{};
201 check(proxy_luid.LowPart == real_luid.LowPart && proxy_luid.HighPart == real_luid.HighPart, 201 check(proxy_luid.LowPart == real_luid.LowPart && proxy_luid.HighPart == real_luid.HighPart,
202 "slot 43 forwards GetAdapterLuid (struct return)"); 202 "slot 43 forwards GetAdapterLuid (struct return)");
203 // Slots 25 and 26 return a struct wider than 8 bytes. The console title calls them with the C ABI: the hidden
204 // return pointer first (RCX), then the device (RDX), then the arguments, and the buffer comes back in RAX
205 // (measured for slot 26 on the retail executable). Call them that way through raw function pointers and compare
206 // with the PC device's own answers.
207 check(rt::d3d12_xs::device_slot_overridden(25), "device slot 25 is the C-ABI GetResourceAllocationInfo override");
208 check(rt::d3d12_xs::device_slot_overridden(26), "device slot 26 is the C-ABI GetCustomHeapProperties override");
209 if (real) {
210 using HeapPropsFn = D3D12_HEAP_PROPERTIES*(WINAPI*)(D3D12_HEAP_PROPERTIES*, void*, UINT, D3D12_HEAP_TYPE);
211 auto get_heap_props = reinterpret_cast<HeapPropsFn>(proxy_vtbl[26]);
212 for (D3D12_HEAP_TYPE type : {D3D12_HEAP_TYPE_DEFAULT, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_TYPE_READBACK}) {
213 D3D12_HEAP_PROPERTIES got;
214 std::memset(&got, 0xcd, sizeof(got));
215 D3D12_HEAP_PROPERTIES* returned = get_heap_props(&got, device.Get(), 1, type);
216 const D3D12_HEAP_PROPERTIES want = real->GetCustomHeapProperties(1, type);
217 check(returned == &got, "slot 26 returns the caller's buffer in RAX");
218 check(std::memcmp(&got, &want, sizeof(got)) == 0,
219 "slot 26 (C ABI) writes the PC device's GetCustomHeapProperties into the caller's buffer");
220 }
221
222 using AllocInfoFn = D3D12_RESOURCE_ALLOCATION_INFO*(WINAPI*)(D3D12_RESOURCE_ALLOCATION_INFO*, void*, UINT, UINT,
223 const D3D12_RESOURCE_DESC*);
224 auto get_alloc_info = reinterpret_cast<AllocInfoFn>(proxy_vtbl[25]);
225 const D3D12_RESOURCE_DESC desc = buffer_desc();
226 D3D12_RESOURCE_ALLOCATION_INFO got{~0ull, ~0ull};
227 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 check(returned == &got, "slot 25 returns the caller's buffer in RAX");
230 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");
232
233 // The runtime's own code calls the proxy through d3d12.h (PC form: this, then the return buffer). Both
234 // slots still answer that form.
235 const D3D12_HEAP_PROPERTIES pc_props = device->GetCustomHeapProperties(1, D3D12_HEAP_TYPE_UPLOAD);
236 const D3D12_HEAP_PROPERTIES pc_want = real->GetCustomHeapProperties(1, D3D12_HEAP_TYPE_UPLOAD);
237 check(std::memcmp(&pc_props, &pc_want, sizeof(pc_props)) == 0, "slot 26 still answers the PC (C++) form");
238 const D3D12_RESOURCE_ALLOCATION_INFO pc_info = device->GetResourceAllocationInfo(0, 1, &desc);
239 check(pc_info.SizeInBytes == want.SizeInBytes && pc_info.Alignment == want.Alignment,
240 "slot 25 still answers the PC (C++) form");
241 }
242
203 D3D12_RESOURCE_DESC reserved_desc = buffer_desc(); 243 D3D12_RESOURCE_DESC reserved_desc = buffer_desc();
204 reserved_desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; 244 reserved_desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
205 ComPtr<ID3D12Resource> reserved; 245 ComPtr<ID3D12Resource> reserved;