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
7 changes: 6 additions & 1 deletion docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 21 additions & 7 deletions runtime/shims/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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<unsigned>(hr), valid ? "placement" : "description", int(desc.Format),
static_cast<unsigned long long>(desc.Width), unsigned(desc.Height), unsigned(desc.DepthOrArraySize),
unsigned(desc.Layout), layout, static_cast<unsigned long long>(alloc.SizeInBytes));
return hr;
}

HRESULT proxy_create_resource(DeviceProxy* self, const D3D12_HEAP_PROPERTIES* heap_properties,
Expand Down
10 changes: 9 additions & 1 deletion runtime/shims/d3d12_xs_placed_depth.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
23 changes: 22 additions & 1 deletion runtime/test/d3d12_placed_depth_test.h
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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<ID3D12Resource> 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<ID3D12Resource> 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<ID3D12DescriptorHeap> heap;
D3D12_DESCRIPTOR_HEAP_DESC heap_desc{D3D12_DESCRIPTOR_HEAP_TYPE_DSV, 2};
Expand Down
Loading