diff options
| author | NiiRoZz <simonin.remi25@gmail.com> | 2026-11-23 18:14:31 +0100 |
|---|---|---|
| committer | NiiRoZz <simonin.remi25@gmail.com> | 2026-11-23 18:19:14 +0100 |
| commit | 4a86034367eacdfca77298d89e37a5bc8545e4e5 (patch) | |
| tree | e9b244373efb345f22f3ad06b738bb01481274bc /runtime | |
| parent | 77878e31bc28ec970b9f3b30d2eceb3b1baacf80 (diff) | |
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 <noreply@anthropic.com>
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/shims/d3d12_xs_desc_clean.h | 19 | ||||
| -rw-r--r-- | runtime/shims/d3d12_xs_device.cpp | 12 | ||||
| -rw-r--r-- | runtime/test/device_proxy_test.cpp | 38 |
3 files changed, 68 insertions, 1 deletions
diff --git a/runtime/shims/d3d12_xs_desc_clean.h b/runtime/shims/d3d12_xs_desc_clean.h index 1782b7d88..51541dda6 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 = | |||
| 23 | 23 | ||
| 24 | constexpr auto kXboxTiledResourceLayout = static_cast<D3D12_TEXTURE_LAYOUT>(0x101); | 24 | constexpr auto kXboxTiledResourceLayout = static_cast<D3D12_TEXTURE_LAYOUT>(0x101); |
| 25 | 25 | ||
| 26 | // The console allows a depth-stencil texture to allow unordered access too (measured locally at a title's call sites: | ||
| 27 | // a 2D R32G8X24_TYPELESS texture with ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS, sized through slot 25), but the PC | ||
| 28 | // runtime refuses that pair, and Vulkan has no depth format with storage support to make it with. Stand-in: such a | ||
| 29 | // texture is a depth-stencil texture without unordered access. Its unordered-access views write no descriptor (the PC | ||
| 30 | // layer refuses a UAV of a texture without the flag), so what a shader writes through them goes nowhere and their | ||
| 31 | // reads see whatever the descriptor held. | ||
| 32 | inline std::uint32_t without_depth_stencil_uav(D3D12_RESOURCE_DIMENSION dimension, std::uint32_t flags) { | ||
| 33 | if (dimension != D3D12_RESOURCE_DIMENSION_BUFFER && (flags & D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)) | ||
| 34 | flags &= ~static_cast<std::uint32_t>(D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS); | ||
| 35 | return flags; | ||
| 36 | } | ||
| 37 | |||
| 38 | // The PC flags of a console description: the PC bits only, without unordered access on a depth-stencil texture. | ||
| 39 | inline std::uint32_t pc_resource_flags(D3D12_RESOURCE_DIMENSION dimension, std::uint32_t xbox_flags) { | ||
| 40 | return without_depth_stencil_uav(dimension, xbox_flags & kPcResourceFlagsMask); | ||
| 41 | } | ||
| 42 | |||
| 26 | // Strip Xbox-only flags and translate the Xbox tiled layout. Preserve all other layouts so the host can validate them. | 43 | // Strip Xbox-only flags and translate the Xbox tiled layout. Preserve all other layouts so the host can validate them. |
| 27 | inline D3D12_RESOURCE_DESC pc_resource_desc(const D3D12_RESOURCE_DESC& xbox) { | 44 | inline D3D12_RESOURCE_DESC pc_resource_desc(const D3D12_RESOURCE_DESC& xbox) { |
| 28 | D3D12_RESOURCE_DESC pc = xbox; | 45 | D3D12_RESOURCE_DESC pc = xbox; |
| @@ -30,7 +47,7 @@ inline D3D12_RESOURCE_DESC pc_resource_desc(const D3D12_RESOURCE_DESC& xbox) { | |||
| 30 | pc.Layout = pc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? D3D12_TEXTURE_LAYOUT_ROW_MAJOR | 47 | pc.Layout = pc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? D3D12_TEXTURE_LAYOUT_ROW_MAJOR |
| 31 | : D3D12_TEXTURE_LAYOUT_UNKNOWN; | 48 | : D3D12_TEXTURE_LAYOUT_UNKNOWN; |
| 32 | } | 49 | } |
| 33 | pc.Flags = static_cast<D3D12_RESOURCE_FLAGS>(static_cast<std::uint32_t>(xbox.Flags) & kPcResourceFlagsMask); | 50 | pc.Flags = static_cast<D3D12_RESOURCE_FLAGS>(pc_resource_flags(xbox.Dimension, static_cast<std::uint32_t>(xbox.Flags))); |
| 34 | return pc; | 51 | return pc; |
| 35 | } | 52 | } |
| 36 | 53 | ||
diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index e82bfb850..b38e2613f 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 | |||
| 1476 | const auto xbox_layout = static_cast<std::uint32_t>(pc_desc.Layout); | 1476 | const auto xbox_layout = static_cast<std::uint32_t>(pc_desc.Layout); |
| 1477 | pc_desc.Layout = pc_desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? D3D12_TEXTURE_LAYOUT_ROW_MAJOR | 1477 | pc_desc.Layout = pc_desc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? D3D12_TEXTURE_LAYOUT_ROW_MAJOR |
| 1478 | : D3D12_TEXTURE_LAYOUT_UNKNOWN; | 1478 | : D3D12_TEXTURE_LAYOUT_UNKNOWN; |
| 1479 | // A console depth-stencil texture may allow unordered access; the PC one may not (without_depth_stencil_uav, the | ||
| 1480 | // slot 25 stand-in). Only that bit is dropped here: the other flag bits go on as they came. | ||
| 1481 | pc_desc.Flags = static_cast<D3D12_RESOURCE_FLAGS>( | ||
| 1482 | without_depth_stencil_uav(pc_desc.Dimension, static_cast<std::uint32_t>(pc_desc.Flags))); | ||
| 1479 | 1483 | ||
| 1480 | static std::atomic<bool> logged{false}; | 1484 | static std::atomic<bool> logged{false}; |
| 1481 | if (!logged.exchange(true, std::memory_order_relaxed)) { | 1485 | 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 | |||
| 1679 | for (UINT i = 0; i < desc_count; ++i) { | 1683 | for (UINT i = 0; i < desc_count; ++i) { |
| 1680 | const auto& desc = descs[i]; | 1684 | const auto& desc = descs[i]; |
| 1681 | clean[i] = call.console_abi || desc.Layout == kXboxTiledResourceLayout ? pc_resource_desc(desc) : desc; | 1685 | clean[i] = call.console_abi || desc.Layout == kXboxTiledResourceLayout ? pc_resource_desc(desc) : desc; |
| 1686 | static std::atomic<bool> uav_dropped{false}; | ||
| 1687 | if (((static_cast<std::uint32_t>(desc.Flags) & ~static_cast<std::uint32_t>(clean[i].Flags)) & | ||
| 1688 | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS) && | ||
| 1689 | first_call(uav_dropped)) | ||
| 1690 | std::fprintf(stderr, | ||
| 1691 | "[rt] d3d12_xs: slot 25: depth-stencil texture (format %d) sized without unordered " | ||
| 1692 | "access, which the PC refuses with it (stand-in)\n", | ||
| 1693 | static_cast<int>(desc.Format)); | ||
| 1682 | } | 1694 | } |
| 1683 | descs = clean.get(); | 1695 | descs = clean.get(); |
| 1684 | } | 1696 | } |
diff --git a/runtime/test/device_proxy_test.cpp b/runtime/test/device_proxy_test.cpp index af0afde22..d218f4ded 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) { | |||
| 227 | const D3D12_RESOURCE_ALLOCATION_INFO pc_info = device->GetResourceAllocationInfo(0, 1, &desc); | 227 | const D3D12_RESOURCE_ALLOCATION_INFO pc_info = device->GetResourceAllocationInfo(0, 1, &desc); |
| 228 | check(pc_info.SizeInBytes == want.SizeInBytes && pc_info.Alignment == want.Alignment, | 228 | check(pc_info.SizeInBytes == want.SizeInBytes && pc_info.Alignment == want.Alignment, |
| 229 | "slot 25 still answers the PC (C++) form"); | 229 | "slot 25 still answers the PC (C++) form"); |
| 230 | |||
| 231 | // A console depth-stencil texture that allows unordered access too, as a title sizes one: a 2D | ||
| 232 | // R32G8X24_TYPELESS texture with ALLOW_DEPTH_STENCIL | ALLOW_UNORDERED_ACCESS and the console layout word. The | ||
| 233 | // PC device refuses the flag pair (negative control); slot 25 sizes it as the depth-stencil texture alone. | ||
| 234 | D3D12_RESOURCE_DESC ds_uav{}; | ||
| 235 | ds_uav.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; | ||
| 236 | ds_uav.Width = 2560; | ||
| 237 | ds_uav.Height = 1440; | ||
| 238 | ds_uav.DepthOrArraySize = 1; | ||
| 239 | ds_uav.MipLevels = 1; | ||
| 240 | ds_uav.Format = DXGI_FORMAT_R32G8X24_TYPELESS; | ||
| 241 | ds_uav.SampleDesc.Count = 1; | ||
| 242 | ds_uav.Layout = static_cast<D3D12_TEXTURE_LAYOUT>(0x101); | ||
| 243 | ds_uav.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; | ||
| 244 | D3D12_RESOURCE_DESC pc_pair = ds_uav; | ||
| 245 | pc_pair.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; | ||
| 246 | check(real->GetResourceAllocationInfo(0, 1, &pc_pair).SizeInBytes == UINT64_MAX, | ||
| 247 | "the PC device refuses a depth-stencil texture with unordered access (negative control)"); | ||
| 248 | D3D12_RESOURCE_DESC ds_only = pc_pair; | ||
| 249 | ds_only.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; | ||
| 250 | const D3D12_RESOURCE_ALLOCATION_INFO ds_want = real->GetResourceAllocationInfo(0, 1, &ds_only); | ||
| 251 | check(ds_want.SizeInBytes != UINT64_MAX, "WARP sizes the depth-stencil texture without unordered access"); | ||
| 252 | const D3D12_RESOURCE_DESC ds_clean = rt::d3d12_xs::pc_resource_desc(ds_uav); | ||
| 253 | check(ds_clean.Flags == D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL, | ||
| 254 | "pc_resource_desc drops unordered access from a depth-stencil texture"); | ||
| 255 | D3D12_RESOURCE_DESC uav_buffer = buffer_desc(); | ||
| 256 | uav_buffer.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; | ||
| 257 | D3D12_RESOURCE_DESC rt_uav = ds_only; | ||
| 258 | rt_uav.Format = DXGI_FORMAT_R8G8B8A8_UNORM; | ||
| 259 | rt_uav.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; | ||
| 260 | check(rt::d3d12_xs::pc_resource_desc(uav_buffer).Flags == D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS && | ||
| 261 | rt::d3d12_xs::pc_resource_desc(rt_uav).Flags == rt_uav.Flags, | ||
| 262 | "pc_resource_desc keeps unordered access on buffers and color textures"); | ||
| 263 | D3D12_RESOURCE_ALLOCATION_INFO ds_got{~0ull, ~0ull}; | ||
| 264 | get_alloc_info(&ds_got, device.Get(), 0, 1, &ds_uav); | ||
| 265 | check(ds_got.SizeInBytes != UINT64_MAX && ds_got.SizeInBytes >= ds_want.SizeInBytes && | ||
| 266 | (ds_got.SizeInBytes >> 32) == 0, | ||
| 267 | "slot 25 (C ABI) sizes a console depth-stencil texture with unordered access"); | ||
| 230 | } | 268 | } |
| 231 | 269 | ||
| 232 | D3D12_RESOURCE_DESC reserved_desc = buffer_desc(); | 270 | D3D12_RESOURCE_DESC reserved_desc = buffer_desc(); |