feat(libSceGnmDriver): add mode-aware init states #18217

Merged
DonRyuzaki merged 3 commits from upstream-pr/18217 into main 2026-11-15 10:52:32 +00:00
DonRyuzaki commented 2026-11-10 21:43:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by DonRyuzaki on 2026-11-10T21:43:27Z.


What

inFAMOUS Second Son's regular GNM import report #17581 includes sceGnmDrawInitDefaultHardwareState350 (yb2cRhagD1I) and sceGnmDrawInitToDefaultContextState400 (im2ZuItabu4). Both currently exist only in the Neo provider, while the title imports the regular libSceGnmDriver.prx.

This adds the two regular exports. They select the base or Neo command packet sequence through sceKernelIsNeoMode, which already derives its answer from title metadata. The Neo arrays are shared with the existing Neo provider; the derived base 350 and 400 sequences were compared word-for-word with pinned shadPS4 source and matched exactly. A new test checks base and Neo title metadata in separate processes, packet boundaries, mode-specific registers and buffer errors.

This fixes two imports, not the rest of #17581 or title execution. Packet contents and null-buffer error are not measured on a PS5; the debt entry records that limit. Actual open patches in #16882, #17711, #17942, #6977, #17393 and #17396 were checked for these two regular exports; none owns them.

Tested

Merged upstream main 00cb2314f490fea6e113bf9a2773867a60ee4771; exact validated head 610b60ec08fb66f19423e7fa245109ce9603be73, tree 8d92278bbf16648ea0798d36bc8b38afeb5b440a.

  • The manual source resolution retains upstream's regular 200-state export and test alongside this PR's distinct regular 350/400-state exports and mode-aware test. The merged declarations and implementations each occur once; the existing debt entries are retained.
  • Ubuntu 24.04 under WSL2, GCC 13.3, CMake/Ninja Release, bundled dependencies, BUILD_TESTING=ON, eight compiler jobs. The complete libs runtime target and the named focused test executables built on this exact tree. Third-party submodule pins are unchanged from the build cache.
  • public_headers, guest_gnm_driver_init_modes, gnm_default_state_200, guest_gnm_driver, and guest_gnm_neo_default_state each passed three consecutive CTest runs: 15/15 executions across 5 test names, zero skips, 84.61 seconds combined CTest wall time. Used ctest --no-tests=error --output-on-failure --repeat until-fail:3 with the exact-name filter.
  • Literal git diff --check and tools/check_conventions.py against the pinned main and this PR's title/body pass. A merge preview against later main ab6ef0b5629d5f0412217dcceea6deac7b8b0b01 passed before push.
  • The original implementation's link-failing negative control and source sequence comparison apply to their stated older head. No current-head Windows/macOS, game, console, or validation-layer GPU execution is claimed. The title import report is external evidence, not a new game test. The full project CTest suite was not run.

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
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: CUSA00223 #17581 (these two imports only)
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5249418701 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18217). Originally posted by [DonRyuzaki](https://github.com/DonRyuzaki) on 2026-11-10T21:43:27Z. --- ### What inFAMOUS Second Son's [regular GNM import report #17581](https://github.com/boykopovar/AnyPS5/issues/17581) includes sceGnmDrawInitDefaultHardwareState350 (yb2cRhagD1I) and sceGnmDrawInitToDefaultContextState400 (im2ZuItabu4). Both currently exist only in the Neo provider, while the title imports the regular libSceGnmDriver.prx. This adds the two regular exports. They select the base or Neo command packet sequence through sceKernelIsNeoMode, which already derives its answer from title metadata. The Neo arrays are shared with the existing Neo provider; the derived base 350 and 400 sequences were compared word-for-word with [pinned shadPS4 source](https://github.com/shadps4-emu/shadPS4/blob/a808e7626e3c7de8d0f0fda6a91f620b42f6c762/src/core/libraries/gnmdriver/gnmdriver.cpp) and matched exactly. A new test checks base and Neo title metadata in separate processes, packet boundaries, mode-specific registers and buffer errors. This fixes two imports, not the rest of #17581 or title execution. Packet contents and null-buffer error are not measured on a PS5; the debt entry records that limit. Actual open patches in #16882, #17711, #17942, #6977, #17393 and #17396 were checked for these two regular exports; none owns them. ### Tested Merged upstream main `00cb2314f490fea6e113bf9a2773867a60ee4771`; exact validated head `610b60ec08fb66f19423e7fa245109ce9603be73`, tree `8d92278bbf16648ea0798d36bc8b38afeb5b440a`. - The manual source resolution retains upstream's regular 200-state export and test alongside this PR's distinct regular 350/400-state exports and mode-aware test. The merged declarations and implementations each occur once; the existing debt entries are retained. - Ubuntu 24.04 under WSL2, GCC 13.3, CMake/Ninja Release, bundled dependencies, `BUILD_TESTING=ON`, eight compiler jobs. The complete `libs` runtime target and the named focused test executables built on this exact tree. Third-party submodule pins are unchanged from the build cache. - `public_headers`, `guest_gnm_driver_init_modes`, `gnm_default_state_200`, `guest_gnm_driver`, and `guest_gnm_neo_default_state` each passed three consecutive CTest runs: **15/15 executions across 5 test names**, zero skips, 84.61 seconds combined CTest wall time. Used `ctest --no-tests=error --output-on-failure --repeat until-fail:3` with the exact-name filter. - Literal `git diff --check` and `tools/check_conventions.py` against the pinned main and this PR's title/body pass. A merge preview against later main `ab6ef0b5629d5f0412217dcceea6deac7b8b0b01` passed before push. - The original implementation's link-failing negative control and source sequence comparison apply to their stated older head. No current-head Windows/macOS, game, console, or validation-layer GPU execution is claimed. The title import report is external evidence, not a new game test. The full project CTest suite was not run. ### 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 - [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 - [x] Unblocks: CUSA00223 #17581 (these two imports only) - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-12 21:04:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-12T21:04:10Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

The new test for sceGnmDrawInitToDefaultContextState400 cannot pass as written: it walks packet boundaries over all 256 words, but the function writes only 98 (base) or 102 (Neo) words.

Changes are required before merge: fix the packet-boundary check in core/libs/prx/libSceGnmDriver/tests/InitModes.cpp:106 so it covers only the words the function writes.

What I ran

  • Head reviewed: 8bd393e782b1322b89afc80f8436dfaf21f169a1, base main.
  • This was a read-only review. I did not build or run the tests.
  • Repository reads through the reader:
python3 repo_read.py search "ContextState400" core/libs/prx
python3 repo_read.py search "HwInitPacketWords" core/libs/prx/libSceGnmDriver
python3 repo_read.py search "WriteContextState" core/libs/prx/libSceGnmDriverForNeoMode/Export.cpp
python3 repo_read.py cat core/libs/prx/libSceGnmDriver/Export.cpp 440 456
python3 repo_read.py cat core/libs/prx/libSceGnmDriverForNeoMode/include/InitSequences.hpp 81 84
python3 repo_read.py cat core/libs/prx/libSceGnmDriverForNeoMode/Export.cpp 33 46
  • Read in full: the diff of all five changed files.
  • Read at head: the functions the diff touches (Export.cpp 440–456, the Neo WriteContextState, the start of the Neo ContextState400 array).
  • Not read in full: the five files at head, and the rest of InitSequences.hpp.

Results

Check Result Note
Test logic against production code failed Read only; see Blocking
Build and run the new test here not run Read-only run
Author's reported runs on this head not verified Conflicts with the code; see Not verified
Derived sequences against shadPS4 not run No network access in this run

Findings

Blocking

  • core/libs/prx/libSceGnmDriver/tests/InitModes.cpp:106: the 400 test calls WholePackets(words) over the whole 256-word buffer. The function writes only 98 words in base mode and 102 in Neo mode (Export.cpp:453, and the Neo array has 102 entries). The rest of the buffer keeps the 0xdeadbeef fill. That value decodes as a packet with a count of 0x1ead, so the walk runs past the end, WholePackets returns false, and the test throws "400 packets are invalid" in both modes. The test therefore fails by its own logic, whatever the sequences contain.
    • Smallest fix: pass the written length into WholePackets (98 for base, 102 for Neo) and check that prefix only. The prefix checks at lines 102–105 already assume this layout.

Non-blocking

  • core/libs/prx/libSceGnmDriver/Export.cpp:453: the 400 writer returns 256 while it writes only 98 or 102 words. This matches the Neo provider's WriteContextState (core/libs/prx/libSceGnmDriverForNeoMode/Export.cpp:33-38), so it is consistent, but the unwritten tail of the caller's buffer is left as it was. Worth a sentence in the debt entry if that is the intended contract.

Sources

Not verified

  • The author's reported runs on 8bd393e (9/9 and 12/12 passes, the PRX hash, the hosted Windows job). I did not repeat them, and the code reading above says the 400 check cannot pass. Only a fresh run settles which is right.
  • Whether the base 350 sequence and the base 400 prefix match shadPS4. The comparison was not run here.
  • Whether sceKernelIsNeoMode reads the param.sfo fixture from the working directory, which the test's child process depends on.
  • Packet contents and the null-buffer error on a PS5, as the description already states.

To get this to a good state

  • Make the 400 packet check cover only the written words (98 base, 102 Neo), then push the new head.
  • Rerun guest_gnm_driver_init_modes on the new head and post the unedited output.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5881983639 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18217#pullrequestreview-5881983639). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-12T21:04:10Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested The new test for `sceGnmDrawInitToDefaultContextState400` cannot pass as written: it walks packet boundaries over all 256 words, but the function writes only 98 (base) or 102 (Neo) words. Changes are required before merge: fix the packet-boundary check in `core/libs/prx/libSceGnmDriver/tests/InitModes.cpp:106` so it covers only the words the function writes. ## What I ran - Head reviewed: `8bd393e782b1322b89afc80f8436dfaf21f169a1`, base `main`. - This was a read-only review. I did not build or run the tests. - Repository reads through the reader: ``` python3 repo_read.py search "ContextState400" core/libs/prx python3 repo_read.py search "HwInitPacketWords" core/libs/prx/libSceGnmDriver python3 repo_read.py search "WriteContextState" core/libs/prx/libSceGnmDriverForNeoMode/Export.cpp python3 repo_read.py cat core/libs/prx/libSceGnmDriver/Export.cpp 440 456 python3 repo_read.py cat core/libs/prx/libSceGnmDriverForNeoMode/include/InitSequences.hpp 81 84 python3 repo_read.py cat core/libs/prx/libSceGnmDriverForNeoMode/Export.cpp 33 46 ``` - Read in full: the diff of all five changed files. - Read at head: the functions the diff touches (`Export.cpp` 440–456, the Neo `WriteContextState`, the start of the Neo `ContextState400` array). - Not read in full: the five files at head, and the rest of `InitSequences.hpp`. ## Results | Check | Result | Note | |---|---|---| | Test logic against production code | failed | Read only; see Blocking | | Build and run the new test here | not run | Read-only run | | Author's reported runs on this head | not verified | Conflicts with the code; see Not verified | | Derived sequences against shadPS4 | not run | No network access in this run | ## Findings ### Blocking - `core/libs/prx/libSceGnmDriver/tests/InitModes.cpp:106`: the 400 test calls `WholePackets(words)` over the whole 256-word buffer. The function writes only 98 words in base mode and 102 in Neo mode (`Export.cpp:453`, and the Neo array has 102 entries). The rest of the buffer keeps the `0xdeadbeef` fill. That value decodes as a packet with a count of `0x1ead`, so the walk runs past the end, `WholePackets` returns false, and the test throws "400 packets are invalid" in both modes. The test therefore fails by its own logic, whatever the sequences contain. - Smallest fix: pass the written length into `WholePackets` (98 for base, 102 for Neo) and check that prefix only. The prefix checks at lines 102–105 already assume this layout. ### Non-blocking - `core/libs/prx/libSceGnmDriver/Export.cpp:453`: the 400 writer returns 256 while it writes only 98 or 102 words. This matches the Neo provider's `WriteContextState` (`core/libs/prx/libSceGnmDriverForNeoMode/Export.cpp:33-38`), so it is consistent, but the unwritten tail of the caller's buffer is left as it was. Worth a sentence in the debt entry if that is the intended contract. ## Sources - Test line: https://github.com/boykopovar/AnyPS5/blob/8bd393e782b1322b89afc80f8436dfaf21f169a1/core/libs/prx/libSceGnmDriver/tests/InitModes.cpp#L106 - Writer: https://github.com/boykopovar/AnyPS5/blob/8bd393e782b1322b89afc80f8436dfaf21f169a1/core/libs/prx/libSceGnmDriver/Export.cpp#L449-L455 ## Not verified - The author's reported runs on `8bd393e` (9/9 and 12/12 passes, the PRX hash, the hosted Windows job). I did not repeat them, and the code reading above says the 400 check cannot pass. Only a fresh run settles which is right. - Whether the base 350 sequence and the base 400 prefix match shadPS4. The comparison was not run here. - Whether `sceKernelIsNeoMode` reads the `param.sfo` fixture from the working directory, which the test's child process depends on. - Packet contents and the null-buffer error on a PS5, as the description already states. ## To get this to a good state - Make the 400 packet check cover only the written words (98 base, 102 Neo), then push the new head. - Rerun `guest_gnm_driver_init_modes` on the new head and post the unedited output.
MarcZX10 commented 2026-11-14 03:02:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T03:02:22Z.

Review: APPROVED


Reviewed — looks good

The changed packet writers and mode selection are consistent with the inspected sequences and buffer handling; the author reports focused builds and tests, which I did not run.

What I ran

Reviewed head 599084acf8fc3bbc0e16a5c9e12efb1c60c0f736 from the prepared bundle. No build or tests were run in this review. The PR description reports successful Linux builds and 12/12 focused test executions.

Results

Check Result Note
Source review passed All five changed files read
Build and tests not run Author-reported results only

Findings

Blocking

None.

Non-blocking

None.

Not verified

No build or test was run independently. Console, game, GPU, Windows runtime, and full-suite behavior were not verified. review/files.json was not supplied; the manifest lists five changed files and marks each as included, and all five were read. No files were excluded in the manifest excerpt reviewed.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5901126286 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18217#pullrequestreview-5901126286). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T03:02:22Z. **Review:** APPROVED --- # Reviewed — looks good The changed packet writers and mode selection are consistent with the inspected sequences and buffer handling; the author reports focused builds and tests, which I did not run. ## What I ran Reviewed head `599084acf8fc3bbc0e16a5c9e12efb1c60c0f736` from the prepared bundle. No build or tests were run in this review. The PR description reports successful Linux builds and 12/12 focused test executions. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | All five changed files read | | Build and tests | not run | Author-reported results only | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No build or test was run independently. Console, game, GPU, Windows runtime, and full-suite behavior were not verified. `review/files.json` was not supplied; the manifest lists five changed files and marks each as included, and all five were read. No files were excluded in the manifest excerpt reviewed. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-14 19:22:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T19:22:53Z.

Review: APPROVED


Reviewed — looks good

The change adds the two regular GNM exports with base/Neo packet selection and focused tests; I found no blocking defect in the changed code I read.

What I ran

Reviewed head 610b60ec08fb66f19423e7fa245109ce9603be73 using repo_read.py to inspect the prepared diff and repository files. I ran no build or tests; the test runs described in the PR are author-reported.

Results

Check Result Note
Changed code review passed Five changed files read
Build and tests not run Results in the description are author-reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

No commands, builds, or tests were run. Console behavior and the packet sequences were not independently verified. All changed files listed in the manifest were read: core/libs/prx/libSceGnmDriver/CMakeLists.txt, core/libs/prx/libSceGnmDriver/Export.cpp, core/libs/prx/libSceGnmDriver/include/Api.hpp, core/libs/prx/libSceGnmDriver/tests/InitModes.cpp, and docs/dev/debt/libSceGnmDriver.md. No changed files were excluded.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5906691829 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18217#pullrequestreview-5906691829). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T19:22:53Z. **Review:** APPROVED --- # Reviewed — looks good The change adds the two regular GNM exports with base/Neo packet selection and focused tests; I found no blocking defect in the changed code I read. ## What I ran Reviewed head `610b60ec08fb66f19423e7fa245109ce9603be73` using `repo_read.py` to inspect the prepared diff and repository files. I ran no build or tests; the test runs described in the PR are author-reported. ## Results | Check | Result | Note | |---|---|---| | Changed code review | passed | Five changed files read | | Build and tests | not run | Results in the description are author-reported | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No commands, builds, or tests were run. Console behavior and the packet sequences were not independently verified. All changed files listed in the manifest were read: `core/libs/prx/libSceGnmDriver/CMakeLists.txt`, `core/libs/prx/libSceGnmDriver/Export.cpp`, `core/libs/prx/libSceGnmDriver/include/Api.hpp`, `core/libs/prx/libSceGnmDriver/tests/InitModes.cpp`, and `docs/dev/debt/libSceGnmDriver.md`. No changed files were excluded. ## To get this to a good state Nothing is required.
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!18217
No description provided.