shader: check binary32 subnormals in a Vulkan pixel shader #2016

Manually merged
github merged 2 commits from gh-pr/2016/head into gh-pr/2016/base 2026-11-26 23:50:02 +00:00
Owner

@⁠Ybucaille on GitHub · 2026-11-24 23:10 UTC · original
Ybucaille:shader/vulkan-denorm-host → main · +622 −0 · 5 files · 2 commits · merged 2026-11-25 00:10 UTC

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 preserve from flush.

  • tests/vk_pixel_draw.c: a small C Vulkan host (full-screen triangle, 256 bytes of constants, RGBA32F or
    RGBA32UI target, raw readback). It mirrors draw_verified on D3D12 and is kept generic so a follow-up can draw
    translated shaders with it. --caps DEVICE prints 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: a ps_6_2 shader runs seven operations with subnormal inputs or
    results (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 result
    word is read back exactly from an RGBA32UI pixel and compared with IEEE binary32 arithmetic in Python.
    • -denorm preserve must match on every case.
    • -denorm ftz is the negative control and must differ on at least one case, or the check fails.
    • Missing shaderDenormPreserveFloat32 (exit 77) and validation refusals from spirv-val or the driver
      (exit 78) are reported apart from mismatches (exit 1).
    • The log has the device, driver, DXC and SPIRV-Tools versions, program, mode, SPIR-V execution mode, every
      word read back and the cases where the control differs.
  • DXC options: -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: docs/non-windows-hosts.md (usage) and docs/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.py render the
same bits under Vulkan; that is the next change.

Reproduce

python3 -B tests/pixel_denorm_vulkan_check.py /usr/bin/dxc tests/vk_pixel_draw.c --device Intel
VK_DRIVER_FILES=/usr/share/vulkan/icd.d/lvp_icd.json \
  python3 -B tests/pixel_denorm_vulkan_check.py /usr/bin/dxc tests/vk_pixel_draw.c --device llvmpipe

Needs DXC, spirv-val and spirv-dis, a C compiler and the Vulkan loader headers. Use --device RADV (or the
device 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.

case a b op preserve IEEE ftz
sub*1 00000001 3f800000 a * b 00000001 00000001 00000000
sub+0 007fffff 00000000 a + b 007fffff 007fffff 00000000
minnorm*0.5 00800000 3f000000 a * b 00400000 00400000 00000000
minnorm-sub 00800000 00000001 a - b 007fffff 007fffff 00800000
sub+sub 00000001 00000001 a + b 00000002 00000002 00000000
-sub*1 80000003 3f800000 a * b 80000003 80000003 80000000
sub*2^23 00000001 4b000000 a * b 00800000 00800000 00000000

Preserve conforms on 7 of 7. The ftz control differs on 7 of 7, for example 00000001 * 1.0 reads back
00000000.

lavapipe (llvmpipe, LLVM 23.1.4, Mesa 26.2.7): shaderDenormPreserveFloat32 = 0. Reported as a capability
skip, exit 77, not as a mismatch.

Other checks: git diff --check clean; tests/docs_links_check.py passed (18 files, 389 links).
Not run: CMake, ctest and Windows CI (Linux only; the check is outside CMake).

AI-assisted.

**@⁠Ybucaille** on GitHub · 2026-11-24 23:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2016) `Ybucaille:shader/vulkan-denorm-host` → `main` · +622 −0 · 5 files · 2 commits · merged 2026-11-25 00:10 UTC 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 preserve` from flush. - `tests/vk_pixel_draw.c`: a small C Vulkan host (full-screen triangle, 256 bytes of constants, RGBA32F or RGBA32UI target, raw readback). It mirrors `draw_verified` on D3D12 and is kept generic so a follow-up can draw translated shaders with it. `--caps DEVICE` prints 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`: a `ps_6_2` shader runs seven operations with subnormal inputs or results (`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 result word is read back exactly from an RGBA32UI pixel and compared with IEEE binary32 arithmetic in Python. - `-denorm preserve` must match on every case. - `-denorm ftz` is the negative control and must differ on at least one case, or the check fails. - Missing `shaderDenormPreserveFloat32` (exit 77) and validation refusals from `spirv-val` or the driver (exit 78) are reported apart from mismatches (exit 1). - The log has the device, driver, DXC and SPIRV-Tools versions, program, mode, SPIR-V execution mode, every word read back and the cases where the control differs. - DXC options: `-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: `docs/non-windows-hosts.md` (usage) and `docs/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.py` render the same bits under Vulkan; that is the next change. ## Reproduce ```bash python3 -B tests/pixel_denorm_vulkan_check.py /usr/bin/dxc tests/vk_pixel_draw.c --device Intel VK_DRIVER_FILES=/usr/share/vulkan/icd.d/lvp_icd.json \ python3 -B tests/pixel_denorm_vulkan_check.py /usr/bin/dxc tests/vk_pixel_draw.c --device llvmpipe ``` Needs DXC, `spirv-val` and `spirv-dis`, a C compiler and the Vulkan loader headers. Use `--device RADV` (or the device 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. | case | a | b | op | preserve | IEEE | ftz | |---|---|---|---|---|---|---| | sub*1 | 00000001 | 3f800000 | a * b | 00000001 | 00000001 | 00000000 | | sub+0 | 007fffff | 00000000 | a + b | 007fffff | 007fffff | 00000000 | | minnorm*0.5 | 00800000 | 3f000000 | a * b | 00400000 | 00400000 | 00000000 | | minnorm-sub | 00800000 | 00000001 | a - b | 007fffff | 007fffff | 00800000 | | sub+sub | 00000001 | 00000001 | a + b | 00000002 | 00000002 | 00000000 | | -sub*1 | 80000003 | 3f800000 | a * b | 80000003 | 80000003 | 80000000 | | sub*2^23 | 00000001 | 4b000000 | a * b | 00800000 | 00800000 | 00000000 | Preserve conforms on 7 of 7. The ftz control differs on 7 of 7, for example `00000001 * 1.0` reads back `00000000`. lavapipe (llvmpipe, LLVM 23.1.4, Mesa 26.2.7): `shaderDenormPreserveFloat32` = 0. Reported as a capability skip, exit 77, not as a mismatch. Other checks: `git diff --check` clean; `tests/docs_links_check.py` passed (18 files, 389 links). Not run: CMake, ctest and Windows CI (Linux only; the check is outside CMake). AI-assisted.
Add a small C Vulkan host (full-screen triangle, constants, RGBA32F or
RGBA32UI target, raw readback) and a source-built ps_6_2 check that runs
seven subnormal operations and compares the words read back with IEEE
binary32 arithmetic. -denorm preserve must match; -denorm ftz is the
negative control and must differ, so the probe separates preserve from
flush.

A device without shaderDenormPreserveFloat32 (for example lavapipe) is
a capability skip, and a module that spirv-val or the driver refuses is
a validation refusal; both are reported apart from mismatches. The log
names the device, driver, DXC and SPIRV-Tools versions and every word.

The host stays generic so a later change can draw translated shaders
with it. Refs #614.

AI-assisted.
The combined status looked at a refusal first, so a preserve readback
that differed from IEEE was reported as 78 when the ftz build was
refused. 78 means a refusal with no measured mismatch. The decision is
now a pure classify() that evaluates the preserve readback first.

Run without arguments, the script checks classify() without a device:
preserve mismatch with an ftz refusal (1), an ftz control that matches
preserve (1), and the nominal ok and refusal cases. The Linux Python
checks job runs it.

AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:49:59 +00:00
github manually merged commit 40a769c394 into gh-pr/2016/base 2026-11-26 23:50:02 +00:00
Author
Owner

@⁠Ybucaille on GitHub · 2026-11-24 23:59 UTC · original

Thanks for the review. Fixed in 40a769c3 on the same branch (no rebase or amend).

  • The combined status now evaluates the preserve readback before any refusal. A preserve readback that differs from IEEE exits 1 even when the ftz build is refused. 78 is kept for a refusal with no measured mismatch, and 77 for a missing capability.
  • The decision is a pure classify(preserve, ftz) function, so it can be tested without a device.
  • Device-free controls, run before anything else and on their own when the script gets no arguments: preserve mismatch with an ftz refusal (expect 1), ftz control that matches preserve (expect failure, kept from before), preserve OK with a refused or errored ftz, both refused, and the nominal cases. Ten cases in total.
  • The no-argument run is added to the "Run platform-independent Python checks on Linux" step in windows.yml, so it runs in CI. docs/non-windows-hosts.md describes the exit codes and the no-device run.
  • I put the old ordering back temporarily: the new control for preserve mismatch plus ftz refusal fails with classify(...) is refused, expected mismatch.
  • Re-run locally after the change: Intel exits 0 (7 of 7 ftz cases differ), lavapipe exits 77, py_compile, docs_links_check.py and git diff --check pass. The Intel run remains author evidence.

AI-assisted.

**@⁠Ybucaille** on GitHub · 2026-11-24 23:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2016#issuecomment-7148023033) Thanks for the review. Fixed in 40a769c3 on the same branch (no rebase or amend). - The combined status now evaluates the `preserve` readback before any refusal. A `preserve` readback that differs from IEEE exits 1 even when the `ftz` build is refused. 78 is kept for a refusal with no measured mismatch, and 77 for a missing capability. - The decision is a pure `classify(preserve, ftz)` function, so it can be tested without a device. - Device-free controls, run before anything else and on their own when the script gets no arguments: `preserve` mismatch with an `ftz` refusal (expect 1), `ftz` control that matches `preserve` (expect failure, kept from before), `preserve` OK with a refused or errored `ftz`, both refused, and the nominal cases. Ten cases in total. - The no-argument run is added to the "Run platform-independent Python checks on Linux" step in `windows.yml`, so it runs in CI. `docs/non-windows-hosts.md` describes the exit codes and the no-device run. - I put the old ordering back temporarily: the new control for `preserve` mismatch plus `ftz` refusal fails with `classify(...) is refused, expected mismatch`. - Re-run locally after the change: Intel exits 0 (7 of 7 `ftz` cases differ), lavapipe exits 77, `py_compile`, `docs_links_check.py` and `git diff --check` pass. The Intel run remains author evidence. AI-assisted.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 23:16 UTC · original · reviewed

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.
  • Win2025 pipeline run: "nothing to run on Windows (no CTest target or py-check discovered)". The check is a manual Linux and Vulkan tool and is not registered in CMake, so it has no Windows run.

Mutation: I changed the minnorm*0.5 expected word from 0x00400000 to 0x00400001. The script stopped with ValueError: 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 with shaderDenormPreserveFloat32, 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.

**@⁠tedin7** on GitHub · 2026-11-24 23:16 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2016#pullrequestreview-6048928530) · **reviewed** Review of head 73ad8879402e2dd931d8d962acfa9767d2386dcb (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. - Win2025 pipeline run: "nothing to run on Windows (no CTest target or py-check discovered)". The check is a manual Linux and Vulkan tool and is not registered in CMake, so it has no Windows run. Mutation: I changed the `minnorm*0.5` expected word from `0x00400000` to `0x00400001`. The script stopped with `ValueError: 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 with `shaderDenormPreserveFloat32`, 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.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 23:52 UTC · original · requested changes

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.

**@⁠R0Y00** on GitHub · 2026-11-24 23:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2016#pullrequestreview-6049330560) · **requested changes** 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.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-25 00:08 UTC · original · approved these changes

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.

**@⁠R0Y00** on GitHub · 2026-11-25 00:08 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2016#pullrequestreview-6049504064) · **approved these changes** 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.