fix(libSceVideodec2): mark returned pictures as not discarded #10913

Merged
thuanquang merged 1 commit from upstream-pr/10913 into main 2026-10-26 21:56:04 +00:00
thuanquang commented 2026-10-25 09:41:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-25T09:41:10Z.


What

SceVideodec2::OutputInfo had no member at offset 0xb, so sceVideodec2Decode and sceVideodec2Flush never wrote that byte, and a caller saw whatever it had left there. This PR names the byte isDiscardedFrame and sets it to 0 when a picture is returned; a result without a picture and a refused access unit leave it as the caller set it. A static_assert pins the layout (size 0x38, the flag at 0xb, codecType at 0xc, frameBuffer at 0x20).

Sources for the field:

  • A review on this PR read firmware 13.42's libSceVideodec2.sprx (https://github.com/boykopovar/AnyPS5/pull/10913#issuecomment-6397761452): Decode and Flush write the byte only where a picture is returned, from a flag in the decoder core's result, and leave it untouched in a result without a picture and for a refused access unit. This PR follows that. The core's flag itself is not modelled: AnyPS5 returns no picture for a VP9 frame that is not shown, so a returned picture has 0.
  • SharpProspero declares it as IsDiscardedFrame at this offset (Videodec2.cs#L150-L192).
  • KytyPS5 declares is_discarded_frame there and writes false in every Decode and Flush result that passes its argument checks, with or without a picture (libVideoDec2.cpp#L91-L483).
  • shadPS4 leaves the byte as padding (videodec2.h#L68-L82).
  • PPSA05110 sets only thisSize in the output it passes to its VP9 Decode call (0x13728dd) and to Flush (0x1371f7e), and takes a picture only when isValid is set and this byte is 0; otherwise it drops the picture. Read from disassembly, not measured on a console.

Not measured by us: the firmware behaviour above comes from that review, not from a console run or our own reading; when the decoder core sets the flag is not modelled. The debt entry records this.

Where it stops on main

PPSA05110 (own dump), on unmodified main 48c160c58b (2026-10-27; #10887 and #10614 are merged, so nothing local is needed any more): after New Game, about 430 s into a run from a system save, the opening movie's second VP9 decoder starts and the title stops with

FATAL: unhandled exception 0xc0000094 on thread 18640 ''
  rip 0x0000000001737e1a eboot.exe+0x1347e1a

The same stop was first seen on main 61fc572cee plus a local build of #10887's declarations and #10614.

(integer divide by zero in the title's code). A local hook (not part of this PR) logged byte 0xb as each Decode or Flush call arrived, before AnyPS5 writes the output, which is what main hands back: 2143 of the first 2400 pictures came with it nonzero (every logged value was 0x62; an earlier run had 0x5e). They span the title's two movies so far; the decoder of the movie at the stop was created before picture 300, so at least 1874 of them came after it. The title drops those pictures, so its movie player has no displayed frame and divides by that frame's time unit, which is still 0.

Tested

  • Windows 11 26200, WinLibs GCC 15.2.0, Release, on main 57f506f811.
  • New testDiscardedFrameFlag in guest_videodec2: it fills the output with 0xFF, as a caller's old stack bytes would, refuses an empty access unit, and decodes a VP9 and an H.264 stream through Decode and Flush. A returned picture must have the byte at 0; a result without a picture and the refused access unit must leave it at 0xFF. On main's library it fails 3/3 with a returned picture is marked as discarded; with this change it passes 3/3.
  • guest_videodec2, guest_videodec2_unimplemented, guest_vdecsw, guest_videodec: 4/4 pass, three times.
  • PPSA05110 (own dump), RX 6700 XT, same stack plus this change and the logging hook (shared GPU): the opening movie plays to its end with its subtitles, then the first gameplay scene starts; no stop in a 900 s run. That run used the first version of this PR, which also cleared the byte in results without a picture; the title reads the byte only together with isValid, so that difference does not reach it.
  • Linux, by wachi35676 on WSL Ubuntu 24.04 with GCC 13.3, this head merged onto main aeff26bd9 (comment): guest_videodec2, guest_videodec2_unimplemented and guest_videodec pass 3 of 3 with 0 warnings; with Export.cpp and include/Api.hpp from main, guest_videodec2 fails. macOS was not built.

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 (not applicable)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: PPSA05110 #10872
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5003586225 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10913). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-25T09:41:10Z. --- ### What `SceVideodec2::OutputInfo` had no member at offset 0xb, so `sceVideodec2Decode` and `sceVideodec2Flush` never wrote that byte, and a caller saw whatever it had left there. This PR names the byte `isDiscardedFrame` and sets it to 0 when a picture is returned; a result without a picture and a refused access unit leave it as the caller set it. A `static_assert` pins the layout (size 0x38, the flag at 0xb, `codecType` at 0xc, `frameBuffer` at 0x20). Sources for the field: - A review on this PR read firmware 13.42's `libSceVideodec2.sprx` (https://github.com/boykopovar/AnyPS5/pull/10913#issuecomment-6397761452): Decode and Flush write the byte only where a picture is returned, from a flag in the decoder core's result, and leave it untouched in a result without a picture and for a refused access unit. This PR follows that. The core's flag itself is not modelled: AnyPS5 returns no picture for a VP9 frame that is not shown, so a returned picture has 0. - SharpProspero declares it as `IsDiscardedFrame` at this offset ([Videodec2.cs#L150-L192](https://github.com/SvenGDK/SharpProspero/blob/5dfdb4b0b166e83dc9ae275001afb695f12c7174/src/SharpProspero/Interop/Video/Videodec2.cs#L150-L192)). - KytyPS5 declares `is_discarded_frame` there and writes `false` in every Decode and Flush result that passes its argument checks, with or without a picture ([libVideoDec2.cpp#L91-L483](https://github.com/KytyPS5/KytyPS5/blob/83f8bfd3c9c35fcb135ef6c33dfd88bbfe066ee2/src/libs/libVideoDec2.cpp#L91-L483)). - shadPS4 leaves the byte as padding ([videodec2.h#L68-L82](https://github.com/shadps4-emu/shadPS4/blob/e0845a12dc05f2fde85e7b203c76de03f93a585d/src/core/libraries/videodec/videodec2.h#L68-L82)). - PPSA05110 sets only `thisSize` in the output it passes to its VP9 Decode call (0x13728dd) and to Flush (0x1371f7e), and takes a picture only when `isValid` is set and this byte is 0; otherwise it drops the picture. Read from disassembly, not measured on a console. Not measured by us: the firmware behaviour above comes from that review, not from a console run or our own reading; when the decoder core sets the flag is not modelled. The debt entry records this. ### Where it stops on `main` PPSA05110 (own dump), on unmodified `main` `48c160c58b` (2026-10-27; #10887 and #10614 are merged, so nothing local is needed any more): after New Game, about 430 s into a run from a system save, the opening movie's second VP9 decoder starts and the title stops with ``` FATAL: unhandled exception 0xc0000094 on thread 18640 '' rip 0x0000000001737e1a eboot.exe+0x1347e1a ``` The same stop was first seen on `main` `61fc572cee` plus a local build of #10887's declarations and #10614. (integer divide by zero in the title's code). A local hook (not part of this PR) logged byte 0xb as each Decode or Flush call arrived, before AnyPS5 writes the output, which is what `main` hands back: 2143 of the first 2400 pictures came with it nonzero (every logged value was 0x62; an earlier run had 0x5e). They span the title's two movies so far; the decoder of the movie at the stop was created before picture 300, so at least 1874 of them came after it. The title drops those pictures, so its movie player has no displayed frame and divides by that frame's time unit, which is still 0. ### Tested - Windows 11 26200, WinLibs GCC 15.2.0, Release, on `main` `57f506f811`. - New `testDiscardedFrameFlag` in `guest_videodec2`: it fills the output with 0xFF, as a caller's old stack bytes would, refuses an empty access unit, and decodes a VP9 and an H.264 stream through Decode and Flush. A returned picture must have the byte at 0; a result without a picture and the refused access unit must leave it at 0xFF. On `main`'s library it fails 3/3 with `a returned picture is marked as discarded`; with this change it passes 3/3. - `guest_videodec2`, `guest_videodec2_unimplemented`, `guest_vdecsw`, `guest_videodec`: 4/4 pass, three times. - PPSA05110 (own dump), RX 6700 XT, same stack plus this change and the logging hook (shared GPU): the opening movie plays to its end with its subtitles, then the first gameplay scene starts; no stop in a 900 s run. That run used the first version of this PR, which also cleared the byte in results without a picture; the title reads the byte only together with `isValid`, so that difference does not reach it. - Linux, by wachi35676 on WSL Ubuntu 24.04 with GCC 13.3, this head merged onto `main` `aeff26bd9` ([comment](https://github.com/boykopovar/AnyPS5/pull/10913#issuecomment-6403099884)): `guest_videodec2`, `guest_videodec2_unimplemented` and `guest_videodec` pass 3 of 3 with 0 warnings; with `Export.cpp` and `include/Api.hpp` from `main`, `guest_videodec2` fails. macOS was not built. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 (not applicable) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: PPSA05110 #10872 - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-25 09:49:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T09:49:25Z.

Review: APPROVED


Reviewed exact head d39564ff0efbbc4a87bd15c408f298250a001188.

The output layout is pinned with offsets matching the candidate field declaration. ClearOutput resets isDiscardedFrame for a successful Decode/Flush result, and the refused empty-access-unit return explicitly calls ClearOutput before returning its error code. Invalid pointer/handle paths throw rather than returning an output structure. The new regression initializes the output bytes to 0xff and checks the flag after a refused access unit, valid decoded pictures, and flush output; it exercises both VP9 and H.264. The PR also records the remaining console uncertainty in technical debt rather than claiming that all discarded-frame semantics are known.

The author reports that the focused regression failed 3/3 on main and passed 3/3 with this change; four neighboring videodec tests passed three times, and their PPSA05110 run completed the opening movie and entered gameplay. GitHub eligibility, intake, labels, conventions, and report checks pass; platform product jobs are skipped by path policy. Local git diff --check and tools/check_conventions.py --base upstream/main --head upstream/pr-10913 pass. I did not independently run the decoder tests or title.

No blocking issue found in the scoped output-flag correction.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5642595430 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10913#pullrequestreview-5642595430). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T09:49:25Z. **Review:** APPROVED --- Reviewed exact head `d39564ff0efbbc4a87bd15c408f298250a001188`. The output layout is pinned with offsets matching the candidate field declaration. `ClearOutput` resets `isDiscardedFrame` for a successful Decode/Flush result, and the refused empty-access-unit return explicitly calls `ClearOutput` before returning its error code. Invalid pointer/handle paths throw rather than returning an output structure. The new regression initializes the output bytes to `0xff` and checks the flag after a refused access unit, valid decoded pictures, and flush output; it exercises both VP9 and H.264. The PR also records the remaining console uncertainty in technical debt rather than claiming that all discarded-frame semantics are known. The author reports that the focused regression failed 3/3 on main and passed 3/3 with this change; four neighboring videodec tests passed three times, and their PPSA05110 run completed the opening movie and entered gameplay. GitHub eligibility, intake, labels, conventions, and report checks pass; platform product jobs are skipped by path policy. Local `git diff --check` and `tools/check_conventions.py --base upstream/main --head upstream/pr-10913` pass. I did not independently run the decoder tests or title. No blocking issue found in the scoped output-flag correction. AI-assisted: yes.
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!10913
No description provided.