perf(shader): reuse starting pixel lane predicates #11699

Merged
Filip722 merged 1 commit from upstream-pr/11699 into main 2026-10-28 03:59:09 +00:00
Filip722 commented 2026-10-27 03:59:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Filip722 on 2026-10-27T03:59:46Z.


What

A pixel shader that saves its initial EXEC, enters whole-quad mode, and restores that EXEC reconstructs its own lane bit from subgroup ballots. This change reuses the captured HelperInvocation == 0 predicate when the existing starting-lane proof establishes the mask's real-lane coverage. It removes the ballot, whole-quad expansion and lane-index chain when those values have no other consumers.

  • Extend the existing pixel starting-lane fold; raw EXEC words and masks taken after divergence retain their existing behavior.
  • Cover the real-only projection and partial/divergent exclusions in the existing CPU fixture.
  • Add a save-before-WQM/restore-before-export case to the existing pixel interpolation test, on wave32 and wave64.

The condition comes from the same entry ballot being projected. A non-helper invocation contributes its own predicate bit; a helper contributes zero. The other AND operands must cover the starting real lanes. This follows the SPIR-V ballot semantics and retains the helper distinction from Vulkan's helper-invocation rules.

Tested

Linux 7.2.12-x64v3-xanmod1, Ryzen 5 7640HS, Radeon 760M, RADV Mesa 25.0.7-2+deb13u1; Release GCC 15.2, default SPIRV-Tools setting OFF. Base abed03546804575703dbedcdd3c65efc6bf5d0f2, candidate 9c5397dc27b486f5e38638e39b96f94485a0c714.

The same added homebrew case passes the pixel checks on both revisions (932 interior pixels per draw). Compiler statistics from each newly created Vulkan pipeline show:

Guest wave Native instructions, main → change Native code bytes, main → change
32 48 → 24 228 → 112
64 53 → 24 248 → 112

Allocated SGPR/VGPR counts are unchanged; no spills. The unchanged reference fragment keeps the same native hash. The two guest wave sizes share the resulting candidate pipeline.

Paired ctest -V runs on the same Radeon with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation: agc_constant_bit_test, agc_masked_select, agc_driver_graphics, agc_driver_pixel_exec_interpolation, agc_driver_pixel_helper_lanes, agc_driver_pixel_implicit_derivatives, agc_shader_memory, agc_spirv_module. All eight pass on both revisions, actual validation-layer insertion is recorded, neither log reports the missing-layer warning, and neither contains a VUID- error or a skip.

God of War: Sons of Sparta PPSA28997 01.008.001, early Cyclops fight on the same machine, copied save, fixed 8 inputs, immutable warm shader/driver caches, focused 1152x648 window, 1920x1080 output (guest internal rendering remains 4K), mailbox. Each capture uses the same ordinary APS5_TRACE_SECONDS=138:20 window, fully inside the verified fight; normal game output is inherited.

Revision Presents Frame p50 / p90 / p99 / max ms GPU ms/present
main 254 77.182 / 81.647 / 105.807 / 107.545 74.767
change 252 77.989 / 82.530 / 103.218 / 107.145 75.843

This single pair does not demonstrate a gameplay speedup. The candidate was 0.807 ms slower at p50 and 1.076 ms slower in GPU time, both within the retained baseline ranges 2.565 ms / 2.296 ms. No FPS improvement is claimed. This PR's demonstrated result is fewer native instructions in the focused homebrew case. AI/pose is not deterministic replay; the baseline also had 16 KiB swapped in, with no swap-out. Both scene/focus audits passed, with no observed thermal flags or other readable active GPU clients.

performance_compare.py reports window.first_present 4114 versus 4168 as the sole configuration difference, so its strict matching-context mode rejects the pair. The requested wall-time window is seconds 138:20 in both. Both builds contain the disclosed identical lightweight screenshot/origin hooks outside the candidate commit, explaining dirty:true; the exact patch is in the evidence bundle. VideoOut's executable difference consists only of two immediate constants encoding the trace revision string. These limitations are why the gameplay timing is descriptive.

Raw summary lines (main, then change):

{"commit":"abed03546804","dirty":true,"env":{"APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_SCREENSHOT_TRIGGER":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"138:20"},"gpu":"AMD Radeon 760M (RADV PHOENIX)","driver":"radv Mesa 25.0.7-2+deb13u1","os":"Linux 7.2.12-x64v3-xanmod1","cpu":"AMD Ryzen 5 7640HS w/ Radeon 760M Graphics","cpu_threads":12,"memory_mib":23820,"title_id":"PPSA28997","title":"God of War Sons of Sparta","content_version":"01.008.001","resolution":"1920x1080","window":{"spec":"seconds 138:20","first_present":4114,"ms":20017.505},"presents":254,"frame_ms":{"p50":77.182,"p90":81.647,"p99":105.807,"max":107.545},"gpu_busy_ms_per_present":74.767,"worker_busy_pct":{"queue worker 0x0":87.315},"top_phases_ms_per_frame":{"Driver.Packet":68.605,"Driver.Packet.draw":65.570,"Driver.Draw":65.499,"Driver.Draw.draw_enqueued":57.646,"Recorder.Sync":55.570,"VideoOut.Flip":8.964,"Driver.Present":8.941,"VideoOut.Flip.present":8.912},"trace_dropped":false,"trace":"aps5-trace-abed03546804-614689.json.gz"}
{"commit":"9c5397dc27b4","dirty":true,"env":{"APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_SCREENSHOT_TRIGGER":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"138:20"},"gpu":"AMD Radeon 760M (RADV PHOENIX)","driver":"radv Mesa 25.0.7-2+deb13u1","os":"Linux 7.2.12-x64v3-xanmod1","cpu":"AMD Ryzen 5 7640HS w/ Radeon 760M Graphics","cpu_threads":12,"memory_mib":23820,"title_id":"PPSA28997","title":"God of War Sons of Sparta","content_version":"01.008.001","resolution":"1920x1080","window":{"spec":"seconds 138:20","first_present":4168,"ms":20064.891},"presents":252,"frame_ms":{"p50":77.989,"p90":82.530,"p99":103.218,"max":107.145},"gpu_busy_ms_per_present":75.843,"worker_busy_pct":{"queue worker 0x0":87.505},"top_phases_ms_per_frame":{"Driver.Packet":69.456,"Driver.Packet.draw":66.382,"Driver.Draw":66.313,"Driver.Draw.draw_enqueued":58.509,"Recorder.Sync":56.021,"VideoOut.Flip":8.928,"Driver.Present":8.903,"VideoOut.Flip.present":8.874},"trace_dropped":false,"trace":"aps5-trace-9c5397dc27b4-616743.json.gz"}

Full validation logs, native statistics, raw summaries, trace digests, comparison and lossless gzip traces. The text gist carries each original .json.gz as base64; clone/download it and run python3 decode_traces.py to recover the original bytes with SHA256 verification. Both trace payloads and every other published file were downloaded again and matched byte-for-byte.

The overlap checker left #5021 uncomparable because its ARM64 port conflicts with main. Manual inspection found a separate vertex ULessThan32 rule and vertex tests; it does not implement this pixel rule.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon 760M, RADV Mesa 25.0.7-2+deb13u1, Linux 7.2.12-x64v3-xanmod1
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5028356591 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11699). Originally posted by [Filip722](https://github.com/Filip722) on 2026-10-27T03:59:46Z. --- ### What A pixel shader that saves its initial EXEC, enters whole-quad mode, and restores that EXEC reconstructs its own lane bit from subgroup ballots. This change reuses the captured `HelperInvocation == 0` predicate when the existing starting-lane proof establishes the mask's real-lane coverage. It removes the ballot, whole-quad expansion and lane-index chain when those values have no other consumers. - Extend the existing pixel starting-lane fold; raw EXEC words and masks taken after divergence retain their existing behavior. - Cover the real-only projection and partial/divergent exclusions in the existing CPU fixture. - Add a save-before-WQM/restore-before-export case to the existing pixel interpolation test, on wave32 and wave64. The condition comes from the same entry ballot being projected. A non-helper invocation contributes its own predicate bit; a helper contributes zero. The other AND operands must cover the starting real lanes. This follows the [SPIR-V ballot semantics](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpGroupNonUniformBallot) and retains the helper distinction from [Vulkan's helper-invocation rules](https://docs.vulkan.org/spec/latest/chapters/shaders.html#shaders-helper-invocations). ### Tested Linux 7.2.12-x64v3-xanmod1, Ryzen 5 7640HS, Radeon 760M, RADV Mesa 25.0.7-2+deb13u1; Release GCC 15.2, default SPIRV-Tools setting OFF. Base `abed03546804575703dbedcdd3c65efc6bf5d0f2`, candidate `9c5397dc27b486f5e38638e39b96f94485a0c714`. The same added homebrew case passes the pixel checks on both revisions (932 interior pixels per draw). Compiler statistics from each newly created Vulkan pipeline show: | Guest wave | Native instructions, main → change | Native code bytes, main → change | |---|---:|---:| | 32 | 48 → 24 | 228 → 112 | | 64 | 53 → 24 | 248 → 112 | Allocated SGPR/VGPR counts are unchanged; no spills. The unchanged reference fragment keeps the same native hash. The two guest wave sizes share the resulting candidate pipeline. Paired `ctest -V` runs on the same Radeon with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`: `agc_constant_bit_test`, `agc_masked_select`, `agc_driver_graphics`, `agc_driver_pixel_exec_interpolation`, `agc_driver_pixel_helper_lanes`, `agc_driver_pixel_implicit_derivatives`, `agc_shader_memory`, `agc_spirv_module`. All eight pass on both revisions, actual validation-layer insertion is recorded, neither log reports the missing-layer warning, and neither contains a `VUID-` error or a skip. God of War: Sons of Sparta PPSA28997 01.008.001, early Cyclops fight on the same machine, copied save, fixed 8 inputs, immutable warm shader/driver caches, focused 1152x648 window, 1920x1080 output (guest internal rendering remains 4K), mailbox. Each capture uses the same ordinary `APS5_TRACE_SECONDS=138:20` window, fully inside the verified fight; normal game output is inherited. | Revision | Presents | Frame p50 / p90 / p99 / max ms | GPU ms/present | |---|---:|---|---:| | main | 254 | 77.182 / 81.647 / 105.807 / 107.545 | 74.767 | | change | 252 | 77.989 / 82.530 / 103.218 / 107.145 | 75.843 | This single pair does **not** demonstrate a gameplay speedup. The candidate was 0.807 ms slower at p50 and 1.076 ms slower in GPU time, both within the retained baseline ranges 2.565 ms / 2.296 ms. No FPS improvement is claimed. This PR's demonstrated result is fewer native instructions in the focused homebrew case. AI/pose is not deterministic replay; the baseline also had 16 KiB swapped in, with no swap-out. Both scene/focus audits passed, with no observed thermal flags or other readable active GPU clients. `performance_compare.py` reports `window.first_present` 4114 versus 4168 as the sole configuration difference, so its strict matching-context mode rejects the pair. The requested wall-time window is seconds 138:20 in both. Both builds contain the disclosed identical lightweight screenshot/origin hooks outside the candidate commit, explaining `dirty:true`; the exact patch is in the evidence bundle. VideoOut's executable difference consists only of two immediate constants encoding the trace revision string. These limitations are why the gameplay timing is descriptive. Raw summary lines (main, then change): ```json {"commit":"abed03546804","dirty":true,"env":{"APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_SCREENSHOT_TRIGGER":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"138:20"},"gpu":"AMD Radeon 760M (RADV PHOENIX)","driver":"radv Mesa 25.0.7-2+deb13u1","os":"Linux 7.2.12-x64v3-xanmod1","cpu":"AMD Ryzen 5 7640HS w/ Radeon 760M Graphics","cpu_threads":12,"memory_mib":23820,"title_id":"PPSA28997","title":"God of War Sons of Sparta","content_version":"01.008.001","resolution":"1920x1080","window":{"spec":"seconds 138:20","first_present":4114,"ms":20017.505},"presents":254,"frame_ms":{"p50":77.182,"p90":81.647,"p99":105.807,"max":107.545},"gpu_busy_ms_per_present":74.767,"worker_busy_pct":{"queue worker 0x0":87.315},"top_phases_ms_per_frame":{"Driver.Packet":68.605,"Driver.Packet.draw":65.570,"Driver.Draw":65.499,"Driver.Draw.draw_enqueued":57.646,"Recorder.Sync":55.570,"VideoOut.Flip":8.964,"Driver.Present":8.941,"VideoOut.Flip.present":8.912},"trace_dropped":false,"trace":"aps5-trace-abed03546804-614689.json.gz"} {"commit":"9c5397dc27b4","dirty":true,"env":{"APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"<path>","APS5_SCREENSHOT_TRIGGER":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_SECONDS":"138:20"},"gpu":"AMD Radeon 760M (RADV PHOENIX)","driver":"radv Mesa 25.0.7-2+deb13u1","os":"Linux 7.2.12-x64v3-xanmod1","cpu":"AMD Ryzen 5 7640HS w/ Radeon 760M Graphics","cpu_threads":12,"memory_mib":23820,"title_id":"PPSA28997","title":"God of War Sons of Sparta","content_version":"01.008.001","resolution":"1920x1080","window":{"spec":"seconds 138:20","first_present":4168,"ms":20064.891},"presents":252,"frame_ms":{"p50":77.989,"p90":82.530,"p99":103.218,"max":107.145},"gpu_busy_ms_per_present":75.843,"worker_busy_pct":{"queue worker 0x0":87.505},"top_phases_ms_per_frame":{"Driver.Packet":69.456,"Driver.Packet.draw":66.382,"Driver.Draw":66.313,"Driver.Draw.draw_enqueued":58.509,"Recorder.Sync":56.021,"VideoOut.Flip":8.928,"Driver.Present":8.903,"VideoOut.Flip.present":8.874},"trace_dropped":false,"trace":"aps5-trace-9c5397dc27b4-616743.json.gz"} ``` [Full validation logs, native statistics, raw summaries, trace digests, comparison and lossless gzip traces](https://gist.github.com/Filip722/da05665795a0cdd8439e9c916b08c7cb). The text gist carries each original `.json.gz` as base64; clone/download it and run `python3 decode_traces.py` to recover the original bytes with SHA256 verification. Both trace payloads and every other published file were downloaded again and matched byte-for-byte. The overlap checker left #5021 uncomparable because its ARM64 port conflicts with main. Manual inspection found a separate vertex `ULessThan32` rule and vertex tests; it does not implement this pixel rule. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: AMD Radeon 760M, RADV Mesa 25.0.7-2+deb13u1, Linux 7.2.12-x64v3-xanmod1 - [x] AI-assisted: yes
MarcZX10 commented 2026-10-27 06:53:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T06:53:49Z.

Review: APPROVED


Reviewed head 9c5397dc27. The fold only reuses the entry real-lane predicate when the ballot is evaluated across the starting lanes and the other AND operands retain real-lane coverage; partial masks and divergent ballots remain unfurled. The added CPU cases cover those exclusions, and the execution case covers restoring the saved entry EXEC before export on wave32 and wave64. I also reviewed the paired hardware test/performance evidence in the PR description; it is appropriately explicit that the single gameplay pair does not establish a speedup. I did not independently rerun the GPU suite.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5663274422 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11699#pullrequestreview-5663274422). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T06:53:49Z. **Review:** APPROVED --- Reviewed head 9c5397dc27b486f5e38638e39b96f94485a0c714. The fold only reuses the entry real-lane predicate when the ballot is evaluated across the starting lanes and the other AND operands retain real-lane coverage; partial masks and divergent ballots remain unfurled. The added CPU cases cover those exclusions, and the execution case covers restoring the saved entry EXEC before export on wave32 and wave64. I also reviewed the paired hardware test/performance evidence in the PR description; it is appropriately explicit that the single gameplay pair does not establish a speedup. I did not independently rerun the GPU suite.
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!11699
No description provided.