From 2e3b55965f3216542ef9fe0a220efcd802a94ce3 Mon Sep 17 00:00:00 2001 From: MiguelMatMar Date: Tue, 24 Nov 2026 00:14:31 +0100 Subject: [PATCH] runtime: build again on MSVC after #9576 (console descriptor heap on slot 14) - d3d12_xs_device.cpp called rt::d3d12::create_console_descriptor_heap, which is neither declared there nor linked into the tests that build the file without the Vulkan layer. It now goes through a handler (set_console_descriptor_heap_handler), as slot 133 does. - The handler is opt-in. The slot reads 16 bytes past a PC descriptor and takes any non-zero word there for a console address. Registered by default, that made d3d12_f16_halves crash. - create_console_descriptor_heap used the private Device::identity() and passed a const DeviceState to DescriptorHeap; Device now makes the heap itself. - d3d12_console_descriptor_heap_test: Ref gets operator->, create_device_proxy gets its IID, and the test registers the handler. It still fails on its own check (the proxy's CPU heap start is the host pointer, not the console address). AI-assisted (Claude Code). Windows 11, MSVC 14.44, RTX 4080 SUPER. Co-Authored-By: Claude Opus 5.5 --- runtime/shims/d3d12_vulkan_device.cpp | 10 ++++++++-- runtime/shims/d3d12_xs_device.cpp | 13 +++++++++++-- runtime/shims/d3d12_xs_device.h | 11 +++++++++++ runtime/test/d3d12_console_descriptor_heap_test.cpp | 5 ++++- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index a6911d0f4e..57f4c50501 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -5500,6 +5500,13 @@ class Device final const leonida::BindlessSet* bindless() const { return state_.bindless.get(); } const DeviceState& state() const { return state_; } IUnknown* holder() { return identity(); } + // A descriptor heap whose handle starts report the console's address (create_console_descriptor_heap). + DescriptorHeap* new_console_descriptor_heap(const D3D12_DESCRIPTOR_HEAP_DESC& desc, std::uint64_t address, + std::uint64_t size) { + auto* heap = new DescriptorHeap(state_, desc, address, size); + heap->attach_device(identity()); + return heap; + } 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; } @@ -9998,8 +10005,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()); + auto* heap = d->new_console_descriptor_heap(*desc, console_address, console_size); if (!heap->ok()) { heap->Release(); return E_OUTOFMEMORY; diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 187406e3d8..661594d888 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -1579,6 +1579,9 @@ static bool readable_range(const void* ptr, std::size_t bytes) { return true; } +// Registered by the Vulkan layer (set_console_descriptor_heap_handler). +std::atomic g_console_descriptor_heap{nullptr}; + HRESULT proxy_create_descriptor_heap(DeviceProxy* self, const D3D12_DESCRIPTOR_HEAP_DESC* desc, const IID* riid, void** out) { note_slot(14); @@ -1601,9 +1604,11 @@ 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( + hr = handler( self->real, desc, static_cast(address), size, __uuidof(ID3D12DescriptorHeap), &created); } @@ -2033,6 +2038,10 @@ unsigned device_proxy_slot_count(const void* device) { return static_cast(device)->slot_count; } +void set_console_descriptor_heap_handler(ConsoleDescriptorHeapHandler handler) { + g_console_descriptor_heap.store(handler, std::memory_order_release); +} + void set_placed_at_va_handler(PlacedAtVaHandler handler) { g_placed_at_va.store(handler, std::memory_order_release); } diff --git a/runtime/shims/d3d12_xs_device.h b/runtime/shims/d3d12_xs_device.h index ac0437215d..878ff71070 100644 --- a/runtime/shims/d3d12_xs_device.h +++ b/runtime/shims/d3d12_xs_device.h @@ -100,6 +100,17 @@ 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 descriptor (address and size after the PC D3D12_DESCRIPTOR_HEAP_DESC, +// issue #313) is created by the device behind the proxy through this handler (rt::d3d12::create_console_descriptor_heap). +// A handler keeps this file free of a link dependency on the Vulkan layer: it is also built into tests without it. +// Nothing registers it by default: the slot reads 16 bytes past a PC descriptor and takes any non-zero word there +// for a console address, which a PC caller's stack can hold (d3d12_f16_halves crashed that way). With none +// registered the slot creates a plain PC heap, as before #9576. +using ConsoleDescriptorHeapHandler = HRESULT (*)(ID3D12Device* real, const D3D12_DESCRIPTOR_HEAP_DESC* desc, + D3D12_GPU_VIRTUAL_ADDRESS 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..81df8ede47 100644 --- a/runtime/test/d3d12_console_descriptor_heap_test.cpp +++ b/runtime/test/d3d12_console_descriptor_heap_test.cpp @@ -24,6 +24,7 @@ struct Ref { return &p; } T* get() const { return p; } + T* operator->() const { return p; } }; bool check_console_addressed_heap(ID3D12Device* device) { @@ -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; } @@ -126,6 +127,8 @@ int main() { const auto status = vk.initialize(); if (status == vktest::DeviceStatus::unavailable) return 77; if (status != vktest::DeviceStatus::ready) return 1; + // The console slot 14 path is opt-in (d3d12_xs_device.h); this test exercises it. + rt::d3d12_xs::set_console_descriptor_heap_handler(&rt::d3d12::create_console_descriptor_heap); Ref device; rt::d3d12::VulkanDeviceInfo info{};