graphics: add structured PM4 submission inspector #345

Closed
github-bot wants to merge 1 commit from gh-pr/345/head into gh-pr/345/base
Owner

@⁠Techx3 on GitHub · 2026-08-28 19:11 UTC · original
Techx3:techx3/pm4-submission-inspector → main · +1081 −3 · 9 files · 1 commits · closed without merging

Summary

Add an opt-in structured PM4 submission inspector alongside the existing text command-buffer dump.

When Command Buffer Dump is enabled, Kyty now writes one JSON trace per graphics or async-compute submission. Normal execution is unchanged when dumping is disabled.

Captured data

  • Root packet words and readable nested indirect command buffers.
  • Direct and indirect context, shader, and uconfig register writes.
  • Persistent register-state counts and hash per queue.
  • Queue, frame, source address, packet offsets, payloads, predicates, and opcode names.
  • Explicit Known, Partial, Inferred, Unknown, Unsupported, and UnreadableAtCaptureTime classifications.

Known means the packet structure was decoded. It does not claim complete runtime semantics.

Safety and correctness

  • Validate every mapped guest-memory segment before copying indirect data.
  • Cap nesting depth, individual snapshots, and total snapshot size.
  • Detect already-captured indirect buffers to stop cycles.
  • Keep graphics and async-compute state in separate namespaces even when their numeric queue IDs match.
  • Verify directory creation and the exact number of JSON bytes written.
  • Preserve existing opcode naming through shared read-only helpers.

Verification

  • pm4_inspector_tests build passed with clang-cl.
  • pm4_inspector_tests.exe passed.
  • CTest pm4_inspector passed (1/1).
  • Full kyty_emulator build passed.

Tests cover direct and indirect registers, nested buffers, malformed and unknown packets, state persistence/reset, JSON schema, trace file output, and cross-kind queue isolation.

Scope

This PR intentionally excludes the later AGC resource-registration layer from the external branch because those ABI additions require separate validation. It also does not overlap the PM4 fuzzer in #302: that PR stress-tests packet walking, while this change produces deterministic semantic traces for real submissions.

The SDK 12 Shader Core ISA corpus confirms command-buffer interaction at a general level but does not document the private packet names used here. Accordingly, unsupported named opcodes are classified as Inferred, not Known.

Original work is retained through the commit co-author trailer.

**@⁠Techx3** on GitHub · 2026-08-28 19:11 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/345) `Techx3:techx3/pm4-submission-inspector` → `main` · +1081 −3 · 9 files · 1 commits · closed without merging ## Summary Add an opt-in structured PM4 submission inspector alongside the existing text command-buffer dump. When Command Buffer Dump is enabled, Kyty now writes one JSON trace per graphics or async-compute submission. Normal execution is unchanged when dumping is disabled. ## Captured data - Root packet words and readable nested indirect command buffers. - Direct and indirect context, shader, and uconfig register writes. - Persistent register-state counts and hash per queue. - Queue, frame, source address, packet offsets, payloads, predicates, and opcode names. - Explicit Known, Partial, Inferred, Unknown, Unsupported, and UnreadableAtCaptureTime classifications. Known means the packet structure was decoded. It does not claim complete runtime semantics. ## Safety and correctness - Validate every mapped guest-memory segment before copying indirect data. - Cap nesting depth, individual snapshots, and total snapshot size. - Detect already-captured indirect buffers to stop cycles. - Keep graphics and async-compute state in separate namespaces even when their numeric queue IDs match. - Verify directory creation and the exact number of JSON bytes written. - Preserve existing opcode naming through shared read-only helpers. ## Verification - pm4_inspector_tests build passed with clang-cl. - pm4_inspector_tests.exe passed. - CTest pm4_inspector passed (1/1). - Full kyty_emulator build passed. Tests cover direct and indirect registers, nested buffers, malformed and unknown packets, state persistence/reset, JSON schema, trace file output, and cross-kind queue isolation. ## Scope This PR intentionally excludes the later AGC resource-registration layer from the external branch because those ABI additions require separate validation. It also does not overlap the PM4 fuzzer in #302: that PR stress-tests packet walking, while this change produces deterministic semantic traces for real submissions. The SDK 12 Shader Core ISA corpus confirms command-buffer interaction at a general level but does not document the private packet names used here. Accordingly, unsupported named opcodes are classified as Inferred, not Known. Original work is retained through the commit co-author trailer.
Emit bounded JSON traces for graphics and async-compute submissions when command-buffer dumping is enabled. Decode direct and indirect register writes, snapshot readable nested buffers, persist queue-local state, and classify unsupported or unreadable packets without changing execution.

Validate complete guest ranges before snapshots, isolate graphics and compute state namespaces, verify trace writes, and cover packet parsing, recursion, malformed input, JSON schema, file output, and queue isolation.

Co-authored-by: GodsWill <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:17:00 +00:00
github-bot closed this pull request 2026-11-26 09:17:00 +00:00
Author
Owner

@⁠Nmzik on GitHub · 2026-08-29 07:05 UTC · original

We don't need that on the main branch. Keep it private as a debugging helper for yourself. I also deliberately avoid adding one-time debugging stuff to the project because I don't want to complicate the codebase.

**@⁠Nmzik** on GitHub · 2026-08-29 07:05 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/345#issuecomment-5460966456) We don't need that on the main branch. Keep it private as a debugging helper for yourself. I also deliberately avoid adding one-time debugging stuff to the project because I don't want to complicate the codebase.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.