WIP: fix(shaders): tighten SPIR-V barriers, loop block order and IR folding #1324
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!1324
Loading…
Reference in a new issue
No description provided.
Delete branch "gmourao/Longshot:fix/shaders-spirv-ir-cleanup"
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?
Type: fix · Risk: low · Tested on: Windows 11, AMD Radeon RX 9060 XT (RDNA 4, Adrenalin 26.10.1;
--changed main+ isolated cold-cache gameplay smoke on71c9c585; awaiting Linuxspirv-val) · Needs: Linux, spirv-valWhy
Several shader recompiler emissions violated Vulkan SPIR-V validation rules or produced redundant IR/SPIR-V instructions across stages: OpenGL-only
AtomicCounterMemoryandWorkgroupMemorysemantics appeared on non-workgroup barriers, CAS loops inDefineWriteStorageCasLoopFunctionandDefineGlobalMemoryFunctionsemitted merge blocks before continue blocks, and redundant integer/bitwise identities and mesh prologue clamps inflated generated shaders.How to reproduce
Seen on: Windows 11 (SPIR-V backend and IR optimizer on
main @ e41de662; same code paths apply on Linux)Settings and switches: defaults
Steps: translate shaders emitting memory/subgroup barriers, global/storage CAS loops, mesh stage-buffer zeroing, or immediate-lane
ShuffleIndex, or inspect the emitted SPIR-V againstspirv-valExpected: barriers use Vulkan-valid scopes and semantics, CAS loop helpers emit
continue_labelbeforeend_label/endloop_label, and dead/identity operations are folded safely before SPIR-V emissionActual:
MemoryBarriersetsAtomicCounterMemory,EmitSubgroupBarriersetsWorkgroupMemoryon fragment/vertex stages, CAS loop merge blocks precede continue blocks, and redundant prologue/IR instructions remain in SPIR-VWhat changed
Tightened Vulkan SPIR-V validity in barriers and CAS loop block ordering, and eliminated redundant IR and SPIR-V instructions in mesh prologues, warp shuffles, SSBO offset calculation, and integer/bitwise constant propagation.
gpu/vk/eden/shader_recompiler/backend/spirv/emit_spirv_barriers.cpp): removed OpenGL-onlyAtomicCounterMemoryfromMemoryBarrier, gatedWorkgroupMemorytoCompute,Task,Mesh, andmesh_fallbackin bothMemoryBarrierandEmitSubgroupBarrier(MemoryBarrierpasses its scope through unchanged;EmitSubgroupBarrieralso gatesspv::Scope::Workgroupand usesspv::MemorySemanticsMask::MaskNonewithspv::Scope::Subgroupwhen!has_workgroup, per VUID 10870).gpu/vk/eden/shader_recompiler/backend/spirv/spirv_emit_context.cpp): ordering cleanup placingcontinue_labelbeforeend_label/endloop_labelinDefineWriteStorageCasLoopFunctionand both CAS loops inDefineGlobalMemoryFunctions(write_global_cas_loop_funcandatomic_global_add_f32_func).emit_spirv_mesh.cpp,emit_spirv_warp.cpp): inEmitMeshPrologue, skippedOpIAdd(..., 0)on chunkfirst == 0, skippedClamped()for full chunks (first + ctx.mesh_threads <= count), and removed the redundantBarrier(ctx)beforemesh_primitive_count = 0; inEmitShuffleIndex, fast-pathed immediatelane/clampwithsegment == 0whenStageSupportsSubgroups(ctx)viaBroadcastLane, while preservingSetInBoundsFlag(inst, in_range)before the non-subgroup early return.global_memory_to_storage_buffer_pass.cpp,constant_propagation_pass.cpp,translate_program.cpp): guardedStorageOffsetalignment masking withalignment > 1; added integer/bitwise identity folds inConstantPropagationPass(FoldISub32x - 0, shift-by-zero / zero-base shifts, bitwise identities), guarded byHasAssociatedPseudoOperation()so liveGetZeroFromOp/GetSignFromOppseudo-ops are never orphaned; added a secondConstantPropagationPassafterTexturePass/RescalingPassbeforeDeadCodeEliminationPass.tests/test_spirv_barrier_semantics.pyandtests/test_constant_prop_pseudo_ops.py, and extendedtests/test_cas_loop_ceiling.py,tests/test_amd_fragment_warp.py, andtests/test_mesh_stage_buffer_zero.py.Measurements
Nothing to measure in isolation at runtime yet: this PR fixes SPIR-V validation semantics and removes redundant IR/SPIR-V operations; Windows selected suite (
tests/run_all.py --changed main) passed (17 passed, 0 failed, 2 skipped).Flags and settings
None
Testing
Tested: on Windows 11 (
tests/run_all.py --changed main: 17 passed, 0 failed, 2 skipped;scripts/check_third_party.pypassed;RX_VK_ONLY=1 nx2/build.py --standalonecompiled and linkedlongshot_vk.dllon71c9c585: 0 failed, 13 MB), plus an isolated cold-cache gameplay smoke test on AMD RX 9060 XT (18,600 presents, 1,642 programs translated, 2,106 pipelines compiled, 69,929 KB pipeline cache saved, 0 shader/SPIR-V/device-lost errors).Not tested: Linux build and
spirv-valexecution (skipped on Windows).Must be tested:
spirv-val): runpython -I -B tests/run_all.pyincluding SPIR-V validation checks and a gameplay smoke test, expecting 0 failures and valid SPIR-V modules (Test Farm: @Beanstalk Please test this PR on Linux by running the fullpython -I -B tests/run_all.pysuite includingspirv-valchecks and a gameplay smoke test)Risks
What could break: a shader relying on an unmasked
BitwiseAndor an unexpected interaction from the post-textureConstantPropagationPass.Turning it off: revert the commit.
Compatibility: modifies files under
gpu/vk/eden/, which updatesLONGSHOT_SHADER_STAMPonce; the first launch after updating re-translates and rebuildslongshot_programs.binandlongshot_vk_pipelines.binonce.Checklist
Everyone
type(scope): description) of the status line's type.can't be run by hand is in Testing's Not testable by hand, with why.
in Risks. Not ticked yet: Measurements defers measuring with yet, and the one-time shader rebuild on first launch is never timed.
main.python -I -B tests/run_all.pypasses (--changed main: 17 passed, 0 failed, 2 skipped on Windows [nx2/test_coop_spirv.py,tests/test_native_float_atomic_add.pyrequirespirv-valon Linux]; full Linux suite queued on Test Farm).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
mainand passing here.tests/that reads changed source updated in this PR, not weakened.Tested in game: Windows 11 RX 9060 XT (26.10.1): isolated cold-cache gameplay smoke on
71c9c585(18600 presents, 1642 programs, 2106 pipelines, 0 shader/SPIR-V/device-lost errors)@Beanstalk Please test this PR on Linux by running the full python -I -B tests/run_all.py suite including spirv-val checks and a gameplay smoke test
@gmourao only members of
BigBeanscan start the farm. One of them can approve this request by reacting 👍 to it or to this comment.Brought up to the ready-for-review standard (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.