diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index 8adb86fff..4a9e85731 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -2246,7 +2246,15 @@ class Device final if (!desc || !xr_bias_compatible(*desc)) return fail(); const auto align = [](UINT64 value, UINT64 to) { return (value + to - 1) / to * to; }; if (desc->Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) { - if (first != 0 || count != 1) return fail(); + // The PC runtime refuses any buffer field that isn't its one valid value (all measured on WARP, Width, + // Height, Format, MipLevels 0, Layout and Count 0 also on an NVIDIA GPU). It doesn't look at Flags, so a + // buffer with the render-target flag still gets its footprint (D3D-122). + if (first != 0 || count != 1 || !desc->Width || desc->Height != 1 || desc->DepthOrArraySize != 1 || + desc->MipLevels != 1 || desc->Format != DXGI_FORMAT_UNKNOWN || + desc->Layout != D3D12_TEXTURE_LAYOUT_ROW_MAJOR || desc->SampleDesc.Count != 1 || + desc->SampleDesc.Quality != 0 || + (desc->Alignment && desc->Alignment != D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT)) + return fail(); if (layouts) layouts[0] = {base, {DXGI_FORMAT_UNKNOWN, UINT(desc->Width), 1, 1, UINT(align(desc->Width, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT))}}; if (rows) rows[0] = 1; @@ -2261,6 +2269,16 @@ class Device final return fail(); } if (one_d && desc->Height != 1) return fail(); + // Structural checks only, as measured on the PC runtime (D3D-122). Not allocation()'s: the footprint path + // accepts extra mips, 2D ROW_MAJOR and Quality > 0 at one sample, and extent limits, alignment and + // multisample quality differ between adapters, so those stay unchecked. + const UINT samples = desc->SampleDesc.Count; + const bool multisample_ok = desc->Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE2D && desc->MipLevels == 1 && + desc->Layout != D3D12_TEXTURE_LAYOUT_ROW_MAJOR && !(samples & (samples - 1)) && + (desc->Flags & (D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET | + D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL)); + if (!desc->Width || !desc->Height || !desc->DepthOrArraySize || !samples || (samples > 1 && !multisample_ok)) + return fail(); const Format format = texture_storage_format(desc->Format, true); // typeless depth families are planar either way UINT mips = desc->MipLevels; const UINT depth = volume ? desc->DepthOrArraySize : 1; diff --git a/runtime/test/d3d12_vulkan_device_test.cpp b/runtime/test/d3d12_vulkan_device_test.cpp index 7e6650a42..6b39fb2f9 100644 --- a/runtime/test/d3d12_vulkan_device_test.cpp +++ b/runtime/test/d3d12_vulkan_device_test.cpp @@ -427,6 +427,58 @@ int compare_format_info(ID3D12Device* ours, const vktest::Device& vk) { return mismatches; } +// D3D-122: descriptions GetCopyableFootprints must refuse (false) or answer (true), as the PC runtime does. All were +// measured on WARP. Also on an NVIDIA GPU: texture Width/Height 0, Count 0, Count 4 without a render-target or depth +// flag, Count 3; buffer Width 0, Height 2, Format, MipLevels 0, Layout, Count 0; and the buffer render-target, extra +// mip, ROW_MAJOR and Quality 1 controls. compare_footprints checks them against the host, the main test on their own. +std::vector> footprint_validity_cases() { + const auto rgba = DXGI_FORMAT_R8G8B8A8_UNORM; + const auto rt = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; + std::vector> cases; + const auto add = [&](D3D12_RESOURCE_DESC d, bool valid, auto&& change) { + change(d); + cases.push_back({d, valid}); + }; + const auto buffer = buffer_desc(256); + add(buffer, false, [](auto& d) { d.Width = 0; }); + add(buffer, false, [](auto& d) { d.Height = 2; }); + add(buffer, false, [](auto& d) { d.DepthOrArraySize = 2; }); + add(buffer, false, [](auto& d) { d.MipLevels = 0; }); + add(buffer, false, [](auto& d) { d.MipLevels = 2; }); + add(buffer, false, [&](auto& d) { d.Format = rgba; }); + add(buffer, false, [](auto& d) { d.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; }); + add(buffer, false, [](auto& d) { d.SampleDesc.Count = 0; }); + add(buffer, false, [](auto& d) { d.SampleDesc.Count = 2; }); + add(buffer, false, [](auto& d) { d.SampleDesc.Quality = 1; }); + add(buffer, false, [](auto& d) { d.Alignment = 4096; }); + add(buffer, true, [&](auto& d) { d.Flags = rt; }); + add(buffer, true, [](auto& d) { d.Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT; }); + + const auto texture = texture_desc(16, 16, rgba, D3D12_RESOURCE_FLAG_NONE); + add(texture, false, [](auto& d) { d.Width = 0; }); + add(texture, false, [](auto& d) { d.Height = 0; }); + add(texture, false, [](auto& d) { d.DepthOrArraySize = 0; }); + add(texture, false, [](auto& d) { d.SampleDesc.Count = 0; }); + add(texture, false, [](auto& d) { d.SampleDesc.Count = 4; }); // no render-target or depth flag + add(texture, false, [](auto& d) { d.SampleDesc.Count = 4, d.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; }); + add(texture, false, [&](auto& d) { d.SampleDesc.Count = 3, d.Flags = rt; }); + add(texture, false, [&](auto& d) { d.SampleDesc.Count = 4, d.Flags = rt, d.MipLevels = 2; }); + add(texture, false, [&](auto& d) { d.SampleDesc.Count = 4, d.Flags = rt, d.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; }); + add(texture, true, [&](auto& d) { d.SampleDesc.Count = 4, d.Flags = rt; }); + add(texture, true, [](auto& d) { d.MipLevels = 9; }); // past the full chain + add(texture, true, [](auto& d) { d.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; }); + add(texture, true, [](auto& d) { d.SampleDesc.Quality = 1; }); + add(texture_desc(16, 16, DXGI_FORMAT_D32_FLOAT, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL), true, + [](auto& d) { d.SampleDesc.Count = 4; }); + + add(line_desc(16, 1, 1, rgba), false, [](auto& d) { d.Width = 0; }); + add(line_desc(16, 1, 1, rgba), false, [&](auto& d) { d.SampleDesc.Count = 2, d.Flags = rt; }); + add(volume_desc(1), false, [](auto& d) { d.DepthOrArraySize = 0; }); + add(volume_desc(1), false, [](auto& d) { d.Height = 0; }); + add(volume_desc(1), false, [&](auto& d) { d.SampleDesc.Count = 2, d.Flags = rt; }); + return cases; +} + // GetCopyableFootprints must match the PC runtime's exactly, since applications size and fill upload buffers from // it. Unaligned block-compressed cases are skipped when the host runtime cannot answer them, so the rest still // run. Returns the number of mismatches, or -1 when the host has no D3D12 device to compare with. @@ -439,7 +491,7 @@ int compare_footprints(ID3D12Device* ours) { D3D12_RESOURCE_DESC desc; UINT subresources; }; - const Case cases[] = { + std::vector cases = { {volume_desc(5), 5}, {line_desc(13, 4, 1, DXGI_FORMAT_R8G8B8A8_UNORM), 4}, {line_desc(5, 3, 2, DXGI_FORMAT_R8G8B8A8_UNORM), 6}, @@ -472,6 +524,7 @@ int compare_footprints(ID3D12Device* ours) { {texture_desc(16, 16, DXGI_FORMAT_R8G8_UINT, D3D12_RESOURCE_FLAG_NONE, 3), 3}, {texture_desc(16, 16, DXGI_FORMAT_R8G8_SINT, D3D12_RESOURCE_FLAG_NONE, 3), 3}, }; + for (const auto& c : footprint_validity_cases()) cases.push_back({c.first, 1}); int mismatches = 0; for (const Case& c : cases) { if (!unaligned_blocks && uses_unaligned_blocks(c.desc)) { @@ -1945,6 +1998,18 @@ int main() { if (footprint_mismatches < 0) std::printf("GetCopyableFootprints: no host D3D12 device to compare with, skipped\n"); EXPECT(footprint_mismatches <= 0); + { + // D3D-122: the same refusals without a host device (CI's llvmpipe), so they can't regress unseen. + const auto cases = footprint_validity_cases(); + for (size_t i = 0; i < cases.size(); ++i) { + UINT64 total = 0; + device->GetCopyableFootprints(&cases[i].first, 0, 1, 0, nullptr, nullptr, nullptr, &total); + if ((total != UINT64_MAX) != cases[i].second) + std::fprintf(stderr, "footprint validity case %zu: total %llu, expected %s\n", i, + (unsigned long long)total, cases[i].second ? "a footprint" : "the failure answer"); + EXPECT((total != UINT64_MAX) == cases[i].second); + } + } // Shader model and root signature (D3D-86): the answers are only useful if the game can rely on them, so // pin both the ceiling and the refusal cases rather than just comparing with the host.