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

Merged
Ybucaille merged 2 commits from upstream-pr/2016 into main 2026-11-25 00:10:49 +00:00
Ybucaille commented 2026-11-24 23:10:38 +00:00 (Migrated from github.com)

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 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593275140 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2016). Originally posted by [Ybucaille](https://github.com/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 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.
tedin7 commented 2026-11-25 00:04:56 +00:00 (Migrated from github.com)

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.
  • 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6048928530 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2016#pullrequestreview-6048928530). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T23:16:17Z. **Review:** COMMENTED --- 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.
R0Y00 commented 2026-11-25 00:04:56 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049330560 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2016#pullrequestreview-6049330560). Originally posted by [R0Y00](https://github.com/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.
upstream-sync closed this pull request 2026-11-25 01:01:06 +00:00
R0Y00 commented 2026-11-25 01:01:06 +00:00 (Migrated from github.com)

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6049504064 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2016#pullrequestreview-6049504064). Originally posted by [R0Y00](https://github.com/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.
Ybucaille commented 2026-11-25 01:02:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Ybucaille on 2026-11-24T23:59:53Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148023033 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2016#issuecomment-7148023033). Originally posted by [Ybucaille](https://github.com/Ybucaille) on 2026-11-24T23:59:53Z. --- 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.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2009
No description provided.