shader: lower s_bfe_u64, s_bfe_i64 and s_brev_b64 in the direct compute path #3089
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3089"
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 R0Y00/Xbox2Windows. Originally posted by legacy-code-archaeologist on 2026-11-27T14:51:22Z.
Fixes #3086 (part of #2935).
Base:
mainatca659396; commit720abcb5.Summary
s_brev_b64,s_bfe_u64, ands_bfe_i64in src/gfx1013_direct_compute.inl, reading all sources before writing the destination pair so overlapping registers stay intact.s_brev_b64uses pure 32-bit DXIL@dx.op.unary.i32(i32 30, ...)(reversebits) without settingInt64Ops, swapping and bit-reversing both halves while leavingSCCunchanged.s_bfe_u64ands_bfe_i64extract width = S1[22:16] bits at offset = S1[5:0] (clamping at 64, sign-extending negative literals fors_bfe_i64only, and writingSCC = (D != 0)).transfer()in src/gfx1013_compute_native.cpp to also clears[dst + 1]for_u64SOP1/SOP2 instructions, and updateuses_scc_after()fors_bfe_u64/s_bfe_i64(overwriteSCC) ands_brev_b64(preserveSCC).Verification
cmake --build --preset dev --target compile_dxil native_store_replay native_compute_ir_dump: built cleanly.ctest --preset dev --no-tests=error -R '^(native_salu_bfe64_brev64_|native_salu_shift64_|native_salu64_)' -V:native_salu_bfe64_brev64_controlspassed (1.30s; pure 32-bit DXILs_brev_b64, 21 cases compiled,_u64descriptor-clobber refusal, 9 negative refusal checks, 6 oracle mutants caught);native_salu_shift64_controlsandnative_salu64_controlspassed.ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' -j 4 --output-on-failure: 27/27 passed (18.72s).tests/docs_links_check.py: passed (79 Markdown files, 586 links).native_salu_bfe64_brev64_hardware: skipped with exit code 77 (requires shader model 6.6 with wave32) on local Quadro M1000M (SM 6.1); GPU readback is unmeasured locally.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-27T15:20:54Z.
Independent AMD Radeon RX 9070 XT result on
720abcb5. Not a code change; measurements only.The body records
native_salu_bfe64_brev64_hardwareas skipped (77: the entry needs shader model 6.6 with wave32, the author's Quadro M1000M reports 6.1), so the GPU readback is unmeasured. This is that run, plus a mutant matrix on the C++ lowering of the three instructions.Environment
devGet-WindowsCapability -Online -Name Tools.Graphics.DirectX~~~~0.0.1.0reportsState: NotPresent, so no validation output exists in any run below720abcb544bf6aa5fd8aec346b148674c9825403,git status --porcelain --untracked-files=noempty,Total Tests: 2625Commands
Observed
The hardware entry passed twice, 4.47 s and 3.88 s, all 21 cases matching words, SCC and guard words:
controlspassed in 1.43 s: 21 cases compiled, 9 operand and destination refusals plus the symbolic descriptor-clobber refusal (unproven resource descriptor s32), and the six oracle mutants caught on 4/4/3/1/1/4 cases. Neighbouring family^native_saluwith-j 4: 6/6 passed (native_salu64controls and hardware,native_salu_bfe64_brev64controls and hardware,native_salu_shift64controls and hardware).native_store_replaycreates its device withD3D12CreateDevice(nullptr, …)and logs no adapter line, so the identity comes from a separate probe making the same call and matchingGetAdapterLuid()against the DXGI enumeration:What the hardware entry pins
One edit per mutant, rebuild, this entry, then
git checkout --with the file sha256 back tof55c3768…andgit status --porcelain --untracked-files=noempty. Restored tree re-run: 21/21 green.s_brev_b64halves not swapped (src/gfx1013_direct_compute.inl:1873-1874,rev_lobuilt fromhi) → fails case 1brev pair scc=0:('brev pair scc=0', (3869426816, 4155757969), 0).& 127→& 63(:1881) → fails case 9bfe_u64 full 64, expected(2309737967, 19088743)scc 1; 8 cases passed before.:1896,or out_lo, out_hi→out_lo) → fails case 15bfe_u64 hi-only nonzero scc, expected(0, 16)scc 1; 14 before.signguard (:1870) → fails case 5brev literal 0x80000001, expected(0, 2147483649)scc 1; 4 before. What this pins is the negative half —s_brev_b64must not extend the literal — and nos_bfe_i64case can separate thesignconjunct, sincesignis true for all of them by construction.width >= 64select replaced by the narrowed result (:1889) → fails case 10bfe_i64 width=127 clamp, expected(305419896, 2147483649)scc 1; 9 before. Note what case 10 pins: the clamp value 127, not the>= 64branch as a property. Atwidth = 64the pad is(64 - 64) & 63 = 0, so the narrowed result already equals the shifted one and case 9 is a no-op for this edit.The
controlsentry does not see this class: on the width-mask tree it still reportsPassed 1.02 secwhile the hardware entry fails. It asserts on emitted-op presence and on refusal messages, so the constants above are pinned by the hardware entry only.What it does not pin, measured
offset = ctrl & 63→& 127(:1880) passes 21/21 on a rebuilt binary, and a probe does not separate the two forms either. Withctrl = 0x0008005c(ISA offset 28, width 8, bit 6 set) the mutated tree shifts by 92; the readback is the same on both trees (lo=0x00000078 scc=1), where the leaked mask would givelo=0x00000000 scc=0. So on this target the wider constant is absorbed before it is observable: the mutant is dead, not merely uncaught, and a case carrying bit 6 would not separate them either. Which layer absorbs it — DXC legalising a shift by 92, or the ISA masking the shift count to 6 bits — was not isolated; there is no DXIL or SASS dump of the mutated shader. The& 63on:1880is justified by the field definition (S1[5:0]), not by any execution here.n == "s_bfe_u64" || n == "s_bfe_i64"from theoverwriteslist (:1457) keeps both entries green (controls 1.17 s,hardware 5.63 s), and reverting then != "s_brev_b64"exclusion fromuncertain_scalar(:1463) does the same (0.98 s,3.52 s). Scope: the two entries of this PR; the wider suite was not run on those trees.CI
Neither entry runs on a
pull_request: the test presetprlists nonative_salu*name. After merge,.github/workflows/windows.yml:496runs the push sweep with-E '_hardware$', so_controlsruns onmainand the hardware half is never built.Limits
One machine, one driver, and no debug layer (above). The adapter identity is established for a separate process making the same
D3D12CreateDevice(nullptr)call; the runner's own device LUID is not logged, and two1002:7550adapters are enumerated on this host, so the match with enum 0 is the best available evidence rather than a reading of the runner. The green says the 21 cases produce the expected words, SCC and guard words on this adapter, and nothing about the inputs the fixture does not build.AI-assisted; runs executed on the machine above.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T15:25:56Z.
Review: APPROVED
Independent integration of
720abcb5withmain5df098da(treef6f9c27b002eee8e3f3b5dafc38e2744fc15baac). The bitfield code keeps all evaluated shift amounts valid, handles widths 0 and 64+, and sets SCC from both output words. Bit reverse swaps the reversed words and preserves SCC. The_u64symbolic clobber control refuses an unproven descriptor.Built
compile_dxil native_store_replayand ranctest --test-dir <build> --no-tests=error -j 1 -V -R '^native_(salu_bfe64_brev64|salu_shift64|salu64)_(controls|hardware)$'. Debug and Release/O2each passed 6/6 with no skips. All 21 BFE/reverse cases matched the result words, SCC and guards on the RTX 4060 Laptop (driver 32.0.16.1656, Windows 11 26200.9974, SDK DXC 10.0.26100, replay debug layer off). The negative references and invalid encodings differed as expected. These wave32 replay cases have no local WARP coverage.