Shaders: include v_readfirstlane_b32 in wave64 exchange and check implicit reads in lane_uniform #354
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!354
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-354"
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?
@AscilCH on GitHub · 2026-11-24 23:49 UTC · original
AscilCH:fix/shader-wave64-readfirstlane-and-uniform→main· +297 −18 · 2 files · 1 commits · openProblem
Two wave64-on-wave32 soundness bugs in
crates/victory-shader/src/emit/lower.rs:exchangeforv_readfirstlane_b32(Lower::new):console_lanes,crosses, andVICTORY_WAVE_WHYcheckedv_readlane_b32andv_writelane_b32but omittedv_readfirstlane_b32. On 32-lane hosts, a console wave64 compute shader usingv_readfirstlane_b32without another full-wave crossing op did not set upexchangeLDS, so lanes 32..63 executedWaveReadLaneFirston their own 32-lane half instead of across all 64 lanes.lane_uniform:lane_uniformonly checkedv.srcand ignored implicit reads ininst.reads(e.g., accumulator VGPRs inv_fmac_*/v_mac_*/v_dot*c_*, preserved 16-bit destination halves, and implicitVCCin VOP2v_cndmask_b32/v_add_co_ci_u32/v_div_fmas_f32) as well asmovrel*. Whenever explicit sources were uniform, the per-lane result was falsely added toself.uniform, causingv_readfirstlane_b32to skipexchange_halves.Fix
v_readfirstlane_b32toconsole_lanes,crosses, andVICTORY_WAVE_WHY(leaving waterfall descriptor reads unaffected since those lower per-lane).(reg, val)ininst.readsinsidelane_uniform(and excludemovrel*) so implicit VGPR andVCCdependencies are properly tracked.wave64_readfirstlane_exchanges_across_halves_on_32_lane_hostandwave64_implicit_reads_are_not_marked_lane_uniforminemit::wave64_tests(assertingwave_size == Some(32)andhalf_exchanges> 0 for standalonev_readfirstlane_b32,v_fmac_f32, and VOP2v_cndmask_b32,half_exchanges == 0for truly uniformv_mov_b32, validated bydxil.dll, and executed on 32-lane hardware when supported).Verification
cargo test -p victory-shader --locked wave64: 9 passed, 0 failed (dxil.dllvalidation +wave_size/half_exchangesassertions; note Intel UHD adapter 0 skips[WaveSize(32)]compute execution as with the existingwave64_tests)cargo test -p victory-shader --locked waterfall: 21 passed, 0 failed (verified waterfall wave64 unaffected)cargo xtask policy: 169 files okcargo clippy -p victory-shader --all-targets --locked -- -D warnings: cleancargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: clean(AI-assisted; synthetic tests only, no game data.)
@m335671 on GitHub · 2026-11-25 17:53 UTC · original
Offline check on a 32-lane card. On current
main, this PR makes the driver refuse 10 compute pipelines that it creates without it, and it adds none.Tested
main3973179, thenmainwith this PR's head6273077merged in. The merge was clean.VICTORY_HOST_MAX_WAVE=32 victory translate --list --pipelinesover the title's whole shader pack, compared program by program by hash.main3973179main+ this PREach of the 10 goes from
pipeline createdtopipeline: The parameter is incorrect.:meshlet_culling:CS_BatchCullPreSkinnedMeshlets, with its_Prev,_ParaboloidShadowsand_ParaboloidShadows_Prevvariants (0452fc2d2e2fc4c3and 3 others)subsurfacescatter:CS_SSSPrefilterFull/Half, each with its_MaterialTilesvariant (41f021c4e168e70b,7e96471a390eb947and 2 others)vfx_proj_decal_hit_detection:CS_ComputeHitDetectionResultsandCS_ComputeHitDetectionSkinnedResultsNone of the programs that
mainrefuses comes up with it.My guess, which I haven't checked: these programs already pass through
v_readfirstlane_b32and now take the half exchange as well, and the form the driver gets is no longer one it accepts. That would fit "the fix is right, but it needs a fallback when the exchange form can't be created". The pre-skinned meshlet culling is the one that matters most: if its dispatches are dropped, skinned meshes may not be culled or drawn.Not tested: in the title (offline the result is already worse on this card), other GPUs, and the PR on its own base (
2119b0e).AI use: Claude Code (Claude Opus 5.5) built and ran the check on my machine, compared the listings and wrote this comment.
@HAL9000RELOADED on GitHub · 2026-11-25 19:29 UTC · original
RX 7900 XTX (RDNA3), Windows 10 + #402 for SM 6.6, main
d510ee4: both new tests pass on the card with this PR. No other test changed. Run table: #129 (#129).@ArturoWolff on GitHub · 2026-11-26 16:48 UTC · original · edited 2026-11-26 17:56 UTC
There is one more ordinary two-result case worth covering in the uniformity analysis here:
v_swap_b32. AscilCH's implicit-read work in #354 is what led me to check it. The destination's old value is an actual input to the value written back to the source, not merely an inactive-lane preservation dependency. AMD's RDNA 2 ISA, section 12.8, V_SWAP_B32 defines the exchange of both operands.I tested the actual
ir::build->structure->all_lane_blocks->lane_uniformpath with this entirely synthetic, unguarded sequence and its reverse register order:Here
v0is a varying input. The fixture also runs both input orders and both same-kind controls. Its independent CPU oracle swaps two initialized values for each of 64 lanes and checks which output is constant across the lanes. A1below means the output is proved uniform, in encoded destination/source order. These are analysis results, not GPU readbacks.All four controls (both varying or both uniform, in both register orders) agree with the oracle in all three builds. The two focused tests on each uncorrected revision return 1 pass / 1 intended assertion failure; on the corrected receiver both pass. The existing native library suite gives 171 passed / 3 ignored before and after, with identical named outcomes. The historical #354 head gives 170 passed / 2 ignored. All builds completed successfully.
Exact tested revisions: main
93db653ada3ee0b94b2334243d7af81c3d12f27aand #354 head6273077e2b8d3583f681aeafbce1ce83040f936d. These are separate source snapshots, not a causal whole-PR A/B. The controlled correction is on the first revision, with the same test-only fixture and lockfile before/after. Native x86_64 Linux, Rust 1.98.1, independent Cargo targets, locked/offline builds. No game, display, or GPU access.Strict Clippy for the corrected non-test library also exits 0. Strict native
--lib --testslint exits 101 on both the receiver and its corrected version, with the same four unused-import/variable/mutability diagnostics in the unchangedemit/mod.rs. I left those unrelated Windows-gated test warnings outside this correction.The narrow correction I tested is to retain the existing VALU and guard eligibility checks, handle this instruction before the generic
alikeclassification, and propagate each old SSA input only to the output it supplies. Withvborrowed from the existingFields::Valumatch:For #354 this needs to be before the generic implicit-read/overwritten-destination filtering. Simply requiring both old values to be uniform would avoid the false positive but still miss the uniform output of a mixed swap. The tested main's ascending-register read selection also makes the two register orders differ. The per-result rule handles both tested orders while retaining the existing guard eligibility checks. This matters because
v_readfirstlane_b32can consume this proof when deciding whether the two host halves need to exchange values.Main advanced to
e4245f3c1b0490250d9cf0946a2113000be98687while closing this comparison. I checked that the text oflane_uniformis unchanged and that the correction applies cleanly there, but its surrounding translator has changed and that newer revision has not been built or executed in this comparison. This is only a small proven analysis correction; I have not established a connection to the ten pipeline refusals reported above, the two water programs, driver execution, lighting, or title frame time.Update: actual RTX 4060 / Proton readbacks on main
e4245f3The CPU analysis above now has a physical execution counterpart on
e4245f3c1b0490250d9cf0946a2113000be98687. I used the same narrow per-result correction, not the whole historical #354 change, in a detached copy of that revision. Both arms have identical synthetic test code, registration and Cargo.lock. The production difference is confined to the swap uniformity analysis described above.The new
ordinary_swaps_preserve_console_first_lane_valuestest exercises both encoded register orders, all four combinations of varying/uniform inputs, and a console-wide lane read to retain the wave64-on-wave32 path. It compares both exchanged values and both subsequent first-lane broadcasts against an independent per-lane arithmetic oracle. Each dispatch writes 256 words into its own bounded output resource. All eight shaders in each arm passed the DXIL validator, created a compute PSO, completed their fence, returned the complete readback, and passed the device-status check.In the failing baseline case, the first-lane value should be 1063 across all 64 lanes. Lanes 32–63 instead return 1095. The corrected shader returns 1063 throughout. The other three mixed cases already returned correct data, but emitted an unnecessary exchange. All four same-kind controls keep their exact correct outputs and barrier counts. Across eight cases per arm: 32/2048 incorrect output words before, 0/2048 after. The focused test has one intended baseline assertion failure (Windows child exit 101) and one corrected pass (child exit 0). Both native Linux library suites report 175 passed, 0 failed, 3 ignored, with identical named outcomes.
Conditions: NVIDIA GeForce RTX 4060, driver 620.73.04, 8188 MiB VRAM, SM 6.6, wave lanes 32..32; GE-Proton 11-14 / Wine 11.0 Staging, vkd3d-proton build
71cae091b06571e. Separate locked/offline Rust 1.98.1 and LLVM MinGW builds, fresh matching copies of the same game-free prefix, initially empty private driver caches,VICTORY_SHADER_OPT=63,VICTORY_GROUP_SYNC=2. A private virtual display was used only for device initialization. The host-memory guard remained at 512 MiB and neither arm had a guard stop, host OOM kill, or monitored kernel GPU fault.This confirms an actual arithmetic correctness improvement on the newer receiver, as well as removing needless synchronization in the other mixed cases. The emitted instruction counts are not timing measurements. There is still no measured connection to the title's water or lighting problems, the ten reported pipeline refusals, game frame time, or AMD/native Windows behavior. No game launch, captures, extracted shader code, or game data were involved. The full corrected test patch is kept isolated from installed main; the source-file-size policy discussion in #1342 is an independent existing integration issue, not something I have bypassed.
AI assistance: Hermes Agent, working on behalf of ArturoWolff. (GPT 6.2 Sol Max).
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.