Shaders: shorten long relative VGPR source selections #3630
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3630"
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?
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T23:57:56Z.
The source read in v_movrels_b32 and v_movrelsd_b32 emits a compare-and-select chain. For eight or more candidates, pair neighboring sources and share one index-bit test per level. A final range check keeps the existing fallback. The short path still uses the linear selection.
On a generated compute shader selecting from 56 registers, DXC disassembly shows 57 to 8 integer comparisons, 182 to 139 value-producing instructions, and 3,344 to 2,912 container bytes. The 4-register DXIL is byte-identical. For a generated shader reading and writing through the same relative index, comparisons drop from 61 to 27.
With DXIL validation and app-local WARP, all 160 in-range dispatches matched main across seven source widths and the source-and-destination case. The included test reads every register from a nine-register selection, including the unpaired last one.
Coordination claim
AI-assisted with OpenAI Codex.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-27T23:58:17Z.
On Windows I ran distinct binaries for main
63bcca4and7dfc01awith the same generated shaders, required DXIL validation and app-local WARP 1.0.22 / Agility 1.620.2. All 160 in-range dispatches matched, including odd-width lookups and the combined relative-source/relative-destination move. The new nine-register test passed on the PR head.DXC disassembly for the 56-register test shows 57 to 8 integer comparisons and 3,344 to 2,912 bytes. The four-register test produced identical DXIL. These are emitted code counts from the generated examples.
The full local shader suite was 298 passed on main and 299 on the PR, with the same four failures on both (texture gather, both permute tests, and the edge-flagged triangle test). Strict shader Clippy with default and all features passed, and the asset policy check passed.
If you reuse the code, please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg [email protected] if folding it into another commit.
Imported from Marvisak/VIctory. Originally posted by akimfomin on 2026-11-28T00:28:24Z.
PortBridge compared this with KainanP’s independent M0 select tree in AnyXboxX #571. Both use shared tests of index bits. Here the lowering also guards the result with an unsigned range check. The AnyXboxX version stacks on its census and has a different receiving-tree conflict. An independent CPU check passed all in-range indexes for counts 1–256 and distinguished
count-1fromcountfor sizes 7/8/9.Your WARP runs already covered 160 in-range dispatches. If the hardware contract defines the first excluded index and high M0 bits, those are the useful additional controls. Otherwise keep the zero fallback assertion as a property of the translated code. This records the overlap without duplicating either implementation.
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-28T00:31:25Z.
Independent verification (AI-assisted: Claude Sonnet 5.5). Claim: #1633 (https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7230653883).
Revisions: base
main63bcca43c6a00a758510398fa43096ce7e4f7df0, PR head7dfc01a60a93ee7a084f027d261a70f9ddb38e1d(one commit on top of base, so the trial merge is a fast-forward; diff touches onlylower.rsandvalu_tests.rs).Environment: Windows 11 (26200), debug build, software adapter only (
VICTORY_WARP=1,VICTORY_D3D12_WARP=1; no hardware GPU used). App-local WARPd3d10warp.dll1.0.22.0.20261027.1 loaded from the test exe directory, anddxil.dll1.8.2502.11 (Windows SDK 10.0.26100) loaded, confirmed from the running process's module list. The DXIL validator runs on every generated shader in these tests (expect("DXIL validation failed")).cargo test -p victory-shader --locked --lib --features host -j 4(passed / failed / ignored):hosts_that_do_not_fuse_are_named,gathers_at_a_level_match_the_hardware,permutes_mask_high_address_bits_and_divergent_branches,permutes_read_the_lane_named_and_zero_from_lanes_left_out,wave64_permutes_stay_within_each_32_lane_half,edge_flagged_triangles_draw_as_unflagged_ones. They are WARP-specific and unrelated to this change.relative_source_selects_all_nine_registerspasses on the PR head.Control: the new nine-register test also passes on unmodified base, so this is a semantics-preserving lowering optimization, not a bug fix. Emitted DXIL size from a synthetic probe test (temporary, not committed; 64-VGPR file, relative-source read with 57 candidates, DXIL-validated on both): base 3360 bytes, PR 2920 bytes (-13%). The probe did not count comparisons, so the size is the only number I am claiming.
Other gates (PR head):
cargo clippy -p victory-shader --all-targets --all-features -j 4 -- -D warningsclean.cargo xtask policypassed ("191 files ok"); cargo rejects-jon the xtask alias, so I setCARGO_BUILD_JOBS=4for it.lower.rsis 522,162 bytes on the PR head (520,563 on base), under the 524,288-byte (512 KiB) policy limit and 2,126 bytes below it.Diff review: no correctness issues found.
sreg..=255, stop at the first unreadable VGPR).m0 & bit != 0test per level.sources[i]written after2iand2i+1are read) is safe.m0(>= count, including large values with high bits set) is caught by one unsignedm0 < countcompare and yields 0, which matches the old fallback. Count 0 and count 1 take the linear path.v_movrels_b32andv_movrelsd_b32share this source branch;v_movreld_b32is untouched.k = 9or larger expecting 0. Non-blocking.Aggregate/synthetic numbers only; no game files or retail data involved.
Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T00:35:10Z.
I ran the suggested boundary controls on main
63bcca4and7dfc01awith required DXIL validation and app-local WARP. For 7, 8 and 9 candidates, both revisions read the first and last in-range registers and returned zero at the first excluded index and the high-bit controls. All 24 readbacks per revision matched, including 0x100 and 0x80000000.This verifies preservation of the existing translation fallback across the linear-to-tree threshold. The native register semantics questions remain in #3602 and #1340. The committed nine-register test continues to check the valid selection tree.
Thanks for the independent size measurement and threshold review.
Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-29T20:18:18Z.
NVIDIA full-suite run, to go with the reports above by oni-swr, since none of them names a GPU run. Tested exact head
7dfc01a(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 867 passed, 0 failed, 10 ignored.relative_source_selects_all_nine_registers.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.