Skip to content

rdna2spirv: computed I/J pairs under --bary-fallback (SHADER-COMPUTED-IJ-NO-PERVERTEX) - #1426

Open
Dashhhhhhhh wants to merge 2 commits into
ProjectLeonida:mainfrom
Dashhhhhhhh:fix/computed-ij-no-pervertex
Open

Dashhhhhhhh wants to merge 2 commits into
ProjectLeonida:mainfrom
Dashhhhhhhh:fix/computed-ij-no-pervertex

Conversation

@Dashhhhhhhh

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: SHADER-COMPUTED-IJ-NO-PERVERTEX

Fixes: #1285

What and why

A GPU without PerVertexKHR inputs was translated with only --f16-interp-fallback. Every computed I/J pixel shader was then refused (computed I/J pair under --f16-interp-fallback / --bary-fallback), and the shaders stage stopped at 26,296 of 26,503. That is the RX 5700 XT report in #1285: geometry shaders are present, VK_KHR_fragment_shader_barycentric is not.

--bary-fallback now keeps those attributes. Each one is a Flat vec4[3] at three free locations, recorded as bary_fallback_input.per_vertex. The pass-through geometry shader writes vertex k's value into element k, and the pixel shader weights them the same way as the PerVertexKHR path: P0 + I·(P1 − P0) + J·(P2 − P0). --f16-interp-fallback alone still refuses them. That is the MoltenVK case, which has no geometry stage.

make_game.py turns --bary-fallback on together with --f16-interp-fallback when per_vertex_inputs is false and geometry_shader is true. LEONIDA_BARY_FALLBACK=0 still forces the native path. A GPU with no geometry stage stays on the f16 fallback alone.

This is the translator half of draft #120 (old PR 9855), rebased onto current main because that draft no longer merges, plus the make_game selection #1285 needs. #120 by itself left the automatic f16-only path refusing the same 207 shaders.

Tested

  • python -I scripts/run_semantic_tests.py tests/semantic -p test_interp_computed_ij.py — 28 tests, 0 failed
  • python -I scripts/run_semantic_tests.py tests/semantic -p 'test_interp*.py' — 14 files, 211 tests, 0 failed
  • python -I scripts/run_semantic_tests.py tests/semantic -p 'test_bary*.py' and -p 'test_f16_interp*.py' — 0 failed
  • python -I tests/test_shader_build_fallbacks.py, tests/test_run_gpu_tests.py, tests/test_vk_subgroup_info.py, tests/test_make_game_translator_flags.py, tests/test_make_game_argparse.py, tests/test_make_game_wave64.py
  • No game files. spirv-val is not installed here, so test_geometry_shader_validates was skipped.

GPUs tested: n/a (Apple M4, MoltenVK not installed; the geometry-shader path needs a device with geometry shaders)

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.

Made with Cursor

Those pixel shaders were refused under both fallbacks, so the shaders stage stopped on a geometry-capable GPU without fragmentShaderBarycentric. The barycentric fallback now supplies the three vertex values, and make_game selects it there.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ecox982745

Copy link
Copy Markdown

I ran the computed-I/J fixture on the RTX 4090 (Windows 11, NVIDIA 616.64) at b9191a31, using vk_harness built from that head. The geometry fallback produced the same frame as native barycentric interpolation. I also checked all four channels independently against the fixture's expected RGBA at every pixel.

Mode on PR head Result for vs_ids + ps_ij_computed
Native per-vertex inputs 4,096/4,096 pixels matched bit for bit
Forced --bary-fallback, generated geometry shader bound 4,096/4,096 matched
Forced --bary-fallback --f16-interp-fallback, generated geometry shader bound 4,096/4,096 matched
--f16-interp-fallback alone Builder skipped the fixture as expected

On the PR base 9c5e7066, the fixture builder also skipped it with both fallbacks enabled. On the head, every module used for the three draws passed spirv-val --target-env vulkan1.2. Disassembling the two fallback fragment modules confirmed neither declared the fragment barycentric extension, its capability, or a per-vertex input decoration. The native fragment module declared all three.

All 28 focused CPU/translator tests passed, including test_geometry_shader_validates, with no skips. The RTX supports native barycentrics, so this verifies a forced fallback with synthetic inputs. Automatic selection and the originally reported shader set on the RX 5700 XT still need checking on that setup. AI-assisted verification.

@GeorgiyDemo

Copy link
Copy Markdown
Contributor

Tested b9191a318 on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 364ab4eab (translator/tooling PR; GPU binaries from the build at 66d4f5aa3):

  • tests/semantic/test_interp_computed_ij.py (run from tests/semantic): 28/28 OK at this head; the same file on main errors 12 of 28, so the computed-I/J and bary-fallback cases are new coverage.
  • tests/test_make_game_translator_flags.py, tests/test_run_gpu_tests.py, tests/test_shader_build_fallbacks.py, tests/test_vk_subgroup_info.py: all OK (unittest).
  • GPU: --filter ps_ij_computed still SKIPs by default ("computed I/J pairs need per-vertex inputs: --f16-interp-fallback without --bary-fallback"). Forced with LEONIDA_BARY_FALLBACK=1, the translator emits ps_ij_computed.bary_gs.spv and it passes spirv-val, but the run then SKIPs with unsupported: no geometryShader — Apple's Vulkan drivers have no geometry stage, so this path cannot be executed here (same limitation as #9855).
  • What this does not show: the fallback rendering itself on a GPU with geometry shaders.

AI-assisted; synthetic fixtures only, no game data.

@mrgenty

mrgenty commented Nov 26, 2026

Copy link
Copy Markdown

This conflicts with main now. I resolved it in #1930's base (merge commit 52d6df8b), in case it saves you time:

  • tools/vk_subgroup_info.py: main added the check that per_vertex counts only when VK_KHR_fragment_shader_barycentric is in the device's extension list (RADV sets the feature on gfx90c without it). I kept that check after your unpack with geometry_shader, and merged the two docstring paragraphs.
  • docs/design.md: in each conflicting row only one side had changed. I took main's "Mixed flat and smooth f32 reads" row and its new "Wave64 emulation: cross-lane reads of missing lanes" row, and your "Computed I/J barycentrics" and "Barycentric fallback" rows.

On that tree (main 73516a29 + #1497 + this PR), on an RTX 3060: test_vk_subgroup_info.py, test_make_game_translator_flags.py and test_interp_computed_ij.py pass, and so does run_semantic_tests.py (498 files, 6,357 tests, 0 failed).

@qhukz13

qhukz13 commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Tested the translator half on a retail corpus (1.0.2.1) with the Pascal flag set, since the PR could not be checked on a GPU with geometry shaders.

RUN: make_game.py --stages check,shaders,runtime --wave64-emulate auto --mesh-compute --bary-fallback on mandy main d442851 (translator flags written by the stage: --bary-fallback --mesh-compute --f16-interp-fallback), llvm-mc 21.1.8, 20 jobs.

  • MEASURED, main: the shaders stage stops at 26,296 of 26,503. All 207 refusals are pixel shaders with the single reason computed I/J pair under --bary-fallback: no PerVertexKHR inputs (rerun of just those 207 with the same flags; nothing else in the list).
  • MEASURED, this PR (e7987db merged onto main 431ceba locally; only tools/rdna2spirv.py and tools/bary_fallback_gs.py used): the same 207 with the same flags give 207 translated, 207 pass spirv-val.
  • MEASURED: all 207 are wave64 pixel shaders and all land in wave64 tier C on 32-wide subgroups (wave64_graphics_reasons in the index), so on Pascal they would also be inexact for that reason, independent of this PR.
  • NOT TESTED: rendering. With main's runtime the per-vertex Flat vec4[3] inputs still need the geometry stage to feed them (runtime/d3d12: the --bary-fallback geometry stage feeds computed I/J pairs (RT-BARY-FALLBACK-PER-VERTEX) #1930, which is also conflicting), so I did not boot with these modules.
  • READ IN CODE: against current main the merge conflicts in tools/vk_subgroup_info.py and docs/design.md; tools/rdna2spirv.py merges cleanly.

GPUs tested: GTX 1050 Ti 4 GB (Pascal, profile S), driver 582.66, Windows 10 — translation and spirv-val only, no GPU run of these modules.

AI-assisted (Claude Code).

@MoonEyes

Copy link
Copy Markdown
Collaborator

Hi @Dashhhhhhhh, thanks for this pull request. It currently conflicts with main (conflicting file(s): docs/design.md, tools/vk_subgroup_info.py), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

@ecox982745

Copy link
Copy Markdown

@Dashhhhhhhh @mrgenty — I tested a fix for the sparse varying-location report. Commit d1361e9c4f applies independently to this PR at b9191a3186 and to #1930 at c6aa38942e. Either branch can take that single commit. The change searches until it finds three consecutive free locations and keeps the existing lowest-location policy.

With scalar inputs at 0, 1, 2, 4, 6 and 8, the old allocator raises StopIteration. The new allocator puts the two per-vertex inputs at 9–11 and 12–14 and leaves location 3 for barycentric weights.

  • CPU. Of 256 synthetic layouts with two per-vertex arrays, the old translator finished 150. The fix finished all 256, matched an independent first-fit check for every allocation, and produced identical SPIR-V assembly and metadata for the original 150. The full semantic suite on this PR plus the fix passed 6,230 tests across 476 files. The focused suite passed 29/29 on both patched parents.
  • RTX 4090, Windows 11, NVIDIA 616.64. I drew the sparse fixture with this PR’s Python-generated geometry shader, then with the runtime C++ geometry-shader builder from runtime/d3d12: the --bary-fallback geometry stage feeds computed I/J pairs (RT-BARY-FALLBACK-PER-VERTEX) #1930. Each path ran with --bary-fallback alone and with --f16-interp-fallback added. All 16,384 pixels across the four draws returned the expected RGBA (21, 7, 1, 8). The modules passed SPIR-V validation for Vulkan 1.2 and 1.3. The draws emitted no Khronos validation messages.

AI-assisted fix and synthetic hardware verification using OpenAI Codex (GPT-6).

@mrgenty

mrgenty commented Nov 28, 2026

Copy link
Copy Markdown

@ecox982745 thanks, I took d1361e9c into #1930 unchanged (9a51aff6d), with main merged. It still applies here as you say.

@enlight3d

Copy link
Copy Markdown
Contributor

Run on RTX 3090 (PR head only, because it conflicts with main)

  • Heads: PR head b9191a3, main 8fb9748. The merge conflicts in docs/design.md, runtime/test/shaders/build.py and runtime/test/shaders/check.py, so I tested the PR head as it is (detached, not merged).
  • These are Python tests (no ctest entry, no GPU test program). Python 3.13, from the repo root, each with python -I:
    • scripts/run_semantic_tests.py tests/semantic -p test_interp_computed_ij.py: 28 tests, 0 failed
    • ... -p "test_interp*.py": 14 files, 211 tests, 0 failed; -p "test_bary*.py": 15 tests, 0 failed; -p "test_f16_interp*.py": 15 tests, 0 failed
    • tests/test_shader_build_fallbacks.py (7), tests/test_run_gpu_tests.py (65), tests/test_vk_subgroup_info.py (55), tests/test_make_game_translator_flags.py (34), tests/test_make_game_argparse.py (38), tests/test_make_game_wave64.py (38): all OK. spirv-val is installed here (Vulkan SDK) and no test was reported as skipped.
  • Red: same head with the non-test files put back to the merge-base version (docs/, make_game.py, runtime/test/shaders/build.py and check.py, scripts/run_gpu_tests.py, tools/bary_fallback_gs.py, tools/rdna2spirv.py, tools/vk_subgroup_info.py; the tests/ files kept), same commands:
    • Behavioural: test_interp_computed_ij fails 12 of 28 tests with "computed I/J pair under --bary-fallback: no PerVertexKHR inputs", the refusal the PR removes; test_shader_build_fallbacks (3 failures) and test_run_gpu_tests (5 failures) fail on the old skip rules for ps_ij_computed.
    • New API only: test_vk_subgroup_info (no FEATURES2_GEOMETRY_SHADER) and test_make_game_translator_flags (no runtime_gpu_geometry_shader) fail because the new names do not exist without the change.
    • Still green with the change reverted: test_bary*, test_f16_interp*, test_make_game_argparse, test_make_game_wave64 (they do not cover the change).
    • With the PR's change back, all of the above pass again.
  • Not run: the GPU side (ps_ij_computed through run_gpu_tests.py with LEONIDA_BARY_FALLBACK=1). It needs llvm-mc, which this machine does not have (neither native nor in WSL), and ps_ij_computed has no pre-disassembled fixture for --disasm-dir. The geometry-shader path was therefore not drawn on a GPU here.
  • Link: this PR changes no runtime C++ source (only Python and runtime/test/shaders/*.py). gta6rt.exe built from the PR head, imports compared with a plain main build (dumpbin /imports, DLL!symbol): one entry differs, api-ms-win-crt-stdio-l1-1-0.dll!__stdio_common_vswscanf; it comes from the older base of this branch (runtime/src/base_reservation.h calls a scanf function there; main does not), not from the PR. No new imports from this PR.
  • Machine: RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro 10.0.26300, MSVC 19.44.

The branch is 4161 commits behind main; could you merge main into it when you have a moment? Thanks.

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

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

7 participants