Shaders: NaN guard on colour exports and typed stores (VICTORY_NAN_GUARD) #837
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!837
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-837"
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?
@PastiiJay on GitHub · 2026-11-25 09:57 UTC · original
PastiiJay:amd-nan-guard→main· +51 −2 · 1 files · 2 commits · openAsked for on #3: this ports the NaN guard from KLBF Lab, our AMD-focused build (commit
0e5f4b2, test builds in KLBF Lab Beta), onto currentmain, on its own.What it does. A float a pixel program exports to a colour target has NaN turned into 0 and an infinity into ±65504. Typed image and buffer stores get the same treatment, but only for the NaN the GPU itself produces (
0x7FC00000, either sign) and infinities, so integer bits written through a typed store pass untouched. Raw buffer stores are left alone (there is no type to go by). The idea: a NaN produced by a 32-lane program running on a 64-lane AMD wave can no longer stay in a temporal buffer the title blends into every frame and spread as purple.Switch.
VICTORY_NAN_GUARD, on by default;VICTORY_NAN_GUARD=0turns it off. On currentmainthe translation-cache key picks up every"VICTORY_*"literal invictory-shaderthroughbuild.rs, so the switch joins the key without editing a list (the manual list mentioned on #3 is no longer there), andshader_cache.rsis unchanged.Measured. On an RX 9070 XT, by us and by IxMxAMAR (see #3; related: #318). This was the change that removed the remaining purple in both cases.
Caveats. This probably hides the symptom rather than fixing the root cause (whatever produces the NaN in the first place), so it may be worth keeping only until that is found. We have a single machine, so results on other cards are unknown.
Checks.
cargo build --release,cargo clippy(no new warnings),cargo test --release -p victory-shader: 215 passed, 0 failed.@avt0m4t48 on GitHub · 2026-11-25 10:51 UTC · original
I independently checked
23da1ac38c9826d07bd3e14f8d415f5c037953c5against its parent and the listed base,9376fd60c0ba0e76a74c39b49b1407dbac0a64c7. I inspected 80 scalar operands in the emitted DXIL from 20 original synthetic shaders.7fc00000,ffc00000,7f800000, andff800000. Noncanonical NaNs, signed zeros, subnormals, and finite controls passed through. Unsigned color exports and raw buffer stores preserved all 16 patterns.0x7fc00000now emits zero. The four exceptions are worth spelling out in the PR description because they qualify the statement that integer bits pass through.VICTORY_NAN_GUARD=0, all 20 emitted containers were byte-identical to base. The translation fingerprint contained the switch and distinguished default from opt-out.cargo check --locked --offline -p victory-shader --tests --target x86_64-pc-windows-msvc. The operand checks used LLVM disassembly. Windows execution, Microsoft DXIL validation, and GPU readback remain unverified.AI-assisted using Codex.
@eazyves on GitHub · 2026-11-25 10:51 UTC · original
Two notes; I haven't run this in the game.
From reading the diff, integer bits do not always pass untouched. Typed stores all go out as
textureStore.f32/bufferStore.f32here, whatever the view's format, sonan_guard(_, false)also sees integers. By its arithmetic, these four 32-bit values change:0x7F8000000x477FE0000xFF8000000xC77FE0000x7FC00000,0xFFC000000They can be ordinary data:
0xFF800000as packed RGBA8 is an opaque mid blue. If a uint or packed store reaches this path, it would be a wrong value rather than a NaN. I did not check whether the title's stores do. If the format isn't known at that point, limiting the guard to the colour exports (strict) would avoid it.Tests on an RX 9070 XT (driver 32.0.32029.2010, Windows 11 26200),
23da1ac:cargo test --workspace --locked --no-fail-fastgives 539 passed, 1 failed, 10 ignored, with the hardware device in use. The failure ismodules::display::tests::sdr_and_display_deferrals(0x80070032), which fails onmainhere too because I run from a service session. The PR adds no test of the guard itself.AI-assisted (Claude Code); run on my machine.
@PastiiJay on GitHub · 2026-11-25 10:58 UTC · original
Thank you both @avt0m4t48 and @eazyves, very careful reviews.
You are right: typed stores go out as
.f32whatever the view's format, so the four words0x7F800000,0xFF800000,0x7FC00000and0xFFC00000were changed even when they were integer data. Pushed45c5924:strictpath, where the target is known to be float);VICTORY_NAN_GUARD=stores, with the four changed words spelled out in the code comment;VICTORY_NAN_GUARD=0is unchanged (off, byte-identical output).We will re-run our AMD tests with the default and with
storesto check whether the colour-export guard alone keeps the image clean, and report back here.@avt0m4t48 on GitHub · 2026-11-25 11:05 UTC · original
I reran the original 20 synthetic shader fixtures on
45c59247c37d61fa77df96f2188cb9f58c0a6e8eand compared the emitted DXIL with the same9376fd60c0ba0e76a74c39b49b1407dbac0a64c7baseline.VICTORY_NAN_GUARD=stores: float colour output matched the default byte for byte. The typed image and buffer paths each changed exactly0x7F800000,0xFF800000,0x7FC00000and0xFFC00000out of 16 tested words. Raw stores and unsigned colour exports still matched the base.VICTORY_NAN_GUARD=0: all 20 containers matched the base byte for byte. The shader translation fingerprint distinguished all three settings.The untouched PR head passed the Linux shader library suite (171 passed, 2 ignored) and Windows MSVC cross-target test compilation. The fixture check inspects emitted operands and container bytes. Windows execution, DXIL validation, and GPU readback are still open.
@PastiiJay on GitHub · 2026-11-25 11:10 UTC · original
Thanks @avt0m4t48 for re-running the fixtures on
45c5924, that confirms the three settings behave as intended. The in-game A/B on our RX 9070 XT (default vsstores) is next; we'll post the result here.@PastiiJay on GitHub · 2026-11-25 12:25 UTC · original
In-game check on our RX 9070 XT (Adrenalin 32.0.32029.2010, Series S mode with AMD FSR,
45c5924on top of our AMD branch): two 14 min runs, one with the default (colour exports only) and one withVICTORY_NAN_GUARD=stores. Both ran without a device removal, at a median of 6.6 and 6.8 fps in the world. With the default, the cutscenes and the boat section render cleanly: no purple blocks stuck on screen; some small purple patches remain on vegetation, as in our earlier builds. So the colour-export guard alone looks enough for what it was meant to fix here. One machine, two runs.@MamaLeVrai on GitHub · 2026-11-25 12:23 UTC · original · edited 2026-11-25 12:51 UTC
Test report on real hardware: AMD RX 6950 XT (RDNA2), Windows 11, Rust 1.98.1, with a GPU present. I merged this PR's head
45c5924intomainf85101bin a throwaway tree (no conflict).cargo clippy --workspace --all-targets --locked -- -D warningsfails with the errorsmainitself has on this machine (placed_filler_twins,depth_written, a sort, andmanual implementation of .is_multiple_of()atvictory-gpu/src/shadow.rs:2675; PR #841 fixes the first three), also with--all-features; this PR adds none. (Correction: my first version of this report said that theis_multiple_ofone was extra here. It is inmaintoo: my first baseline run ofmaindid not list it, and a run with--keep-goingon a cleanmaindoes.)cargo test --workspace --locked: run 1: stopped atindirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields(the one that fails onmainitself most runs here (PR #849 and #847 fix its assertion)) andwatch::tests::a_write_is_reported_at_every_checked_view(not a test I have seen fail before; I did not look into it); run 2: 565 passed, 0 failed, 12 ignored (mainalone: 555 passed, 0 failed, 11 ignored). The title was not run, so this says nothing about in-game effect. No game data.AI-assisted (Claude Code); no game data.
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.