shader: decode and translate V_FRACT_F16 (VOP1 0x5f) and V_CMPX_LT_U16 (VOPC 0xb9) #582
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!582
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/582/head"
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?
@RingMinusOne on GitHub · 2026-09-12 03:59 UTC · original
RingMinusOne:contrib/shader-decode-fixes→main· +260 −0 · 5 files · 1 commits · merged 2026-09-12 13:21 UTCTwo gaps in the shader decoder tables, each of which aborted CFG construction for any shader using the instruction. Found while bringing up a commercial Frostbite title, which uses both heavily.
VOP1
0x5f—V_FRACT_F16VOP1_OPCODE_LISTjumps from0x5e(V_RNDNE_F16) straight to0x60(V_SIN_F16):Decoding
0x7e12bf07as VOP1 givesvdst=v9,opcode=0x5f,src0=0x107(v7) —v_fract_f16 v9, v7.Everything needed already existed:
IR::ValueOpcode::FPFract32lowers to the SPIR-VGlslFractextended instruction, andFloat16Unaryis the established path for this family. This adds the opcode to the enum, to both the VOP1 and VOP3-encoded VOP1 tables, to the float source/result predicates, to the SDWA rule table, and to the translator, mirroringV_RNDNE_F16.invalid_negativeisfalsesince negative inputs are valid for fract.Without the SDWA rule entry,
FindVop1SdwaRulereturnsnullptrand SDWA-encoded forms are still rejected, so that table needs the entry too.VOPC
0xb9—V_CMPX_LT_U16This one reports a misleading reason:
The SDWA word decodes to
src0_sel=DWORD, src1_sel=DWORD, a no-op selector, so the modifier is not the problem.SupportsVopcSdwa()isopcode != Opcode::UNSUPPORTED, so that message fires whenever the opcode failed to decode and the instruction happens to be SDWA-encoded. The real cause is that0xb9is absent fromVOPC_OPCODE_LIST.Identifying it needed care, because the table does not follow any single published AMD map. I reconstructed the numbering from the table's own entries — 8-wide blocks ordered
F, LT, EQ, LE, GT, NE, GE, T— and checked it against every existing entry I could anchor: 23 agreements, 0 mismatches. The twoCLASSops are consistent, occupying the unusable always-false slot. The neighbouring0xbc = V_CMPX_GT_U16fixes the block base at0xb8, mirroringV_CMP_*_U16at0xa8, giving0xb9 = V_CMPX_LT_U16.The translator reuses
EmitInteger16ComparewithULessThan32exactly asV_CMP_LT_U16does, with the exec-writing flag set as forV_CMPX_GT_U16. One table entry covers both encodings, sinceVOPC_OPSbacks the plain and VOP3-encoded lookups.Verification
indices[0x5f]in the VOP1 table goes from0— absent, soLookupOpcodereturnsUNSUPPORTED— to a valid entry index, and likewiseindices[0xb9]in the VOPC table.A formatting note:
VOPC_OPCODE_LISTis laid out two entries per line, and I have put the new0xb9entry on its own line rather than repacking the surrounding rows, to keep the diff to a single added line. Happy to reflow it if you would prefer the table stay uniform.While in the VOP1 table I noticed
0x59(V_FREXP_MANT_F16) and0x5a(V_FREXP_EXP_I16_F16) are also missing. I have left them alone, since unlike fract they need real semantics written rather than a table entry, and I have no test case that exercises them.🤖 Generated with Claude Code
@RingMinusOne on GitHub · 2026-09-12 12:03 UTC · original
Heads up on two commits I pushed here that are not about the opcodes.
CI was failing on Windows with
-Wc++11-narrowingerrors in the SPIR-V backend — files this PR does not touch.mainwas red for the same reason, so it was pre-existing rather than something this branch introduced. I mergedmainin to pick up3a27f8a, which fixedSpirvBuilder.cpp, but clang-cl still rejected the remaining sites, so the second commit covers those.Constant operands like
spv::OpBitcastnarrow implicitly and are fine. The ones that fail are the non-constant cases:EmitNativeforwards its argument pack straight intoAddFunction, soEmitGlslpassing aGLSLstd450opcode as a runtime argument narrows, plus fourspv::Opvalues chosen by a runtime ternary. I usedstatic_cast<uint32_t>to match what you did inSpirvBuilder.cpp.Unary,Binary,EmitCompareU32ConstantandEmitBinaryU32already takeuint32_topcodes, so I left them alone.Happy to pull that build fix out into its own PR if you would rather keep this one to the decoder change — it only landed here because it was blocking the checks. Thanks for adding the test coverage.
@RingMinusOne on GitHub · 2026-09-12 13:12 UTC · original
1208d22supersedes the build commits I mentioned above — giving the builder typed operands that encode enums is clearly the right fix, rather than the per-sitestatic_castworkarounds I had been adding.Every conflict was in a file those commits touched, so I resolved each by taking your version and dropped my casts entirely. The branch is now back to just the decoder change plus your tests:
Sorry for the noise in the middle there — I was chasing the narrowing errors file by file while you were fixing the underlying cause.