Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -2861,6 +2861,17 @@ The console has two list topologies Vulkan lacks: rectangle list (`IASetPrimitiv
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).
Where the provider (`Resource::enable_depth_stencil_uav`) has no unordered-access form of a texture it answers
`E_INVALIDARG` or `E_NOTIMPL`, and slots 76 and 133 then make the texture without unordered access, as before the
provider: slot 76 as a committed depth-stencil texture, slot 133 through its stand-in (the title-placed texture, or
the committed one). The first such refusal per slot is logged. That is the console D16S8 format (118) on a GPU with
D24S8 attachments (every NVIDIA card): `pc_format()` makes it as `D24_UNORM_S8_UINT`, which the provider does not
take; a real boot stopped on an int3 after slot 133 returned that refusal. Its UAVs then write no
descriptor, as for the slot 25 stand-in. Any other failure (out of memory, the backing itself, a refused placement)
is passed on as before. Follow-up: teach `enable_depth_stencil_uav` the D24S8-made form of format 118 (its widened
path already serves a D16S8 target stored as `D32_SFLOAT_S8_UINT`), so these textures keep their UAVs on NVIDIA
too. `xs_proxy_mock` checks the refusal against a mock provider, and `xbox_d16s8_refused_uav` on a GPU with
`LEONIDA_CONSOLE_D16S8=d24`.
- 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.
Expand Down
5 changes: 5 additions & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2895,6 +2895,11 @@ if(TARGET Vulkan::Headers)
set_tests_properties(xbox_d16s8_storage PROPERTIES
ENVIRONMENT "LEONIDA_TEST_D16S8_UAV=1;LEONIDA_CONSOLE_D16S8=native" SKIP_RETURN_CODE 77 TIMEOUT 30)
set_tests_properties(xbox_depth_storage PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 30)
# Made as D24S8, a D16S8 depth-stencil texture with unordered access is refused by the depth provider; slots 76
# and 133 make it without unordered access instead (d24 forces what a GPU with D24S8 attachments chooses).
add_test(NAME xbox_d16s8_refused_uav COMMAND xbox_depth_storage_test)
set_tests_properties(xbox_d16s8_refused_uav PROPERTIES
ENVIRONMENT "LEONIDA_TEST_D16S8_REFUSED_UAV=1;LEONIDA_CONSOLE_D16S8=d24" SKIP_RETURN_CODE 77 TIMEOUT 30)
add_executable(xbox_d16s8_surface_test test/xbox_d16s8_surface_test.cpp)
target_link_libraries(xbox_d16s8_surface_test PRIVATE gta6rt_d3d12_com)
target_compile_definitions(xbox_d16s8_surface_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX)
Expand Down
56 changes: 44 additions & 12 deletions runtime/shims/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4253,9 +4253,26 @@ D3D12_RESOURCE_STATES depth_image_state(D3D12_RESOURCE_STATES requested) {
return requested == D3D12_RESOURCE_STATE_UNORDERED_ACCESS ? D3D12_RESOURCE_STATE_COMMON : requested;
}

// The depth provider answers E_INVALIDARG or E_NOTIMPL for a texture it has no unordered-access form of
// (Resource::enable_depth_stencil_uav). A console D16S8 target is one on a GPU with D24S8 attachments (every NVIDIA
// card): pc_format() makes it as D24_UNORM_S8_UINT, and the provider takes only R16_TYPELESS, 118 and
// R32G8X24_TYPELESS. Slots 76 and 133 then make the texture without unordered access, as they did before the provider
// (#939), and the title gets its texture instead of asserting. Any other failure is passed on as it is.
bool depth_provider_refusal(HRESULT hr) { return hr == E_INVALIDARG || hr == E_NOTIMPL; }

void note_depth_provider_refusal(std::atomic<bool>& seen, unsigned slot, DXGI_FORMAT format, HRESULT hr) {
if (first_call(seen))
std::fprintf(stderr,
"[rt] d3d12_xs: slot %u: the depth provider refused a depth-stencil texture with unordered access "
"(format %d, hr=0x%08x); it is made without unordered access\n",
slot, static_cast<int>(format), static_cast<unsigned>(hr));
}

// `refused` (optional) is set when the provider refused the texture (depth_provider_refusal), not when the backing
// itself failed.
HRESULT create_depth_uav_backing(DeviceProxy* self, const D3D12_HEAP_PROPERTIES* props, D3D12_HEAP_FLAGS flags,
const D3D12_RESOURCE_DESC& native, D3D12_RESOURCE_STATES initial,
const D3D12_CLEAR_VALUE* clear, ID3D12Resource** out) {
const D3D12_CLEAR_VALUE* clear, ID3D12Resource** out, bool* refused = nullptr) {
// The logical Xbox texture has a UAV. Its writable planes take ALLOW_SHADER_ATOMICS, which the PC
// rejects on the depth-only attachment. Upload/readback heaps cannot hold a UAV on either API.
if (props && (props->Type == D3D12_HEAP_TYPE_UPLOAD || props->Type == D3D12_HEAP_TYPE_READBACK))
Expand All @@ -4268,12 +4285,14 @@ HRESULT create_depth_uav_backing(DeviceProxy* self, const D3D12_HEAP_PROPERTIES*
if (FAILED(hr)) {
(*out)->Release();
*out = nullptr;
if (refused) *refused = depth_provider_refusal(hr);
}
return hr;
}

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) {
std::uint32_t layout, const D3D12_CLEAR_VALUE* clear, REFIID riid, void** out,
bool* provider_refused) {
const auto native = depth_image_desc(desc);
const bool valid = self->validate_depth_placement(native, layout, clear);
D3D12_RESOURCE_ALLOCATION_INFO alloc{};
Expand All @@ -4283,12 +4302,13 @@ HRESULT proxy_create_placed_depth(DeviceProxy* self, UINT64 address, const D3D12
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);
clear, backing, provider_refused);
});
}
// A refusal here reaches no trace line, and the title stops on an int3 right after it: log the first few.
// A refusal here reaches no trace line, and the title stops on an int3 right after it: log the first few. The
// provider's own refusal is not one of them: slot 133 makes that texture without unordered access and says so.
static std::atomic<int> refusals{0};
if (FAILED(hr) && refusals.fetch_add(1, std::memory_order_relaxed) < 8)
if (FAILED(hr) && !*provider_refused && 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",
Expand Down Expand Up @@ -4329,13 +4349,19 @@ HRESULT proxy_create_resource(DeviceProxy* self, const D3D12_HEAP_PROPERTIES* he
// With a provider for the unordered-access planes the texture keeps them (two resources behind one).
if (supports_depth_uav(self, *xbox_desc)) {
ID3D12Resource* resource = nullptr;
bool refused = false;
HRESULT hr = create_depth_uav_backing(self, heap_properties, heap_flags, depth_image_desc(pc_desc),
depth_image_state(initial_state), clear_value, &resource);
if (FAILED(hr)) return hr;
hr = resource->QueryInterface(*riid, out);
if (SUCCEEDED(hr)) lease_title_resource_memory(self, *out, pc_desc, unsigned(xbox_desc->Layout));
resource->Release();
return hr;
depth_image_state(initial_state), clear_value, &resource, &refused);
if (SUCCEEDED(hr)) {
hr = resource->QueryInterface(*riid, out);
if (SUCCEEDED(hr)) lease_title_resource_memory(self, *out, pc_desc, unsigned(xbox_desc->Layout));
resource->Release();
return hr;
}
if (!refused) return hr;
// pc_desc has no unordered access already (without_depth_stencil_uav): the committed texture below is it.
static std::atomic<bool> refusal_seen{false};
note_depth_provider_refusal(refusal_seen, 76, xbox_desc->Format, hr);
}
const HRESULT hr = self->real->CreateCommittedResource(heap_properties, heap_flags, &pc_desc,
pc_initial_state(&pc_desc, initial_state), clear_value,
Expand Down Expand Up @@ -4663,7 +4689,13 @@ HRESULT proxy_create_placed_resource_slot133(DeviceProxy* self, std::uint64_t va
depth_uav_description(*xbox_desc)) {
note_slot(133);
*out = nullptr;
return proxy_create_placed_depth(self, va, *xbox_desc, state, clear_value, *riid, out);
bool refused = false;
const HRESULT hr = proxy_create_placed_depth(self, va, *xbox_desc, state, clear_value, *riid, out, &refused);
if (!refused) return hr;
// The paths below make it without unordered access, as before the provider (depth_provider_refusal).
*out = nullptr;
static std::atomic<bool> refusal_seen{false};
note_depth_provider_refusal(refusal_seen, 133, xbox_desc->Format, hr);
}
if (out && xbox_desc && riid) {
const HRESULT hr = proxy_create_buffer_at_va(self, reinterpret_cast<void*>(va), xbox_desc, state, clear_value,
Expand Down
49 changes: 49 additions & 0 deletions runtime/test/xbox_depth_storage_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,50 @@ int check_lease(ID3D12Device* dev, ID3D12Device* xbox) {
rt::d3d12_xs::set_descriptor_heap_allocator(nullptr, nullptr);
return 0;
}

// With the console D16S8 family made as D24S8 (LEONIDA_CONSOLE_D16S8=d24; the default on a GPU with D24S8
// attachments, every NVIDIA card), the depth provider has no unordered-access form of a format 118 depth-stencil
// texture and refuses it (Resource::enable_depth_stencil_uav). Slots 76 and 133 then make it without unordered
// access, as before the provider, so the title gets its texture instead of asserting. The description is the one
// measured where a real boot stopped: 1280x720, one mip, the all-ones layout through slot 133.
int check_d16s8_refused_uav(ID3D12Device* xbox) {
D3D12_RESOURCE_DESC tex{};
tex.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
tex.Width = 1280;
tex.Height = 720;
tex.DepthOrArraySize = tex.MipLevels = 1;
tex.SampleDesc.Count = 1;
tex.Format = static_cast<DXGI_FORMAT>(118);
tex.Layout = static_cast<D3D12_TEXTURE_LAYOUT>(0x101);
tex.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
D3D12_HEAP_PROPERTIES heap{D3D12_HEAP_TYPE_DEFAULT};
D3D12_CLEAR_VALUE clear{};
clear.Format = tex.Format;
clear.DepthStencil.Depth = 1;
using Create = HRESULT(WINAPI*)(void*, const D3D12_HEAP_PROPERTIES*, UINT, const D3D12_RESOURCE_DESC*, UINT,
const D3D12_CLEAR_VALUE*, const IID*, void**);
Ref<ID3D12Resource> committed;
VERIFY(SUCCEEDED(reinterpret_cast<Create>(slot(xbox, 76))(xbox, &heap, 0, &tex, D3D12_RESOURCE_STATE_DEPTH_WRITE,
&clear, &__uuidof(ID3D12Resource),
reinterpret_cast<void**>(&committed.p))));
VERIFY(committed.p && committed->GetDesc().Flags == D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL);

using Place = HRESULT(WINAPI*)(void*, UINT64, const D3D12_RESOURCE_DESC*, UINT, const D3D12_CLEAR_VALUE*,
const IID*, void**);
constexpr SIZE_T pages = 16u << 20; // past the texture's size on any GPU; VirtualAlloc aligns it to 64 KiB
void* va = VirtualAlloc(nullptr, pages, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
VERIFY(va);
Ref<ID3D12Resource> placed;
const HRESULT hr = reinterpret_cast<Place>(slot(xbox, 133))(xbox, reinterpret_cast<UINT64>(va), &tex, 0xFFFFFFFFu,
&clear, &__uuidof(ID3D12Resource),
reinterpret_cast<void**>(&placed.p));
const bool made = SUCCEEDED(hr) && placed.p && placed->GetDesc().Flags == D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
placed = {};
VirtualFree(va, 0, MEM_RELEASE);
VERIFY(made);
std::printf("Xbox D16S8 made as D24S8: slots 76 and 133 make the depth-stencil texture without unordered access\n");
return 0;
}
}

int main() {
Expand Down Expand Up @@ -96,6 +140,11 @@ int main() {
VERIFY(SUCCEEDED(rt::d3d12_xs::create_device_proxy(dev, __uuidof(ID3D12Device),
reinterpret_cast<void**>(&proxy.p), true)));
rt::d3d12::set_device_outer(dev, proxy.p);
if (std::getenv("LEONIDA_TEST_D16S8_REFUSED_UAV")) {
VERIFY(check_d16s8_refused_uav(proxy.p) == 0);
VERIFY(gpu.validation_errors() == 0);
return 0;
}
VERIFY(check_lease(dev, proxy.p) == 0);
const auto allocation = dev->GetResourceAllocationInfo(0, 1, &tex);
VERIFY(allocation.SizeInBytes >= 768u * 768 * layers * 2 && allocation.SizeInBytes != UINT64_MAX);
Expand Down
Loading
Loading