feat(agc): execute INDEX_ATTRIBUTES_INDIRECT (PM4 0x91) #4895

Merged
fdfawef324 merged 1 commit from upstream-pr/4895 into main 2026-10-14 05:12:19 +00:00
fdfawef324 commented 2026-10-13 02:28:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-13T02:28:10Z.


What

The driver had no handler for PFP opcode 0x91 INDEX_ATTRIBUTES_INDIRECT, so a submission containing it threw opcode is not known in the reference. Demon's Souls (PPSA01342) stops there at its first indirect draw. The packet now runs: when it executes, it reads the 16-byte record at attribute_base + attribute_index * 16 from guest memory and sets INDEX_BASE, INDEX_BUFFER_SIZE and INDEX_TYPE from it, exactly as the INDEX_BASE (0x26), INDEX_BUFFER_SIZE (0x13) and INDEX_TYPE (0x2a) packets do.

packet dword field
0 0xc0029100
1 bit 0 indirect_mode, bits 1-3 reserved, attribute_base_lo
2 attribute_base_hi (or addr_offset when indirect_mode is 1)
3 16-bit attribute_index
record dword field
0 index buffer address, low
1 index buffer address, high
2 index buffer size, in indices
3 index type (VGT_INDEX_TYPE: 0 = 16-bit, 1 = 32-bit, 2 = 8-bit)

Sources:

  • Packet: PAL BuildIndexAttributesIndirect and PM4_PFP_INDEX_ATTRIBUTES_INDIRECT: 4 dwords, the base must be 4-dword aligned (it asserts that the reserved bits are 0), and indirect_mode 1 puts addr_offset in dword 2.
  • Record: PAL IndexAttribIndirect, "the layout of the index buffer attributes used by a INDEX_ATTRIBUTES_INDIRECT packet": gpuVirtAddrLo, gpuVirtAddrHi, indexBufferSize (in indices, not bytes), indexType. The type uses the VGT_INDEX_TYPE encoding; the Log2IndexSize table beside it is indexed 16, 32, 8.
  • Mesa does not define the packet. At 9a50e25c nothing under src/amd or radeonsi names INDEX_ATTRIBUTES_INDIRECT (sid.h included), and RADV's DGC dgc_emit_index_buffer (the file was radv_device_generated_commands.c) writes VGT_INDEX_TYPE, INDEX_BASE and INDEX_BUFFER_SIZE directly.

Behaviour:

  • Validation: the graphics queue only, 4 dwords. indirect_mode 1 throws (indirect mode (addr_offset) is not implemented); sceAgcDcbSetIndexIndirectArgs (#4392) never sets it. Reserved base bits 1-3 throw (unaligned base), and so do reserved bits 16-31 of dword 3.
  • Execution: the record is read when the packet runs, not at submission. Pending waits land and queued labels are recorded first, as for COND_EXEC, and the read goes through GuestMemory::Read (flush hook, then CheckRange with 16-byte alignment). A null, unmapped or overflowing record address throws, and the index state stays as it was.
  • A record with an index type above 3 throws, naming the record address and the type, as INDEX_TYPE validation does. Type 3 is stored and then rejected by the next indexed draw (unsupported index type), as for the direct packets. The base and size are not checked until the draw, also as for the direct packets.
  • The packet counts as a memory access (AccessesMemory), so dispatch-ahead resolution stops at it and APS5_DRAIN_ALL drains before it.

Recorded in docs/dev/debt/libSceAgcDriver.md: the layout comes from PAL only. It was not measured on a PS5 or checked against a title.

Tested

Windows Server 2025, RTX 3060, GCC 15.2 (WinLibs), build-dev.

  • The 26 ctest entries of agc_driver_pm4_tests, agc_driver_tests, agc_driver_flip_tests, agc_driver_recorder_tests and agc_driver_graphics_tests pass, among them agc_driver_pm4, agc_driver_pm4_failure, agc_driver, agc_driver_flip, agc_driver_graphics, agc_pipeline_cache and agc_draw_inputs_in_place.
  • New testIndexAttributesIndirect builds a 0x91 packet by hand with a record in memory. It checks that the packet loads base, size and type, and that the indexed draws DRAW_INDEX_OFFSET_2 (0x35) and DRAW_INDEX_INDIRECT (0x25) after it resolve to the same parameters as after INDEX_BASE + INDEX_BUFFER_SIZE + INDEX_TYPE. It checks that the read goes through the flush hook over exactly the record's 16 bytes. Rejections leave the index state unchanged: indirect mode, an unaligned base, reserved index bits, a wrong size, a compute queue, a null, unmapped or overflowing record address, and a record type of 4 (the message names the record address). Type 3 is rejected at the draw.
  • New testIndexAttributesReadAtExecution submits WAIT_REG_MEM, then 0x91, then WRITE_DATA. While the queue waits, the record changes from an invalid one (type 4) to a valid one. The worker finishes, so the record is read when the packet runs.
  • Red/green: with the driver change reverted and the tests kept, agc_driver_pm4 fails at the catalog check (reference opcode catalog is incomplete). With the catalog count also set back to 55, it fails in the new test (INDEX_ATTRIBUTES_INDIRECT is not executed). With the change it passes.
  • python -I tools/check_test_registration.py build-dev and tools/check_conventions.py pass.
  • Not run: any title (PPSA01342 included), and the driver tests outside those five executables (agc_driver_flat_*, agc_driver_prepared_shaders_*, the execution and BDA tests). No speed change is claimed.

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: #4392 (the sceAgcDcbSetIndexIndirectArgs builder; that PR is closed at present and has to be reopened)
  • Unblocks: PPSA01342 #1283
  • GPUs tested: NVIDIA GeForce RTX 3060 12 GB, driver 591.86 (32.0.15.9186), Vulkan 1.4.325, Windows Server 2025 10.0.26100
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4837490989 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4895). Originally posted by [fdfawef324](https://github.com/fdfawef324) on 2026-10-13T02:28:10Z. --- ### What The driver had no handler for PFP opcode 0x91 INDEX_ATTRIBUTES_INDIRECT, so a submission containing it threw `opcode is not known in the reference`. Demon's Souls (PPSA01342) stops there at its first indirect draw. The packet now runs: when it executes, it reads the 16-byte record at `attribute_base + attribute_index * 16` from guest memory and sets INDEX_BASE, INDEX_BUFFER_SIZE and INDEX_TYPE from it, exactly as the INDEX_BASE (0x26), INDEX_BUFFER_SIZE (0x13) and INDEX_TYPE (0x2a) packets do. | packet dword | field | | --- | --- | | 0 | `0xc0029100` | | 1 | bit 0 `indirect_mode`, bits 1-3 reserved, `attribute_base_lo` | | 2 | `attribute_base_hi` (or `addr_offset` when `indirect_mode` is 1) | | 3 | 16-bit `attribute_index` | | record dword | field | | --- | --- | | 0 | index buffer address, low | | 1 | index buffer address, high | | 2 | index buffer size, in indices | | 3 | index type (VGT_INDEX_TYPE: 0 = 16-bit, 1 = 32-bit, 2 = 8-bit) | Sources: - Packet: PAL [`BuildIndexAttributesIndirect`](https://github.com/GPUOpen-Drivers/pal/blob/c5e800072a32f68b6ccc4422936d96167c6e0728/src/core/hw/gfxip/gfx9/gfx9CmdUtil.cpp#L2586-L2613) and [`PM4_PFP_INDEX_ATTRIBUTES_INDIRECT`](https://github.com/GPUOpen-Drivers/pal/blob/c5e800072a32f68b6ccc4422936d96167c6e0728/src/core/hw/gfxip/gfx9/chip/gfx9_plus_merged_f32_pfp_pm4_packets.h#L2441-L2485): 4 dwords, the base must be 4-dword aligned (it asserts that the reserved bits are 0), and `indirect_mode` 1 puts `addr_offset` in dword 2. - Record: PAL [`IndexAttribIndirect`](https://github.com/GPUOpen-Drivers/pal/blob/c5e800072a32f68b6ccc4422936d96167c6e0728/src/core/hw/gfxip/gfx9/gfx9Chip.h#L60-L67), "the layout of the index buffer attributes used by a INDEX_ATTRIBUTES_INDIRECT packet": `gpuVirtAddrLo`, `gpuVirtAddrHi`, `indexBufferSize` (in indices, not bytes), `indexType`. The type uses the VGT_INDEX_TYPE encoding; the [`Log2IndexSize`](https://github.com/GPUOpen-Drivers/pal/blob/c5e800072a32f68b6ccc4422936d96167c6e0728/src/core/hw/gfxip/gfx9/gfx9Chip.h#L83-L89) table beside it is indexed 16, 32, 8. - Mesa does not define the packet. At [`9a50e25c`](https://gitlab.freedesktop.org/mesa/mesa/-/tree/9a50e25c64b941dfc03e5462d0533feda58cabe6/src/amd) nothing under `src/amd` or radeonsi names INDEX_ATTRIBUTES_INDIRECT (`sid.h` included), and RADV's DGC [`dgc_emit_index_buffer`](https://gitlab.freedesktop.org/mesa/mesa/-/blob/9a50e25c64b941dfc03e5462d0533feda58cabe6/src/amd/vulkan/radv_dgc.c#L1611-L1654) (the file was `radv_device_generated_commands.c`) writes VGT_INDEX_TYPE, INDEX_BASE and INDEX_BUFFER_SIZE directly. Behaviour: - Validation: the graphics queue only, 4 dwords. `indirect_mode` 1 throws (`indirect mode (addr_offset) is not implemented`); `sceAgcDcbSetIndexIndirectArgs` (#4392) never sets it. Reserved base bits 1-3 throw (unaligned base), and so do reserved bits 16-31 of dword 3. - Execution: the record is read when the packet runs, not at submission. Pending waits land and queued labels are recorded first, as for COND_EXEC, and the read goes through `GuestMemory::Read` (flush hook, then `CheckRange` with 16-byte alignment). A null, unmapped or overflowing record address throws, and the index state stays as it was. - A record with an index type above 3 throws, naming the record address and the type, as INDEX_TYPE validation does. Type 3 is stored and then rejected by the next indexed draw (`unsupported index type`), as for the direct packets. The base and size are not checked until the draw, also as for the direct packets. - The packet counts as a memory access (`AccessesMemory`), so dispatch-ahead resolution stops at it and `APS5_DRAIN_ALL` drains before it. Recorded in `docs/dev/debt/libSceAgcDriver.md`: the layout comes from PAL only. It was not measured on a PS5 or checked against a title. ### Tested Windows Server 2025, RTX 3060, GCC 15.2 (WinLibs), `build-dev`. - The 26 ctest entries of `agc_driver_pm4_tests`, `agc_driver_tests`, `agc_driver_flip_tests`, `agc_driver_recorder_tests` and `agc_driver_graphics_tests` pass, among them `agc_driver_pm4`, `agc_driver_pm4_failure`, `agc_driver`, `agc_driver_flip`, `agc_driver_graphics`, `agc_pipeline_cache` and `agc_draw_inputs_in_place`. - New `testIndexAttributesIndirect` builds a 0x91 packet by hand with a record in memory. It checks that the packet loads base, size and type, and that the indexed draws DRAW_INDEX_OFFSET_2 (0x35) and DRAW_INDEX_INDIRECT (0x25) after it resolve to the same parameters as after INDEX_BASE + INDEX_BUFFER_SIZE + INDEX_TYPE. It checks that the read goes through the flush hook over exactly the record's 16 bytes. Rejections leave the index state unchanged: indirect mode, an unaligned base, reserved index bits, a wrong size, a compute queue, a null, unmapped or overflowing record address, and a record type of 4 (the message names the record address). Type 3 is rejected at the draw. - New `testIndexAttributesReadAtExecution` submits WAIT_REG_MEM, then 0x91, then WRITE_DATA. While the queue waits, the record changes from an invalid one (type 4) to a valid one. The worker finishes, so the record is read when the packet runs. - Red/green: with the driver change reverted and the tests kept, `agc_driver_pm4` fails at the catalog check (`reference opcode catalog is incomplete`). With the catalog count also set back to 55, it fails in the new test (`INDEX_ATTRIBUTES_INDIRECT is not executed`). With the change it passes. - `python -I tools/check_test_registration.py build-dev` and `tools/check_conventions.py` pass. - Not run: any title (PPSA01342 included), and the driver tests outside those five executables (`agc_driver_flat_*`, `agc_driver_prepared_shaders_*`, the execution and BDA tests). No speed change is claimed. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] 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: #4392 (the `sceAgcDcbSetIndexIndirectArgs` builder; that PR is closed at present and has to be reopened) - [x] Unblocks: PPSA01342 #1283 - [x] GPUs tested: NVIDIA GeForce RTX 3060 12 GB, driver 591.86 (32.0.15.9186), Vulkan 1.4.325, Windows Server 2025 10.0.26100 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
xXPBSXx commented 2026-10-13 04:39:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T04:39:10Z.


Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on current main 3779597 together with four other open GPU PRs (their own commits cherry-picked, no merge commits), so only the tests that belong to this PR say something about it:

  • tests/Pm4.cpp (agc_driver_pm4): 3 of 3 runs passed.

Not tested: no game run. The batch was built once, not per PR; nothing failed, so no bisect was needed.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6138358050 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4895#issuecomment-6138358050). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T04:39:10Z. --- Windows test (MinGW GCC 15.2, Release, Windows 10, RTX 4080 SUPER). Built on current main `3779597` together with four other open GPU PRs (their own commits cherry-picked, no merge commits), so only the tests that belong to this PR say something about it: - `tests/Pm4.cpp` (`agc_driver_pm4`): 3 of 3 runs passed. Not tested: no game run. The batch was built once, not per PR; nothing failed, so no bisect was needed. AI-assisted (Claude Code).
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!4895
No description provided.