sampler_source_census: fix V#/pointer/SMEM/v_mov dataflow and harden JSON I/O (SAMPLER-SOURCE-CENSUS-DATAFLOW-AND-IO) #1530

Open
github-bot wants to merge 1 commit from github-bot/gh-1530 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 03:37 UTC · original
IlyassRS3:fix/sampler-source-census-dataflow-io → main · +340 −16 · 2 files · 1 commits · open

What changed

  • V# per-dword offset preservation (tools/sampler_source_census.py:one_load_source): collect [source(t, seen) for t in base] and check agreement on the source origin ({g[0] for g in got}) while combining any(g[1]) and max(g[2]), instead of requiring all four dwords to have identical (where, dyn, k) tuples. Previously, adding a static or dynamic offset to word 0 of a user V# dropped it to undetermined (V# from different sources).
  • 64-bit pointer high-word zero and offset tracking (tools/sampler_source_census.py:one_load_source): recognize 3-tuple unary-folded zero constants (("const", 0, op) from s_not_b32/s_brev_b32) as a zero high word, and propagate dyn/k from a user high word instead of ignoring them.
  • SMEM offset:IMM modifier tracking (tools/sampler_source_census.py:analyse, one_load_source, one_load): parse offset:N from ins["mods"] so combined sOFF offset:IMM loads count IMM in max_pointer_constant (dynamic) and max_static_offset (constant SGPR + offset:IMM).
  • Spill-copy soundness (tools/sampler_source_census.py:step): do not treat v_mov_b32_sdwa, v_mov_b32_dpp, instructions with modifiers (clamp, etc.), or register operands with neg/abs/sext as lossless spill copies.
  • Robustness (tools/sampler_source_census.py:anchored, blocks_of, analyse, census): convert invalid hex in anchored() into hic.Skip instead of crashing with ValueError, handle empty instruction lists cleanly in blocks_of([])/analyse([], ...), and validate positive non-bool integers for limit and jobs in census().
  • Pre-scan --json guards, atomic write, and OSError handling (tools/sampler_source_census.py:main): refuse --json targeting a folder, index.json, anything inside disasm, or any .dxbc / fssm/*.fssm / .s input (via report_paths.same_report_path and os.path.samestat for hardlinks); catch OSError from census() with exit code 2; write --json atomically through a sibling temp file with file_mode.published_mode, replace_retry.replace, allow_nan=False, and explicit newline="\n".
  • Tests (tests/test_sampler_source_census.py): added 7 synthetic unit/CLI regression tests covering every fix above.

Claimed in the coordination issue as:

SAMPLER-SOURCE-CENSUS-DATAFLOW-AND-IO (#14)

How it was tested

  • python3 -I -W error tests/test_sampler_source_census.py: 37/37 passed (0 warnings).
  • python3 -I tests/test_text_write_line_endings.py: 3/3 passed.
  • python3 -I scripts/check_no_game_data.py tools/sampler_source_census.py tests/test_sampler_source_census.py: passed.
  • python3 -m compileall -q tools/sampler_source_census.py tests/test_sampler_source_census.py: passed.
  • Mutation check against unpatched main:tools/sampler_source_census.py: all 7 new tests fail (FAILED (failures=6, errors=1)), all 30 baseline tests pass.

Metadata

  • AI-assisted: yes
  • GPUs tested: none (CPU-only synthetic disassembly / CLI unit tests on macOS arm64; no game files used)
**@⁠IlyassRS3** on GitHub · 2026-11-25 03:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1530) `IlyassRS3:fix/sampler-source-census-dataflow-io` → `main` · +340 −16 · 2 files · 1 commits · open ## What changed - **V# per-dword offset preservation (`tools/sampler_source_census.py:one_load_source`)**: collect `[source(t, seen) for t in base]` and check agreement on the source origin (`{g[0] for g in got}`) while combining `any(g[1])` and `max(g[2])`, instead of requiring all four dwords to have identical `(where, dyn, k)` tuples. Previously, adding a static or dynamic offset to word 0 of a user V# dropped it to `undetermined` (`V# from different sources`). - **64-bit pointer high-word zero and offset tracking (`tools/sampler_source_census.py:one_load_source`)**: recognize 3-tuple unary-folded zero constants (`("const", 0, op)` from `s_not_b32`/`s_brev_b32`) as a zero high word, and propagate `dyn`/`k` from a user high word instead of ignoring them. - **SMEM `offset:IMM` modifier tracking (`tools/sampler_source_census.py:analyse`, `one_load_source`, `one_load`)**: parse `offset:N` from `ins["mods"]` so combined `sOFF offset:IMM` loads count `IMM` in `max_pointer_constant` (dynamic) and `max_static_offset` (constant SGPR + `offset:IMM`). - **Spill-copy soundness (`tools/sampler_source_census.py:step`)**: do not treat `v_mov_b32_sdwa`, `v_mov_b32_dpp`, instructions with modifiers (`clamp`, etc.), or register operands with `neg`/`abs`/`sext` as lossless spill copies. - **Robustness (`tools/sampler_source_census.py:anchored`, `blocks_of`, `analyse`, `census`)**: convert invalid hex in `anchored()` into `hic.Skip` instead of crashing with `ValueError`, handle empty instruction lists cleanly in `blocks_of([])`/`analyse([], ...)`, and validate positive non-bool integers for `limit` and `jobs` in `census()`. - **Pre-scan `--json` guards, atomic write, and `OSError` handling (`tools/sampler_source_census.py:main`)**: refuse `--json` targeting a folder, `index.json`, anything inside `disasm`, or any `.dxbc` / `fssm/*.fssm` / `.s` input (via `report_paths.same_report_path` and `os.path.samestat` for hardlinks); catch `OSError` from `census()` with exit code 2; write `--json` atomically through a sibling temp file with `file_mode.published_mode`, `replace_retry.replace`, `allow_nan=False`, and explicit `newline="\n"`. - **Tests (`tests/test_sampler_source_census.py`)**: added 7 synthetic unit/CLI regression tests covering every fix above. ## Claimed in the coordination issue as: `SAMPLER-SOURCE-CENSUS-DATAFLOW-AND-IO` (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ## How it was tested - `python3 -I -W error tests/test_sampler_source_census.py`: 37/37 passed (0 warnings). - `python3 -I tests/test_text_write_line_endings.py`: 3/3 passed. - `python3 -I scripts/check_no_game_data.py tools/sampler_source_census.py tests/test_sampler_source_census.py`: passed. - `python3 -m compileall -q tools/sampler_source_census.py tests/test_sampler_source_census.py`: passed. - Mutation check against unpatched `main:tools/sampler_source_census.py`: all 7 new tests fail (`FAILED (failures=6, errors=1)`), all 30 baseline tests pass. ## Metadata - AI-assisted: yes - GPUs tested: none (CPU-only synthetic disassembly / CLI unit tests on macOS arm64; no game files used)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:55:30 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 03:37 UTC · original · reviewed

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 03:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1530#pullrequestreview-6051499247) · **reviewed** Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Author
Owner

@⁠klikso on GitHub · 2026-11-25 17:40 UTC · original

Ran on a real corpus, since the description's tests are synthetic: my own 1.0.2.1, the 26,503 listings that make_game.py disassembles (<work>/shaders/dxbc/disasm, llvm-mc 23.1.6, main 3d4f66123), Windows 11, Python 3.13.

python -I tools/sampler_source_census.py <work>/shaders/dxbc/disasm --json census.json --jobs 3, once with main fe1553456's tool and once with this branch's tools/sampler_source_census.py on the same tree. main has no commit to that file since this branch's base, so only the change differs.

  • The two runs are byte-identical, both the printed report and the JSON. 14,025 shaders sample, with 366,628 sampling instructions: 189,412 user_pointer, 174,796 literal, 0 user_sgprs, 0 other_base and 2,420 undetermined.
  • These are also the numbers in docs/d3d12_vulkan.md's SHADER-735 table, so this copy reproduces the published census as well.
  • What that means for the change: none of the dataflow fixes (V#/pointer, SMEM, v_mov) moves an instruction between classes on 1.0.2.1, and the 0 other_base conclusion the doc draws from this tool holds with the branch too. The fixes guard cases this corpus doesn't have.
  • Run time: 14 min 43 s on main, 14 min 47 s with the branch (one run each, --jobs 3).
  • python -I tests/test_sampler_source_census.py with the branch's file: OK.

Counts only; the listings and the JSON stay on my machine.

AI-assisted: yes (Claude Code; run on the machine above)

**@⁠klikso** on GitHub · 2026-11-25 17:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1530#issuecomment-7169840248) Ran on a real corpus, since the description's tests are synthetic: my own 1.0.2.1, the 26,503 listings that `make_game.py` disassembles (`<work>/shaders/dxbc/disasm`, llvm-mc 23.1.6, `main` 3d4f66123), Windows 11, Python 3.13. `python -I tools/sampler_source_census.py <work>/shaders/dxbc/disasm --json census.json --jobs 3`, once with `main` `fe1553456`'s tool and once with this branch's `tools/sampler_source_census.py` on the same tree. `main` has no commit to that file since this branch's base, so only the change differs. - **The two runs are byte-identical,** both the printed report and the JSON. 14,025 shaders sample, with 366,628 sampling instructions: 189,412 `user_pointer`, 174,796 `literal`, 0 `user_sgprs`, 0 `other_base` and 2,420 `undetermined`. - **These are also the numbers in `docs/d3d12_vulkan.md`'s SHADER-735 table,** so this copy reproduces the published census as well. - **What that means for the change:** none of the dataflow fixes (V#/pointer, SMEM, `v_mov`) moves an instruction between classes on 1.0.2.1, and the 0 `other_base` conclusion the doc draws from this tool holds with the branch too. The fixes guard cases this corpus doesn't have. - Run time: 14 min 43 s on `main`, 14 min 47 s with the branch (one run each, `--jobs 3`). - `python -I tests/test_sampler_source_census.py` with the branch's file: OK. Counts only; the listings and the JSON stay on my machine. AI-assisted: yes (Claude Code; run on the machine above)
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1530/head:github-bot/gh-1530'
git switch 'github-bot/gh-1530'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1530'
git switch 'github-bot/gh-1530'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1530'
git switch 'github-bot/gh-1530'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1530'
git switch 'main'
git merge --squash 'github-bot/gh-1530'
git switch 'main'
git merge --ff-only 'github-bot/gh-1530'
git switch 'main'
git merge 'github-bot/gh-1530'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.