From 3793c9bcb0e33336d1290ec5918161748b8cf091 Mon Sep 17 00:00:00 2001 From: carlos-seiffert <242512372+carlos-seiffert@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:19:22 -0300 Subject: [PATCH 1/2] runtime: build on MSVC again after the 2026-11-23 merge round Main at 0b3caaee does not compile with MSVC (gta6rt_d3d12_com, acphal and the tests that use them): - d3d12_xs_device.cpp called rt::d3d12::create_console_descriptor_heap without its declaration. Including d3d12_com.h there is not an option: the proxy is built into a dozen tests without the Vulkan layer. Slot 14 now calls a handler the Vulkan layer can register (set_console_descriptor_heap_handler), as slot 133 already does. - create_console_descriptor_heap used Device's private identity() and passed the const state() to DescriptorHeap. It now forwards to a Device member. - acphal.cpp's SHAPE_XMA_CONTEXT and SHAPE_PCM_CONTEXT were 60 and 28 bytes, so their static_asserts failed with every compiler. Only sizeof is used (the context array stride); the padding now gives the GDK sizes, 64 and 32. - d3d12_console_descriptor_heap_test used Ref's missing operator-> and IID_PPV_ARGS on a void**. The slot 14 handler is not registered by default: registered for every Vulkan device, it crashed 8 ctest programs that create PC heaps through the proxy (the slot reads 16 bytes past a 16-byte PC description). The console heap test registers it itself. Co-Authored-By: Claude Opus 5.5 --- runtime/shims/acphal.cpp | 9 ++++++-- runtime/shims/d3d12_vulkan_device.cpp | 21 ++++++++++++------- runtime/shims/d3d12_xs_device.cpp | 14 +++++++++---- runtime/shims/d3d12_xs_device.h | 12 +++++++++++ .../d3d12_console_descriptor_heap_test.cpp | 5 ++++- 5 files changed, 47 insertions(+), 14 deletions(-) diff --git a/runtime/shims/acphal.cpp b/runtime/shims/acphal.cpp index 553f57f207..3fa21341b0 100644 --- a/runtime/shims/acphal.cpp +++ b/runtime/shims/acphal.cpp @@ -141,7 +141,10 @@ struct SHAPE_XMA_CONTEXT { uint32_t reserved1 : 6; uint32_t loopStartOffset : 26; uint32_t loopEndOffset : 6; - uint32_t reserved[10]; + // The bit-fields above take 5 dwords, not 6: the third holds 24 bits, and a 26-bit field cannot straddle a + // dword with MSVC, GCC or Clang. 11 dwords of padding keep the GDK size (only sizeof is used, as the array + // stride in AcpHalAllocateShapeContexts); the bit positions inside the first dwords are not verified. + uint32_t reserved[11]; }; static_assert(sizeof(SHAPE_XMA_CONTEXT) == 64, "SHAPE_XMA_CONTEXT is 64 bytes per GDK"); @@ -162,7 +165,9 @@ struct SHAPE_PCM_CONTEXT { uint32_t reserved6 : 15; uint32_t format : 2; uint32_t reserved7 : 14; - uint32_t reserved[1]; + // The bit-fields above take 6 dwords; 2 of padding keep the GDK size of 32 (only sizeof is used, as the array + // stride in AcpHalAllocateShapeContexts). + uint32_t reserved[2]; }; static_assert(sizeof(SHAPE_PCM_CONTEXT) == 32, "SHAPE_PCM_CONTEXT is 32 bytes per GDK"); diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index aa299cc8c4..63d3f6607a 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -5500,6 +5500,19 @@ class Device final const leonida::BindlessSet* bindless() const { return state_.bindless.get(); } const DeviceState& state() const { return state_; } IUnknown* holder() { return identity(); } + + // create_console_descriptor_heap (d3d12_com.h): a heap at the console address the Xbox slot 14 call passes. A + // member, because the heap needs the device's mutable state and COM identity. + HRESULT create_console_heap(const D3D12_DESCRIPTOR_HEAP_DESC& desc, std::uint64_t console_address, + std::uint64_t console_size, REFIID riid, void** out) { + auto* heap = new DescriptorHeap(state_, desc, console_address, console_size); + heap->attach_device(identity()); + if (!heap->ok()) { + heap->Release(); + return E_OUTOFMEMORY; + } + return hand_out(heap, riid, out); + } bool bind_sampler(const leonida::gfx10::SamplerWords& words) { return state_.bind_sampler(words); } void own(const OwnedRuntime& owned) { owned_ = owned; } void set_outer(IUnknown* outer) { outer_ = outer; } @@ -9994,13 +10007,7 @@ HRESULT create_console_descriptor_heap(ID3D12Device* device, const D3D12_DESCRIP auto* d = Device::from(real ? real : device); if (!d) return E_INVALIDARG; - auto* heap = new DescriptorHeap(d->state(), *desc, console_address, console_size); - heap->attach_device(d->identity()); - if (!heap->ok()) { - heap->Release(); - return E_OUTOFMEMORY; - } - return hand_out(heap, riid, out); + return d->create_console_heap(*desc, console_address, console_size, riid, out); } std::filesystem::path configured_shader_directory(std::string* error, const std::filesystem::path& config) { diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 187406e3d8..0598301c93 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -44,6 +44,9 @@ namespace rt::d3d12_xs { namespace { +// Slot 14's console-address heap handler (set_console_descriptor_heap_handler); null without the Vulkan layer. +std::atomic g_console_descriptor_heap{nullptr}; + // The retail title calls device slots well past ID3D12Device14 (slot 133 at least); every slot past the PC device's // vtable goes through the generic thunk and is refused with E_NOTIMPL, so the table must outlast the highest one. constexpr unsigned kMaxSlots = 192; @@ -1601,11 +1604,10 @@ HRESULT proxy_create_descriptor_heap(DeviceProxy* self, const D3D12_DESCRIPTOR_H std::memcpy(&size, bytes + sizeof(D3D12_DESCRIPTOR_HEAP_DESC) + sizeof(address), sizeof(size)); // Console-extended slot 14 (issue #313): address/size follow the PC desc. Only take this path when a // non-zero console VA is present; normal PC 16-byte descs never enter it. - if (address != 0) { + const ConsoleDescriptorHeapHandler handler = g_console_descriptor_heap.load(std::memory_order_acquire); + if (address != 0 && handler) { console_extended = true; - hr = rt::d3d12::create_console_descriptor_heap( - self->real, desc, static_cast(address), size, - __uuidof(ID3D12DescriptorHeap), &created); + hr = handler(self->real, desc, address, size, __uuidof(ID3D12DescriptorHeap), &created); } } } @@ -2037,6 +2039,10 @@ void set_placed_at_va_handler(PlacedAtVaHandler handler) { g_placed_at_va.store(handler, std::memory_order_release); } +void set_console_descriptor_heap_handler(ConsoleDescriptorHeapHandler handler) { + g_console_descriptor_heap.store(handler, std::memory_order_release); +} + void set_placed_at_va_pages_hook(PlacedAtVaPagesHook hook) { g_placed_at_va_pages.store(hook, std::memory_order_release); } diff --git a/runtime/shims/d3d12_xs_device.h b/runtime/shims/d3d12_xs_device.h index ac0437215d..6e9006c7e6 100644 --- a/runtime/shims/d3d12_xs_device.h +++ b/runtime/shims/d3d12_xs_device.h @@ -100,6 +100,18 @@ using PlacedAtVaHandler = HRESULT (*)(ID3D12Device* real, void* va, const D3D12_ std::uint32_t layout, REFIID riid, void** out); void set_placed_at_va_handler(PlacedAtVaHandler handler); +// Device slot 14 with the console's extended description (a 16-byte PC D3D12_DESCRIPTOR_HEAP_DESC, then the heap's +// address and size, issue #313) makes the heap at that address through this handler, which the Vulkan layer registers +// (rt::d3d12::create_console_descriptor_heap). The proxy does not call the Vulkan layer itself: this file is also +// built into tests without it. With none registered, slot 14 creates an ordinary heap on the device behind it. +// Nothing registers it by default: the slot cannot yet tell the console's 32-byte description from a PC caller's +// 16-byte one, whose next 16 bytes are whatever follows it in memory (registered for every Vulkan device, it +// crashed eight ctest programs that create PC heaps through the proxy). d3d12_console_descriptor_heap_test +// registers it itself. +using ConsoleDescriptorHeapHandler = HRESULT (*)(ID3D12Device* real, const D3D12_DESCRIPTOR_HEAP_DESC* desc, + std::uint64_t address, std::uint64_t size, REFIID riid, void** out); +void set_console_descriptor_heap_handler(ConsoleDescriptorHeapHandler handler); + // Called by slot 133 for a buffer, before the handler, with the buffer's range [va, va + width). gta6rt registers // rt::xmem::commit_physical_range: xmem commits physical pages on first touch, so a range the title has mapped but // not written yet is still reserved, and the handler's import refuses reserved pages (it would answer with its diff --git a/runtime/test/d3d12_console_descriptor_heap_test.cpp b/runtime/test/d3d12_console_descriptor_heap_test.cpp index 5f694b5a2a..20cfe5c83d 100644 --- a/runtime/test/d3d12_console_descriptor_heap_test.cpp +++ b/runtime/test/d3d12_console_descriptor_heap_test.cpp @@ -16,6 +16,7 @@ template struct Ref { T* p = nullptr; ~Ref() { if (p) p->Release(); } + T* operator->() const { return p; } T** put() { if (p) { p->Release(); @@ -65,7 +66,7 @@ bool check_console_addressed_heap(ID3D12Device* device) { bool check_xs_proxy_slot14(ID3D12Device* real_device) { void* proxy_raw = nullptr; - if (FAILED(rt::d3d12_xs::create_device_proxy(real_device, IID_PPV_ARGS(&proxy_raw))) || !proxy_raw) { + if (FAILED(rt::d3d12_xs::create_device_proxy(real_device, __uuidof(ID3D12Device), &proxy_raw)) || !proxy_raw) { std::fprintf(stderr, "create_device_proxy failed\n"); return false; } @@ -142,6 +143,8 @@ int main() { if (!check_normal_heap_unchanged(device.get())) return 1; if (!check_console_addressed_heap(device.get())) return 1; + // The layer does not register slot 14's console handler by default (d3d12_xs_device.h); this check does. + rt::d3d12_xs::set_console_descriptor_heap_handler(&rt::d3d12::create_console_descriptor_heap); if (!check_xs_proxy_slot14(device.get())) return 1; std::fprintf(stderr, "ok\n"); return 0; From 967f20036dbdd8bfb50f213ca26e034f3e728e41 Mon Sep 17 00:00:00 2001 From: carlos-seiffert <242512372+carlos-seiffert@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:31:30 -0300 Subject: [PATCH 2/2] d3d12_xs_rootsig: one checksum check, the one that keeps an all-zero checksum #9492 and #8959 both added an incoming-checksum check to the RTS0 rewrite, and the merge kept both. #9492's, first in the function, refuses any checksum that does not match, including an all-zero one; #8959's accepts an all-zero checksum, as the host d3d12.dll does, and keeps it zero after the rewrite. With both, the first refuses what the second is there to accept, so two root_sig cases fail: "blob helper rewrites an all-zero-checksum Xbox blob and keeps its zero checksum" and "shim deserializer accepts an all-zero-checksum Xbox blob with the high byte cleared". #8959's check still refuses any other mismatching checksum, so #9492's corrupted-blob cases keep passing: root_sig passes in full with MSVC. Co-Authored-By: Claude Opus 5.5 --- runtime/shims/d3d12_xs_rootsig.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/runtime/shims/d3d12_xs_rootsig.cpp b/runtime/shims/d3d12_xs_rootsig.cpp index 242418daed..329e4f896f 100644 --- a/runtime/shims/d3d12_xs_rootsig.cpp +++ b/runtime/shims/d3d12_xs_rootsig.cpp @@ -146,12 +146,6 @@ bool copy_rts0_blob_clear_xbox_flags(const void* data, size_t size, std::vector< std::memcpy(&chunk_count, bytes + 28, sizeof(chunk_count)); if (chunk_count == 0 || chunk_count > 16 || static_cast(chunk_count) * 4 > size - 32) return false; - // Verify the incoming container hash before rewriting: a corrupted blob must reach the host deserializer - // unchanged so it is rejected, rather than getting a freshly forged valid hash. - uint32_t expected_hash[4]; - dxbc_checksum(bytes, size, expected_hash); - if (std::memcmp(expected_hash, bytes + 4, sizeof(expected_hash)) != 0) return false; - const size_t min_chunk_off = 32 + static_cast(chunk_count) * 4; for (uint32_t i = 0; i < chunk_count; ++i) { uint32_t off = 0;