upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 01:38:14 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 01:38:14 -0500
commit86ef2454a81ecfc64bc74b6fa251042e882c8bd4 (patch)
tree508d3727c31459b97b8880b31f1cba88cad3796b /runtime
parent586c6352538407e2ca18b582b305494ab4a00a7b (diff)
parent55bf9d0328f84657486395b6d56862c6faf2e3dc (diff)
Merge pull request #1069 from undeadhuman37
Diffstat (limited to 'runtime')
-rw-r--r--runtime/shims/d3d12_vulkan_device.cpp20
-rw-r--r--runtime/test/d3d12_vulkan_device_test.cpp67
2 files changed, 85 insertions, 2 deletions
diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp
index a2fed2f54..d9ce3943a 100644
--- a/runtime/shims/d3d12_vulkan_device.cpp
+++ b/runtime/shims/d3d12_vulkan_device.cpp
@@ -2397,7 +2397,15 @@ public:
2397 if (!desc || !xr_bias_compatible(*desc)) return fail(); 2397 if (!desc || !xr_bias_compatible(*desc)) return fail();
2398 const auto align = [](UINT64 value, UINT64 to) { return (value + to - 1) / to * to; }; 2398 const auto align = [](UINT64 value, UINT64 to) { return (value + to - 1) / to * to; };
2399 if (desc->Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) { 2399 if (desc->Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) {
2400 if (first != 0 || count != 1) return fail(); 2400 // The PC runtime refuses any buffer field that isn't its one valid value (all measured on WARP, Width,
2401 // Height, Format, MipLevels 0, Layout and Count 0 also on an NVIDIA GPU). It doesn't look at Flags, so a
2402 // buffer with the render-target flag still gets its footprint (D3D-122).
2403 if (first != 0 || count != 1 || !desc->Width || desc->Height != 1 || desc->DepthOrArraySize != 1 ||
2404 desc->MipLevels != 1 || desc->Format != DXGI_FORMAT_UNKNOWN ||
2405 desc->Layout != D3D12_TEXTURE_LAYOUT_ROW_MAJOR || desc->SampleDesc.Count != 1 ||
2406 desc->SampleDesc.Quality != 0 ||
2407 (desc->Alignment && desc->Alignment != D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT))
2408 return fail();
2401 if (layouts) layouts[0] = {base, {DXGI_FORMAT_UNKNOWN, UINT(desc->Width), 1, 1, 2409 if (layouts) layouts[0] = {base, {DXGI_FORMAT_UNKNOWN, UINT(desc->Width), 1, 1,
2402 UINT(align(desc->Width, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT))}}; 2410 UINT(align(desc->Width, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT))}};
2403 if (rows) rows[0] = 1; 2411 if (rows) rows[0] = 1;
@@ -2412,6 +2420,16 @@ public:
2412 return fail(); 2420 return fail();
2413 } 2421 }
2414 if (one_d && desc->Height != 1) return fail(); 2422 if (one_d && desc->Height != 1) return fail();
2423 // Structural checks only, as measured on the PC runtime (D3D-122). Not allocation()'s: the footprint path
2424 // accepts extra mips, 2D ROW_MAJOR and Quality > 0 at one sample, and extent limits, alignment and
2425 // multisample quality differ between adapters, so those stay unchecked.
2426 const UINT samples = desc->SampleDesc.Count;
2427 const bool multisample_ok = desc->Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE2D && desc->MipLevels == 1 &&
2428 desc->Layout != D3D12_TEXTURE_LAYOUT_ROW_MAJOR && !(samples & (samples - 1)) &&
2429 (desc->Flags & (D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET |
2430 D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL));
2431 if (!desc->Width || !desc->Height || !desc->DepthOrArraySize || !samples || (samples > 1 && !multisample_ok))
2432 return fail();
2415 const Format format = texture_storage_format(desc->Format, true); // typeless depth families are planar either way 2433 const Format format = texture_storage_format(desc->Format, true); // typeless depth families are planar either way
2416 UINT mips = desc->MipLevels; 2434 UINT mips = desc->MipLevels;
2417 const UINT depth = volume ? desc->DepthOrArraySize : 1; 2435 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 a97e2fad2..a8d6e32b4 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) {
427 return mismatches; 427 return mismatches;
428} 428}
429 429
430// D3D-122: descriptions GetCopyableFootprints must refuse (false) or answer (true), as the PC runtime does. All were
431// measured on WARP. Also on an NVIDIA GPU: texture Width/Height 0, Count 0, Count 4 without a render-target or depth
432// flag, Count 3; buffer Width 0, Height 2, Format, MipLevels 0, Layout, Count 0; and the buffer render-target, extra
433// mip, ROW_MAJOR and Quality 1 controls. compare_footprints checks them against the host, the main test on their own.
434std::vector<std::pair<D3D12_RESOURCE_DESC, bool>> footprint_validity_cases() {
435 const auto rgba = DXGI_FORMAT_R8G8B8A8_UNORM;
436 const auto rt = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
437 std::vector<std::pair<D3D12_RESOURCE_DESC, bool>> cases;
438 const auto add = [&](D3D12_RESOURCE_DESC d, bool valid, auto&& change) {
439 change(d);
440 cases.push_back({d, valid});
441 };
442 const auto buffer = buffer_desc(256);
443 add(buffer, false, [](auto& d) { d.Width = 0; });
444 add(buffer, false, [](auto& d) { d.Height = 2; });
445 add(buffer, false, [](auto& d) { d.DepthOrArraySize = 2; });
446 add(buffer, false, [](auto& d) { d.MipLevels = 0; });
447 add(buffer, false, [](auto& d) { d.MipLevels = 2; });
448 add(buffer, false, [&](auto& d) { d.Format = rgba; });
449 add(buffer, false, [](auto& d) { d.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; });
450 add(buffer, false, [](auto& d) { d.SampleDesc.Count = 0; });
451 add(buffer, false, [](auto& d) { d.SampleDesc.Count = 2; });
452 add(buffer, false, [](auto& d) { d.SampleDesc.Quality = 1; });
453 add(buffer, false, [](auto& d) { d.Alignment = 4096; });
454 add(buffer, true, [&](auto& d) { d.Flags = rt; });
455 add(buffer, true, [](auto& d) { d.Alignment = D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT; });
456
457 const auto texture = texture_desc(16, 16, rgba, D3D12_RESOURCE_FLAG_NONE);
458 add(texture, false, [](auto& d) { d.Width = 0; });
459 add(texture, false, [](auto& d) { d.Height = 0; });
460 add(texture, false, [](auto& d) { d.DepthOrArraySize = 0; });
461 add(texture, false, [](auto& d) { d.SampleDesc.Count = 0; });
462 add(texture, false, [](auto& d) { d.SampleDesc.Count = 4; }); // no render-target or depth flag
463 add(texture, false, [](auto& d) { d.SampleDesc.Count = 4, d.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; });
464 add(texture, false, [&](auto& d) { d.SampleDesc.Count = 3, d.Flags = rt; });
465 add(texture, false, [&](auto& d) { d.SampleDesc.Count = 4, d.Flags = rt, d.MipLevels = 2; });
466 add(texture, false, [&](auto& d) { d.SampleDesc.Count = 4, d.Flags = rt, d.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; });
467 add(texture, true, [&](auto& d) { d.SampleDesc.Count = 4, d.Flags = rt; });
468 add(texture, true, [](auto& d) { d.MipLevels = 9; }); // past the full chain
469 add(texture, true, [](auto& d) { d.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; });
470 add(texture, true, [](auto& d) { d.SampleDesc.Quality = 1; });
471 add(texture_desc(16, 16, DXGI_FORMAT_D32_FLOAT, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL), true,
472 [](auto& d) { d.SampleDesc.Count = 4; });
473
474 add(line_desc(16, 1, 1, rgba), false, [](auto& d) { d.Width = 0; });
475 add(line_desc(16, 1, 1, rgba), false, [&](auto& d) { d.SampleDesc.Count = 2, d.Flags = rt; });
476 add(volume_desc(1), false, [](auto& d) { d.DepthOrArraySize = 0; });
477 add(volume_desc(1), false, [](auto& d) { d.Height = 0; });
478 add(volume_desc(1), false, [&](auto& d) { d.SampleDesc.Count = 2, d.Flags = rt; });
479 return cases;
480}
481
430// GetCopyableFootprints must match the PC runtime's exactly, since applications size and fill upload buffers from 482// GetCopyableFootprints must match the PC runtime's exactly, since applications size and fill upload buffers from
431// it. Unaligned block-compressed cases are skipped when the host runtime cannot answer them, so the rest still 483// it. Unaligned block-compressed cases are skipped when the host runtime cannot answer them, so the rest still
432// run. Returns the number of mismatches, or -1 when the host has no D3D12 device to compare with. 484// 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) {
439 D3D12_RESOURCE_DESC desc; 491 D3D12_RESOURCE_DESC desc;
440 UINT subresources; 492 UINT subresources;
441 }; 493 };
442 const Case cases[] = { 494 std::vector<Case> cases = {
443 {volume_desc(5), 5}, 495 {volume_desc(5), 5},
444 {line_desc(13, 4, 1, DXGI_FORMAT_R8G8B8A8_UNORM), 4}, 496 {line_desc(13, 4, 1, DXGI_FORMAT_R8G8B8A8_UNORM), 4},
445 {line_desc(5, 3, 2, DXGI_FORMAT_R8G8B8A8_UNORM), 6}, 497 {line_desc(5, 3, 2, DXGI_FORMAT_R8G8B8A8_UNORM), 6},
@@ -472,6 +524,7 @@ int compare_footprints(ID3D12Device* ours) {
472 {texture_desc(16, 16, DXGI_FORMAT_R8G8_UINT, D3D12_RESOURCE_FLAG_NONE, 3), 3}, 524 {texture_desc(16, 16, DXGI_FORMAT_R8G8_UINT, D3D12_RESOURCE_FLAG_NONE, 3), 3},
473 {texture_desc(16, 16, DXGI_FORMAT_R8G8_SINT, D3D12_RESOURCE_FLAG_NONE, 3), 3}, 525 {texture_desc(16, 16, DXGI_FORMAT_R8G8_SINT, D3D12_RESOURCE_FLAG_NONE, 3), 3},
474 }; 526 };
527 for (const auto& c : footprint_validity_cases()) cases.push_back({c.first, 1});
475 int mismatches = 0; 528 int mismatches = 0;
476 for (const Case& c : cases) { 529 for (const Case& c : cases) {
477 if (!unaligned_blocks && uses_unaligned_blocks(c.desc)) { 530 if (!unaligned_blocks && uses_unaligned_blocks(c.desc)) {
@@ -1956,6 +2009,18 @@ int main() {
1956 if (footprint_mismatches < 0) 2009 if (footprint_mismatches < 0)
1957 std::printf("GetCopyableFootprints: no host D3D12 device to compare with, skipped\n"); 2010 std::printf("GetCopyableFootprints: no host D3D12 device to compare with, skipped\n");
1958 EXPECT(footprint_mismatches <= 0); 2011 EXPECT(footprint_mismatches <= 0);
2012 {
2013 // D3D-122: the same refusals without a host device (CI's llvmpipe), so they can't regress unseen.
2014 const auto cases = footprint_validity_cases();
2015 for (size_t i = 0; i < cases.size(); ++i) {
2016 UINT64 total = 0;
2017 device->GetCopyableFootprints(&cases[i].first, 0, 1, 0, nullptr, nullptr, nullptr, &total);
2018 if ((total != UINT64_MAX) != cases[i].second)
2019 std::fprintf(stderr, "footprint validity case %zu: total %llu, expected %s\n", i,
2020 (unsigned long long)total, cases[i].second ? "a footprint" : "the failure answer");
2021 EXPECT((total != UINT64_MAX) == cases[i].second);
2022 }
2023 }
1959 2024
1960 // Shader model and root signature (D3D-86): the answers are only useful if the game can rely on them, so 2025 // Shader model and root signature (D3D-86): the answers are only useful if the game can rely on them, so
1961 // pin both the ceiling and the refusal cases rather than just comparing with the host. 2026 // pin both the ceiling and the refusal cases rather than just comparing with the host.