shader: check binary32 subnormals in a Vulkan pixel shader #2009
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2016"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Ybucaille on 2026-11-24T23:10:38Z.
Refs #614. Related: #473 (FP32 Vulkan check, same optional-host style).
Summary
Adds the Vulkan host requested on #614 and the first case that runs on it: a source-built pixel shader that
distinguishes
-denorm preservefrom flush.tests/vk_pixel_draw.c: a small C Vulkan host (full-screen triangle, 256 bytes of constants, RGBA32F orRGBA32UI target, raw readback). It mirrors
draw_verifiedon D3D12 and is kept generic so a follow-up can drawtranslated shaders with it.
--caps DEVICEprints the device, driver and float-control properties. Exit codes:77 no device or capability, 78 the driver refused the shader module or pipeline.
tests/pixel_denorm_vulkan_check.py: aps_6_2shader runs seven operations with subnormal inputs orresults (
1 * 2^-149,0x007fffff + 0,minnorm * 0.5,minnorm - 2^-149,2^-149 + 2^-149,-0x00000003 * 1,2^-149 * 2^23). Inputs come from a constant buffer so DXC cannot fold them. Each resultword is read back exactly from an RGBA32UI pixel and compared with IEEE binary32 arithmetic in Python.
-denorm preservemust match on every case.-denorm ftzis the negative control and must differ on at least one case, or the check fails.shaderDenormPreserveFloat32(exit 77) and validation refusals fromspirv-valor the driver(exit 78) are reported apart from mismatches (exit 1).
word read back and the cases where the control differs.
-spirv -fspv-target-env=vulkan1.2 -fvk-b-shift 0 0 -fvk-t-shift 16 0 -fvk-s-shift 32 0 -fvk-u-shift 48 0.docs/non-windows-hosts.md(usage) anddocs/experiments.md(method and results).Like #473, the check is optional and is not registered in CMake or CI. It measures how a driver treats
subnormals in this one shader. It does not show that the translated shaders from
tools/pixel_aot.pyrender thesame bits under Vulkan; that is the next change.
Reproduce
Needs DXC,
spirv-valandspirv-dis, a C compiler and the Vulkan loader headers. Use--device RADV(or thedevice name substring) for an AMD adapter.
Results
DXC 1.10.2605.37, SPIRV-Tools v2026.4, Arch Linux.
Intel UHD Graphics (TGL GT1), Mesa 26.2.7 (ANV), Vulkan 1.4.354,
shaderDenormPreserveFloat32= 1. Exit 0.Preserve conforms on 7 of 7. The ftz control differs on 7 of 7, for example
00000001 * 1.0reads back00000000.lavapipe (llvmpipe, LLVM 23.1.4, Mesa 26.2.7):
shaderDenormPreserveFloat32= 0. Reported as a capabilityskip, exit 77, not as a mismatch.
Other checks:
git diff --checkclean;tests/docs_links_check.pypassed (18 files, 389 links).Not run: CMake, ctest and Windows CI (Linux only; the check is outside CMake).
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T23:16:17Z.
Review: COMMENTED
Review of head
73ad887940(docs, one Python check, one C Vulkan host).Commands executed locally (Linux):
git merge-tree --write-tree --name-only origin/main HEAD: clean, no conflicts.gh pr checks 2016: Windows build/test, gfx1013 fixtures and Linux Python checks pass. Windows /O2 shows skipping.python3 -I -m py_compile tests/pixel_denorm_vulkan_check.py: OK.cc -std=c11 -O1 -Wall -fsyntax-only tests/vk_pixel_draw.c: no warnings.python3 tests/docs_links_check.py: PASS (18 files, 389 links).python3 tests/bidi_controls_check.py: PASS.git diff --check origin/main...HEAD: PASS.Mutation: I changed the
minnorm*0.5expected word from0x00400000to0x00400001. The script stopped withValueError: The IEEE table disagrees with the Python reference, so that mutation is killed. It only covers the reference table. The driver comparison path (preserve vs IEEE, ftz control must differ) needs DXC plus a Vulkan device withshaderDenormPreserveFloat32, and this host has neither, so I could not mutate that path.Read-through: the semantics look correct. The reference uses double arithmetic rounded once to binary32, which is exact for + - and *. The ftz control must differ, so the probe cannot pass vacuously. Capability skip (77) and validation refusal (78) are kept apart from mismatches. Clean-room: the shader and host are original, with no copied code. The PR does not touch CMakeLists.txt.
P1: 0. P2: 0.
Not merged by me. The Win2025 gate has no run for this PR and the device-level logic could not be exercised here, so the merge prerequisites are not met. A maintainer with a Vulkan 1.2 device and DXC can run the documented command and decide.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T23:52:00Z.
Review: CHANGES_REQUESTED
One classification issue in the optional Vulkan probe: if preserve renders incorrect words and FTZ is refused, the refusal branch returns 78 and hides the measured preserve mismatch, although 78 is documented to mean a refusal with no mismatch. Evaluate successful preserve readback before deciding the combined status. Add a device-free classification control for preserve mismatch plus FTZ refusal (expect 1), and keep the successful-but-indistinguishable FTZ control. Local Windows does not have the SPIR-V validation tools, so the reported Intel execution remains author evidence.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T00:08:52Z.
Review: APPROVED
Reviewed
40a769c3. All 10 device-free classification controls passed locally. The preserve mismatch now wins over an FTZ refusal, and indistinguishable FTZ still fails. The Intel Vulkan run is author evidence. I did not rerun the driver path on this Windows host.Imported from R0Y00/Xbox2Windows. Originally posted by Ybucaille on 2026-11-24T23:59:53Z.
Thanks for the review. Fixed in
40a769c3on the same branch (no rebase or amend).preservereadback before any refusal. Apreservereadback that differs from IEEE exits 1 even when theftzbuild is refused. 78 is kept for a refusal with no measured mismatch, and 77 for a missing capability.classify(preserve, ftz)function, so it can be tested without a device.preservemismatch with anftzrefusal (expect 1),ftzcontrol that matchespreserve(expect failure, kept from before),preserveOK with a refused or erroredftz, both refused, and the nominal cases. Ten cases in total.windows.yml, so it runs in CI.docs/non-windows-hosts.mddescribes the exit codes and the no-device run.preservemismatch plusftzrefusal fails withclassify(...) is refused, expected mismatch.ftzcases differ), lavapipe exits 77,py_compile,docs_links_check.pyandgit diff --checkpass. The Intel run remains author evidence.AI-assisted.