Skip to content

feat(agc): poll and write registers in PM4 COND_WRITE - #16184

Merged
oneandonlydean merged 3 commits into
boykopovar:mainfrom
AlexWhitehouse:feat/agc-cond-write-registers
Nov 15, 2026
Merged

oneandonlydean merged 3 commits into
boykopovar:mainfrom
AlexWhitehouse:feat/agc-cond-write-registers

Conversation

@AlexWhitehouse

Copy link
Copy Markdown
Contributor

What

PM4 COND_WRITE (opcode 0x45) worked only with a memory poll and a memory destination. A register poll threw register-space COND_WRITE poll is not implemented, and a register destination threw register or scratch COND_WRITE destination is not implemented. This PR runs both for the registers the queue already models.

Packet, from AMD's Southern Islands programming guide §2.7.2 (pp. 33–34) and PAL's GFX10 packet definition (lines 521–630, nine dwords):

  • POLL_SPACE (bit 4) selects register or memory, and WRITE_SPACE (bits 8–9) selects register, memory or scratch.
  • The value read is masked and compared with the reference using function 0–6; when the comparison holds, the write data goes to the destination.
  • Register addresses are absolute dword register numbers. The bank bases are the ones PAL's SET_*_REG builders subtract (gfx9CmdUtil.cpp lines 3650, 4025 and 4084) and Mesa's sid.h defines. Mesa's ac_cmdbuf.h converts byte offsets to the same dword numbers.

Change (core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp):

  • Register poll: reads the queue's shader (0x2c00–0x2fff), context (0xa000–0xa3ff) or user-config (0xc000–0xffff) register value, using the comparison code memory polls already use.
  • Register destination: goes through the same register write as the matching SET_SH_REG, SET_CONTEXT_REG or SET_UCONFIG_REG, so a register's side effects apply. The test checks this with VGT_INDEX_TYPE (0xc243). It reports no guest memory store to capture or replay.
  • Unchanged: the memory-poll, memory-destination path. fix(agc): leave GPU-stored words out of frame capture deltas #12568 and feat(agc): read frame capture deltas with the title's work in flight #15136 edit that statement for frame-capture accounting, and both still merge cleanly.
  • Still throws: a poll of a register with no value written yet, addresses outside the three banks (hardware status registers included), a nonzero register-address high dword, the scratch destination, reserved control bits and memory swap modes.
  • Debt: a new docs/dev/debt/libSceAgcDriver.md entry records what still throws and that PS5 behaviour, GFX10 high-dword handling and write confirmation are not measured.

Tested

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: none
  • GPUs tested: NVIDIA GeForce RTX 3060, driver 610.88, Windows 11 (build 26300); Mesa lavapipe 26.0.8 (LLVM 21.1.8), Ubuntu 26.04
  • AI-assisted: yes

🤖 Generated with Claude Code

Use the queue register banks for DWORD-addressed COND_WRITE polls and destinations. Preserve masked comparisons, ordered packet execution, register side effects and the existing memory store. Refuse unknown register values, unmodeled ranges and scratch destinations. Cover comparisons, bank selection, isolation, ordering and rejected forms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added docs agc libSceAgc* labels Nov 5, 2026
@TechLevelZero

Copy link
Copy Markdown
Contributor

✅ NVIDIA GPU test: passed

PR head e3c04eb merged onto main e9247a9 · tested 2026-11-05 23:47 UTC · 24 min

GPU NVIDIA RTX 2000 Ada Generation, driver 595.99.02, Vulkan 1.4.329
Host Ubuntu 26.04.1 LTS, kernel 7.0.0-38-generic, container ubuntu:24.04
Logs build and test logs for this run
Build ✅ passed (Release, -DANYPS5_ENABLE_SPIRV_TOOLS=ON)
Tests ✅ 2,886 passed · 3 failed (0 new, 3 also fail on main) · 51 skipped (ANYPS5_REQUIRE_VULKAN=1)
Test setup CPU-only tests without a GPU; GPU tests (and any CPU-only test that failed or skipped without one) once on the GPU with VK_LAYER_KHRONOS_validation and ANYPS5_NO_SHADER_CACHE=1; main ran the same way
Test selection 2,940 of 4,105 tests run: the ones this change can reach, chosen by tools/select_tests.py from main's build graph
Vulkan validation ✅ no new validation IDs vs main (969 tests run on the GPU)
Slow tests (>30 s, GPU tests timed with validation layers) ⚠️ agc_driver_pipeline_journal 119.2 s
Failing on main too (3, not counted against this PR)
agc_driver_image_table
guest_mmap_executable
guest_socket_options_multicast
Validation IDs already present on main (9 IDs in 585 tests)
VUID-VkDeviceCreateInfo-pNext-pNext (585 tests): agc_driver, agc_driver_address_draw_space_reuse, agc_driver_address_passes, agc_driver_alias_copy_label, agc_driver_alpha_to_coverage, agc_driver_array_layer_target, agc_driver_bc_block_copy, agc_driver_bda_anchor_reads, and 577 more
VUID-VkShaderModuleCreateInfo-pCode-08737 (14 tests): agc_driver_dpp16_operands, agc_driver_dpp8_pk_fmac, agc_driver_dx10_clamp, agc_driver_f16_fma_denormal_modes, agc_driver_f16_fma_invalid_nan, agc_driver_float16_fma_rounding, agc_driver_float16_modifiers, agc_driver_float16_native, and 6 more
VUID-VkShaderModuleCreateInfo-pCode-08739 (14 tests): agc_driver_dpp16_operands, agc_driver_dpp8_pk_fmac, agc_driver_dx10_clamp, agc_driver_f16_fma_denormal_modes, agc_driver_f16_fma_invalid_nan, agc_driver_float16_fma_rounding, agc_driver_float16_modifiers, agc_driver_float16_native, and 6 more
VUID-VkShaderModuleCreateInfo-pCode-08741 (14 tests): agc_driver_dpp16_operands, agc_driver_dpp8_pk_fmac, agc_driver_dx10_clamp, agc_driver_f16_fma_denormal_modes, agc_driver_f16_fma_invalid_nan, agc_driver_float16_fma_rounding, agc_driver_float16_modifiers, agc_driver_float16_native, and 6 more
VUID-vkCmdCopyImage-srcImage-01548 (7 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_sampling, agc_driver_depth_storage_dispatch, agc_driver_depth_surface_from_storage, agc_driver_dispatch_move_depth
VUID-vkCmdCopyImage-srcImage-01551 (7 tests): agc_driver_depth_clear_hle, agc_driver_depth_plane_buffer_memory, agc_driver_depth_plane_partial_store, agc_driver_depth_plane_sampling, agc_driver_depth_storage_dispatch, agc_driver_depth_surface_from_storage, agc_driver_dispatch_move_depth
VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 (1 test): agc_driver_prepared_exports
VUID-VkPipelineShaderStageCreateInfo-module-parameter (1 test): agc_driver_float16_unused_nan_payloads
VUID-VkPipelineShaderStageCreateInfo-pSpecializationInfo-06849 (1 test): agc_driver_float16_unused_nan_payloads
Skipped (51)
agc_driver_gcn_display_present: skipped, no display: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
agc_driver_sample_order_grid_reference: skipped, the device does not keep depth drawn at custom sample locations at those locations, even after a transition that names them: the composite of uniform renders holds the guest's depth in 0 of 3005 sloped samples, so no path can be compared with it bit for bit
agc_driver_vertex_elected_atomic_max: skipped, the device runs vertex programs in subgroups, so they keep their cross-lane reductions
agc_host_import_sparse: skipped, host imports are unavailable: /dev/udmabuf is not accessible
guest_http_uri_locale: 
guest_net_ctl: skipped, the host has no IPv4 address
guest_net_ctl_disconnected: skipped, the host has no IPv4 address
guest_video_out_color_space: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_device_capability: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_hdr: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_high_frame_rate: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_host_resolution_disabled: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_host_resolution_four_k: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_host_resolution_height_only: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_host_resolution_limit: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_host_resolution_malformed: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_host_resolution_width_only: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_output_mode: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_resolution_status: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
guest_video_out_wqhd_detection: skipped, no display or Vulkan device: SDL_InitSubSystem(VIDEO | GAMECONTROLLER) failed: wayland,x11 not available
video_out_flip_aftergpu: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_backtoback: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_controls: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_cpuflip_in_order: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_dcc: skipped, no display or Vulkan device: DisplayWindow: Vulkan support is either not configured in SDL or not available in current SDL video driver (offscreen) or platform
video_out_flip_deferred: skipped, no
Reproduce
git fetch origin e3c04eb5458ed660d3c35e17f929de453e97af76 e9247a966ff6cce55816ffe1d73a2679074348a4
git checkout e9247a966ff6cce55816ffe1d73a2679074348a4 && git merge --no-ff e3c04eb5458ed660d3c35e17f929de453e97af76
git submodule update --init --recursive
cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON
cmake --build build && cmake --build build --target libs
VK_DRIVER_FILES=/nonexistent/icd.json ctest --test-dir build -E '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 32 --output-on-failure
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation \
  ctest --test-dir build -R '^(agc|shader|recompiler|videoout|video_out|guest_video_out|vulkan)|gpu' --timeout 120 --parallel 4 --output-on-failure
# failures are then re-run alone: --timeout 360 --parallel 2; new validation IDs: the test alone, twice, --parallel 1

Automated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs.

@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 4448 docs/dev/debt/libSceAgcDriver.md
PR 5372 docs/dev/debt/libSceAgcDriver.md
PR 5925 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/DispatchAhead.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6186 core/libs/prx/libSceAgcDriver/tests/Pm4.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6188 core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp
PR 6280 docs/dev/debt/libSceAgcDriver.md
PR 6412 docs/dev/debt/libSceAgcDriver.md
PR 6481 docs/dev/debt/libSceAgcDriver.md
PR 6804 docs/dev/debt/libSceAgcDriver.md
PR 6808 docs/dev/debt/libSceAgcDriver.md
PR 7002 docs/dev/debt/libSceAgcDriver.md
PR 7256 docs/dev/debt/libSceAgcDriver.md
PR 7449 docs/dev/debt/libSceAgcDriver.md
PR 7642 docs/dev/debt/libSceAgcDriver.md
PR 8592 docs/dev/debt/libSceAgcDriver.md
PR 9335 docs/dev/debt/libSceAgcDriver.md
PR 9356 docs/dev/debt/libSceAgcDriver.md
PR 9387 docs/dev/debt/libSceAgcDriver.md
PR 9508 docs/dev/debt/libSceAgcDriver.md
PR 9895 docs/dev/debt/libSceAgcDriver.md
PR 9950 docs/dev/debt/libSceAgcDriver.md
PR 10049 docs/dev/debt/libSceAgcDriver.md
PR 10193 docs/dev/debt/libSceAgcDriver.md
PR 10249 core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp
PR 10359 docs/dev/debt/libSceAgcDriver.md
PR 10743 docs/dev/debt/libSceAgcDriver.md
PR 11551 docs/dev/debt/libSceAgcDriver.md
PR 11825 docs/dev/debt/libSceAgcDriver.md
PR 12904 docs/dev/debt/libSceAgcDriver.md
PR 13809 docs/dev/debt/libSceAgcDriver.md
PR 13863 docs/dev/debt/libSceAgcDriver.md
PR 13920 docs/dev/debt/libSceAgcDriver.md
PR 13928 docs/dev/debt/libSceAgcDriver.md
PR 13929 docs/dev/debt/libSceAgcDriver.md
PR 13963 docs/dev/debt/libSceAgcDriver.md
PR 14944 docs/dev/debt/libSceAgcDriver.md
PR 15456 docs/dev/debt/libSceAgcDriver.md
PR 15529 docs/dev/debt/libSceAgcDriver.md
PR 15548 docs/dev/debt/libSceAgcDriver.md
PR 15621 docs/dev/debt/libSceAgcDriver.md
PR 16253 docs/dev/debt/libSceAgcDriver.md
PR 16260 docs/dev/debt/libSceAgcDriver.md
PR 16427 docs/dev/debt/libSceAgcDriver.md
PR 16483 docs/dev/debt/libSceAgcDriver.md
PR 16753 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/DispatchAhead.cpp
PR 17611 docs/dev/debt/libSceAgcDriver.md
PR 17915 docs/dev/debt/libSceAgcDriver.md
PR 17943 docs/dev/debt/libSceAgcDriver.md
PR 17956 docs/dev/debt/libSceAgcDriver.md
PR 18029 docs/dev/debt/libSceAgcDriver.md
PR 18515 docs/dev/debt/libSceAgcDriver.md
PR 18914 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/DispatchAhead.cpp
core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp
core/libs/prx/libSceAgcDriver/tests/Pm4.cpp
PR 19191 core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp
core/libs/prx/libSceAgcDriver/tests/Pm4.cpp
PR 20156 docs/dev/debt/libSceAgcDriver.md
PR 20186 docs/dev/debt/libSceAgcDriver.md
PR 20187 docs/dev/debt/libSceAgcDriver.md

@oneandonlydean oneandonlydean self-assigned this Nov 8, 2026
@Jirka135

Copy link
Copy Markdown
Contributor

Reviewed PM4 COND_WRITE register poll and write — no blocking findings

The field decoding matches the GFX10 packet definition and the repo's own register helpers; I found three non-blocking questions, none showing a wrong result on the tested path.

What I ran

Head reviewed: e3c04eb5458ed660d3c35e17f929de453e97af76 (base main). I read the description, the thread, the single commit, the full diff, and at head Execution/src/Pm4.cpp (Validate, DecodeStores, Execute, waitCompares, registerBankBase), tests/Pm4.cpp, the debt entry, and the other 0x45 users (DispatchAhead.cpp, PacketMemory.cpp, tools/Pm4Analysis.cpp). I also read PAL's PM4_ME_COND_WRITE at the pinned commit via gh api GET.

No build or test was run here; this review is from reading the code only. The test results in the description are the author's.

Results

Check Result Note
Control bits vs PAL (function 0-2, poll space 4, write space 8-9; dwords 2-3 poll, 4 reference, 5 mask, 6-7 write, 8 data) passed Pm4.cpp:513-523, 739-742, 592-606 match PAL lines 521-630. wr_confirm is bit 20, outside the 0x317 mask, so it throws as the debt entry says.
Register numbering and banks vs COPY_DATA register source passed Same absolute dword numbers, same registerBankBase, same zero high dword (Pm4.cpp:193-198, 205-209, 568). WAIT_REG_MEM has no precedent: its register space still throws (:503).
Register destination = SET_*_REG write passed (execution only) Execute calls writeRegister with 0x76/0x69/0x79 and the bank-relative offset (:1215-1218), as :1188-1192 does.
Memory-poll and memory-destination path passed Unchanged apart from the poll-space guard (:1205). Alignment now applies only to memory addresses (:522).
Tests fail without the fix passed (by reasoning) Validate threw on any register poll or destination on main, so testConditionalWriteRegisters (tests/Pm4.cpp:1558) fails there.

Findings

Blocking

None.

Non-blocking

  1. A COND_WRITE can write a context or user-config register on a compute queue. Validate rejects SET_CONTEXT_REG and SET_UCONFIG_REG there (Pm4.cpp:490, graphics() at :308); 0x45 has no such check (:513-523), and the new test only runs queue 0 (tests/Pm4.cpp:71-73). The description says the destination "goes through the same register write", which holds for Execute but not for validation. Is the gap intended?
  2. DispatchAhead.cpp:236-243 steps over 0x45 without executing it (it is in AccessesMemory) and keeps scanning. A register-destination COND_WRITE now changes preview state that a later dispatch in the window reads (:205-212), so the speculative shader preparation may use stale registers. From reading, this only costs a wasted precompile, not a wrong result. Worth a look if you want it exact.
  3. tools/Pm4Analysis.cpp:112-115 still prints every COND_WRITE as a memory poll and a memory store, so a register poll shows a register number as an address.

Not verified

  • PS5 hardware behaviour, GFX10 high-dword semantics and write confirmation (the debt entry says the same).
  • Any build or run on Windows, AMD or the CI jobs.
  • Whether RegisterStateKey stays consistent through a COND_WRITE in a real submission; the unit test's execute helper checks it on queue 0 only.

To get this to a good state

Nothing is required. Please answer or fix item 1 (and 2 if it matters), and update the analysis tool line (3).

AI-assisted: yes (code read with Claude Code; no build or test run).

A register-destination COND_WRITE into the context or user-config bank now
fails validation on a compute queue, as SET_CONTEXT_REG and SET_UCONFIG_REG
do. The dispatch-ahead scan stops at a register-destination COND_WRITE
instead of skipping it, and Pm4Analysis prints register operands as
registers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlexWhitehouse

Copy link
Copy Markdown
Contributor Author

Thanks for the review. All three are addressed in bbbaa58:

  1. A register-destination COND_WRITE into the context or user-config bank now fails validation on a compute queue with the same "graphics packet in compute queue" error as SET_CONTEXT_REG and SET_UCONFIG_REG; shader-bank destinations and register polls stay allowed there, as SET_SH_REG and COPY_DATA register sources are. testConditionalWriteRegisters covers both cases on queue 1, and removing the new check makes it fail with "expected PM4 rejection".
  2. The dispatch-ahead scan now stops at a register-destination COND_WRITE instead of stepping over it, so no later speculative preparation reads registers it could have changed.
  3. Pm4Analysis prints a register poll and a register destination as register 0x... instead of an address.

Linux (lavapipe): 34/34 of the PM4, frame replay, dispatch-ahead, recorder and register-key tests pass, and check_conventions.py passes. No Windows or hardware run for this follow-up.

…ITE register write

Move the register-destination COND_WRITE check to the top of the scan loop,
away from the indirect-register branch that boykopovar#18914 rewrites, so the two
changes merge without a conflict. Behaviour is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlexWhitehouse

Copy link
Copy Markdown
Contributor Author

pr-overlap flagged #18914 on DispatchAhead.cpp lines 233-235. In d723030 the register-destination COND_WRITE check moved to the top of the scan loop, away from the indirect-register branch #18914 rewrites; a test merge with #18914's head is now clean, behaviour is unchanged, and the 34 related tests still pass.

@oneandonlydean
oneandonlydean merged commit 899594e into boykopovar:main Nov 15, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants