From 5dbc30bed79b399b527460501c0ee33f28712096 Mon Sep 17 00:00:00 2001 From: sneylol Date: Mon, 23 Nov 2026 16:32:28 +0100 Subject: [PATCH 01/13] 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 --- docs/design.md | 4 +- runtime/shims/d3d12_xs_device.cpp | 76 ++++++++++++++++++++++++++---- runtime/shims/d3d12_xs_device.h | 3 ++ runtime/test/device_proxy_test.cpp | 41 ++++++++++++++++ 4 files changed, 113 insertions(+), 11 deletions(-) diff --git a/docs/design.md b/docs/design.md index 703c870c69..fc9c324a0b 100644 --- a/docs/design.md +++ b/docs/design.md @@ -182,7 +182,9 @@ Full-scan indexes are also saved to `%LOCALAPPDATA%\RpfPreview\Indexes`, so the `CreateCommittedResource` with the Xbox `0x101`/`0x1` layout word replaced by the PC layout. Slots 9/10 are `ID3D12DescriptorHeap` methods, not device methods. The PC heap getters take a hidden return pointer (RDX), while Xbox expects the 8-byte handle in RAX, so slot 14 wraps the heap and slots 9/10 convert it. The heap holds - a reference to the device proxy and its `GetDevice` returns that same proxy. Queues, fences, command lists and + a reference to the device proxy and its `GetDevice` returns that same proxy. The retail executable calls the + struct-returning device methods with the C ABI, return buffer first: `GetCustomHeapProperties` (slot 26) is + measured as `rcx` = buffer, `rdx` = device. Slots 25 and 26 take that form, and still take the PC one. Queues, fences, command lists and `PresentX` extensions remain unimplemented. - PSO metadata is a new variant (`PSIN`, `LSCH` schema, `LENM`, `LSNS`, `LGID`, `LRSC`, `CHKS`, little-endian). CodeWalker's parser reads the container but not the new schema; dump it once the exe gives the field names. diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 590f86bd73..72fa1b3bc4 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -3,12 +3,13 @@ // How forwarding works: the proxy object's first word is a vtable built once from one thunk per slot. A thunk // receives the proxy in RCX, replaces it with the PC device pointer from offset 8, and tail-calls the PC method at // the same index through a 15-argument integer prototype. Every PC D3D12 device method takes integer/pointer -// arguments only, so the x64 registers and stack words line up exactly; methods that return a struct keep their -// hidden return pointer in RDX, which is passed through as the first argument unchanged. The measured exceptions -// are IUnknown (0-2), slot 14 (which wraps the heap), 62 and 76, plus the heap proxy's 9/10 conversion from the -// PC hidden-pointer form to the Xbox RAX form. Slots 8/75 (command queues), 36 (fences) and 32 (a shared fence) wrap -// what they create in queue and fence proxies built the same way, and slots 31/34/35/45/46/50 hand the real objects -// behind heap, queue and fence proxies to the real device (see the command queue and fence section). +// arguments only, so the x64 registers and stack words line up exactly. The measured exceptions are IUnknown (0-2), +// slot 14 (which wraps the heap), 62 and 76, the struct-returning slots 25 and 26 (the title calls them with the C +// ABI, hidden return pointer first: see "Struct-returning device methods" below), plus the heap proxy's 9/10 +// conversion from the PC hidden-pointer form to the Xbox RAX form. Slots 8/75 (command queues), 36 (fences) and 32 +// (a shared fence) wrap what they create in queue and fence proxies built the same way, and slots 31/34/35/45/46/50 +// hand the real objects behind heap, queue and fence proxies to the real device (see the command queue and fence +// section). // // A thunk declares 14 argument words, but the title passes only as many as the method takes, so the caller's frame // may end right after the four register homes. The compiler owns a function's incoming stack-argument slots and may @@ -111,7 +112,8 @@ const char* slot_name(unsigned slot) { case 11: return "CreateComputePipelineState (PC slot 11)"; case 14: return "CreateDescriptorHeap"; case 16: return "CreateRootSignature"; - case 25: return "GetResourceAllocationInfo"; + case 25: return "GetResourceAllocationInfo (C or PC form)"; + case 26: return "GetCustomHeapProperties (C or PC form)"; case 27: return "CreateCommittedResource (PC slot 27)"; case 31: return "CreateSharedHandle (proxies unwrapped)"; case 32: return "OpenSharedHandle (a fence comes back wrapped)"; @@ -1387,10 +1389,64 @@ void fill_vtable(void** vtable, std::index_sequence) { ((vtable[I] = reinterpret_cast(&proxy_slot(I)>) ), ...); } +// ---- Struct-returning device methods: the console title calls them with the C ABI ---- +// +// The PC vtable (MSVC C++) takes `this` in RCX and, for a struct return, the hidden return pointer in RDX. The console +// title does not. Measured with the retail game_scarlett_master.exe 1.0.2.1 under gta6rt --run: its first +// GetCustomHeapProperties call (device slot 26) is `rcx = return buffer on the caller's stack, rdx = the device, +// r8 = node mask 1, r9 = heap type` (DEFAULT, then UPLOAD), and it reads the result from that buffer. That is the C +// convention, where a struct wider than 8 bytes comes back through a hidden *first* argument (an 8-byte one comes back +// in RAX, which is what the heap proxy's slots 9/10 already measured). The generic forwarder took the return buffer +// for the device and crashed on its vtable. +// +// The runtime's own code and tests still call the proxy through d3d12.h, in the PC form, so these thunks accept both, +// as the heap proxy's 9/10 do: whichever of the first two arguments is the device proxy (its first word is the proxy +// vtable) is `this`, and the other is the return buffer. A return buffer never starts with that vtable pointer: the +// C-form caller hands over uninitialised memory to be written, and the PC-form caller is this runtime. The buffer is +// returned in RAX, as both conventions require. +// slot 25 GetResourceAllocationInfo -> D3D12_RESOURCE_ALLOCATION_INFO (16 bytes): same rule as slot 26 (inferred, +// no call site measured yet) +// slot 26 GetCustomHeapProperties -> D3D12_HEAP_PROPERTIES (20 bytes): measured +// Not changed: slot 43 GetAdapterLuid (an 8-byte LUID; by the same rule the title would expect it in RAX, but no call +// site is measured yet, so it still forwards in the PC form). +void** get_vtable(); + +struct StructReturnCall { + DeviceProxy* self; + void* ret; +}; + +StructReturnCall struct_return_call(std::uint64_t a0, std::uint64_t a1) { + void** const vtable = get_vtable(); + if (a0 && *reinterpret_cast(a0) == vtable) // PC form: this, return buffer + return {reinterpret_cast(a0), reinterpret_cast(a1)}; + return {reinterpret_cast(a1), reinterpret_cast(a0)}; // C form: return buffer, this +} + +void* WINAPI proxy_get_resource_allocation_info(std::uint64_t a0, std::uint64_t a1, std::uint64_t visible_mask, + std::uint64_t count, const D3D12_RESOURCE_DESC* descs) { + note_slot(25); + const StructReturnCall call = struct_return_call(a0, a1); + *static_cast(call.ret) = call.self->real->GetResourceAllocationInfo( + static_cast(visible_mask), static_cast(count), descs); + return call.ret; +} + +void* WINAPI proxy_get_custom_heap_properties(std::uint64_t a0, std::uint64_t a1, std::uint64_t node_mask, + std::uint64_t heap_type) { + note_slot(26); + const StructReturnCall call = struct_return_call(a0, a1); + *static_cast(call.ret) = call.self->real->GetCustomHeapProperties( + static_cast(node_mask), static_cast(static_cast(heap_type))); + return call.ret; +} + void** get_vtable() { static void** vtable = [] { static void* storage[kMaxSlots]; fill_vtable(storage, std::make_index_sequence{}); + storage[25] = reinterpret_cast(&proxy_get_resource_allocation_info); + storage[26] = reinterpret_cast(&proxy_get_custom_heap_properties); return storage; }(); return vtable; @@ -1515,9 +1571,9 @@ ID3D12Device* device_proxy_real_device(const void* device) { } bool device_slot_overridden(unsigned slot) { - return slot <= 2 || slot == 8 || slot == 9 || slot == 14 || slot == 31 || slot == 32 || slot == 34 || slot == 35 || - slot == 36 || slot == 45 || slot == 46 || slot == 50 || slot == 62 || slot == 67 || - slot == 75 || slot == 76; + return slot <= 2 || slot == 8 || slot == 9 || slot == 14 || slot == 25 || slot == 26 || slot == 31 || slot == 32 || + slot == 34 || slot == 35 || slot == 36 || slot == 45 || slot == 46 || slot == 50 || slot == 62 || + slot == 67 || slot == 75 || slot == 76; } bool is_queue_proxy(const void* queue) { return is_child_proxy(queue); } diff --git a/runtime/shims/d3d12_xs_device.h b/runtime/shims/d3d12_xs_device.h index 8ff508e6fd..95ba2ef98a 100644 --- a/runtime/shims/d3d12_xs_device.h +++ b/runtime/shims/d3d12_xs_device.h @@ -7,6 +7,9 @@ // (+0x00 root signature, +0x28 code, +0x30 size) to D3D12_COMPUTE_PIPELINE_STATE_DESC and forwards // to PC CreateComputePipelineState (slot 11). The PC slot 67 is CreateProtectedResourceSession1. // slot 76 resource creation -> PC CreateCommittedResource (PC slot 27), with the Xbox layout word ignored. +// slot 26 GetCustomHeapProperties, called by the retail title with the C ABI: return buffer in RCX, the device +// in RDX (the PC form is `this` in RCX, return buffer in RDX). Slot 25 (GetResourceAllocationInfo, also a +// struct wider than 8 bytes) takes the same form by the same rule. Both accept either form. // The measured slots 9/10 (GetCPU/GPUDescriptorHandleForHeapStart) are ID3D12DescriptorHeap methods, not device // methods: the PC device's 9/10 are CreateCommandAllocator/CreateGraphicsPipelineState and are forwarded unchanged. // On the PC heap those getters use the hidden return pointer in RDX; the Xbox ABI returns the 8-byte handle in diff --git a/runtime/test/device_proxy_test.cpp b/runtime/test/device_proxy_test.cpp index d5a6ec04e1..f30207336c 100644 --- a/runtime/test/device_proxy_test.cpp +++ b/runtime/test/device_proxy_test.cpp @@ -3,6 +3,7 @@ // It creates the proxy through the registered d3d12_xs!D3D12XboxCreateDevice shim, then calls the measured Xbox // slots exactly as the guest would (raw function pointers, not the C++ interface): // slot 14 CreateDescriptorHeap (returns a heap proxy) +// slot 25/26 GetResourceAllocationInfo/GetCustomHeapProperties in the title's C form (return buffer first) // heap 9/10 GetCPU/GetGPUDescriptorHandleForHeapStart (Xbox: 8-byte handle in RAX; the PC heap uses the // hidden return pointer in RDX, so slot 14 wraps it) // slot 62 CreateComputePipelineState @@ -199,6 +200,46 @@ int main(int argc, char** argv) { const LUID real_luid = real ? real->GetAdapterLuid() : LUID{}; check(proxy_luid.LowPart == real_luid.LowPart && proxy_luid.HighPart == real_luid.HighPart, "slot 43 forwards GetAdapterLuid (struct return)"); + // Slots 25 and 26 return a struct wider than 8 bytes. The console title calls them with the C ABI: the hidden + // return pointer first (RCX), then the device (RDX), then the arguments, and the buffer comes back in RAX + // (measured for slot 26 on the retail executable). Call them that way through raw function pointers and compare + // with the PC device's own answers. + check(rt::d3d12_xs::device_slot_overridden(25), "device slot 25 is the C-ABI GetResourceAllocationInfo override"); + check(rt::d3d12_xs::device_slot_overridden(26), "device slot 26 is the C-ABI GetCustomHeapProperties override"); + if (real) { + using HeapPropsFn = D3D12_HEAP_PROPERTIES*(WINAPI*)(D3D12_HEAP_PROPERTIES*, void*, UINT, D3D12_HEAP_TYPE); + auto get_heap_props = reinterpret_cast(proxy_vtbl[26]); + for (D3D12_HEAP_TYPE type : {D3D12_HEAP_TYPE_DEFAULT, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_TYPE_READBACK}) { + D3D12_HEAP_PROPERTIES got; + std::memset(&got, 0xcd, sizeof(got)); + D3D12_HEAP_PROPERTIES* returned = get_heap_props(&got, device.Get(), 1, type); + const D3D12_HEAP_PROPERTIES want = real->GetCustomHeapProperties(1, type); + check(returned == &got, "slot 26 returns the caller's buffer in RAX"); + check(std::memcmp(&got, &want, sizeof(got)) == 0, + "slot 26 (C ABI) writes the PC device's GetCustomHeapProperties into the caller's buffer"); + } + + using AllocInfoFn = D3D12_RESOURCE_ALLOCATION_INFO*(WINAPI*)(D3D12_RESOURCE_ALLOCATION_INFO*, void*, UINT, UINT, + const D3D12_RESOURCE_DESC*); + auto get_alloc_info = reinterpret_cast(proxy_vtbl[25]); + const D3D12_RESOURCE_DESC desc = buffer_desc(); + D3D12_RESOURCE_ALLOCATION_INFO got{~0ull, ~0ull}; + D3D12_RESOURCE_ALLOCATION_INFO* returned = get_alloc_info(&got, device.Get(), 0, 1, &desc); + const D3D12_RESOURCE_ALLOCATION_INFO want = real->GetResourceAllocationInfo(0, 1, &desc); + check(returned == &got, "slot 25 returns the caller's buffer in RAX"); + check(got.SizeInBytes == want.SizeInBytes && got.Alignment == want.Alignment, + "slot 25 (C ABI) writes the PC device's GetResourceAllocationInfo into the caller's buffer"); + + // The runtime's own code calls the proxy through d3d12.h (PC form: this, then the return buffer). Both + // slots still answer that form. + const D3D12_HEAP_PROPERTIES pc_props = device->GetCustomHeapProperties(1, D3D12_HEAP_TYPE_UPLOAD); + const D3D12_HEAP_PROPERTIES pc_want = real->GetCustomHeapProperties(1, D3D12_HEAP_TYPE_UPLOAD); + check(std::memcmp(&pc_props, &pc_want, sizeof(pc_props)) == 0, "slot 26 still answers the PC (C++) form"); + const D3D12_RESOURCE_ALLOCATION_INFO pc_info = device->GetResourceAllocationInfo(0, 1, &desc); + check(pc_info.SizeInBytes == want.SizeInBytes && pc_info.Alignment == want.Alignment, + "slot 25 still answers the PC (C++) form"); + } + D3D12_RESOURCE_DESC reserved_desc = buffer_desc(); reserved_desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; ComPtr reserved; From 86b8e04e4c707350a10af7ef16f77b2c2e17b1ae Mon Sep 17 00:00:00 2001 From: Senne Cools <113857183+sennecools@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:33:12 +0100 Subject: [PATCH 02/13] 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. --- docs/d3d12_vulkan.md | 6 +++ runtime/shims/d3d12_xs_device.cpp | 32 ++++++++++++++-- runtime/shims/d3d12_xs_device.h | 9 ++++- runtime/test/device_proxy_test.cpp | 36 ++++++++++++++++++ runtime/test/xs_proxy_mock_test.cpp | 59 ++++++++++++++++++++++++++++- 5 files changed, 134 insertions(+), 8 deletions(-) diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index 3f112891da..3fdd77324b 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -2184,6 +2184,12 @@ The trace will enumerate them. `WRITE_COMBINE`/`L0`, `READBACK` `WRITE_BACK`/`L0`, `GPU_UPLOAD` `WRITE_COMBINE`/`L1`, all with type `CUSTOM` and node masks 1. `CUSTOM`, unknown types and node masks above 1 get an all-zero answer, logged. The test compares `DEFAULT`, `UPLOAD` and `READBACK` byte for byte with the host runtime's answer (RTX 4090: identical). + The retail executable calls it (device slot 26) with the buffer for the returned struct in RCX and the device in + RDX, node mask in R8 and heap type in R9: three calls right after device creation, node mask 1 and types 1, 2 + and 3 (measured under `gta6rt --run` with a register probe in the slot's thunk). A PC C++ method has the device + in RCX and the buffer in RDX, so the Xbox-ABI proxy takes the console form when RDX holds the proxy + (`d3d12_xs_device.cpp`; `xs_proxy_mock_test`, `device_proxy_test`). Slots 25 and 43 return structs too; the + executable has not been seen calling them yet, so the proxy still forwards them in the PC form. - Residency and power (D3D-33) are no-ops that still check their arguments (`d3d12_vulkan_device.cpp`, tested in `d3d12_vulkan_device_test`). Vulkan has no residency API: memory from `vkAllocateMemory` stays usable until `vkFreeMemory`, and paging under pressure is the kernel driver's job, so every pageable object is always resident. diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 590f86bd73..653a50fd7d 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -5,8 +5,8 @@ // the same index through a 15-argument integer prototype. Every PC D3D12 device method takes integer/pointer // arguments only, so the x64 registers and stack words line up exactly; methods that return a struct keep their // hidden return pointer in RDX, which is passed through as the first argument unchanged. The measured exceptions -// are IUnknown (0-2), slot 14 (which wraps the heap), 62 and 76, plus the heap proxy's 9/10 conversion from the -// PC hidden-pointer form to the Xbox RAX form. Slots 8/75 (command queues), 36 (fences) and 32 (a shared fence) wrap +// are IUnknown (0-2), slot 14 (which wraps the heap), 26 (the title passes the return buffer in RCX and the device in +// RDX), 62 and 76, plus the heap proxy's 9/10 conversion from the PC hidden-pointer form to the Xbox RAX form. Slots 8/75 (command queues), 36 (fences) and 32 (a shared fence) wrap // what they create in queue and fence proxies built the same way, and slots 31/34/35/45/46/50 hand the real objects // behind heap, queue and fence proxies to the real device (see the command queue and fence section). // @@ -112,6 +112,7 @@ const char* slot_name(unsigned slot) { case 14: return "CreateDescriptorHeap"; case 16: return "CreateRootSignature"; case 25: return "GetResourceAllocationInfo"; + case 26: return "GetCustomHeapProperties"; case 27: return "CreateCommittedResource (PC slot 27)"; case 31: return "CreateSharedHandle (proxies unwrapped)"; case 32: return "OpenSharedHandle (a fence comes back wrapped)"; @@ -1318,6 +1319,21 @@ HRESULT proxy_create_resource(DeviceProxy* self, const D3D12_HEAP_PROPERTIES* he *riid, out); } +// Device slot 26, GetCustomHeapProperties, as the retail executable calls it. Measured on 1.0.2.1 under +// gta6rt --run with a register probe in this slot's thunk: three calls right after device creation, each with the +// device proxy in RDX and not in RCX, R8 = 1 and R9 = 1, 2, 3 (node mask 1; DEFAULT, UPLOAD, READBACK). So the +// buffer for the returned D3D12_HEAP_PROPERTIES is in RCX and the device in RDX. That is how x64 passes them to a +// plain function that takes the device as its first argument and returns a struct; a PC C++ method has the device +// in RCX and the buffer in RDX. The forwarder took RCX for the proxy, read the PC vtable out of the title's stack +// buffer and faulted. The buffer's address goes back in RAX, as that convention returns it; what the title does with +// RAX is not measured. +D3D12_HEAP_PROPERTIES* proxy_get_custom_heap_properties(D3D12_HEAP_PROPERTIES* out, DeviceProxy* self, + UINT node_mask, D3D12_HEAP_TYPE heap_type) { + note_slot(26); + *out = self->real->GetCustomHeapProperties(node_mask, heap_type); + return out; +} + template std::uint64_t WINAPI proxy_slot(DeviceProxy* self, std::uint64_t a1, std::uint64_t a2, std::uint64_t a3, std::uint64_t a4, std::uint64_t a5, std::uint64_t a6, std::uint64_t a7, @@ -1368,6 +1384,14 @@ std::uint64_t WINAPI proxy_slot(DeviceProxy* self, std::uint64_t a1, std::uint64 reinterpret_cast(a5), reinterpret_cast(a6), reinterpret_cast(a7))); } else { + if constexpr (Slot == 26) { + // The console form has the device in RDX. A PC C++ caller has the proxy in RCX and its return buffer in + // RDX; that call goes to the forwarder below, as before. + if (is_device_proxy(reinterpret_cast(a1))) + return reinterpret_cast(proxy_get_custom_heap_properties( + reinterpret_cast(self), reinterpret_cast(a1), + static_cast(a2), static_cast(static_cast(a3)))); + } note_slot(Slot); if (Slot >= self->slot_count) return hr_to_u64(refuse_beyond_device(Slot, self->slot_count)); @@ -1515,8 +1539,8 @@ ID3D12Device* device_proxy_real_device(const void* device) { } bool device_slot_overridden(unsigned slot) { - return slot <= 2 || slot == 8 || slot == 9 || slot == 14 || slot == 31 || slot == 32 || slot == 34 || slot == 35 || - slot == 36 || slot == 45 || slot == 46 || slot == 50 || slot == 62 || slot == 67 || + return slot <= 2 || slot == 8 || slot == 9 || slot == 14 || slot == 26 || slot == 31 || slot == 32 || slot == 34 || + slot == 35 || slot == 36 || slot == 45 || slot == 46 || slot == 50 || slot == 62 || slot == 67 || slot == 75 || slot == 76; } diff --git a/runtime/shims/d3d12_xs_device.h b/runtime/shims/d3d12_xs_device.h index 8ff508e6fd..3168f653b4 100644 --- a/runtime/shims/d3d12_xs_device.h +++ b/runtime/shims/d3d12_xs_device.h @@ -1,6 +1,11 @@ // Xbox-ABI proxy around a PC ID3D12Device. // // Measured Xbox device deviations used here (vtable indices, x64): +// slot 26 GetCustomHeapProperties, the PC slot, but the retail executable calls it with the buffer for the +// returned struct in RCX and the device in RDX (node mask in R8, heap type in R9). A PC C++ method has +// the device in RCX and the buffer in RDX. The thunk takes the console form when RDX holds a device +// proxy, and forwards the PC form otherwise. Slots 25 and 43 return structs too; no call of them by +// the executable has been seen yet, so they are forwarded in the PC form. // slot 62 CreateComputePipelineState(desc, w2, w3, iid, out): two words (0 from XboxBvhBuilder, meaning unknown) // before the IID. The PC slot 62 is CreateStateObject. // slot 67 CreateComputePipelineState from native code (desc, iid, out): converts the Xbox native-code desc @@ -78,8 +83,8 @@ unsigned device_proxy_slot_count(const void* device); ID3D12Device* device_proxy_real_device(const void* device); // True for slots the proxy handles itself rather than forwarding verbatim: IUnknown (0-2), 8 and 75 (queue -// proxies), 9 (allocator proxies), 14, 31/34/35/45/46/50 (proxies unwrapped), 32 and 36 (fence proxies), 62, 67 -// and 76. Slot 10 is intentionally false: the measured 9/10 handle conversion is on the heap proxy, and device +// proxies), 9 (allocator proxies), 14, 26 (the console's struct-return form), 31/34/35/45/46/50 (proxies unwrapped), +// 32 and 36 (fence proxies), 62, 67 and 76. Slot 10 is intentionally false: the measured 9/10 handle conversion is on the heap proxy, and device // slot 9 is CreateCommandAllocator, which the proxy handles for the allocator proxy. bool device_slot_overridden(unsigned slot); diff --git a/runtime/test/device_proxy_test.cpp b/runtime/test/device_proxy_test.cpp index d5a6ec04e1..e20e9df1d0 100644 --- a/runtime/test/device_proxy_test.cpp +++ b/runtime/test/device_proxy_test.cpp @@ -3,6 +3,7 @@ // It creates the proxy through the registered d3d12_xs!D3D12XboxCreateDevice shim, then calls the measured Xbox // slots exactly as the guest would (raw function pointers, not the C++ interface): // slot 14 CreateDescriptorHeap (returns a heap proxy) +// slot 26 GetCustomHeapProperties with the struct's buffer in RCX and the device in RDX // heap 9/10 GetCPU/GetGPUDescriptorHandleForHeapStart (Xbox: 8-byte handle in RAX; the PC heap uses the // hidden return pointer in RDX, so slot 14 wraps it) // slot 62 CreateComputePipelineState @@ -206,6 +207,41 @@ int main(int argc, char** argv) { IID_PPV_ARGS(reserved.GetAddressOf())); check(SUCCEEDED(hr) && reserved != nullptr, "slot 30 forwards CreateReservedResource (stack arguments)"); + // Slot 26 the way the retail executable calls GetCustomHeapProperties: the buffer for the struct in RCX, the + // device in RDX, for the three heap types it asks about. The answer is the PC device's own, and nothing but + // the struct is written (the buffer sits in a pattern). On main this call read the PC vtable through the buffer. + check(rt::d3d12_xs::device_slot_overridden(26), "device slot 26 takes the console's struct-return form"); + using XboxGetCustomHeapPropertiesFn = + D3D12_HEAP_PROPERTIES*(WINAPI*)(D3D12_HEAP_PROPERTIES*, void*, UINT, D3D12_HEAP_TYPE); + auto get_custom_heap = reinterpret_cast(proxy_vtbl[26]); + const D3D12_HEAP_TYPE heap_types[] = {D3D12_HEAP_TYPE_DEFAULT, D3D12_HEAP_TYPE_UPLOAD, D3D12_HEAP_TYPE_READBACK}; + bool console_returns_buffer = true, console_matches_pc = real != nullptr, console_writes_only_struct = true; + for (const D3D12_HEAP_TYPE type : heap_types) { + struct Padded { + D3D12_HEAP_PROPERTIES value; + std::uint8_t after[64]; + } padded; + std::memset(&padded, 0xA5, sizeof(padded)); + console_returns_buffer = get_custom_heap(&padded.value, device.Get(), 1, type) == &padded.value && + console_returns_buffer; + const D3D12_HEAP_PROPERTIES want = real ? real->GetCustomHeapProperties(1, type) : D3D12_HEAP_PROPERTIES{}; + console_matches_pc = console_matches_pc && std::memcmp(&padded.value, &want, sizeof(want)) == 0; + for (const std::uint8_t byte : padded.after) + console_writes_only_struct = console_writes_only_struct && byte == 0xA5; + } + check(console_returns_buffer, "slot 26 console form returns the buffer's address"); + check(console_matches_pc, "slot 26 console form writes the PC device's DEFAULT, UPLOAD and READBACK properties"); + check(console_writes_only_struct, "slot 26 console form writes nothing past the struct"); + check(rt::d3d12_xs::device_slot_hits(26) == 3, "slot 26 hit counter is 3"); + check(rt::d3d12_xs::is_device_proxy(device.Get()) && rt::d3d12_xs::device_proxy_real_device(device.Get()) == real, + "the proxy is intact after the console-form calls"); + // A PC C++ call through the proxy (the proxy in RCX, the buffer in RDX) is still forwarded. + const D3D12_HEAP_PROPERTIES pc_form = device->GetCustomHeapProperties(1, D3D12_HEAP_TYPE_UPLOAD); + const D3D12_HEAP_PROPERTIES pc_want = real ? real->GetCustomHeapProperties(1, D3D12_HEAP_TYPE_UPLOAD) + : D3D12_HEAP_PROPERTIES{}; + check(real && std::memcmp(&pc_form, &pc_want, sizeof(pc_want)) == 0 && rt::d3d12_xs::device_slot_hits(26) == 4, + "slot 26 PC form still forwards GetCustomHeapProperties"); + // Slot 14: descriptor heap through the proxy. The proxy wraps the real PC heap for the handle ABI. D3D12_DESCRIPTOR_HEAP_DESC heap_desc{}; heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp index f115b6655e..5d4ad5d410 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -7,6 +7,7 @@ // - OpenSharedHandle of a fence (as ID3D12Fence, IUnknown, Fence1), of a non-fence object, of an invalid handle, // and with a null output or IID, with the references of every object it touches; // - allocation failures in the proxy (operator new, the arrays it unwraps), injected in this executable only; +// - device slot 26 called the console's way (the struct's buffer in RCX, the device in RDX) and the PC way; // - --fail-virtualalloc / --fail-virtualprotect / --fail-veh: the guard region's setup failing, injected by // patching this executable's own import table before the first proxy table is built (one process each). // Every device, queue, fence and resource here is a mock that records the calls it gets. No game data, no Xbox DLLs. @@ -75,6 +76,7 @@ enum class Kind { device, queue, fence, resource, allocator }; constexpr unsigned kMockSlots = 128; constexpr std::uint64_t kFenceHandle = 0x1000, kResourceHandle = 0x2000; // the handles the mock device opens constexpr std::uint64_t kCompletedValue = 7; // what a mock fence's slot 8 returns +constexpr UINT kHeapMarker = 0x26262626; // the VisibleNodeMask a mock device's slot 26 answers // {5d1e0c4a-2b7f-4e61-9a3d-8c4b2f1e6a70}: an interface the mock queue implements that the proxy does not model. constexpr GUID kExtraIid{0x5d1e0c4a, 0x2b7f, 0x4e61, {0x9a, 0x3d, 0x8c, 0x4b, 0x2f, 0x1e, 0x6a, 0x70}}; @@ -177,6 +179,15 @@ std::uint64_t mock_call(Mock* m, unsigned slot, const std::uint64_t* words) { return static_cast(E_INVALIDARG); case 34: case 35: case 46: copy_array(m, slot, a2, a1); break; // (count, objects, ...) case 45: copy_array(m, slot, a1, a3); break; // (fences, values, count, ...) + case 26: { // GetCustomHeapProperties, the PC method: (return buffer, node mask, heap type) + auto* out = reinterpret_cast(a1); + if (!out) break; + *out = {}; + out->Type = static_cast(static_cast(a3)); + out->CreationNodeMask = static_cast(a2); + out->VisibleNodeMask = kHeapMarker; + return a1; // a struct-returning method hands the buffer's address back in RAX + } case 50: copy_array(m, slot, a3, a2); break; // (flags, count, objects, fence, value) default: break; } @@ -648,7 +659,51 @@ int check_allocators() { return 0; } -// ---- 7. The refused tail and the guard region ---- +// ---- 7. Device slot 26, GetCustomHeapProperties, the console's way and the PC's ---- + +int check_custom_heap_properties() { + Mock* mock = nullptr; + void* device = make_device(mock, 0, true); + EXPECT(device && xs::device_slot_overridden(26)); + void* const* vtable = *reinterpret_cast(device); + + // The retail executable's call: the buffer for the struct in RCX, the device in RDX, node mask and heap type in + // R8 and R9 (their upper halves are not the callee's to read). The buffer sits inside a pattern that must stay. + struct Padded { + std::uint8_t before[16]; + D3D12_HEAP_PROPERTIES value; + std::uint8_t after[64]; + } padded; + std::memset(&padded, 0xA5, sizeof(padded)); + using ConsoleFn = std::uint64_t(WINAPI*)(void*, void*, std::uint64_t, std::uint64_t); + const std::uint64_t returned = reinterpret_cast(vtable[26])( + &padded.value, device, 0xdeadbeef00000001ull, 0xdeadbeef00000002ull); + EXPECT(returned == word(&padded.value)); + // The PC method got (buffer, node mask, heap type) once, on the device behind the proxy. + EXPECT(mock->calls[26] == 1); + EXPECT(static_cast(mock->args[26][1]) == 1 && static_cast(mock->args[26][2]) == 2); + EXPECT(padded.value.Type == D3D12_HEAP_TYPE_UPLOAD && padded.value.CreationNodeMask == 1 && + padded.value.VisibleNodeMask == kHeapMarker); + for (const std::uint8_t byte : padded.before) EXPECT(byte == 0xA5); + for (const std::uint8_t byte : padded.after) EXPECT(byte == 0xA5); + // The proxy is what it was: main's forwarder took the buffer for the proxy, and a thunk that took the proxy + // for the buffer would write the struct over it. + EXPECT(xs::is_device_proxy(device) && word(xs::device_proxy_real_device(device)) == word(mock) && + xs::device_proxy_slot_count(device) == 44 && xs::device_proxy_ref_count(device) == 1); + + // A PC C++ caller: the proxy in RCX and its buffer in RDX. That call is forwarded as it is. + D3D12_HEAP_PROPERTIES pc{}; + EXPECT(raw(device, 26, word(&pc), 1, 3) == word(&pc)); + EXPECT(mock->calls[26] == 2 && mock->args[26][0] == word(&pc)); + EXPECT(pc.Type == D3D12_HEAP_TYPE_READBACK && pc.CreationNodeMask == 1 && pc.VisibleNodeMask == kHeapMarker); + + EXPECT(release(device) == 0 && mock->refs == 0); + std::printf("%s: device slot 26 with the buffer in RCX and the device in RDX reaches the PC method and writes " + "only the struct; the PC form is forwarded unchanged\n", g_label); + return 0; +} + +// ---- 8. The refused tail and the guard region ---- int check_tail(bool want_guarded) { Mock* mock = nullptr; @@ -771,7 +826,7 @@ int main(int argc, char** argv) { if (argc == 2) return run_fault_mode(argv[1]); if (argc != 1) return 2; if (check_tail(true) || check_levels() || check_fence1() || check_create_failures() || check_open_shared() || - check_alloc_failures() || check_allocators()) + check_alloc_failures() || check_allocators() || check_custom_heap_properties()) return 1; std::printf("xs_proxy_mock_test: PASS (%d allocations refused on purpose)\n", g_failed_news); return 0; From 936675b9758523b756d3ba56e26f06c2e85c33ff Mon Sep 17 00:00:00 2001 From: Senne Cools <113857183+sennecools@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:40:19 +0100 Subject: [PATCH 03/13] d3d12_xs: appendix A.4 names the one claim from the executable; wrap two comments AI-assisted. --- docs/d3d12_vulkan.md | 5 +++-- runtime/shims/d3d12_xs_device.cpp | 7 ++++--- runtime/shims/d3d12_xs_device.h | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index 3fdd77324b..f540e2d0a8 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -4078,8 +4078,9 @@ on a PC device behind the Xbox-ABI proxy). Measured: - `amd_fidelityfx_loader_xbox.dll`, `Bink2Scarlett.dll`, `libHttpClient.GDK.dll`, `XCurl.dll`: no `d3d12_xs` imports. -- The package layout XML, chunk 1001, lists `game_scarlett_master.exe`; the file is absent from the folder. No - claim in this document depends on the executable's contents. +- The package layout XML, chunk 1001, lists `game_scarlett_master.exe`; the file is absent from the folder. One + claim in this document comes from running the executable from a player's own copy: how it calls device slot 26 + (section 4.1; register roles and argument values only). No other claim depends on the executable's contents. - The repository's existing import survey (`docs/design.md`, "Baseline already recorded") records that the 16 bundled DLLs need only `xmem` and the two `d3d12_xs` root-signature calls; our scan of the six non-CRT DLLs is consistent. diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 653a50fd7d..dfb4e0471c 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -6,9 +6,10 @@ // arguments only, so the x64 registers and stack words line up exactly; methods that return a struct keep their // hidden return pointer in RDX, which is passed through as the first argument unchanged. The measured exceptions // are IUnknown (0-2), slot 14 (which wraps the heap), 26 (the title passes the return buffer in RCX and the device in -// RDX), 62 and 76, plus the heap proxy's 9/10 conversion from the PC hidden-pointer form to the Xbox RAX form. Slots 8/75 (command queues), 36 (fences) and 32 (a shared fence) wrap -// what they create in queue and fence proxies built the same way, and slots 31/34/35/45/46/50 hand the real objects -// behind heap, queue and fence proxies to the real device (see the command queue and fence section). +// RDX), 62 and 76, plus the heap proxy's 9/10 conversion from the PC hidden-pointer form to the Xbox RAX form. Slots +// 8/75 (command queues), 36 (fences) and 32 (a shared fence) wrap what they create in queue and fence proxies built +// the same way, and slots 31/34/35/45/46/50 hand the real objects behind heap, queue and fence proxies to the real +// device (see the command queue and fence section). // // A thunk declares 14 argument words, but the title passes only as many as the method takes, so the caller's frame // may end right after the four register homes. The compiler owns a function's incoming stack-argument slots and may diff --git a/runtime/shims/d3d12_xs_device.h b/runtime/shims/d3d12_xs_device.h index 3168f653b4..2b1faa4d5f 100644 --- a/runtime/shims/d3d12_xs_device.h +++ b/runtime/shims/d3d12_xs_device.h @@ -84,8 +84,8 @@ ID3D12Device* device_proxy_real_device(const void* device); // True for slots the proxy handles itself rather than forwarding verbatim: IUnknown (0-2), 8 and 75 (queue // proxies), 9 (allocator proxies), 14, 26 (the console's struct-return form), 31/34/35/45/46/50 (proxies unwrapped), -// 32 and 36 (fence proxies), 62, 67 and 76. Slot 10 is intentionally false: the measured 9/10 handle conversion is on the heap proxy, and device -// slot 9 is CreateCommandAllocator, which the proxy handles for the allocator proxy. +// 32 and 36 (fence proxies), 62, 67 and 76. Slot 10 is intentionally false: the measured 9/10 handle conversion is on +// the heap proxy, and device slot 9 is CreateCommandAllocator, which the proxy handles for the allocator proxy. bool device_slot_overridden(unsigned slot); // Queue and fence proxies created by device slots 8/75 and 36. The real_* accessors return the wrapped object From 23e9c9535dce7fe32049c99205c0629893bef932 Mon Sep 17 00:00:00 2001 From: Senne Cools <113857183+sennecools@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:42:53 +0100 Subject: [PATCH 04/13] d3d12_xs: say what is known about slots 25 and 43 AI-assisted. --- docs/d3d12_vulkan.md | 5 +++-- runtime/shims/d3d12_xs_device.h | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index f540e2d0a8..ae6f6e8933 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -2188,8 +2188,9 @@ The trace will enumerate them. RDX, node mask in R8 and heap type in R9: three calls right after device creation, node mask 1 and types 1, 2 and 3 (measured under `gta6rt --run` with a register probe in the slot's thunk). A PC C++ method has the device in RCX and the buffer in RDX, so the Xbox-ABI proxy takes the console form when RDX holds the proxy - (`d3d12_xs_device.cpp`; `xs_proxy_mock_test`, `device_proxy_test`). Slots 25 and 43 return structs too; the - executable has not been seen calling them yet, so the proxy still forwards them in the PC form. + (`d3d12_xs_device.cpp`; `xs_proxy_mock_test`, `device_proxy_test`). Slots 25 and 43 return structs too and the + proxy still forwards them in the PC form: slot 25 is reported called the same way later in the boot (#6982), + with console resource descriptions that need converting first, and no call of slot 43 has been seen. - Residency and power (D3D-33) are no-ops that still check their arguments (`d3d12_vulkan_device.cpp`, tested in `d3d12_vulkan_device_test`). Vulkan has no residency API: memory from `vkAllocateMemory` stays usable until `vkFreeMemory`, and paging under pressure is the kernel driver's job, so every pageable object is always resident. diff --git a/runtime/shims/d3d12_xs_device.h b/runtime/shims/d3d12_xs_device.h index 2b1faa4d5f..03e12ea5b7 100644 --- a/runtime/shims/d3d12_xs_device.h +++ b/runtime/shims/d3d12_xs_device.h @@ -4,8 +4,9 @@ // slot 26 GetCustomHeapProperties, the PC slot, but the retail executable calls it with the buffer for the // returned struct in RCX and the device in RDX (node mask in R8, heap type in R9). A PC C++ method has // the device in RCX and the buffer in RDX. The thunk takes the console form when RDX holds a device -// proxy, and forwards the PC form otherwise. Slots 25 and 43 return structs too; no call of them by -// the executable has been seen yet, so they are forwarded in the PC form. +// proxy, and forwards the PC form otherwise. Slots 25 and 43 return structs too and are still +// forwarded in the PC form: 25 is reported called the same way later in the boot (#6982), with console +// resource descriptions the PC method cannot take as they are, and no call of 43 has been seen. // slot 62 CreateComputePipelineState(desc, w2, w3, iid, out): two words (0 from XboxBvhBuilder, meaning unknown) // before the IID. The PC slot 62 is CreateStateObject. // slot 67 CreateComputePipelineState from native code (desc, iid, out): converts the Xbox native-code desc From 88978553998b51e0e43733606fd67bb253c587ab Mon Sep 17 00:00:00 2001 From: tedin7 Date: Mon, 23 Nov 2026 16:52:16 +0100 Subject: [PATCH 05/13] d3d12_xs: device slot 25 pads a render target to whole console tiles (RT-5 stop 17) The retail title asserts when its first full-screen render targets leave more than 2 MiB of a fixed budget unused (docs/retail_boot_chain.md, #6982). The PC size is about width x height x element bytes; the console takes whole RDNA2 SW_64KB tiles. Slot 25 adds the difference per render target description and never lowers a size. Depends on #6973. --- docs/d3d12_vulkan.md | 8 ++ runtime/shims/d3d12_xs_alloc_size.h | 117 ++++++++++++++++++++++++++++ runtime/shims/d3d12_xs_device.cpp | 27 ++++++- runtime/test/xs_proxy_mock_test.cpp | 117 +++++++++++++++++++++++++++- 4 files changed, 265 insertions(+), 4 deletions(-) create mode 100644 runtime/shims/d3d12_xs_alloc_size.h diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index 3f112891da..46b4831d99 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -2176,6 +2176,14 @@ The trace will enumerate them. Intel Raptor Lake-S (101.7092) and RTX 5060 Laptop (621.24) hosts wrap, two 2^63 buffers to 0, and WARP on that PC still saturates. A wrapped total could make a caller allocate less than one of its resources, so the layer keeps saturating, and the test accepts a host that wraps. + Behind the Xbox-ABI proxy (device slot 25) a 2D render target of a listed colour format with one sample is padded to + whole console tiles: the size is the sum over its mips, each mip rounded up to the RDNA2 SW_64KB_D tile shape + (`runtime/src/gfx10_tiling.h`: 128 x 128 pixels for 4-byte elements, 128 x 64 for 8-byte ones), with the mips that + fit in one tile sharing one tail tile, times the array size. A 1920 x 1080 RGBA8 target is 135 tiles, 8,847,360 bytes, + where the PC answer is 8,323,072. The proxy adds the difference per description to the PC total when the console + size is larger and never lowers a size (`d3d12_xs_alloc_size.h`; `xs_proxy_mock_test`). **Assumption**: the + retail title's own sizes are not measured (#6982, stop 17), so that its allocation is these shapes and no DCC or + CMask memory is open until they are. - `GetAdapterLuid` (implemented): `VkPhysicalDeviceIDProperties::deviceLUID`, which on Windows is the DXGI adapter's LUID; `d3d12_fence_timing_test` finds it with `IDXGIFactory4::EnumAdapterByLuid` (RTX 4090, driver 621.14). A driver that reports `deviceLUIDValid = VK_FALSE` gets a zero LUID, logged. diff --git a/runtime/shims/d3d12_xs_alloc_size.h b/runtime/shims/d3d12_xs_alloc_size.h new file mode 100644 index 0000000000..8caead8d70 --- /dev/null +++ b/runtime/shims/d3d12_xs_alloc_size.h @@ -0,0 +1,117 @@ +// Console allocation sizes for render targets, for the Xbox-ABI device proxy's slot 25 (GetResourceAllocationInfo). +// +// Why: the retail title checks a fixed memory budget against what its first full-screen render targets used and asserts +// when more than 2 MiB is left over (docs/retail_boot_chain.md, stop 17, #6982). The PC device sizes a 2D render target +// from the Vulkan driver's memory requirements, which is about width x height x element bytes. The console lays a +// render target out in 64 KiB tiles (the RDNA2 SW_64KB layouts), so its allocation is the surface padded to whole +// tiles: for 4-byte elements a tile is 128 x 128 pixels, and 1080 rows take nine tile rows, not 8.4. The PC size is +// smaller by that padding, summed over every full-screen target. +// +// What this is: the tile shapes are the RDNA2 SW_64KB_D shapes of runtime/src/gfx10_tiling.h (Mesa addrlib patterns, +// validated against real textures in docs/textures.md). That a console render target uses these shapes and no extra +// (DCC, CMask) memory in its allocation size is an assumption: the title's own sizes are not measured. The rule only +// ever makes a size larger than the PC device's own answer, never smaller. +#pragma once + +#include "../src/gfx10_tiling.h" + +#include +#include + +#include +#include +#include + +namespace rt::d3d12_xs { + +constexpr UINT64 kConsoleTileBytes = 64 * 1024; // one SW_64KB tile + +// Bytes per element of the colour formats a render target takes, or 0 for any other format (the PC size then stays). +inline std::size_t render_target_element_bytes(DXGI_FORMAT format) { + switch (format) { + case DXGI_FORMAT_R8_TYPELESS: case DXGI_FORMAT_R8_UNORM: case DXGI_FORMAT_R8_UINT: + case DXGI_FORMAT_R8_SNORM: case DXGI_FORMAT_R8_SINT: case DXGI_FORMAT_A8_UNORM: + return 1; + case DXGI_FORMAT_R8G8_TYPELESS: case DXGI_FORMAT_R8G8_UNORM: case DXGI_FORMAT_R8G8_UINT: + case DXGI_FORMAT_R8G8_SNORM: case DXGI_FORMAT_R8G8_SINT: case DXGI_FORMAT_R16_TYPELESS: + case DXGI_FORMAT_R16_FLOAT: case DXGI_FORMAT_R16_UNORM: case DXGI_FORMAT_R16_UINT: + case DXGI_FORMAT_R16_SNORM: case DXGI_FORMAT_R16_SINT: case DXGI_FORMAT_B5G6R5_UNORM: + return 2; + case DXGI_FORMAT_R10G10B10A2_TYPELESS: case DXGI_FORMAT_R10G10B10A2_UNORM: + case DXGI_FORMAT_R10G10B10A2_UINT: case DXGI_FORMAT_R11G11B10_FLOAT: + case DXGI_FORMAT_R8G8B8A8_TYPELESS: case DXGI_FORMAT_R8G8B8A8_UNORM: + case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: case DXGI_FORMAT_R8G8B8A8_UINT: + case DXGI_FORMAT_R8G8B8A8_SNORM: case DXGI_FORMAT_R8G8B8A8_SINT: + case DXGI_FORMAT_B8G8R8A8_TYPELESS: case DXGI_FORMAT_B8G8R8A8_UNORM: + case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: case DXGI_FORMAT_B8G8R8X8_TYPELESS: + case DXGI_FORMAT_B8G8R8X8_UNORM: case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: + case DXGI_FORMAT_R16G16_TYPELESS: case DXGI_FORMAT_R16G16_FLOAT: case DXGI_FORMAT_R16G16_UNORM: + case DXGI_FORMAT_R16G16_UINT: case DXGI_FORMAT_R16G16_SNORM: case DXGI_FORMAT_R16G16_SINT: + case DXGI_FORMAT_R32_TYPELESS: case DXGI_FORMAT_R32_FLOAT: case DXGI_FORMAT_R32_UINT: + case DXGI_FORMAT_R32_SINT: + return 4; + case DXGI_FORMAT_R16G16B16A16_TYPELESS: case DXGI_FORMAT_R16G16B16A16_FLOAT: + case DXGI_FORMAT_R16G16B16A16_UNORM: case DXGI_FORMAT_R16G16B16A16_UINT: + case DXGI_FORMAT_R16G16B16A16_SNORM: case DXGI_FORMAT_R16G16B16A16_SINT: + case DXGI_FORMAT_R32G32_TYPELESS: case DXGI_FORMAT_R32G32_FLOAT: case DXGI_FORMAT_R32G32_UINT: + case DXGI_FORMAT_R32G32_SINT: + return 8; + case DXGI_FORMAT_R32G32B32A32_TYPELESS: case DXGI_FORMAT_R32G32B32A32_FLOAT: + case DXGI_FORMAT_R32G32B32A32_UINT: case DXGI_FORMAT_R32G32B32A32_SINT: + return 16; + default: + return 0; + } +} + +// The console's allocation size for a single-sampled 2D render target, or 0 when the rule does not apply (not a 2D +// texture, not a render target, more than one sample, an unlisted format, an empty extent, or a size that overflows). +// Mips whose extent fits in one tile share the tail tile; every other mip is padded to whole tiles. Slices add up. +inline UINT64 console_render_target_size(const D3D12_RESOURCE_DESC& desc) { + if (desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D) return 0; + if (!(desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET)) return 0; + if (desc.SampleDesc.Count > 1) return 0; + const std::size_t element_bytes = render_target_element_bytes(desc.Format); + if (!element_bytes || !desc.Width || !desc.Height || !desc.DepthOrArraySize) return 0; + + const UINT mips = desc.MipLevels ? desc.MipLevels : 1; + UINT64 slice = 0; + bool tail = false; + for (UINT mip = 0; mip < mips && mip < 32; ++mip) { + const UINT64 width = std::max(desc.Width >> mip, 1); + const UINT64 height = std::max(desc.Height >> mip, 1); + leonida::gfx10::TiledSurface2D surface; + if (width > UINT32_MAX || + !leonida::gfx10::TiledSurface2D::make(leonida::gfx10::TileMode::sw_64kb_d, element_bytes, + static_cast(width), static_cast(height), + surface)) + return 0; + if (width <= surface.tile_width() && height <= surface.tile_height()) { + tail = true; + break; + } + slice += surface.tiled_size(); + } + if (tail) slice += kConsoleTileBytes; + const UINT64 slices = desc.DepthOrArraySize; + if (slice > UINT64_MAX / slices) return 0; + return slice * slices; +} + +// What GetResourceAllocationInfo adds to the PC device's answer: for every description with a console size larger than +// the PC device's size for it alone, the difference. pc_size_of(i) is the PC device's size for description i alone. +// A description the PC device refuses (UINT64_MAX) or the rule does not cover adds nothing. +template +UINT64 console_render_target_extra(const D3D12_RESOURCE_DESC* descs, UINT count, PcSizeOf pc_size_of) { + UINT64 extra = 0; + for (UINT i = 0; descs && i < count; ++i) { + const UINT64 console = console_render_target_size(descs[i]); + if (!console) continue; + const UINT64 pc = pc_size_of(i); + if (pc == UINT64_MAX || pc >= console) continue; + extra += console - pc; + } + return extra; +} + +} // namespace rt::d3d12_xs diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 72fa1b3bc4..98a67cafe0 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -19,6 +19,7 @@ // frame. xs_proxy_mock_test's mock hit this in an optimized build, and its thunks now pass their words by pointer. #include "d3d12_xs_device.h" #include "d3d12_trace.h" +#include "d3d12_xs_alloc_size.h" #include "../src/shader_library.h" // leonida::fspx_payload_from_parts for slot 67 #include @@ -1423,12 +1424,34 @@ StructReturnCall struct_return_call(std::uint64_t a0, std::uint64_t a1) { return {reinterpret_cast(a1), reinterpret_cast(a0)}; // C form: return buffer, this } +// The size the PC device saturates a total at (docs/d3d12_vulkan.md, GetResourceAllocationInfo). +constexpr UINT64 kSizeSaturated = 0xFFFFFFFFFFFF0000ull; + void* WINAPI proxy_get_resource_allocation_info(std::uint64_t a0, std::uint64_t a1, std::uint64_t visible_mask, std::uint64_t count, const D3D12_RESOURCE_DESC* descs) { note_slot(25); const StructReturnCall call = struct_return_call(a0, a1); - *static_cast(call.ret) = call.self->real->GetResourceAllocationInfo( - static_cast(visible_mask), static_cast(count), descs); + ID3D12Device* const real = call.self->real; + D3D12_RESOURCE_ALLOCATION_INFO info = + real->GetResourceAllocationInfo(static_cast(visible_mask), static_cast(count), descs); + // A render target takes whole console tiles, which the PC device's size does not (d3d12_xs_alloc_size.h). The + // total grows by what each render target lacks on its own, so the placement of the others stays as the PC lays it. + if (info.SizeInBytes != UINT64_MAX) { + const UINT64 extra = console_render_target_extra(descs, static_cast(count), [&](UINT i) { + return real->GetResourceAllocationInfo(static_cast(visible_mask), 1, &descs[i]).SizeInBytes; + }); + if (extra) { + static std::atomic logged{false}; + if (!logged.exchange(true, std::memory_order_relaxed)) + std::fprintf(stderr, + "[rt] d3d12_xs: slot 25: render target sizes padded to console tiles, +%llu B on " + "%llu B for %u description(s)\n", + static_cast(extra), + static_cast(info.SizeInBytes), static_cast(count)); + info.SizeInBytes = extra > kSizeSaturated - info.SizeInBytes ? kSizeSaturated : info.SizeInBytes + extra; + } + } + *static_cast(call.ret) = info; return call.ret; } diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp index f115b6655e..6a62c0e34f 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -162,6 +162,27 @@ void copy_array(Mock* m, unsigned slot, std::uint64_t objects, std::uint64_t cou for (std::uint32_t i = 0; in && i < static_cast(count) && i < 4; ++i) m->array[slot][i] = in[i]; } +// The PC device's GetResourceAllocationInfo, as a driver that packs a surface with no tile padding answers it: a buffer +// its width, a texture width x height x slices x element bytes (4 for RGBA8, 8 for RGBA16F), each rounded up to +// 64 KiB, summed over the descriptions; a texture with no width is refused. The struct is written to the hidden return +// pointer (RDX of a C++ method call), which comes back in RAX. +std::uint64_t mock_allocation_info(std::uint64_t ret, std::uint64_t count, std::uint64_t descs_word) { + const auto* descs = reinterpret_cast(descs_word); + std::uint64_t total = 0; + bool refused = false; + for (std::uint32_t i = 0; descs && i < static_cast(count); ++i) { + const D3D12_RESOURCE_DESC& d = descs[i]; + std::uint64_t bytes = d.Width; + if (d.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) + bytes = d.Width * d.Height * d.DepthOrArraySize * (d.Format == DXGI_FORMAT_R16G16B16A16_FLOAT ? 8 : 4); + refused = refused || d.Width == 0; + total += (bytes + 65535) / 65536 * 65536; + } + auto* out = reinterpret_cast(ret); + *out = {refused ? UINT64_MAX : total, 65536}; + return ret; +} + // `words` are the call's first five words (a1..a5), copied into the thunk's own frame. std::uint64_t mock_call(Mock* m, unsigned slot, const std::uint64_t* words) { const std::uint64_t a1 = words[0], a2 = words[1], a3 = words[2], a4 = words[3]; @@ -175,6 +196,7 @@ std::uint64_t mock_call(Mock* m, unsigned slot, const std::uint64_t* words) { if (a1 == kFenceHandle) return static_cast(mock_create(m, Kind::fence, a2, a3)); if (a1 == kResourceHandle) return static_cast(mock_create(m, Kind::resource, a2, a3)); return static_cast(E_INVALIDARG); + case 25: return mock_allocation_info(a1, a3, a4); // GetResourceAllocationInfo (mask a2 is unused) case 34: case 35: case 46: copy_array(m, slot, a2, a1); break; // (count, objects, ...) case 45: copy_array(m, slot, a1, a3); break; // (fences, values, count, ...) case 50: copy_array(m, slot, a3, a2); break; // (flags, count, objects, fence, value) @@ -648,7 +670,98 @@ int check_allocators() { return 0; } -// ---- 7. The refused tail and the guard region ---- +// ---- 7. Device slot 25, GetResourceAllocationInfo: a render target takes whole console tiles ---- + +D3D12_RESOURCE_DESC target_desc(std::uint64_t width, UINT height, DXGI_FORMAT format, UINT slices = 1) { + D3D12_RESOURCE_DESC d{}; + d.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; + d.Width = width; + d.Height = height; + d.DepthOrArraySize = static_cast(slices); + d.MipLevels = 1; + d.Format = format; + d.SampleDesc.Count = 1; + d.Layout = static_cast(0x101); // the Xbox tiled layout word + d.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; + return d; +} + +int check_render_target_sizes() { + Mock* mock = nullptr; + void* device = make_device(mock, 0, true); + EXPECT(device); + void* const* vtable = *reinterpret_cast(device); + // The retail executable's call: the buffer for the struct in RCX, the device in RDX. + using ConsoleFn = D3D12_RESOURCE_ALLOCATION_INFO*(WINAPI*)(D3D12_RESOURCE_ALLOCATION_INFO*, void*, UINT, UINT, + const D3D12_RESOURCE_DESC*); + const auto get_info = reinterpret_cast(vtable[25]); + auto ask = [&](const D3D12_RESOURCE_DESC* descs, UINT count) { + D3D12_RESOURCE_ALLOCATION_INFO info{0xDEAD, 0xBEEF}; + const bool same_buffer = get_info(&info, device, 0, count, descs) == &info; + if (!same_buffer) info.SizeInBytes = 0; + return info; + }; + + // A 1920 x 1080 RGBA8 target. A 4-byte element tile is 128 x 128 pixels: 15 tiles across, 9 down (1080 / 128 is + // 8.4), 135 x 64 KiB = 8,847,360 B. The PC device packs it as 8,294,400 B, 8,323,072 B rounded to 64 KiB. + const D3D12_RESOURCE_DESC hd = target_desc(1920, 1080, DXGI_FORMAT_R8G8B8A8_UNORM); + D3D12_RESOURCE_ALLOCATION_INFO info = ask(&hd, 1); + EXPECT(info.SizeInBytes == 8847360 && info.Alignment == 65536); + // A 3840 x 2160 RGBA16F target: an 8-byte element tile is 128 x 64, 30 across and 34 down (2160 / 64 is 33.75), + // 1020 tiles = 66,846,720 B, where the PC device says 66,387,968 B. + const D3D12_RESOURCE_DESC uhd = target_desc(3840, 2160, DXGI_FORMAT_R16G16B16A16_FLOAT); + EXPECT(ask(&uhd, 1).SizeInBytes == 66846720); + // Both in one call: the sum of the two console sizes. + const D3D12_RESOURCE_DESC both[] = {hd, uhd}; + EXPECT(ask(both, 2).SizeInBytes == 8847360 + 66846720); + // Two slices take two surfaces. + const D3D12_RESOURCE_DESC two = target_desc(1920, 1080, DXGI_FORMAT_R8G8B8A8_UNORM, 2); + EXPECT(ask(&two, 1).SizeInBytes == 2 * 8847360); + + // What is left alone: a texture that is not a render target, a buffer, a render target of a format the rule does + // not list, one the PC device refuses, and a surface that is already whole tiles (1024 x 1024 RGBA8). + D3D12_RESOURCE_DESC sampled = hd; + sampled.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; + EXPECT(ask(&sampled, 1).SizeInBytes == 8323072); + D3D12_RESOURCE_DESC buffer{}; + buffer.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; + buffer.Width = 100000; + buffer.Height = 1; + buffer.DepthOrArraySize = 1; + buffer.MipLevels = 1; + buffer.SampleDesc.Count = 1; + buffer.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; + buffer.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; + EXPECT(ask(&buffer, 1).SizeInBytes == 131072); + D3D12_RESOURCE_DESC odd_format = hd; + odd_format.Format = DXGI_FORMAT_BC1_UNORM; + EXPECT(ask(&odd_format, 1).SizeInBytes == 8323072); + D3D12_RESOURCE_DESC empty = hd; + empty.Width = 0; + EXPECT(ask(&empty, 1).SizeInBytes == UINT64_MAX); + const D3D12_RESOURCE_DESC exact = target_desc(1024, 1024, DXGI_FORMAT_R8G8B8A8_UNORM); + EXPECT(ask(&exact, 1).SizeInBytes == 4194304); + // A refused description in a list refuses the list, as before. + const D3D12_RESOURCE_DESC refused[] = {hd, empty}; + EXPECT(ask(refused, 2).SizeInBytes == UINT64_MAX); + // A mip chain: 1920 x 1080 with 3 mips is mip 0 in 135 tiles, mip 1 (960 x 540) in 8 x 5 = 40 tiles and mip 2 + // (480 x 270) in 4 x 3 = 12 tiles. + D3D12_RESOURCE_DESC mips = hd; + mips.MipLevels = 3; + EXPECT(ask(&mips, 1).SizeInBytes == (135 + 40 + 12) * 65536ull); + + // The PC form (this in RCX, the buffer in RDX) answers the same sizes. + D3D12_RESOURCE_ALLOCATION_INFO pc{}; + EXPECT(raw(device, 25, word(&pc), 0, 1, word(&hd)) == word(&pc)); + EXPECT(pc.SizeInBytes == 8847360); + + EXPECT(release(device) == 0 && mock->refs == 0); + std::printf("%s: device slot 25 pads render targets to whole console tiles and leaves the other sizes as the PC " + "device gives them\n", g_label); + return 0; +} + +// ---- 8. The refused tail and the guard region ---- int check_tail(bool want_guarded) { Mock* mock = nullptr; @@ -771,7 +884,7 @@ int main(int argc, char** argv) { if (argc == 2) return run_fault_mode(argv[1]); if (argc != 1) return 2; if (check_tail(true) || check_levels() || check_fence1() || check_create_failures() || check_open_shared() || - check_alloc_failures() || check_allocators()) + check_alloc_failures() || check_allocators() || check_render_target_sizes()) return 1; std::printf("xs_proxy_mock_test: PASS (%d allocations refused on purpose)\n", g_failed_news); return 0; From c7ca0f2d1c3d1aaa1dca7c01740dac076c523154 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Mon, 23 Nov 2026 16:56:52 +0100 Subject: [PATCH 06/13] d3d12_xs: device slot 25 gives the PC device clean resource descriptions (RT-5 stop 16) The title's descriptions carry the Xbox layout word and flag bits above the PC ones. Slot 25 now passes a copy with PC flags and a PC layout; the title's array is not written. Depends on #7078. --- docs/d3d12_vulkan.md | 3 ++ runtime/shims/d3d12_xs_desc_clean.h | 34 ++++++++++++++ runtime/shims/d3d12_xs_device.cpp | 16 ++++++- runtime/test/xs_proxy_mock_test.cpp | 69 ++++++++++++++++++++++++++++- 4 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 runtime/shims/d3d12_xs_desc_clean.h diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index 46b4831d99..a43969674e 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -2184,6 +2184,9 @@ The trace will enumerate them. size is larger and never lowers a size (`d3d12_xs_alloc_size.h`; `xs_proxy_mock_test`). **Assumption**: the retail title's own sizes are not measured (#6982, stop 17), so that its allocation is these shapes and no DCC or CMask memory is open until they are. + The descriptions the title passes to slot 25 carry console values (layout word `0x101`/`0x1`, flag bits above the PC + ones). The proxy gives the PC device a copy with the PC flags only and ROW_MAJOR (buffer) or UNKNOWN (texture); the + title's array is never written (`d3d12_xs_desc_clean.h`, the same cleaning as slot 76; #6982 section 3.7). - `GetAdapterLuid` (implemented): `VkPhysicalDeviceIDProperties::deviceLUID`, which on Windows is the DXGI adapter's LUID; `d3d12_fence_timing_test` finds it with `IDXGIFactory4::EnumAdapterByLuid` (RTX 4090, driver 621.14). A driver that reports `deviceLUIDValid = VK_FALSE` gets a zero LUID, logged. diff --git a/runtime/shims/d3d12_xs_desc_clean.h b/runtime/shims/d3d12_xs_desc_clean.h new file mode 100644 index 0000000000..61f49eb8b2 --- /dev/null +++ b/runtime/shims/d3d12_xs_desc_clean.h @@ -0,0 +1,34 @@ +// The PC form of a resource description the retail title builds for the console, for the Xbox-ABI device proxy. +// +// The title's D3D12_RESOURCE_DESC carries console values the PC device cannot take: the layout word is 0x101 (tiled) +// or 0x1 (row-major buffer), and the flags have bits above the PC ones set (docs/retail_boot_chain.md, #6982). Slot 76 +// replaces the layout word the same way before it forwards to CreateCommittedResource; slot 25 and the slot 127 +// stand-in need the same cleaning. The title's own description is never written: a caller gets a copy. +#pragma once + +#include +#include + +#include + +namespace rt::d3d12_xs { + +// The D3D12_RESOURCE_FLAGS bits the PC runtime defines; every other bit is a console one. +constexpr std::uint32_t kPcResourceFlagsMask = + D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | + D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS | D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE | + D3D12_RESOURCE_FLAG_ALLOW_CROSS_ADAPTER | D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS | + D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY | D3D12_RESOURCE_FLAG_VIDEO_ENCODE_REFERENCE_ONLY | + D3D12_RESOURCE_FLAG_RAYTRACING_ACCELERATION_STRUCTURE; + +// A copy of the title's description with the PC flags only and a PC layout: ROW_MAJOR for a buffer, UNKNOWN for a +// texture (the layout the PC device picks itself). +inline D3D12_RESOURCE_DESC pc_resource_desc(const D3D12_RESOURCE_DESC& xbox) { + D3D12_RESOURCE_DESC pc = xbox; + pc.Layout = xbox.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? D3D12_TEXTURE_LAYOUT_ROW_MAJOR + : D3D12_TEXTURE_LAYOUT_UNKNOWN; + pc.Flags = static_cast(static_cast(xbox.Flags) & kPcResourceFlagsMask); + return pc; +} + +} // namespace rt::d3d12_xs diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 98a67cafe0..46509c8870 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -20,6 +20,7 @@ #include "d3d12_xs_device.h" #include "d3d12_trace.h" #include "d3d12_xs_alloc_size.h" +#include "d3d12_xs_desc_clean.h" #include "../src/shader_library.h" // leonida::fspx_payload_from_parts for slot 67 #include @@ -1432,8 +1433,21 @@ void* WINAPI proxy_get_resource_allocation_info(std::uint64_t a0, std::uint64_t note_slot(25); const StructReturnCall call = struct_return_call(a0, a1); ID3D12Device* const real = call.self->real; + // The descriptions are the console's. The PC device gets a copy with PC flags and layout; the title's array is + // read only. A copy that cannot be made answers as an invalid description. + const UINT desc_count = static_cast(count); + std::unique_ptr clean; + if (descs && desc_count) { + clean.reset(new (std::nothrow) D3D12_RESOURCE_DESC[desc_count]); + if (!clean) { + *static_cast(call.ret) = {UINT64_MAX, D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT}; + return call.ret; + } + for (UINT i = 0; i < desc_count; ++i) clean[i] = pc_resource_desc(descs[i]); + descs = clean.get(); + } D3D12_RESOURCE_ALLOCATION_INFO info = - real->GetResourceAllocationInfo(static_cast(visible_mask), static_cast(count), descs); + real->GetResourceAllocationInfo(static_cast(visible_mask), desc_count, descs); // A render target takes whole console tiles, which the PC device's size does not (d3d12_xs_alloc_size.h). The // total grows by what each render target lacks on its own, so the placement of the others stays as the PC lays it. if (info.SizeInBytes != UINT64_MAX) { diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp index 6a62c0e34f..b45389cf20 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -166,8 +166,17 @@ void copy_array(Mock* m, unsigned slot, std::uint64_t objects, std::uint64_t cou // its width, a texture width x height x slices x element bytes (4 for RGBA8, 8 for RGBA16F), each rounded up to // 64 KiB, summed over the descriptions; a texture with no width is refused. The struct is written to the hidden return // pointer (RDX of a C++ method call), which comes back in RAX. +D3D12_RESOURCE_DESC g_seen_descs[4]; // the first descriptions the mock device's slot 25 was given +std::uint32_t g_seen_desc_count = 0; +std::uint32_t g_seen_calls = 0; // slot 25 calls since the test cleared it; only the first is recorded + std::uint64_t mock_allocation_info(std::uint64_t ret, std::uint64_t count, std::uint64_t descs_word) { const auto* descs = reinterpret_cast(descs_word); + if (g_seen_calls++ == 0) { + g_seen_desc_count = static_cast(count); + for (std::uint32_t i = 0; descs && i < g_seen_desc_count && i < std::size(g_seen_descs); ++i) + g_seen_descs[i] = descs[i]; + } std::uint64_t total = 0; bool refused = false; for (std::uint32_t i = 0; descs && i < static_cast(count); ++i) { @@ -761,6 +770,63 @@ int check_render_target_sizes() { return 0; } +// ---- 7b. Device slot 25 hands the PC device clean descriptions and leaves the title's array alone ---- + +int check_allocation_descriptions_cleaned() { + constexpr std::uint32_t kXboxTiledLayout = 0x101, kXboxRowMajorLayout = 0x1, kXboxFlagBits = 0x40000 | 0x20000; + constexpr D3D12_RESOURCE_FLAGS kPcFlags = + D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; + Mock* mock = nullptr; + void* device = make_device(mock, 0, true); + EXPECT(device); + void* const* vtable = *reinterpret_cast(device); + using ConsoleFn = D3D12_RESOURCE_ALLOCATION_INFO*(WINAPI*)(D3D12_RESOURCE_ALLOCATION_INFO*, void*, UINT, UINT, + const D3D12_RESOURCE_DESC*); + const auto get_info = reinterpret_cast(vtable[25]); + + // A texture with the Xbox tiled layout word and Xbox bits above the PC flags, and a buffer with the row-major word. + D3D12_RESOURCE_DESC titles[2] = {target_desc(1920, 1080, DXGI_FORMAT_R8G8B8A8_UNORM), {}}; + titles[0].Flags = static_cast(kPcFlags | kXboxFlagBits); + titles[0].Layout = static_cast(kXboxTiledLayout); + titles[1].Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; + titles[1].Width = 100000; + titles[1].Height = 1; + titles[1].DepthOrArraySize = 1; + titles[1].MipLevels = 1; + titles[1].SampleDesc.Count = 1; + titles[1].Layout = static_cast(kXboxRowMajorLayout); + titles[1].Flags = static_cast(kXboxFlagBits); + D3D12_RESOURCE_DESC kept[2]; + std::memcpy(kept, titles, sizeof(kept)); + + D3D12_RESOURCE_ALLOCATION_INFO info{}; + g_seen_desc_count = 0; + g_seen_calls = 0; + std::memset(g_seen_descs, 0xCC, sizeof(g_seen_descs)); + EXPECT(get_info(&info, device, 0, 2, titles) == &info); + // The PC device saw both descriptions with PC flags and a PC layout, the rest of each as the title wrote it. + EXPECT(g_seen_desc_count == 2); + EXPECT(g_seen_descs[0].Layout == D3D12_TEXTURE_LAYOUT_UNKNOWN && g_seen_descs[0].Flags == kPcFlags); + EXPECT(g_seen_descs[0].Width == 1920 && g_seen_descs[0].Height == 1080 && + g_seen_descs[0].Format == DXGI_FORMAT_R8G8B8A8_UNORM); + EXPECT(g_seen_descs[1].Layout == D3D12_TEXTURE_LAYOUT_ROW_MAJOR && g_seen_descs[1].Flags == D3D12_RESOURCE_FLAG_NONE); + EXPECT(g_seen_descs[1].Width == 100000); + // The title's array is as it was, and the size still follows the render-target flag it kept (the proxy's later + // per-target questions to the PC device are not recorded). + EXPECT(std::memcmp(kept, titles, sizeof(kept)) == 0); + EXPECT(info.SizeInBytes == 8847360 + 131072); + + // A null array with a zero count reaches the PC device as it came. + g_seen_desc_count = 99; + g_seen_calls = 0; + EXPECT(get_info(&info, device, 0, 0, nullptr) == &info && g_seen_calls == 1 && g_seen_desc_count == 0); + + EXPECT(release(device) == 0 && mock->refs == 0); + std::printf("%s: device slot 25 gives the PC device descriptions with PC flags and layout, and the title's own " + "array is not written\n", g_label); + return 0; +} + // ---- 8. The refused tail and the guard region ---- int check_tail(bool want_guarded) { @@ -884,7 +950,8 @@ int main(int argc, char** argv) { if (argc == 2) return run_fault_mode(argv[1]); if (argc != 1) return 2; if (check_tail(true) || check_levels() || check_fence1() || check_create_failures() || check_open_shared() || - check_alloc_failures() || check_allocators() || check_render_target_sizes()) + check_alloc_failures() || check_allocators() || check_render_target_sizes() || + check_allocation_descriptions_cleaned()) return 1; std::printf("xs_proxy_mock_test: PASS (%d allocations refused on purpose)\n", g_failed_news); return 0; From 359390833f62378a5d1d2c0f9a6cea48fccbcb53 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Mon, 23 Nov 2026 17:26:57 +0100 Subject: [PATCH 07/13] d3d12_xs: console render target sizes follow each resource's alignment, slot 56 offsets, full mip chains, rounded-up mip extents, B5G5R5A1, saturating sums --- docs/d3d12_vulkan.md | 23 ++-- runtime/shims/d3d12_xs_alloc_size.h | 81 +++++++++++---- runtime/shims/d3d12_xs_device.cpp | 73 +++++++++---- runtime/test/xs_proxy_mock_test.cpp | 156 +++++++++++++++++++++++++--- 4 files changed, 266 insertions(+), 67 deletions(-) diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index ec34868126..431c1ecdd6 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -2209,12 +2209,17 @@ The trace will enumerate them. Intel Raptor Lake-S (101.7092) and RTX 5060 Laptop (621.24) hosts wrap, two 2^63 buffers to 0, and WARP on that PC still saturates. A wrapped total could make a caller allocate less than one of its resources, so the layer keeps saturating, and the test accepts a host that wraps. - Behind the Xbox-ABI proxy (device slot 25) a 2D render target of a listed colour format with one sample is padded to - whole console tiles: the size is the sum over its mips, each mip rounded up to the RDNA2 SW_64KB_D tile shape - (`runtime/src/gfx10_tiling.h`: 128 x 128 pixels for 4-byte elements, 128 x 64 for 8-byte ones), with the mips that - fit in one tile sharing one tail tile, times the array size. A 1920 x 1080 RGBA8 target is 135 tiles, 8,847,360 bytes, - where the PC answer is 8,323,072. The proxy adds the difference per description to the PC total when the console - size is larger and never lowers a size (`d3d12_xs_alloc_size.h`; `xs_proxy_mock_test`). **Assumption**: the + Behind the Xbox-ABI proxy (device slots 25 and 56) a 2D render target of a listed colour format with one sample is + padded to whole console tiles: the size is the sum over its mips (MipLevels 0 is the full chain, an odd extent + rounds up), each mip rounded up to the RDNA2 SW_64KB_D tile shape (`runtime/src/gfx10_tiling.h`: 256 x 128 pixels + for 2-byte elements, 128 x 128 for 4-byte, 128 x 64 for 8-byte, 64 x 64 for 16-byte), with the first mip that fits + in half a tile's width and a whole tile's height, and the mips after it, sharing one tail tile, times the array + size. A 1920 x 1080 RGBA8 target is 135 tiles, 8,847,360 bytes, where the PC answer is 8,323,072. The proxy lays + the descriptions out as the PC device does (each at its own alignment, the total rounded up to the largest + alignment, sums saturating) with each render target at the larger of its console size and its PC size; a 4 MiB + aligned multisampled neighbour therefore keeps its place (a 1 x 1 four-sample target and a 1080p target need 16 MiB, + not 12.5). Slot 56 reports the same offsets. The PC layout stands when no description grows + (`d3d12_xs_alloc_size.h`; `xs_proxy_mock_test`). **Assumption**: the retail title's own sizes are not measured (#6982, stop 17), so that its allocation is these shapes and no DCC or CMask memory is open until they are. - `GetAdapterLuid` (implemented): `VkPhysicalDeviceIDProperties::deviceLUID`, which on Windows is the DXGI @@ -2229,9 +2234,9 @@ The trace will enumerate them. RDX, node mask in R8 and heap type in R9: three calls right after device creation, node mask 1 and types 1, 2 and 3 (measured under `gta6rt --run` with a register probe in the slot's thunk). A PC C++ method has the device in RCX and the buffer in RDX, so the Xbox-ABI proxy takes the console form when RDX holds the proxy - (`d3d12_xs_device.cpp`; `xs_proxy_mock_test`, `device_proxy_test`). Slots 25 and 43 return structs too and the - proxy still forwards them in the PC form: slot 25 is reported called the same way later in the boot (#6982), - with console resource descriptions that need converting first, and no call of slot 43 has been seen. + (`d3d12_xs_device.cpp`; `xs_proxy_mock_test`, `device_proxy_test`). Slot 43 returns a struct too and the + proxy still forwards it in the PC form: no call of slot 43 has been seen. Slots 25 and 56 take the same form by the + same rule (reported later in the boot, #6982; not measured), as #6973 first did for slot 25. - Residency and power (D3D-33) are no-ops that still check their arguments (`d3d12_vulkan_device.cpp`, tested in `d3d12_vulkan_device_test`). Vulkan has no residency API: memory from `vkAllocateMemory` stays usable until `vkFreeMemory`, and paging under pressure is the kernel driver's job, so every pageable object is always resident. diff --git a/runtime/shims/d3d12_xs_alloc_size.h b/runtime/shims/d3d12_xs_alloc_size.h index 8caead8d70..3321c4ec88 100644 --- a/runtime/shims/d3d12_xs_alloc_size.h +++ b/runtime/shims/d3d12_xs_alloc_size.h @@ -1,4 +1,4 @@ -// Console allocation sizes for render targets, for the Xbox-ABI device proxy's slot 25 (GetResourceAllocationInfo). +// Console allocation sizes for render targets, for the Xbox-ABI device proxy's slots 25 and 56 (GetResourceAllocationInfo and GetResourceAllocationInfo1). // // Why: the retail title checks a fixed memory budget against what its first full-screen render targets used and asserts // when more than 2 MiB is left over (docs/retail_boot_chain.md, stop 17, #6982). The PC device sizes a 2D render target @@ -10,7 +10,9 @@ // What this is: the tile shapes are the RDNA2 SW_64KB_D shapes of runtime/src/gfx10_tiling.h (Mesa addrlib patterns, // validated against real textures in docs/textures.md). That a console render target uses these shapes and no extra // (DCC, CMask) memory in its allocation size is an assumption: the title's own sizes are not measured. The rule only -// ever makes a size larger than the PC device's own answer, never smaller. +// ever makes a size larger than the PC device's own answer, never smaller. The mip tail follows AMD's addrlib +// (gfx10, 2D): a mip extent is rounded up (ShiftCeil), and the tail starts at the first mip that fits in half a tile's +// width and a whole tile's height; the tail is one tile. #pragma once #include "../src/gfx10_tiling.h" @@ -19,6 +21,7 @@ #include #include +#include #include #include @@ -36,6 +39,7 @@ inline std::size_t render_target_element_bytes(DXGI_FORMAT format) { case DXGI_FORMAT_R8G8_SNORM: case DXGI_FORMAT_R8G8_SINT: case DXGI_FORMAT_R16_TYPELESS: case DXGI_FORMAT_R16_FLOAT: case DXGI_FORMAT_R16_UNORM: case DXGI_FORMAT_R16_UINT: case DXGI_FORMAT_R16_SNORM: case DXGI_FORMAT_R16_SINT: case DXGI_FORMAT_B5G6R5_UNORM: + case DXGI_FORMAT_B5G5R5A1_UNORM: return 2; case DXGI_FORMAT_R10G10B10A2_TYPELESS: case DXGI_FORMAT_R10G10B10A2_UNORM: case DXGI_FORMAT_R10G10B10A2_UINT: case DXGI_FORMAT_R11G11B10_FLOAT: @@ -66,7 +70,9 @@ inline std::size_t render_target_element_bytes(DXGI_FORMAT format) { // The console's allocation size for a single-sampled 2D render target, or 0 when the rule does not apply (not a 2D // texture, not a render target, more than one sample, an unlisted format, an empty extent, or a size that overflows). -// Mips whose extent fits in one tile share the tail tile; every other mip is padded to whole tiles. Slices add up. +// MipLevels 0 is the full chain, as on the PC device. A mip extent is rounded up. Mips before the tail are padded to +// whole tiles; the first mip that fits in half a tile's width and the whole tile height, and every mip after it, share +// one tail tile. Slices add up. inline UINT64 console_render_target_size(const D3D12_RESOURCE_DESC& desc) { if (desc.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D) return 0; if (!(desc.Flags & D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET)) return 0; @@ -74,19 +80,20 @@ inline UINT64 console_render_target_size(const D3D12_RESOURCE_DESC& desc) { const std::size_t element_bytes = render_target_element_bytes(desc.Format); if (!element_bytes || !desc.Width || !desc.Height || !desc.DepthOrArraySize) return 0; - const UINT mips = desc.MipLevels ? desc.MipLevels : 1; + const UINT full_chain = static_cast(std::bit_width(std::max(desc.Width, desc.Height))); + const UINT mips = desc.MipLevels ? std::min(desc.MipLevels, full_chain) : full_chain; UINT64 slice = 0; bool tail = false; - for (UINT mip = 0; mip < mips && mip < 32; ++mip) { - const UINT64 width = std::max(desc.Width >> mip, 1); - const UINT64 height = std::max(desc.Height >> mip, 1); + for (UINT mip = 0; mip < mips; ++mip) { + const UINT64 width = std::max((desc.Width + (UINT64{1} << mip) - 1) >> mip, 1); + const UINT64 height = std::max((UINT64{desc.Height} + (UINT64{1} << mip) - 1) >> mip, 1); leonida::gfx10::TiledSurface2D surface; if (width > UINT32_MAX || !leonida::gfx10::TiledSurface2D::make(leonida::gfx10::TileMode::sw_64kb_d, element_bytes, static_cast(width), static_cast(height), surface)) return 0; - if (width <= surface.tile_width() && height <= surface.tile_height()) { + if (width <= surface.tile_width() / 2 && height <= surface.tile_height()) { tail = true; break; } @@ -98,20 +105,52 @@ inline UINT64 console_render_target_size(const D3D12_RESOURCE_DESC& desc) { return slice * slices; } -// What GetResourceAllocationInfo adds to the PC device's answer: for every description with a console size larger than -// the PC device's size for it alone, the difference. pc_size_of(i) is the PC device's size for description i alone. -// A description the PC device refuses (UINT64_MAX) or the rule does not cover adds nothing. -template -UINT64 console_render_target_extra(const D3D12_RESOURCE_DESC* descs, UINT count, PcSizeOf pc_size_of) { - UINT64 extra = 0; - for (UINT i = 0; descs && i < count; ++i) { - const UINT64 console = console_render_target_size(descs[i]); - if (!console) continue; - const UINT64 pc = pc_size_of(i); - if (pc == UINT64_MAX || pc >= console) continue; - extra += console - pc; +// Rounds up to a multiple of `to`, stopping at the last multiple below 2^64 instead of wrapping (as the PC device's +// totals do). +inline UINT64 align_up_saturating(UINT64 value, UINT64 to) { + return value > UINT64_MAX - (to - 1) ? UINT64_MAX / to * to : (value + to - 1) / to * to; +} + +// Lays the descriptions out as the PC device does (one after another, each at its own alignment, the total rounded up +// to the largest alignment), with a render target's size taken as its console size when that is larger than the PC +// size. pc_one(i) is the PC device's answer for description i alone. Sizes are rounded to each description's own +// alignment, so a multisampled neighbour at 4 MiB keeps its place, and sums saturate instead of wrapping. When +// `each` is given it receives every description's offset, alignment and size. +// +// Returns false, and writes nothing, when no description is a console render target that grows, or when the PC +// device refuses one: the PC answer then stands. A true answer is never below what the PC device gave for the same +// descriptions laid out in that way. +template +bool console_placement(const D3D12_RESOURCE_DESC* descs, UINT count, PcOne pc_one, + D3D12_RESOURCE_ALLOCATION_INFO& total, D3D12_RESOURCE_ALLOCATION_INFO1* each) { + if (!descs) return false; + bool any_target = false; + for (UINT i = 0; i < count && !any_target; ++i) any_target = console_render_target_size(descs[i]) != 0; + if (!any_target) return false; + // Two passes when `each` is wanted: the first decides, the second writes, so a refusal or a list that does not + // grow leaves the array as the PC device filled it. + for (const bool write : {false, true}) { + if (write && !each) break; + bool grows = false; + UINT64 end = 0, alignment = 1; + for (UINT i = 0; i < count; ++i) { + const D3D12_RESOURCE_ALLOCATION_INFO one = pc_one(i); + if (one.SizeInBytes == UINT64_MAX || !one.Alignment) return false; + UINT64 size = one.SizeInBytes; + const UINT64 console = console_render_target_size(descs[i]); + if (console > size) { + size = align_up_saturating(console, one.Alignment); + grows = true; + } + const UINT64 offset = align_up_saturating(end, one.Alignment); + if (write) each[i] = {offset, one.Alignment, size}; + end = size > UINT64_MAX - offset ? UINT64_MAX : offset + size; + alignment = std::max(alignment, one.Alignment); + } + if (!grows) return false; + total = {align_up_saturating(end, alignment), alignment}; } - return extra; + return true; } } // namespace rt::d3d12_xs diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index fb4fc9b365..858771f3be 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -142,6 +143,7 @@ const char* slot_name(unsigned slot) { case 46: return "SetResidencyPriority (proxies unwrapped)"; case 48: return "Xbox CreateCommandQueueX -> queue proxy"; case 50: return "EnqueueMakeResident (proxies unwrapped)"; + case 56: return "GetResourceAllocationInfo1 (C or PC form)"; case 62: return "Xbox CreateComputePipelineState"; case 67: return "Xbox DeserializeComputePipelineStateX"; case 73: return "Xbox CreateCommandListX -> PC CreateCommandList"; @@ -1637,42 +1639,69 @@ StructReturnCall struct_return_call(std::uint64_t a0, std::uint64_t a1) { return {reinterpret_cast(a1), reinterpret_cast(a0)}; // C form: return buffer, this } -// The size the PC device saturates a total at (docs/d3d12_vulkan.md, GetResourceAllocationInfo). -constexpr UINT64 kSizeSaturated = 0xFFFFFFFFFFFF0000ull; +// The console size of a list of descriptions (d3d12_xs_alloc_size.h): the PC device's answer with every console render +// target laid out at its console size, each at its own alignment. `info` is the PC answer and is replaced only when +// the console layout is larger. `each` is the per-description array of slot 56, or null. +void apply_console_placement(const D3D12_RESOURCE_DESC* descs, UINT count, D3D12_RESOURCE_ALLOCATION_INFO& info, + D3D12_RESOURCE_ALLOCATION_INFO1* each, + const std::function& pc_one, unsigned slot) { + if (info.SizeInBytes == UINT64_MAX) return; + D3D12_RESOURCE_ALLOCATION_INFO console{}; + if (!console_placement(descs, count, pc_one, console, each)) return; + static std::atomic logged{false}; + if (!logged.exchange(true, std::memory_order_relaxed)) + std::fprintf(stderr, + "[rt] d3d12_xs: slot %u: render targets sized as console tiles, %llu B for %llu B on %u " + "description(s)\n", + slot, static_cast(console.SizeInBytes), + static_cast(info.SizeInBytes), static_cast(count)); + if (console.SizeInBytes >= info.SizeInBytes) info = console; +} void* WINAPI proxy_get_resource_allocation_info(std::uint64_t a0, std::uint64_t a1, std::uint64_t visible_mask, std::uint64_t count, const D3D12_RESOURCE_DESC* descs) { note_slot(25); const StructReturnCall call = struct_return_call(a0, a1); ID3D12Device* const real = call.self->real; - D3D12_RESOURCE_ALLOCATION_INFO info = - real->GetResourceAllocationInfo(static_cast(visible_mask), static_cast(count), descs); - // A render target takes whole console tiles, which the PC device's size does not (d3d12_xs_alloc_size.h). The - // total grows by what each render target lacks on its own, so the placement of the others stays as the PC lays it. - if (info.SizeInBytes != UINT64_MAX) { - const UINT64 extra = console_render_target_extra(descs, static_cast(count), [&](UINT i) { - return real->GetResourceAllocationInfo(static_cast(visible_mask), 1, &descs[i]).SizeInBytes; - }); - if (extra) { - static std::atomic logged{false}; - if (!logged.exchange(true, std::memory_order_relaxed)) - std::fprintf(stderr, - "[rt] d3d12_xs: slot 25: render target sizes padded to console tiles, +%llu B on " - "%llu B for %u description(s)\n", - static_cast(extra), - static_cast(info.SizeInBytes), static_cast(count)); - info.SizeInBytes = extra > kSizeSaturated - info.SizeInBytes ? kSizeSaturated : info.SizeInBytes + extra; - } - } + const UINT mask = static_cast(visible_mask), n = static_cast(count); + D3D12_RESOURCE_ALLOCATION_INFO info = real->GetResourceAllocationInfo(mask, n, descs); + apply_console_placement(descs, n, info, nullptr, + [&](UINT i) { return real->GetResourceAllocationInfo(mask, 1, &descs[i]); }, 25); *static_cast(call.ret) = info; return call.ret; } +// Slot 56, ID3D12Device4::GetResourceAllocationInfo1: the same answer, and the per-description offsets follow the +// padded sizes, so a title that places its resources at those offsets does not overlap them. The call is forwarded +// as it came; the console layout then replaces the total and the offsets. +void* WINAPI proxy_get_resource_allocation_info1(std::uint64_t a0, std::uint64_t a1, std::uint64_t visible_mask, + std::uint64_t count, const D3D12_RESOURCE_DESC* descs, + D3D12_RESOURCE_ALLOCATION_INFO1* each) { + const StructReturnCall call = struct_return_call(a0, a1); + DeviceProxy* const self = call.self; + note_slot(56); + if (56 >= self->slot_count) { + return reinterpret_cast(hr_to_u64(refuse_beyond_device(56, self->slot_count))); + } + using Fn = void*(WINAPI*)(void*, void*, UINT, UINT, const D3D12_RESOURCE_DESC*, D3D12_RESOURCE_ALLOCATION_INFO1*); + const UINT n = static_cast(count); + void* const returned = reinterpret_cast(self->real_vtable[56])( + self->real, call.ret, static_cast(visible_mask), n, descs, each); + if (each) { + auto& info = *static_cast(call.ret); + apply_console_placement(descs, n, info, each, [&](UINT i) { + return D3D12_RESOURCE_ALLOCATION_INFO{each[i].SizeInBytes, each[i].Alignment}; + }, 56); + } + return returned; +} + void** get_vtable() { static void** vtable = [] { static void* storage[kMaxSlots]; fill_vtable(storage, std::make_index_sequence{}); storage[25] = reinterpret_cast(&proxy_get_resource_allocation_info); + storage[56] = reinterpret_cast(&proxy_get_resource_allocation_info1); return storage; }(); return vtable; @@ -1798,7 +1827,7 @@ ID3D12Device* device_proxy_real_device(const void* device) { bool device_slot_overridden(unsigned slot) { if (slot <= 2 || slot == 8 || slot == 9 || slot == 14 || slot == 25 || slot == 26 || slot == 31 || slot == 32 || slot == 34 || - slot == 35 || slot == 36 || slot == 45 || slot == 46 || slot == 50 || slot == 62 || slot == 67 || + slot == 35 || slot == 36 || slot == 45 || slot == 46 || slot == 50 || slot == 56 || slot == 62 || slot == 67 || slot == 75 || slot == 76) return true; const XboxDeviceSlotRoutes& routes = xbox_device_slot_routes(); diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp index 800293cad1..51765382b6 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -16,6 +16,8 @@ #include #include +#include + #include #include @@ -183,24 +185,46 @@ void copy_array(Mock* m, unsigned slot, std::uint64_t objects, std::uint64_t cou for (std::uint32_t i = 0; in && i < static_cast(count) && i < 4; ++i) m->array[slot][i] = in[i]; } -// The PC device's GetResourceAllocationInfo, as a driver that packs a surface with no tile padding answers it: a buffer -// its width, a texture width x height x slices x element bytes (4 for RGBA8, 8 for RGBA16F), each rounded up to -// 64 KiB, summed over the descriptions; a texture with no width is refused. The struct is written to the hidden return -// pointer (RDX of a C++ method call), which comes back in RAX. -std::uint64_t mock_allocation_info(std::uint64_t ret, std::uint64_t count, std::uint64_t descs_word) { +// GetResourceAllocationInfo as a PC driver without console tile padding answers it. A buffer is its width, a texture +// width x height x slices x element bytes (2 for B5G5R5A1, 4 for RGBA8, 8 for RGBA16F, 16 for RGBA32F; mips are not +// counted, and one resource is at most 4 GiB, the way a driver caps an allocation), each rounded up to the +// resource's alignment: 64 KiB, or 4 MiB with more than one sample. A texture with no width is refused. Resources are +// laid out one after another, each at its own alignment, and the total is rounded up to the largest alignment, as the +// Vulkan layer's place() does. The struct is written to the hidden return pointer (RDX of a C++ method call), which +// comes back in RAX. `each` (slot 56) gets every resource's offset, alignment and size. +std::uint64_t mock_align(std::uint64_t value, std::uint64_t to) { + return value > UINT64_MAX - (to - 1) ? UINT64_MAX / to * to : (value + to - 1) / to * to; +} + +D3D12_RESOURCE_ALLOCATION_INFO mock_one_allocation(const D3D12_RESOURCE_DESC& d) { + if (d.Width == 0) return {UINT64_MAX, 65536}; + if (d.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) return {mock_align(d.Width, 65536), 65536}; + std::uint64_t element = 4; + if (d.Format == DXGI_FORMAT_B5G5R5A1_UNORM) element = 2; + if (d.Format == DXGI_FORMAT_R16G16B16A16_FLOAT) element = 8; + if (d.Format == DXGI_FORMAT_R32G32B32A32_FLOAT) element = 16; + const std::uint64_t samples = d.SampleDesc.Count ? d.SampleDesc.Count : 1; + const std::uint64_t alignment = samples > 1 ? 4194304 : 65536; + const std::uint64_t bytes = std::min( + d.Width * d.Height * d.DepthOrArraySize * element * samples, std::uint64_t{4} << 30); + return {mock_align(bytes, alignment), alignment}; +} + +std::uint64_t mock_allocation_info(std::uint64_t ret, std::uint64_t count, std::uint64_t descs_word, + D3D12_RESOURCE_ALLOCATION_INFO1* each = nullptr) { const auto* descs = reinterpret_cast(descs_word); - std::uint64_t total = 0; + D3D12_RESOURCE_ALLOCATION_INFO total{0, 1}; bool refused = false; for (std::uint32_t i = 0; descs && i < static_cast(count); ++i) { - const D3D12_RESOURCE_DESC& d = descs[i]; - std::uint64_t bytes = d.Width; - if (d.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER) - bytes = d.Width * d.Height * d.DepthOrArraySize * (d.Format == DXGI_FORMAT_R16G16B16A16_FLOAT ? 8 : 4); - refused = refused || d.Width == 0; - total += (bytes + 65535) / 65536 * 65536; + const D3D12_RESOURCE_ALLOCATION_INFO one = mock_one_allocation(descs[i]); + refused = refused || one.SizeInBytes == UINT64_MAX; + const std::uint64_t offset = mock_align(total.SizeInBytes, one.Alignment); + if (each) each[i] = {offset, one.Alignment, one.SizeInBytes}; + total.SizeInBytes = one.SizeInBytes > UINT64_MAX - offset ? UINT64_MAX : offset + one.SizeInBytes; + total.Alignment = std::max(total.Alignment, one.Alignment); } auto* out = reinterpret_cast(ret); - *out = {refused ? UINT64_MAX : total, 65536}; + *out = {refused ? UINT64_MAX : mock_align(total.SizeInBytes, total.Alignment), total.Alignment}; return ret; } @@ -218,6 +242,8 @@ std::uint64_t mock_call(Mock* m, unsigned slot, const std::uint64_t* words) { if (a1 == kResourceHandle) return static_cast(mock_create(m, Kind::resource, a2, a3)); return static_cast(E_INVALIDARG); case 25: return mock_allocation_info(a1, a3, a4); // GetResourceAllocationInfo (mask a2 is unused) + case 56: // GetResourceAllocationInfo1: (return buffer, mask, count, descs, per-description array) + return mock_allocation_info(a1, a3, a4, reinterpret_cast(words[4])); case 34: case 35: case 46: copy_array(m, slot, a2, a1); break; // (count, objects, ...) case 45: copy_array(m, slot, a1, a3); break; // (fences, values, count, ...) case 26: { // GetCustomHeapProperties, the PC method: (return buffer, node mask, heap type) @@ -811,6 +837,106 @@ int check_render_target_sizes() { return 0; } +// ---- 11. Console render target layout: alignment, per-description offsets, mips, formats, overflow ---- + +int check_render_target_layout() { + Mock* mock = nullptr; + void* device = make_device(mock, 9, true); + EXPECT(device); + void* const* vtable = *reinterpret_cast(device); + // The retail executable's calls: the buffer for the struct in RCX, the device in RDX. + using InfoFn = D3D12_RESOURCE_ALLOCATION_INFO*(WINAPI*)(D3D12_RESOURCE_ALLOCATION_INFO*, void*, UINT, UINT, + const D3D12_RESOURCE_DESC*); + using Info1Fn = D3D12_RESOURCE_ALLOCATION_INFO*(WINAPI*)(D3D12_RESOURCE_ALLOCATION_INFO*, void*, UINT, UINT, + const D3D12_RESOURCE_DESC*, + D3D12_RESOURCE_ALLOCATION_INFO1*); + const auto get_info = reinterpret_cast(vtable[25]); + const auto get_info1 = reinterpret_cast(vtable[56]); + auto ask = [&](const D3D12_RESOURCE_DESC* descs, UINT count) { + D3D12_RESOURCE_ALLOCATION_INFO info{0xDEAD, 0xBEEF}; + if (get_info(&info, device, 0, count, descs) != &info) info = {0, 0}; + return info; + }; + auto ask_one = [&](const D3D12_RESOURCE_DESC& d) { return ask(&d, 1); }; + auto target = [](std::uint64_t w, UINT h, DXGI_FORMAT f, UINT slices, UINT mips) { + D3D12_RESOURCE_DESC d = target_desc(w, h, f, slices); + d.MipLevels = static_cast(mips); + return d; + }; + + // A four-sample 1 x 1 target is 4 MiB at 4 MiB alignment. Next to a 1080p target that grows to 8,847,360 B, the + // two need 4 MiB + 8,847,360 B = 13,041,664 B placed, and the total is a whole number of 4 MiB: 16 MiB, in + // either order. (The PC device says 12 MiB for them; adding the 512 KiB the padding takes would say 12.5 MiB.) + const D3D12_RESOURCE_DESC hd = target_desc(1920, 1080, DXGI_FORMAT_R8G8B8A8_UNORM); + D3D12_RESOURCE_DESC msaa = target_desc(1, 1, DXGI_FORMAT_R8G8B8A8_UNORM); + msaa.SampleDesc.Count = 4; + const D3D12_RESOURCE_DESC msaa_first[] = {msaa, hd}; + const D3D12_RESOURCE_DESC msaa_last[] = {hd, msaa}; + D3D12_RESOURCE_ALLOCATION_INFO info = ask(msaa_first, 2); + EXPECT(info.SizeInBytes == 16777216 && info.Alignment == 4194304); + info = ask(msaa_last, 2); + EXPECT(info.SizeInBytes == 16777216 && info.Alignment == 4194304); + EXPECT(ask(&msaa, 1).SizeInBytes == 4194304); // multisampled targets are left as the PC device sizes them + + // GetResourceAllocationInfo1: the offsets follow the padded sizes, in the console form and the PC form. + const D3D12_RESOURCE_DESC two[] = {hd, hd}; + D3D12_RESOURCE_ALLOCATION_INFO1 each[2]{}; + D3D12_RESOURCE_ALLOCATION_INFO total{}; + EXPECT(get_info1(&total, device, 0, 2, two, each) == &total); + EXPECT(total.SizeInBytes == 17694720 && total.Alignment == 65536); + EXPECT(each[0].Offset == 0 && each[0].SizeInBytes == 8847360 && each[0].Alignment == 65536); + EXPECT(each[1].Offset == 8847360 && each[1].SizeInBytes == 8847360 && each[1].Alignment == 65536); + D3D12_RESOURCE_ALLOCATION_INFO1 mixed[2]{}; + D3D12_RESOURCE_ALLOCATION_INFO pc{}; + EXPECT(raw(device, 56, word(&pc), 0, 2, word(msaa_first), word(mixed)) == word(&pc)); + EXPECT(pc.SizeInBytes == 16777216 && pc.Alignment == 4194304); + EXPECT(mixed[0].Offset == 0 && mixed[0].SizeInBytes == 4194304 && mixed[0].Alignment == 4194304); + EXPECT(mixed[1].Offset == 4194304 && mixed[1].SizeInBytes == 8847360 && mixed[1].Alignment == 65536); + // Nothing to pad: the PC device's answer stands, per-description array included. + D3D12_RESOURCE_DESC buffer{}; + buffer.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; + buffer.Width = 100000; + buffer.Height = 1; + buffer.DepthOrArraySize = 1; + buffer.MipLevels = 1; + buffer.SampleDesc.Count = 1; + buffer.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; + const D3D12_RESOURCE_DESC buffers[] = {buffer, buffer}; + D3D12_RESOURCE_ALLOCATION_INFO1 plain[2]{}; + EXPECT(get_info1(&total, device, 0, 2, buffers, plain) == &total); + EXPECT(total.SizeInBytes == 262144 && plain[1].Offset == 131072 && plain[1].SizeInBytes == 131072); + + // Mips: 0 is the full chain. 256 x 128 RGBA8 takes two tiles for mip 0, one for mip 1 (128 x 64 is wider than half a + // tile) and one tail tile for the rest. + EXPECT(ask_one(target(256, 128, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 0)).SizeInBytes == + 4 * 65536ull); + // 128 x 32 with two mips and two slices: mip 0 is a whole tile, mip 1 (64 x 16) is the tail tile, per slice. + EXPECT(ask_one(target(128, 32, DXGI_FORMAT_R8G8B8A8_UNORM, 2, 2)).SizeInBytes == + 4 * 65536ull); + // 257 x 32 with two mips: mip 0 is 3 tiles across, mip 1 is 129 x 16 (an odd extent rounds up): 2 tiles. + EXPECT(ask_one(target(257, 32, DXGI_FORMAT_R8G8B8A8_UNORM, 1, 2)).SizeInBytes == + 5 * 65536ull); + // 2-byte B5G5R5A1 is a 256 x 128 tile: 257 x 64 takes two. + EXPECT(ask_one(target(257, 64, DXGI_FORMAT_B5G5R5A1_UNORM, 1, 1)).SizeInBytes == + 2 * 65536ull); + // 16-byte RGBA32F is a 64 x 64 tile: 65 x 32 takes two. + EXPECT(ask_one(target(65, 32, DXGI_FORMAT_R32G32B32A32_FLOAT, 1, 1)).SizeInBytes == + 2 * 65536ull); + + // Sums saturate where the PC device's do. A 2^26 x 2^26 RGBA32F target of 200 slices is 200 x 2^56 B (the PC mock + // caps it at 4 GiB); two of them are past 2^64. + const D3D12_RESOURCE_DESC huge = target(1ull << 26, 1u << 26, DXGI_FORMAT_R32G32B32A32_FLOAT, 200, 1); + EXPECT(ask(&huge, 1).SizeInBytes == 200ull << 56); + const D3D12_RESOURCE_DESC huge_two[] = {huge, huge}; + info = ask(huge_two, 2); + EXPECT(info.SizeInBytes == 0xFFFFFFFFFFFF0000ull && info.Alignment == 65536); + + EXPECT(release(device) == 0 && mock->refs == 0); + std::printf("%s: render targets are laid out at their own alignments, with per-description offsets, mip chains " + "and saturating sums\n", g_label); + return 0; +} + // ---- 7. Xbox device slots from the public HLE (48, 73, 78, 79, 80) ---- // // A device that answers ID3D12Device11 (80 PC slots) is the Vulkan layer's shape: slots 78/79 are inside its table @@ -1116,8 +1242,8 @@ int main(int argc, char** argv) { } if (argc != 1) return 2; if (check_tail(true) || check_levels() || check_fence1() || check_create_failures() || check_open_shared() || - check_alloc_failures() || check_allocators() || check_render_target_sizes() || check_xbox_slots() || - check_custom_heap_properties()) + check_alloc_failures() || check_allocators() || check_render_target_sizes() || check_render_target_layout() || + check_xbox_slots() || check_custom_heap_properties()) return 1; std::printf("xs_proxy_mock_test: PASS (%d allocations refused on purpose)\n", g_failed_news); return 0; From d7451f9d9b0ef8881219979a4a9c538e4939b134 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Mon, 23 Nov 2026 17:34:42 +0100 Subject: [PATCH 08/13] test: device_proxy_test expects slot 25 to answer for the cleaned description, the PC device's answer for the console layout word is UINT64_MAX (found by devnull34 on #7110) --- runtime/test/device_proxy_test.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/runtime/test/device_proxy_test.cpp b/runtime/test/device_proxy_test.cpp index 3cf5ff5c06..7e27c6ee86 100644 --- a/runtime/test/device_proxy_test.cpp +++ b/runtime/test/device_proxy_test.cpp @@ -23,6 +23,7 @@ #include #include "d3d12_trace.h" +#include "d3d12_xs_desc_clean.h" #include "d3d12_xs_device.h" #include "shims.h" @@ -212,7 +213,10 @@ int main(int argc, char** argv) { const D3D12_RESOURCE_DESC desc = buffer_desc(); D3D12_RESOURCE_ALLOCATION_INFO got{~0ull, ~0ull}; D3D12_RESOURCE_ALLOCATION_INFO* returned = get_alloc_info(&got, device.Get(), 0, 1, &desc); - const D3D12_RESOURCE_ALLOCATION_INFO want = real->GetResourceAllocationInfo(0, 1, &desc); + // The proxy cleans the console layout word and flag bits before the PC call (stop 16), so the expected answer is + // the PC device's for the cleaned description (the raw 0x101 layout makes WARP answer UINT64_MAX). + const D3D12_RESOURCE_DESC clean = rt::d3d12_xs::pc_resource_desc(desc); + const D3D12_RESOURCE_ALLOCATION_INFO want = real->GetResourceAllocationInfo(0, 1, &clean); check(returned == &got, "slot 25 returns the caller's buffer in RAX"); check(got.SizeInBytes == want.SizeInBytes && got.Alignment == want.Alignment, "slot 25 (C ABI) writes the PC device's GetResourceAllocationInfo into the caller's buffer"); From b4d1ba179436a73989b7c33dfcdd1eda473575f4 Mon Sep 17 00:00:00 2001 From: Johan John Joji <83926918+TripleJ160@users.noreply.github.com> Date: Mon, 23 Nov 2026 11:37:29 -0500 Subject: [PATCH 09/13] d3d12: preserve PC descriptor validation in slot 25 --- docs/d3d12_vulkan.md | 5 +++-- runtime/shims/d3d12_xs_desc_clean.h | 11 +++++++---- runtime/shims/d3d12_xs_device.cpp | 14 +++++++++----- runtime/test/device_proxy_test.cpp | 1 + runtime/test/xs_proxy_mock_test.cpp | 12 ++++++++++++ 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index 829ea3e326..af6f48ef5e 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -2223,8 +2223,9 @@ The trace will enumerate them. retail title's own sizes are not measured (#6982, stop 17), so that its allocation is these shapes and no DCC or CMask memory is open until they are. The descriptions the title passes to slot 25 carry console values (layout word `0x101`/`0x1`, flag bits above the PC - ones). The proxy gives the PC device a copy with the PC flags only and ROW_MAJOR (buffer) or UNKNOWN (texture); the - title's array is never written (`d3d12_xs_desc_clean.h`, the same cleaning as slot 76; #6982 section 3.7). + ones). For console-form calls or descriptors explicitly using layout `0x101`, the proxy strips Xbox-only flags and + translates layout `0x101` to ROW_MAJOR for buffers or UNKNOWN for textures. Other PC-form descriptors reach the host + unchanged for validation (`d3d12_xs_desc_clean.h`; #6982 section 3.7). - `GetAdapterLuid` (implemented): `VkPhysicalDeviceIDProperties::deviceLUID`, which on Windows is the DXGI adapter's LUID; `d3d12_fence_timing_test` finds it with `IDXGIFactory4::EnumAdapterByLuid` (RTX 4090, driver 621.14). A driver that reports `deviceLUIDValid = VK_FALSE` gets a zero LUID, logged. diff --git a/runtime/shims/d3d12_xs_desc_clean.h b/runtime/shims/d3d12_xs_desc_clean.h index 61f49eb8b2..1782b7d880 100644 --- a/runtime/shims/d3d12_xs_desc_clean.h +++ b/runtime/shims/d3d12_xs_desc_clean.h @@ -21,12 +21,15 @@ constexpr std::uint32_t kPcResourceFlagsMask = D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY | D3D12_RESOURCE_FLAG_VIDEO_ENCODE_REFERENCE_ONLY | D3D12_RESOURCE_FLAG_RAYTRACING_ACCELERATION_STRUCTURE; -// A copy of the title's description with the PC flags only and a PC layout: ROW_MAJOR for a buffer, UNKNOWN for a -// texture (the layout the PC device picks itself). +constexpr auto kXboxTiledResourceLayout = static_cast(0x101); + +// Strip Xbox-only flags and translate the Xbox tiled layout. Preserve all other layouts so the host can validate them. inline D3D12_RESOURCE_DESC pc_resource_desc(const D3D12_RESOURCE_DESC& xbox) { D3D12_RESOURCE_DESC pc = xbox; - pc.Layout = xbox.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? D3D12_TEXTURE_LAYOUT_ROW_MAJOR - : D3D12_TEXTURE_LAYOUT_UNKNOWN; + if (pc.Layout == kXboxTiledResourceLayout) { + pc.Layout = pc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? D3D12_TEXTURE_LAYOUT_ROW_MAJOR + : D3D12_TEXTURE_LAYOUT_UNKNOWN; + } pc.Flags = static_cast(static_cast(xbox.Flags) & kPcResourceFlagsMask); return pc; } diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index bcf630d84a..cf95372ed7 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -1631,13 +1631,14 @@ void** get_vtable(); struct StructReturnCall { DeviceProxy* self; void* ret; + bool console_abi; }; StructReturnCall struct_return_call(std::uint64_t a0, std::uint64_t a1) { void** const vtable = get_vtable(); if (a0 && *reinterpret_cast(a0) == vtable) // PC form: this, return buffer - return {reinterpret_cast(a0), reinterpret_cast(a1)}; - return {reinterpret_cast(a1), reinterpret_cast(a0)}; // C form: return buffer, this + return {reinterpret_cast(a0), reinterpret_cast(a1), false}; + return {reinterpret_cast(a1), reinterpret_cast(a0), true}; // C form: return buffer, this } // The console size of a list of descriptions (d3d12_xs_alloc_size.h): the PC device's answer with every console render @@ -1664,8 +1665,8 @@ void* WINAPI proxy_get_resource_allocation_info(std::uint64_t a0, std::uint64_t note_slot(25); const StructReturnCall call = struct_return_call(a0, a1); ID3D12Device* const real = call.self->real; - // The descriptions are the console's. The PC device gets a copy with PC flags and layout; the title's array is - // read only. A copy that cannot be made answers as an invalid description. + // Normalize console descriptors in a copy. PC calls can also pass the Xbox tiled layout explicitly. Otherwise + // their flags and layout reach the host unchanged so the host can validate them. const UINT desc_count = static_cast(count); std::unique_ptr clean; if (descs && desc_count) { @@ -1674,7 +1675,10 @@ void* WINAPI proxy_get_resource_allocation_info(std::uint64_t a0, std::uint64_t *static_cast(call.ret) = {UINT64_MAX, D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT}; return call.ret; } - for (UINT i = 0; i < desc_count; ++i) clean[i] = pc_resource_desc(descs[i]); + for (UINT i = 0; i < desc_count; ++i) { + const auto& desc = descs[i]; + clean[i] = call.console_abi || desc.Layout == kXboxTiledResourceLayout ? pc_resource_desc(desc) : desc; + } descs = clean.get(); } const UINT mask = static_cast(visible_mask); diff --git a/runtime/test/device_proxy_test.cpp b/runtime/test/device_proxy_test.cpp index 7e27c6ee86..af0afde22a 100644 --- a/runtime/test/device_proxy_test.cpp +++ b/runtime/test/device_proxy_test.cpp @@ -217,6 +217,7 @@ int main(int argc, char** argv) { // the PC device's for the cleaned description (the raw 0x101 layout makes WARP answer UINT64_MAX). const D3D12_RESOURCE_DESC clean = rt::d3d12_xs::pc_resource_desc(desc); const D3D12_RESOURCE_ALLOCATION_INFO want = real->GetResourceAllocationInfo(0, 1, &clean); + check(want.SizeInBytes != UINT64_MAX, "WARP accepts the normalized slot-25 buffer description"); check(returned == &got, "slot 25 returns the caller's buffer in RAX"); check(got.SizeInBytes == want.SizeInBytes && got.Alignment == want.Alignment, "slot 25 (C ABI) writes the PC device's GetResourceAllocationInfo into the caller's buffer"); diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp index 92db4cb987..3356e378bd 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -892,6 +892,18 @@ int check_allocation_descriptions_cleaned() { EXPECT(std::memcmp(kept, titles, sizeof(kept)) == 0); EXPECT(info.SizeInBytes == 8847360 + 131072); + // PC calls must keep their layout and flags so the host can reject an invalid descriptor. + using PcFn = D3D12_RESOURCE_ALLOCATION_INFO*(WINAPI*)(void*, D3D12_RESOURCE_ALLOCATION_INFO*, UINT, UINT, + const D3D12_RESOURCE_DESC*); + const auto get_pc_info = reinterpret_cast(vtable[25]); + D3D12_RESOURCE_DESC pc_buffer = titles[1]; + pc_buffer.Layout = D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE; + pc_buffer.Flags = static_cast(0x1000); + g_seen_calls = 0; + EXPECT(get_pc_info(device, &info, 0, 1, &pc_buffer) == &info); + EXPECT(g_seen_desc_count == 1 && g_seen_descs[0].Layout == D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE); + EXPECT(g_seen_descs[0].Flags == pc_buffer.Flags); + // A null array with a zero count reaches the PC device as it came. g_seen_desc_count = 99; g_seen_calls = 0; From 3ace9869da2d6607a297e7ca6398bf4be342d78d Mon Sep 17 00:00:00 2001 From: tedin7 Date: Mon, 23 Nov 2026 17:39:33 +0100 Subject: [PATCH 10/13] fix: slot 56 gives the same console total when the caller passes no per-resource array --- runtime/shims/d3d12_xs_device.cpp | 12 ++++++++++++ runtime/test/xs_proxy_mock_test.cpp | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 858771f3be..c53ea04661 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -1685,6 +1686,17 @@ void* WINAPI proxy_get_resource_allocation_info1(std::uint64_t a0, std::uint64_t } using Fn = void*(WINAPI*)(void*, void*, UINT, UINT, const D3D12_RESOURCE_DESC*, D3D12_RESOURCE_ALLOCATION_INFO1*); const UINT n = static_cast(count); + // The per-resource array is optional (_Out_writes_opt_). The console total must not depend on whether the + // caller asked for it, so without one the host's per-resource answers go to a local array (found by Alpha325). + std::vector local; + if (!each && descs && n) { + try { + local.resize(n); + each = local.data(); + } catch (const std::bad_alloc&) { + each = nullptr; // the host total stands + } + } void* const returned = reinterpret_cast(self->real_vtable[56])( self->real, call.ret, static_cast(visible_mask), n, descs, each); if (each) { diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp index 51765382b6..03de5a3a78 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -886,6 +886,10 @@ int check_render_target_layout() { EXPECT(total.SizeInBytes == 17694720 && total.Alignment == 65536); EXPECT(each[0].Offset == 0 && each[0].SizeInBytes == 8847360 && each[0].Alignment == 65536); EXPECT(each[1].Offset == 8847360 && each[1].SizeInBytes == 8847360 && each[1].Alignment == 65536); + // The per-description array is optional: without one the total is the same 17,694,720 B. + D3D12_RESOURCE_ALLOCATION_INFO no_array{}; + EXPECT(get_info1(&no_array, device, 0, 2, two, nullptr) == &no_array); + EXPECT(no_array.SizeInBytes == 17694720 && no_array.Alignment == 65536); D3D12_RESOURCE_ALLOCATION_INFO1 mixed[2]{}; D3D12_RESOURCE_ALLOCATION_INFO pc{}; EXPECT(raw(device, 56, word(&pc), 0, 2, word(msaa_first), word(mixed)) == word(&pc)); From 4a86034367eacdfca77298d89e37a5bc8545e4e5 Mon Sep 17 00:00:00 2001 From: NiiRoZz Date: Mon, 23 Nov 2026 18:14:31 +0100 Subject: [PATCH 11/13] d3d12_xs: a console depth-stencil texture with unordered access is sized and created without it (stand-in) The console allows ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS on a texture; the PC runtime refuses the pair and slot 25 answered UINT64_MAX for it. pc_resource_flags drops the UAV bit from depth-stencil textures (slot 25 through pc_resource_desc, and slot 76). Their UAV views then write no descriptor. Co-Authored-By: Claude Opus 5.5 --- runtime/shims/d3d12_xs_desc_clean.h | 19 ++++++++++++++- runtime/shims/d3d12_xs_device.cpp | 12 +++++++++ runtime/test/device_proxy_test.cpp | 38 +++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/runtime/shims/d3d12_xs_desc_clean.h b/runtime/shims/d3d12_xs_desc_clean.h index 1782b7d880..51541dda61 100644 --- a/runtime/shims/d3d12_xs_desc_clean.h +++ b/runtime/shims/d3d12_xs_desc_clean.h @@ -23,6 +23,23 @@ constexpr std::uint32_t kPcResourceFlagsMask = constexpr auto kXboxTiledResourceLayout = static_cast(0x101); +// The console allows a depth-stencil texture to allow unordered access too (measured locally at a title's call sites: +// a 2D R32G8X24_TYPELESS texture with ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS, sized through slot 25), but the PC +// runtime refuses that pair, and Vulkan has no depth format with storage support to make it with. Stand-in: such a +// texture is a depth-stencil texture without unordered access. Its unordered-access views write no descriptor (the PC +// layer refuses a UAV of a texture without the flag), so what a shader writes through them goes nowhere and their +// reads see whatever the descriptor held. +inline std::uint32_t without_depth_stencil_uav(D3D12_RESOURCE_DIMENSION dimension, std::uint32_t flags) { + if (dimension != D3D12_RESOURCE_DIMENSION_BUFFER && (flags & D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)) + flags &= ~static_cast(D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS); + return flags; +} + +// The PC flags of a console description: the PC bits only, without unordered access on a depth-stencil texture. +inline std::uint32_t pc_resource_flags(D3D12_RESOURCE_DIMENSION dimension, std::uint32_t xbox_flags) { + return without_depth_stencil_uav(dimension, xbox_flags & kPcResourceFlagsMask); +} + // Strip Xbox-only flags and translate the Xbox tiled layout. Preserve all other layouts so the host can validate them. inline D3D12_RESOURCE_DESC pc_resource_desc(const D3D12_RESOURCE_DESC& xbox) { D3D12_RESOURCE_DESC pc = xbox; @@ -30,7 +47,7 @@ inline D3D12_RESOURCE_DESC pc_resource_desc(const D3D12_RESOURCE_DESC& xbox) { pc.Layout = pc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? D3D12_TEXTURE_LAYOUT_ROW_MAJOR : D3D12_TEXTURE_LAYOUT_UNKNOWN; } - pc.Flags = static_cast(static_cast(xbox.Flags) & kPcResourceFlagsMask); + pc.Flags = static_cast(pc_resource_flags(xbox.Dimension, static_cast(xbox.Flags))); return pc; } diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index e82bfb8507..b38e2613f7 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -1476,6 +1476,10 @@ HRESULT proxy_create_resource(DeviceProxy* self, const D3D12_HEAP_PROPERTIES* he const auto xbox_layout = static_cast(pc_desc.Layout); pc_desc.Layout = pc_desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? D3D12_TEXTURE_LAYOUT_ROW_MAJOR : D3D12_TEXTURE_LAYOUT_UNKNOWN; + // A console depth-stencil texture may allow unordered access; the PC one may not (without_depth_stencil_uav, the + // slot 25 stand-in). Only that bit is dropped here: the other flag bits go on as they came. + pc_desc.Flags = static_cast( + without_depth_stencil_uav(pc_desc.Dimension, static_cast(pc_desc.Flags))); static std::atomic logged{false}; if (!logged.exchange(true, std::memory_order_relaxed)) { @@ -1679,6 +1683,14 @@ void* WINAPI proxy_get_resource_allocation_info(std::uint64_t a0, std::uint64_t for (UINT i = 0; i < desc_count; ++i) { const auto& desc = descs[i]; clean[i] = call.console_abi || desc.Layout == kXboxTiledResourceLayout ? pc_resource_desc(desc) : desc; + static std::atomic uav_dropped{false}; + if (((static_cast(desc.Flags) & ~static_cast(clean[i].Flags)) & + D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS) && + first_call(uav_dropped)) + std::fprintf(stderr, + "[rt] d3d12_xs: slot 25: depth-stencil texture (format %d) sized without unordered " + "access, which the PC refuses with it (stand-in)\n", + static_cast(desc.Format)); } descs = clean.get(); } diff --git a/runtime/test/device_proxy_test.cpp b/runtime/test/device_proxy_test.cpp index af0afde22a..d218f4ded3 100644 --- a/runtime/test/device_proxy_test.cpp +++ b/runtime/test/device_proxy_test.cpp @@ -227,6 +227,44 @@ int main(int argc, char** argv) { const D3D12_RESOURCE_ALLOCATION_INFO pc_info = device->GetResourceAllocationInfo(0, 1, &desc); check(pc_info.SizeInBytes == want.SizeInBytes && pc_info.Alignment == want.Alignment, "slot 25 still answers the PC (C++) form"); + + // A console depth-stencil texture that allows unordered access too, as a title sizes one: a 2D + // R32G8X24_TYPELESS texture with ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS and the console layout word. The + // PC device refuses the flag pair (negative control); slot 25 sizes it as the depth-stencil texture alone. + D3D12_RESOURCE_DESC ds_uav{}; + ds_uav.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; + ds_uav.Width = 2560; + ds_uav.Height = 1440; + ds_uav.DepthOrArraySize = 1; + ds_uav.MipLevels = 1; + ds_uav.Format = DXGI_FORMAT_R32G8X24_TYPELESS; + ds_uav.SampleDesc.Count = 1; + ds_uav.Layout = static_cast(0x101); + ds_uav.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; + D3D12_RESOURCE_DESC pc_pair = ds_uav; + pc_pair.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; + check(real->GetResourceAllocationInfo(0, 1, &pc_pair).SizeInBytes == UINT64_MAX, + "the PC device refuses a depth-stencil texture with unordered access (negative control)"); + D3D12_RESOURCE_DESC ds_only = pc_pair; + ds_only.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; + const D3D12_RESOURCE_ALLOCATION_INFO ds_want = real->GetResourceAllocationInfo(0, 1, &ds_only); + check(ds_want.SizeInBytes != UINT64_MAX, "WARP sizes the depth-stencil texture without unordered access"); + const D3D12_RESOURCE_DESC ds_clean = rt::d3d12_xs::pc_resource_desc(ds_uav); + check(ds_clean.Flags == D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL, + "pc_resource_desc drops unordered access from a depth-stencil texture"); + D3D12_RESOURCE_DESC uav_buffer = buffer_desc(); + uav_buffer.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; + D3D12_RESOURCE_DESC rt_uav = ds_only; + rt_uav.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + rt_uav.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; + check(rt::d3d12_xs::pc_resource_desc(uav_buffer).Flags == D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS && + rt::d3d12_xs::pc_resource_desc(rt_uav).Flags == rt_uav.Flags, + "pc_resource_desc keeps unordered access on buffers and color textures"); + D3D12_RESOURCE_ALLOCATION_INFO ds_got{~0ull, ~0ull}; + get_alloc_info(&ds_got, device.Get(), 0, 1, &ds_uav); + check(ds_got.SizeInBytes != UINT64_MAX && ds_got.SizeInBytes >= ds_want.SizeInBytes && + (ds_got.SizeInBytes >> 32) == 0, + "slot 25 (C ABI) sizes a console depth-stencil texture with unordered access"); } D3D12_RESOURCE_DESC reserved_desc = buffer_desc(); From b8cbab6ab0b37920addfc5a362449f49a8220637 Mon Sep 17 00:00:00 2001 From: tedin7 Date: Mon, 23 Nov 2026 19:18:17 +0100 Subject: [PATCH 12/13] d3d12: normalize additional console layouts in slot 25 --- runtime/shims/d3d12_xs_desc_clean.h | 15 ++++++++------- runtime/test/xs_proxy_mock_test.cpp | 30 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/runtime/shims/d3d12_xs_desc_clean.h b/runtime/shims/d3d12_xs_desc_clean.h index 1782b7d880..7f09306659 100644 --- a/runtime/shims/d3d12_xs_desc_clean.h +++ b/runtime/shims/d3d12_xs_desc_clean.h @@ -1,9 +1,7 @@ // The PC form of a resource description the retail title builds for the console, for the Xbox-ABI device proxy. // -// The title's D3D12_RESOURCE_DESC carries console values the PC device cannot take: the layout word is 0x101 (tiled) -// or 0x1 (row-major buffer), and the flags have bits above the PC ones set (docs/retail_boot_chain.md, #6982). Slot 76 -// replaces the layout word the same way before it forwards to CreateCommittedResource; slot 25 and the slot 127 -// stand-in need the same cleaning. The title's own description is never written: a caller gets a copy. +// The title's D3D12_RESOURCE_DESC carries console layout words and flag bits the PC device cannot take +// (docs/retail_boot_chain.md, #6982). The slot 25 cleaner returns a copy of the title's description. #pragma once #include @@ -21,12 +19,15 @@ constexpr std::uint32_t kPcResourceFlagsMask = D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY | D3D12_RESOURCE_FLAG_VIDEO_ENCODE_REFERENCE_ONLY | D3D12_RESOURCE_FLAG_RAYTRACING_ACCELERATION_STRUCTURE; -constexpr auto kXboxTiledResourceLayout = static_cast(0x101); +inline const auto kXboxTiledResourceLayout = static_cast(0x101); -// Strip Xbox-only flags and translate the Xbox tiled layout. Preserve all other layouts so the host can validate them. +// Strip Xbox-only flags and preserve the three supported PC layouts. In addition to 0x101, zebraso measured +// layout words 0x102 and 0x105 reaching slot 25 during a retail boot. inline D3D12_RESOURCE_DESC pc_resource_desc(const D3D12_RESOURCE_DESC& xbox) { D3D12_RESOURCE_DESC pc = xbox; - if (pc.Layout == kXboxTiledResourceLayout) { + if (pc.Layout != D3D12_TEXTURE_LAYOUT_UNKNOWN && + pc.Layout != D3D12_TEXTURE_LAYOUT_ROW_MAJOR && + pc.Layout != D3D12_TEXTURE_LAYOUT_64KB_STANDARD_SWIZZLE) { pc.Layout = pc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? D3D12_TEXTURE_LAYOUT_ROW_MAJOR : D3D12_TEXTURE_LAYOUT_UNKNOWN; } diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp index 29d4d2d211..0d4513911c 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -892,6 +892,36 @@ int check_allocation_descriptions_cleaned() { EXPECT(std::memcmp(kept, titles, sizeof(kept)) == 0); EXPECT(info.SizeInBytes == 8847360 + 131072); + const D3D12_TEXTURE_LAYOUT normalized_layouts[] = { + static_cast(kXboxTiledLayout), + static_cast(0x102), + static_cast(0x105), + D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE, + }; + for (const auto layout : normalized_layouts) { + D3D12_RESOURCE_DESC descs[] = {titles[0], titles[1]}; + descs[0].Layout = descs[1].Layout = layout; + g_seen_calls = 0; + EXPECT(get_info(&info, device, 0, 2, descs) == &info); + EXPECT(g_seen_desc_count == 2); + EXPECT(g_seen_descs[0].Layout == D3D12_TEXTURE_LAYOUT_UNKNOWN); + EXPECT(g_seen_descs[1].Layout == D3D12_TEXTURE_LAYOUT_ROW_MAJOR); + } + + const D3D12_TEXTURE_LAYOUT preserved_layouts[] = { + D3D12_TEXTURE_LAYOUT_UNKNOWN, + D3D12_TEXTURE_LAYOUT_ROW_MAJOR, + D3D12_TEXTURE_LAYOUT_64KB_STANDARD_SWIZZLE, + }; + for (const auto layout : preserved_layouts) { + D3D12_RESOURCE_DESC descs[] = {titles[0], titles[1]}; + descs[0].Layout = descs[1].Layout = layout; + g_seen_calls = 0; + EXPECT(get_info(&info, device, 0, 2, descs) == &info); + EXPECT(g_seen_desc_count == 2); + EXPECT(g_seen_descs[0].Layout == layout && g_seen_descs[1].Layout == layout); + } + // PC calls must keep their layout and flags so the host can reject an invalid descriptor. using PcFn = D3D12_RESOURCE_ALLOCATION_INFO*(WINAPI*)(void*, D3D12_RESOURCE_ALLOCATION_INFO*, UINT, UINT, const D3D12_RESOURCE_DESC*); From a9c59607b8ad94f7982bc5d63dd22a9fe41cb58e Mon Sep 17 00:00:00 2001 From: tedin7 Date: Mon, 23 Nov 2026 19:29:51 +0100 Subject: [PATCH 13/13] d3d12: strip incompatible UAV flags from Xbox resource descriptions --- runtime/shims/d3d12_xs_desc_clean.h | 25 ++++++++++++++++++++++++- runtime/test/device_proxy_test.cpp | 25 +++++++++++++++++++++++++ runtime/test/xs_proxy_mock_test.cpp | 21 +++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/runtime/shims/d3d12_xs_desc_clean.h b/runtime/shims/d3d12_xs_desc_clean.h index 7f09306659..e79fbda353 100644 --- a/runtime/shims/d3d12_xs_desc_clean.h +++ b/runtime/shims/d3d12_xs_desc_clean.h @@ -21,6 +21,22 @@ constexpr std::uint32_t kPcResourceFlagsMask = inline const auto kXboxTiledResourceLayout = static_cast(0x101); +inline bool is_depth_resource_format(DXGI_FORMAT format) { + switch (format) { + case DXGI_FORMAT_D16_UNORM: + case DXGI_FORMAT_D24_UNORM_S8_UINT: + case DXGI_FORMAT_D32_FLOAT: + case DXGI_FORMAT_D32_FLOAT_S8X24_UINT: + case DXGI_FORMAT_R16_TYPELESS: + case DXGI_FORMAT_R24G8_TYPELESS: + case DXGI_FORMAT_R32_TYPELESS: + case DXGI_FORMAT_R32G8X24_TYPELESS: + return true; + default: + return false; + } +} + // Strip Xbox-only flags and preserve the three supported PC layouts. In addition to 0x101, zebraso measured // layout words 0x102 and 0x105 reaching slot 25 during a retail boot. inline D3D12_RESOURCE_DESC pc_resource_desc(const D3D12_RESOURCE_DESC& xbox) { @@ -31,7 +47,14 @@ inline D3D12_RESOURCE_DESC pc_resource_desc(const D3D12_RESOURCE_DESC& xbox) { pc.Layout = pc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? D3D12_TEXTURE_LAYOUT_ROW_MAJOR : D3D12_TEXTURE_LAYOUT_UNKNOWN; } - pc.Flags = static_cast(static_cast(xbox.Flags) & kPcResourceFlagsMask); + std::uint32_t flags = static_cast(xbox.Flags) & kPcResourceFlagsMask; + // zebraso measured slot 25 rejecting B5G5R5A1 render targets with UAV on an RTX 5080 without + // storage-image support for that format. Depth-stencil resources also cannot be UAVs on PC. + if (pc.Format == DXGI_FORMAT_B5G5R5A1_UNORM || + ((flags & D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL) && is_depth_resource_format(pc.Format))) { + flags &= ~static_cast(D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS); + } + pc.Flags = static_cast(flags); return pc; } diff --git a/runtime/test/device_proxy_test.cpp b/runtime/test/device_proxy_test.cpp index af0afde22a..0e9a339c8d 100644 --- a/runtime/test/device_proxy_test.cpp +++ b/runtime/test/device_proxy_test.cpp @@ -229,6 +229,31 @@ int main(int argc, char** argv) { "slot 25 still answers the PC (C++) form"); } + constexpr auto kUav = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; + constexpr auto kDepthStencil = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; + constexpr auto kRenderTarget = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; + const struct { + DXGI_FORMAT format; + D3D12_RESOURCE_FLAGS input; + D3D12_RESOURCE_FLAGS expected; + const char* message; + } flag_cases[] = { + {DXGI_FORMAT_B5G5R5A1_UNORM, kRenderTarget | kUav, kRenderTarget, "B5G5R5A1 keeps only RT"}, + {DXGI_FORMAT_R32G8X24_TYPELESS, kDepthStencil | kUav, kDepthStencil, "R32G8X24 depth keeps only DS"}, + {DXGI_FORMAT_R8G8B8A8_UNORM, kRenderTarget | kUav, kRenderTarget | kUav, "RGBA8 keeps RT and UAV"}, + {DXGI_FORMAT_R32_FLOAT, kUav, kUav, "R32_FLOAT keeps UAV"}, + {DXGI_FORMAT_R32_TYPELESS, kUav, kUav, "R32_TYPELESS without DS keeps UAV"}, + {DXGI_FORMAT_D16_UNORM, kDepthStencil | kUav, kDepthStencil, "D16 depth keeps only DS"}, + }; + for (const auto& test : flag_cases) { + D3D12_RESOURCE_DESC desc{}; + desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; + desc.Format = test.format; + desc.Flags = test.input; + const auto clean = rt::d3d12_xs::pc_resource_desc(desc); + check(clean.Flags == test.expected && clean.Format == test.format && desc.Flags == test.input, test.message); + } + D3D12_RESOURCE_DESC reserved_desc = buffer_desc(); reserved_desc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; ComPtr reserved; diff --git a/runtime/test/xs_proxy_mock_test.cpp b/runtime/test/xs_proxy_mock_test.cpp index 0d4513911c..54be08a696 100644 --- a/runtime/test/xs_proxy_mock_test.cpp +++ b/runtime/test/xs_proxy_mock_test.cpp @@ -922,6 +922,27 @@ int check_allocation_descriptions_cleaned() { EXPECT(g_seen_descs[0].Layout == layout && g_seen_descs[1].Layout == layout); } + constexpr auto kUav = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; + constexpr auto kDepthStencil = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; + constexpr auto kRenderTarget = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; + D3D12_RESOURCE_DESC formats[] = { + target_desc(64, 64, DXGI_FORMAT_B5G5R5A1_UNORM), + target_desc(64, 64, DXGI_FORMAT_R32G8X24_TYPELESS), + target_desc(64, 64, DXGI_FORMAT_R8G8B8A8_UNORM), + target_desc(64, 64, DXGI_FORMAT_R32_FLOAT), + }; + formats[0].Flags = kPcFlags; + formats[1].Flags = kDepthStencil | kUav; + formats[2].Flags = kPcFlags; + formats[3].Flags = kUav; + g_seen_calls = 0; + EXPECT(get_info(&info, device, 0, 4, formats) == &info); + EXPECT(g_seen_desc_count == 4); + EXPECT(g_seen_descs[0].Flags == kRenderTarget); + EXPECT(g_seen_descs[1].Flags == kDepthStencil); + EXPECT(g_seen_descs[2].Flags == kPcFlags); + EXPECT(g_seen_descs[3].Flags == kUav); + // PC calls must keep their layout and flags so the host can reject an invalid descriptor. using PcFn = D3D12_RESOURCE_ALLOCATION_INFO*(WINAPI*)(void*, D3D12_RESOURCE_ALLOCATION_INFO*, UINT, UINT, const D3D12_RESOURCE_DESC*);