Repository navigation
Shaders: in halves, a first lane is read only of a value alike in both halves - #1
Closed
justrealyme wants to merge 1 commit into
Closed
justrealyme wants to merge 1 commit into
justrealyme wants to merge 1 commit into
Conversation
…h halves A wave64 program in halves (two 32-lane host waves per console wave) read v_readfirstlane_b32 as the host wave's first lane. For lanes 32..63 that is console lane 32, not lane 0: a value that differs between the halves comes out per half. On an RTX 5070 Ti, the first lane of the thread id read 32 in all 32 upper lanes (the console: 0). Now the read is kept only for a value proven the same in every lane of the console wave (`halves::lane_uniform`: built from scalars, constants and such values, under conditions that are themselves alike, LDS reads at alike addresses, the thread id shifted past the console wave), which is what the console compiler reads first lanes for. Any other first-lane read is refused with its reason; one whose result is unused costs nothing, as with the other cross-half reads. Offline over the title's shaders (translate --list --wave32): 2,372 compute programs emitted before, 2,360 after; the 12 now refused say "a first-lane read of a value that may differ between 32-lane halves". No other program changes. The analysis is ported from the one in fxceless/victory-fork (Marvisak#497 there). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
chippy01
added a commit
that referenced
this pull request
Nov 25, 2026
…sole wave What was wrong: two results in halves were wrong in the upper host wave (console lanes 32-63). Measured before this change on an RTX 3070 Ti (driver 32.0.16.2124) and the Radeon iGPU of a Ryzen 9 7900X (RDNA2), 32 of 64 lanes wrong on both, while the Radeon's own wave64 form gave the console's results: - v_readfirstlane_b32 read the host wave's first lane, which in the upper half is console lane 32 or later: a first-lane read of the thread id gave 32 in lanes 32-63, the console 0 (reported on Marvisak#2633 by justrealyme). - A DPP row mask was applied by the host lane's row, 0 or 1: with row_mask:0xc, lanes 32-63 (the console's rows 2 and 3) kept their old value instead of taking the DPP result. What changed: - A first-lane read in halves is kept for a value proven the same in every lane of the console wave (halves::lane_uniform: values made from scalars, constants and such values, under conditions that are themselves alike; LDS reads, and buffer loads through a scalar descriptor, at alike addresses; the thread id shifted past the console wave) and in groups of 32 threads or fewer, which one host wave holds whole. Any other is refused with its reason; one nothing uses costs nothing. The analysis is justrealyme's (#1), ported from fxceless/victory-fork (Marvisak#497 there). Added here: buffer loads (a typed buffer's element the compiler loads with a vector load, then reads the first lane of), the dwords a waterfall loop reads (each lane's own, so not alike), and the small-group exception. - DPP row masks take the row from the console lane. - The GPU tests share one dispatch helper. Evidence, translate --list --wave32 over shaders.rpf, the executable, XboxBvhBuilder.dll and the FidelityFX DLL: compute programs emitted 2,372 -> 2,369. The 3 no longer emitted read the first lane of a value the analysis cannot show is alike (scattering_transmittance_system's cloud multiple-scattering cache: a value joined from a branch on a per-lane compare; two ptx_prerender light-atlas programs: a select on a mask made from EXEC, in a loop), so in halves they could compute per-half values. 14 programs refused before give this reason first now; no other outcome changes. The analysis as #1 has it refuses 12: the small-group exception keeps 5 of them, buffer loads 4. No program of the title uses a DPP row mask other than 0xF in halves, so that fix changes none of its translations. Tests (emit::halves_tests): - dpp_row_masks_name_the_console_rows_on_every_gpu (new): row_mask:0xc; 0 of 64 lanes differ on both GPUs (32 before). - first_lanes_kept_in_halves_match_the_console_on_every_gpu (new): the thread id's first lane in a group of 32 and l >> 6 in a group of 128; 0 lanes differ on both GPUs. - reads_across_32_lane_halves_are_refused_with_their_reason: the thread id's first lane is refused in a group of 64 and kept in a group of 32; an unused one costs nothing; a buffer dword loaded at an offset alike in every lane is kept, at the thread id's offset refused. - the_test_programs_are_what_their_comments_say: every hand-encoded program checked against the disassembler. Checks: cargo clippy --workspace --all-targets --locked -- -D warnings, and with --all-features: clean. cargo xtask policy: ok. cargo test -p victory-shader --lib -- --test-threads=1: 273 passed, 3 failed, the same 3 as on main on this NVIDIA machine (two stride_tests, gathers_at_a_level_match_the_hardware); heap_direct_texture_reads_mark_their_heap_index skipped as before. lower.rs is 495,122 bytes. Co-Authored-By: justrealyme <82029927+justrealyme@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
|
Thanks! I reproduced the bug on an RTX 3070 Ti and the Radeon iGPU, and folded this into Marvisak#2633 with you as co-author. I added two things on top of your analysis:
Closing this one in favour of the commit on Marvisak#2633. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A fix for Marvisak#2633: in halves,
v_readfirstlane_b32read the host wave's first lane. For console lanes 32..63 that is lane 32, not lane 0, so a value that differs between the halves comes out per half.How it showed up
A test program in halves (
v_mbcntfor console lanes, thenv_readfirstlane_b32 s12, v0), dispatched on an RTX 5070 Ti (driver 621.40): all 32 upper lanes read 32; the console reads 0. The Intel iGPU on the same machine got 48 of 64 lanes wrong.The change
halves::lane_uniform). That covers what the console compiler reads first lanes for:id >> 6and up, for groups whose console waves are runs of 64 along x).emit/lower/halves.rs.lower.rsgrows by 24 lines (494,791 bytes).Evidence
victory translate --list --wave32over the title's shader pack, executable, BVH builder DLL and upscaler DLL:Tests
reads_across_32_lane_halves_are_refused_with_their_reason:first_lanes_of_alike_values_match_the_console_on_every_gpu(new, runs on every hardware adapter): a group of 128 (two console waves) reads the first lane oftid >> 6in halves. 0 of 128 lanes differ from the console on the RTX 5070 Ti and the Intel iGPU.the_first_lane_program_is_what_its_comments_say: the hand-encoded words are checked against the disassembler.Checks on Windows 11, RTX 5070 Ti, driver 621.40:
cargo test -p victory-shader --lib --release -- --test-threads=1: 273 passed. The 3 failures are the same NVIDIA ones listed in Shaders: wave64 compute programs run in 32-lane halves on hosts of 32-lane waves Marvisak/VIctory#2633 (twostride_tests,gathers_at_a_level_match_the_hardware), andheap_direct_texture_reads_mark_their_heap_indexwas skipped as there.cargo clippy --workspace --all-targets --locked -- -D warnings, also with--all-features: clean.cargo xtask policy: ok.Not covered
Without console lanes, a wave64 program's first-lane reads stay as on
main: the host wave's first lane, whatever wave size the driver picks. That is the existing shortcut and is not changed here.AI-assisted (Claude Code). No game data in this PR.
🤖 Generated with Claude Code