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
15 changes: 7 additions & 8 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -2988,14 +2988,13 @@ The console has two list topologies Vulkan lacks: rectangle list (`IASetPrimitiv
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`.
the committed one). The first such refusal per slot is logged (`xs_proxy_mock` checks the refusal against a mock
provider). Any other failure (out of memory, the backing itself, a refused placement) is passed on as before.
Console D16S8 (format 118) made as `D24_UNORM_S8_UINT` via `pc_format()` (the default on GPUs with D24S8
attachments, such as NVIDIA) keeps its UAVs through the widened `R16_TYPELESS` + `R8_UINT` storage planes:
plane-0 barriers convert between 24-bit UNORM words in transfer scratch and `R32_SFLOAT` via `Depth24Converter`
and blit between the intermediate `R32_FLOAT` image and `R16_UNORM` (viewed as `R16_UINT` or `R16_UNORM`), while
plane 1 copies stencil bytes directly (`xbox_d16s8_d24_storage` 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
10 changes: 5 additions & 5 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3086,11 +3086,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)
# Made as D24S8 (the default on GPUs with D24S8 attachments, e.g. NVIDIA), a D16S8 depth-stencil texture keeps
# its UAVs through the widened R16_TYPELESS + R8_UINT planes and Depth24Converter.
add_test(NAME xbox_d16s8_d24_storage COMMAND xbox_depth_storage_test)
set_tests_properties(xbox_d16s8_d24_storage PROPERTIES
ENVIRONMENT "LEONIDA_TEST_D16S8_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
45 changes: 38 additions & 7 deletions runtime/shims/d3d12_vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4968,7 +4968,8 @@ Format texture_format(const DeviceState& device, const D3D12_RESOURCE_DESC& desc
// no-op. An A8 render target's VK_FORMAT_A8_UNORM_KHR image (Format::a8_as_alpha) is in a class of its own: no
// other format can be a view format of it, so any other castable format is refused here, before Vulkan.
HRESULT castable_view_formats(const Format& format, DXGI_FORMAT resource_format, UINT32 count,
const DXGI_FORMAT* castable, std::vector<VkFormat>& out, bool depth_uav_planes = false) {
const DXGI_FORMAT* castable, std::vector<VkFormat>& out, bool depth_uav_planes = false,
bool console_d16s8 = false) {
if (!count || !castable) return S_OK;
const bool depth = (format.aspects & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) != 0;
const leonida::BlockFormat own = leonida::block_format(format.format, format.aspects);
Expand All @@ -4985,6 +4986,13 @@ HRESULT castable_view_formats(const Format& format, DXGI_FORMAT resource_format,
const bool valid = format.format == VK_FORMAT_D16_UNORM
? view == DXGI_FORMAT_R16_TYPELESS || view == DXGI_FORMAT_D16_UNORM ||
view == DXGI_FORMAT_R16_UNORM || view == DXGI_FORMAT_R16_UINT
: (format.xbox_depth16_stencil8 || console_d16s8)
? view == xbox_d16s8 || view == xbox_d16_plane || view == xbox_s8_plane ||
(format.d24 && (view == DXGI_FORMAT_D24_UNORM_S8_UINT ||
view == DXGI_FORMAT_R24_UNORM_X8_TYPELESS ||
view == DXGI_FORMAT_X24_TYPELESS_G8_UINT)) ||
view == DXGI_FORMAT_R16_TYPELESS || view == DXGI_FORMAT_R16_UNORM ||
view == DXGI_FORMAT_R16_UINT || view == DXGI_FORMAT_R8_UINT
: view == DXGI_FORMAT_R32G8X24_TYPELESS || view == DXGI_FORMAT_D32_FLOAT_S8X24_UINT ||
view == DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS || view == DXGI_FORMAT_X32_TYPELESS_G8X24_UINT ||
view == DXGI_FORMAT_R32_FLOAT || view == DXGI_FORMAT_R8_UINT;
Expand Down Expand Up @@ -6570,10 +6578,13 @@ class Resource final
}

public:
void mark_console_d16s8() { console_d16s8_ = true; }
bool console_d16s8() const { return console_d16s8_; }

// The Xbox proxy calls this before publishing an allocated depth texture. Each storage plane owns a
// regular color image with its own GFX10 address, so a UAV cannot replace the original SRV in set 0.
HRESULT enable_depth_stencil_uav(D3D12_HEAP_FLAGS storage_heap_flags) {
const bool narrow_stencil = desc_.Format == xbox_d16s8;
const bool narrow_stencil = desc_.Format == xbox_d16s8 || console_d16s8_;
const bool depth16 = desc_.Format == DXGI_FORMAT_R16_TYPELESS || narrow_stencil;
if (!image_ || (!depth16 && desc_.Format != DXGI_FORMAT_R32G8X24_TYPELESS) ||
!(desc_.Flags & D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL) ||
Expand All @@ -6590,7 +6601,10 @@ class Resource final
std::unique_ptr<Resource> conversion;
if (widened) {
const auto blit = VK_FORMAT_FEATURE_2_BLIT_SRC_BIT | VK_FORMAT_FEATURE_2_BLIT_DST_BIT;
if (format_ != VK_FORMAT_D32_SFLOAT_S8_UINT || (device_.optimal_features(VK_FORMAT_R16_UNORM) & blit) != blit ||
const bool d24_backing = format_ == VK_FORMAT_D24_UNORM_S8_UINT;
if ((format_ != VK_FORMAT_D32_SFLOAT_S8_UINT && !d24_backing) ||
(d24_backing && !device_.context->has_depth24()) ||
(device_.optimal_features(VK_FORMAT_R16_UNORM) & blit) != blit ||
(device_.optimal_features(VK_FORMAT_R32_SFLOAT) & blit) != blit) return E_NOTIMPL;
auto intermediate = plane_desc;
intermediate.Format = DXGI_FORMAT_R32_FLOAT;
Expand Down Expand Up @@ -7206,6 +7220,7 @@ class Resource final
leonida::ResourceBinding binding_{}; // a texture's, as registered with the context
std::unique_ptr<Resource> depth_conversion_;
std::array<std::unique_ptr<Resource>, 2> storage_planes_; // Xbox depth/stencil UAV, by plane
bool console_d16s8_ = false; // created from Xbox format 118 (even when pc_format made it D24S8)
VkImage shared_zero_ = VK_NULL_HANDLE; // owned by the device
std::unique_ptr<leonida::DeferredImageBinding> deferred_attachment_;
std::atomic<bool> replay_seen_{false};
Expand Down Expand Up @@ -11085,12 +11100,15 @@ class Device final
// device addresses the same scratch holds the triangle indices of indexed quad lists (quad_index_expand.h):
// a compute pass writes them through the chunk's address and the draw binds the chunk as its index buffer.
const bool index_scratch = info.buffer_device_address;
const VkBufferUsageFlags scratch_extra =
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
(index_scratch ? VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT : 0);
state_.context->enable_copy_scratch(
get_device,
[this, index_scratch](const VkMemoryRequirements& requirements) {
return state_.allocate(requirements, 0, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, nullptr, index_scratch);
},
index_scratch ? VK_BUFFER_USAGE_INDEX_BUFFER_BIT | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT : 0, state_.families);
scratch_extra, state_.families);
if (info.buffer_device_address && info.physical && info.get_instance_proc) {
if (const auto get_props = reinterpret_cast<PFN_vkGetPhysicalDeviceProperties>(
info.get_instance_proc(info.instance, "vkGetPhysicalDeviceProperties"))) {
Expand Down Expand Up @@ -14483,7 +14501,7 @@ class Device final
return;
}
const Resource* storage = r->depth_stencil_uav(view.plane);
const bool raw_narrow = storage && r->desc().Format == xbox_d16s8 && view.plane == 0 &&
const bool raw_narrow = storage && (r->desc().Format == xbox_d16s8 || r->console_d16s8()) && view.plane == 0 &&
(view.format == DXGI_FORMAT_R16_UINT ||
(storage->desc().Format == DXGI_FORMAT_R16_TYPELESS && view.format == DXGI_FORMAT_R16_UNORM));
if (!storage || (!raw_narrow && view.format != storage->desc().Format)) {
Expand Down Expand Up @@ -15219,9 +15237,17 @@ class Device final
if (out) *out = nullptr;
auto* heap = Heap::from<Heap>(heap_interface);
if (!heap || !desc) return d3d12_trace::result(method, E_INVALIDARG);
const bool from_xbox_d16s8 = desc->Format == xbox_d16s8;
D3D12_RESOURCE_DESC canonical = *desc;
canonical.Format = pc_format(canonical.Format); // the console's D16S8 family as D24S8
desc = &canonical;
// Its clear value too, or the clear format's family (118) would not match the resource's (D24S8) below.
D3D12_CLEAR_VALUE canonical_clear{};
if (clear) {
canonical_clear = *clear;
canonical_clear.Format = pc_format(canonical_clear.Format);
clear = &canonical_clear;
}
if (heap->host_address()) {
// An existing heap is not an arena range, and the placed path addresses resources by arena offset.
log_once("a placed resource in an existing heap (OpenExistingHeapFromAddress) is not supported yet; "
Expand Down Expand Up @@ -15309,6 +15335,7 @@ class Device final
// create_texture makes for 1D, 2D and 3D alike (arrays and mips included), as for a committed texture.
const VkDeviceSize placed_va = desc->Dimension == D3D12_RESOURCE_DIMENSION_BUFFER ? heap->offset() + heap_offset : 0;
auto* resource = new Resource(state_, *desc, heap->properties(), heap->flags(), placed_va);
if (from_xbox_d16s8) resource->mark_console_d16s8();
resource->attach_device(identity());
HRESULT hr = E_NOTIMPL;
if (buffer) {
Expand All @@ -15320,7 +15347,8 @@ class Device final
hr = E_INVALIDARG;
} else {
std::vector<VkFormat> cast_formats;
hr = castable_view_formats(format, desc->Format, castable_count, castable, cast_formats);
hr = castable_view_formats(format, desc->Format, castable_count, castable, cast_formats, false,
from_xbox_d16s8);
if (SUCCEEDED(hr)) hr = resource->create_texture(format, cast_formats);
if (SUCCEEDED(hr)) resource->keep_castable_formats(castable_count, castable);
}
Expand Down Expand Up @@ -16588,6 +16616,7 @@ class Device final
TitleImageOrigin origin = TitleImageOrigin::ordinary) {
if (out) *out = nullptr;
if (!heap || !desc) return E_INVALIDARG;
const bool from_xbox_d16s8 = desc->Format == xbox_d16s8;
D3D12_RESOURCE_DESC canonical = *desc;
canonical.Format = pc_format(canonical.Format); // the console's D16S8 family as D24S8
desc = &canonical;
Expand All @@ -16596,6 +16625,7 @@ class Device final
return E_INVALIDARG;
}
auto* resource = new Resource(state_, *desc, *heap, heap_flags);
if (from_xbox_d16s8) resource->mark_console_d16s8();
resource->attach_device(identity());
HRESULT hr = E_NOTIMPL;
if (desc->Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) {
Expand Down Expand Up @@ -16632,7 +16662,8 @@ class Device final
hr = E_INVALIDARG;
} else {
std::vector<VkFormat> cast_formats;
hr = castable_view_formats(format, desc->Format, castable_count, castable, cast_formats, storage_heap_flags.has_value());
hr = castable_view_formats(format, desc->Format, castable_count, castable, cast_formats,
storage_heap_flags.has_value(), from_xbox_d16s8);
if (SUCCEEDED(hr)) hr = resource->create_texture(format, cast_formats, origin);
if (SUCCEEDED(hr)) resource->keep_castable_formats(castable_count, castable);
if (SUCCEEDED(hr) && storage_heap_flags) hr = resource->enable_depth_stencil_uav(*storage_heap_flags);
Expand Down
5 changes: 5 additions & 0 deletions runtime/src/vulkan_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,11 @@ class VulkanContext {
};
}

bool has_depth24() {
std::shared_lock lock(resource_mutex_);
return depth24_ != nullptr;
}

// Copies the replay stages through a buffer (depth <-> colour, vulkan_replay.h) take device-local scratch from
// `allocate`. Without this such a copy is refused as unsupported. `extra_usage` is added to the chunks' transfer
// usage, for configure_quad_indices.
Expand Down
Loading
Loading