Shaders: what a loop computes the same way on every pass is computed once before it (opt 128, off by default) #963
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!963
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-963"
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?
@jptorres96 on GitHub · 2026-11-28 10:14 UTC · original
jptorres96:shader-licm→main· +480 −9 · 2 files · 1 commits · openPort of Belobug/VIctory-Belobug-AMD#633: a loop-invariant code motion pass in
victory-shader'sbitcode::opt(shader optimization, the "optimize shaders" item).What it does. Inside a loop, a value whose operands are all defined outside it (or are themselves hoisted) is computed once in the loop's preheader instead of on every pass. A preheader block is created where the loop is entered by a conditional branch.
What stays.
Opt-in only. New bit
128inVICTORY_SHADER_OPT.DEFAULTis unchanged (63), so the shader cache key and every existing translation stay the same.191adds it to the usual passes,255is every pass.Tests. Unit tests for the hoist, preheader creation and the two-loops case, plus the existing randomized check (
every_pass_leaves_what_random_programs_store) now runs with the pass included.Full
cargo test -p victory-shader --libon Windows with the DXIL validator (DXC 1.9.2609.5), RTX 4080 SUPER host:VICTORY_SHADER_OPTAlso 212/212 on Linux (no validator) in all three modes.
Not measured: frame time in the game (I don't have it). The pass is off by default so it can be tried with
VICTORY_SHADER_OPT=191by anyone who does.🤖 Generated with Claude Code
https://claude.ai/code/session_01H4Yjw2JbmwkmbLrWRuREWT
@gut0to on GitHub · 2026-12-01 14:52 UTC · original · reviewed
AI-assisted review: I checked this LICM finding against the DXIL operation definitions and the changed code. The review was prepared with AI assistance, and I verified the issue against the PR source.
@ -1216,0 +1424,4 @@Op::Bin(..) | Op::Cast(..) | Op::Cmp(..) | Op::Select(..) | Op::Extract(..) => true,Op::Gep(..) => true,Op::Call(f, _) => every_pass && effects[*f as usize] == Effect::Pure,_ => false,@gut0to on GitHub · 2026-12-01 14:52 UTC · original
Could derivative operations be classified as lane-sensitive here? DXIL represents
derivFineX/YandderivCoarseX/Ythroughdx.op.unary.f32, soeffect()currently sees theirReadNoneattribute and returnsPure; unlike ordinary pure arithmetic, derivative results can depend on the active 2x2 quad lanes. Hoisting one out of divergent loop control flow may therefore change its value. Please identify derivative opcodes from the operation argument and keep them in place, with a divergent-loop regression test.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.