Skip to content

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

Open
zmasi wants to merge 7 commits into
ProjectLeonida:mainfrom
zmasi:fix/rdna2spirv-f16-interp-computed-ij
Open

zmasi wants to merge 7 commits into
ProjectLeonida:mainfrom
zmasi:fix/rdna2spirv-f16-interp-computed-ij

Conversation

@zmasi

@zmasi zmasi commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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

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.

In real arithmetic, perspective-correct BaryCoordKHR $(I, J)$ absorbs $1/W$ so every smooth-interpolated input $P$ (both standard f32 attributes and decoded --f16-interp-fallback halves) is affine in $(I, J)$ across a $2 \times 2$ screen quad ($P = P_0 + I \cdot P_{10} + J \cdot P_{20}$). Under F16_HALVES and not BARY_FALLBACK (shortcut: in Gen.ij_quad_eval):

  • Declares OpCapability FragmentBarycentricKHR + SPV_KHR_fragment_shader_barycentric (features: ["fragmentShaderBarycentric"] in index.json for BuiltIn BaryCoordKHR) alongside core Vulkan 1.0 OpCapability DerivativeControl (zero extra VkPhysicalDeviceFeatures bits, zero extra Locations, zero geometry shader), hoisting OpDPdxFine and OpDPdyFine of BaryCoordKHR.y/.z and each computed (attribute, component) channel into uniform %entry.
  • Evaluates $P(I', J') \approx 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.
  • Documented shortcut: error bound and det == 0 fallback: because %bary and smooth fragment inputs arrive quantized to binary32 (per-lane residual $|e_q| \le \frac{1}{2}\operatorname{ulp}(P_q) + |P_{10}|\frac{1}{2}\operatorname{ulp}(I_q) + |P_{20}|\frac{1}{2}\operatorname{ulp}(J_q)$), 1-pixel quad finite differences amplify input rounding by $1 + 2|\alpha| + 2|\beta|$ ($\alpha \approx (I' - I_c) / (\partial I / \partial x)$, proportional to pixel step up to the primitive's pixel span): sub-pixel shifts ($|\alpha|, |\beta| \le 1$ px) stay near input precision ($\sim 2 \times 10^{-6}$ at 1920x1080), while distant constant jumps across wide primitives scale with pixel span (e.g. $2.04 \times 10^{-3}$ / $1$ f16 ulp at 1080p on [-2.75, 10], or $0.358$ / $&gt;300$ f16 ulps when jumping $&gt;1,100$ px to $(0, 0)$ across a 2048-px perspective triangle with $P \in [1.5, 4096]$). Degenerate zero-area, 1D/line-primitive (constant $J \implies \det = 0$), subnormal, $\pm\infty$, and NaN determinants are guarded via integer IEEE-754 normal-range bit comparisons (0x00800000 <= (OpBitcast_u32(det) & 0x7FFFFFFF) < 0x7F800000, avoiding OpFDiv-by-zero and MoltenVK's OpFOrdNotEqual NaN hazard) and return pixel-center $P_c$.
  • 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 (and independently verified natively on Apple M3 / M3 Pro MoltenVK and RTX 5070 / RTX 4090 in review comments below).
  • Translator & unit suites: python -m compileall -q make_game.py tools tests, tests/semantic/test_interp_computed_ij_fallback.py (including 64x64, 1920x1080, and 2048x2048 perspective finite-difference error bounds against a binary64 Jacobian oracle plus 1D line-primitive det == 0 fallback), tests/semantic/test_interp*.py, tests/test_shader_build_fallbacks.py, tests/test_run_gpu_tests.py, tests/test_text_write_line_endings.py, tests/test_docs_links.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 (Profile L)

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.

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

EvgHaze commented Nov 26, 2026

Copy link
Copy Markdown

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.

@ecox982745

Copy link
Copy Markdown

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.

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@wavehs wavehs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@zmasi

zmasi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

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.

…e det==0 fallback

- Mark Gen.ij_quad_eval with shortcut: in tools/rdna2spirv.py and update docs/design.md
  to state that binary32 quad finite differences amplify rasterizer input rounding by
  (1 + 2|alpha| + 2|beta|) (~|i - I_c| / |dI/dx| up to primitive pixel span) and that
  det == 0 (including 1D/line primitives with constant J) falls back to P_c.
- Tighten test_perspective_fixture_branch_and_f16_halves against a binary64 Jacobian
  oracle and add test_wide_2048px_perspective_extrapolation_bound_and_line_det_zero_fallback
  covering a 2048px perspective triangle (P in [1.5, 4096.0]) and line det == 0 fallback.
@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Merged main and pushed a5d954a4a before marking this PR ready for review:

  • Added an explicit # shortcut: note on Gen.ij_quad_eval (tools/rdna2spirv.py) and updated docs/design.md to state the (1 + 2|alpha| + 2|beta|) * m_ulp binary32 quad finite-difference amplification bound (alpha ~ (i - I_c) / (dI/dx), proportional to pixel step up to the primitive's pixel span) and that det == 0 (including 1D/line primitives where J is constant across the quad) returns pixel-center P_c rather than extrapolating along one axis.
  • Tightened test_perspective_fixture_branch_and_f16_halves against an independent binary64 Jacobian oracle and added test_wide_2048px_perspective_extrapolation_bound_and_line_det_zero_fallback covering a 2048-px perspective triangle (P in [1.5, 4096.0]) and 1D line det == 0 fallback (255/255 semantic interp tests pass locally, and ps_ij_computed passes on the macOS MoltenVK CI runner).

No game files. AI-assisted.

@zmasi
zmasi marked this pull request as ready for review November 28, 2026 09:33
@ecox982745

Copy link
Copy Markdown

Tested the new 2048 × 2048 perspective case on a physical RTX 4090 (Windows, NVIDIA 616.64) at a5d954a4a789591ec57330ced9705096fedefba0. The local interpolation target stayed within 0.00141 of the analytical value throughout the triangle. A jump back to vertex 0 showed a much larger error on the derivative fallback.

I translated the instruction list directly from test_wide_2048px_perspective_extrapolation_bound_and_line_det_zero_fallback in each mode. A synthetic vertex shader supplied the test's W values (1, 1.3, 1.7) and attributes (1.5, 4096, 5.5), using packed or decoded halves as appropriate. I built vk_harness from the same revision. Both modes covered the same 2,096,128 interior pixels, with the clear value everywhere else. Two draws per mode produced byte-identical RGBA32F readbacks within that mode.

Maximum absolute error across covered pixels Native barycentrics Derivative fallback
Subpixel offset, f32 0.000897 0.001409
Jump to vertex 0, f32 (expected 1.5) 0 1.187353
Jump to vertex 0, decoded f16 (expected 1.5) 0 1.187500

At pixel (1993, 39), native returned 1.5 in both distant-target channels. The fallback returned 2.687353 and 2.6875. The distant-target f32 error exceeded 0.30 at 105,661 pixels (5.04%). The subpixel reference uses binary64 perspective-correct barycentrics with the vertex shader's binary32 W values and the fixture's (+2^-12, -2^-12) shift.

The nine CPU tests in test_interp_computed_ij_fallback passed. Both vertex and both fragment modules passed spirv-val for Vulkan 1.2. The GPU test covered the triangle case. The degenerate-line case was checked on CPU. These figures describe this high-range synthetic input on one NVIDIA driver. AI-assisted with OpenAI Codex (GPT-6).

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @ecox982745 for running the 2048×2048 perspective fixture on physical RTX 4090 hardware at a5d954a4a and sharing the exact readback figures! Seeing 0.001409 peak error (< 2e-3) across all 2,096,128 covered pixels for the (+2^-12, -2^-12) subpixel shift alongside 1.187353 (1.1875 decoded f16) on the full-viewport jump back to vertex 0 directly confirms the # shortcut: local-linear vs wide-perspective extrapolation regime on silicon. The ~3.3x factor over the pure IEEE-754 0.5-ulp finite-difference residual at 2048 px aligns cleanly with hardware fixed-point barycentric quantization before quad differencing.

AI-assisted.

@EvgHaze

EvgHaze commented Nov 28, 2026

Copy link
Copy Markdown

Apple check — merged onto main (f96cec8cc), M3, both drivers.

Machine:  Apple M3 (Mac15,13), 8 cores
OS:       macOS 27.0 (26A5406e), arm64
Drivers:  MoltenVK 1.4.2, Mesa 26.3.1 (KosmicKrisp)
Commit:   f96cec8cc Merge branch 'pr-2239-check' into try-2239
          (main 5b6ffd5a8 + this branch a5d954a4, merged cleanly)
Tools:    llvm-mc 23.1.6, spirv-val 2026.4, cmake 4.4.4, python 3.13.7

Build:    ok
Semantic: 507 files, 6409 tests, 0 files failed in 207 s with 8 jobs
GPU:      MoltenVK   198/271 passed, 71 skipped
          KosmicKrisp 190/271 passed, 75 skipped

No regression against main (5b6ffd5a8) on either driver:

main this branch on main
Semantic 506 files / 6 400 tests / 0 failed 507 files / 6 409 tests / 0 failed
MoltenVK 197 passed, 72 skipped 198 passed, 71 skipped
KosmicKrisp 190 passed, 75 skipped 190 passed, 75 skipped

The failing set is identical on both revisions: cs_imgatomic_ext and ps_ssharp on MoltenVK; cs_bvh, cs_bvh32, cs_fma_fused, cs_imgatomic_ext, ps_cndmask_sign_mods, ps_valu16_mad_sel on KosmicKrisp. The new ps_ij computed-derivative fallback fixture passes on both drivers, and it accounts for the one extra semantic file and the six extra tests.

One note on the head. a5d954a4 is 213 commits behind main and predates #1724, which rewrote cs_fma_fused's f16 operands to be read at run time. At that head cs_fma_fused fails on MoltenVK in 3 of 3 runs (word 7 (f16): got 0x00000000), while main passes it in 3 of 3 — so it is staleness of the branch, not this change. Merging the current main in cleared it (the merge applied without conflicts), and the numbers above are from that merged state. A rebase before merge would keep CI and reviewers on the same footing.

AI-assisted.

@zmasi

zmasi commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @EvgHaze for the Apple M3 MoltenVK 1.4.2 (198/271 passed, 71 skipped) and KosmicKrisp 26.3.1 re-verification and for flagging the pre-#1724 cs_fma_fused staleness! Merged current main (6647c033a, including #1724) cleanly in f77b4d80d (9/9 test_interp_computed_ij_fallback.py passed, zero code changes beyond the fast-forward merge).

AI-assisted.

@EvgHaze

EvgHaze commented Nov 28, 2026

Copy link
Copy Markdown

Re-checked the merged head f77b4d80d (current main + this branch, #1724 included). The pre-#1724 staleness is gone.

Machine:  Apple M3 (Mac15,13), 8 cores
OS:       macOS 27.0 (26A5406e), arm64
Drivers:  MoltenVK 1.4.2, Mesa 26.3.1 (KosmicKrisp)
Commit:   f77b4d80d Merge remote-tracking branch 'origin/main' into fix/rdna2spirv-f16-interp-computed-ij
          (0 commits behind main at the time of the run)
Tools:    llvm-mc 23.1.6, spirv-val 2026.4, cmake 4.4.4, python 3.13.7

Build:    ok
Semantic: 508 files, 6414 tests, 0 files failed in 164 s with 8 jobs
GPU:      MoltenVK   198/271 passed, 71 skipped
          KosmicKrisp 190/271 passed, 75 skipped

cs_fma_fused on MoltenVK: passed 3 of 3 runs at f77b4d80d (it passed 3/3 on main and failed 3/3 at the old head a5d954a4), so the earlier failure was the missing #1724 fixture update and nothing in this change. The KosmicKrisp side still reads 0x7352 for the f16 word, which is the expected divergence that docs/testing.md documents for Mesa 26.3.1 on this machine — the same as on main.

The rest of the failing set is unchanged from main and unrelated to this PR: cs_imgatomic_ext and ps_ssharp on MoltenVK; cs_bvh, cs_bvh32, cs_fma_fused, cs_imgatomic_ext, ps_cndmask_sign_mods, ps_valu16_mad_sel on KosmicKrisp. The new ps_ij fallback fixture (test_interp_computed_ij_fallback.py) passes on both drivers, in the suite and in the semantic run.

Green from the Apple M3 side as far as this branch is concerned.

AI-assisted.

@lixonik lixonik left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed and verified the updated head f77b4d80d (incorporating the review updates and main merge including #1724).

Code audit:

  • tools/rdna2spirv.py: Gen.ij_quad_eval cleanly lowers computed I/J barycentrics under --f16-interp-fallback via %entry 2x2 screen-quad fine derivatives with integer-bit IEEE-754 normal-range guarding on det (0x00800000 <= |det|_bits < 0x7F800000), leaving default PerVertexKHR and --bary-fallback refusal behavior unchanged.

Verification (Windows 11, Python 3.12, llvm-mc LLVM 21.1.8, spirv-as / spirv-val Vulkan SDK 1.4.363.1):

  • python tests/semantic/test_interp_computed_ij.py -v: 22/22 passed.
  • python tests/semantic/test_interp_computed_ij_fallback.py -v: 9/9 passed.
  • python -I tests/test_shader_build_fallbacks.py -v: 7/7 passed.
  • python -I tests/test_run_gpu_tests.py -v: 75/75 passed.
  • python -I scripts/check_no_game_data.py: passed.

AI-assisted (Antigravity, Gemini).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants