diff options
| author | Emma <47298336+zzEmmazz@users.noreply.github.com> | 2026-11-22 23:59:14 +0200 |
|---|---|---|
| committer | Emma <47298336+zzEmmazz@users.noreply.github.com> | 2026-11-22 23:59:14 +0200 |
| commit | 0fa95b983ecefdf6f5ceea3c8aa44cae22fc9c76 (patch) | |
| tree | 52710f107f55e005f3a4e2633b5e07b87fb5529d /runtime | |
| parent | f847748cc76bd3777f9c070c4034eb2fc1c04e64 (diff) | |
d3d12: ArraySize -1 in 2D-array RTVs and DSVs is every slice from the first on
CreateRenderTargetView and CreateDepthStencilView stored ArraySize -1 of a
TEXTURE2DARRAY or TEXTURE2DMSARRAY view as the layer count, so the view was
nulled (typeless and castable RGBA8) or the list was refused at replay. The
host accepts it and clears the remaining slices. Resolve it at creation;
out-of-range views are refused as before. d3d12_view_slices_test compares
clears through such views with the host on the same adapter and WARP.
d3d12_typeless_rtv_test listed {first slice 1, ArraySize -1} on a four-slice
texture among the views the layer must reject; the host accepts that view, so
the entry now uses first slice 4, which the host refuses too.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/CMakeLists.txt | 9 | ||||
| -rw-r--r-- | runtime/shims/d3d12_vulkan_device.cpp | 17 | ||||
| -rw-r--r-- | runtime/test/d3d12_typeless_rtv_test.cpp | 4 | ||||
| -rw-r--r-- | runtime/test/d3d12_view_slices_test.cpp | 262 |
4 files changed, 287 insertions, 5 deletions
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 8f1dce2ca..355f92731 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt | |||
| @@ -1255,6 +1255,15 @@ if(TARGET Vulkan::Headers) | |||
| 1255 | target_compile_options(d3d12_typeless_rtv_test PRIVATE /W4 /permissive- /utf-8) | 1255 | target_compile_options(d3d12_typeless_rtv_test PRIVATE /W4 /permissive- /utf-8) |
| 1256 | add_test(NAME d3d12_typeless_rtv COMMAND d3d12_typeless_rtv_test) | 1256 | add_test(NAME d3d12_typeless_rtv COMMAND d3d12_typeless_rtv_test) |
| 1257 | 1257 | ||
| 1258 | # ArraySize -1 in array RTVs and DSVs (every slice from the first on), against the host on the same adapter | ||
| 1259 | # and WARP. | ||
| 1260 | add_executable(d3d12_view_slices_test test/d3d12_view_slices_test.cpp) | ||
| 1261 | target_link_libraries(d3d12_view_slices_test PRIVATE gta6rt_d3d12_com d3d12 dxgi) | ||
| 1262 | target_compile_definitions(d3d12_view_slices_test PRIVATE WIN32_LEAN_AND_MEAN NOMINMAX) | ||
| 1263 | target_compile_options(d3d12_view_slices_test PRIVATE /W4 /permissive- /utf-8) | ||
| 1264 | add_test(NAME d3d12_view_slices COMMAND d3d12_view_slices_test) | ||
| 1265 | set_tests_properties(d3d12_view_slices PROPERTIES SKIP_RETURN_CODE 77) | ||
| 1266 | |||
| 1258 | # Typed RTV clears and draws of every TYPELESS color family against the host on the same adapter and WARP | 1267 | # Typed RTV clears and draws of every TYPELESS color family against the host on the same adapter and WARP |
| 1259 | # (D3D-275). The draws need glslangValidator for their GLSL stand-ins of translated shaders. | 1268 | # (D3D-275). The draws need glslangValidator for their GLSL stand-ins of translated shaders. |
| 1260 | add_executable(d3d12_typeless_families_test test/d3d12_typeless_families_test.cpp) | 1269 | add_executable(d3d12_typeless_families_test test/d3d12_typeless_families_test.cpp) |
diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index 3fb36bd4a..10df0ec6b 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp | |||
| @@ -341,6 +341,13 @@ leonida::TargetView line_target_view(leonida::ResourceId id, const D3D12_RESOURC | |||
| 341 | return {id, mip, first_layer, count}; | 341 | return {id, mip, first_layer, count}; |
| 342 | } | 342 | } |
| 343 | 343 | ||
| 344 | // ArraySize of a 2D-array RTV or DSV: UINT_MAX is every slice from the first on, as on the host. Any other count | ||
| 345 | // is kept, and UINT_MAX with a first slice past the array too, so an out-of-range view is refused as before. | ||
| 346 | UINT view_slices(const D3D12_RESOURCE_DESC& resource, UINT first_layer, UINT layer_count) { | ||
| 347 | const bool remaining = layer_count == UINT_MAX && first_layer < resource.DepthOrArraySize; | ||
| 348 | return remaining ? resource.DepthOrArraySize - first_layer : layer_count; | ||
| 349 | } | ||
| 350 | |||
| 344 | // The VkImage a texture description becomes, with its mip count already resolved (MipLevels != 0). Shared by | 351 | // The VkImage a texture description becomes, with its mip count already resolved (MipLevels != 0). Shared by |
| 345 | // texture creation and GetResourceAllocationInfo, so the sizes reported are the sizes later allocated. | 352 | // texture creation and GetResourceAllocationInfo, so the sizes reported are the sizes later allocated. |
| 346 | // Keeps the optional VkImageFormatListCreateInfo alongside VkImageCreateInfo so info.pNext stays valid. | 353 | // Keeps the optional VkImageFormatListCreateInfo alongside VkImageCreateInfo so info.pNext stays valid. |
| @@ -4842,10 +4849,11 @@ public: | |||
| 4842 | view = {rid, 0, 0, 1}; | 4849 | view = {rid, 0, 0, 1}; |
| 4843 | } else if (desc && desc->ViewDimension == D3D12_RTV_DIMENSION_TEXTURE2DARRAY) { | 4850 | } else if (desc && desc->ViewDimension == D3D12_RTV_DIMENSION_TEXTURE2DARRAY) { |
| 4844 | view = {rid, desc->Texture2DArray.MipSlice, desc->Texture2DArray.FirstArraySlice, | 4851 | view = {rid, desc->Texture2DArray.MipSlice, desc->Texture2DArray.FirstArraySlice, |
| 4845 | desc->Texture2DArray.ArraySize}; | 4852 | view_slices(rd, desc->Texture2DArray.FirstArraySlice, desc->Texture2DArray.ArraySize)}; |
| 4846 | } else if (desc && desc->ViewDimension == D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY) { | 4853 | } else if (desc && desc->ViewDimension == D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY) { |
| 4847 | // Multisample textures have one mip, so only the slice range is chosen (as for the DSV). | 4854 | // Multisample textures have one mip, so only the slice range is chosen (as for the DSV). |
| 4848 | view = {rid, 0, desc->Texture2DMSArray.FirstArraySlice, desc->Texture2DMSArray.ArraySize}; | 4855 | view = {rid, 0, desc->Texture2DMSArray.FirstArraySlice, |
| 4856 | view_slices(rd, desc->Texture2DMSArray.FirstArraySlice, desc->Texture2DMSArray.ArraySize)}; | ||
| 4849 | } else if (desc) { | 4857 | } else if (desc) { |
| 4850 | log_once("render-target view dimension not supported:", desc->ViewDimension); | 4858 | log_once("render-target view dimension not supported:", desc->ViewDimension); |
| 4851 | view = {}; | 4859 | view = {}; |
| @@ -4938,10 +4946,11 @@ public: | |||
| 4938 | view = {r->id(), 0, 0, 1}; | 4946 | view = {r->id(), 0, 0, 1}; |
| 4939 | } else if (desc && desc->ViewDimension == D3D12_DSV_DIMENSION_TEXTURE2DARRAY) { | 4947 | } else if (desc && desc->ViewDimension == D3D12_DSV_DIMENSION_TEXTURE2DARRAY) { |
| 4940 | view = {r->id(), desc->Texture2DArray.MipSlice, desc->Texture2DArray.FirstArraySlice, | 4948 | view = {r->id(), desc->Texture2DArray.MipSlice, desc->Texture2DArray.FirstArraySlice, |
| 4941 | desc->Texture2DArray.ArraySize}; | 4949 | view_slices(rd, desc->Texture2DArray.FirstArraySlice, desc->Texture2DArray.ArraySize)}; |
| 4942 | } else if (desc && desc->ViewDimension == D3D12_DSV_DIMENSION_TEXTURE2DMSARRAY) { | 4950 | } else if (desc && desc->ViewDimension == D3D12_DSV_DIMENSION_TEXTURE2DMSARRAY) { |
| 4943 | // Multisample textures have one mip, so only the slice range is chosen. | 4951 | // Multisample textures have one mip, so only the slice range is chosen. |
| 4944 | view = {r->id(), 0, desc->Texture2DMSArray.FirstArraySlice, desc->Texture2DMSArray.ArraySize}; | 4952 | view = {r->id(), 0, desc->Texture2DMSArray.FirstArraySlice, |
| 4953 | view_slices(rd, desc->Texture2DMSArray.FirstArraySlice, desc->Texture2DMSArray.ArraySize)}; | ||
| 4945 | } else if (desc) { | 4954 | } else if (desc) { |
| 4946 | log_once("depth-stencil view dimension not supported:", desc->ViewDimension); | 4955 | log_once("depth-stencil view dimension not supported:", desc->ViewDimension); |
| 4947 | view = {}; | 4956 | view = {}; |
diff --git a/runtime/test/d3d12_typeless_rtv_test.cpp b/runtime/test/d3d12_typeless_rtv_test.cpp index d8b8d841e..fb1662c09 100644 --- a/runtime/test/d3d12_typeless_rtv_test.cpp +++ b/runtime/test/d3d12_typeless_rtv_test.cpp | |||
| @@ -643,7 +643,9 @@ int main() { | |||
| 643 | invalid.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DARRAY; | 643 | invalid.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DARRAY; |
| 644 | invalid.Texture2DArray = {0, 1, 1, 0}; | 644 | invalid.Texture2DArray = {0, 1, 1, 0}; |
| 645 | if (!rejects(DXGI_FORMAT_R8G8B8A8_TYPELESS, &invalid)) return 1; | 645 | if (!rejects(DXGI_FORMAT_R8G8B8A8_TYPELESS, &invalid)) return 1; |
| 646 | for (const auto range : {std::pair{1u, UINT_MAX}, std::pair{0u, 0u}, std::pair{4u, 1u}, std::pair{3u, 2u}}) { | 646 | // ArraySize -1 from a slice of the array is every slice left (d3d12_view_slices_test); past the array it is |
| 647 | // refused. | ||
| 648 | for (const auto range : {std::pair{4u, UINT_MAX}, std::pair{0u, 0u}, std::pair{4u, 1u}, std::pair{3u, 2u}}) { | ||
| 647 | invalid.Texture2DArray = {1, range.first, range.second, 0}; | 649 | invalid.Texture2DArray = {1, range.first, range.second, 0}; |
| 648 | if (!rejects(DXGI_FORMAT_R8G8B8A8_TYPELESS, &invalid, 3, 4)) return 1; | 650 | if (!rejects(DXGI_FORMAT_R8G8B8A8_TYPELESS, &invalid, 3, 4)) return 1; |
| 649 | } | 651 | } |
diff --git a/runtime/test/d3d12_view_slices_test.cpp b/runtime/test/d3d12_view_slices_test.cpp new file mode 100644 index 000000000..ec1e54521 --- /dev/null +++ b/runtime/test/d3d12_view_slices_test.cpp | |||
| @@ -0,0 +1,262 @@ | |||
| 1 | // ArraySize = -1 (UINT_MAX) in a render-target or depth-stencil view of a texture array: every slice from | ||
| 2 | // FirstArraySlice on, as D3D12 documents and the host measures. Each case seeds every subresource of a four-slice | ||
| 3 | // texture with zeros through one-slice views, clears to one through a single view with ArraySize -1, reads every | ||
| 4 | // subresource back and names the ones the clear reached: TEXTURE2DARRAY views of a mip chain (typed, typeless and | ||
| 5 | // depth) and TEXTURE2DMSARRAY views of 4x textures (read through a resolve). The layer must reach exactly the | ||
| 6 | // slices from the first one on, in the view's mip only, and so must the host's D3D12 on the layer's adapter and on | ||
| 7 | // WARP (skipped under Wine; WARP is not given the depth resolve, which removes its device, d3d12_depth_resolve_test). | ||
| 8 | // The layer's 4x depth array is checked by its descriptor instead (the same bytes as the view that counts the | ||
| 9 | // remaining slices, and the list runs): read through the layer's depth resolve, every slice of such a texture shows | ||
| 10 | // slice 0 on the AMD driver, with a counted ArraySize as well, so that readback cannot tell the slices apart there. | ||
| 11 | // A range the host's debug layer refuses stays refused by the layer: a first slice past the array (with -1 too), no | ||
| 12 | // slices, more slices than are left, and UINT_MAX - 1. Those are not run on the host. | ||
| 13 | // No game data or shaders. Needs a Vulkan GPU; LEONIDA_VK_VALIDATION=1 checks Vulkan usage. | ||
| 14 | #include "vk_test_device.h" | ||
| 15 | #include "d3d12_copy_compare.h" | ||
| 16 | |||
| 17 | namespace { | ||
| 18 | using copycmp::Ptr; | ||
| 19 | |||
| 20 | constexpr UINT kSlices = 4, kSize = 8; | ||
| 21 | |||
| 22 | struct Case { | ||
| 23 | const char* name; | ||
| 24 | bool depth; // a depth-stencil view of a depth texture, else a render-target view | ||
| 25 | DXGI_FORMAT resource, view; | ||
| 26 | UINT samples; // 4: TEXTURE2DMSARRAY views of a texture with one mip | ||
| 27 | }; | ||
| 28 | |||
| 29 | // Seeds, clears through {mip, first, count} and reads back. `reached` gets one bit per subresource (mip + slice * | ||
| 30 | // mips) the clear wrote. Returns an error text when the list was refused or the readback is not all zeros or ones. | ||
| 31 | // With `by_descriptor` (the layer only, whose descriptor is the bytes of its slot) nothing is read back: the view's | ||
| 32 | // slot must hold the bytes it holds for the view that counts the slices from `first` on, and the list must run. | ||
| 33 | std::string clear_through(copycmp::Run& run, const Case& c, UINT mip, UINT first, UINT count, std::uint32_t& reached, | ||
| 34 | bool by_descriptor = false) { | ||
| 35 | ID3D12Device* device = run.device; | ||
| 36 | const bool msaa = c.samples > 1; | ||
| 37 | D3D12_RESOURCE_DESC desc{}; | ||
| 38 | desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; | ||
| 39 | desc.Width = desc.Height = kSize; | ||
| 40 | desc.DepthOrArraySize = kSlices; | ||
| 41 | desc.MipLevels = msaa ? 1 : 3; | ||
| 42 | desc.Format = c.resource; | ||
| 43 | desc.SampleDesc.Count = c.samples; | ||
| 44 | desc.Flags = c.depth ? D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL : D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; | ||
| 45 | const auto written = c.depth ? D3D12_RESOURCE_STATE_DEPTH_WRITE : D3D12_RESOURCE_STATE_RENDER_TARGET; | ||
| 46 | D3D12_RESOURCE_DESC plain = desc; // what a multisampled texture is resolved into, slice by slice | ||
| 47 | plain.Format = c.view; | ||
| 48 | plain.SampleDesc.Count = 1; | ||
| 49 | if (!c.depth) plain.Flags = D3D12_RESOURCE_FLAG_NONE; | ||
| 50 | const UINT n = UINT(desc.MipLevels) * kSlices; | ||
| 51 | std::vector<copycmp::Placed> placed(n); | ||
| 52 | std::vector<UINT> rows(n); | ||
| 53 | std::vector<UINT64> row_bytes(n); | ||
| 54 | UINT64 total = 0; | ||
| 55 | device->GetCopyableFootprints(msaa ? &plain : &desc, 0, n, 0, placed.data(), rows.data(), row_bytes.data(), &total); | ||
| 56 | |||
| 57 | Ptr<ID3D12Resource> texture, resolved, readback; | ||
| 58 | Ptr<ID3D12DescriptorHeap> heap; | ||
| 59 | Ptr<ID3D12GraphicsCommandList1> list1; | ||
| 60 | const D3D12_DESCRIPTOR_HEAP_DESC heap_desc{ | ||
| 61 | c.depth ? D3D12_DESCRIPTOR_HEAP_TYPE_DSV : D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 1, | ||
| 62 | D3D12_DESCRIPTOR_HEAP_FLAG_NONE, 0}; | ||
| 63 | if (!run.texture(desc, written, texture) || | ||
| 64 | (msaa && !run.texture(plain, D3D12_RESOURCE_STATE_RESOLVE_DEST, resolved)) || | ||
| 65 | !run.buffer(D3D12_HEAP_TYPE_READBACK, total, D3D12_RESOURCE_STATE_COPY_DEST, readback) || | ||
| 66 | FAILED(device->CreateDescriptorHeap(&heap_desc, IID_PPV_ARGS(&heap.p))) || | ||
| 67 | (msaa && c.depth && FAILED(run.list->QueryInterface(IID_PPV_ARGS(&list1.p))))) | ||
| 68 | return "resource creation failed"; | ||
| 69 | const auto slot = heap->GetCPUDescriptorHandleForHeapStart(); | ||
| 70 | // A clear takes the descriptor as it is when the clear is recorded, so one slot serves every view. | ||
| 71 | const auto clear = [&](UINT view_mip, UINT view_first, UINT view_count, FLOAT value) { | ||
| 72 | if (c.depth) { | ||
| 73 | D3D12_DEPTH_STENCIL_VIEW_DESC view{}; | ||
| 74 | view.Format = c.view; | ||
| 75 | view.ViewDimension = msaa ? D3D12_DSV_DIMENSION_TEXTURE2DMSARRAY : D3D12_DSV_DIMENSION_TEXTURE2DARRAY; | ||
| 76 | if (msaa) view.Texture2DMSArray = {view_first, view_count}; | ||
| 77 | else view.Texture2DArray = {view_mip, view_first, view_count}; | ||
| 78 | device->CreateDepthStencilView(texture.p, &view, slot); | ||
| 79 | run.list->ClearDepthStencilView(slot, D3D12_CLEAR_FLAG_DEPTH, value, 0, 0, nullptr); | ||
| 80 | } else { | ||
| 81 | D3D12_RENDER_TARGET_VIEW_DESC view{}; | ||
| 82 | view.Format = c.view; | ||
| 83 | view.ViewDimension = msaa ? D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY : D3D12_RTV_DIMENSION_TEXTURE2DARRAY; | ||
| 84 | if (msaa) view.Texture2DMSArray = {view_first, view_count}; | ||
| 85 | else view.Texture2DArray = {view_mip, view_first, view_count, 0}; | ||
| 86 | device->CreateRenderTargetView(texture.p, &view, slot); | ||
| 87 | const FLOAT colour[4] = {value, value, value, value}; | ||
| 88 | run.list->ClearRenderTargetView(slot, colour, 0, nullptr); | ||
| 89 | } | ||
| 90 | }; | ||
| 91 | for (UINT slice = 0; slice < kSlices; ++slice) | ||
| 92 | for (UINT level = 0; level < desc.MipLevels; ++level) clear(level, slice, 1, 0.0f); | ||
| 93 | std::vector<std::uint8_t> counted; | ||
| 94 | if (by_descriptor) { | ||
| 95 | clear(mip, first, kSlices - first, 0.0f); | ||
| 96 | const auto* at = reinterpret_cast<const std::uint8_t*>(slot.ptr); | ||
| 97 | counted.assign(at, at + device->GetDescriptorHandleIncrementSize(heap_desc.Type)); | ||
| 98 | } | ||
| 99 | clear(mip, first, count, 1.0f); | ||
| 100 | if (by_descriptor) { | ||
| 101 | if (std::memcmp(counted.data(), reinterpret_cast<const void*>(slot.ptr), counted.size())) | ||
| 102 | return "the descriptor is not the one of the view that counts the remaining slices"; | ||
| 103 | return run.submit(); | ||
| 104 | } | ||
| 105 | |||
| 106 | if (msaa) { | ||
| 107 | run.barrier(texture.p, written, D3D12_RESOURCE_STATE_RESOLVE_SOURCE); | ||
| 108 | for (UINT slice = 0; slice < kSlices; ++slice) { | ||
| 109 | if (c.depth) | ||
| 110 | list1->ResolveSubresourceRegion(resolved.p, slice, 0, 0, texture.p, slice, nullptr, c.view, | ||
| 111 | D3D12_RESOLVE_MODE_MIN); | ||
| 112 | else | ||
| 113 | run.list->ResolveSubresource(resolved.p, slice, texture.p, slice, c.view); | ||
| 114 | } | ||
| 115 | run.barrier(resolved.p, D3D12_RESOURCE_STATE_RESOLVE_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE); | ||
| 116 | } else { | ||
| 117 | run.barrier(texture.p, written, D3D12_RESOURCE_STATE_COPY_SOURCE); | ||
| 118 | } | ||
| 119 | for (UINT i = 0; i < n; ++i) { | ||
| 120 | const auto dst = copycmp::foot_loc(readback.p, placed[i]); | ||
| 121 | const auto src = copycmp::sub_loc(msaa ? resolved.p : texture.p, i); | ||
| 122 | run.list->CopyTextureRegion(&dst, 0, 0, 0, &src, nullptr); | ||
| 123 | } | ||
| 124 | if (std::string error = run.submit(); !error.empty()) return error; | ||
| 125 | |||
| 126 | void* mapped = nullptr; | ||
| 127 | if (FAILED(readback->Map(0, nullptr, &mapped)) || !mapped) return "Map failed"; | ||
| 128 | const auto* bytes = static_cast<const std::uint8_t*>(mapped); | ||
| 129 | reached = 0; | ||
| 130 | std::string error; | ||
| 131 | for (UINT i = 0; i < n && error.empty(); ++i) { | ||
| 132 | // One, in every format here, has a byte that is not zero in each texel; zero has none. | ||
| 133 | const size_t texel = size_t(row_bytes[i]) / placed[i].Footprint.Width; | ||
| 134 | size_t ones = 0, texels = 0; | ||
| 135 | for (UINT row = 0; row < rows[i]; ++row) | ||
| 136 | for (UINT x = 0; x < placed[i].Footprint.Width; ++x, ++texels) { | ||
| 137 | const std::uint8_t* at = | ||
| 138 | bytes + placed[i].Offset + size_t(row) * placed[i].Footprint.RowPitch + x * texel; | ||
| 139 | ones += std::any_of(at, at + texel, [](std::uint8_t b) { return b != 0; }); | ||
| 140 | } | ||
| 141 | if (ones == texels) reached |= 1u << i; | ||
| 142 | else if (ones) error = "subresource " + std::to_string(i) + " is partly cleared"; | ||
| 143 | } | ||
| 144 | readback->Unmap(0, nullptr); | ||
| 145 | return error; | ||
| 146 | } | ||
| 147 | |||
| 148 | std::string slices_of(std::uint32_t reached, UINT mips) { | ||
| 149 | std::string text; | ||
| 150 | for (UINT i = 0; i < mips * kSlices; ++i) | ||
| 151 | if (reached & (1u << i)) text += " " + std::to_string(i / mips) + "." + std::to_string(i % mips); | ||
| 152 | return text.empty() ? " none" : text; // slice.mip | ||
| 153 | } | ||
| 154 | } // namespace | ||
| 155 | |||
| 156 | int main() { | ||
| 157 | vktest::Device vk; | ||
| 158 | const auto status = vk.initialize(); | ||
| 159 | if (status == vktest::DeviceStatus::unavailable) return 77; // no Vulkan GPU: ctest skips | ||
| 160 | if (status != vktest::DeviceStatus::ready) return 1; | ||
| 161 | Ptr<ID3D12Device> ours; | ||
| 162 | rt::d3d12::VulkanDeviceInfo info{}; | ||
| 163 | info.get_instance_proc = vk.instance_proc; | ||
| 164 | info.instance = vk.instance; | ||
| 165 | info.physical = vk.physical; | ||
| 166 | info.device = vk.device; | ||
| 167 | info.queue = vk.queue; | ||
| 168 | info.queue_family = vk.family; | ||
| 169 | if (FAILED(rt::d3d12::create_vulkan_device(info, IID_PPV_ARGS(&ours.p)))) return 1; | ||
| 170 | |||
| 171 | // The references: the host's D3D12 on the layer's adapter (by LUID), and WARP. | ||
| 172 | struct Host { | ||
| 173 | std::string name; | ||
| 174 | Ptr<ID3D12Device> device; | ||
| 175 | bool warp = false; | ||
| 176 | }; | ||
| 177 | Host hosts[2]; | ||
| 178 | if (!copycmp::host_is_wine()) { | ||
| 179 | VkPhysicalDeviceIDProperties id{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES}; | ||
| 180 | VkPhysicalDeviceProperties2 properties{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, &id}; | ||
| 181 | vk.instance_fn<PFN_vkGetPhysicalDeviceProperties2>("vkGetPhysicalDeviceProperties2")(vk.physical, &properties); | ||
| 182 | LUID luid{}; | ||
| 183 | std::memcpy(&luid, id.deviceLUID, sizeof(luid)); | ||
| 184 | if (!id.deviceLUIDValid || !copycmp::try_create_host(hosts[0].device, hosts[0].name, &luid)) | ||
| 185 | std::printf("no host D3D12 device on the layer's adapter: compared with WARP only\n"); | ||
| 186 | Ptr<IDXGIFactory4> factory; | ||
| 187 | Ptr<IDXGIAdapter> adapter; | ||
| 188 | if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory.p))) || | ||
| 189 | FAILED(factory->EnumWarpAdapter(IID_PPV_ARGS(&adapter.p))) || | ||
| 190 | FAILED(D3D12CreateDevice(adapter.p, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&hosts[1].device.p)))) { | ||
| 191 | std::fprintf(stderr, "WARP reference unavailable\n"); | ||
| 192 | return 1; | ||
| 193 | } | ||
| 194 | hosts[1].name = "WARP"; | ||
| 195 | hosts[1].warp = true; | ||
| 196 | } | ||
| 197 | |||
| 198 | constexpr DXGI_FORMAT rgba8 = DXGI_FORMAT_R8G8B8A8_UNORM, depth32 = DXGI_FORMAT_D32_FLOAT; | ||
| 199 | const Case cases[] = { | ||
| 200 | {"RTV R8G8B8A8_UNORM", false, rgba8, rgba8, 1}, | ||
| 201 | {"RTV R8G8B8A8_UNORM of TYPELESS", false, DXGI_FORMAT_R8G8B8A8_TYPELESS, rgba8, 1}, | ||
| 202 | {"RTV R16G16B16A16_FLOAT", false, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, 1}, | ||
| 203 | {"DSV D32_FLOAT", true, depth32, depth32, 1}, | ||
| 204 | {"RTV R8G8B8A8_UNORM 4x", false, rgba8, rgba8, 4}, | ||
| 205 | {"RTV R8G8B8A8_UNORM of TYPELESS 4x", false, DXGI_FORMAT_R8G8B8A8_TYPELESS, rgba8, 4}, | ||
| 206 | {"DSV D32_FLOAT 4x", true, depth32, depth32, 4}, | ||
| 207 | }; | ||
| 208 | unsigned failures = 0, compared = 0, refused = 0; | ||
| 209 | for (const Case& c : cases) { | ||
| 210 | const UINT mips = c.samples > 1 ? 1 : 3; | ||
| 211 | // Every slice from the first on, in the view's mip. | ||
| 212 | for (const UINT first : {0u, 1u, 3u}) { | ||
| 213 | const UINT mip = c.samples > 1 ? 0 : std::min(first, 2u); | ||
| 214 | std::uint32_t expected = 0; | ||
| 215 | for (UINT slice = first; slice < kSlices; ++slice) expected |= 1u << (mip + slice * mips); | ||
| 216 | const auto check = [&](ID3D12Device* device, bool is_ours, const char* who) { | ||
| 217 | copycmp::Run run; | ||
| 218 | std::uint32_t reached = 0; | ||
| 219 | std::string error = run.init(device, is_ours) ? "" : "no queue or list"; | ||
| 220 | if (error.empty()) { | ||
| 221 | run.begin(); | ||
| 222 | const bool by_descriptor = is_ours && c.depth && c.samples > 1; | ||
| 223 | error = clear_through(run, c, mip, first, UINT_MAX, reached, by_descriptor); | ||
| 224 | if (by_descriptor && error.empty()) reached = expected; | ||
| 225 | } | ||
| 226 | if (error.empty() && reached == expected) return; | ||
| 227 | ++failures; | ||
| 228 | std::fprintf(stderr, "%s, mip %u, first slice %u, ArraySize -1, on %s: %s%s; expected slice.mip%s\n", | ||
| 229 | c.name, mip, first, who, error.empty() ? "cleared slice.mip" : error.c_str(), | ||
| 230 | error.empty() ? slices_of(reached, mips).c_str() : "", slices_of(expected, mips).c_str()); | ||
| 231 | }; | ||
| 232 | check(ours.p, true, "the layer"); | ||
| 233 | for (const Host& host : hosts) { | ||
| 234 | if (!host.device.p || (host.warp && c.depth && c.samples > 1)) continue; | ||
| 235 | check(host.device.p, false, host.name.c_str()); | ||
| 236 | ++compared; | ||
| 237 | } | ||
| 238 | } | ||
| 239 | // What the host's debug layer refuses, the layer refuses: the list fails at Close or when it runs. | ||
| 240 | struct Range { UINT first, count; }; | ||
| 241 | for (const Range range : {Range{kSlices, UINT_MAX}, Range{UINT_MAX, UINT_MAX}, Range{0, 0}, Range{3, 2}, | ||
| 242 | Range{0, kSlices + 1}, Range{1, UINT_MAX - 1}}) { | ||
| 243 | copycmp::Run run; | ||
| 244 | std::uint32_t reached = 0; | ||
| 245 | if (!run.init(ours.p, true)) return 1; | ||
| 246 | run.begin(); | ||
| 247 | const std::string error = clear_through(run, c, 0, range.first, range.count, reached); | ||
| 248 | if (run.refused) { | ||
| 249 | ++refused; | ||
| 250 | continue; | ||
| 251 | } | ||
| 252 | ++failures; | ||
| 253 | std::fprintf(stderr, "%s, first slice %d, ArraySize %d: the layer %s\n", c.name, int(range.first), | ||
| 254 | int(range.count), error.empty() ? "ran the clear" : error.c_str()); | ||
| 255 | } | ||
| 256 | } | ||
| 257 | if (hosts[0].device.p) std::printf("host reference: %s, and WARP\n", hosts[0].name.c_str()); | ||
| 258 | std::printf("ArraySize -1 views: %u clears on the layer, %u on the host; %u out-of-range views refused; " | ||
| 259 | "%u failures\n", | ||
| 260 | unsigned(std::size(cases)) * 3, compared, refused, failures); | ||
| 261 | return failures || vk.validation_errors() ? 1 : 0; | ||
| 262 | } | ||