From d16eb1ff0a55cbc3bd09730a66aa9abe2266f7ea Mon Sep 17 00:00:00 2001 From: Jan Trencansky Date: Tue, 24 Nov 2026 22:47:54 -0500 Subject: [PATCH] d3d12: give a depth placement inside another one's PC extent its own image The slot-133 depth/UAV registry recorded each placement's extent as the PC allocation size and refused, with E_NOTIMPL, any placement that started inside another live range. On RADV the PC size of a large D16 target is above the block the title placed it in, so the title's next block starts inside the previous range: its first depth target was refused, no trace line showed it, and the title stopped on its own assert and crash reporter about 30 s into the boot (Game Init, frame 0) on an RDNA2 iGPU. Overlapping placements at different addresses never shared a backing, so between two opaque layouts the inner one now gets an image of its own, as D3D12 leaves an alias's contents undefined until it is reinitialized. A non-opaque layout is still refused there, and the same-address rules are unchanged. A refused depth placement is now logged. d3d12_depth_stencil_uav_test places a texture one alignment step inside another one: refused for the tiled Xbox layout, its own backing for the opaque one, and the outer placement still finds its shared backing. Co-Authored-By: Claude Opus 5.5 --- docs/d3d12_vulkan.md | 7 ++++++- runtime/shims/d3d12_xs_device.cpp | 28 +++++++++++++++++++------- runtime/shims/d3d12_xs_placed_depth.h | 10 ++++++++- runtime/test/d3d12_placed_depth_test.h | 23 ++++++++++++++++++++- 4 files changed, 58 insertions(+), 10 deletions(-) diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index 97d737c8ea..e23985ecb3 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -2855,7 +2855,12 @@ The console has two list topologies Vulkan lacks: rectangle list (`IASetPrimitiv plane 1. For `R16_TYPELESS`, use `R16_UINT` on plane 0 to access the raw D16 bits. An array UAV selects a contiguous range of layers. The depth/stencil and shader-resource views continue to use the attachment image. Slot 133 keeps the guest address. Identical, live placements share their image and writable planes across - distinct COM objects. A partial overlap or incompatible reinterpretation is refused. + distinct COM objects. An incompatible reinterpretation at the same address is refused. A placement's extent is + the PC allocation size, which can exceed the title's own block (RADV sizes a large D16 target above it, so the + title's next block starts inside the range); a placement that starts inside another one therefore gets its own + image when both layouts are opaque, since D3D12 leaves an alias's contents undefined until reinitialized, and is + refused only for a non-opaque layout. Before this, the retail boot stopped on the title's assert while it created + its D16 depth targets on an RDNA2 iGPU under RADV. A refused depth placement is logged (no trace line covers it). - Legacy and enhanced texture transitions copy the selected planes and layers to or from their storage images. Fence-ordered graphics and compute queues can share UAV access. A dedicated compute family can perform the plane transfer itself when `VK_KHR_maintenance10` and the format's depth/stencil copy flags allow it. diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 3bad45d284..60d7c62f30 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -4275,13 +4275,27 @@ HRESULT create_depth_uav_backing(DeviceProxy* self, const D3D12_HEAP_PROPERTIES* HRESULT proxy_create_placed_depth(DeviceProxy* self, UINT64 address, const D3D12_RESOURCE_DESC& desc, std::uint32_t layout, const D3D12_CLEAR_VALUE* clear, REFIID riid, void** out) { const auto native = depth_image_desc(desc); - if (!self->validate_depth_placement(native, layout, clear)) return E_INVALIDARG; - const auto alloc = self->real->GetResourceAllocationInfo(0, 1, &native); - const D3D12_HEAP_PROPERTIES heap{D3D12_HEAP_TYPE_DEFAULT}; - return self->placed_depth_textures.create(address, native, alloc, clear, desc.Layout == D3D12_TEXTURE_LAYOUT_UNKNOWN, riid, out, [&](ID3D12Resource** backing) { - return create_depth_uav_backing(self, &heap, D3D12_HEAP_FLAG_NONE, native, D3D12_RESOURCE_STATE_COMMON, - clear, backing); - }); + const bool valid = self->validate_depth_placement(native, layout, clear); + D3D12_RESOURCE_ALLOCATION_INFO alloc{}; + HRESULT hr = E_INVALIDARG; + if (valid) { + alloc = self->real->GetResourceAllocationInfo(0, 1, &native); + const D3D12_HEAP_PROPERTIES heap{D3D12_HEAP_TYPE_DEFAULT}; + hr = self->placed_depth_textures.create(address, native, alloc, clear, desc.Layout == D3D12_TEXTURE_LAYOUT_UNKNOWN, riid, out, [&](ID3D12Resource** backing) { + return create_depth_uav_backing(self, &heap, D3D12_HEAP_FLAG_NONE, native, D3D12_RESOURCE_STATE_COMMON, + clear, backing); + }); + } + // A refusal here reaches no trace line, and the title stops on an int3 right after it: log the first few. + static std::atomic refusals{0}; + if (FAILED(hr) && refusals.fetch_add(1, std::memory_order_relaxed) < 8) + std::fprintf(stderr, + "[rt] d3d12_xs: slot 133 depth texture refused (hr=0x%08x, %s): format %d %llux%ux%u, Xbox layout " + "0x%x, layout word 0x%x, PC size %llu\n", + static_cast(hr), valid ? "placement" : "description", int(desc.Format), + static_cast(desc.Width), unsigned(desc.Height), unsigned(desc.DepthOrArraySize), + unsigned(desc.Layout), layout, static_cast(alloc.SizeInBytes)); + return hr; } HRESULT proxy_create_resource(DeviceProxy* self, const D3D12_HEAP_PROPERTIES* heap_properties, diff --git a/runtime/shims/d3d12_xs_placed_depth.h b/runtime/shims/d3d12_xs_placed_depth.h index 73bc28eb7a..1476851b2e 100644 --- a/runtime/shims/d3d12_xs_placed_depth.h +++ b/runtime/shims/d3d12_xs_placed_depth.h @@ -79,11 +79,19 @@ class PlacedDepthTextures { // an aliasing barrier and reinitialization. The API promises data inheritance only for // identical descriptions and optimized clears. Keep that matching backing alive even // when another shape is also registered at this address. + // A range's end is the PC allocation's size, which can run past the title's own footprint (on + // RADV a large D16 target is sized above the block the title placed it in, and the title's next + // block starts inside it). A placement that starts inside another range therefore shares nothing + // with it: between two opaque layouts it gets a backing of its own, since D3D12 leaves an alias's + // contents undefined until it is reinitialized. Only a non-opaque layout is refused there. const auto limit = ranges_.lower_bound(end); for (auto it = ranges_.begin(); it != limit; ++it) { const auto& range = it->second; if (range.end <= address) continue; - if (it->first != address) return E_NOTIMPL; + if (it->first != address) { + if (!opaque_layout || !range.opaque_layout) return E_NOTIMPL; + continue; + } const bool same_shape = compatible(desc, range.desc); if (range.end == end && same_shape && range.optimized == optimized) { if (auto live = range.backing.lock()) owner = std::move(live); diff --git a/runtime/test/d3d12_placed_depth_test.h b/runtime/test/d3d12_placed_depth_test.h index 95d32772bd..5ef9f88a98 100644 --- a/runtime/test/d3d12_placed_depth_test.h +++ b/runtime/test/d3d12_placed_depth_test.h @@ -1,6 +1,7 @@ // Slot-133 aliases share GPU contents and retain individual COM identities. #pragma once #include "d3d12_copy_compare.h" +#include "../shims/d3d12_xs_device.h" namespace placeddepthtest { @@ -54,8 +55,28 @@ inline bool check_alias_lifetime(ID3D12Device* device, ID3D12Device* xbox, bool optimized.DepthStencil = {1.0f, 0}; if (place(address, xbox_desc, invalid, &optimized) != E_NOTIMPL || invalid.p) return false; if ((!opaque && (place(address, smaller, invalid) != E_NOTIMPL || invalid.p)) || - place(address + allocation.Alignment, xbox_desc, invalid) != E_NOTIMPL || invalid.p || place(address + 1, xbox_desc, invalid) != E_INVALIDARG || invalid.p) return false; + // A placement that starts inside another one's PC allocation: the title's own blocks can be smaller than the + // PC sizes them (a D16 target on RADV), so the next block starts inside the range. Opaque layouts get a backing + // of their own there; a layout whose bytes would have to be shared is still refused. + if (!opaque) { + if (place(address + allocation.Alignment, xbox_desc, invalid) != E_NOTIMPL || invalid.p) return false; + } else { + Ptr inside; + if (FAILED(place(address + allocation.Alignment, xbox_desc, inside)) || + inside->GetGPUVirtualAddress() != address + allocation.Alignment || + rt::d3d12_xs::texture_backing(inside.p) == rt::d3d12_xs::texture_backing(first.p)) { + std::fprintf(stderr, "slot-133 alias: a placement inside another range was refused or shared\n"); + return false; + } + // Placing the first shape again still finds its own backing, with the inner range registered. + Ptr again; + if (FAILED(place(address, xbox_desc, again)) || + rt::d3d12_xs::texture_backing(again.p) != rt::d3d12_xs::texture_backing(first.p)) { + std::fprintf(stderr, "slot-133 alias: the outer range lost its backing to the inner one\n"); + return false; + } + } Ptr heap; D3D12_DESCRIPTOR_HEAP_DESC heap_desc{D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 2};