diff options
| author | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 09:15:05 -0500 |
|---|---|---|
| committer | ItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com> | 2026-11-22 09:15:05 -0500 |
| commit | 082190c19b2ca3f595f03354d21a5d85f1453eef (patch) | |
| tree | f5d1fd3b11b26998736f9f8d385025ebfd23c706 /runtime | |
| parent | a9947725088196586f16d3d5d922916e30cbef38 (diff) | |
| parent | ceb244b1248e7d73ce789d0b89cadde06066c223 (diff) | |
Merge pull request #1752 from CowDeV
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/test/d3d12_vulkan_device_test.cpp | 71 |
1 files changed, 50 insertions, 21 deletions
diff --git a/runtime/test/d3d12_vulkan_device_test.cpp b/runtime/test/d3d12_vulkan_device_test.cpp index b79df1e84..65b0d7d51 100644 --- a/runtime/test/d3d12_vulkan_device_test.cpp +++ b/runtime/test/d3d12_vulkan_device_test.cpp | |||
| @@ -1609,6 +1609,15 @@ int compare_feature_support(ID3D12Device* ours) { | |||
| 1609 | 1609 | ||
| 1610 | // Same-adapter host D3D12 device matched by VkPhysicalDeviceIDProperties (LUID first, then PCI IDs), falling back | 1610 | // Same-adapter host D3D12 device matched by VkPhysicalDeviceIDProperties (LUID first, then PCI IDs), falling back |
| 1611 | // to the default adapter. False if the host has no D3D12 device. | 1611 | // to the default adapter. False if the host has no D3D12 device. |
| 1612 | // D3D11.3 spec 3.2.3.8's ideal FLOAT -> SRGB encoding of c in [0, 1], before scaling to the format's maximum. | ||
| 1613 | double ideal_srgb(double c) { return c <= 0.0031308 ? c * 12.92 : 1.055 * std::pow(c, 1.0 / 2.4) - 0.055; } | ||
| 1614 | |||
| 1615 | // Both bytes within 0.6 ULP (on the integer side) of the ideal value: the tolerance spec 3.2.3.6 (FLOAT -> UNORM) | ||
| 1616 | // and 3.2.3.8 (FLOAT -> SRGB) permit, so two drivers may give the codes either side of a near-tie. | ||
| 1617 | bool within_06_ulp(std::uint8_t a, std::uint8_t b, double ideal) { | ||
| 1618 | return std::abs(double(a) - ideal) <= 0.6 && std::abs(double(b) - ideal) <= 0.6; | ||
| 1619 | } | ||
| 1620 | |||
| 1612 | bool create_host_device_for_physical(VkInstance instance, VkPhysicalDevice physical, | 1621 | bool create_host_device_for_physical(VkInstance instance, VkPhysicalDevice physical, |
| 1613 | PFN_vkGetInstanceProcAddr instance_proc, Ref<ID3D12Device>& host, | 1622 | PFN_vkGetInstanceProcAddr instance_proc, Ref<ID3D12Device>& host, |
| 1614 | std::string& adapter_name) { | 1623 | std::string& adapter_name) { |
| @@ -5249,6 +5258,15 @@ int main() { | |||
| 5249 | EXPECT(words[0] == 0 && words[1] == 0 && words[2] == 0 && words[3] == 0); | 5258 | EXPECT(words[0] == 0 && words[1] == 0 && words[2] == 0 && words[3] == 0); |
| 5250 | } | 5259 | } |
| 5251 | 5260 | ||
| 5261 | // The tolerance host_side applies, pinned here so every GPU checks it: its accept side only runs where the | ||
| 5262 | // host rounds differently (Intel's SRGB clear), so a change to it would otherwise stay green elsewhere. | ||
| 5263 | // One code either side of a near-tie is accepted; two codes, or a code past 0.6 ULP, are not. | ||
| 5264 | EXPECT(within_06_ulp(187, 188, ideal_srgb(0.5) * 255.0) && within_06_ulp(127, 128, 127.5)); | ||
| 5265 | EXPECT(!within_06_ulp(186, 188, ideal_srgb(0.5) * 255.0) && !within_06_ulp(126, 128, 127.5)); | ||
| 5266 | EXPECT(!within_06_ulp(224, 225, ideal_srgb(0.75) * 255.0) && | ||
| 5267 | !within_06_ulp(136, 137, ideal_srgb(0.25) * 255.0)); | ||
| 5268 | EXPECT(!within_06_ulp(254, 255, 255.0)); | ||
| 5269 | |||
| 5252 | // The host PC runtime's bytes and refusals: the default adapter when it can cast, WARP otherwise. | 5270 | // The host PC runtime's bytes and refusals: the default adapter when it can cast, WARP otherwise. |
| 5253 | bool compared = false; | 5271 | bool compared = false; |
| 5254 | const char* source = "no host"; | 5272 | const char* source = "no host"; |
| @@ -5258,33 +5276,44 @@ int main() { | |||
| 5258 | if (!placed_cast_scenario(device10, false, host.data())) return false; | 5276 | if (!placed_cast_scenario(device10, false, host.data())) return false; |
| 5259 | if (!placed_cast_refusals(device10, host_refusals)) return false; | 5277 | if (!placed_cast_refusals(device10, host_refusals)) return false; |
| 5260 | unsigned differences = 0; | 5278 | unsigned differences = 0; |
| 5261 | // D3D12 does not pin float -> UNORM at a tie: the D3D11.3 functional spec (3.2.3.6 FLOAT -> UNORM) | 5279 | // D3D12 does not pin float -> UNORM or float -> SRGB to one code: the D3D11.3 functional spec |
| 5262 | // computes c * (2^n - 1) + 0.5 and drops the fraction, but permits a tolerance of 0.6 ULP on the integer | 5280 | // (3.2.3.6 FLOAT -> UNORM, 3.2.3.8 FLOAT -> SRGB) permits a tolerance of 0.6 ULP on the integer side, so |
| 5263 | // side, so a value exactly halfway between two codes (0.5 * 255 = 127.5) may map to either. WARP and AMD | 5281 | // a value near halfway between two codes may map to either. The plain clear's 0.5 * 255 = 127.5 is a |
| 5264 | // give the upper code; NVIDIA's D3D12 driver and its Vulkan driver the lower (RTX 3080 616.64, RTX 3090 | 5282 | // tie: WARP and AMD give the upper code, NVIDIA's D3D12 driver and its Vulkan driver the lower (RTX 3080 |
| 5265 | // 610.88 and RTX 5070 Laptop 617.42). On the layer's own adapter (same LUID) the comparison stays exact; | 5283 | // 616.64, RTX 3090 610.88 and RTX 5070 Laptop 617.42). The SRGB-cast clear's 0.5 encodes to 187.516: |
| 5266 | // against another adapter or WARP the plain clear accepts either code on a tie channel. | 5284 | // WARP and NVIDIA's Vulkan driver give 188, Intel's Vulkan driver 187 (UHD 770 101.7092), both within |
| 5285 | // 0.6 ULP. On the layer's own adapter (same LUID) the comparison stays exact; against another adapter | ||
| 5286 | // or WARP a byte may differ when both sides are within 0.6 ULP of the ideal value. | ||
| 5267 | const FLOAT clear_value[4] = {0.25f, 0.5f, 0.75f, 1.0f}; // placed_cast_scenario's clear colour | 5287 | const FLOAT clear_value[4] = {0.25f, 0.5f, 0.75f, 1.0f}; // placed_cast_scenario's clear colour |
| 5268 | unsigned tie_bytes_other_way = 0; | 5288 | const auto within_tolerance = [&](std::uint8_t ours_byte, std::uint8_t host_byte, double ideal) { |
| 5289 | return !same_adapter && within_06_ulp(ours_byte, host_byte, ideal); | ||
| 5290 | }; | ||
| 5291 | unsigned plain_within = 0, srgb_within = 0; | ||
| 5269 | for (UINT row = 0; row < 4; ++row) | 5292 | for (UINT row = 0; row < 4; ++row) |
| 5270 | for (UINT i = 0; i < 16; ++i) { | 5293 | for (UINT i = 0; i < 16; ++i) { |
| 5271 | const UINT a = row * 256 + i, b = 1024 + row * 256 + i; | 5294 | const UINT a = row * 256 + i, b = 1024 + row * 256 + i; |
| 5272 | const double scaled = double(clear_value[i % 4]) * 255.0; | 5295 | const double c = clear_value[i % 4]; |
| 5273 | const bool tie = !same_adapter && scaled - std::floor(scaled) == 0.5; | 5296 | const double plain_ideal = c * 255.0; |
| 5274 | if (tie && std::abs(int(ours[b]) - int(host[b])) == 1) { | 5297 | const double srgb_ideal = (i % 4 == 3 ? c : ideal_srgb(c)) * 255.0; // alpha stays linear |
| 5275 | ++tie_bytes_other_way; | 5298 | if (ours[b] != host[b]) { |
| 5276 | } else if (ours[b] != host[b] && differences++ < 8) { | 5299 | if (within_tolerance(ours[b], host[b], plain_ideal)) |
| 5277 | std::fprintf(stderr, "placed plain clear row %u byte %u: ours %02x, host %02x\n", row, i, | 5300 | ++plain_within; |
| 5278 | ours[b], host[b]); | 5301 | else if (differences++ < 8) |
| 5302 | std::fprintf(stderr, "placed plain clear row %u byte %u: ours %02x, host %02x\n", row, i, | ||
| 5303 | ours[b], host[b]); | ||
| 5304 | } | ||
| 5305 | if (ours[a] != host[a]) { | ||
| 5306 | if (within_tolerance(ours[a], host[a], srgb_ideal)) | ||
| 5307 | ++srgb_within; | ||
| 5308 | else if (differences++ < 8) | ||
| 5309 | std::fprintf(stderr, "placed SRGB-cast clear row %u byte %u: ours %02x, host %02x\n", | ||
| 5310 | row, i, ours[a], host[a]); | ||
| 5279 | } | 5311 | } |
| 5280 | if (ours[a] != host[a] && differences++ < 8) | ||
| 5281 | std::fprintf(stderr, "placed SRGB-cast clear row %u byte %u: ours %02x, host %02x\n", row, | ||
| 5282 | i, ours[a], host[a]); | ||
| 5283 | } | 5312 | } |
| 5284 | if (tie_bytes_other_way) | 5313 | if (plain_within || srgb_within) |
| 5285 | std::printf("placed plain clear: the host rounds the exact .5 tie the other way in %u bytes (within " | 5314 | std::printf("placed clears: %u plain and %u SRGB-cast bytes differ from the host by one code, both " |
| 5286 | "the 0.6 ULP tolerance of D3D11.3 spec 3.2.3.6)\n", | 5315 | "within the 0.6 ULP tolerance of D3D11.3 spec 3.2.3.6 and 3.2.3.8\n", |
| 5287 | tie_bytes_other_way); | 5316 | plain_within, srgb_within); |
| 5288 | for (UINT i = 0; i < 3; ++i) | 5317 | for (UINT i = 0; i < 3; ++i) |
| 5289 | if (our_refusals[i] != host_refusals[i]) { | 5318 | if (our_refusals[i] != host_refusals[i]) { |
| 5290 | ++differences; | 5319 | ++differences; |