tools: one cached work_root() per shader instead of nine realpath() calls (OLD-9777) #1265

Open
github-bot wants to merge 3 commits from github-bot/gh-1265 into main AGit
Owner

@⁠ambroseautomation on GitHub · 2026-11-24 21:03 UTC · original
ambroseautomation:carry/old-9777-work-root-cache → main · +65 −10 · 4 files · 3 commits · open

Claimed in the coordination issue as: OLD-9777 (#14)

What and why

Carries forward old-pr/9777 (draft #55, original commit author pes7 preserved across all 3 commits; indexed in #17), rebased cleanly onto current main (0b45fdc21).

Replaces repeated os.path.realpath calls per shader in tools/rdna2spirv.py and tools/shader_meta.py with a cached work_root() helper in tools/report_paths.py:

  • Caches os.path.realpath for absolute paths so translating a shader resolves its work root once instead of nine times (byte-identical output).
  • Resolves relative paths on every call (never from the cache), so changing working directory between calls still resolves accurately.
  • Adds WorkRootTests in tests/test_report_paths.py verifying absolute-path caching, relative-path re-resolution after os.chdir, and 8.3 short-path compatibility on Windows.

Tested

  • python -I tests/test_report_paths.py -v: 24 tests, OK (1 skipped: Windows symlink privilege).
  • python -m compileall -q make_game.py tools tests: exit 0.
  • python -I scripts/check_no_game_data.py tools/report_paths.py tools/rdna2spirv.py tools/shader_meta.py tests/test_report_paths.py: exit 0 (no game data).

GPUs tested: n/a (Python path resolution helper + stdlib unit tests on Windows 11 Pro 64-bit, Python 3.12.10)

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. (n/a — path-resolution caching only, no codegen changes)
**@⁠ambroseautomation** on GitHub · 2026-11-24 21:03 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1265) `ambroseautomation:carry/old-9777-work-root-cache` → `main` · +65 −10 · 4 files · 3 commits · open Claimed in the coordination issue as: OLD-9777 (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### What and why Carries forward `old-pr/9777` (draft #55, original commit author `pes7` preserved across all 3 commits; indexed in #17), rebased cleanly onto current `main` (`0b45fdc21`). Replaces repeated `os.path.realpath` calls per shader in `tools/rdna2spirv.py` and `tools/shader_meta.py` with a cached `work_root()` helper in `tools/report_paths.py`: - Caches `os.path.realpath` for absolute paths so translating a shader resolves its work root once instead of nine times (byte-identical output). - Resolves relative paths on every call (never from the cache), so changing working directory between calls still resolves accurately. - Adds `WorkRootTests` in `tests/test_report_paths.py` verifying absolute-path caching, relative-path re-resolution after `os.chdir`, and 8.3 short-path compatibility on Windows. ### Tested - `python -I tests/test_report_paths.py -v`: 24 tests, OK (1 skipped: Windows symlink privilege). - `python -m compileall -q make_game.py tools tests`: exit 0. - `python -I scripts/check_no_game_data.py tools/report_paths.py tools/rdna2spirv.py tools/shader_meta.py tests/test_report_paths.py`: exit 0 (no game data). GPUs tested: n/a (Python path resolution helper + stdlib unit tests on Windows 11 Pro 64-bit, Python 3.12.10) 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. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — path-resolution caching only, no codegen changes)
Everything that reads index.json, the .dxbc input signatures or the fssm headers derives the shader's work folder
with os.path.dirname(os.path.dirname(os.path.realpath(path))) - nine copies of that expression across rdna2spirv.py
and shader_meta.py, asked up to sixteen times per shader, and os.path.realpath is a _getfinalpathname call on Windows
(~40 us). It is the same string every time, so report_paths.work_root() resolves it once per path and keeps it, with a
1<<14 cap for a process that walks a corpus.

Measured with scripts/bench_translate.py --compare (#7056), 5 rounds, best of 3, same machine: the 52-fixture corpus
goes 63.2 -> 54.6 us/instruction (0.86x), ALU and s_nop unchanged (0.99x). The 52 pixel and vertex fixtures still
translate to byte-identical SPIR-V assembly (sha256 157189dc...).
A relative path names a different folder after a chdir, so a cache keyed by the spelling alone answered the second
call with the first working directory's root (reported by @senyurah on #7335, with a two-work-folder repro through
shader_meta.fspx_code_sha256_file). Absolute paths, which is what the translator passes, are still resolved once;
relative ones are now resolved on every call, exactly as before the cache.

tests/test_report_paths.py: two new tests, one for the chdir sequence, one that an absolute path is resolved once.
tempfile hands back the 8.3 spelling on this machine (NAZARP~1) while realpath, which work_root uses, gives the long
one; the assertion now resolves both sides the same way.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:45:00 +00:00
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-25 06:23 UTC · original · approved these changes

Approving. Merged into current main (42537e7) with no conflicts. tests/test_report_paths.py plus the shader_meta tests pass (57 passed), and the full translator suite gives 487 files / 6,279 tests with only test_int32_to_f64 failing, as on main here (Linux, Python 3.13).

I checked every replaced call: each was the same dirname(dirname(realpath(path))), so work_root returns the same value. Only absolute spellings are cached, so a chdir can't give a stale answer, and the size cap stops the table growing past one corpus.

AI-assisted (Claude).

**@⁠tiguan26** on GitHub · 2026-11-25 06:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1265#pullrequestreview-6052784950) · **approved these changes** Approving. Merged into current main (42537e7) with no conflicts. `tests/test_report_paths.py` plus the shader_meta tests pass (57 passed), and the full translator suite gives 487 files / 6,279 tests with only `test_int32_to_f64` failing, as on main here (Linux, Python 3.13). I checked every replaced call: each was the same `dirname(dirname(realpath(path)))`, so `work_root` returns the same value. Only absolute spellings are cached, so a `chdir` can't give a stale answer, and the size cap stops the table growing past one corpus. AI-assisted (Claude).
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 14:42 UTC · original

Reviewed 74cc3eb: 3 commits (cached work_root() helper, relative-path chdir guard, tests). Ran on arm64 Linux with no game files: tests/test_report_paths.py 24 OK on the branch; the branch's test file fails on main (no work_root) as expected; test_shader_meta, test_shader_meta_operands, test_shader_library, test_pe_shader_containers, test_bvh_shaders_stage and the fspx semantic tests all pass on both trees and on the branch applied to current main (the nine call sites are unchanged there; patch applies cleanly). Probed relative/absolute/symlinked/retargeted spellings across two synthetic work folders: only difference from main is the retargeted-symlink case, which is the documented "cannot change while a build runs" assumption and unreachable in a build where each spelling is translated once; relative-path-after-chdir behaves correctly on both. No findings. AI-assisted review.

Recommendation: Merge

**@⁠PierreEbele** on GitHub · 2026-11-25 14:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1265#issuecomment-7165695450) Reviewed 74cc3eb: 3 commits (cached work_root() helper, relative-path chdir guard, tests). Ran on arm64 Linux with no game files: tests/test_report_paths.py 24 OK on the branch; the branch's test file fails on main (no work_root) as expected; test_shader_meta, test_shader_meta_operands, test_shader_library, test_pe_shader_containers, test_bvh_shaders_stage and the fspx semantic tests all pass on both trees and on the branch applied to current main (the nine call sites are unchanged there; patch applies cleanly). Probed relative/absolute/symlinked/retargeted spellings across two synthetic work folders: only difference from main is the retargeted-symlink case, which is the documented "cannot change while a build runs" assumption and unreachable in a build where each spelling is translated once; relative-path-after-chdir behaves correctly on both. No findings. AI-assisted review. **Recommendation:** Merge
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/1265/head:github-bot/gh-1265'
git switch 'github-bot/gh-1265'

Merge

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