diff options
| author | marquezini <felipemarquesini10@gmail.com> | 2026-11-22 14:12:39 -0300 |
|---|---|---|
| committer | marquezini <felipemarquesini10@gmail.com> | 2026-11-22 14:12:39 -0300 |
| commit | 4e596d1a6dd844366d76c6e459a9f04c1ecafb1a (patch) | |
| tree | 45f008d59d21d5d814be016aaab18389471fb402 /runtime/test/d3d12_vulkan_device_test.cpp | |
| parent | 2bee23fe7940a186ea9d487394470893a9a33928 (diff) | |
d3d12_vulkan_device_test: accept the layer's nearest-even tie on its own adapter
The placed plain clear (D3D-90/D3D-221) is compared byte for byte with the host
D3D12 runtime when the host is the layer's own adapter. Its 0.5 * 255 = 127.5 is
a tie: NVIDIA's D3D12 driver writes 0x7f, WARP and AMD 0x80, and the D3D11.3
spec (3.2.3.6) permits either within 0.6 ULP. With this branch the layer rounds
normalised clear values itself, to nearest even, so on an NVIDIA adapter it
writes 0x80 and the exact same-adapter comparison failed (RTX 5070, 621.24).
On the same adapter a differing plain byte is now accepted only when it is
exactly the nearest-even code and within 0.6 ULP; every other difference still
fails, and the SRGB-cast comparison is unchanged.
Diffstat (limited to 'runtime/test/d3d12_vulkan_device_test.cpp')
| -rw-r--r-- | runtime/test/d3d12_vulkan_device_test.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/runtime/test/d3d12_vulkan_device_test.cpp b/runtime/test/d3d12_vulkan_device_test.cpp index 91d3244ce..4e43049b8 100644 --- a/runtime/test/d3d12_vulkan_device_test.cpp +++ b/runtime/test/d3d12_vulkan_device_test.cpp | |||
| @@ -1621,6 +1621,13 @@ bool within_06_ulp(std::uint8_t a, std::uint8_t b, double ideal) { | |||
| 1621 | return std::abs(double(a) - ideal) <= 0.6 && std::abs(double(b) - ideal) <= 0.6; | 1621 | return std::abs(double(a) - ideal) <= 0.6 && std::abs(double(b) - ideal) <= 0.6; |
| 1622 | } | 1622 | } |
| 1623 | 1623 | ||
| 1624 | // The code nearest to `ideal`, a tie going to the even one: what the layer writes for a normalised clear (#521's | ||
| 1625 | // quantize_unorm), whichever way the GPU's own driver rounds the tie. | ||
| 1626 | double nearest_even_code(double ideal) { | ||
| 1627 | const double r = std::floor(ideal + 0.5); | ||
| 1628 | return r - ideal == 0.5 && std::fmod(r, 2.0) != 0.0 ? r - 1.0 : r; | ||
| 1629 | } | ||
| 1630 | |||
| 1624 | bool create_host_device_for_physical(VkInstance instance, VkPhysicalDevice physical, | 1631 | bool create_host_device_for_physical(VkInstance instance, VkPhysicalDevice physical, |
| 1625 | PFN_vkGetInstanceProcAddr instance_proc, Ref<ID3D12Device>& host, | 1632 | PFN_vkGetInstanceProcAddr instance_proc, Ref<ID3D12Device>& host, |
| 1626 | std::string& adapter_name) { | 1633 | std::string& adapter_name) { |
| @@ -6418,6 +6425,9 @@ int main() { | |||
| 6418 | // WARP and NVIDIA's Vulkan driver give 188, Intel's Vulkan driver 187 (UHD 770 101.7092), both within | 6425 | // WARP and NVIDIA's Vulkan driver give 188, Intel's Vulkan driver 187 (UHD 770 101.7092), both within |
| 6419 | // 0.6 ULP. On the layer's own adapter (same LUID) the comparison stays exact; against another adapter | 6426 | // 0.6 ULP. On the layer's own adapter (same LUID) the comparison stays exact; against another adapter |
| 6420 | // or WARP a byte may differ when both sides are within 0.6 ULP of the ideal value. | 6427 | // or WARP a byte may differ when both sides are within 0.6 ULP of the ideal value. |
| 6428 | // The plain clear's normalised values are rounded by the layer itself (nearest even, WARP's and AMD's | ||
| 6429 | // code), so on its own NVIDIA adapter the tie byte may be the step above the driver's: accepted only | ||
| 6430 | // when it is exactly that nearest-even code and within 0.6 ULP. | ||
| 6421 | const FLOAT clear_value[4] = {0.25f, 0.5f, 0.75f, 1.0f}; // placed_cast_scenario's clear colour | 6431 | const FLOAT clear_value[4] = {0.25f, 0.5f, 0.75f, 1.0f}; // placed_cast_scenario's clear colour |
| 6422 | const auto within_tolerance = [&](std::uint8_t ours_byte, std::uint8_t host_byte, double ideal) { | 6432 | const auto within_tolerance = [&](std::uint8_t ours_byte, std::uint8_t host_byte, double ideal) { |
| 6423 | return !same_adapter && within_06_ulp(ours_byte, host_byte, ideal); | 6433 | return !same_adapter && within_06_ulp(ours_byte, host_byte, ideal); |
| @@ -6430,7 +6440,9 @@ int main() { | |||
| 6430 | const double plain_ideal = c * 255.0; | 6440 | const double plain_ideal = c * 255.0; |
| 6431 | const double srgb_ideal = (i % 4 == 3 ? c : ideal_srgb(c)) * 255.0; // alpha stays linear | 6441 | const double srgb_ideal = (i % 4 == 3 ? c : ideal_srgb(c)) * 255.0; // alpha stays linear |
| 6432 | if (ours[b] != host[b]) { | 6442 | if (ours[b] != host[b]) { |
| 6433 | if (within_tolerance(ours[b], host[b], plain_ideal)) | 6443 | const bool layer_tie = double(ours[b]) == nearest_even_code(plain_ideal) && |
| 6444 | within_06_ulp(ours[b], host[b], plain_ideal); | ||
| 6445 | if (within_tolerance(ours[b], host[b], plain_ideal) || layer_tie) | ||
| 6434 | ++plain_within; | 6446 | ++plain_within; |
| 6435 | else if (differences++ < 8) | 6447 | else if (differences++ < 8) |
| 6436 | std::fprintf(stderr, "placed plain clear row %u byte %u: ours %02x, host %02x\n", row, i, | 6448 | std::fprintf(stderr, "placed plain clear row %u byte %u: ours %02x, host %02x\n", row, i, |