fix(shader): declare compute invocation builtins used by lowering #14870
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14870"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by edubox on 2026-11-01T21:54:46Z.
What
Compute shaders that read
GlobalInvocationIdorWorkgroupIdcould fail module emission withstage input 12 was not declared(WorkgroupId) orstage input 15 was not declared(GlobalInvocationId), even though the IR uses them.DefineInputsonly addedWorkgroupIdwhenlaneCount == 2or the wave was spanned, andGlobalInvocationIdwas left toCollectBuiltinInputs; when a lowering pass introduces either builtin after collection, the interface variables are missing.DefineInputsnow 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
0x1058daf400and several0x10527...compute programs withstage 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_programandagc_shader_disk_cachepass.agc_driver_image_packed_horizontal_gatherandagc_driver_graphicspass withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationonmainand on the change; neither log hasVUID-lines.stage input 12/15failures disappear from the log and the game reaches the next shader problem.tools/check_conventions.py --base origin/mainandgit diff --checkare clean.tools/pr_overlap.pyreports only a shared file with #12619 and #12764 (no shared function; #12764 also uses these builtins).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T01:08:35Z.
Review: COMMENTED
DefineInputscurrently adds each extra builtin only under the condition that needs it (laneCount == 2 || spannedWave,ldsLock,LdsInDeviceMemory). The PR declaresWorkgroupId,LocalInvocationIndexandGlobalInvocationIdin every compute module instead.GetBuiltinafterCollectBuiltinInputs(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 keepInfo().inputsaccurate. Unconditional declarations hide the next stale-info case.RecompileResult::Identity, every compute pipeline journal entry and the disk cache entries change. Fine if intended; worth a line in the PR.stage input 12 was not declared.Not run here.
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:GetBuiltininstructions in the final IR at emission. A builtin a lowering adds afterCollectBuiltinInputsgets declared, and a compute module that reads none of them keeps its SPIR-V and cache identity.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/main93dbd0f82a:agc_compute_builtinspasses. Negative control: with main'sSpirvEmitterHelpers.cppit fails withSPIR-V module emission failed: stage input 12 was not declared.agc_driver_image_packed_horizontal_gatherandagc_driver_graphicspass on this branch and on main, none skipped. Neither log has the missing-layer message, aVUID-or aSYNC-HAZARDID.That adds an AMD run to your NVIDIA one.