Shaders: simplify the high-half offset in s_ff1_i32_b64 #3688
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3688"
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 Ingenioeren on 2026-11-28T07:01:30Z.
s_ff1_i32_b64scans two dwords and offsets a high-half match by 32. Replace the high-half add/compare/select withFirstbitLo(high) | 32: results 0–31 become 32–63, and the0xffffffffno-match sentinel stays unchanged. The low-half selection and SCC behavior stay the same. DXIL FirstbitLo contract.A synthetic compute shader with two dynamic root constants and a live UAV store emits 23 → 21 DXIL instructions (8.7% fewer). This counts the whole written function, including setup and terminators; GPU time and game frame rate were not measured. The test-only counter is identical to #3600 and the subsequent lowering PRs.
Validation on Windows, RX 6750 XT and WARP, using synthetic inputs only:
cargo test --locked --offline -p victory-shader scalar_first_set_bit_64 -- --nocapture: tests-only control fails the count assertion at 23 versus 21; final passes both tests. The execution test passes before and after on both adapters: 14,720 inputs, three destination choices (separate, overlapping low, overlapping high), both SCC values, zero model mismatches or adapter differences. It includes every single-bit position, every pair of low/high first-bit positions, zero, complements, prefixes, and deterministic random inputs. The reference searches individual bits. DXIL validates.cargo test --locked --offline -p victory-shader --no-fail-fast: baseline 300 passed / 2 known failures / 3 ignored; final 302 passed / the same 2 failures / 3 ignored. Failures arerectangles_get_their_fourth_cornerandelements_sharing_a_row_keep_their_order(local dxil.dll PSV mismatch). Integration: 3 passed / 1 ignored; doc tests: 0.cargo clippy --locked --offline -p victory-shader --all-targets --all-features -- -D warnings: passed before and after.cargo run --locked --offline -p xtask -- policy --staged: passed, all 3 staged files.git diff --cached --check: passed. Rustfmt comparisons retain exactly main's existing formatting deviations in all three changed files.#148/#2063 add first-clear-bit support near this arm; this change only simplifies the existing first-set-bit lowering. Depending on merge order, the shared arm may need a small rebase.
No game files or game run. The new execution probe uses wave32. Other vendors, Linux/RADV, graphics and mesh execution were not tested.
AI assistance: prepared with OpenAI Codex, reviewed by Ingenioeren.
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-28T07:25:43Z.
Independent Software WARP Verification
main):63bcca43c6a00a758510398fa43096ce7e4f7df0#3688head:d9e912fdc9984598308cba59f19e02b694f15636(clean fast-forward merge; merge tree54b7a5edcc041677b0c8612baeb59d334b1638cc; also merges cleanly with#3679into tree6526713a581880b3eeb40fb931a3d69cd1658847)VICTORY_WARP=1,VICTORY_D3D12_WARP=1); DXGI reportsMicrosoft Basic Render Driver (VendorId=0x1414, DeviceId=0x008C, Flags=0x2)d3d10warp.dll10.0.26100.9818,dxil.dll1.8.2502.11Results (base vs merged)
63bcca43:cargo test --locked -p victory-shader -j 4 --no-fail-fast: lib 298 passed, 4 failed, 3 ignored; integration (resource_tracking) 3 passed, 0 failed, 1 ignored; doc-tests 0. (The 4 lib failures are WARP-expected hardware-only tests:a_mask_joined_with_data_at_a_uniform_loop_is_its_number,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.)scalar_first_set_bit_64_instruction_countfailed as expected (23vs21DXIL instructions);scalar_first_set_bit_64_matches_the_referencepassed (14,720 inputs, 0 mismatches).#3688(d9e912fd):cargo test --locked -p victory-shader scalar_first_set_bit_64 -j 4 -- --nocapture: 2 passed, 0 failed (21DXIL instructions; execution test 14,720 inputs, 0 mismatches).cargo test --locked -p victory-shader -j 4 --no-fail-fast: lib 300 passed, 4 failed, 3 ignored (+2 new tests passing, exact same 4 pre-existing WARP-only failures); integration 3 passed, 0 failed, 1 ignored; doc-tests 0.cargo clippy --locked -p victory-shader --all-targets --all-features -j 4 -- -D warnings: passedcargo xtask policy: passed (191 files ok);crates/victory-shader/src/emit/lower.rsis 521,070 / 524,288 bytes (+507 bytes over base520,563, leaving 3,218 bytes of headroom below the 512 KiB policy cap).Diff Review
FirstbitLo(high)returns0..=31whenhigh != 0(bit 5 is 0, sofb | 32 == fb + 32in32..=63) and0xffffffffwhenhigh == 0(bit 5 is already 1, so0xffffffff | 32 == 0xffffffff). Low-half precedence (a != 0 ? fa : fb) and SCC preservation (unchanged bys_ff1_i32_b64, verified across both SCC states and overlapping destinations) are preserved.#148/#2063(s_ff0_i32_b32/s_ff0_i32_b64, currently 160 commits behindmain); only touches the existings_ff1_i32_b64arm.Verified by Gemini 4 Neon (Antigravity) on software WARP.
Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T15:51:54Z.
Hardware run: RX 5700 XT (Navi 10, RDNA1, 32–64 lanes, driver 32.0.21045.29003, Windows 11 26200), head
d9e912fon63bcca4.scalar_first_set_bit_64_matches_the_referencepasses with zero mismatches on the card and on WARP.scalar_first_set_bit_64_instruction_countpasses.victory-shader --lib --features host: 304 passed, 0 failed, 3 ignored.AI use: Claude Code (Claude Opus 5.5).
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.