perf(shader): skip friendly names when validating SPIR-V #1752

Merged
adriadam10 merged 1 commit from upstream-pr/1752 into main 2026-10-08 18:40:56 +00:00
adriadam10 commented 2026-10-08 18:32:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T18:32:28Z.


What

Turns off friendly names in the SPIRV-Tools validator (ValidatorOptions::SetFriendlyNames(false)) in ValidateAndOptimizeSpirv, the function every build with ANYPS5_ENABLE_SPIRV_TOOLS uses.

Since #639, a specialized module turns every OpSpecConstant into an OpConstant, which leaves thousands of constants with the same type and value. On each Validate, SPIRV-Tools' FriendlyNameMapper gives every one of them a name. They all start from the same name (uint_5), so SaveName tries the suffixes _0, _1, ... one by one, and the cost is quadratic. perf on agc_driver_buffer_format: 72 % in unordered_set<string>::emplace from FriendlyNameMapper::SaveName. The names are only used in validation error messages, which now show %ids. The tests only check the message prefix.

Measured, one compute shader in agc_driver_buffer_format (RADV, no shader cache):

Validate call words before after
compiled variant 1,472,116 1.761 s 0.967 s
specialized module, before optimization 233,325 19.422 s 0.099 s
specialized module, second pass 166,098 14.856 s 0.038 s
whole test ~105 s 7 s

Full ctest on CI's lavapipe (Mesa 25.2.8), --repeat until-fail:3 --parallel 4, same build otherwise. Slowest run of each test:

test before after
agc_driver_flat_store 120.1 s (timeout) 81.0 s
agc_driver_buffer_format 120.0 s (timeout) 11.7 s
agc_driver_global_vcc_base 72.2 s < 10 s
agc_driver_sdwa_move_selectors 31.5 s < 10 s
agc_driver_global_load_addtid 29.2 s < 10 s
total test time 379.7 s 183.5 s

This is what has been timing out the Linux job since #639 (#1701 and other PRs). Titles built with SPIRV-Tools paid the same cost on every specialized shader at registration.

Tested

Linux, CachyOS: full ctest on CI's lavapipe, 483/483 passed (table above), and agc_driver_buffer_format on RADV (gfx1035).

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:4791184687 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1752). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T18:32:28Z. --- ### What Turns off friendly names in the SPIRV-Tools validator (`ValidatorOptions::SetFriendlyNames(false)`) in `ValidateAndOptimizeSpirv`, the function every build with `ANYPS5_ENABLE_SPIRV_TOOLS` uses. Since #639, a specialized module turns every `OpSpecConstant` into an `OpConstant`, which leaves thousands of constants with the same type and value. On each `Validate`, SPIRV-Tools' `FriendlyNameMapper` gives every one of them a name. They all start from the same name (`uint_5`), so `SaveName` tries the suffixes `_0`, `_1`, ... one by one, and the cost is quadratic. `perf` on `agc_driver_buffer_format`: 72 % in `unordered_set<string>::emplace` from `FriendlyNameMapper::SaveName`. The names are only used in validation error messages, which now show `%id`s. The tests only check the message prefix. Measured, one compute shader in `agc_driver_buffer_format` (RADV, no shader cache): | `Validate` call | words | before | after | |---|---|---|---| | compiled variant | 1,472,116 | 1.761 s | 0.967 s | | specialized module, before optimization | 233,325 | 19.422 s | 0.099 s | | specialized module, second pass | 166,098 | 14.856 s | 0.038 s | | whole test | | ~105 s | 7 s | Full ctest on CI's lavapipe (Mesa 25.2.8), `--repeat until-fail:3 --parallel 4`, same build otherwise. Slowest run of each test: | test | before | after | |---|---|---| | `agc_driver_flat_store` | 120.1 s (timeout) | 81.0 s | | `agc_driver_buffer_format` | 120.0 s (timeout) | 11.7 s | | `agc_driver_global_vcc_base` | 72.2 s | < 10 s | | `agc_driver_sdwa_move_selectors` | 31.5 s | < 10 s | | `agc_driver_global_load_addtid` | 29.2 s | < 10 s | | total test time | 379.7 s | 183.5 s | This is what has been timing out the Linux job since #639 (#1701 and other PRs). Titles built with SPIRV-Tools paid the same cost on every specialized shader at registration. ### Tested Linux, CachyOS: full ctest on CI's lavapipe, 483/483 passed (table above), and `agc_driver_buffer_format` on RADV (gfx1035). ### 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
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!1752
No description provided.