fix(shader): declare compute invocation builtins used by lowering #14870

Merged
edubox merged 1 commit from upstream-pr/14870 into main 2026-11-08 18:07:17 +00:00
edubox commented 2026-11-01 21:54:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by edubox on 2026-11-01T21:54:46Z.


What

Compute shaders that read GlobalInvocationId or WorkgroupId could fail module emission with stage input 12 was not declared (WorkgroupId) or stage input 15 was not declared (GlobalInvocationId), even though the IR uses them. DefineInputs only added WorkgroupId when laneCount == 2 or the wave was spanned, and GlobalInvocationId was left to CollectBuiltinInputs; when a lowering pass introduces either builtin after collection, the interface variables are missing.

DefineInputs now adds only the compute invocation builtins that the IR actually reads, plus the existing lanes and LDS conditions. Unused compute builtin inputs are legal, and the lowering paths that combine local and workgroup ids find their inputs. A compute module that reads none of them keeps its previous SPIR-V and shader cache identity.

God of War Ragnarök (PPSA08330) fails on 0x1058daf400 and several 0x10527... compute programs with stage input 12; with this change those programs prepare, and the run advances to a different, unrelated blocker (a vertex shader without a position export).

Tested

Linux x86-64 (CachyOS), GCC 16.2.1, Release, NVIDIA GeForce RTX 4080 SUPER (driver 615.78.8.0):

  • agc_compute_builtins, agc_spirv_module, agc_guarded_memory_loads, agc_tessellation_lowering, agc_validate_program and agc_shader_disk_cache pass.
  • agc_driver_image_packed_horizontal_gather and agc_driver_graphics pass with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation on main and on the change; neither log has VUID- lines.
  • God of War Ragnarök with the flatten work from the related branch: the stage input 12/15 failures disappear from the log and the game reaches the next shader problem.

tools/check_conventions.py --base origin/main and git diff --check are clean. tools/pr_overlap.py reports only a shared file with #12619 and #12764 (no shared function; #12764 also uses these builtins).

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: NVIDIA GeForce RTX 4080 SUPER, driver 615.78.8.0, Linux (CachyOS, x86-64)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5111950370 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14870). Originally posted by [edubox](https://github.com/edubox) on 2026-11-01T21:54:46Z. --- ### What Compute shaders that read `GlobalInvocationId` or `WorkgroupId` could fail module emission with `stage input 12 was not declared` (WorkgroupId) or `stage input 15 was not declared` (GlobalInvocationId), even though the IR uses them. `DefineInputs` only added `WorkgroupId` when `laneCount == 2` or the wave was spanned, and `GlobalInvocationId` was left to `CollectBuiltinInputs`; when a lowering pass introduces either builtin after collection, the interface variables are missing. `DefineInputs` now adds only the compute invocation builtins that the IR actually reads, plus the existing lanes and LDS conditions. Unused compute builtin inputs are legal, and the lowering paths that combine local and workgroup ids find their inputs. A compute module that reads none of them keeps its previous SPIR-V and shader cache identity. God of War Ragnarök (PPSA08330) fails on `0x1058daf400` and several `0x10527...` compute programs with `stage input 12`; with this change those programs prepare, and the run advances to a different, unrelated blocker (a vertex shader without a position export). ### Tested Linux x86-64 (CachyOS), GCC 16.2.1, Release, NVIDIA GeForce RTX 4080 SUPER (driver 615.78.8.0): - `agc_compute_builtins`, `agc_spirv_module`, `agc_guarded_memory_loads`, `agc_tessellation_lowering`, `agc_validate_program` and `agc_shader_disk_cache` pass. - `agc_driver_image_packed_horizontal_gather` and `agc_driver_graphics` pass with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` on `main` and on the change; neither log has `VUID-` lines. - God of War Ragnarök with the flatten work from the related branch: the `stage input 12`/`15` failures disappear from the log and the game reaches the next shader problem. `tools/check_conventions.py --base origin/main` and `git diff --check` are clean. `tools/pr_overlap.py` reports only a shared file with #12619 and #12764 (no shared function; #12764 also uses these builtins). ### 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: NVIDIA GeForce RTX 4080 SUPER, driver 615.78.8.0, Linux (CachyOS, x86-64) - [x] AI-assisted: yes
BunnyFl commented 2026-11-02 01:08:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T01:08:35Z.

Review: COMMENTED


DefineInputs currently adds each extra builtin only under the condition that needs it (laneCount == 2 || spannedWave, ldsLock, LdsInDeviceMemory). The PR declares WorkgroupId, LocalInvocationIndex and GlobalInvocationId in every compute module instead.

  1. Which lowering adds the GetBuiltin after CollectBuiltinInputs (ShaderInfoCollector.cpp:650) ran? If it's one pass, re-collecting there, or adding the input under that pass's condition as the other cases do, would keep Info().inputs accurate. Unconditional declarations hide the next stale-info case.
  2. The change alters every compute module's SPIR-V, so RecompileResult::Identity, every compute pipeline journal entry and the disk cache entries change. Fine if intended; worth a line in the PR.
  3. There's no regression test for the failing shape. A recompile/emission test of a compute program that reaches the failing lowering (the PPSA08330 shape, without the title ID in the test name) would fail on main with stage input 12 was not declared.

Not run here.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5731157523 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14870#pullrequestreview-5731157523). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-02T01:08:35Z. **Review:** COMMENTED --- `DefineInputs` currently adds each extra builtin only under the condition that needs it (`laneCount == 2 || spannedWave`, `ldsLock`, `LdsInDeviceMemory`). The PR declares `WorkgroupId`, `LocalInvocationIndex` and `GlobalInvocationId` in every compute module instead. 1. Which lowering adds the `GetBuiltin` after `CollectBuiltinInputs` (`ShaderInfoCollector.cpp:650`) ran? If it's one pass, re-collecting there, or adding the input under that pass's condition as the other cases do, would keep `Info().inputs` accurate. Unconditional declarations hide the next stale-info case. 2. The change alters every compute module's SPIR-V, so `RecompileResult::Identity`, every compute pipeline journal entry and the disk cache entries change. Fine if intended; worth a line in the PR. 3. There's no regression test for the failing shape. A recompile/emission test of a compute program that reaches the failing lowering (the PPSA08330 shape, without the title ID in the test name) would fail on main with `stage input 12 was not declared`. Not run here.
BunnyFl commented 2026-11-02 03:24:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T03:24:45Z.

Review: APPROVED


Re-reviewed at 594674bfe3, which answers all three points from my earlier comment:

  • Declarations now follow the GetBuiltin instructions in the final IR at emission. A builtin a lowering adds after CollectBuiltinInputs gets declared, and a compute module that reads none of them keeps its SPIR-V and cache identity.
  • The regression test is there.

Windows 11, WinLibs GCC 15.2.0 r7, Release, AMD Radeon RX 9070 XT (driver 32.0.32015.7029), Vulkan SDK 1.4.363 validation layer, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. Merged into upstream/main 93dbd0f82a:

  • agc_compute_builtins passes. Negative control: with main's SpirvEmitterHelpers.cpp it fails with SPIR-V module emission failed: stage input 12 was not declared.
  • agc_driver_image_packed_horizontal_gather and agc_driver_graphics pass on this branch and on main, none skipped. Neither log has the missing-layer message, a VUID- or a SYNC-HAZARD ID.

That adds an AMD run to your NVIDIA one.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5731780775 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14870#pullrequestreview-5731780775). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-02T03:24:45Z. **Review:** APPROVED --- Re-reviewed at 594674bfe3, which answers all three points from my earlier comment: - Declarations now follow the `GetBuiltin` instructions in the final IR at emission. A builtin a lowering adds after `CollectBuiltinInputs` gets declared, and a compute module that reads none of them keeps its SPIR-V and cache identity. - The regression test is there. Windows 11, WinLibs GCC 15.2.0 r7, Release, AMD Radeon RX 9070 XT (driver 32.0.32015.7029), Vulkan SDK 1.4.363 validation layer, `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`. Merged into upstream/main 93dbd0f82a: - `agc_compute_builtins` passes. Negative control: with main's `SpirvEmitterHelpers.cpp` it fails with `SPIR-V module emission failed: stage input 12 was not declared`. - `agc_driver_image_packed_horizontal_gather` and `agc_driver_graphics` pass on this branch and on main, none skipped. Neither log has the missing-layer message, a `VUID-` or a `SYNC-HAZARD` ID. That adds an AMD run to your NVIDIA one.
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!14870
No description provided.