Skip to content

fix(recompiler): apply the S_BFE_U32 width when the vertex fetch scanner folds constants - #2371

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
fisherjoey:fix/scanner-s-bfe-u32
Oct 10, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
fisherjoey:fix/scanner-s-bfe-u32

Conversation

@fisherjoey

Copy link
Copy Markdown
Contributor

Closes #2370

What

The embedded vertex fetch scanner folded S_BFE_U32 on constant SGPRs as a plain right shift and ignored the width field. It now calls scalarBfeU32, which matches the translator's sBfeU32: offset S1 & 31, width (S1 >> 16) & 0x7f clamped to 32, and 0 when the width is 0.

The other ops that reach that switch are S_AND_B32, S_LSHL_B32, S_ADD_I32 and S_ADD_U32 (isAttributePropagationAlu). The two adds land in the default case, which adds, so those are correct.

Tested

New test agc_embedded_vertex_fetch. It decodes a vertex program that builds an SMEM offset with s_mov_b32 and s_bfe_u32, loads a buffer descriptor from the buffer table at that offset, and fetches with buffer_load_format_xyzw on the vertex index. It checks the buffer slot the plan records.

case expected slot main d70b899 this branch
S0 0x9e000000, S1 0x001e0000 (width 30) 31457280 165675008 31457280
S0 0xfff00320, S1 0x00080004 (width 8, offset 4) 3 16773123 3
S0 0x00000320, S1 0 (width 0) 0 50 0
S0 0x00000320, S1 0x007f0000 (width above 32) 50 50 50
  • ctest -R agc_ -j1 on Linux (Nobara 44, GCC 16): 257 of 258 on an RTX 5070 Ti (NVIDIA 595.91.07) and 258 of 258 on RADV (Ryzen 5 7600X iGPU, Mesa 26.2.1). The NVIDIA failure, agc_driver_dcc_keys_first_write, fails the same way on main d70b899.
  • tools/check_conventions.py: passes.
  • Windows: not tested.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw
  • No notes, investigation .md files or images added to the repository
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

@github-actions github-actions Bot added build shader core/shader agc libSceAgc* labels Oct 9, 2026
@Kikoarl

Kikoarl commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Linux run: Linux 7.2 (x86_64), GCC 16.2.1, Release, -DBUILD_TESTING=ON, #2371 (f00c2f2d) tested on current main (0fdda7be).

  • tests/agc_embedded_vertex_fetch_tests: passes cleanly.
  • tools/check_conventions.py: passes cleanly.
  • Confirms proper bitfield extract width application during vertex fetch constant folding.

@popcoder565

Copy link
Copy Markdown
Contributor

Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), RTX 3060 Laptop (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head f00c2f2d, merged onto main 8b393b6 in one build with 31 other PRs that had no Windows run.

No title was run.

🤖 Addressed by Claude Code

@fma-rc

fma-rc commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Hardware measurement of s_bfe_u32, and a run of the PR. Radeon 610M (gfx1036), tools/hw-oracle at main 0c0dc1e, Linux 7.2.9, hsa-rocr 7.2.4, clang 23.1.1; ieee 0, dx10_clamp 1, denorm32 0, denorm16 3, round32 0, round16 0, fp16_overflow 0.

405 rows: sources 0x9e000000, 0xfff00320, 0x00000320, 0xffffffff, 0x80000001 × offsets 0, 4, 31 × widths 0, 1, 8, 30, 31, 32, 33, 64, 127, each with the remaining S1 bits clear, with bit 23 set, and with 0xff00ffe0 set. Every row equals this PR's scalarBfeU32 (compiled unchanged); main's src0 >> (src1 & 31) differs on 123 of them. SCC is result != 0 in every row.

PR head f00c2f2 merged onto main 0c0dc1e, Linux, GCC 16.2.1, Release: agc_embedded_vertex_fetch passes. With EmbeddedVertexFetch.cpp reverted to main it fails with slots 165675008, 16773123 and 50, as in the PR's table.

Not measured: gfx1013.

AI-assisted: yes.

@fisherjoey

Copy link
Copy Markdown
Contributor Author

@fma-rc thanks for the hardware rows. The widths 33, 64 and 127 also settle the one thing I hadn't checked on hardware: a width of 32 or more keeps every bit above the offset, rather than wrapping modulo 32. That matches the translator's extractBits32, which this PR copies.

AI-assisted: yes

@adriadam10

Copy link
Copy Markdown
Collaborator

Checked on a merged tree: agc_embedded_vertex_fetch passes and fails with the fix reverted; HW oracle (gfx1035, 405 rows over sources × offsets × widths 0..127 × high S1 bits) matches scalarBfeU32 on every row, main differs on 123. Consistent with the runs by @Kikoarl, @popcoder565 and @fma-rc. Merging.

@adriadam10
adriadam10 merged commit 5bcbbeb into boykopovar:main Oct 10, 2026
8 checks passed
SleglJan pushed a commit to SleglJan/AnyPS5 that referenced this pull request Oct 10, 2026
fix(recompiler): apply the S_BFE_U32 width when the vertex fetch scanner folds constants
@fisherjoey
fisherjoey deleted the fix/scanner-s-bfe-u32 branch November 11, 2026 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Vertex fetch scanner ignores the S_BFE_U32 width when folding constants

5 participants