Lower RDNA2 32-bit bitfield extracts with masked HLSL shifts #127
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/128"
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 KomaGuy on 2026-11-21T16:41:29Z.
Change
Align 32-bit bitfield extraction (
v_bfe_u32,v_bfe_i32,s_bfe_u32, ands_bfe_i32) intools/ffx_dispatch_aot.pyandtests/ffx_dispatch_io.hlsliwith AMD RDNA2 (gfx1013/gfx1030) hardware semantics under HLSL Shader Model 6 shift rules:v_bfe_i32/s_bfe_i32whenoffset + width > 32orwidth == 0: Replacesasint(x << (32 - offset - width)) >> (32 - width)withbfe_i, avoiding modulo-32 shift-count underflow whenoffset + width > 32(which extracted low bits instead of sign-extending[31:offset]) and returning0whenwidth == 0instead ofasint(x << ...).v_bfe_u32/v_bfe_i325-bit operand masking: Masks vectoroffset(S1[4:0]) andwidth(S2[4:0]) to& 31u, without modifyingscc.s_bfe_u32ands_bfe_i32scalar control operand (S1) andSCCupdate: Unpacksoffset = S1 & 31uand 7-bitwidth = (S1 >> 16) & 127uin HLSL rather thanint(inputs[1], 0), supporting SGPRS1operands, negative inline constants,s_bfe_i32, andwidth >= 32without(1u << 32) - 1wrapping to0in HLSL, and setsscc = dest != 0u;(withsccalso declared inpredecessor()ands_cselect_b32supported alongsidesrc_sccconsumers).Verification
Tested on Linux x86_64:
python3 -B tests/ffx_dispatch_aot_check.py llvm-mc-19 llvm-objcopy-19 libLLVM-19.so.1— passed (existing packed-coordinate and i8 network checks, syntheticgfx1013BFE+SCCconsumer sequences withv_cndmask_b32_e64 ..., src_sccands_cselect_b32acrosstranslate()andpredecessor(), stale-SCCset/clear evaluation afters_cmp_*, vector-BFESCCpreservation, and 2,016 bit-level RDNA2 reference checks).python3 -B tests/pixel_aot_check.py binary llvm-mc-19 llvm-objcopy-19 libLLVM-19.so.1— passed.python3 -B tests/script_state_check.py,bcpack_check.py,resource_ranges_check.py,dxcontainer_part_offsets_check.py,layout_chunks_check.py— all passed.Evidence and follow-up
tests/ffx_dispatch_aot_check.pyare assembled from original inlinegfx1013instructions withllvm-mcand checked against an independent bit-array RDNA2BFEreference and generated-shaderSCCevaluation under the repository's MIT license.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T17:16:53Z.
Please cover a scalar BFE followed by an SCC-dependent instruction. The PR computes the extracted value but says SCC is left to compares. Either preserve BFE's SCC semantics or explicitly reject consumers that would read a stale flag, with a fixture for that path.
Imported from R0Y00/Xbox2Windows. Originally posted by KomaGuy on 2026-11-21T17:37:19Z.
Updated in
03c61dcto preserve scalar BFESCCsemantics:s_bfe_u32ands_bfe_i32now emitscc = <dest> != 0u;(v_bfe_*leavessccuntouched),predecessor()declaresscc, ands_cselect_b32is supported alongsidesrc_sccconsumers.gfx1013fixtures intests/ffx_dispatch_aot_check.pycoverings_bfe_u32ands_bfe_i32followed byv_cndmask_b32_e64 ..., src_sccands_cselect_b32, evaluating the generated statements to check clearing a priorscc = 1(zero field andwidth == 0), settingscc = 1after a priorscc = 0(nonzero unsigned and negative signed extracts), and preservingsccacross an interveningv_bfe_u32.