Shaders: lower s_bfe_u64, s_bfe_i64 and s_bfm_b64 #1395
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1395
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1395"
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?
@AnoHunted on GitHub · 2026-11-24 17:42 UTC · original
AnoHunted:shaders-scalar-bitfield-64→main· +208 −0 · 2 files · 2 commits · openWhat
The scalar 64-bit lowering path refused
s_bfe_u64,s_bfe_i64ands_bfm_b64. They now lower:s_bfe_u64/s_bfe_i64: the field is(src0 >> src1[5:0]) & ((1 << src1[22:16]) - 1); the signed form sign-extends from the field's top bit (width 0 gives 0). SCC is set to whether the result is nonzero.s_bfm_b64:((1 << src0[5:0]) - 1) << src1[5:0]. It does not write SCC, so SCC keeps its earlier value.A width of 64 or more (and a field running past bit 63) is not defined by the ISA; it takes every bit, with shift amounts masked, so the lowering cannot go out of range. No test depends on that case. The 32-bit
s_bfm_b32is left as it is.Why
A shader using any of these three failed to translate. They are the 64-bit counterparts of
s_bfe_u32/s_bfe_i32/s_bfm_b32, which already lower.Related PRs: #163 and #231 contained these ops but are not on main. #447 (64-bit literal sign extension) touches the same function but not these arms; this change is made on current main and does not depend on it. #166 covers different 64-bit bit ops.
Tested
Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1 (hardware and WARP):
cargo test -p victory-shader --features host -- --test-threads=1: main 120 passed, 0 failed, 1 ignored; branch 123 passed, 0 failed, 1 ignored (3 new tests).s_bfe_64_extracts_and_sets_scc: runs both ops on the GPU for low dword, high dword and SCC (e.g.0xFEDCBA9876543210, offset 32, width 16 gives0xBA98unsigned and0xFFFFFFFFFFFFBA98signed; zero field gives 0 and SCC 0).s_bfm_b64_builds_a_mask_and_keeps_scc: masks such as width 40 / offset 8 give0x0000FFFFFFFFFF00, and SCC set by ans_cmpbefore the instruction is read back unchanged afterwards (both 0 and 1, including a nonzero mask).scalar_64_bit_field_ops_lower: hand-assembled encodings lower.AMD hardware: not tested.
Not tested
No game files were used.
@dcastell1 on GitHub · 2026-11-24 17:51 UTC · original
Verified on native Windows (no Wine): NVIDIA GeForce RTX 5090 (driver 621.24), Windows 11 10.0.26300, Rust 1.98.1, MSVC 14.44.35207, debug build.
main@ffe310ebaseline on this box: 342 passed, 0 failed, 6 ignored.Three more than the baseline;
s_bfe_u64,s_bfe_i64ands_bfm_b64lowering ships its cases and they run green.Tree restored afterwards (full diff against a clean checkout); no game data, the tests are synthetic. AI-assisted (opencode): applied the patch to a built tree, ran
cargo test --workspace, reverted it.@matheusfermiano-source on GitHub · 2026-11-24 18:08 UTC · original
An AMD run, since the PR says AMD hardware was not tested; under Proton on Linux:
scalar_64_bit_field_ops_lower,s_bfe_64_extracts_and_sets_scc,s_bfm_b64_builds_a_mask_and_keeps_sccpass on both GPUs.a91e9ad. Built on Linux with llvm-mingw forx86_64-pc-windows-gnullvm(Rust 1.98.1) and run under Proton Experimental (11.0-20261027b) with its vkd3d-proton 3.1.0, one GPU at a time;dxil.dllfrom DXC 1.9.2609 was loaded, so the test modules were validated.victory-shadersuite 122 passed, 1 failed, 1 ignored. Nothing fails that passes onmain(ffe310e). The one failure,emit::tests::stub_pipeline_is_created, fails onmainhere too: vkd3d-proton accepts the zeroed DXIL hash that the Windows runtime refuses (one of the Wine failures listed in #1218).This is RADV, not AMD's Windows driver, so it adds to a Windows run rather than replacing it. Synthetic tests only, no game files. AI-assisted (Claude Code, Opus 5.5); every run was on this machine.
@wwwwwwww3333333 on GitHub · 2026-11-24 19:14 UTC · original
Native Windows run on AMD RDNA2: RX 6750 XT (RDNA2, gfx1031), AMD driver 32.0.21045.29003, i5-13400F, Windows 11, Rust 1.98.1 MSVC. Head
a91e9adon mainffe310e(clean merge).cargo test -p victory-shader --lib -- --test-threads=1: 123 passed, 0 failed, 1 ignored (main alone: 120 passed).s_bfe_64_extracts_and_sets_scc,s_bfm_b64_builds_a_mask_and_keeps_sccran on the hardware adapter and then on WARP, and passed on both.scalar_64_bit_field_ops_lowerpasses too. The earlier AMD run here was under Proton; this one is AMD's own D3D12 driver.Synthetic tests only, no game files. AI-assisted (Claude picked the PRs and wrote the batch script; I ran it on my machine).
@sinan-cmyk on GitHub · 2026-11-24 20:44 UTC · original
Offline measurement on a retail dump, and the shader tests on Ada
Result: no count change against
main.Offline. I merged head
a91e9adontomainffe310e(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 21,724 onmain, 21,724 with this PR.No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on
main. The count shows that the change rejects nothing. It does not show whether the output is right.Tests: with the same merge,
cargo test --locked -p victory-shader --libpassed 123, failed 0. The bitcode benchmark is ignored, as onmain, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, withVICTORY_WARPunset.No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
@Marvisak on GitHub · 2026-11-25 02:38 UTC · original
Automated triage for the maintainers. Recommended for a maintainer's look: this lowers s_bfe_u64, s_bfe_i64 and s_bfm_b64 (SOP2 0x29, 0x2a, 0x25) in the scalar 64-bit arm of
lower.rs, which main refuses today. I checked the arms against the RDNA2 ISA (offset in bits 5:0, width in bits 22:16, SCC = result nonzero for s_bfe, SCC untouched by s_bfm), the hand-assembled encodings inscalar_64_bit_field_ops_lower, and the expected values in the GPU tests; contributors report the tests passing on NVIDIA and AMD (native and vkd3d-proton). CI fails only onsynthetic_tests::gathers_at_a_level_match_the_hardwareandpermutes_read_the_lane_named_and_zero_from_lanes_left_out, which this PR does not touch and which fail the same way on other PRs against current main. Small nit: there is a doubled blank line afters_bfm_b64_builds_a_mask_and_keeps_sccinvalu_tests.rs.Generated by Claude Code
@fuzeofficlal on GitHub · 2026-11-26 01:08 UTC · original
Code review and RTX 5090 + WARP + DXIL verification at head
a8299456fc12merged ontomain(63bcca43c6a0):xtask):crates/victory-shader/src/emit/lower.rsreaches526,300bytes (+2,012B over the524,288-byte limit), causingcargo xtask policyto fail (rc=1). Moving these 64-bit bitfield helpers into a submodule underemit/lower/will clear the policy check with headroom.lower.rs:3816-3922):s_bfe_u64/s_bfe_i64maskoff = n & 63,w = (n >> 16) & 127, handlefull = w >= 64andw == 0cleanly (skipping sign-extension onfull | (w == 0)while usingAShr/LShrand(64 - w) & 63shifts in-range), and setSCCvia 64-bitnonzero(rl, rh).s_bfm_b64masks bothsrc0[5:0]andsrc1[5:0]and leavesSCCuntouched.dxil.dll10.0.26100.0, Rust 1.98.1):cargo xtask policy: FAIL (lower.rs: 526300 bytes exceeds the 524288-byte limit)cargo clippy --locked -p victory-shader --tests -- -D warnings: 0 warningsscalar_64_bit_field_ops_lower s_bfe_64 s_bfm_b64: 3/3 passed across RTX 5090 (hardware) and WARP (warp+ explicitVICTORY_WARP=12/2).Lowering and hardware tests are solid — just needs extracting out of
lower.rsto passxtask policy.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.