Shaders: validate far-jump arithmetic and control-flow entries #2686
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2686
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2686"
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?
@XeNS1 on GitHub · 2026-11-25 18:12 UTC · original
XeNS1:codex/far-jump-recognition-20261125→main· +458 −58 · 2 files · 2 commits · opengfx10::far_jumpfollowed a target derived from the low-word literal even when the high-word carry was missing, mismatched, or clobbered. A physical getpc / arithmetic / setpc sequence also does not prove a constant target when another branch enters after getpc: the bypassing path can carry a different register pair. Decode and IR previously recomputed this decision from different predecessor sets, which could produce an IR jump to code that was never decoded.Validate the complete local getpc / low arithmetic / matching high carry / setpc chain, including both registers and both halves of the signed offset. Wide host arithmetic handles subtraction of i64::MIN. Within the existing four-instruction lookback, only NOPs, s_waitcnt and s_waitcnt_depctr may separate the operations.
Track discovered branch and jump destinations and leave the setpc indirect if any entry bypasses part of its setup. A later path can invalidate a chain already followed: in that case decode restarts with the additional entries retained, removing speculative code and its errors. Errors are deferred until pending paths have been explored, so an invalid speculative target cannot hide the path that invalidates it. The entry set only grows, and every retry blocks at least one newly invalidated chain. IR consumes the final decoded flow decisions rather than resolving the jump a second time. Entering at getpc remains valid; unreachable data is not scanned for apparent branches. This is conservative local recognition, not general constant propagation.
Eleven new synthetic tests cover arithmetic/carry validation, register and SCC clobbers, signed 64-bit offsets, scheduling controls, entries at low/high/setpc, both traversal orders, late ordinary and resolved-far entries, valid/invalid/out-of-range speculative targets, and flow decisions whose invalidating branch disappears on retry. The CFG negative cases check the indirect IR exit in both wave sizes. The original arithmetic regressions failed 3 tests against main; the CFG regressions failed 5 tests against the first PR revision. All 36 decoder/SP3/IR tests now pass.
Validation on Linux x86-64 / Rust 1.100.0:
cargo check -p victory-shader --all-features --locked --offlinepasses. Changed code is formatted; repository asset policy (184 files), staged policy (2 files), and diff checks pass.Semantics checked against AMD RDNA2 ISA, sections 12.1/12.3 and the LLVM 21.1 far-branch sequence. The decoder/control API changes here overlap #2012's lookup work and will need integration if both land. No GPU or game files used; all instruction fixtures are handwritten from the public ISA. No measured in-game impact claimed. AI-assisted: OpenAI Codex.
Coordination claim.
@DrDarkDK on GitHub · 2026-11-25 18:15 UTC · original
A branch can reach
s_setpc_b64without executing the address setup the lookback validates. For example, a conditional branch can targetsetpcdirectly while fallthrough executesgetpc, the low-word operation, and the carry. The lookback resolves one fixed target for both paths, even though the taken branch can arrive with a different address pair.Could we add that control-flow case and leave the jump indirect when a branch can enter after
getpc? Both the decoder and IR builder callcontrol, so the test should check that they agree.Static review only.
AI-assisted with Codex.
@kotekompotek on GitHub · 2026-11-25 18:38 UTC · original
The recognizer is now honest: requiring the matching carry op (addc for add, subb for sub), checking both registers of the pair, and whitelisting only nop/waitcnt as separators closes both holes - a stale getpc+literal pairing and the +/-4GiB-vs-+20 high-word ambiguity. Combining the halves before negating (i128) also fixes the i64::MIN subtraction edge. Test matrix covers every failure mode I can think of, including SCC clobbers and register clobbers at each position in the chain.
@fuzeofficlal on GitHub · 2026-11-25 18:40 UTC · original
Independent Windows 11 verification and code review of
38b757ec(on13f91ca):Verification (
rustc 1.98.1MSVC)cargo clippy --locked -p victory-shader --all-targets -- -D warningsand--features host: 0 warnings.gfx10: 21 passed, 0 failed (all 5 new far-jump tests pass).ir::tests(9 passed),structure::tests(11 passed, 1 ignored),emit::flow_tests(1 passed).Code Review Notes
s_getpc_b64->s_add_u32/s_sub_u32-> matchings_addc_u32/s_subb_u32->s_setpc_b64), GFX10 inline constant decoding (128..=192,193..=208,0xFF),i128negation safety, and stricts_nop/s_waitcnt/s_waitcnt_depctrclobber rejection all look solid.far_jumpwalks backward by byte offset throughbefore(at)without checking whether a branch targets the interior of the chain ors_setpc_b64directly, there is also adecodevsir::build_boundedmismatch:0x00: s_cbranch_scc1 getpc; 0x04: s_branch setpc. Whendecode()follows0x04tosetpcfirst,founddoes not yet containgetpc..addc, sofar_jumpreturnsIndirect(Flow::Stop) and never decodestarget.pendingthen decodesgetpc..addcintofound.ir::build_boundedrunsgfx10::controlover the completedlist, now seesgetpc..addcimmediately beforesetpc, classifies it asFlow::Jump(target), and failsblock_at(target)(jump into a block) becausetargetwas never decoded.s_setpc_b64are not branch targets (or handling the chain consistently acrossdecodeandir::build_bounded) avoids both false-positive static jumps and this decode/IR divergence.@XeNS1 on GitHub · 2026-11-25 18:57 UTC · original
Addressed the CFG-entry and traversal-order findings in
6dbac145d9. Thanks @DrDarkDK and @fuzeofficlal for the concrete cases and the Windows verification of the first revision.The decoder now records branch/jump destinations and rejects a setup with an entry in
(getpc, setpc]. This includes destinations discovered later on another path, including resolved far jumps. If such an entry invalidates a chain already followed, decode restarts and discards speculative instructions and errors. Entries are retained across retries so removing the invalidating path cannot make the same chain oscillate between direct and indirect. Errors from speculative targets are deferred until pending paths have been visited.IR uses the final decoded flow decisions instead of repeating the physical lookback on the final sorted instruction list. This covers the
cbranch getpc; branch setpcordering and the case where the branch invalidating a chain is itself removed during retry.Six additional synthetic tests cover low/high/setpc entries, both visitation orders, late direct/far entries, valid/invalid/out-of-range speculative targets, and retained indirect decisions. A positive control still resolves a branch to getpc and ignores an unreachable data word resembling a branch. The CFG negative cases also check indirect IR exits for wave32 and wave64. With these tests, the previous PR revision had 31 pass / 5 fail; the updated code has 36 pass / 0 fail. Strict harness Clippy, all-features shader library check, repository/staged asset policy and diff checks pass locally. Fixtures are handwritten public-ISA instructions; no game data or game execution was used.
Windows CI on this exact head: passed both workspace Clippy configurations and the workspace tests (run).
AI-assisted with OpenAI Codex.
@pablogonz12 on GitHub · 2026-11-25 19:41 UTC · original
AMD/RADV offline check of the head commit (no game run).
origin/main13f91caee.victory-shader --example retranslate, then dxil-spirv (master),spirv-val --target-env vulkan1.3, and a realvkCreateCompute/GraphicsPipelineson RADV (vkpipe, one process per program, so a driver crash or hang is recorded per program rather than stopping the batch).Result, base
13f91caeevs head6dbac145d: both translate 749 / 751 (the same 2 refused in both:a lane mask read as data is not supported). 0 of the 751 programs' DXIL bytes change, no pipeline result or time differs.None of these programs takes a far jump, so the validation this PR adds is not reached by the dump: the new tests are the evidence, and
victory-shader's test target does not build on Linux here (Windows validator module). No objection from this side.Not tested in a game run; not tested on NVIDIA.
@fuzeofficlal on GitHub · 2026-11-25 19:51 UTC · original
Re-verified
6dbac14on Windows 11 (rustc 1.98.1MSVC,13f91ca):Verification
cargo clippy --locked -p victory-shader --all-targets -- -D warningsand--features host: 0 warnings.cargo xtask policy: 184 files ok.gfx10: 27 passed, 0 failed (all 6 new CFG entry / traversal-order / far-jump recheck tests pass),ir::9 passed,structure11 passed (1 ignored),emit::flow_tests1 passed.Review Confirmation
s_setpc_b64entry-point issue and thedecodevsir::build_boundedtraversal-order divergence are cleanly resolved:decode_with_flows's monotonicentries: BTreeSet<usize>retry loop (allowing entries tostartwhile rejecting(start + 1..=end)), deferred speculative errors, and havingir::build_boundedconsume the resolvedflowsdirectly close the loop completely. Looks ready to merge!@Marvisak on GitHub · 2026-11-25 22:19 UTC · original
Automated triage for the maintainers.
Merge candidate (recommend a look).
gfx10::far_jumpnow accepts a getpc /s_add_u32|s_sub_u32/ matchings_addc_u32|s_subb_u32/ setpc chain only when the registers and carry match and nothing buts_nop/s_waitcnt/s_waitcnt_depctrsits between the steps. It builds the offset from both words (i128, so-i64::MINis safe).decode_with_flowsleaves the setpc indirect when any branch enters after getpc, andir::build_boundednow uses the decoder's final flow decisions instead of resolving the jump a second time. I read the retry loop: entries only grow, and a chain blocked by a known entry is never accepted again, so it terminates. Errors are held until the walk is final. The only other caller of the removedcontrolwasir.rs. The change is more conservative than main (more jumps stay indirect), and the semantics are cited to the public RDNA2 ISA and LLVM's far-branch sequence. The two decode/IR divergence cases raised in review are covered by tests.Heads-up: it conflicts with #2012 (decode by dword table) in
crates/victory-shader/src/gfx10/mod.rs, so whichever lands second needs a rebase.CI:
checkpassing on this head.Generated by Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.