fix(shader): fold fixed 32-lane vertex bounds #5914
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5914"
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 fdfawef324 on 2026-10-14T15:32:04Z.
What
For a vertex shader targeting a fixed 32-lane host subgroup and SPIR-V below 1.6, fold a lane word
SelectU32(LaneId < 32, low, high)to its low word when both words are constants. This lets the existing constant and dead-code passes remove a constant lower-half export mask before later safety checks.Lane words selected from words that are not constants, such as the words of the entry EXEC ballot, keep their
LaneId < 32test. The half-wave scan matcher of the SPIR-V backend recognises a lane word by that select. An earlier head of this PR folded the compare itself. The matcher then missed a wave64 vertex scan keyed by the entry EXEC, andagc_shader_memoryfailed.Partial masks and observable lane outputs retain their lane dependence. The fold excludes other stages, unknown/64/single-lane subgroup requests and unknown/SPIR-V 1.6 module versions. This is the independent optimizer follow-up requested in #5466; it has no stencil replay or disk-cache changes.
Tested
Windows Server 2025, RTX 3060, GCC 15.2,
build-devRelease (-O3), rebased on main5050a23f3.agc_constant_bit_testpasses. Disabling only this fold makes the fixture fail.a lane word selected from ballot words keeps its lower-half testfails with the earlier fold, which replaced everyLaneId < 32compare.agc_shader_memorypasses.7289938ce, it failed inverifyHalfWaveReduction, on the wave64 vertex UMin scan at 32 lanes:v_readlane_b32 of lane 63 is outside the 32-lane host subgroup that runs this wave64 program at one lane per invocation.Recompiler.cpp, which matches main's behaviour.agc_shader_memory,agc_constant_bit_test,agc_constant_phi,agc_masked_select,agc_scalar_select_mask,agc_integer_narrowing,agc_structurizer,agc_spirv_module,agc_validate_program,agc_pass_hazards,agc_shader_disk_cacheandrequest_serializeragc_driver_graphics,agc_driver_stencil_replay,agc_driver_ngg_vertex_wave_reduction,agc_driver_ngg_vertex_wave_info,agc_driver_vertex_clip_cull_draw,agc_driver_vertex_fetch,agc_vertex_layer_export,agc_embedded_vertex_fetch,agc_vertex_inputandagc_driver_tessellationagc_driver_read_lane,agc_driver_write_lane,agc_driver_read_first_lane,agc_driver_wave32_subgroup,agc_driver_wave32_exec_lane_bits,agc_driver_pixel_wave_reductionandagc_vertex_barrieragc_driver_stencil_ref_export, because the device lacksVK_EXT_shader_stencil_export.tools/check_conventions.pypasses.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repositoryCo-Authored-By: Codex [email protected]
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-14T21:10:18Z.
Rebased onto main
7289938cewithout conflicts and fixed a regression, now at238093ec7. The PR stays in draft.Before (
1d9ad1c38rebased onto7289938ce)agc_shader_memoryfailed:ShaderRecompiler::Recompile: SPIR-V emission failed: hash=0x65536 stage=1 opcode=ReadLane reason=v_readlane_b32 of lane 63 is outside the 32-lane host subgroup that runs this wave64 program at one lane per invocation. This isverifyHalfWaveReduction's wave64 vertex UMin scan at 32 lanes.FoldVertexLaneBoundscall removed fromRecompiler.cpp, the test passed, so the fold caused the failure.LaneId < 32compare with true. The half-wave scan matcher inSpirvAluEmitterMath.cpp(LaneBitWords/EntryLaneWalk) recognises a lane word asSelectU32(LaneId < 32, low, high). After the fold, the entry EXEC lane word became the low ballot word alone. The matcher then failed to prove the high half, and the raw lane-63 readlane reached SPIR-V emission.Fix (
238093ec7)FoldVertexLaneBoundsnow folds the lane word select itself to its low word, and only when both words are constants.ConstantBitTestcase:a lane word selected from ballot words keeps its lower-half test. It fails with the previous fold.After, on Windows Server 2025, NVIDIA GeForce RTX 3060 with driver 591.86, GCC 15.2
-O3Release:agc_shader_memoryandagc_constant_bit_testpass.agc_driver_stencil_ref_exportis skipped because the device lacksVK_EXT_shader_stencil_export. They includeagc_driver_graphics,agc_driver_stencil_replay,agc_driver_ngg_vertex_wave_reduction,agc_structurizer,agc_shader_disk_cacheandagc_masked_select.The description was updated to match the narrower fold and the tests run.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-15T11:57:43Z.
Rebased onto main
5050a23f3(236+ commits since7289938ce, including recompiler and SPIR-V backend changes) without conflicts, now atd353c6bcc.git range-diffshows both commits unchanged.On Windows Server 2025, NVIDIA GeForce RTX 3060 with driver 591.86, GCC 15.2
-O3Release, atd353c6bcc:agc_driver_stencil_ref_exportis skipped because the device lacksVK_EXT_shader_stencil_export. They includeagc_shader_memory,agc_constant_bit_test,agc_driver_stencil_replayandagc_driver_ngg_vertex_wave_reduction.FoldVertexLaneBoundsforced to return false,agc_constant_bit_testfails on the four folding cases; restored, it passes.tools/check_conventions.pypasses.The description now names the new base and the larger test set.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:11:33Z.
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.
core/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Optimization/src/ConstantFolder.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppcore/shader/recompiler/Recompiler.cppImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T11:30:52Z.
Checked the fold (vertex stage, fixed 32-lane host subgroup, SPIR-V < 1.6, constant words only), its controls (partial/single-bit masks, ballot-word selects, other stages, subgroup and version contracts) and ran
agc_constant_bit_testandagc_shader_memoryon the PR merged onto current main; both pass. Merging once the full Build is green.