fix(shader): mark the vertex position output invariant #2458
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2458"
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 gjonn on 2026-10-09T21:54:08Z.
What
The recompiled vertex and mesh shaders now declare their position output
Invariant.A title (PPSA01317) draws a depth pre-pass (reverse Z, compare GREATER, depth writes on) and then draws the same geometry again in its G-buffer pass with compare GREATER_OR_EQUAL. The two passes use different vertex programs that compute the position the same way. On the GPU both give bit-identical depth. In Vulkan, without
Invariantthe driver is free to compile the same position arithmetic differently in each shader, for example contracting a multiply and an add into an FMA in one and not the other. The second pass's depth then came out slightly smaller and every fragment failed the test. The SPIR-V spec guarantees that anInvariantoutput gives the same result in different shaders for the same inputs and computation, which is what the hardware already does.PerVertexType(SpirvEmitterHelpers.cpp): the gl_PerVertex block decorates member 0 (BuiltIn Position)Invariantas well. Every non-mesh stage that exports a position writes it through this block.DefineMeshOutputs(SpirvModuleEmitter.cpp): the mesh shader's Position output variable is decoratedInvariant.RectListShaders.cpp) are unchanged. Three corners are copied unchanged from the vertex shader, whose position is nowInvariant. The fourth corner is a sum of the other three weighted by +1 or -1, so every product is exact and FMA contraction gives the same result.Invariantmay cost a little optimization on position math only. Since the shader disk cache key is derived from the recompiler sources, cached shaders are rebuilt automatically.Tested
agc_position_invariancetest recompiles a vertex shader and a mesh shader that export a position. It checks that everyBuiltIn Positionin the SPIR-V (the block member or the mesh output variable) is alsoInvariant. Both checks fail without this change.ctest -R "agc|shader|spirv|recompil": 262 of 262 pass, among themagc_shader_memory,agc_shader_disk_cache,agc_spirv_module,agc_validate_program,agc_driver_graphics,agc_driver_prepared_graphicsandagc_driver_mesh. The mesh and graphics tests draw on an RTX 5090 Laptop GPU with the decoration in place.Invariantand the depth test on, they reached 42% after 1000 of the frame's draws, the normal progressive fill.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-09T22:50:10Z.
Tested on Linux (CachyOS x86_64, Intel RPL-S iGPU / Mesa 26.3.0-devel / Vulkan 1.4.363, GCC 16.2.1) at
21f94288:/tmp/anyps5_build) with zero warnings/errors.python3 tools/check_conventions.py --base origin/main --head HEAD-> PASS (0 errors).PositionInvariance.cppand SPIR-V emitter output. Decorating vertex position output withInvariantprevents multi-pass Z-fighting across depth pre-passes.LGTM!
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:17:48Z.
Checked on Linux: built the AGC/AgcDriver scope,
agc_position_invariancepasses and fails with the two emitter changes reverted; the rest of the scoped ctest is green. The decoration follows the SPIR-VInvariantguarantee, and the rect-list reasoning holds. Merging.