diff options
| author | tedin7 <tommasoderosa94@gmail.com> | 2026-11-23 17:18:32 +0100 |
|---|---|---|
| committer | tedin7 <tommasoderosa94@gmail.com> | 2026-11-23 17:18:32 +0100 |
| commit | 40360ccb4fdc9fd8bc2b3c2425ca859913fdc451 (patch) | |
| tree | f0bcdae6a1f1fc228153860e2316c2afa06cb7e9 /runtime/test/device_proxy_test.cpp | |
| parent | 824a17f01a5f3f02ba4d8e8dc3d2936806093d96 (diff) | |
| parent | 0d73e8b95d9af460227efbce4b7ec182764abe2d (diff) | |
Merge #6964 (slot 26 console form) into fast-rtbudget: slot 26 from #6964, slot 25 return-buffer form kept from #6973
Diffstat (limited to 'runtime/test/device_proxy_test.cpp')
| -rw-r--r-- | runtime/test/device_proxy_test.cpp | 61 |
1 files changed, 40 insertions, 21 deletions
diff --git a/runtime/test/device_proxy_test.cpp b/runtime/test/device_proxy_test.cpp index f4c7eb445..3cf5ff5c0 100644 --- a/runtime/test/device_proxy_test.cpp +++ b/runtime/test/device_proxy_test.cpp | |||
| @@ -200,25 +200,12 @@ 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 | 203 | // Slot 25 returns a struct wider than 8 bytes. The console title calls it 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 | 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 | 205 | // (measured for slot 26 on the retail executable). Call slot 25 that way through a raw function pointer and compare |
| 206 | // with the PC device's own answers. | 206 | // with the PC device's own answer. |
| 207 | check(rt::d3d12_xs::device_slot_overridden(25), "device slot 25 is the C-ABI GetResourceAllocationInfo override"); | 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) { | 208 | 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, | 209 | using AllocInfoFn = D3D12_RESOURCE_ALLOCATION_INFO*(WINAPI*)(D3D12_RESOURCE_ALLOCATION_INFO*, void*, UINT, UINT, |
| 223 | const D3D12_RESOURCE_DESC*); | 210 | const D3D12_RESOURCE_DESC*); |
| 224 | auto get_alloc_info = reinterpret_cast<AllocInfoFn>(proxy_vtbl[25]); | 211 | auto get_alloc_info = reinterpret_cast<AllocInfoFn>(proxy_vtbl[25]); |
| @@ -230,11 +217,8 @@ int main(int argc, char** argv) { | |||
| 230 | check(got.SizeInBytes == want.SizeInBytes && got.Alignment == want.Alignment, | 217 | 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"); | 218 | "slot 25 (C ABI) writes the PC device's GetResourceAllocationInfo into the caller's buffer"); |
| 232 | 219 | ||
| 233 | // The runtime's own code calls the proxy through d3d12.h (PC form: this, then the return buffer). Both | 220 | // The runtime's own code calls the proxy through d3d12.h (PC form: this, then the return buffer). Slot 25 |
| 234 | // slots still answer that form. | 221 | // still answers 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); | 222 | const D3D12_RESOURCE_ALLOCATION_INFO pc_info = device->GetResourceAllocationInfo(0, 1, &desc); |
| 239 | check(pc_info.SizeInBytes == want.SizeInBytes && pc_info.Alignment == want.Alignment, | 223 | check(pc_info.SizeInBytes == want.SizeInBytes && pc_info.Alignment == want.Alignment, |
| 240 | "slot 25 still answers the PC (C++) form"); | 224 | "slot 25 still answers the PC (C++) form"); |
| @@ -247,6 +231,41 @@ int main(int argc, char** argv) { | |||
| 247 | IID_PPV_ARGS(reserved.GetAddressOf())); | 231 | IID_PPV_ARGS(reserved.GetAddressOf())); |
| 248 | check(SUCCEEDED(hr) && reserved != nullptr, "slot 30 forwards CreateReservedResource (stack arguments)"); | 232 | check(SUCCEEDED(hr) && reserved != nullptr, "slot 30 forwards CreateReservedResource (stack arguments)"); |
| 249 | 233 | ||
| 234 | // Slot 26 the way the retail executable calls GetCustomHeapProperties: the buffer for the struct in RCX, the | ||
| 235 | // device in RDX, for the three heap types it asks about. The answer is the PC device's own, and nothing but | ||
| 236 | // the struct is written (the buffer sits in a pattern). On main this call read the PC vtable through the buffer. | ||
| 237 | check(rt::d3d12_xs::device_slot_overridden(26), "device slot 26 takes the console's struct-return form"); | ||
| 238 | using XboxGetCustomHeapPropertiesFn = | ||
| 239 | D3D12_HEAP_PROPERTIES*(WINAPI*)(D3D12_HEAP_PROPERTIES*, void*, UINT, D3D12_HEAP_TYPE); | ||
| 240 | auto get_custom_heap = reinterpret_cast<XboxGetCustomHeapPropertiesFn>(proxy_vtbl[26]); | ||
| 241 | const D3D12_HEAP_TYPE heap_types[] = {D3D12_HEAP_TYPE_DEFAULT, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_TYPE_READBACK}; | ||
| 242 | bool console_returns_buffer = true, console_matches_pc = real != nullptr, console_writes_only_struct = true; | ||
| 243 | for (const D3D12_HEAP_TYPE type : heap_types) { | ||
| 244 | struct Padded { | ||
| 245 | D3D12_HEAP_PROPERTIES value; | ||
| 246 | std::uint8_t after[64]; | ||
| 247 | } padded; | ||
| 248 | std::memset(&padded, 0xA5, sizeof(padded)); | ||
| 249 | console_returns_buffer = get_custom_heap(&padded.value, device.Get(), 1, type) == &padded.value && | ||
| 250 | console_returns_buffer; | ||
| 251 | const D3D12_HEAP_PROPERTIES want = real ? real->GetCustomHeapProperties(1, type) : D3D12_HEAP_PROPERTIES{}; | ||
| 252 | console_matches_pc = console_matches_pc && std::memcmp(&padded.value, &want, sizeof(want)) == 0; | ||
| 253 | for (const std::uint8_t byte : padded.after) | ||
| 254 | console_writes_only_struct = console_writes_only_struct && byte == 0xA5; | ||
| 255 | } | ||
| 256 | check(console_returns_buffer, "slot 26 console form returns the buffer's address"); | ||
| 257 | check(console_matches_pc, "slot 26 console form writes the PC device's DEFAULT, UPLOAD and READBACK properties"); | ||
| 258 | check(console_writes_only_struct, "slot 26 console form writes nothing past the struct"); | ||
| 259 | check(rt::d3d12_xs::device_slot_hits(26) == 3, "slot 26 hit counter is 3"); | ||
| 260 | check(rt::d3d12_xs::is_device_proxy(device.Get()) && rt::d3d12_xs::device_proxy_real_device(device.Get()) == real, | ||
| 261 | "the proxy is intact after the console-form calls"); | ||
| 262 | // A PC C++ call through the proxy (the proxy in RCX, the buffer in RDX) is still forwarded. | ||
| 263 | const D3D12_HEAP_PROPERTIES pc_form = device->GetCustomHeapProperties(1, D3D12_HEAP_TYPE_UPLOAD); | ||
| 264 | const D3D12_HEAP_PROPERTIES pc_want = real ? real->GetCustomHeapProperties(1, D3D12_HEAP_TYPE_UPLOAD) | ||
| 265 | : D3D12_HEAP_PROPERTIES{}; | ||
| 266 | check(real && std::memcmp(&pc_form, &pc_want, sizeof(pc_want)) == 0 && rt::d3d12_xs::device_slot_hits(26) == 4, | ||
| 267 | "slot 26 PC form still forwards GetCustomHeapProperties"); | ||
| 268 | |||
| 250 | // Slot 14: descriptor heap through the proxy. The proxy wraps the real PC heap for the handle ABI. | 269 | // Slot 14: descriptor heap through the proxy. The proxy wraps the real PC heap for the handle ABI. |
| 251 | D3D12_DESCRIPTOR_HEAP_DESC heap_desc{}; | 270 | D3D12_DESCRIPTOR_HEAP_DESC heap_desc{}; |
| 252 | heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; | 271 | heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; |