CP: close a command buffer whose last dword cannot be a packet #1405

Open
github-bot wants to merge 1 commit from github-bot/gh-1405 into main AGit
Owner

@⁠Franseven on GitHub · 2026-10-11 07:46 UTC · original
Franseven:pr/cp-tail → main · +13 −1 · 1 files · 1 commits · open

Game

Gran Turismo 7 (PPSA01341).

Problem

CommandProcessor::ProcessPm4 ends the whole emulator when a command buffer runs out with a single
dword left:

const auto remaining_dw = total_dw - cursor.offset_dw;
...
EXIT_NOT_IMPLEMENTED(remaining_dw < 2);

One dword cannot be a packet at all. It is not a packet whose declared length runs past the end of
the buffer — that case is still rejected by the existing checks — it is a lone word: a type-3
header with no body, or the type-2 filler word. Games do leave one behind the last real packet.

GT7 stops that way after the session has already drawn. The fatal line lands at the end of a log
that had already emitted 912 shader-counter lines, not at startup:

Shaders: VS 171 | PS 638 | CS 99 | GS 4 | LS 0 | HS 0 | TES 0
--- Fatal Error ---
Not implemented (remaining_dw < 2) in src/graphics/guest_gpu/graphicsRun.cpp:912

Other runs show the same buffer closing with a lone 0x00000000 word at offset 0xc4 (and
0xcc).

Related to #1330, but the opposite case: this is the last dword of a buffer, which cannot be a
packet at all (it would be a type-0/type-3 header with no body), not a packet whose declared length
runs past the end. The two can coexist — #1330 refuses a truncated packet that declares a length,
this one ignores a trailing word that cannot declare anything.

Change

-		EXIT_NOT_IMPLEMENTED(remaining_dw < 2);
+		if (remaining_dw < 2) {
+			// A single dword is too short for any packet: a type-0/type-3 header with no body,
+			// or a type-2 NOP carrying a count, which is filler and not a length. Games really do
+			// leave one word behind the last real packet: consume it and the buffer is done.
+			static std::atomic<uint32_t> tail_log_count {0};
+			if (tail_log_count.fetch_add(1, std::memory_order_relaxed) < 16) {
+				LOGF("CP: trailing dword 0x%08" PRIx32 " at offset=0x%05" PRIx32 "\n", packet[0],
+				     total_dw - remaining_dw);
+			}
+			cursor.offset_dw++;
+			execution.m_made_progress = true;
+			continue;
+		}

The continue matters: the loop advances cursor.offset_dw and sets m_made_progress, so the
buffer closes normally instead of ending the run. The offset is logged at most 16 times, because
GT7 reaches this point repeatedly.

Testing

Built with clang-cl 23.1.3 (Release) on Windows; the emulator links and runs. The change is
confined to the PM4 loop, so nothing outside the command processor is affected.
eatedly.

**@⁠Franseven** on GitHub · 2026-10-11 07:46 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1405) `Franseven:pr/cp-tail` → `main` · +13 −1 · 1 files · 1 commits · open ### Game Gran Turismo 7 (PPSA01341). ### Problem `CommandProcessor::ProcessPm4` ends the whole emulator when a command buffer runs out with a single dword left: ```cpp const auto remaining_dw = total_dw - cursor.offset_dw; ... EXIT_NOT_IMPLEMENTED(remaining_dw < 2); ``` One dword cannot be a packet at all. It is not a packet whose declared length runs past the end of the buffer — that case is still rejected by the existing checks — it is a lone word: a type-3 header with no body, or the type-2 filler word. Games do leave one behind the last real packet. GT7 stops that way *after* the session has already drawn. The fatal line lands at the end of a log that had already emitted 912 shader-counter lines, not at startup: ``` Shaders: VS 171 | PS 638 | CS 99 | GS 4 | LS 0 | HS 0 | TES 0 --- Fatal Error --- Not implemented (remaining_dw < 2) in src/graphics/guest_gpu/graphicsRun.cpp:912 ``` Other runs show the same buffer closing with a lone `0x00000000` word at offset `0xc4` (and `0xcc`). Related to #1330, but the opposite case: this is the last dword of a buffer, which cannot be a packet at all (it would be a type-0/type-3 header with no body), not a packet whose declared length runs past the end. The two can coexist — #1330 refuses a truncated packet that *declares* a length, this one ignores a trailing word that cannot declare anything. ### Change ```diff - EXIT_NOT_IMPLEMENTED(remaining_dw < 2); + if (remaining_dw < 2) { + // A single dword is too short for any packet: a type-0/type-3 header with no body, + // or a type-2 NOP carrying a count, which is filler and not a length. Games really do + // leave one word behind the last real packet: consume it and the buffer is done. + static std::atomic<uint32_t> tail_log_count {0}; + if (tail_log_count.fetch_add(1, std::memory_order_relaxed) < 16) { + LOGF("CP: trailing dword 0x%08" PRIx32 " at offset=0x%05" PRIx32 "\n", packet[0], + total_dw - remaining_dw); + } + cursor.offset_dw++; + execution.m_made_progress = true; + continue; + } ``` The `continue` matters: the loop advances `cursor.offset_dw` and sets `m_made_progress`, so the buffer closes normally instead of ending the run. The offset is logged at most 16 times, because GT7 reaches this point repeatedly. ### Testing Built with clang-cl 23.1.3 (Release) on Windows; the emulator links and runs. The change is confined to the PM4 loop, so nothing outside the command processor is affected. eatedly.
ProcessPm4 ends the run when a single dword is left in the buffer:
EXIT_NOT_IMPLEMENTED(remaining_dw < 2). One dword cannot be a packet at
all - a type-3 header with no body, or the type-2 filler word - and games
do leave one behind the last real packet. Gran Turismo 7 stops that way
after the session has already drawn: the fatal line arrives after 912
shader-counter lines, and in other runs the same buffer ends with a lone
0x00000000 dword at offset 0xc4.

Consume the word and let the buffer close normally instead of ending the
run. The offset is logged at most 16 times, since GT7 reaches it
repeatedly.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:55:57 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-11 07:50 UTC · original

Review in Change Stack →

📝 Walkthrough

Walkthrough

When fewer than two dwords remain, ProcessPm4 consumes the trailing dword, logs at most 16 such cases, and marks execution progress. This replaces the previous EXIT_NOT_IMPLEMENTED result for that condition.

Suggested reviewers: nmzik


Priority: ➖ Normal

Change: Bug fix

Merge Risk: 🔵 Low · up to 222d8

A truncated final command can be silently dropped. Distinguish filler from incomplete packets before merging, or accept this bounded risk explicitly.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check Passed The description clearly explains the trailing-dword failure in CommandProcessor::ProcessPm4, the intended fix, logging behavior, affected game, and reported build validation.
Title check Passed The title clearly and concisely describes the main change: closing a command buffer when its final dword cannot form a packet.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-11 07:50 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1405#issuecomment-6106843866) <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1405?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> ## Walkthrough When fewer than two dwords remain, `ProcessPm4` consumes the trailing dword, logs at most 16 such cases, and marks execution progress. This replaces the previous `EXIT_NOT_IMPLEMENTED` result for that condition. **Suggested reviewers:** `nmzik` <hr> </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"222d83016cc9776711c1eebdf3c6c50b512c2fe5" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** **🔵 Low** · up to `222d8` <!-- final_review_risk_coverage:{"sourceCommitId":"222d83016cc9776711c1eebdf3c6c50b512c2fe5","coveredCommitId":"222d83016cc9776711c1eebdf3c6c50b512c2fe5","kind":"reviewed"} --> A truncated final command can be silently dropped. Distinguish filler from incomplete packets before merging, or accept this bounded risk explicitly. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks | <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v1.svg" width="14" height="17" align="middle" alt="Passed" title="Passed"></picture></sup> 4 | <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v1.svg" width="14" height="17" align="middle" alt="Failed" title="Failed"></picture></sup> 1</strong></summary> <dl> <dd> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :---------------- | :----------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Warning](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-warning.svg) | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong>✅ Passed checks (4 passed)</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description clearly explains the trailing-dword failure in `CommandProcessor::ProcessPm4`, the intended fix, logging behavior, affected game, and reported build validation. | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely describes the main change: closing a command buffer when its final dword cannot form a packet. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | </dd> </dl> </details> <hr> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1405)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) <hr> </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -696,3 +696,3 @@
}
EXIT_NOT_IMPLEMENTED(remaining_dw < 2);
if (remaining_dw < 2) {
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-11 07:50 UTC · original

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '660,790p' src/graphics/guest_gpu/graphicsRun.cpp
sed -n '1,110p' src/graphics/guest_gpu/pm4.h
rg -n 'ProcessPm4|PacketSizeDw|KYTY_PM4_LEN' src/graphics/guest_gpu

Repository: KytyPS5/KytyPS5

Length of output: 17045


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- ProcessPm4 callers and execution setup ---'
rg -n -F --glob '*.{cpp,h}' -- 'ProcessPm4(' src/graphics/guest_gpu
rg -n -F --glob '*.{cpp,h}' -- 'Pm4Execution' src/graphics/guest_gpu
printf '%s\n' '--- command-buffer submission and span construction ---'
rg -n -F --glob '*.{cpp,h}' -- 'ProcessCommands' src/graphics/guest_gpu
rg -n -F --glob '*.{cpp,h}' -- 'ProcessCommand' src/graphics/guest_gpu
rg -n -F --glob '*.{cpp,h}' -- 'std::span<const uint32_t>' src/graphics/guest_gpu
printf '%s\n' '--- parser and length-validation implementation ---'
sed -n '1,180p' src/graphics/guest_gpu/pm4.cpp
sed -n '120,190p' src/graphics/guest_gpu/command_processor/commandProcessor.h
sed -n '620,675p' src/graphics/guest_gpu/graphicsRun.cpp

Repository: KytyPS5/KytyPS5

Length of output: 15550


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- ProcessPm4 callers and execution setup ---'
rg -n -F --glob '*.{cpp,h}' -- 'ProcessPm4(' src/graphics/guest_gpu || test "$?" -eq 1
rg -n -F --glob '*.{cpp,h}' -- 'Pm4Execution' src/graphics/guest_gpu || test "$?" -eq 1
printf '%s\n' '--- command-buffer submission and span construction ---'
rg -n -F --glob '*.{cpp,h}' -- 'ProcessCommands' src/graphics/guest_gpu || test "$?" -eq 1
rg -n -F --glob '*.{cpp,h}' -- 'ProcessCommand' src/graphics/guest_gpu || test "$?" -eq 1
rg -n -F --glob '*.{cpp,h}' -- 'std::span<const uint32_t>' src/graphics/guest_gpu || test "$?" -eq 1
printf '%s\n' '--- parser and length-validation implementation ---'
sed -n '1,180p' src/graphics/guest_gpu/pm4.cpp
sed -n '120,190p' src/graphics/guest_gpu/command_processor/commandProcessor.h
sed -n '620,675p' src/graphics/guest_gpu/graphicsRun.cpp

Repository: KytyPS5/KytyPS5

Length of output: 15550


🏁 Script executed:

pwd
rg -n -F -- 'ProcessPm4(' src/graphics/guest_gpu
rg -n -F -- 'Pm4Execution' src/graphics/guest_gpu
rg -n -F -- 'PacketSizeDw' src/graphics/guest_gpu

Repository: KytyPS5/KytyPS5

Length of output: 1884


🌐 Web query:

KytyPS5 CommandProcessor ProcessPm4 graphicsRun.cpp Pm4Execution

💡 Result:

`CommandProcessor::ProcessPm4(Pm4Execution&)` is the PM4 packet-execution loop in KytyPS5’s `graphicsRun.cpp`.

- **Execution state:** `Pm4Execution` keeps a stack of command-buffer cursors (each with a dword offset), plus a pending indirect buffer, chain flag, suspension flag, and progress flag. That state persists when processing is blocked, so execution can resume later. ([github.com](https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/command_processor/commandProcessor.h?utm_source=openai))
- **Per packet:** The loop selects the top cursor, handles end-of-buffer and padding, reads the packet header/opcode, and optionally skips predicated packets. Otherwise it finds the opcode handler in `g_cp_op_func` and invokes it. An unknown opcode logs nearby command words and exits. ([github.com](https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/graphicsRun.cpp))
- **Blocking and indirect buffers:** A handler can suspend execution; the loop returns without advancing past that packet. On the next processing attempt, the same cursor position is retried. If a handler schedules an indirect buffer, the loop either pushes it onto the cursor stack (call) or replaces the current cursor (chain/taken branch). ([github.com](https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/graphicsRun.cpp))
- **Completion:** `Process()` reports `Complete` when the cursor stack is empty; otherwise it reports `Blocked`. ([github.com](https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/graphicsRun.cpp))

These details are from the repository’s `main` branch; the cited source does not pin them to a particular release or commit. ([github.com](https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/graphicsRun.cpp?utm_source=openai))

Citations:

- 1: https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/command_processor/commandProcessor.h?utm_source=openai
- 2: https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/graphicsRun.cpp
- 3: https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/graphicsRun.cpp
- 4: https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/graphicsRun.cpp
- 5: https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/graphicsRun.cpp?utm_source=openai

🏁 Script executed:

set -o pipefail
printf '%s\n' '--- GuestGpu submission and processing ---'
sed -n '96,170p' src/graphics/guest_gpu/graphicsRun.cpp
printf '%s\n' '--- Process entry and execution state ---'
sed -n '24,52p' src/graphics/guest_gpu/command_processor/commandProcessor.h
sed -n '624,678p' src/graphics/guest_gpu/graphicsRun.cpp
printf '%s\n' '--- exact changed diff against requested base ---'
git diff --unified=25 730e1a3cf39d50c787d477e813e0bef92006a063 222d83016cc9776711c1eebdf3c6c50b512c2fe5 -- src/graphics/guest_gpu/graphicsRun.cpp

Repository: KytyPS5/KytyPS5

Length of output: 8081


Reject incomplete multi-dword packets before consuming the tail.

GuestGpu::Submit and SubmitCompute accept one-dword command spans. CommandProcessor::Process forwards them without packet-size validation. If the dword is an ordinary PM4 header, the new tail branch consumes it before EXIT_IF(packet_dw > remaining_dw) runs. The command is dropped, and processing reports completion.

Suggested fix
--- "a/src/graphics/guest_gpu/graphicsRun.cpp"
+++ "b/src/graphics/guest_gpu/graphicsRun.cpp"
@@ -695,11 +695,11 @@
 			continue;
 		}
 
 		if (remaining_dw < 2) {
-			// A single dword is too short for any packet: a type-0/type-3 header with no body,
-			// or a type-2 NOP carrying a count, which is filler and not a length. Games really do
-			// leave one word behind the last real packet: consume it and the buffer is done.
+			EXIT_NOT_IMPLEMENTED((packet_header >> 30u) != 2u &&
+			                     Pm4::PacketSizeDw(packet_header) != 1u);
+			// Type-2 filler and the recognized one-dword form can end a command buffer.
 			static std::atomic<uint32_t> tail_log_count {0};
 			if (tail_log_count.fetch_add(1, std::memory_order_relaxed) < 16) {
 				LOGF("CP: trailing dword 0x%08" PRIx32 " at offset=0x%05" PRIx32 "\n", packet[0],
 				     total_dw - remaining_dw);
**@⁠coderabbitai[bot]** on GitHub · 2026-10-11 07:50 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1405#discussion_r4240763842) **🎯 Functional Correctness** | **🟡 Minor** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash sed -n '660,790p' src/graphics/guest_gpu/graphicsRun.cpp sed -n '1,110p' src/graphics/guest_gpu/pm4.h rg -n 'ProcessPm4|PacketSizeDw|KYTY_PM4_LEN' src/graphics/guest_gpu ``` Repository: KytyPS5/KytyPS5 Length of output: 17045 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- ProcessPm4 callers and execution setup ---' rg -n -F --glob '*.{cpp,h}' -- 'ProcessPm4(' src/graphics/guest_gpu rg -n -F --glob '*.{cpp,h}' -- 'Pm4Execution' src/graphics/guest_gpu printf '%s\n' '--- command-buffer submission and span construction ---' rg -n -F --glob '*.{cpp,h}' -- 'ProcessCommands' src/graphics/guest_gpu rg -n -F --glob '*.{cpp,h}' -- 'ProcessCommand' src/graphics/guest_gpu rg -n -F --glob '*.{cpp,h}' -- 'std::span<const uint32_t>' src/graphics/guest_gpu printf '%s\n' '--- parser and length-validation implementation ---' sed -n '1,180p' src/graphics/guest_gpu/pm4.cpp sed -n '120,190p' src/graphics/guest_gpu/command_processor/commandProcessor.h sed -n '620,675p' src/graphics/guest_gpu/graphicsRun.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 15550 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- ProcessPm4 callers and execution setup ---' rg -n -F --glob '*.{cpp,h}' -- 'ProcessPm4(' src/graphics/guest_gpu || test "$?" -eq 1 rg -n -F --glob '*.{cpp,h}' -- 'Pm4Execution' src/graphics/guest_gpu || test "$?" -eq 1 printf '%s\n' '--- command-buffer submission and span construction ---' rg -n -F --glob '*.{cpp,h}' -- 'ProcessCommands' src/graphics/guest_gpu || test "$?" -eq 1 rg -n -F --glob '*.{cpp,h}' -- 'ProcessCommand' src/graphics/guest_gpu || test "$?" -eq 1 rg -n -F --glob '*.{cpp,h}' -- 'std::span<const uint32_t>' src/graphics/guest_gpu || test "$?" -eq 1 printf '%s\n' '--- parser and length-validation implementation ---' sed -n '1,180p' src/graphics/guest_gpu/pm4.cpp sed -n '120,190p' src/graphics/guest_gpu/command_processor/commandProcessor.h sed -n '620,675p' src/graphics/guest_gpu/graphicsRun.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 15550 --- 🏁 Script executed: ```bash pwd rg -n -F -- 'ProcessPm4(' src/graphics/guest_gpu rg -n -F -- 'Pm4Execution' src/graphics/guest_gpu rg -n -F -- 'PacketSizeDw' src/graphics/guest_gpu ``` Repository: KytyPS5/KytyPS5 Length of output: 1884 --- 🌐 Web query: `KytyPS5 CommandProcessor ProcessPm4 graphicsRun.cpp Pm4Execution` 💡 Result: ``` `CommandProcessor::ProcessPm4(Pm4Execution&)` is the PM4 packet-execution loop in KytyPS5’s `graphicsRun.cpp`. - **Execution state:** `Pm4Execution` keeps a stack of command-buffer cursors (each with a dword offset), plus a pending indirect buffer, chain flag, suspension flag, and progress flag. That state persists when processing is blocked, so execution can resume later. ([github.com](https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/command_processor/commandProcessor.h?utm_source=openai)) - **Per packet:** The loop selects the top cursor, handles end-of-buffer and padding, reads the packet header/opcode, and optionally skips predicated packets. Otherwise it finds the opcode handler in `g_cp_op_func` and invokes it. An unknown opcode logs nearby command words and exits. ([github.com](https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/graphicsRun.cpp)) - **Blocking and indirect buffers:** A handler can suspend execution; the loop returns without advancing past that packet. On the next processing attempt, the same cursor position is retried. If a handler schedules an indirect buffer, the loop either pushes it onto the cursor stack (call) or replaces the current cursor (chain/taken branch). ([github.com](https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/graphicsRun.cpp)) - **Completion:** `Process()` reports `Complete` when the cursor stack is empty; otherwise it reports `Blocked`. ([github.com](https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/graphicsRun.cpp)) These details are from the repository’s `main` branch; the cited source does not pin them to a particular release or commit. ([github.com](https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/graphicsRun.cpp?utm_source=openai)) Citations: - 1: https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/command_processor/commandProcessor.h?utm_source=openai - 2: https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/graphicsRun.cpp - 3: https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/graphicsRun.cpp - 4: https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/graphicsRun.cpp - 5: https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/graphicsRun.cpp?utm_source=openai ``` --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- GuestGpu submission and processing ---' sed -n '96,170p' src/graphics/guest_gpu/graphicsRun.cpp printf '%s\n' '--- Process entry and execution state ---' sed -n '24,52p' src/graphics/guest_gpu/command_processor/commandProcessor.h sed -n '624,678p' src/graphics/guest_gpu/graphicsRun.cpp printf '%s\n' '--- exact changed diff against requested base ---' git diff --unified=25 730e1a3cf39d50c787d477e813e0bef92006a063 222d83016cc9776711c1eebdf3c6c50b512c2fe5 -- src/graphics/guest_gpu/graphicsRun.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 8081 --- </details> **Reject incomplete multi-dword packets before consuming the tail.** `GuestGpu::Submit` and `SubmitCompute` accept one-dword command spans. `CommandProcessor::Process` forwards them without packet-size validation. If the dword is an ordinary PM4 header, the new tail branch consumes it before `EXIT_IF(packet_dw > remaining_dw)` runs. The command is dropped, and processing reports completion. <details> <summary>Suggested fix</summary> ```diff --- "a/src/graphics/guest_gpu/graphicsRun.cpp" +++ "b/src/graphics/guest_gpu/graphicsRun.cpp" @@ -695,11 +695,11 @@ continue; } if (remaining_dw < 2) { - // A single dword is too short for any packet: a type-0/type-3 header with no body, - // or a type-2 NOP carrying a count, which is filler and not a length. Games really do - // leave one word behind the last real packet: consume it and the buffer is done. + EXIT_NOT_IMPLEMENTED((packet_header >> 30u) != 2u && + Pm4::PacketSizeDw(packet_header) != 1u); + // Type-2 filler and the recognized one-dword form can end a command buffer. static std::atomic<uint32_t> tail_log_count {0}; if (tail_log_count.fetch_add(1, std::memory_order_relaxed) < 16) { LOGF("CP: trailing dword 0x%08" PRIx32 " at offset=0x%05" PRIx32 "\n", packet[0], total_dw - remaining_dw); ``` </details> <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:21392296ba4cdf76cccdbd8c --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-11 07:50 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3d89930f-2c0c-4dc6-b8ca-8bfd8f5d0166
📥 Commits

Reviewing files that changed from the base of the PR and between c0ebf22476 and 222d83016c.

📒 Files selected for processing (1)
  • src/graphics/guest_gpu/graphicsRun.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-11 07:50 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1405#pullrequestreview-5482432500) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `3d89930f-2c0c-4dc6-b8ca-8bfd8f5d0166` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between c0ebf224769b146b453e8d61521af345d5e660d5 and 222d83016cc9776711c1eebdf3c6c50b512c2fe5. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/graphics/guest_gpu/graphicsRun.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=623d795a-3b3d-49f5-aee8-15181a2ec9a0 attempt=ac2bd315-4ddd-424f-9654-571234ba350a batch=1/1 -->
Author
Owner

@⁠theantipopau on GitHub · 2026-10-12 11:13 UTC · original

The trade matches the code: graphicsRun.cpp:694 already consumes single-dword packets through PacketSizeDw(header) == 1u and the type-2 NOP/packet-0xC0000000 forms, so a lone trailing word — one that can't even reach the header checks since it has no body — previously hit the bare EXIT_NOT_IMPLEMENTED(remaining_dw < 2) regardless of its value. Your change keeps every real packet's declared-length check (packet_dw > remaining_dw still EXITs) and only converts the header-without-body case into a consume and close, with the capped LOGF. m_made_progress = true is right so the buffer stack unwinds instead of spinning.

One nit, non-blocking: the type-2 filler comment says "a type-2 NOP carrying a count" — on RDNA a type-2 packet is pure filler (0xC0001000-style words carry no count); the word GT7 leaves is 0x00000000, which is neither type-0 nor type-3. Worth rewording when you next touch it, but either way the consume is correct.

**@⁠theantipopau** on GitHub · 2026-10-12 11:13 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1405#issuecomment-6123130421) The trade matches the code: [graphicsRun.cpp:694](https://github.com/KytyPS5/KytyPS5/blob/main/src/graphics/guest_gpu/graphicsRun.cpp) already consumes single-dword packets through `PacketSizeDw(header) == 1u` and the type-2 NOP/packet-0xC0000000 forms, so a *lone trailing word* — one that can't even reach the header checks since it has no body — previously hit the bare `EXIT_NOT_IMPLEMENTED(remaining_dw < 2)` regardless of its value. Your change keeps every real packet's declared-length check (`packet_dw > remaining_dw` still EXITs) and only converts the header-without-body case into a consume and close, with the capped LOGF. `m_made_progress = true` is right so the buffer stack unwinds instead of spinning. One nit, non-blocking: the type-2 filler comment says "a type-2 NOP carrying a count" — on RDNA a type-2 packet is pure filler (`0xC0001000`-style words carry no count); the word GT7 leaves is 0x00000000, which is neither type-0 nor type-3. Worth rewording when you next touch it, but either way the consume is correct.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1405/head:github-bot/gh-1405'
git switch 'github-bot/gh-1405'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1405'
git switch 'github-bot/gh-1405'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1405'
git switch 'github-bot/gh-1405'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1405'
git switch 'main'
git merge --squash 'github-bot/gh-1405'
git switch 'main'
git merge --ff-only 'github-bot/gh-1405'
git switch 'main'
git merge 'github-bot/gh-1405'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.