fix(agc): start the context at its reset state for color targets and viewports #10420

Closed
stuart-russell wants to merge 5 commits from upstream-pr/10420 into main
stuart-russell commented 2026-10-23 23:40:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by stuart-russell on 2026-10-23T23:40:32Z.


What

Start the AGC context at the values the hardware resets it to, so a title that never programs part of the state gets the state the console would.

  • CB_TARGET_MASK (0x8e) and CB_SHADER_MASK (0x8f) start at 0xffffffff, the gfx10 clear-state reset values; a CLEAR_STATE packet still applies the zeros the AGC default tables hold.
  • PA_CL_VTE_CNTL (0x206) starts at 0, the reset value, where every viewport transform is disabled; a draw with that value gets a viewport covering its render target. 0x43f keeps the register-derived viewport, and any other value still throws. The interface check also accepts 0 in drawCovers and the draw rejection.
  • A SPI_SHADER_COL_FORMAT (0x1c5) entry of 0 (SPI_SHADER_ZERO) leaves its export without a color attachment instead of throwing.
  • A SPI_SHADER_POS_FORMAT (0x1c3) entry of 0 discards the primitive (no position export), which is recorded in the pipeline key and the journal, with the journal FileFormat bumped.
  • A 0xffffffff register offset in a SET_*_REG packet or an indirect register list writes no register; the rest of the packet or list proceeds.
  • VGT_SHADER_STAGES_EN with every stage enable clear draws on the vertex path instead of throwing.
  • DecodePixelStageInfo takes the input count from the shader header and throws on per-primitive inputs.
  • DB_RENDER_CONTROL: the copy, resummarize and decompress bits change no modeled state when no depth or stencil plane is bound, and reserved bits 14 to 31 are ignored.
  • The pipeline cache is not written after a device loss, where its contents are undefined.
  • A device fault from the debug thread retries its query instead of ending the thread.
  • APS5_TRACE_QUEUE reports queue order, the present result, a dispatch's shape and the presented display buffer; a recorder batch that outlives its fence reports its serial, fence status and the timeline value.

References

  • The Linux radeon driver starts cb_target_mask and cb_shader_mask at 0xFFFFFFFF when it initialises its register tracking (drivers/gpu/drm/radeon/r600_cs.c, r600_cs_track_init), which is the hardware reset value for the masks.
  • PA_CL_VTE_CNTL gates the viewport transform per axis; decaf-emu models the disabled case as the unscaled NDC path (src/libgpu/src/vulkan/vulkan_viewscissor.cpp), and xenia reads the same enables to derive its draw extent (src/xenia/gpu/draw_extent_estimator.cc).
  • 0x43f is the value that enables X, Y and Z scale and offset and leaves the XY format bit clear, which is the register-derived viewport this driver already builds.
  • The context register space ends below 0x4000, so a 0xffffffff offset names no register; the title's trace contains such packets (recorded before the change, they threw).
  • Measurement: with the previous defaults the title's first draws decoded a viewport of (-1,-1) 2x2 and no color target, and every draw was discarded; with these values the same trace decodes its color targets and a full-target viewport.

Tested

agc_driver_pm4 and agc_driver_graphics (18 tests) pass, and tools/check_conventions.py --base origin/main passes, on the rebased tree.

A Windows build of these changes (MinGW cross-build, NVIDIA RTX 3070, driver 32.0.15.9186, Windows 11) ran PPSA30528, which previously produced a black window, to its loading screen with audio. That run was made before the rebase onto the current main; the merged tree has not been re-run against a title yet.

VK_LAYER_KHRONOS_validation is not installed on the Linux test machine (/usr/share/vulkan/explicit_layer.d is absent), so the ANYPS5_REQUIRE_VULKAN=1 comparison on main and on this branch has not been run yet.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: PPSA30528 (renders its loading screen; text decoding and a compute sync problem remain, tracked separately)
  • GPUs tested: AGC tests on Linux without a Vulkan device; the title run was on an NVIDIA RTX 3070 (driver 32.0.15.9186) on Windows 11
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4990615495 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10420). Originally posted by [stuart-russell](https://github.com/stuart-russell) on 2026-10-23T23:40:32Z. --- ### What Start the AGC context at the values the hardware resets it to, so a title that never programs part of the state gets the state the console would. - `CB_TARGET_MASK` (0x8e) and `CB_SHADER_MASK` (0x8f) start at `0xffffffff`, the gfx10 clear-state reset values; a `CLEAR_STATE` packet still applies the zeros the AGC default tables hold. - `PA_CL_VTE_CNTL` (0x206) starts at 0, the reset value, where every viewport transform is disabled; a draw with that value gets a viewport covering its render target. `0x43f` keeps the register-derived viewport, and any other value still throws. The interface check also accepts 0 in `drawCovers` and the draw rejection. - A `SPI_SHADER_COL_FORMAT` (0x1c5) entry of 0 (`SPI_SHADER_ZERO`) leaves its export without a color attachment instead of throwing. - A `SPI_SHADER_POS_FORMAT` (0x1c3) entry of 0 discards the primitive (no position export), which is recorded in the pipeline key and the journal, with the journal `FileFormat` bumped. - A `0xffffffff` register offset in a `SET_*_REG` packet or an indirect register list writes no register; the rest of the packet or list proceeds. - `VGT_SHADER_STAGES_EN` with every stage enable clear draws on the vertex path instead of throwing. - `DecodePixelStageInfo` takes the input count from the shader header and throws on per-primitive inputs. - `DB_RENDER_CONTROL`: the copy, resummarize and decompress bits change no modeled state when no depth or stencil plane is bound, and reserved bits 14 to 31 are ignored. - The pipeline cache is not written after a device loss, where its contents are undefined. - A device fault from the debug thread retries its query instead of ending the thread. - `APS5_TRACE_QUEUE` reports queue order, the present result, a dispatch's shape and the presented display buffer; a recorder batch that outlives its fence reports its serial, fence status and the timeline value. ### References - The Linux radeon driver starts `cb_target_mask` and `cb_shader_mask` at `0xFFFFFFFF` when it initialises its register tracking (`drivers/gpu/drm/radeon/r600_cs.c`, `r600_cs_track_init`), which is the hardware reset value for the masks. - `PA_CL_VTE_CNTL` gates the viewport transform per axis; decaf-emu models the disabled case as the unscaled NDC path (`src/libgpu/src/vulkan/vulkan_viewscissor.cpp`), and xenia reads the same enables to derive its draw extent (`src/xenia/gpu/draw_extent_estimator.cc`). - `0x43f` is the value that enables X, Y and Z scale and offset and leaves the XY format bit clear, which is the register-derived viewport this driver already builds. - The context register space ends below `0x4000`, so a `0xffffffff` offset names no register; the title's trace contains such packets (recorded before the change, they threw). - Measurement: with the previous defaults the title's first draws decoded a viewport of (-1,-1) 2x2 and no color target, and every draw was discarded; with these values the same trace decodes its color targets and a full-target viewport. ### Tested `agc_driver_pm4` and `agc_driver_graphics` (18 tests) pass, and `tools/check_conventions.py --base origin/main` passes, on the rebased tree. A Windows build of these changes (MinGW cross-build, NVIDIA RTX 3070, driver 32.0.15.9186, Windows 11) ran PPSA30528, which previously produced a black window, to its loading screen with audio. That run was made before the rebase onto the current `main`; the merged tree has not been re-run against a title yet. `VK_LAYER_KHRONOS_validation` is not installed on the Linux test machine (`/usr/share/vulkan/explicit_layer.d` is absent), so the `ANYPS5_REQUIRE_VULKAN=1` comparison on `main` and on this branch has not been run yet. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [ ] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [ ] Unblocks: PPSA30528 (renders its loading screen; text decoding and a compute sync problem remain, tracked separately) - [ ] GPUs tested: AGC tests on Linux without a Vulkan device; the title run was on an NVIDIA RTX 3070 (driver 32.0.15.9186) on Windows 11 - [x] AI-assisted: yes
MarcZX10 commented 2026-10-23 23:41:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-23T23:41:16Z.

Review: CHANGES_REQUESTED


I found one hot-path issue in the shader-use instrumentation. The rest of the broad state-reset changes need the pending AGC build/test checks before a full review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5635557170 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10420#pullrequestreview-5635557170). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-23T23:41:16Z. **Review:** CHANGES_REQUESTED --- I found one hot-path issue in the shader-use instrumentation. The rest of the broad state-reset changes need the pending AGC build/test checks before a full review.
adriadam10 commented 2026-10-24 01:06:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-24T01:06:47Z.

Review: CHANGES_REQUESTED


Thanks for the work and the write-up. This needs splitting and a few fixes before it can be merged.

  • One topic per PR. This bundles at least: reset values of CB_TARGET_MASK/CB_SHADER_MASK/PA_CL_VTE_CNTL, zero export formats, the 0xffffffff register sentinel, rasterizer discard, legacy vertex routing, pixel input counts from the shader header, DB_RENDER_CONTROL, pipeline cache after device loss, present synchronisation, and the PM4-ring/trace diagnostics. Please send each behaviour change as its own PR with its own test and its own reference.
  • Description does not match the diff. Not mentioned in the body: rasterizerDiscard when SPI_SHADER_POS_FORMAT is 0 (Graphics/src/State.cpp:1491, new pipeline/journal key fields, FileFormat bump), legacy vertex routing now accepted (State.cpp:1169), DecodePixelStageInfo taking the input count from the shader header and throwing on per-primitive inputs (Graphics/src/ShaderInputState.cpp:110-127), and the DeviceFault retry loop (DeviceFault.hpp:58).
  • Present without semaphores (VulkanDevice.cpp:3636, :3763): the blit and vkQueuePresentKHR being on one queue does not order the presentation engine's read of the image after the blit. Present must wait on a semaphore signalled by the submit. Please keep it, or show why it is safe on every driver.
  • Hot path / diagnostics: std::getenv("APS5_TRACE_QUEUE") is called on every dispatch (Dispatch.cpp:440), present (VulkanDevice.cpp:3641, :3768); make them static const bool like the neighbouring ones. The ~1.4 KB [discard-trace] format string in DrawCapture.cpp:33 and the 256-entry shader-use ring taking a mutex on every draw (SubmissionRing.cpp:310) are debugging aids and should not ship in this fix. MarcZX10's change request on the shader-use instrumentation is still open.
  • Recorder.cpp:4090 prints submissions twice in the same message.
  • Register semantics need a source. Why CB_TARGET_MASK/CB_SHADER_MASK reset to 0xffffffff, what PA_CL_VTE_CNTL == 0 means for a draw, and what the 0xffffffff list entry does on hardware: cite the reference (KytyPS5/prosper/gfx10 docs) or a measurement in the PR, and add the matching lines to docs/dev/debt/libSceAgcDriver.md for what stays inferred.
  • Testing (AGENTS.md): AGC/shader-recompiler changes need the focused tests on main and on the change with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, and a comparison showing no new VUID- errors. "GPUs tested: n/a" is not right for this PR. The title run was before the rebase; please name the title/PPSA and re-run it on the current tree.

You are welcome to reopen/resubmit the pieces with these addressed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636000153 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10420#pullrequestreview-5636000153). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-24T01:06:47Z. **Review:** CHANGES_REQUESTED --- Thanks for the work and the write-up. This needs splitting and a few fixes before it can be merged. - **One topic per PR.** This bundles at least: reset values of `CB_TARGET_MASK`/`CB_SHADER_MASK`/`PA_CL_VTE_CNTL`, zero export formats, the `0xffffffff` register sentinel, rasterizer discard, legacy vertex routing, pixel input counts from the shader header, `DB_RENDER_CONTROL`, pipeline cache after device loss, present synchronisation, and the PM4-ring/trace diagnostics. Please send each behaviour change as its own PR with its own test and its own reference. - **Description does not match the diff.** Not mentioned in the body: `rasterizerDiscard` when `SPI_SHADER_POS_FORMAT` is 0 (`Graphics/src/State.cpp:1491`, new pipeline/journal key fields, `FileFormat` bump), legacy vertex routing now accepted (`State.cpp:1169`), `DecodePixelStageInfo` taking the input count from the shader header and throwing on per-primitive inputs (`Graphics/src/ShaderInputState.cpp:110-127`), and the DeviceFault retry loop (`DeviceFault.hpp:58`). - **Present without semaphores** (`VulkanDevice.cpp:3636`, `:3763`): the blit and `vkQueuePresentKHR` being on one queue does not order the presentation engine's read of the image after the blit. Present must wait on a semaphore signalled by the submit. Please keep it, or show why it is safe on every driver. - **Hot path / diagnostics**: `std::getenv("APS5_TRACE_QUEUE")` is called on every dispatch (`Dispatch.cpp:440`), present (`VulkanDevice.cpp:3641`, `:3768`); make them `static const bool` like the neighbouring ones. The ~1.4 KB `[discard-trace]` format string in `DrawCapture.cpp:33` and the 256-entry shader-use ring taking a mutex on every draw (`SubmissionRing.cpp:310`) are debugging aids and should not ship in this fix. MarcZX10's change request on the shader-use instrumentation is still open. - `Recorder.cpp:4090` prints `submissions` twice in the same message. - **Register semantics need a source.** Why `CB_TARGET_MASK`/`CB_SHADER_MASK` reset to `0xffffffff`, what `PA_CL_VTE_CNTL == 0` means for a draw, and what the `0xffffffff` list entry does on hardware: cite the reference (KytyPS5/prosper/gfx10 docs) or a measurement in the PR, and add the matching lines to `docs/dev/debt/libSceAgcDriver.md` for what stays inferred. - **Testing** (AGENTS.md): AGC/shader-recompiler changes need the focused tests on `main` and on the change with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, and a comparison showing no new `VUID-` errors. "GPUs tested: n/a" is not right for this PR. The title run was before the rebase; please name the title/PPSA and re-run it on the current tree. You are welcome to reopen/resubmit the pieces with these addressed.

Pull request closed

Sign in to join this conversation.
No reviewers
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!10420
No description provided.