Repository navigation
Conversation
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.
|
Apple check — this turns a skip into a real GPU pass on the one driver this fallback is for.
So on the device this rule exists for — KosmicKrisp is unchanged in both trees, which is correct rather than a regression: it has no
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. |
|
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
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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.pyon MoltenVK reportsper_vertex_inputs: false, sorun_gpu_tests.pyselects--f16-interp-fallbackby itself - noLEONIDA_F16_INTERP_FALLBACK=1needed, which is the honest macOS case.run_gpu_tests.py --filter ps_ij_computedon 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 oldor 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, then196 passed / 3 failed / 69 skippedof 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) isps_ij_computedmoving 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). Hereps_ij_computedskips withreads 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 is500 / 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.pyandtests/test_run_gpu_tests.py: OK.
Negative controls
- Revert only the implementation (
git checkout bdbc7e923 -- tools/rdna2spirv.py), keep the new test file: the new semantic file reportsFAILED (errors=4), and the GPU run becomesFAIL ps_ij_computed missing .spv (translation failed)- the oldcomputed I/J pair under --f16-interp-fallback: no PerVertexKHR inputsrefusal. Restored. - Sabotage the reconstruction: change
ij_quad_eval's I offset from%ij_icto%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. - Sabotage the determinant guard (
%ij_nz = OpLogicalAnd %bool %ij_dlo %ij_dlo, dropping the>= 0x7F800000upper bound): 2 failures in the new semantic file - the±inf/NaNdegenerate 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.
…and 1080p precision check
|
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
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.
|
Merged
No game files. AI-assisted. |
|
Tested the new 2048 × 2048 perspective case on a physical RTX 4090 (Windows, NVIDIA 616.64) at I translated the instruction list directly from
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 |
|
Thanks @ecox982745 for running the 2048×2048 perspective fixture on physical RTX 4090 hardware at AI-assisted. |
|
Apple check — merged onto No regression against
The failing set is identical on both revisions: One note on the head. AI-assisted. |
|
Thanks @EvgHaze for the Apple M3 MoltenVK 1.4.2 ( AI-assisted. |
|
Re-checked the merged head
The rest of the failing set is unchanged from Green from the Apple M3 side as far as this branch is concerned. AI-assisted. |
lixonik
left a comment
There was a problem hiding this comment.
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_evalcleanly lowers computed I/J barycentrics under--f16-interp-fallbackvia%entry2x2 screen-quad fine derivatives with integer-bit IEEE-754 normal-range guarding ondet(0x00800000 <= |det|_bits < 0x7F800000), leaving defaultPerVertexKHRand--bary-fallbackrefusal 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).
Claimed in the coordination issue as:
SHADER-F16-INTERP-COMPUTED-IJ(#1608 (comment))Depends on: #1426 (orthogonal topic: #1426 handles
--bary-fallbackwithFlat vec4[3]geometry-shader pass-through and leavesF16_HALVES and not BARY_FALLBACKrefused; listed here because adjacent hunk context intools/rdna2spirv.pyandtests/test_shader_build_fallbacks.pysits nearby on merge)What and why
When
per_vertex_inputsis unavailable and no geometry shader is used (--f16-interp-fallbackwithout--bary-fallback, e.g. on MoltenVK / Apple Silicon whereBuiltIn BaryCoordKHRis available withoutPerVertexKHRor geometry shaders),interp_ij_analysisintools/rdna2spirv.pyrefused 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 enablingsampleRateShadingand is rejected onBaryCoordKHRby SPIRV-Cross MSL.In real arithmetic, perspective-correct$(I, J)$ absorbs $1/W$ so every smooth-interpolated input $P$ (both standard $(I, J)$ across a $2 \times 2$ screen quad ($P = P_0 + I \cdot P_{10} + J \cdot P_{20}$ ). Under
BaryCoordKHRf32attributes and decoded--f16-interp-fallbackhalves) is affine inF16_HALVES and not BARY_FALLBACK(shortcut:inGen.ij_quad_eval):OpCapability FragmentBarycentricKHR+SPV_KHR_fragment_shader_barycentric(features: ["fragmentShaderBarycentric"]inindex.jsonforBuiltIn BaryCoordKHR) alongside core Vulkan 1.0OpCapability DerivativeControl(zero extraVkPhysicalDeviceFeaturesbits, zero extraLocations, zero geometry shader), hoistingOpDPdxFineandOpDPdyFineofBaryCoordKHR.y/.zand each computed(attribute, component)channel into uniform%entry.v_interpsite, including inside non-uniformEXEC-masked branches and loops.shortcut:error bound anddet == 0fallback: because%baryand 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 by1920x1080), while distant constant jumps across wide primitives scale with pixel span (e.g.1080pon[-2.75, 10], or2048-px perspective triangle withNaNdeterminants are guarded via integer IEEE-754 normal-range bit comparisons (0x00800000 <= (OpBitcast_u32(det) & 0x7FFFFFFF) < 0x7F800000, avoidingOpFDiv-by-zero and MoltenVK'sOpFOrdNotEqualNaN hazard) and return pixel-center--bary-fallback(BARY_FALLBACK) refusal and defaultPerVertexKHRemission completely unchanged.Tested
--f16-interp-fallback):26,296 / 26,503->26,503 / 26,503(100%) translated and26,503 / 26,503passspirv-val(--target-env vulkan1.2 --allow-offset-texture-operand); all207 / 207previously refused pixel shaders passspirv-val, remain byte-identical under default flags, and remain refused under--bary-fallbackalone.LEONIDA_F16_INTERP_FALLBACK=1 LEONIDA_BARY_FALLBACK=0,VK_LAYER_KHRONOS_validation1.4.363):runtime/test/shaders/build.py vs_ids ps_ij_computed ps_interp_f16_high vs_f16_pack:4/4translated,4/4spirv-valpass (OpCapability FragmentBarycentricKHR+OpCapability DerivativeControl, zeroPerVertexKHR).vk_pipeline_check:2/2PS modules ok,2/2PS pipelines ok,0validation errors.vk_harness vs_ids.spv ps_ij_computed.spv(64x64):4,096 / 4,096pixels pass (exact_xyw = 4096/4096,exact_z_bits = 4096/4096,max_err_z = 0.0);scripts/run_gpu_tests.py --filter ps_ij_computedpasses1/1(and independently verified natively on Apple M3 / M3 Pro MoltenVK and RTX 5070 / RTX 4090 in review comments below).python -m compileall -q make_game.py tools tests,tests/semantic/test_interp_computed_ij_fallback.py(including64x64,1920x1080, and2048x2048perspective finite-difference error bounds against a binary64 Jacobian oracle plus 1D line-primitivedet == 0fallback),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, andpython -I scripts/check_no_game_data.pyacross 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
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.