perf(shader): reuse masked-select visitation storage #2654

Closed
Celegans12 wants to merge 1 commit from upstream-pr/2654 into main
Celegans12 commented 2026-10-10 10:12:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-10T10:12:44Z.


What

Masked-select elimination allocates a pending vector and a pointer set for each candidate's use walk. This reuses one pending vector and lazily allocated generation marks within the pass.

Dense marks are used only when the value's ID and pointer match the program's owned arena. Foreign, duplicate and newly added IDs retain the pointer-set fallback. Traversal order, mask and loop rules, fixed-point behavior and the seeded 4,096-visit limit stay unchanged. The const arena accessor supports that ownership check.

APS5_NO_PERF_MASKED_SELECT_SCRATCH retains the original containers. Its presence is excluded from the disk-cache key because both modes produce the same result; compiler source changes still produce a new SourceVersion. No request, cache-format or runtime-ABI layout changes are included.

Tested

  • Candidate bae853e9 is based on main 40a5b8fa; validated merge 45cf3503 includes 1de7e438. Both platforms passed configure/full build/libs/registration and masked-select, shader-memory and disk-cache tests in both modes without skips.
  • Windows/NVIDIA RTX 3080 Laptop GPU: 686 executed passes, four offscreen-display skips and one deliberate missing-ICD case; zero failures, skip policy passed.
  • Linux/llvmpipe LLVM 20.1.2: 651 executed passes, 32 skips, zero failures. Skip policy failed only for WSL async write-watch; that path is untested. The real plane-address test passed unskipped on both backends.
Coverage limits and historical measurement

Linux: CTest 0, skip checker/helper 1, raw accepted=false. The async userfaultfd gate and skip checker are unchanged. Not tested: unavailable device/display, watched-memory, optional assembly and platform-specific subcases.

Removing the neutral entry causes the expected opposite-mode miss after an ordinary hit; GREEN hits both ways. Historical integration: 30 exact SPIR-V comparisons; one eight-request OFF/ON/OFF triplet, 2.088/1.902/2.101 s. No current-main/game speedup claim.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4810441541 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2654). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-10T10:12:44Z. --- ### What Masked-select elimination allocates a pending vector and a pointer set for each candidate's use walk. This reuses one pending vector and lazily allocated generation marks within the pass. Dense marks are used only when the value's ID and pointer match the program's owned arena. Foreign, duplicate and newly added IDs retain the pointer-set fallback. Traversal order, mask and loop rules, fixed-point behavior and the seeded 4,096-visit limit stay unchanged. The const arena accessor supports that ownership check. `APS5_NO_PERF_MASKED_SELECT_SCRATCH` retains the original containers. Its presence is excluded from the disk-cache key because both modes produce the same result; compiler source changes still produce a new SourceVersion. No request, cache-format or runtime-ABI layout changes are included. ### Tested - Candidate `bae853e9` is based on `main` 40a5b8fa; validated merge `45cf3503` includes `1de7e438`. Both platforms passed configure/full build/`libs`/registration and masked-select, shader-memory and disk-cache tests in both modes without skips. - Windows/NVIDIA RTX 3080 Laptop GPU: 686 executed passes, four offscreen-display skips and one deliberate missing-ICD case; zero failures, skip policy passed. - Linux/llvmpipe LLVM 20.1.2: 651 executed passes, 32 skips, zero failures. Skip policy failed only for WSL async write-watch; that path is untested. The real plane-address test passed unskipped on both backends. <details><summary>Coverage limits and historical measurement</summary> Linux: CTest 0, skip checker/helper 1, raw `accepted=false`. The async userfaultfd gate and skip checker are unchanged. Not tested: unavailable device/display, watched-memory, optional assembly and platform-specific subcases. Removing the neutral entry causes the expected opposite-mode miss after an ordinary hit; GREEN hits both ways. Historical integration: 30 exact SPIR-V comparisons; one eight-request OFF/ON/OFF triplet, 2.088/1.902/2.101 s. No current-main/game speedup claim. </details> ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
popcoder565 commented 2026-10-10 15:57:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-10T15:57:31Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head bae853e9, merged onto main 57f96fd2b in one build with 4 other new PRs.

  • This PR's tests pass: agc_masked_select and agc_shader_disk_cache.
  • Full ctest in that build: 711 of 711.

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6099392736 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2654#issuecomment-6099392736). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-10T15:57:31Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `bae853e9`, merged onto `main` 57f96fd2b in one build with 4 other new PRs. - This PR's tests pass: `agc_masked_select` and `agc_shader_disk_cache`. - Full ctest in that build: 711 of 711. No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
ArjenS-LA commented 2026-10-10 20:35:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ArjenS-LA on 2026-10-10T20:35:06Z.


Independent focused Windows check at bae853e9dc08b3ed3bb2d2d953acd28b1dbf0250: I compiled the PR's unmodified MaskedSelect.cpp, top-level IR sources, MaskedSelectEliminator.cpp and DeadCodeEliminator.cpp into a standalone executable, using headers from that same commit. MinGW-w64 GCC 15.2.0 (UCRT/POSIX/SEH r2), C++20, -O2 -DNDEBUG.

The executable exited 0 both with APS5_NO_PERF_MASKED_SELECT_SCRATCH absent and with it set to 1. The added differential cases exercise the seeded visit-limit boundary, duplicate users, pointer identity/fallback IDs, 8-bit generation wrap, pending-state cleanup, fixed-point mutation and loop observations. This gives an isolated pass-level check alongside the integration run above.

This run does not validate disk-cache neutrality, a merge into current main, GPU execution or a title speedup. AI-assisted: Codex inspected the source and performed the compilation and runs on my Windows machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101911859 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2654#issuecomment-6101911859). Originally posted by [ArjenS-LA](https://github.com/ArjenS-LA) on 2026-10-10T20:35:06Z. --- Independent focused Windows check at `bae853e9dc08b3ed3bb2d2d953acd28b1dbf0250`: I compiled the PR's unmodified `MaskedSelect.cpp`, top-level IR sources, `MaskedSelectEliminator.cpp` and `DeadCodeEliminator.cpp` into a standalone executable, using headers from that same commit. MinGW-w64 GCC 15.2.0 (UCRT/POSIX/SEH r2), C++20, `-O2 -DNDEBUG`. The executable exited 0 both with `APS5_NO_PERF_MASKED_SELECT_SCRATCH` absent and with it set to `1`. The added differential cases exercise the seeded visit-limit boundary, duplicate users, pointer identity/fallback IDs, 8-bit generation wrap, pending-state cleanup, fixed-point mutation and loop observations. This gives an isolated pass-level check alongside the integration run above. This run does not validate disk-cache neutrality, a merge into current main, GPU execution or a title speedup. AI-assisted: Codex inspected the source and performed the compilation and runs on my Windows machine.
adriadam10 commented 2026-10-10 22:37:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:37:15Z.

Review: CHANGES_REQUESTED


Thanks for the thorough tests. The behaviour looks equivalent to the fallback path (visit limit, duplicate users, ID/pointer identity and generation wrap are all covered), but I can't see the benefit that justifies the extra code path:

  • The description says "No current-main/game speedup claim", and the only number is a single OFF/ON/OFF triplet (2.088 / 1.902 / 2.101 s) from a historical tree, which is within run-to-run noise.
  • A quick before/after on the same tree (MaskedSelectEliminator::Eliminate with and without APS5_NO_PERF_MASKED_SELECT_SCRATCH, 300 to 3000 masked selects with short use chains) showed no difference beyond noise (e.g. ~20 ms in both modes for 3000 selects).

Perf PRs need before/after numbers on current main. Please post a measurement where masked-select elimination is a visible share of the compile (several runs, medians, the command used), or drop the PR if it isn't. Without a measurable gain this adds MaskedSelectVisited.hpp, an env switch and a second walk implementation for nothing.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5481058180 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2654#pullrequestreview-5481058180). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T22:37:15Z. **Review:** CHANGES_REQUESTED --- Thanks for the thorough tests. The behaviour looks equivalent to the fallback path (visit limit, duplicate users, ID/pointer identity and generation wrap are all covered), but I can't see the benefit that justifies the extra code path: - The description says "No current-main/game speedup claim", and the only number is a single OFF/ON/OFF triplet (2.088 / 1.902 / 2.101 s) from a historical tree, which is within run-to-run noise. - A quick before/after on the same tree (`MaskedSelectEliminator::Eliminate` with and without `APS5_NO_PERF_MASKED_SELECT_SCRATCH`, 300 to 3000 masked selects with short use chains) showed no difference beyond noise (e.g. ~20 ms in both modes for 3000 selects). Perf PRs need before/after numbers on current `main`. Please post a measurement where masked-select elimination is a visible share of the compile (several runs, medians, the command used), or drop the PR if it isn't. Without a measurable gain this adds `MaskedSelectVisited.hpp`, an env switch and a second walk implementation for nothing.
Celegans12 commented 2026-10-11 11:21:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Celegans12 on 2026-10-11T11:21:17Z.


I checked this against current main. The masked-lane walk now already retains its pending vector and generation-marked visitation storage in cd4eaacf7c7300fee08a30c4c1188a86177e85db. That covers the allocation change proposed here. The earlier timing does not establish an additional benefit over current main, so I don't think rebasing this extra implementation is justified.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108484870 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2654#issuecomment-6108484870). Originally posted by [Celegans12](https://github.com/Celegans12) on 2026-10-11T11:21:17Z. --- I checked this against current main. The masked-lane walk now already retains its pending vector and generation-marked visitation storage in `cd4eaacf7c7300fee08a30c4c1188a86177e85db`. That covers the allocation change proposed here. The earlier timing does not establish an additional benefit over current main, so I don't think rebasing this extra implementation is justified.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!2654
No description provided.