fix(shader): read the tenth opcode bit of PS4 VOP3 instructions #25598
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/25598"
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 adam25136 on 2026-11-22T11:03:24Z.
What
A PS4 (GCN) VOP3 instruction's opcode is read from bits 25:17 of its first word, nine bits. PS4 Pro shaders also use VOP3 opcodes from 512 up, whose tenth bit is bit 16: shadPS4 reads it for every VOP3 instruction (
op_msb = bit::extract(hexInstruction, 16, 16); op = op + op_msb * (1 << 9);indecodeInstructionVOP3, decode.cpp L736-737; its opcode list ends the range with "in neo mode, VOP3 gets an additional bit for OP so round up", opcodes.h L700-L719).GcnOpcodeTables.hppalready maps 16 of those opcodes (0x303 to 0x372, for examplev_lshl_add_u320x346 andv_add3_u320x36d) to the RDNA opcodes of the same numbers, but without the bit no instruction reaches them: each decodes as the opcode 512 below, or is refused where that one is unmapped (0x30d, 0x30e).v_add3_u32(877) becomesv_div_scale_f32(365), a VOP3b, and that word's bits 14:8, which hold the ABS, CLAMP and reserved bits of a VOP3a, are taken as its scalar destination.No public AMD document covers this encoding: the Sea Islands ISA has no VOP3 opcodes from 512 up, the bit comes from shadPS4, the opcode numbers are the ones RDNA 2 gives the same instructions (all 16 are at these numbers in AMD's "RDNA 2" Instruction Set Architecture reference guide, section 12.12 VOP3A & VOP3B Instructions, and
RdnaVectorOpDecoder.cppdecodes them), and it is not measured on a PS4 Pro. inFAMOUS's shader supports it two ways. None of the 14 words that read asv_div_scale_f32with nine bits meets that instruction's rule in the Sea Islands ISA, "s0 must equal s1 or s2" (itsV_DIV_SCALE_F32entry), while asv_add3_u32they do address arithmetic on the thread and group IDs (for examplev6 = v1 + s15 - 1at pc 0x11c: thread y plus group y × 8, minus 1). And of the 28 compute shaders the driver saved from inFAMOUS (5,125 VOP3 words), only this shader's 19 words set bit 16, each an opcode the table maps, and no word sets any other reserved bit.encodeVop3reads the opcode from bits 25:17 and bit 16 (avop3Opcodehelper). In the Sea Islands ISA bit 16 is reserved in both VOP3 forms (VOP3a "reserved [16:12]", VOP3b "[16:15] Reserved", AMD Sea Islands Series Instruction Set Architecture, chapter 13, section 13.3), so instructions that leave it clear decode as before.InstControlVOP3in instruction.h L132-L140). The re-encoding to RDNA does not carry those bits, and ten of the sixteen opcodes are 16-bit operations whose halves OP_SEL picks, so a mapped ten-bit opcode with any of them set now throws: dropping them would run the 16-bit ones on the wrong halves. inFAMOUS's shader has 19 ten-bit-opcode words (v_lshl_add_u32once,v_add3_u3214 times,v_and_or_b324 times), none with them set.unsupported VOP3), as an unmapped nine-bit one is; the two opcodes in shadPS4's list that the table leaves out, 784 (v_sub_co_u32) and 833 (v_mad_f16), decoded onmainasv_max_f32andv_mad_f32(their low nine bits, 0x110 and 0x141) and are now refused.GCN VOP3 opcodes from 512 up: read the shadPS4 way, not measured on a PS4 Pro.Tested
Windows 10 Pro 22H2 (19045), NVIDIA GeForce RTX 5080 (driver 621.14), WinLibs GCC 15.2.0 (r7), Release. The selected tests, the validation-layer run and the inFAMOUS starts ran on this change on
main6c70b74203; the decode test, the breaks and the replay on it before a rebase, ondac08f50bc; it is now on7eb79b0c48. None of themaincommits in between changecore/shaderorlibSceAgcDriver, and its changed lines are the same.agc_gcn_decode(newVop3OpcodeTakesBit16): the word inFAMOUS uses,0xd2db0011 0x04104100, decodes asv_add3_u32 v17, v0, s32, v4with no scalar destination; the same word with bit 16 clear still decodes asv_div_scale_f32withs[0:1]as its scalar destination, and with bit 12 set too, which in that word makes the scalar destinations[16:17], it still decodes with that destination, so the OP_SEL refusal leaves nine-bit opcodes alone; each of the 16 ten-bit opcodes the table maps decodes as the RDNA opcode of the same number; a word with bit 16 set overv_rsq_clamp_f32's low bits (0x3ac, unmapped) is refused rather than read asv_rsq_clamp_f32; andv_add_nc_u16(0x303) with any one OP_SEL bit set is refused. It passes, and each of 5 deliberate breaks fails it: bits 25:17 alone (as onmain), bit 16 as the ninth opcode bit (bit 8), bit 15 as the tenth, the OP_SEL refusal removed, and that refusal applied to nine-bit opcodes too.agc_shader_replay --gcnon the request the driver saved for inFAMOUS's compute shader0x2f2fb2100(APS5_DUMP_SHADERS): withmain's decoder, resource analysis fails withGetImageResource dword 0 is not a valid runtime value; chain: CompositeExtractU32x4(Ballot(...)), because the image reads from pc 0x14c on uses[0:7]after thirteen such instructions (pc 0x3c to 0x130) wrotes[0:1]; with this change it passes, and the replay then stops on descriptor memory the request does not hold.tools/select_tests.pyselects for the 3 changed files (ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1), on this branch and onmain6c70b74203:agc_driver_bda_devicefails on both andagc_driver_store_over_untrackedonly onmain; the same 24 tests are skipped on both.VK_LAYER_KHRONOS_validation1.4.367 (VK_ADD_LAYER_PATH=<the layer's folder> VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer VK_LOADER_LAYERS_DISABLE=~implicit~ ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1), the tests matchinggcn|Gcn|shader_memory|decode,ctest -V: 48 on the branch and onmain, all pass; each log has 16Insert instance layerlines, nowas not foundand no VUID.libc.prxandlibSceFios2.prxunwrapped with our local PS4 variant oftools/unwrap_self.py, converted with each build's relinker (--windows --registry --trace-imports), two starts of up to 60 s per build, no input. Both builds aremain6c70b74203with #18184, #21961 and #25557 merged locally and one local relinker change in no PR (a title that needslibSceGnmDriver.prxalso loadslibSceGnmDriverForNeoMode.prx, standing in for #17711, which conflicts withmain); without those the title stops earlier.0x2f2fb2100withShaderRecompiler::Recompile: GetImageResource dword 0 is not a valid runtime value;PS4 multisampled textures outside the depth tile modes are not implemented, which is outside this PR.python tools/check_conventions.py --base origin/mainwith this title and description: all checks passed.python tools/pr_overlap.py --branch fix/gcn-vop3-opcode-msb(2,381 open pull requests probed): no overlap. The one that shares files, my #23237 (refusing GCN DPP words), changes other lines of the same two files and merges with this branch without conflicts. That PR refuses DPP because no title is known to use it, its layout is not measured on a PS4 Pro and some of its controls have no RDNA counterpart; this one reads bit 16, though it is not measured on a PS4 Pro either, because a title uses it, and 14 of its shader's words only make sense with the bit.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)AI-assisted: Claude Code found the cause, wrote the change and its test, ran the tests and the inFAMOUS starts, and drafted this description; separate review agents checked it.
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T11:14:12Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the evidence supports merging, with the console validation noted below.
What I ran
Reviewed head
5db5a44acde47c648549d590ecd433bc1febe94a. I read the description, commits, diff, manifest, and all three changed files usingrepo_read.py. No tests or builds were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not independently run the reported tests, inspect the excluded-file listing (
files.jsonwas unavailable through the reader), or verify behavior on a PS4 Pro console. The author explicitly notes the opcode interpretation has not been measured on console.To get this to a good state
Nothing is required.