rdna2spirv: model atomic VGPR reads and writes in liveness analyses (SHADER-RBW-ATOMIC-DATA) #1908

Closed
github-bot wants to merge 1 commit from github-bot/gh-1908 into main AGit
Owner

@⁠JordanWebDev on GitHub · 2026-11-25 15:30 UTC · original
JordanWebDev:contrib/rbw-atomic-data → main · +198 −14 · 3 files · 1 commits · closed without merging

Claimed in the coordination issue as: SHADER-RBW-ATOMIC-DATA

What and why

read_before_write_vgprs(), interp_ij_analysis(), and reg_reads_writes() in tools/rdna2spirv.py previously treated only VGPR_READ_ONLY_PREFIXES (plus global_atomic_ without glc in read_before_write_vgprs() only) as read-only on a[0]:

  • Non-returning buffer_atomic_*, image_atomic_*, flat_atomic_*, non-_rtn DS atomics, and ds_store* were treated as overwriting a[0] without reading it, causing pixel shaders whose first touch of entry barycentrics (v0/v1) is e.g. buffer_atomic_add v0, ... to omit loading %bary (sending 0 to the atomic and downstream exports) and falsely triggering computed-I/J PerVertexKHR lowering in interp_ij_analysis().
  • Returning buffer_atomic_* and image_atomic_* (glc) also read a[0] (including multi-VGPR cmpswap / _x2 data pairs) before overwriting a[0] with the prior value.
  • interp_ij_analysis() and reg_reads_writes() also lacked global_atomic_ non-glc handling.

Changes:

  1. Added "ds_store" to VGPR_READ_ONLY_PREFIXES and introduced shared helpers _vgpr_reads_all(op, mods) and _vgpr_dst_also_read(op, mods) in tools/rdna2spirv.py, applied uniformly across read_before_write_vgprs(), interp_ij_analysis(), and reg_reads_writes() (including full a[0] multi-register range range(a[0]["r"], a[0]["r"] + a[0].get("n", 1)) when returning buffer_atomic_*/image_atomic_* or DST_ALSO_READ reads a[0]).
  2. Added tests/semantic/test_rbw_atomic_data.py with CPU fragment execution (spirv_mini_interp) for non-glc and glc PS barycentric buffer_atomic_add, interp_ij_analysis PerVertexKHR discrimination, and unit coverage across buffer_atomic_*, cmpswap, _x2, image_atomic_* (vector & NSA vlist), global_atomic_*, flat_atomic_*, ds_store*, and non-_rtn/_rtn DS atomics.
  3. Added the Atomic VGPR operand liveness (SHADER-RBW-ATOMIC-DATA) row to docs/design.md.

Tested

  • git diff --cached --check -> exit 0
  • python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_rbw_atomic_data.py docs/design.md -> exit 0
  • python -I tests/semantic/test_rbw_atomic_data.py -> Ran 5 tests in 0.039s OK
  • python -I -m unittest discover -s tests/semantic -p "test_store_liveins.py" -> Ran 4 tests in 0.061s OK
  • python -I -m unittest discover -s tests/semantic -p "test_interp_computed_ij.py" -> Ran 22 tests in 0.420s OK
  • python -I -m compileall -q make_game.py tools tests -> exit 0
  • python -I make_game.py --help -> exit 0
  • python -I tests/test_text_write_line_endings.py (3 OK), tests/test_report_paths.py (22 tests, 1 skipped, OK), tests/test_docs_design_rows.py (5 OK), tests/test_docs_repo_paths.py (3 OK), tests/test_docs_repeated_lines.py (2 OK), tests/test_ci_registration.py (16 OK)
  • python -I scripts/run_semantic_tests.py tests/semantic -> 490 files, 6293 tests, 0 files failed in 196 s with 16 jobs

GPUs tested: n/a

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.
**@⁠JordanWebDev** on GitHub · 2026-11-25 15:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1908) `JordanWebDev:contrib/rbw-atomic-data` → `main` · +198 −14 · 3 files · 1 commits · closed without merging Claimed in the coordination issue as: SHADER-RBW-ATOMIC-DATA ### What and why `read_before_write_vgprs()`, `interp_ij_analysis()`, and `reg_reads_writes()` in `tools/rdna2spirv.py` previously treated only `VGPR_READ_ONLY_PREFIXES` (plus `global_atomic_` without `glc` in `read_before_write_vgprs()` only) as read-only on `a[0]`: - Non-returning `buffer_atomic_*`, `image_atomic_*`, `flat_atomic_*`, non-`_rtn` DS atomics, and `ds_store*` were treated as overwriting `a[0]` without reading it, causing pixel shaders whose first touch of entry barycentrics (`v0`/`v1`) is e.g. `buffer_atomic_add v0, ...` to omit loading `%bary` (sending 0 to the atomic and downstream exports) and falsely triggering computed-I/J `PerVertexKHR` lowering in `interp_ij_analysis()`. - Returning `buffer_atomic_*` and `image_atomic_*` (`glc`) also read `a[0]` (including multi-VGPR `cmpswap` / `_x2` data pairs) before overwriting `a[0]` with the prior value. - `interp_ij_analysis()` and `reg_reads_writes()` also lacked `global_atomic_` non-`glc` handling. Changes: 1. Added `"ds_store"` to `VGPR_READ_ONLY_PREFIXES` and introduced shared helpers `_vgpr_reads_all(op, mods)` and `_vgpr_dst_also_read(op, mods)` in `tools/rdna2spirv.py`, applied uniformly across `read_before_write_vgprs()`, `interp_ij_analysis()`, and `reg_reads_writes()` (including full `a[0]` multi-register range `range(a[0]["r"], a[0]["r"] + a[0].get("n", 1))` when returning `buffer_atomic_*`/`image_atomic_*` or `DST_ALSO_READ` reads `a[0]`). 2. Added `tests/semantic/test_rbw_atomic_data.py` with CPU fragment execution (`spirv_mini_interp`) for non-`glc` and `glc` PS barycentric `buffer_atomic_add`, `interp_ij_analysis` `PerVertexKHR` discrimination, and unit coverage across `buffer_atomic_*`, `cmpswap`, `_x2`, `image_atomic_*` (vector & NSA `vlist`), `global_atomic_*`, `flat_atomic_*`, `ds_store*`, and non-`_rtn`/`_rtn` DS atomics. 3. Added the `Atomic VGPR operand liveness (SHADER-RBW-ATOMIC-DATA)` row to `docs/design.md`. ### Tested - `git diff --cached --check` -> exit 0 - `python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_rbw_atomic_data.py docs/design.md` -> exit 0 - `python -I tests/semantic/test_rbw_atomic_data.py` -> Ran 5 tests in 0.039s OK - `python -I -m unittest discover -s tests/semantic -p "test_store_liveins.py"` -> Ran 4 tests in 0.061s OK - `python -I -m unittest discover -s tests/semantic -p "test_interp_computed_ij.py"` -> Ran 22 tests in 0.420s OK - `python -I -m compileall -q make_game.py tools tests` -> exit 0 - `python -I make_game.py --help` -> exit 0 - `python -I tests/test_text_write_line_endings.py` (3 OK), `tests/test_report_paths.py` (22 tests, 1 skipped, OK), `tests/test_docs_design_rows.py` (5 OK), `tests/test_docs_repo_paths.py` (3 OK), `tests/test_docs_repeated_lines.py` (2 OK), `tests/test_ci_registration.py` (16 OK) - `python -I scripts/run_semantic_tests.py tests/semantic` -> 490 files, 6293 tests, 0 files failed in 196 s with 16 jobs GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:10:47 +00:00
Author
Owner

@⁠efeekrb on GitHub · 2026-11-25 17:45 UTC · original

Tested on an NVIDIA GeForce RTX 4060 Laptop GPU (NVIDIA 610.78), Windows 11 build 26300, with an Intel UHD iGPU also present (LEONIDA_VK_DEVICE=4060). This PR's diff applies cleanly to main at 24a29f8 (where the test programs were built) and to main at b9320a118 (git apply --check).

  • Unit tests with the PR applied: tests/semantic/test_rbw_atomic_data.py ran 5 tests, OK.
  • run_gpu_tests.py, full suite, with the PR applied: 274/274 shaders translated and pass spirv-val. Native 209/264 passed, 54 skipped, 1 failed; LEONIDA_W64_EMULATE=1 243/264 passed, 20 skipped, 1 failed. The one failure is cs_imgatomic_ext (the one #1518 addresses), and the counts are identical to main at 24a29f8 without this PR.

So no change on this GPU in either mode. The suite shows no regression; it does not tell whether a fixture exercises the rule this PR changes. No game files; counts and pass/fail lines only. AI-assisted (Claude Code).

**@⁠efeekrb** on GitHub · 2026-11-25 17:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1908#issuecomment-7169955636) Tested on an NVIDIA GeForce RTX 4060 Laptop GPU (NVIDIA 610.78), Windows 11 build 26300, with an Intel UHD iGPU also present (`LEONIDA_VK_DEVICE=4060`). This PR's diff applies cleanly to `main` at `24a29f8` (where the test programs were built) and to `main` at `b9320a118` (`git apply --check`). - Unit tests with the PR applied: `tests/semantic/test_rbw_atomic_data.py` ran 5 tests, OK. - `run_gpu_tests.py`, full suite, with the PR applied: 274/274 shaders translated and pass spirv-val. Native 209/264 passed, 54 skipped, 1 failed; `LEONIDA_W64_EMULATE=1` 243/264 passed, 20 skipped, 1 failed. The one failure is `cs_imgatomic_ext` (the one #1518 addresses), and the counts are identical to `main` at `24a29f8` without this PR. So no change on this GPU in either mode. The suite shows no regression; it does not tell whether a fixture exercises the rule this PR changes. No game files; counts and pass/fail lines only. AI-assisted (Claude Code).
github-bot closed this pull request 2026-11-27 00:36:15 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.