graphics: honour the data format of LOAD_*_REG_INDEX register lists #2245
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!2245
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2245"
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?
@Nawid3333 on GitHub · 2026-11-12 23:33 UTC · original
Nawid3333:fix/load-reg-index-data-format→main· +99 −18 · 4 files · 1 commits · openRefs #2233
Cause
Opcodes 0x63, 0x64 and 0x9F (
IT_SET_SH_REG_INDIRECT,IT_SET_UCONFIG_REG_INDIRECT,IT_SET_CONTEXT_REG_INDIRECT) are AMD's LOAD_SH_REG_INDEX, LOAD_UCONFIG_REG_INDEX and LOAD_CONTEXT_REG_INDEX (PALgfx9_plus_merged_pm4_it_opcodes.h). Their third body dword holdsreg_offsetin bits 0-15 anddata_formatin bit 31:data_format = 1(offset_and_data): the list holds (offset, value) pairs.data_format = 0(offset_and_size): the list holdscountvalues for consecutive registers, starting atreg_offset.PAL's
BuildLoadShRegsIndex/BuildLoadContextRegsIndex(gfx9CmdUtil.cpp) build both forms, and shadPS4'spm4_cmds.h(LoadDataFormat) decodes both.CpOpIndirectCxRegs,CpOpIndirectShRegs,CpOpIndirectUcRegsand the packet dump inDumpPm4PacketStreamignored that dword and always read pairs. A list in the consecutive form therefore had its values used as register offsets, and the loop read twice as many dwords as the list holds. Kyty's own Agc builder always writes0x80000000(pairs), so only packets built by the game itself take the other form.This was found from #2233 (Jak and Daxter: The Precursor Legacy, PPSA20928, which runs in Sony's PS2 Classics emulator), whose log stops at
unknown sh reg at 0020d: 0x1a0inCpOpIndirectShRegs. That stop is not caused by the list format: with this change the game stops at the same packet (log). SH offsets 0x1a0-0x1ab are not shader registers on gfx10.1/gfx10.3 (the Linuxgc_10_1_0_offset.handgc_10_3_0_offset.hheaders have no SH register from offset 0x15c up toCOMPUTE_DISPATCH_INITIATORat 0x200), so that list holds something else when Kyty reads it. That stop is followed up in #2233.Change
pm4.hgets a small reader,Pm4::LoadedRegisters { data, control }:RawOffset(i)returnsdata[2 * i]for pairs, or(control & 0xffff) + ifor consecutive registers.Value(i)returnsdata[2 * i + 1]for pairs, ordata[i]for consecutive registers.The three handlers and the dump build it from the packet's third body dword and read through it. For packets with bit 31 set, which includes every packet Kyty builds, the offsets and values are exactly the ones read before. The NOP/sentinel skips, the CX special cases and the unknown-register exits are unchanged.
Out of scope:
index, an offset instead of an address). Kyty masks it off as before.{0x24a, 0}. They may come from the same misparse, but this PR does not touch them without evidence.Tests
shader_recompiler_compute_testsgainsCheckPm4ConsecutiveIndirectRegisters(selector--context-state-only). It sends one consecutive-form packet per handler, withdata_format = 0andreg_offsetset to the first register:DB_DEPTH_CONTROL= 0x4070078d andDB_EQAA= 0x32. It checks the decoded depth-control fields andmax_anchor_samples == 2,ps_iter_samples == 3.GE_INDX_OFFSET= 0x1234 andGE_MULTI_PRIM_IB_RESET_EN= 1. It checksGetIndexOffset() == 0x1234andGetPrimitiveResetControl() == 1.SPI_SHADER_PGM_LO_PS..SPI_SHADER_PGM_RSRC2_PS= 0x05000104, 0x12, 0x022c018d, 0x3c. It checksdata_addr == 0x120500010400, which needs both LO and HI, plusvgprs == 13anduser_sgpr == 30.The value arrays are padded so that a reader that still takes pairs stays inside them. The pairs form stays covered by the existing
CheckPm4IndirectShaderRegisters,CheckPm4IndirectUconfigRegistersandCheckPm4DepthControlHighBits, which send0x80000000.Run on an RX 9070 XT with
--context-state-only. Upstream's harness needs #2038 on AMD, so #2038 was applied locally for both runs and not committed.58ca8d1d7with the new test only:ShaderRecompilerComputeTests: Pm4ConsecutiveIndirectRegisters failed at context registers: LOAD_CONTEXT_REG_INDEX values were not written from the first register onok, including the three pair-form ones above.Both binaries were built fresh. The fix run used f3db7c8ee; the head
8d2e4376bonly re-wraps one line ofpm4.hfor clang-format.CI on this head: https://github.com/Nawid3333/KytyPS5/actions/runs/43327885017 (Windows and Linux builds pass).
Costs
The pair form costs one bit test of the format per offset and per value read. The consecutive form reads half as many dwords as before. Nothing is allocated.
In a game
Not shown in a game: #2233 stops at the same packet with this change (see above), so it does not fix that game. The evidence is the packet format itself (PAL builds both forms, shadPS4 decodes both) and the new test, which fails on main and passes on this branch. No game is known yet that sends the consecutive form; I will name it here when a log shows one.
Written with Claude Code (AI): Claude Code found the format handling while reading the reporter's log, wrote the change and the test, and ran them. Claude Opus and GLM reviewed the change (no must-fix); the test was extended to two registers per context/user-config case and a nonzero
PGM_HI_PSafter Opus' review.🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-11-12 23:37 UTC · original · edited 2026-11-13 15:56 UTC
No actionable comments were generated in the recent review.
Walkthrough
The change adds
Pm4::LoadedRegistersto read indirect register offsets and values in interleaved or sequential formats. Indirect register handlers and the register dump use this helper. A new test checks indirect writes to depth-context, user-configuration, and pixel-shader registers.Suggested reviewers:
nmzik,claxten10,superkekaChange: Bug fix
Merge Risk:
Minimal · up to
8d2e4The change makes the indirect register-load packets honor their consecutive-value format while leaving pair-form packets unchanged. No merge-blocking risk is evident; in-game confirmation from the reporter is still pending.
Pre-merge checks:
4
Full details: Title check
Explanation
The title names the main change: the three LOAD_*_REG_INDEX handlers and the packet dump now honour the data_format bit of the register list instead of always reading offset/value pairs. The changeset adds Pm4::LoadedRegisters in pm4.h, uses it in pm4.cpp and pm4Handlers.cpp, and adds a consecutive-form test, so the title matches the change.
Full details: Description check
Explanation
The description is specific and technical. It names the affected opcodes (0x63, 0x64, 0x9F) and the handlers (CpOpIndirectCxRegs, CpOpIndirectShRegs, CpOpIndirectUcRegs, DumpPm4PacketStream). It explains the data_format bit and the new Pm4::LoadedRegisters reader, which matches the raw summary. It also describes the new CheckPm4ConsecutiveIndirectRegisters test and the test results. It is related to the changeset, so the check passes.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
00129f88-c7e0-4180-b7d9-27a0bbe64d42Reviewing files that changed from the base of the PR and between
58ca8d1d7fand8d2e4376b0.src/graphics/guest_gpu/command_processor/pm4Handlers.cppsrc/graphics/guest_gpu/pm4.cppsrc/graphics/guest_gpu/pm4.htests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.