fix(shader): truncate overflowing 32-bit bitfield masks #1605
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1605"
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 boykopovar/AnyPS5. Originally posted by QRMOE on 2026-10-08T14:11:52Z.
What
Fixes
S_BFM_B32andV_BFM_B32lowering when the masked width and offset add to more than 32. Construct the low-bit mask at offset zero and shift in 32-bit arithmetic so overflow bits are discarded. Width/offset masking, vector EXEC masking and scalar SCC preservation remain intact. For width 2 and offset 31, the expected result is0x80000000.Semantics: AMD RDNA 1.0 ISA, section 12.1 opcode 36 and section 12.12 opcode 867; SPIR-V OpBitFieldInsert.
The GPU regression uses zero-stride byte buffers with
OOB_SELECT=3, the raw bounds mode in RDNA ISA section 8.1, Table 35. The earlier fixture selected structured bounds with stride zero and dropped stores when run against current main. The descriptor is corrected; all result and SCC assertions remain, with actual/expected values added to failure messages. The technical-debt entry is placed with related shader entries to avoid shared insertion conflicts.Tested
Windows 11, WinLibs MinGW-w64 GCC 15.2.0 UCRT/POSIX/SEH, Ninja Release,
BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=ON; updated to maind70b89989473ba1f6ae13e44e079e67f1f8a44b0.The complete default project build succeeded on the combined validation tree containing these two independent PRs. Seven focused tests passed:
guest_hostname,guest_errors,guest_standard_streams,bitfield_mask,agc_driver_bitfield_mask,agc_driver_scalar_sop2, andagc_driver_vop3_integer_alu. The four shader tests also passed withAPS5_SPIRV_OPT=fullandnone.ANYPS5_REQUIRE_VULKAN=1required actual GPU execution on the AMD Radeon RX 9070 XT. Conventions, whitespace and test registration checks passed. The complete CTest suite was not run.bitfield_maskchecks 32,768 translation/constant-folding cases.agc_driver_bitfield_maskexecutes 4,096 scalar/vector input pairs, checks SCC=0 and SCC=1 preservation and passes in all three optimization modes. Shader lowering is unchanged from the previously reviewed head. The updated GPU fixture has not been rerun on Linux. The earlier independent Linux/NVIDIA/RADV report applies to the previous head.Expected results come from the ISA; native RDNA hardware-oracle measurements and game compatibility remain unverified and recorded in
docs/dev/TechnicalDebt.md. Decoder coverage is unchanged.Checklist
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-09T01:22:25Z.
Linux results on NVIDIA and RADV, since this was tested on Windows with an RX 9070 XT. Everything passes here, including the new
bitfield_maskandagc_driver_bitfield_mask.Nobara 44 (Linux 7.2), GCC 16.2.1, Release,
BUILD_TESTING=ON. This PR merged ontomain29e533ac.main29e533acmain+ this PRctest -R agc_driver -j1-E agc_driver)The one CPU failure is
guest_dynamic_loader(subprocess aborted), which fails the same way onmain.Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-10T01:27:02Z.
Hardware measurement for the TechnicalDebt entry this PR adds, and a run of the PR.
Radeon 610M (gfx1036),
tools/hw-oracleatmain0c0dc1e9, Linux 7.2.9, hsa-rocr 7.2.4, clang 23.1.1. Controls: ieee 0, dx10_clamp 1, denorm32 0, denorm16 3, round32 0, round16 0, fp16_overflow 0.Inputs are the test's own domain: widths 0–31 × offsets 0–31 × upper bits 0, 32, 0x80000000, 0xffffffe0 (4,096 pairs).
v_bfm_b32, wave32 and wave64: 8,192 rows, all equal toexpectedMaskfromtests/execution/BitfieldMask.cpp(compiled unchanged).s_bfm_b32, wave32, SCC preset to 0 and to 1: 8,192 rows, all equal toexpectedMask; SCC unchanged in every row.PR head ca16eaa4 merged onto
main0c0dc1e9, Release, GCC 16.2.1:bitfield_mask,agc_driver_bitfield_mask,agc_driver_scalar_sop2andagc_driver_vop3_integer_alupass on an RTX 5080 (615.71.09) and on RADV (Mesa 26.1.4, same Radeon 610M). WithIntegerInstructions.cppreverted tomain,agc_driver_bitfield_maskstill passes on both devices andbitfield_maskfails (s_bfm_b32 width=2 offset=31 did not fold to the expected mask).Not measured: gfx1013;
s_bfm_b32in wave64.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T05:58:03Z.
Checked
s_bfm_b32/v_bfm_b32on RDNA2 hardware (gfx1035): all 1024 width/offset pairs with upper operand bits 0, 32, 0x80000000 and 0xffffffe0, plus width/offset ≥ 32. 4103 rows, 0 mismatches against the new lowering. SCC is unchanged ons_bfm_b32, and width 2/offset 31 gives0x80000000. Build and ctest are green.bitfield_maskfails without the fix.Added on your branch:
agc_driver_bitfield_masknow skips when the subgroup size is below 32, asWriteLane.cppdoes. Its scalar half usesv_writelane, and it failed on CI's lavapipe (8-lane subgroups) withbitfield mask width=1 offset=8 scalar result 1, expected 256.Merging once CI is green.