fix(agc): CLEAR_STATE leaves SPI_PS_IN_CONTROL at NUM_INTERP 2 #9595
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9595"
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 NaitikJoshiPro on 2026-10-22T03:53:20Z.
What
After a
CLEAR_STATEpacket (or a push-clearCONTEXT_STATE, operation 3), the driver resets the context toInitialContextRegisters(), whereSPI_PS_IN_CONTROL(0x1b6) is 0. The GFX10 clear state has it at 0x2 (NUM_INTERP 2): seeclearstate_gfx10.h,gfx10_SECT_CONTEXT_def_2, theSPI_PS_IN_CONTROLentry.radeonsi relies on that value. After it emits
CLEAR_STATE,si_set_tracked_regs_to_clear_staterecordsSI_TRACKED_SPI_PS_IN_CONTROL = 0x2(mesa si_gfx_cs.c), so for a pixel shader with two interpolants it skips the register write. The driver then reads NUM_INTERP 0 and recompiles the pixel shader with no inputs, and shader info collection throwsinterpolation parameter reference is out of range ... 0 inputs.How it was found. SuperTuxKart (
STKT00001, homebrew from project-oops/oops-apps, which renders through radeonsi) on the native Metal port of this driver at NaitikJoshiPro/AnyPS5-mac. Its first draw after aCLEAR_STATEuses a pixel shader with two interpolants and stopped about 80 s in with the error above. This is not a regression: the context reset has used the starting table sinceCLEAR_STATEwas first handled.Fix.
ClearStateContextRegisters()is the starting table with NUM_INTERP 2.QueueState::ClearContext(), which both packets use, resets to it. The starting context andInitialContextRegisters()keep 0. Registration-time decoding (ShaderRegistry.cpp) starts from that table and prepares a pixel program only while NUM_INTERP is 0. Raising the starting value would stop pixel programs from being prepared at registration (agc_driver_prepared_graphicsandagc_driver_prepared_shaders_abi_deferred_undecodable_statefail that way). A title that writesSPI_PS_IN_CONTROLbefore its draws sees no change. Only a draw that relies on the value a clear leaves now sees NUM_INTERP 2, which is what it would see on GFX10 hardware.Concrete case.
agc_driver_pm4(testContextAndBases) executes aCLEAR_STATEpacket and a push-clear and requires NUM_INTERP 2 after both. It also requires the starting context to keep 0.agc_driver(testClearState) comparesClearContext()againstClearStateContextRegisters()and checks NUM_INTERP 2.mainthe new checks fail withCLEAR_STATE did not leave SPI_PS_IN_CONTROL at its clear-state NUM_INTERP of 2.radeonsi assumes other golden values that the table does not match either, such as
CB_TARGET_MASK/CB_SHADER_MASK0xffffffff,PA_SU_SC_MODE_CNTL0x4 andPA_SU_VTX_CNTL0x5. None of them has stopped a title yet. Each one changes what Sony titles see after a clear, so this PR leaves them out.Tested
main(6ef5a1c4c9) withANYPS5_REQUIRE_VULKAN=1. 41 of 41 tests pass with no skips:agc_driver,agc_driver_pm4and its failure, ring, stall-watchdog, rewind and priority variants,agc_driver_graphics,agc_driver_register_key, and everyagc_driver_prepared_graphics*,agc_driver_prepared_shaders*andagc_driver_prepared_exportstest. Negative control: https://github.com/NaitikJoshiPro/AnyPS5/actions/runs/39717302213 restoresmain'sQueueState.hppunder the new tests.agc_driverandagc_driver_pm4then fail withCLEAR_STATE did not leave SPI_PS_IN_CONTROL at its clear-state NUM_INTERP of 2. Its main step lists two PM4 replay tests as not run, because the workflow did not build their target. The later run leaves them out. The workflow is fork-only and is not part of this PR.main. Onmainit stops before this draw, on the PM4 and register states that the driver still refuses.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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:09:09Z.
Review: CHANGES_REQUESTED
The CLEAR_STATE change and focused test look targeted, but the PR does not yet satisfy the repository’s required validation for AGC changes. Please update from current main, then run the same focused tests on main and this head on the same machine and GPU with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1; attach both ctest -V logs, confirm the validation layer loaded, compare VUIDs, and name the GPU/driver/OS on the checklist. The reported baseline is
6ef5a1c4while main has advanced. Also please correct the checklist’s Unblocks line: the repository requires a title ID and Game bring-up discussion when this fixes a title stop/wrong result, otherwise write none. I could not locate a SuperTuxKart/STKT00001 bring-up discussion in the repository discussion search; please link the applicable discussion or clarify that this is not a title unblock.Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-22T08:37:59Z.
Reviewed; the register-value change itself is well-sourced and complete.
CLEAR_STATE's value forSPI_PS_IN_CONTROLis 0x2 in the Linux clear-state table for GFX10 (gfx10_SECT_CONTEXT_def_2,0x00000002, withSPI_PS_INPUT_ENA/SPI_PS_INPUT_ADDRat 0), which this repo already maps at context offset0x1b6, and the driver's own field extraction reads NUM_INTERP as the low 6 bits — so the write of 2 for a title that clears and then relies on NUM_INTERP≥1 matches the source rather than inventing a value. The switch covers both context-clearing paths (CLEAR_STATEop 0x12 and the push-clear op), registration-time decoding still usesInitialContextRegisters()soagc_driver_prepared_*hashes only gain a new post-clear key (no stale-cache hazard), and the two assertion sites (tests/Pm4.cppfor both clear leaves,tests/Submit.cppfor the bare clear) were both updated — the parallel-table trap this file has caught contributors in before.What's missing is the records, not the code:
No debt entry accompanies the change. The "Host state" section of
docs/dev/debt/libSceAgcDriver.mdalready documents the neighboring decisions with exactly this shape (:14 — "new queues and CLEAR_STATE seed … inferred; GPU power-on reset state is not measured" — and the stencil entry at :67, which cites the SDK tables and says the console reset values weren't measured). This PR now splits clear-state sourcing per register —0x1b6follows the Linux SECT table (a gfx10 table; the PS5 GPU is GFXN_CLASS gfx10.3, where the table differs slightly) while stencil reference masks follow the SDK tables — and neither the NUM_INTERP=2 value (console-unmeasured) nor the per-register sourcing split is recorded. Same pattern as the other recent AGC entries: add one bullet stating the value's source (Linuxclearstate_gfx10.h, gfx10_SECT_CONTEXT_def_2) and that the console's clear-time value is not measured.One unaddressed edge, worth either a sentence in the debt entry or a body note (not a code change): the third context-reset path — a CP queue reset (op 0x09) — still seeds
contextfromInitialContextRegisters(), i.e.0x1b6= 0 there, and the existingtestContextAndBasescase now enshrines that difference. On GFX10 aCLEAR_STATErestores context registers from the golden tables while a queue reset does not rewrite context registers, so leaving op-0x09 alone is defensible — but the PR asserts neither way, and a title that resets by re-queueing and then relies on the clear value would hit the same bug 9595 fixes. One sentence on which behavior the source implies would settle it either way.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T10:00:22Z.
I rechecked exact head
7a6ae55c. The change is confined to the dedicated clear-state register table; the initial registration table remains unchanged. Exact-head conventions andgit diff --checkpass. Hosted eligibility, conventions, intake, labels and report pass; product and relinker jobs are skipped. The author reports 41/41 lavapipe checks on an older base plus a native Metal-port SuperTuxKart run; I did not rerun the GPU tests locally.Two additional review points from the code/source review:
docs/dev/debt/libSceAgcDriver.md, citing theclearstate_gfx10.hsource and stating that the PS5 console value is not measured. The implementation is source-backed but the exact console clear-time value remains an inference.InitialContextRegisters()withSPI_PS_IN_CONTROL == 0, while CLEAR_STATE and push-clear now set it to 2. The source distinction may justify this, but the report/tests currently do not establish the queue-reset behavior.The existing request to rebase onto current main and provide paired same-machine/GPU validation-layer tests with no shader cache still applies: the current head is 100 commits behind, and CI skips product tests. The checklist’s
Unblocks: none on its ownis reasonable if the required follow-up PM4 work is still needed; keep it that way unless a Game bring-up discussion identifies this PR as unblocking a specific title stop.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T13:23:42Z.
Review: DISMISSED
The clear-state correction remains source-backed and the PM4 regression is well targeted. I rechecked exact head
7a6ae55ca2bb97f03cda21e7d0f6f04167df996dagainst current main3ca07d086d5f44fbe3c00370e7f03953ab46ca1b: whitespace and conventions pass, the current-main merge tree is clean, andPm4.cpppasses local GCC 12.2 C++20 syntax-only compilation. I could not syntax-checkSubmit.cppbecause this checkout lacksspirv/unified1/spirv.hpp; I did not run GPU tests locally. The author-reported 41-test lavapipe run and Metal-port title run use older bases, and hosted product tests are skipped.Please address the two documentation/behavior-scope points from the prior review: record that
SPI_PS_IN_CONTROL == 2comes from Linuxclearstate_gfx10.hand that the PS5 console clear-time value is unmeasured; explain why CP queue reset (PM4 op 0x09) still usesInitialContextRegisters()with this field at zero whileCLEAR_STATEand push-clear set it to 2. Then rebase fromd9c99c9ba4dbcbb0a724bad5064e7cb9b1e5f9efonto current main and rerun the same focused AGC tests on main and the change with the Khronos validation layer and no shader cache, attaching bothctest -Vlogs and reporting layer load/VUID comparison. TheUnblocks: noneline is appropriate because the title needs additional PM4 support. This request is for source/debt clarity and required validation only, not intake.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T03:41:50Z.
Review: CHANGES_REQUESTED
@MarcZX10 each point of your two change requests is now covered on the current head:
docs/dev/debt/libSceAgcDriver.mdhas the entry you asked for: the value comes from Linux'sclearstate_gfx10.h, the console value is unmeasured, and the CP queue reset (PM4 op 0x09) and the starting context keep 0 because registration-time decoding prepares a pixel program only while NUM_INTERP is 0.main.mainvs changectest -Vruns with the validation layer, no shader cache andANYPS5_REQUIRE_VULKAN=1are in the thread: @Lindamea1 (RTX 5090, Linux), @savvaniss (RX 9070 XT, Windows) and @ycbuzi (RTX 4070 SUPER, Windows). The layer loaded in each run and no newVUID-appeared.Unblocks: nonestays, as you agreed.Nothing is left for the author. Could you re-review the new head so your request can be cleared?