Vertex fetch scanner ignores the S_BFE_U32 width when folding constants #2370

Closed
opened 2026-10-09 16:40:34 +00:00 by fisherjoey · 0 comments
fisherjoey commented 2026-10-09 16:40:34 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-09T16:40:34Z.


EmbeddedVertexFetchAnalyzer folds S_BFE_U32 on two constant SGPRs as src0 >> (src1 & 31) (the SBfeU32 case in Analyze, core/shader/recompiler/Translation/src/EmbeddedVertexFetch.cpp). It ignores the width in S1 bits [22:16]. The instruction uses offset = S1 & 31 and width = (S1 >> 16) & 0x7f. It returns 0 for width 0, and otherwise S0 >> offset masked to width bits, where a width of 32 or more keeps every bit. The translator's sBfeU32 / extractBits32 in IntegerInstructions.cpp already does this, so the scanner and the translator disagree.

Example: S0 = 0x9e000000, S1 = 0x001e0000 (offset 0, width 30). The instruction gives 0x1e000000 and the scanner gives 0x9e000000.

The folded value can end up as an SMEM offset into the buffer table, and then the plan picks the wrong vertex buffer slot for the embedded fetch. With that pair as the s_load_dwordx4 offset, the scanner reports slot 165675008 instead of 31457280.

I found it with an SMT check of the scanner's constant folds against the instruction semantics.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5781509955 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2370). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-09T16:40:34Z. --- `EmbeddedVertexFetchAnalyzer` folds `S_BFE_U32` on two constant SGPRs as `src0 >> (src1 & 31)` (the `SBfeU32` case in `Analyze`, `core/shader/recompiler/Translation/src/EmbeddedVertexFetch.cpp`). It ignores the width in S1 bits [22:16]. The instruction uses `offset = S1 & 31` and `width = (S1 >> 16) & 0x7f`. It returns 0 for width 0, and otherwise `S0 >> offset` masked to `width` bits, where a width of 32 or more keeps every bit. The translator's `sBfeU32` / `extractBits32` in `IntegerInstructions.cpp` already does this, so the scanner and the translator disagree. Example: S0 = 0x9e000000, S1 = 0x001e0000 (offset 0, width 30). The instruction gives 0x1e000000 and the scanner gives 0x9e000000. The folded value can end up as an SMEM offset into the buffer table, and then the plan picks the wrong vertex buffer slot for the embedded fetch. With that pair as the `s_load_dwordx4` offset, the scanner reports slot 165675008 instead of 31457280. I found it with an SMT check of the scanner's constant folds against the instruction semantics. AI-assisted: yes
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#2370
No description provided.