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:
authorSenne Cools <113857183+sennecools@users.noreply.github.com>2026-11-23 16:33:12 +0100
committerMumogg <104529023+Mumogg@users.noreply.github.com>2026-11-23 21:46:43 -0600
commitc4954581ae27e9db5baabaea091302ed54eb96ea (patch)
tree4f7ae32af088f3d6831618380b3e03df3817c56c /runtime/test/device_proxy_test.cpp
parentece4ba5b31ebc6f345c8e29eae1261f2f780057a (diff)
d3d12_xs: device slot 26 takes the console's struct-return form
The retail executable calls GetCustomHeapProperties with the return buffer in RCX and the device in RDX. The forwarder took RCX for the proxy and faulted. AI-assisted. (cherry picked from commit 86b8e04e4c707350a10af7ef16f77b2c2e17b1ae)
Diffstat (limited to 'runtime/test/device_proxy_test.cpp')
-rw-r--r--runtime/test/device_proxy_test.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/runtime/test/device_proxy_test.cpp b/runtime/test/device_proxy_test.cpp
index 46a853e7c..94bf428d2 100644
--- a/runtime/test/device_proxy_test.cpp
+++ b/runtime/test/device_proxy_test.cpp
@@ -3,6 +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// 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
7// hidden return pointer in RDX, so slot 14 wraps it) 8// hidden return pointer in RDX, so slot 14 wraps it)
8// slot 62 CreateComputePipelineState 9// slot 62 CreateComputePipelineState
@@ -206,6 +207,41 @@ int main(int argc, char** argv) {
206 IID_PPV_ARGS(reserved.GetAddressOf())); 207 IID_PPV_ARGS(reserved.GetAddressOf()));
207 check(SUCCEEDED(hr) && reserved != nullptr, "slot 30 forwards CreateReservedResource (stack arguments)"); 208 check(SUCCEEDED(hr) && reserved != nullptr, "slot 30 forwards CreateReservedResource (stack arguments)");
208 209
210 // Slot 26 the way the retail executable calls GetCustomHeapProperties: the buffer for the struct in RCX, the
211 // device in RDX, for the three heap types it asks about. The answer is the PC device's own, and nothing but
212 // the struct is written (the buffer sits in a pattern). On main this call read the PC vtable through the buffer.
213 check(rt::d3d12_xs::device_slot_overridden(26), "device slot 26 takes the console's struct-return form");
214 using XboxGetCustomHeapPropertiesFn =
215 D3D12_HEAP_PROPERTIES*(WINAPI*)(D3D12_HEAP_PROPERTIES*, void*, UINT, D3D12_HEAP_TYPE);
216 auto get_custom_heap = reinterpret_cast<XboxGetCustomHeapPropertiesFn>(proxy_vtbl[26]);
217 const D3D12_HEAP_TYPE heap_types[] = {D3D12_HEAP_TYPE_DEFAULT, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_TYPE_READBACK};
218 bool console_returns_buffer = true, console_matches_pc = real != nullptr, console_writes_only_struct = true;
219 for (const D3D12_HEAP_TYPE type : heap_types) {
220 struct Padded {
221 D3D12_HEAP_PROPERTIES value;
222 std::uint8_t after[64];
223 } padded;
224 std::memset(&padded, 0xA5, sizeof(padded));
225 console_returns_buffer = get_custom_heap(&padded.value, device.Get(), 1, type) == &padded.value &&
226 console_returns_buffer;
227 const D3D12_HEAP_PROPERTIES want = real ? real->GetCustomHeapProperties(1, type) : D3D12_HEAP_PROPERTIES{};
228 console_matches_pc = console_matches_pc && std::memcmp(&padded.value, &want, sizeof(want)) == 0;
229 for (const std::uint8_t byte : padded.after)
230 console_writes_only_struct = console_writes_only_struct && byte == 0xA5;
231 }
232 check(console_returns_buffer, "slot 26 console form returns the buffer's address");
233 check(console_matches_pc, "slot 26 console form writes the PC device's DEFAULT, UPLOAD and READBACK properties");
234 check(console_writes_only_struct, "slot 26 console form writes nothing past the struct");
235 check(rt::d3d12_xs::device_slot_hits(26) == 3, "slot 26 hit counter is 3");
236 check(rt::d3d12_xs::is_device_proxy(device.Get()) && rt::d3d12_xs::device_proxy_real_device(device.Get()) == real,
237 "the proxy is intact after the console-form calls");
238 // A PC C++ call through the proxy (the proxy in RCX, the buffer in RDX) is still forwarded.
239 const D3D12_HEAP_PROPERTIES pc_form = device->GetCustomHeapProperties(1, D3D12_HEAP_TYPE_UPLOAD);
240 const D3D12_HEAP_PROPERTIES pc_want = real ? real->GetCustomHeapProperties(1, D3D12_HEAP_TYPE_UPLOAD)
241 : D3D12_HEAP_PROPERTIES{};
242 check(real && std::memcmp(&pc_form, &pc_want, sizeof(pc_want)) == 0 && rt::d3d12_xs::device_slot_hits(26) == 4,
243 "slot 26 PC form still forwards GetCustomHeapProperties");
244
209 // Slot 14: descriptor heap through the proxy. The proxy wraps the real PC heap for the handle ABI. 245 // Slot 14: descriptor heap through the proxy. The proxy wraps the real PC heap for the handle ABI.
210 D3D12_DESCRIPTOR_HEAP_DESC heap_desc{}; 246 D3D12_DESCRIPTOR_HEAP_DESC heap_desc{};
211 heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; 247 heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;