From 0a92b1396858836939d39df84ffc933e5b3ed8d6 Mon Sep 17 00:00:00 2001 From: Moriz82 <72836413+Moriz82@users.noreply.github.com> Date: Tue, 24 Nov 2026 16:18:09 -0600 Subject: [PATCH] d3d12: resolve views of live placed textures (RT-TITLE-TEXTURE-VIEWS) A raw shader-resource view of a live image used to return a null descriptor. Match the placement and resource description for SRVs and UAVs, retain the chosen image while creating its view, and remove its entry on final release. The placement ABI is also documented by VIctory. The default and rollback GPU tests each sampled 64 expected texels from a placed view. The default accepted two writable views and rejected two controls. The rollback returned four null UAVs. xs_proxy_mock's invalid environment-slot case used slot 71 as its forwarded PC slot. Slot 71 is routed now, so the case probes slot 72. All six CTest forms of the proxy test pass. Rebased onto main after #375: both sides of device_slot_overridden and of the proxy test's check list are kept. All eight registered forms of the two tests pass on the rebased head under Wine 11.22. AI-assisted (Codex and Claude Code agents). Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 Co-Authored-By: Claude Opus 5.5 --- docs/d3d12_vulkan.md | 5 ++ runtime/CMakeLists.txt | 3 + runtime/test/d3d12_set0_compute_test.cpp | 93 ++++++++++++++++++++++-- 3 files changed, 95 insertions(+), 6 deletions(-) diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index 97d737c8ea..20ecff0f42 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -704,6 +704,11 @@ side inwards: `TEXTURE2DMS` view reads layer zero, while `TEXTURE2DMSARRAY` selects a range starting at `FirstArraySlice` (`ArraySize = UINT_MAX` selects the remaining layers). The format-support query advertises `MULTISAMPLE_LOAD` when the format can be sampled with MSAA and its binding pair is available. + - Xbox device slots 70 (SRV) and 71 (UAV) can select a live texture created by slot 133. + The address and resource description select the most recent compatible placement, including when + several live resources share an address. UAVs require writable backing. A 3D UAV can select one + complete mip. A missing placement or unsupported view gives a null descriptor. + Set `LEONIDA_PLACED_TEXTURE_UAV=0` to restore null placed UAVs. - A texture is named in its T#s by an address of its own, above 4 GiB and 256 bytes apart, that nothing dereferences; its entries leave the set and the table when it is destroyed. - `VulkanDeviceInfo::bindless` says the Vulkan device has the features this needs: `runtimeDescriptorArray`, diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 48c8af3602..232b441ba3 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -3637,6 +3637,9 @@ if(TARGET Vulkan::Headers) target_compile_options(d3d12_set0_compute_test PRIVATE /W4 /permissive- /utf-8) add_test(NAME d3d12_set0_compute COMMAND d3d12_set0_compute_test) set_tests_properties(d3d12_set0_compute PROPERTIES SKIP_RETURN_CODE 77) + add_test(NAME d3d12_placed_texture_uav_off COMMAND d3d12_set0_compute_test) + set_tests_properties(d3d12_placed_texture_uav_off PROPERTIES SKIP_RETURN_CODE 77 + ENVIRONMENT "LEONIDA_PLACED_TEXTURE_UAV=0") set(depth_uav_shader ${CMAKE_CURRENT_SOURCE_DIR}/test/glsl/cs_depth_stencil_uav.comp) foreach(variant IN ITEMS DEPTH_STENCIL_2D DEPTH_STENCIL_ARRAY DEPTH16_2D DEPTH16_ARRAY) set(spv ${CMAKE_CURRENT_BINARY_DIR}/generated/cs_depth_uav_${variant}.spv) diff --git a/runtime/test/d3d12_set0_compute_test.cpp b/runtime/test/d3d12_set0_compute_test.cpp index a37f486d72..1d434a2653 100644 --- a/runtime/test/d3d12_set0_compute_test.cpp +++ b/runtime/test/d3d12_set0_compute_test.cpp @@ -21,10 +21,12 @@ #include "d3d12_test_shaders.h" #include "../shims/d3d12_com.h" #include "../shims/d3d12_xs_device.h" +#include "../src/gfx10_descriptors.h" #include "../src/shader_library.h" #include #include +#include #include #include #include @@ -53,6 +55,82 @@ Texel gradient(UINT x, UINT y) { // The second texture: the first one point-reflected, so no texel of it is in the same place. Texel reflected(UINT x, UINT y) { return gradient(texture_size - 1 - x, texture_size - 1 - y); } +// Exercise the console ABI: slot 133 publishes a placement and slots 70/71 receive descriptions +// plus an address, with no resource pointer. The address itself is opaque to these GPU-only tests. +HRESULT place(ID3D12Device* dev, void* address, const D3D12_RESOURCE_DESC& desc, UINT layout, ID3D12Resource** out) { + using Fn = HRESULT(WINAPI*)(ID3D12Device*, void*, const D3D12_RESOURCE_DESC*, UINT, const void*, REFIID, void**); + return reinterpret_cast(slot(dev, 133))(dev, address, &desc, layout, nullptr, IID_PPV_ARGS(out)); +} + +template +void placed_view(ID3D12Device* dev, UINT method, const D3D12_RESOURCE_DESC& desc, const View& view, + const void* address, D3D12_CPU_DESCRIPTOR_HANDLE dest) { + std::array words{}; + static_assert(sizeof(View) <= 10 * sizeof(UINT)); + std::memcpy(words.data(), &view, sizeof(view)); + std::memcpy(words.data() + 10, &address, sizeof(address)); + using Fn = void(WINAPI*)(ID3D12Device*, const D3D12_RESOURCE_DESC*, const void*, D3D12_CPU_DESCRIPTOR_HANDLE); + reinterpret_cast(slot(dev, method))(dev, &desc, words.data(), dest); +} + +int check_placed_uavs(ID3D12Device* device) { + alignas(256) std::byte address{}; + D3D12_RESOURCE_DESC array{}; + array.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; + array.Width = array.Height = 8; + array.DepthOrArraySize = 6; + array.MipLevels = array.SampleDesc.Count = 1; + array.Format = DXGI_FORMAT_R32_UINT; + array.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; + auto face = array; + face.DepthOrArraySize = 1; + Ref older, newer; + EXPECT(SUCCEEDED(place(device, &address, array, 3, &older.p))); + EXPECT(SUCCEEDED(place(device, &address, face, 3, &newer.p))); + + D3D12_UNORDERED_ACCESS_VIEW_DESC view{}; + view.Format = array.Format; + view.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; + view.Texture2DArray.FirstArraySlice = 5; + view.Texture2DArray.ArraySize = 1; + using Words = std::array; + Words expected{}, got{}; + const D3D12_CPU_DESCRIPTOR_HANDLE dest{reinterpret_cast(got.data())}; + device->CreateUnorderedAccessView(older.p, nullptr, &view, {reinterpret_cast(expected.data())}); + EXPECT(expected != Words{}); + const char* value = std::getenv("LEONIDA_PLACED_TEXTURE_UAV"); + const bool enabled = !value || std::strcmp(value, "0") != 0; + placed_view(device, 71, array, view, &address, dest); + EXPECT(got == (enabled ? expected : Words{})); + older.reset(); + got.fill(~0u); + placed_view(device, 71, array, view, &address, dest); + EXPECT(got == Words{}); // The remaining single-layer image cannot supply layer 5. + + auto volume = face; + volume.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE3D; + volume.DepthOrArraySize = 8; + volume.MipLevels = 2; + Ref volume_target; + EXPECT(SUCCEEDED(place(device, &address, volume, 3, &volume_target.p))); + view.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE3D; + view.Texture3D = {1, 0, 4}; + placed_view(device, 71, volume, view, &address, dest); + leonida::gfx10::Image decoded{}; + if (enabled) { + EXPECT(leonida::gfx10::decode(got, decoded) && decoded.type == leonida::gfx10::ImageType::image_3d && + decoded.first_mip == 1 && decoded.mip_count == 1); + } else { + EXPECT(got == Words{}); + } + view.Texture3D.WSize = 2; + got.fill(~0u); + placed_view(device, 71, volume, view, &address, dest); + EXPECT(got == Words{}); + std::printf("placed UAVs: %u matching views, %u null controls\n", enabled ? 2 : 0, enabled ? 2 : 4); + return 0; +} + } // namespace int main() { @@ -163,10 +241,12 @@ int main() { texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; texture_desc.SampleDesc.Count = 1; Ref textures[2], upload, output, readback; - for (auto& texture : textures) - EXPECT(SUCCEEDED(device->CreateCommittedResource(&default_heap, D3D12_HEAP_FLAG_NONE, &texture_desc, - D3D12_RESOURCE_STATE_COPY_DEST, nullptr, - IID_PPV_ARGS(&texture.p)))); + EXPECT(SUCCEEDED(device->CreateCommittedResource(&default_heap, D3D12_HEAP_FLAG_NONE, &texture_desc, + D3D12_RESOURCE_STATE_COPY_DEST, nullptr, + IID_PPV_ARGS(&textures[0].p)))); + alignas(256) std::byte placement{}; + EXPECT(SUCCEEDED(place(device.p, &placement, texture_desc, 8, &textures[1].p))); + EXPECT(check_placed_uavs(device.p) == 0); // The upload buffer: texture A at 0, texture B at 2048 (8 rows of the 256-byte pitch). constexpr UINT64 b_offset = 2048; const auto upload_desc = buffer_desc(4096); @@ -219,8 +299,9 @@ int main() { srv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; srv.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; srv.Texture2D = {0, 1, 0, 0.0f}; - device->CreateShaderResourceView(textures[i].p, &srv, - D3D12_CPU_DESCRIPTOR_HANDLE{SIZE_T(view_cpu + i * view_step)}); + const D3D12_CPU_DESCRIPTOR_HANDLE dest{SIZE_T(view_cpu + i * view_step)}; + if (i == 0) device->CreateShaderResourceView(textures[i].p, &srv, dest); + else placed_view(device.p, 70, texture_desc, srv, &placement, dest); } // Slot 2: bytes no view was made for. The hash table has no entry for them. std::uint32_t unknown[8];