perf(shader): emit runtime V# byte writes through the looping helper #6706

Merged
milescoviello merged 1 commit from upstream-pr/6706 into main 2026-10-19 09:46:58 +00:00
milescoviello commented 2026-10-16 05:29:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-16T05:29:46Z.


What

#6372 (70a884408) made BDA stores through a bound V# (EmitBdaStore) send their byte path through one looping helper, write_bda_bytes. Stores through a V# the shader computes (EmitBdaWrite, from SpirvRuntimeBuffer.cpp) still emitted that path inline. Each 32-bit store had four get_bda_write_pointer lookups, mapped checks, byte stores and note_bda_write calls for its unaligned case, plus one lookup for the aligned case. Each 8- or 16-bit store had one lookup and one note per byte.

EmitBdaWrite now does the same overflow check as before and then calls write_bda_bytes. The helper does the same lookup, store and note per byte, in order, so faults and written pages are recorded as before.

Crimson Desert (PPSA25286) runs large compute programs whose stores go through computed V#s. On NVIDIA, how long a pipeline takes to create tracks how many calls its module makes. These modules make 500 to 2,000 calls, mostly fault, lookup and note calls, and on main they take up to two minutes each to create. The title reaches them only with #6612 and #6613.

In Crimson Desert, 900 s limit with scripted pad input, APS5_PROFILE_DRAW=1 (which logs every compute pipeline over 100,000 SPIR-V words with its creation time), #6612, #6613 and #6178 (for memory) on both sides:

Build Large compute pipelines Result
without this PR (#6612 at 0eeb8159b) 11 by 885 s, 501 s spent creating them, the longest 133 s no draw; my 16 GiB cap ends it at 885 s
with this PR (#6612 at de9f0f71c) 21 by 597 s, 253 s spent creating them, the longest 41 s reaches its first draw at 597 s, which stops on AGC graphics: fragment shader must export float4 colors to its attachments

The #6612 heads differ only in their tessellation hull code, which these compute programs don't use. That new stop is a separate change.

Tested

Linux (Ubuntu 24.04, GCC 13.3, Release), RTX 4070 Ti, NVIDIA 595.99.

  • agc_driver_bda_device: its runtime write cases (byte, split short, split unaligned dword, read-only byte and suffix, unmapped middle byte, split aligned dword, each plain and coherent) already checked stored bytes, faults and written pages, and they pass with this change. A throwaway build that fails on this byte path shows that only this test reaches it in the 468 area tests. A new check in RunBdaContractTests requires a runtime V# write's byte path to go through write_bda_bytes. A 32-bit write may then make two get_bda_write_pointer calls (the helper's and the aligned store's), and an 8- or 16-bit write one. With main's SpirvBdaRead.cpp it fails with a runtime V# write of 8 bits has 2 write lookups and 0 byte-loop calls. It passes 3 of 3 with this change.
  • ctest (^agc_driver_|^agc_vertex_barrier|recompiler|shader_cache|request_serializer|spirv, 468 tests): 467 pass. agc_driver_store_over_untracked fails the same way on main 5d9dcc42d here; #6385 addresses it.
  • Crimson Desert's seven slowest compute programs, from APS5_DUMP_SHADERS request files. Each was recompiled with agc_shader_replay built from main and from this PR. The SPIR-V was put into that program's own pipeline capture (APS5_DUMP_COMPUTE_PIPELINES, same layout and specialization), and creation was timed with agc_compute_pipeline_replay, with the NVIDIA shader disk cache off (__GL_SHADER_DISK_CACHE=0). The replay tool compiles for its own target, so the word counts differ a little from the title's. One run each:
Program SPIR-V words Calls Creation
A 101,515 → 90,081 874 → 482 33.6 → 6.2 s
B 146,697 → 141,791 694 → 526 22.0 → 9.6 s
C 171,597 → 160,775 1,093 → 722 50.4 → 14.3 s
D 336,216 → 318,702 2,028 → 1,426 123.9 → 32.5 s
E 568,775 → 552,250 1,483 → 916 88.7 → 21.5 s
F 815,765 → 802,296 1,286 → 824 84.4 → 28.4 s
G 786,605 → 783,437 528 → 420 57.9 → 37.1 s
H 172,146 → 140,520 2,212 → 1,127 218.9 → 27.3 s

That's 680 s for the eight on main and 177 s with this change. Program H, the slowest per word, has 776 write lookups and 776 write notes on main. The driver needs 8.6 GiB of memory to create its pipeline on main, and 1.2 GiB with this change (peak RSS of the replay process). Program A's own captured module, as the title compiled it, took 34.5 s in the same replay.

Validated on Windows 11 with an AMD Radeon 860M (RDNA 3.5, driver 32.0.13058.8001) by @LeandroLP23 (comment), in one build of main 6efb7261b with this head and 13 other pull requests: agc_driver_bda_device and agc_driver_store_over_untracked pass 3 runs of 3. 713 of 716 agc_* tests pass; the 3 that fail fail the same way on main there.

Not checked on Intel or on a console.

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 (Crimson Desert reaches these programs only with #6612 and #6613)
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 595.99, Ubuntu 24.04; AMD Radeon 860M, driver 32.0.13058.8001, Windows 11 (tests, by @LeandroLP23)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4883959279 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6706). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-16T05:29:46Z. --- ### What #6372 (70a884408) made BDA stores through a bound V# (`EmitBdaStore`) send their byte path through one looping helper, `write_bda_bytes`. Stores through a V# the shader computes (`EmitBdaWrite`, from `SpirvRuntimeBuffer.cpp`) still emitted that path inline. Each 32-bit store had four `get_bda_write_pointer` lookups, mapped checks, byte stores and `note_bda_write` calls for its unaligned case, plus one lookup for the aligned case. Each 8- or 16-bit store had one lookup and one note per byte. `EmitBdaWrite` now does the same overflow check as before and then calls `write_bda_bytes`. The helper does the same lookup, store and note per byte, in order, so faults and written pages are recorded as before. Crimson Desert (PPSA25286) runs large compute programs whose stores go through computed V#s. On NVIDIA, how long a pipeline takes to create tracks how many calls its module makes. These modules make 500 to 2,000 calls, mostly fault, lookup and note calls, and on `main` they take up to two minutes each to create. The title reaches them only with #6612 and #6613. In Crimson Desert, 900 s limit with scripted pad input, `APS5_PROFILE_DRAW=1` (which logs every compute pipeline over 100,000 SPIR-V words with its creation time), #6612, #6613 and #6178 (for memory) on both sides: | Build | Large compute pipelines | Result | |---|---|---| | without this PR (#6612 at 0eeb8159b) | 11 by 885 s, 501 s spent creating them, the longest 133 s | no draw; my 16 GiB cap ends it at 885 s | | with this PR (#6612 at de9f0f71c) | 21 by 597 s, 253 s spent creating them, the longest 41 s | reaches its first draw at 597 s, which stops on `AGC graphics: fragment shader must export float4 colors to its attachments` | The #6612 heads differ only in their tessellation hull code, which these compute programs don't use. That new stop is a separate change. ### Tested Linux (Ubuntu 24.04, GCC 13.3, Release), RTX 4070 Ti, NVIDIA 595.99. - `agc_driver_bda_device`: its runtime write cases (byte, split short, split unaligned dword, read-only byte and suffix, unmapped middle byte, split aligned dword, each plain and coherent) already checked stored bytes, faults and written pages, and they pass with this change. A throwaway build that fails on this byte path shows that only this test reaches it in the 468 area tests. A new check in `RunBdaContractTests` requires a runtime V# write's byte path to go through `write_bda_bytes`. A 32-bit write may then make two `get_bda_write_pointer` calls (the helper's and the aligned store's), and an 8- or 16-bit write one. With `main`'s `SpirvBdaRead.cpp` it fails with `a runtime V# write of 8 bits has 2 write lookups and 0 byte-loop calls`. It passes 3 of 3 with this change. - ctest (`^agc_driver_|^agc_vertex_barrier|recompiler|shader_cache|request_serializer|spirv`, 468 tests): 467 pass. `agc_driver_store_over_untracked` fails the same way on `main` 5d9dcc42d here; #6385 addresses it. - Crimson Desert's seven slowest compute programs, from `APS5_DUMP_SHADERS` request files. Each was recompiled with `agc_shader_replay` built from `main` and from this PR. The SPIR-V was put into that program's own pipeline capture (`APS5_DUMP_COMPUTE_PIPELINES`, same layout and specialization), and creation was timed with `agc_compute_pipeline_replay`, with the NVIDIA shader disk cache off (`__GL_SHADER_DISK_CACHE=0`). The replay tool compiles for its own target, so the word counts differ a little from the title's. One run each: | Program | SPIR-V words | Calls | Creation | |---|---|---|---| | A | 101,515 → 90,081 | 874 → 482 | 33.6 → 6.2 s | | B | 146,697 → 141,791 | 694 → 526 | 22.0 → 9.6 s | | C | 171,597 → 160,775 | 1,093 → 722 | 50.4 → 14.3 s | | D | 336,216 → 318,702 | 2,028 → 1,426 | 123.9 → 32.5 s | | E | 568,775 → 552,250 | 1,483 → 916 | 88.7 → 21.5 s | | F | 815,765 → 802,296 | 1,286 → 824 | 84.4 → 28.4 s | | G | 786,605 → 783,437 | 528 → 420 | 57.9 → 37.1 s | | H | 172,146 → 140,520 | 2,212 → 1,127 | 218.9 → 27.3 s | That's 680 s for the eight on `main` and 177 s with this change. Program H, the slowest per word, has 776 write lookups and 776 write notes on `main`. The driver needs 8.6 GiB of memory to create its pipeline on `main`, and 1.2 GiB with this change (peak RSS of the replay process). Program A's own captured module, as the title compiled it, took 34.5 s in the same replay. Validated on Windows 11 with an AMD Radeon 860M (RDNA 3.5, driver 32.0.13058.8001) by @LeandroLP23 ([comment](https://github.com/boykopovar/AnyPS5/pull/6706#issuecomment-6252343242)), in one build of `main` 6efb7261b with this head and 13 other pull requests: `agc_driver_bda_device` and `agc_driver_store_over_untracked` pass 3 runs of 3. 713 of 716 `agc_*` tests pass; the 3 that fail fail the same way on `main` there. Not checked on Intel or on a console. ### 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 (Crimson Desert reaches these programs only with #6612 and #6613) - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 595.99, Ubuntu 24.04; AMD Radeon 860M, driver 32.0.13058.8001, Windows 11 (tests, by @LeandroLP23) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
milescoviello commented 2026-10-18 14:29:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T14:29:25Z.


Rebased onto main a62c724c38 (head 2f3e71bae6). The only conflict was in tests/BdaContracts.cpp: #5859 added includes and its ordered-ranges checks at the end of RunBdaContractTests, next to this PR's helper-call checks. Both are kept. EmitBdaWrite is the same as before the rebase; #5859 didn't change it.

Tests on the RTX 4070 Ti (NVIDIA 595.99.02): 7 of the 8 tests matching bda|^shader_ir|request_serializer|agc_shader_replay pass. agc_driver_bda_device stops in #5859's new RunBdaAnchorTests with vkWaitForFences graphics: Vulkan result 2 (a 5 s fence timeout). It does the same on main a62c724c38 and on #5859's merge 644e384808, and passes on 385ed71f2c just before it, so it isn't from this PR. With that one call skipped locally, the rest of agc_driver_bda_device, including RunBdaStoreExecutionTests and the contract checks for this PR's byte path, passes 3 of 3 on this head. I'll report the timeout separately.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251090586 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6706#issuecomment-6251090586). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-18T14:29:25Z. --- Rebased onto `main` a62c724c38 (head 2f3e71bae6). The only conflict was in `tests/BdaContracts.cpp`: #5859 added includes and its ordered-ranges checks at the end of `RunBdaContractTests`, next to this PR's helper-call checks. Both are kept. `EmitBdaWrite` is the same as before the rebase; #5859 didn't change it. Tests on the RTX 4070 Ti (NVIDIA 595.99.02): 7 of the 8 tests matching `bda|^shader_ir|request_serializer|agc_shader_replay` pass. `agc_driver_bda_device` stops in #5859's new `RunBdaAnchorTests` with `vkWaitForFences graphics: Vulkan result 2` (a 5 s fence timeout). It does the same on `main` a62c724c38 and on #5859's merge 644e384808, and passes on 385ed71f2c just before it, so it isn't from this PR. With that one call skipped locally, the rest of `agc_driver_bda_device`, including `RunBdaStoreExecutionTests` and the contract checks for this PR's byte path, passes 3 of 3 on this head. I'll report the timeout separately. AI-assisted: yes (Claude Code)
LeandroLP23 commented 2026-10-18 16:33:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T16:33:05Z.


AMD on Windows: the tests this PR names pass on an RDNA 3.5 GPU.

Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release. main 6efb7261b with this PR (2f3e71bae) merged, together with #7296, #7446, #7377, #7445, #6708, #6748, #6785, #6613, #7449, #7391, #7489, #7484, #7514. They were built once, so the result is for the combination; each merge was clean.

  • agc_driver_bda_device, agc_driver_store_over_untracked: pass, 3 runs of 3.
  • Every agc_* test on the combined build: 713 of 716 pass. The 3 that fail, agc_driver_host_import_lifetime, agc_driver_quad_pixel_mask and agc_driver_layered_volume_vertex_no_gpl, fail the same way on unchanged main here, so none comes from these PRs.
  • agc_compute_pipeline_replay and agc_shader_replay are not ctest names here; I did not replay captures.

AI-assisted

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6252343242 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6706#issuecomment-6252343242). Originally posted by [LeandroLP23](https://github.com/LeandroLP23) on 2026-10-18T16:33:05Z. --- AMD on Windows: the tests this PR names pass on an RDNA 3.5 GPU. Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release. `main` `6efb7261b` with this PR (`2f3e71bae`) merged, together with #7296, #7446, #7377, #7445, #6708, #6748, #6785, #6613, #7449, #7391, #7489, #7484, #7514. They were built once, so the result is for the combination; each merge was clean. - `agc_driver_bda_device`, `agc_driver_store_over_untracked`: pass, 3 runs of 3. - Every `agc_*` test on the combined build: 713 of 716 pass. The 3 that fail, `agc_driver_host_import_lifetime`, `agc_driver_quad_pixel_mask` and `agc_driver_layered_volume_vertex_no_gpl`, fail the same way on unchanged `main` here, so none comes from these PRs. - `agc_compute_pipeline_replay` and `agc_shader_replay` are not ctest names here; I did not replay captures. AI-assisted
milescoviello commented 2026-10-18 18:45:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T18:45:50Z.


Thanks @LeandroLP23 for the AMD run on Windows. I added it to the description.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6253711589 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6706#issuecomment-6253711589). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-18T18:45:50Z. --- Thanks @LeandroLP23 for the AMD run on Windows. I added it to the description. AI-assisted: yes (Claude Code)
github-actions[bot] commented 2026-10-19 00:47:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T00:47:27Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 7392 core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6257287806 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6706#issuecomment-6257287806). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T00:47:27Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 7392](https://www.github.com/boykopovar/AnyPS5/pull/7392) | `core/shader/recompiler/SpirvBackend/src/SpirvBdaRead.cpp` |
adriadam10 commented 2026-10-19 09:48:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T09:48:42Z.


Checked that EmitBdaWrite now matches EmitBdaStore: the helper does the same per-byte lookup, store and note in order, the overflow check stays before the call, and write_bda_bytes/_coherent are defined together with get_bda_write_pointer. The new CallSites check fails on main (no helper calls) and passes with the change; the runtime write cases of agc_driver_bda_device still cover bytes, faults and written pages. Merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6264406574 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6706#issuecomment-6264406574). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T09:48:42Z. --- Checked that `EmitBdaWrite` now matches `EmitBdaStore`: the helper does the same per-byte lookup, store and note in order, the overflow check stays before the call, and `write_bda_bytes`/`_coherent` are defined together with `get_bda_write_pointer`. The new `CallSites` check fails on `main` (no helper calls) and passes with the change; the runtime write cases of `agc_driver_bda_device` still cover bytes, faults and written pages. Merged.
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!6706
No description provided.