rdna2spirv: lower computed I/J barycentrics under --f16-interp-fallback (SHADER-F16-INTERP-COMPUTED-IJ) #2239

Open
github-bot wants to merge 4 commits from github-bot/gh-2239 into main AGit
Owner

@⁠zmasi on GitHub · 2026-11-26 10:01 UTC · original
zmasi:fix/rdna2spirv-f16-interp-computed-ij → main · +614 −67 · 11 files · 4 commits · draft

Claimed in the coordination issue as: SHADER-F16-INTERP-COMPUTED-IJ (#1608)

Depends on: #1426 (orthogonal topic: #1426 handles --bary-fallback with Flat vec4[3] geometry-shader pass-through and leaves F16_HALVES and not BARY_FALLBACK refused; listed here because adjacent hunk context in tools/rdna2spirv.py and tests/test_shader_build_fallbacks.py sits nearby on merge)

What and why

When per_vertex_inputs is unavailable and no geometry shader is used (--f16-interp-fallback without --bary-fallback, e.g. on MoltenVK / Apple Silicon where BuiltIn BaryCoordKHR is available without PerVertexKHR or geometry shaders), interp_ij_analysis in tools/rdna2spirv.py refused all 207 pixel shaders in the corpus that compute custom (I, J) barycentrics into VGPRs (computed I/J pair under --f16-interp-fallback: no PerVertexKHR inputs). OpCapability InterpolationFunction (InterpolateAtOffset) cannot be used without enabling sampleRateShading and is rejected on BaryCoordKHR by SPIRV-Cross MSL.

Because perspective-correct BaryCoordKHR (I, J) already absorbs 1/W, every smooth-interpolated input P (both standard f32 attributes and decoded --f16-interp-fallback halves) satisfies the exact affine relation P = P_0 + I \cdot P_{10} + J \cdot P_{20} across all four invocations of a 2 \times 2 screen quad. Under F16_HALVES and not BARY_FALLBACK:

  • Hoists OpDPdxFine and OpDPdyFine (OpCapability DerivativeControl, core Vulkan 1.0, zero device feature bits, zero extra Locations, zero geometry shader) of BaryCoordKHR.y/.z and each computed (attribute, component) channel into uniform %entry.
  • Guards degenerate zero-area, subnormal, ±inf, and NaN determinants using integer IEEE-754 normal-range bit comparisons (0x00800000 <= (OpBitcast_u32(det) & 0x7FFFFFFF) < 0x7F800000, avoiding OpFDiv-by-zero and MoltenVK's OpFOrdNotEqual NaN hazard) so degenerate quads cleanly fall back to pixel-center P_c.
  • Evaluates P(I', J') = P_c + \alpha \cdot d_x P + \beta \cdot d_y P with pure scalar ALU at each v_interp site, including inside non-uniform EXEC-masked branches and loops.
  • Leaves --bary-fallback (BARY_FALLBACK) refusal and default PerVertexKHR emission completely unchanged.

Tested

  • Full corpus (--f16-interp-fallback): 26,296 / 26,503 -> 26,503 / 26,503 (100%) translated and 26,503 / 26,503 pass spirv-val (--target-env vulkan1.2 --allow-offset-texture-operand); all 207 / 207 previously refused pixel shaders pass spirv-val, remain byte-identical under default flags, and remain refused under --bary-fallback alone.
  • Vulkan GPU hardware (LEONIDA_F16_INTERP_FALLBACK=1 LEONIDA_BARY_FALLBACK=0, VK_LAYER_KHRONOS_validation 1.4.363):
    • runtime/test/shaders/build.py vs_ids ps_ij_computed ps_interp_f16_high vs_f16_pack: 4/4 translated, 4/4 spirv-val pass (OpCapability FragmentBarycentricKHR + OpCapability DerivativeControl, zero PerVertexKHR).
    • vk_pipeline_check: 2/2 PS modules ok, 2/2 PS pipelines ok, 0 validation errors.
    • vk_harness vs_ids.spv ps_ij_computed.spv (64x64): 4,096 / 4,096 pixels pass (exact_xyw = 4096/4096, exact_z_bits = 4096/4096, max_err_z = 0.0); scripts/run_gpu_tests.py --filter ps_ij_computed passes 1/1.
  • Translator & unit suites: python -m compileall -q make_game.py tools tests, tests/semantic/test_interp_computed_ij_fallback.py, tests/semantic/test_interp*.py (211/211), tests/test_shader_build_fallbacks.py (7/7), tests/test_run_gpu_tests.py (71/71), tests/test_text_write_line_endings.py, tests/test_docs_*.py, and python -I scripts/check_no_game_data.py across all touched files (all pass).

GPUs tested: NVIDIA GeForce RTX 3090, driver 610.88 (Vulkan 1.4.341, Khronos validation layer 1.4.363), Windows 11 x64

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
**@⁠zmasi** on GitHub · 2026-11-26 10:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2239) `zmasi:fix/rdna2spirv-f16-interp-computed-ij` → `main` · +614 −67 · 11 files · 4 commits · draft Claimed in the coordination issue as: `SHADER-F16-INTERP-COMPUTED-IJ` (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) Depends on: #1426 (orthogonal topic: #1426 handles `--bary-fallback` with `Flat vec4[3]` geometry-shader pass-through and leaves `F16_HALVES and not BARY_FALLBACK` refused; listed here because adjacent hunk context in `tools/rdna2spirv.py` and `tests/test_shader_build_fallbacks.py` sits nearby on merge) ### What and why When `per_vertex_inputs` is unavailable and no geometry shader is used (`--f16-interp-fallback` without `--bary-fallback`, e.g. on MoltenVK / Apple Silicon where `BuiltIn BaryCoordKHR` is available without `PerVertexKHR` or geometry shaders), `interp_ij_analysis` in `tools/rdna2spirv.py` refused all 207 pixel shaders in the corpus that compute custom `(I, J)` barycentrics into VGPRs (`computed I/J pair under --f16-interp-fallback: no PerVertexKHR inputs`). `OpCapability InterpolationFunction` (`InterpolateAtOffset`) cannot be used without enabling `sampleRateShading` and is rejected on `BaryCoordKHR` by SPIRV-Cross MSL. Because perspective-correct `BaryCoordKHR` $(I, J)$ already absorbs $1/W$, every smooth-interpolated input $P$ (both standard `f32` attributes and decoded `--f16-interp-fallback` halves) satisfies the exact affine relation $P = P_0 + I \cdot P_{10} + J \cdot P_{20}$ across all four invocations of a $2 \times 2$ screen quad. Under `F16_HALVES and not BARY_FALLBACK`: - Hoists `OpDPdxFine` and `OpDPdyFine` (`OpCapability DerivativeControl`, core Vulkan 1.0, zero device feature bits, zero extra `Location`s, zero geometry shader) of `BaryCoordKHR.y/.z` and each computed `(attribute, component)` channel into uniform `%entry`. - Guards degenerate zero-area, subnormal, `±inf`, and `NaN` determinants using integer IEEE-754 normal-range bit comparisons (`0x00800000 <= (OpBitcast_u32(det) & 0x7FFFFFFF) < 0x7F800000`, avoiding `OpFDiv`-by-zero and MoltenVK's `OpFOrdNotEqual` NaN hazard) so degenerate quads cleanly fall back to pixel-center $P_c$. - Evaluates $P(I', J') = P_c + \alpha \cdot d_x P + \beta \cdot d_y P$ with pure scalar ALU at each `v_interp` site, including inside non-uniform `EXEC`-masked branches and loops. - Leaves `--bary-fallback` (`BARY_FALLBACK`) refusal and default `PerVertexKHR` emission completely unchanged. ### Tested - **Full corpus (`--f16-interp-fallback`):** `26,296 / 26,503` -> **`26,503 / 26,503` (`100%`)** translated and **`26,503 / 26,503` pass `spirv-val`** (`--target-env vulkan1.2 --allow-offset-texture-operand`); all `207 / 207` previously refused pixel shaders pass `spirv-val`, remain byte-identical under default flags, and remain refused under `--bary-fallback` alone. - **Vulkan GPU hardware (`LEONIDA_F16_INTERP_FALLBACK=1 LEONIDA_BARY_FALLBACK=0`, `VK_LAYER_KHRONOS_validation` `1.4.363`):** - `runtime/test/shaders/build.py vs_ids ps_ij_computed ps_interp_f16_high vs_f16_pack`: `4/4` translated, `4/4` `spirv-val` pass (`OpCapability FragmentBarycentricKHR` + `OpCapability DerivativeControl`, zero `PerVertexKHR`). - `vk_pipeline_check`: `2/2` PS modules ok, `2/2` PS pipelines ok, `0` validation errors. - `vk_harness vs_ids.spv ps_ij_computed.spv` (`64x64`): **`4,096 / 4,096` pixels pass (`exact_xyw = 4096/4096`, `exact_z_bits = 4096/4096`, `max_err_z = 0.0`)**; `scripts/run_gpu_tests.py --filter ps_ij_computed` passes `1/1`. - **Translator & unit suites:** `python -m compileall -q make_game.py tools tests`, `tests/semantic/test_interp_computed_ij_fallback.py`, `tests/semantic/test_interp*.py` (`211/211`), `tests/test_shader_build_fallbacks.py` (`7/7`), `tests/test_run_gpu_tests.py` (`71/71`), `tests/test_text_write_line_endings.py`, `tests/test_docs_*.py`, and `python -I scripts/check_no_game_data.py` across all touched files (all pass). GPUs tested: NVIDIA GeForce RTX 3090, driver 610.88 (Vulkan 1.4.341, Khronos validation layer 1.4.363), Windows 11 x64 AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
Lower computed v_interp_p1/p2 (I, J) pairs under --f16-interp-fallback (without --bary-fallback) without PerVertexKHR or a geometry shader by hoisting OpDPdxFine/OpDPdyFine screen-quad barycentric and attribute derivatives into uniform %entry (OpCapability DerivativeControl, guarded by an integer IEEE-754 normal determinant check) and evaluating P_0 + I*P_10 + J*P_20 per site.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:24:10 +00:00
Author
Owner

@⁠EvgHaze on GitHub · 2026-11-26 10:19 UTC · original

Apple check — this turns a skip into a real GPU pass on the one driver this fallback is for.

Machine:  Apple M3, 10-core, macOS 27.0 (26A5406e), arm64
Drivers:  MoltenVK 1.4.2 (driver id 14): VK_KHR_fragment_shader_barycentric yes, PerVertexKHR no
          KosmicKrisp, Mesa 26.3.1 (driver id 28): no fragment shader barycentric at all
Base:     main `a73a57e` (clean checkout of the same tree) against this head `cd8d9aa7a`
Tools:    Homebrew llvm-mc 23.1.6, SPIRV-Tools 1.4.363.0, CMake 4.4.4
Tree MoltenVK 1.4.2 KosmicKrisp 26.3.1
main a73a57e SKIP: "computed I/J pairs need PerVertexKHR inputs: no --bary-fallback / --f16-interp-fallback" SKIP, same
this head cd8d9aa7a PASS ps_ij_computed: "computed I/J pair words and v/2 within 1e-6" SKIP: "unsupported: … reads BaryCoordKHR and the device has no VK_KHR_fragment_shader_barycentric"

So on the device this rule exists for — BaryCoordKHR present, PerVertexKHR absent — the fixture goes from never running to running and matching within 1e-6. That is the pair the old skip named and the fallback now covers.

KosmicKrisp is unchanged in both trees, which is correct rather than a regression: it has no VK_KHR_fragment_shader_barycentric, so there is nothing to lower onto.

python3 -I scripts/run_semantic_tests.py tests/semantic: 499 files, 6357 tests, 0 failed (204 s, 8 jobs) at this head.

One note for the PR body: the merge with #1426 is the only untested combination here — I applied this head on its own, not on top of #1426.

AI-assisted. No game data: hand-written fixtures, and every number above is test output.

**@⁠EvgHaze** on GitHub · 2026-11-26 10:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2239#issuecomment-7189207983) Apple check — this turns a skip into a real GPU pass on the one driver this fallback is for. ```text Machine: Apple M3, 10-core, macOS 27.0 (26A5406e), arm64 Drivers: MoltenVK 1.4.2 (driver id 14): VK_KHR_fragment_shader_barycentric yes, PerVertexKHR no KosmicKrisp, Mesa 26.3.1 (driver id 28): no fragment shader barycentric at all Base: main `a73a57e` (clean checkout of the same tree) against this head `cd8d9aa7a` Tools: Homebrew llvm-mc 23.1.6, SPIRV-Tools 1.4.363.0, CMake 4.4.4 ``` | Tree | MoltenVK 1.4.2 | KosmicKrisp 26.3.1 | |---|---|---| | main `a73a57e` | **SKIP**: "computed I/J pairs need PerVertexKHR inputs: no `--bary-fallback` / `--f16-interp-fallback`" | SKIP, same | | this head `cd8d9aa7a` | **PASS** `ps_ij_computed`: "computed I/J pair words and v/2 within 1e-6" | SKIP: "unsupported: … reads BaryCoordKHR and the device has no `VK_KHR_fragment_shader_barycentric`" | So on the device this rule exists for — `BaryCoordKHR` present, `PerVertexKHR` absent — the fixture goes from never running to running and matching within 1e-6. That is the pair the old skip named and the fallback now covers. KosmicKrisp is unchanged in both trees, which is correct rather than a regression: it has no `VK_KHR_fragment_shader_barycentric`, so there is nothing to lower onto. `python3 -I scripts/run_semantic_tests.py tests/semantic`: **499 files, 6357 tests, 0 failed** (204 s, 8 jobs) at this head. One note for the PR body: the merge with #1426 is the only untested combination here — I applied this head on its own, not on top of #1426. AI-assisted. No game data: hand-written fixtures, and every number above is test output.
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-26 10:19 UTC · original

The perspective fixture on an RTX 4090 shows a resolution-dependent precision difference in the derivative fallback. At 1920×1080 the native path returned the expected half-precision value of 1.5 for every covered pixel. The fallback returned 1.4990234375 at one pixel. The computed f32 channel also accumulated measurable error as the viewport grew.

I built vk_harness and translated tests/semantic/fixtures/ps_ij_computed_deriv_fallback.asm from cd8d9aa7a897 in both modes. I used the vertices, attributes, and packed halves from test_perspective_fixture_branch_and_f16_halves. A synthetic vertex shader exported the native inputs or their decoded halves. The clips had W = (1, 2.5, 4). Each row compares RGBA32F readback against the perspective-correct value calculated at each covered pixel center. Both draws ran on Windows, NVIDIA 616.64.

Viewport Interior pixels Peak absolute error in computed f32 (native) Peak absolute error in computed f32 (fallback)
64×64 2,016 0.00000157 0.0000372
512×512 130,816 0.00000239 0.000542
1920×1080 1,036,800 0.00000423 0.002043

At 1080p the largest f32 difference occurred at (1795, 50). The branch snaps both weights to 0.25, giving exactly 3.0 for green. Native returned 3.0, and the fallback returned 3.00204277. Across the image, 1,059 pixels exceeded 0.001 absolute error in this channel. The two compilation modes covered the same pixels. A second 1080p draw produced byte-identical readback for each mode independently.

A 1080p perspective case alongside the existing orthographic GPU check would let reviewers track this error as the lowering evolves. The same perspective fixture on the M3 would make a good comparison with these NVIDIA results and the orthographic MoltenVK pass.

**@⁠ecox982745** on GitHub · 2026-11-26 10:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2239#issuecomment-7189222676) The perspective fixture on an RTX 4090 shows a resolution-dependent precision difference in the derivative fallback. At 1920×1080 the native path returned the expected half-precision value of 1.5 for every covered pixel. The fallback returned 1.4990234375 at one pixel. The computed f32 channel also accumulated measurable error as the viewport grew. I built `vk_harness` and translated `tests/semantic/fixtures/ps_ij_computed_deriv_fallback.asm` from `cd8d9aa7a897` in both modes. I used the vertices, attributes, and packed halves from `test_perspective_fixture_branch_and_f16_halves`. A synthetic vertex shader exported the native inputs or their decoded halves. The clips had W = (1, 2.5, 4). Each row compares RGBA32F readback against the perspective-correct value calculated at each covered pixel center. Both draws ran on Windows, NVIDIA 616.64. | Viewport | Interior pixels | Peak absolute error in computed f32 (native) | Peak absolute error in computed f32 (fallback) | | --- | ---: | ---: | ---: | | 64×64 | 2,016 | 0.00000157 | 0.0000372 | | 512×512 | 130,816 | 0.00000239 | 0.000542 | | 1920×1080 | 1,036,800 | 0.00000423 | 0.002043 | At 1080p the largest f32 difference occurred at (1795, 50). The branch snaps both weights to 0.25, giving exactly 3.0 for green. Native returned 3.0, and the fallback returned 3.00204277. Across the image, 1,059 pixels exceeded 0.001 absolute error in this channel. The two compilation modes covered the same pixels. A second 1080p draw produced byte-identical readback for each mode independently. A 1080p perspective case alongside the existing orthographic GPU check would let reviewers track this error as the lowering evolves. The same perspective fixture on the M3 would make a good comparison with these NVIDIA results and the [orthographic MoltenVK pass](https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/2239).
Author
Owner

@⁠lixonik on GitHub · 2026-11-26 10:56 UTC · original · reviewed

Local synthetic checks at this head: 28 computed-I/J semantic, 7 shader-build fallback, and 71 GPU runner tests passed in Ubuntu on WSL. I also translated the hand-written vs_ids / ps_ij_computed pair in default and --f16-interp-fallback modes, validated both pairs with spirv-val and ran the Windows Vulkan harness. All 4,096 readback pixels matched in each mode. GPU: NVIDIA GeForce RTX 5070, driver 610.88, Windows 11. These runs cover Vulkan and the synthetic fixtures. MoltenVK and the retail corpus were outside this run.

AI-assisted.

**@⁠lixonik** on GitHub · 2026-11-26 10:56 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2239#pullrequestreview-6072893548) · **reviewed** Local synthetic checks at this head: 28 computed-I/J semantic, 7 shader-build fallback, and 71 GPU runner tests passed in Ubuntu on WSL. I also translated the hand-written `vs_ids` / `ps_ij_computed` pair in default and `--f16-interp-fallback` modes, validated both pairs with `spirv-val` and ran the Windows Vulkan harness. All 4,096 readback pixels matched in each mode. GPU: NVIDIA GeForce RTX 5070, driver 610.88, Windows 11. These runs cover Vulkan and the synthetic fixtures. MoltenVK and the retail corpus were outside this run. AI-assisted.
Author
Owner

@⁠wavehs on GitHub · 2026-11-26 19:19 UTC · original · reviewed

macOS arm64 / GPU check of #2239 (SHADER-F16-INTERP-COMPUTED-IJ). This is a translator change plus fixtures; the lowering it adds (OpDPdxFine/OpDPdyFine quad reconstruction) runs on the exact class of device the flag exists for, so I could execute it natively rather than only on the CPU.

Tested head cd8d9aa7a merged onto main bdbc7e923 as merge 1d7ddff26 (clean, no conflicts).

Environment: Apple M3 Pro, arm64 (subgroups 4..32), macOS 27.2.1, Apple clang 21.0.0, CMake 4.5.0, CPython 3.15.2, llvm-mc 23.1.5, SPIRV-Tools v2026.4, glslang 16.6.0, MoltenVK 1.4.0, KosmicKrisp = Mesa 26.3.0 (32-wide).

The new path runs on MoltenVK, which is the device class the flag was added for

  • tools/vk_subgroup_info.py on MoltenVK reports per_vertex_inputs: false, so run_gpu_tests.py selects --f16-interp-fallback by itself - no LEONIDA_F16_INTERP_FALLBACK=1 needed, which is the honest macOS case.
  • run_gpu_tests.py --filter ps_ij_computed on the merge, MoltenVK: PASS ps_ij_computed - computed I/J pair words and v/2 within 1e-6 (the runner's own checker). Before this PR that fixture was skipped by the runner's old or f16_interp_fallback() guard and could not be translated at all.
  • Full suite on the merge, MoltenVK: 278 shaders: 278 translated, 278 pass spirv-val, then 196 passed / 3 failed / 69 skipped of 268. The three failures are exactly main's on this driver (cs_fma_fused, cs_imgatomic_ext, ps_ssharp); the one-test delta against the same-main baseline (195 / 3 / 70) is ps_ij_computed moving from SKIP to PASS.
  • Full suite on the merge, KosmicKrisp: 190 / 5 / 73, the same five failures as main's baseline (cs_bvh, cs_bvh32, cs_imgatomic_ext, ps_cndmask_sign_mods, ps_valu16_mad_sel). Here ps_ij_computed skips with reads BaryCoordKHR and the device has no VK_KHR_fragment_shader_barycentric, so this driver cannot exercise the lowering - see the second finding.

Translator and unit suites

  • Whole semantic suite on the merge: 501 files, 6373 tests, 0 files failed in 61 s with 12 jobs (main is 500 / 6367, so the PR adds one file and six cases and breaks none).
  • tests/semantic/test_interp_computed_ij_fallback.py: 6 tests, OK. tests/semantic/test_interp_computed_ij.py: OK.
  • tests/test_shader_build_fallbacks.py and tests/test_run_gpu_tests.py: OK.

Negative controls

  1. Revert only the implementation (git checkout bdbc7e923 -- tools/rdna2spirv.py), keep the new test file: the new semantic file reports FAILED (errors=4), and the GPU run becomes FAIL ps_ij_computed missing .spv (translation failed) - the old computed I/J pair under --f16-interp-fallback: no PerVertexKHR inputs refusal. Restored.
  2. Sabotage the reconstruction: change ij_quad_eval's I offset from %ij_ic to %ij_jc (tools/rdna2spirv.py:15103). Semantic file: 3 failures. GPU on MoltenVK: FAIL ps_ij_computed 4039 pixels without the computed-pair words, v/2 off by 0, i.e. 4039 of 4096 pixels differ - the GPU fixture really does depend on the arithmetic, not just on the module existing. Restored.
  3. Sabotage the determinant guard (%ij_nz = OpLogicalAnd %bool %ij_dlo %ij_dlo, dropping the >= 0x7F800000 upper bound): 2 failures in the new semantic file - the ±inf/NaN degenerate cases are pinned, not just the zero-area one. Restored.

Finding: the new docs row says v_interp_p1lv_f16 takes P_0 from vsrc2; no code path reads it
docs/design.md:524 ends with "v_interp_p1lv_f16 still overrides P_0 with the half decoded from vsrc2 (Gen.f16_in)". There is no such override: the p1lv branch (tools/rdna2spirv.py:11781-11800) calls attribute(...) and, under --f16-interp-fallback, attribute() returns ij_quad_eval (:15140 and :15151) built from the interpolated attribute and its derivatives; Gen.f16_in is never reached from a p1lv operand. I checked it by translating a computed-I/J p1lv pair with v10 = 0 and with v10 = 0x3f800000: the two SPIR-V texts differ only in the dead OpStore %reg_v10 ... and the constant it stores, and %reg_v10 is never loaded. The non-computed p1lv path behaves the same way (the store is dead there too), so this is inherited, but the sentence is new in this PR and a reviewer or a later change would rely on it. Effect: for a p1lv pair with a computed (I, J), P_0 is the interpolated attribute's vertex-0 value, not the supplied vsrc2; the corpus has 0 computed *_f16 ops (the row says so), so no known shader is wrong today. Either implement the vsrc2 override or drop that clause and add a semantic assertion that two different vsrc2 constants give the same module, so the claim cannot creep back.

Finding: the lowering adds a fragmentShaderBarycentric requirement, and the row reads as if it adds none
assemble() sets bary = ... or bool(gen.ij_deriv) (tools/rdna2spirv.py:16214), so these modules load BuiltIn BaryCoordKHR and carry OpCapability FragmentBarycentricKHR + SPV_KHR_fragment_shader_barycentric. The index does record it - features: ["fragmentShaderBarycentric"] for the generated ps_ij_computed.spv - and both drivers act on it (MoltenVK has it, KosmicKrisp skips). But the row says the lowering declares "core Vulkan 1.0 OpCapability DerivativeControl (unconditional, zero VkPhysicalDeviceFeatures bits, zero extra Location slots)"; for the 207 shaders that previously required nothing under this flag, the module now requires fragmentShaderBarycentric. That is unavoidable (there is no other way to get I, J without per-vertex arrays), and make_game.py selecting --f16-interp-fallback where per_vertex_inputs is false means a device with neither PerVertexKHR nor plain barycentrics gets modules it cannot create a pipeline for - the same dead end as the old refusal, not a regression. It should be written down as a device requirement, though, because "zero VkPhysicalDeviceFeatures bits" is the phrase a follow-up will quote when deciding that this path needs no feature gate.

Nit: the runner's skip under --bary-fallback now says computed I/J pairs need PerVertexKHR inputs: no --bary-fallback, which reads backwards ("no --bary-fallback" as the reason it cannot run, when it is the flag that is on). It only shows up on ANV-style fallback runs, but the old message named both flags and was clearer.

Not run: Windows and the full corpus. The 26,503-shader count and the RTX 3090 result cannot be reproduced here (needs the game copy and Windows); what I can say is that on this machine all 278 GPU fixtures translate and validate, and the computed-pair fixture passes on the driver the flag targets. The change touches no runtime C++, so no shim or D3D12 test is affected, and I did not re-run the C++ suite.

python -I scripts/check_no_game_data.py on all 11 changed files: clean.

No game files. AI-assisted.

**@⁠wavehs** on GitHub · 2026-11-26 19:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2239#pullrequestreview-6079450211) · **reviewed** **macOS arm64 / GPU check of #2239** (SHADER-F16-INTERP-COMPUTED-IJ). This is a translator change plus fixtures; the lowering it adds (`OpDPdxFine`/`OpDPdyFine` quad reconstruction) runs on the exact class of device the flag exists for, so I could execute it natively rather than only on the CPU. Tested head `cd8d9aa7a` merged onto `main` `bdbc7e923` as merge `1d7ddff26` (clean, no conflicts). Environment: Apple M3 Pro, arm64 (subgroups 4..32), macOS 27.2.1, Apple clang 21.0.0, CMake 4.5.0, CPython 3.15.2, `llvm-mc` 23.1.5, SPIRV-Tools v2026.4, glslang 16.6.0, MoltenVK 1.4.0, KosmicKrisp = Mesa 26.3.0 (32-wide). **The new path runs on MoltenVK, which is the device class the flag was added for** - `tools/vk_subgroup_info.py` on MoltenVK reports `per_vertex_inputs: false`, so `run_gpu_tests.py` selects `--f16-interp-fallback` by itself - no `LEONIDA_F16_INTERP_FALLBACK=1` needed, which is the honest macOS case. - `run_gpu_tests.py --filter ps_ij_computed` on the merge, MoltenVK: `PASS ps_ij_computed - computed I/J pair words and v/2 within 1e-6` (the runner's own checker). Before this PR that fixture was skipped by the runner's old `or f16_interp_fallback()` guard and could not be translated at all. - Full suite on the merge, MoltenVK: `278 shaders: 278 translated, 278 pass spirv-val`, then `196 passed / 3 failed / 69 skipped` of 268. The three failures are exactly main's on this driver (`cs_fma_fused`, `cs_imgatomic_ext`, `ps_ssharp`); the one-test delta against the same-main baseline (`195 / 3 / 70`) is `ps_ij_computed` moving from SKIP to PASS. - Full suite on the merge, KosmicKrisp: `190 / 5 / 73`, the same five failures as main's baseline (`cs_bvh`, `cs_bvh32`, `cs_imgatomic_ext`, `ps_cndmask_sign_mods`, `ps_valu16_mad_sel`). Here `ps_ij_computed` skips with `reads BaryCoordKHR and the device has no VK_KHR_fragment_shader_barycentric`, so this driver cannot exercise the lowering - see the second finding. **Translator and unit suites** - Whole semantic suite on the merge: `501 files, 6373 tests, 0 files failed in 61 s with 12 jobs` (main is `500 / 6367`, so the PR adds one file and six cases and breaks none). - `tests/semantic/test_interp_computed_ij_fallback.py`: 6 tests, OK. `tests/semantic/test_interp_computed_ij.py`: OK. - `tests/test_shader_build_fallbacks.py` and `tests/test_run_gpu_tests.py`: OK. **Negative controls** 1. Revert only the implementation (`git checkout bdbc7e923 -- tools/rdna2spirv.py`), keep the new test file: the new semantic file reports `FAILED (errors=4)`, and the GPU run becomes `FAIL ps_ij_computed missing .spv (translation failed)` - the old `computed I/J pair under --f16-interp-fallback: no PerVertexKHR inputs` refusal. Restored. 2. Sabotage the reconstruction: change `ij_quad_eval`'s I offset from `%ij_ic` to `%ij_jc` (`tools/rdna2spirv.py:15103`). Semantic file: 3 failures. GPU on MoltenVK: `FAIL ps_ij_computed 4039 pixels without the computed-pair words, v/2 off by 0`, i.e. 4039 of 4096 pixels differ - the GPU fixture really does depend on the arithmetic, not just on the module existing. Restored. 3. Sabotage the determinant guard (`%ij_nz = OpLogicalAnd %bool %ij_dlo %ij_dlo`, dropping the `>= 0x7F800000` upper bound): 2 failures in the new semantic file - the `±inf`/`NaN` degenerate cases are pinned, not just the zero-area one. Restored. **Finding: the new docs row says `v_interp_p1lv_f16` takes `P_0` from `vsrc2`; no code path reads it** `docs/design.md:524` ends with "`v_interp_p1lv_f16` still overrides `P_0` with the half decoded from `vsrc2` (`Gen.f16_in`)". There is no such override: the p1lv branch (`tools/rdna2spirv.py:11781-11800`) calls `attribute(...)` and, under `--f16-interp-fallback`, `attribute()` returns `ij_quad_eval` (`:15140` and `:15151`) built from the interpolated attribute and its derivatives; `Gen.f16_in` is never reached from a p1lv operand. I checked it by translating a computed-I/J p1lv pair with `v10 = 0` and with `v10 = 0x3f800000`: the two SPIR-V texts differ only in the dead `OpStore %reg_v10 ...` and the constant it stores, and `%reg_v10` is never loaded. The non-computed p1lv path behaves the same way (the store is dead there too), so this is inherited, but the sentence is new in this PR and a reviewer or a later change would rely on it. Effect: for a p1lv pair with a computed `(I, J)`, `P_0` is the interpolated attribute's vertex-0 value, not the supplied `vsrc2`; the corpus has 0 computed `*_f16` ops (the row says so), so no known shader is wrong today. Either implement the `vsrc2` override or drop that clause and add a semantic assertion that two different `vsrc2` constants give the same module, so the claim cannot creep back. **Finding: the lowering adds a `fragmentShaderBarycentric` requirement, and the row reads as if it adds none** `assemble()` sets `bary = ... or bool(gen.ij_deriv)` (`tools/rdna2spirv.py:16214`), so these modules load `BuiltIn BaryCoordKHR` and carry `OpCapability FragmentBarycentricKHR` + `SPV_KHR_fragment_shader_barycentric`. The index does record it - `features: ["fragmentShaderBarycentric"]` for the generated `ps_ij_computed.spv` - and both drivers act on it (MoltenVK has it, KosmicKrisp skips). But the row says the lowering declares "core Vulkan 1.0 `OpCapability DerivativeControl` (unconditional, zero `VkPhysicalDeviceFeatures` bits, zero extra `Location` slots)"; for the 207 shaders that previously required nothing under this flag, the module now requires `fragmentShaderBarycentric`. That is unavoidable (there is no other way to get `I`, `J` without per-vertex arrays), and `make_game.py` selecting `--f16-interp-fallback` where `per_vertex_inputs` is false means a device with neither `PerVertexKHR` nor plain barycentrics gets modules it cannot create a pipeline for - the same dead end as the old refusal, not a regression. It should be written down as a device requirement, though, because "zero `VkPhysicalDeviceFeatures` bits" is the phrase a follow-up will quote when deciding that this path needs no feature gate. **Nit**: the runner's skip under `--bary-fallback` now says `computed I/J pairs need PerVertexKHR inputs: no --bary-fallback`, which reads backwards ("no --bary-fallback" as the reason it cannot run, when it is the flag that is on). It only shows up on ANV-style fallback runs, but the old message named both flags and was clearer. **Not run**: Windows and the full corpus. The 26,503-shader count and the RTX 3090 result cannot be reproduced here (needs the game copy and Windows); what I can say is that on this machine all 278 GPU fixtures translate and validate, and the computed-pair fixture passes on the driver the flag targets. The change touches no runtime C++, so no shim or D3D12 test is affected, and I did not re-run the C++ suite. `python -I scripts/check_no_game_data.py` on all 11 changed files: clean. No game files. AI-assisted.
Author
Owner

@⁠zmasi on GitHub · 2026-11-26 23:49 UTC · original

Thanks @⁠EvgHaze, @⁠wavehs, @⁠lixonik, and @⁠ecox982745 for the Apple M3 / M3 Pro MoltenVK, KosmicKrisp, RTX 5070, and RTX 4090 hardware checks and detailed review.

Merged main (6f5086f2f) and pushed ae364461b addressing each point:

  1. v_interp_p1lv_f16 vsrc2 wording (docs/design.md, tests/semantic/test_interp_computed_ij_fallback.py): Removed the inaccurate vsrc2 override clause so docs/design.md matches the translator (P_0 comes from the interpolated attribute and vsrc2 is unread, as on the non-computed path; 0 computed *_f16 ops in the corpus), and added test_p1lv_f16_computed_ij_uses_interpolated_attribute_not_vsrc2 asserting %reg_v10 is unread and varying v10 (0 vs 0x3f800000) leaves module code and quad outputs invariant.
  2. Explicit fragmentShaderBarycentric device requirement (docs/design.md, tests/semantic/test_interp_computed_ij_fallback.py): Clarified in docs/design.md that the lowering emits OpCapability FragmentBarycentricKHR + SPV_KHR_fragment_shader_barycentric (features: ["fragmentShaderBarycentric"] in index.json for BuiltIn BaryCoordKHR), so devices need VK_KHR_fragment_shader_barycentric (passing natively on MoltenVK M3 / M3 Pro while skipping on drivers without VK_KHR_fragment_shader_barycentric such as KosmicKrisp), whereas DerivativeControl itself adds no extra VkPhysicalDeviceFeatures bit or Location slots; pinned FragmentBarycentricKHR and fragmentShaderBarycentric in the semantic assertions.
  3. --bary-fallback skip wording (scripts/run_gpu_tests.py, runtime/test/shaders/check.py, tests/test_run_gpu_tests.py): Updated both runners' --bary-fallback skip reason to SKIP (computed I/J pairs need PerVertexKHR inputs or BaryCoordKHR; unsupported under --bary-fallback).
  4. 1920x1080 perspective precision (docs/design.md, tests/semantic/test_interp_computed_ij_fallback.py): Added test_1080p_perspective_precision_subpixel_vs_full_viewport_jump (W = (1, 2.5, 4) at 1920x1080, including the (1794.5, 50.5) quad) and documented the error bound in docs/design.md. Because smooth fragment inputs and BaryCoordKHR arrive from the rasterizer already perspective-divided and rounded to binary32, 1-pixel quad differences scale ~1-ulp input rounding by hypot(alpha, beta): sub-pixel barycentric shifts (|alpha|, |beta| <= 1 px) stay within ~2e-6 across 1920x1080, while jumping ~1,000 pixels across the viewport to a constant (0.25, 0.25) amplifies binary32 rasterizer input quantization to 1.09e-3 (2.04e-3 / 1 f16 ulp on RTX 4090 hardware) — agreeing within < 2e-6 against an exact binary64 Jacobian solve on the same binary32 quad inputs.

No game files. AI-assisted.

**@⁠zmasi** on GitHub · 2026-11-26 23:49 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2239#issuecomment-7205899533) Thanks @⁠EvgHaze, @⁠wavehs, @⁠lixonik, and @⁠ecox982745 for the Apple M3 / M3 Pro MoltenVK, KosmicKrisp, RTX 5070, and RTX 4090 hardware checks and detailed review. Merged `main` (`6f5086f2f`) and pushed `ae364461b` addressing each point: 1. **`v_interp_p1lv_f16` `vsrc2` wording (`docs/design.md`, `tests/semantic/test_interp_computed_ij_fallback.py`):** Removed the inaccurate `vsrc2` override clause so `docs/design.md` matches the translator (`P_0` comes from the interpolated attribute and `vsrc2` is unread, as on the non-computed path; `0` computed `*_f16` ops in the corpus), and added `test_p1lv_f16_computed_ij_uses_interpolated_attribute_not_vsrc2` asserting `%reg_v10` is unread and varying `v10` (`0` vs `0x3f800000`) leaves module code and quad outputs invariant. 2. **Explicit `fragmentShaderBarycentric` device requirement (`docs/design.md`, `tests/semantic/test_interp_computed_ij_fallback.py`):** Clarified in `docs/design.md` that the lowering emits `OpCapability FragmentBarycentricKHR` + `SPV_KHR_fragment_shader_barycentric` (`features: ["fragmentShaderBarycentric"]` in `index.json` for `BuiltIn BaryCoordKHR`), so devices need `VK_KHR_fragment_shader_barycentric` (passing natively on MoltenVK M3 / M3 Pro while skipping on drivers without `VK_KHR_fragment_shader_barycentric` such as KosmicKrisp), whereas `DerivativeControl` itself adds no extra `VkPhysicalDeviceFeatures` bit or `Location` slots; pinned `FragmentBarycentricKHR` and `fragmentShaderBarycentric` in the semantic assertions. 3. **`--bary-fallback` skip wording (`scripts/run_gpu_tests.py`, `runtime/test/shaders/check.py`, `tests/test_run_gpu_tests.py`):** Updated both runners' `--bary-fallback` skip reason to `SKIP (computed I/J pairs need PerVertexKHR inputs or BaryCoordKHR; unsupported under --bary-fallback)`. 4. **`1920x1080` perspective precision (`docs/design.md`, `tests/semantic/test_interp_computed_ij_fallback.py`):** Added `test_1080p_perspective_precision_subpixel_vs_full_viewport_jump` (`W = (1, 2.5, 4)` at `1920x1080`, including the `(1794.5, 50.5)` quad) and documented the error bound in `docs/design.md`. Because smooth fragment inputs and `BaryCoordKHR` arrive from the rasterizer already perspective-divided and rounded to binary32, 1-pixel quad differences scale ~1-ulp input rounding by `hypot(alpha, beta)`: sub-pixel barycentric shifts (`|alpha|, |beta| <= 1` px) stay within `~2e-6` across `1920x1080`, while jumping ~1,000 pixels across the viewport to a constant `(0.25, 0.25)` amplifies binary32 rasterizer input quantization to `1.09e-3` (`2.04e-3` / `1` f16 ulp on RTX 4090 hardware) — agreeing within `< 2e-6` against an exact binary64 Jacobian solve on the same binary32 quad inputs. No game files. AI-assisted.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2239/head:github-bot/gh-2239'
git switch 'github-bot/gh-2239'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2239'
git switch 'github-bot/gh-2239'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2239'
git switch 'github-bot/gh-2239'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2239'
git switch 'main'
git merge --squash 'github-bot/gh-2239'
git switch 'main'
git merge --ff-only 'github-bot/gh-2239'
git switch 'main'
git merge 'github-bot/gh-2239'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.