Skip to content

rdna2spirv: unify VGPR read/write operand analysis across liveness and interp passes - #2739

Open
Kosmabb8 wants to merge 1 commit into
ItsNotRexed:mainfrom
Kosmabb8:fix/vgpr-rw-analysis
Open

Kosmabb8 wants to merge 1 commit into
ItsNotRexed:mainfrom
Kosmabb8:fix/vgpr-rw-analysis

Conversation

@Kosmabb8

@Kosmabb8 Kosmabb8 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

The translator's VGPR operand analysis disagreed between liveness, interpolation and pristine-copy tracking. A shared read/write helper now handles swap operands, returning/non-returning atomics, partial d16 writes and implicit EXEC destinations consistently, so these passes retain the same input registers and invalidate the same overwritten copies.

Claim: #2716 (comment)

Merged upstream f847748 in aa9898a. The two conflicts were resolved through the shared helper while preserving upstream's accumulating dot-product reads. Added six opcode/encoding subcases to guard those reads.

Validation on Windows, portable CPython 3.12.10, synthetic CPU tests:

  • VGPR operand/liveness regressions: 11 passed.
  • Accumulating dot-product checks: 5 passed.
  • Interpolation sweep: 207 passed.
  • Full semantic discovery ran 7,333 tests in 886.561 seconds: 14 failures, 4 skips, 1 expected failure. All 14 failures were mutation-test child imports of test_ps_semantics: this embedded Python's ._pth ignores PYTHONPATH. No other failures occurred. A separate external harness supplying the child sys.path explicitly passed both unchanged mutation-test methods, including the baseline and all 13 sabotage cases (95.208 seconds). The unmodified full-suite run is therefore not claimed as green.
  • Compilation and scoped diff checks passed.

All 14 open account PR heads (including #3536 and #3565) merge together cleanly against that snapshot, using this repaired head. Fifteen focused test files in the combined tree passed: 298 unittest cases passed, 4 expected Windows skips, and 8 direct lane-mask checks passed. No cross-PR textual conflict, including with #2742.

No local GPU run, spirv-val/llvm-mc or retail shader corpus. AI-assisted.

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested 70523fbdf3ee0faace7d6ce811166f4954fd2d93 on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

Independent synthetic Vulkan check of 70523fbdf3ee0faace7d6ce811166f4954fd2d93 on Linux 7.0.0-43 (RTX 5090, NVIDIA 595.99.02, subgroup 32, LLVM 21.1.8, SPIRV-Tools 2026.1).

I drew stock ps_bary with vs_ids, then prepended v_swap_b32_e32 v0, v1 and drew again. I compared each swapped pixel against the stock pixel with both interpolated channels and raw weights exchanged, using an absolute tolerance of 1e-6.

  • The PR matched all 4,096 swapped pixels. Reversing only the translator diff made all 4,096 differ: the second interpolated channel and corresponding raw weight were zero in every pixel. The stock draw matched across both translator versions.
  • Both sets of modules passed Vulkan 1.2 SPIR-V validation. All ten focused semantic tests passed on the PR. The GPU comparison specifically covers the register swap and barycentric path.

AI-assisted verification.

@padhossein

Copy link
Copy Markdown
Contributor

Independent VGPR baseline comparison (70523fbd). The 10 targeted tests pass on this head. For an A/B control I ran the same test file with the base translator via LEONIDA_TOOLS_DIR: 33 assertions failed, including the end-to-end swapped barycentric cases and operand-role cases for non-returning atomics. This confirms those are production-translator regressions caught by the tests. Synthetic inputs only.

AI-assisted (Codex).

@sperm

sperm commented Nov 22, 2026

Copy link
Copy Markdown

Tested 70523fb on AMD Radeon RX 9070 XT (RADV GFX1201) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.

  • Full python -I scripts/run_gpu_tests.py (Linux build of this branch's runtime/, LEONIDA_VK_DEVICE per GPU): 170/185 passed, 15 skipped, 0 failed on both GPUs. Compared with the same suite at the merge base 4947579 on the same machine, every test has the same result.
  • python -m unittest discover -s tests/semantic: 2577 OK

No game files. AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Linux (WSL2 Ubuntu, Python 3.12) and native Windows 11 (Python 3.13.1), CPU only: pass. Merges cleanly with main. tests/semantic/test_vgpr_rw_analysis.py: Linux 10 tests OK, Windows 10 tests OK, 0 skips. Negative control (tools/rdna2spirv.py restored to main, Linux): fails (33 failures across the 10 tests), so the tests exercise the real code. Trial merges: clean with #2780, #2742, #2722, #2710; #2711 (SHADER-492, also mergeable on its own) conflicts in tools/rdna2spirv.py, so whichever lands second needs a rebase.

@Kosmabb8

Copy link
Copy Markdown
Contributor Author

Conflict repair aa9898a is now pushed. It merges f847748 and preserves both the shared helper and upstream dot2c/dot8c accumulating reads. Added six opcode/encoding subcases; VGPR 11, dot-product 5 and interpolation 207 tests passed. Full semantic run: 7,333 tests; all 14 failures were embedded-Python mutation-child import failures. An external explicit-child-path rerun passed both unchanged mutation methods, baseline and all 13 sabotage cases; no other full-suite failures. Four skips and one expected failure. Updated PR body with the exact limitation rather than claiming a green full run. All account PR heads merge together cleanly in local integration. No GPU or SPIR-V tool run. AI-assisted.

@Kosmabb8

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto current main (d90444f21) as a single commit, preserving all upstream VGPR-analysis updates (vgpr_dest_registers, sdwa_reads_dst, VGPR_READ_ONLY_PREFIXES with flat_store/scratch_store, unsigned v_dot*c_* accumulating reads, and buffer_load_*_d16 non-format loads) while unifying all four passes (read_before_write_vgprs, interp_ij_analysis, reg_reads_writes, interp_copy_sources) through _insn_vgpr_rw.

Validation (Windows 11, portable Python 3.12.10, python -I, CPU-only synthetic shaders):

  • Positive control (tests/semantic/test_vgpr_rw_analysis.py against unmodified d90444f21): FAILED (failures=28).
  • After fix: test_vgpr_rw_analysis.py 12/12 OK, test_interp*.py 201/201 OK, test_*dot*.py 82/82 OK, test_*sdwa*.py 42/42 OK, test_global_mem_x3.py 14/14 OK (1 skipped), test_alu_swaprel.py 15/15 OK, test_resource_hygiene.py 2/2 OK, compileall exit 0. (test_*atomic*.py ran 283 tests: all 280 non-guard tests passed with 1 skip; test_image_atomics_guard.py had the same 47 pre-existing failures on unmodified d90444f21.)

AI-assisted (Antigravity).

@Kosmabb8
Kosmabb8 force-pushed the fix/vgpr-rw-analysis branch from aa9898a to d4d44c0 Compare November 23, 2026 17:00
@wavehs

wavehs commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested d4d44c09e on Apple M3 Pro (macOS arm64, CPython 3.15.2, CPU only — no GPU, no llvm-mc, no spirv-val needed): pass, and the full semantic suite is A/B clean.

  • tests/semantic/test_vgpr_rw_analysis.py -> 12 tests, OK. test_interp*.py -> 201, OK. *dot*.py -> 82, OK.
  • Full suite, python -I scripts/run_semantic_tests.py tests/semantic:
    • this head alone: 445 files, 5,914 tests, 2 files failed (test_image_atomics_guard 47 failures, test_image_store_d16 1) in 75 s / 12 jobs;
    • origin/main dde82f27e, same command: 447 files, 5,956 tests, the same 2 files with the same 47+1 failures — I diffed the failing test names between the two runs and they are identical;
    • head merged into origin/main: 448 files, 5,968 tests, the same 2 files and the same 47+1, so the PR contributes exactly one file and 12 tests and every one of them is green.
  • Negative control on origin/main dde82f27e (main's tools/rdna2spirv.py, this PR's test kept): test_vgpr_rw_analysis.py FAILED (failures=31) across the 12 tests, so the tests exercise the shared helper rather than modelling it.
  • Merges cleanly onto origin/main dde82f27e (only tools/rdna2spirv.py auto-merged). python -m compileall -q make_game.py tools tests, python -I scripts/check_no_game_data.py on both changed files and git diff --check are clean.
  • Guard: the new file imports rdna2spirv and translates through support.translate_lines, so tests/test_semantic_translator_use.py stays green at this head and on the merged tree (3/3), i.e. it is not new DEBT.

Two notes from reading the diff:

  1. This is not a pure refactor, so the PR title undersells it: besides the four passes now sharing _insn_vgpr_rw, read_before_write_vgprs/the new helper treat buffer_atomic_*/image_atomic_* without glc, non-returning ds_* and lds-modified buffer_load_*/tbuffer_load_* as reading every VGPR operand, where main only did that for global_atomic_*. All three are covered by the new subcases, so the behaviour is pinned — worth saying in the body because it changes fetched-attribute and pristine-copy results, not just the code shape.
  2. The 47+1 failures in test_image_atomics_guard/test_image_store_d16 are not Windows-only and not caused by this PR: they are byte-identical on main dde82f27e on macOS arm64, so that is an existing translator problem on this platform (the OpImageTexelPointer in unguarded block assertion) rather than a merge risk here.

AI-assisted.

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.

6 participants