Skip to content

rdna2spirv: number GS varyings by rank past SV_Position, as the VS and PS do - #5199

Open
Pipodi wants to merge 2 commits into
ItsNotRexed:mainfrom
Pipodi:pass-pipelines
Open

Pipodi wants to merge 2 commits into
ItsNotRexed:mainfrom
Pipodi:pass-pipelines

Conversation

@Pipodi

@Pipodi Pipodi commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new SHADER item, building the graphics pipelines the effect database defines (claim). This PR is the translator fix that item turned up.

Depends on: #4670, #2086, #4913, #5123: no code dependency, only small textual conflicts: #4670 (the test_spirv_gs_to_compute.py layout line), #2086 (rdna2spirv.py, next to the GS block), #4913 (the design.md Geometry shaders row) and #5123 (next to gs_container in build.py). Whichever lands second needs a one-line merge.

What and why

A translated geometry shader decorated each varying with its signature register as its Location. That register counts SV_Position as register 0. The translated VS numbers its outputs by param export index, and the PS its inputs by attribute index, both from 0. So every VS → GS → PS chain was one location off on both sides: the GS read the VS's second varying, and the PS read nothing from the GS.

I found it by pairing programs the way the game does. Every stored SGD5 pass (tools/sgd5_effects.py, docs/sgd5_render_states.md) names its VS/MS (+GS) + PS. I ran tools/shader_link_check.py batch over the 16,325 distinct programme sets with a PS: 301 were incompatible, exactly all the VS+GS+PS sets, with missing-output at gs→ps location 0 and vs→gs location 1.

The fix: a GS input or output varying gets its rank among the signature's non-position registers. gs_input_locations / gs_output_locations in the metadata (read by spirv_stubs.py and spirv_gs_to_compute.py) follow. All 195 GS in the corpus have SV_Position in register 0 and their varyings from register 1, so for them this is register − 1.

The GPU fixtures were written around the old numbering:

  • gs_tri drew with a PS reading location 1. It now uses fs_passthru (location 0). The expected image is unchanged: the GS copies only .xy.
  • The gs_w64_* fixtures read the vertex number vs_ids sends in param1. build.py's gs_container adds a TEXCOORD1 input in register 2, which becomes Location 1, and the fixtures read it there (offset 32). tests/conftest.py mirrors it.

A new test, test_gs_locations_are_ranks_past_the_position, checks registers 1-2 in and 1, 3 out → locations 0-1 on both sides. The packed-register test now expects location 0.

Tested

Windows 11, RTX 4090, NVIDIA 617.42; own 1.0.2.1 copy; LLVM 23.1.5 (llvm-mc). Base: main 3faac55; head 5e576db (the corpus run is at d3d0a1e; 5e576db changes only docs and a comment).

  • Full corpus, base 3faac55 vs this branch d3d0a1e: 26503 translated, 26503 pass spirv-val on both. 0 lost, 0 new, wave64 23,841 both, no flips. Exactly 195 .spv change, all of them GS.
  • shader_link_check.py batch over the 16,325 distinct SGD5 programme sets: base 16,024 compatible, 301 incompatible; this branch 16,325 compatible, 0 incompatible, 0 invalid.
  • python -m pytest tests/test_translate.py tests/test_spirv_gs_to_compute.py tests/test_spirv_gs_to_compute_bounds.py tests/test_wave64_halves_fixtures.py tests/test_fssm_wave_size.py tests/test_wave64_graphics_scan.py: 652 passed.
  • python -I -m unittest discover -s tests/semantic: 6,245 tests. The 5 failures/errors are all in test_loop_ballot_barrier.py (wave64 emulation) and fail the same way on unchanged main 3faac55.
  • GPU, RTX 4090 / NVIDIA 617.42: run_gpu_tests.py --filter gs_ → gs_tri 4096/4096 pixels exact; w64_graphics.py → gs_w64_a_ring ok, gs_w64_c_lane_id skipped (tier C needs a device that can require both 32 and 64; NVIDIA can't).
  • Independent run by @gertify on an AMD Radeon 610M, RADV / Mesa 26.2.6 (subgroup 32..64), Linux (comment): gs_tri 4096/4096 exact, with a negative control showing the device filter applied; w64_graphics.py 27/27 ok, including gs_w64_c_lane_id (tier C); the same 652 pytest tests pass.

AI-assisted: yes (Claude Code).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. Counts only; the fixtures are hand-written.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed: the Geometry shaders row, confirmed by the corpus link check above and the GPU tests.

🤖 Generated with Claude Code

Pipodi and others added 2 commits November 23, 2026 09:43
…d PS do

A geometry shader decorated each varying with its signature register, which
counts SV_Position as register 0, while the translated VS numbers its param
exports and the PS its attribute reads from 0. Every VS+GS+PS programme set
the SGD5 effect databases name (301 distinct) failed shader_link_check.py:
missing output at gs->ps location 0 and vs->gs location 1. The GS now takes
each varying's rank among the non-position registers, on both sides, and the
gs_input_locations / gs_output_locations metadata follow.

The GPU fixtures were written around the old numbering: gs_tri now draws
with fs_passthru (location 0), and the gs_w64_* fixtures, which read vs_ids's
param1, get a TEXCOORD1 input in register 2 (build.py gs_container) and read
it there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…inst; gs_tri draws after vs_tri

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested 5e576db on AMD Radeon 610M (RADV, Mesa 26.2.6, subgroup 32..64), Linux: run_gpu_tests.py --filter gs_ with LEONIDA_VK_DEVICE=RADV passes gs_tri 4096/4096 pixels exact, and a nonexistent device name fails it with "no Vulkan physical device matches", so the filter applied. runtime/test/shaders/w64_graphics.py prints 27 fixture lines, all ok, including gs_w64_a_ring (tier A) and gs_w64_c_lane_id (tier C). tests/test_translate.py plus the GS-to-compute, wave64 halves, FSSM wave size and wave64 graphics scan suites give 652 passed. The PR's NVIDIA run was not repeated.

AI-assisted.

@Pipodi

Pipodi commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @gertify. Your RADV run covers what the RTX 4090 couldn't: gs_w64_c_lane_id is tier C and needs both wave sizes, and it passes on the 610M. The control with a nonexistent device name is a good touch. Added to the Tested section.

AI-assisted (Claude Code).

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

Ran this at 5e576dbe8 on Windows 11, RTX 5070 Ti.

  • tests/test_translate.py with LLVM_MC -> 597 passed; tests/test_spirv_gs_to_compute.py -> 16 passed.
  • GPU: run_gpu_tests.py --filter gs_tri -> 1/1 passed, gs_tri -> 4096/4096 pixels exact; the run reports wave64 VS/PS/GS on 32-wide subgroups: tier A: 1; translator 1/1 + spirv-val.
  • git diff --check clean.

GS varyings are now numbered by rank past SV_Position, matching how the VS and PS number their outputs/inputs, instead of the previous flat sequence; the gs_tri/gs_w64_* fixtures and the docs row were updated together, and the geometry draw still matches every pixel. No blocking issue.

@Rainmaker33

Copy link
Copy Markdown

Tested 5e576dbe (applied on main 3faac55) on an RTX 3090 (Ampere, 32-wide subgroups), driver 610.88, Windows 11, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8: pass.

  • run_gpu_tests.py, whole suite: 170/217 passed, 47 skipped (wave64), 0 failures. That matches main here. gs_tri is 4096/4096 pixels exact.
  • w64_graphics.py: gs_w64_a_ring tier A is ok, and so are the tier A/B vs_w64_* rows. gs_w64_c_lane_id skips as tier C on a 32-only device, the same as on main.

pytest isn't installed here, so I didn't run tests/test_spirv_gs_to_compute.py or test_translate.py.

AI-assisted (Claude Code).

@kacper-serewis kacper-serewis 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.

At 5e576db all 195 cached geometry shaders translated and passed Vulkan 1.2 spirv-val on both revisions. Against independently decoded DXBC signature ranks, correct input location maps improved from 5/195 to 195/195 and output maps from 0/195 to 195/195. All six GS regression tests passed. The 301 program combinations were not replayed. A synthetic SV_RenderTargetArrayIndex still received an ordinary location, consistent with the documented limitation. Position was the only system value in the 195 cached signatures.

AI-assisted independent CPU review.

@lunarminus

Copy link
Copy Markdown

Tested 5e576dbe merged onto main d0835dd9 on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: pass

  • Tree: d0835dd9 is an ancestor of the head, so the merge was a fast-forward. The tree tested is exactly 5e576dbe (main 3faac557 plus this PR).
  • Control: a worktree at 3faac557 without the PR, using the same test programs. The PR changes no C++.
  • Runtime build: built at the head (cmake --build runtime/build/linux --parallel 2, RelWithDebInfo).
  • scripts/run_gpu_tests.py: 202/217 passed, 15 skipped, 0 failed, in both modes (LEONIDA_W64_EMULATE unset and =1).
    • Against 3faac557 without the PR: no test differs in either mode.
    • Against d0835dd9 without the PR (196/210, 14 skipped): no test present in both runs changed result. The 7 extra names come from main and match on the 3faac557 control: cs_smem_sconst_off, ps_far_branch, ps_sample_c, ps_sample_c_b, ps_texture_b_cl and ps_texture_cl pass, ps_m2_literal is skipped.
    • gs_tri passes 4096/4096 pixels exact in both modes, now drawn with fs_passthru.
  • --filter gs_ with LEONIDA_VK_DEVICE=RADV: 1/1 (gs_tri 4096/4096). As a control, LEONIDA_VK_DEVICE=NoSuchGPU fails with "no Vulkan physical device matches".
  • runtime/test/shaders/w64_graphics.py: fixtures built with this PR's build.py, run with the head vk_harness: 27/27 ok.
    • This includes gs_w64_a_ring (tier A) and gs_w64_c_lane_id (tier C, which runs only when 64 and 32 can both be required; otherwise the script prints SKIP).
    • The output is identical on the 3faac557 control.
    • In the PR's gs_w64_c_lane_id SPIR-V, the inputs are Location 0 and 1 and the output is Location 0. On the control, the input and output are both Location 1.
  • pytest: the six files from the Tested section give 652 passed.
  • Semantic suite: python -I -m unittest discover -s tests/semantic ran 6245 tests: 3 failures and 2 errors, the same five test IDs with and without the PR, all in test_loop_ballot_barrier.py.
  • Not repeated here: the full corpus run and the shader_link_check.py count.
  • Nit: the docstring of runtime/test/shaders/w64_graphics.py still says the GS fixtures get the vertex number from vs_ids in TEXCOORD0. They now read TEXCOORD1 (Location 1).

AI-assisted (Claude Code).

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 5e576db on Windows Server 2022, CPython 3.13.12: pass

  • pytest tests/test_translate.py -> 597 collected, all skipped (cases need tools/fixtures not present here)
  • Nothing run-verifiable on this machine; suite loads cleanly.

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

@kacper-serewis kacper-serewis 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.

AI-assisted independent review. At 5e576db the real CPU linker accepted both VS→GS and GS→PS links for a hand-written gs_tri control. The base reported a missing output at both links. Stored pipeline coverage was 0/301 because the cached shader inventory contained no pass-to-stage triples. The earlier 195/195 result verified individual geometry modules.

@kacper-serewis kacper-serewis 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.

AI-assisted independent review. At 5e576db the batch linker accepted all 301 distinct stored VS→GS→PS triples (364 pass occurrences), up from 0/301 on 3faac55. All 691 referenced modules validated on both revisions. Only the 195 GS binaries changed. This package-backed CPU run closes the earlier gap in stored-triple coverage.

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.

7 participants