feat(videoout): apply the output gamma from sceVideoOutAdjustColor #4040

Closed
ee6aba54 wants to merge 1 commit from upstream-pr/4040 into main
ee6aba54 commented 2026-10-11 21:57:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-11T21:57:52Z.


What

sceVideoOutAdjustColor stored the gamma of the color settings, but presentation ignored it. PPSA18391 (engine: Clickteam Fusion) sets a gamma of 2.0 and looks washed out without it.

VideoOut now passes the gamma to the driver (AgcDriverSetOutputGamma_nid_postfix). When it is not 1, presentation copies the finished swapchain image into an RGBA8 storage image, applies out = in ^ gamma to the color channels in a compute pass (OutputGamma.comp) and copies the result back. Swapchain images are created as transfer sources when the surface allows it. Frame dumps (APS5_DUMP_FRAMES) apply the same gamma, so they match the presented image. The console's transfer curve and value range are unverified on hardware; the TechnicalDebt entry for sceVideoOutAdjustColor says so.

Tested

  • Ubuntu 24.04, Linux 7.0, GCC 13.3, Release, rebased onto 18c438b10. agc_driver_graphics gains outputGammaTests: gamma 1 leaves the image unchanged, gamma 2 maps 128 to 64, 51 to 10 and 204 to 163 and keeps alpha. agc_driver_graphics and the video_out tests pass on the rebased branch; the full ctest run (992 tests) was on the previous base 5efd09afc.
  • PPSA18391: with gamma 2.0 applied, the title screen matches a recording from the console; checked by hand on an earlier base.
  • Windows not built or tested.

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 in TechnicalDebt
  • 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: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4822676240 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4040). Originally posted by [ee6aba54](https://github.com/ee6aba54) on 2026-10-11T21:57:52Z. --- ### What `sceVideoOutAdjustColor` stored the gamma of the color settings, but presentation ignored it. PPSA18391 (engine: Clickteam Fusion) sets a gamma of 2.0 and looks washed out without it. VideoOut now passes the gamma to the driver (`AgcDriverSetOutputGamma_nid_postfix`). When it is not 1, presentation copies the finished swapchain image into an RGBA8 storage image, applies `out = in ^ gamma` to the color channels in a compute pass (`OutputGamma.comp`) and copies the result back. Swapchain images are created as transfer sources when the surface allows it. Frame dumps (`APS5_DUMP_FRAMES`) apply the same gamma, so they match the presented image. The console's transfer curve and value range are unverified on hardware; the TechnicalDebt entry for `sceVideoOutAdjustColor` says so. ### Tested - Ubuntu 24.04, Linux 7.0, GCC 13.3, Release, rebased onto `18c438b10`. `agc_driver_graphics` gains `outputGammaTests`: gamma 1 leaves the image unchanged, gamma 2 maps 128 to 64, 51 to 10 and 204 to 163 and keeps alpha. `agc_driver_graphics` and the `video_out` tests pass on the rebased branch; the full `ctest` run (992 tests) was on the previous base `5efd09afc`. - PPSA18391: with gamma 2.0 applied, the title screen matches a recording from the console; checked by hand on an earlier base. - Windows not built or tested. ### 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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
kr4y4 commented 2026-10-13 03:34:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-13T03:34:44Z.


A Windows build and run, since the description says Windows wasn't built or tested.

Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. The head 4b0d7224a merged into main 495bf91a0, which passes 1023 of 1023 on both GPUs.

  • It builds, libs included.
  • agc_driver_graphics (with outputGammaTests) passes on both GPUs with --repeat until-fail:3. The full suite (ctest --timeout 120 --parallel 4) passes 1023 of 1023 on both.
  • No negative control: with the production files as on main, the test doesn't link, because AgcDriver::ApplyOutputGamma is new.

Not run: a title.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6137615620 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4040#issuecomment-6137615620). Originally posted by [kr4y4](https://github.com/kr4y4) on 2026-10-13T03:34:44Z. --- A Windows build and run, since the description says Windows wasn't built or tested. Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. The head 4b0d7224a merged into `main` 495bf91a0, which passes 1023 of 1023 on both GPUs. - It builds, `libs` included. - `agc_driver_graphics` (with `outputGammaTests`) passes on both GPUs with `--repeat until-fail:3`. The full suite (`ctest --timeout 120 --parallel 4`) passes 1023 of 1023 on both. - No negative control: with the production files as on `main`, the test doesn't link, because `AgcDriver::ApplyOutputGamma` is new. Not run: a title. Written with AI assistance.
adriadam10 commented 2026-10-13 10:33:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T10:33:41Z.

Review: CHANGES_REQUESTED


Thanks for the PR, and for the Windows run by @kr4y4. Findings:

  • core/libs/prx/libSceVideoOut/src/Output.cpp:313: settings->gamma goes to the driver unchecked. sceVideoOutColorSettingsSetGamma (same file) only accepts finite values in 0.1–2.0; an uninitialised or hand-built struct with 0, a negative value or NaN reaches pow in OutputGamma.comp (all-white or NaN output). Validate it here, with the same range, and say in TechnicalDebt that the range is inferred.
  • core/libs/prx/libSceAgcDriver/tests/Graphics.cpp:403 (outputGammaTests) only exercises ApplyOutputGamma, the CPU table used for frame dumps. What is presented is PresentationGamma::Record + OutputGamma.comp, which uses pow on the GPU and no 8-bit rounding table, so the two can differ and nothing pins the real path. Add a test that runs Record on a small image (gamma 1 unchanged, gamma 2 on 51/128/204, alpha kept, a size that is not a multiple of 8) and compares with ApplyOutputGamma.
  • The transfer curve: in^gamma is the only evidence from a hand check against a recording, which we can't reproduce. shadPS4's post_process.frag applies a different curve (pow(rgb, 1/(2.4 + 1 - gamma)) with a linear segment), and KytyPS5 only stores the value. Please attach the evidence (the recording frame vs. a dump with the PR, or the console measurement) in the PR, and note in TechnicalDebt that the curve differs from shadPS4's.
  • The eligibility check failure is an infra error (proxy fetch), not caused by this PR.

Happy to look again once these are addressed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5502217478 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4040#pullrequestreview-5502217478). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-13T10:33:41Z. **Review:** CHANGES_REQUESTED --- Thanks for the PR, and for the Windows run by @kr4y4. Findings: - `core/libs/prx/libSceVideoOut/src/Output.cpp:313`: `settings->gamma` goes to the driver unchecked. `sceVideoOutColorSettingsSetGamma` (same file) only accepts finite values in 0.1–2.0; an uninitialised or hand-built struct with 0, a negative value or NaN reaches `pow` in `OutputGamma.comp` (all-white or NaN output). Validate it here, with the same range, and say in TechnicalDebt that the range is inferred. - `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp:403` (`outputGammaTests`) only exercises `ApplyOutputGamma`, the CPU table used for frame dumps. What is presented is `PresentationGamma::Record` + `OutputGamma.comp`, which uses `pow` on the GPU and no 8-bit rounding table, so the two can differ and nothing pins the real path. Add a test that runs `Record` on a small image (gamma 1 unchanged, gamma 2 on 51/128/204, alpha kept, a size that is not a multiple of 8) and compares with `ApplyOutputGamma`. - The transfer curve: `in^gamma` is the only evidence from a hand check against a recording, which we can't reproduce. shadPS4's `post_process.frag` applies a different curve (`pow(rgb, 1/(2.4 + 1 - gamma))` with a linear segment), and KytyPS5 only stores the value. Please attach the evidence (the recording frame vs. a dump with the PR, or the console measurement) in the PR, and note in TechnicalDebt that the curve differs from shadPS4's. - The `eligibility` check failure is an infra error (proxy fetch), not caused by this PR. Happy to look again once these are addressed.
ee6aba54 commented 2026-10-13 19:14:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ee6aba54 on 2026-10-13T19:14:05Z.


Rebased onto 18c438b10: 366c6e414. The only conflict was PostCompile.cmake, where the test targets now link the library; PresentationGamma.cpp and the OutputGamma shader header are added to libSceAgcDriver and agc_driver_visual_test only. No change to the code of this PR; the review points above are still open and will come in a separate update.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6153213196 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4040#issuecomment-6153213196). Originally posted by [ee6aba54](https://github.com/ee6aba54) on 2026-10-13T19:14:05Z. --- Rebased onto `18c438b10`: `366c6e414`. The only conflict was `PostCompile.cmake`, where the test targets now link the library; `PresentationGamma.cpp` and the `OutputGamma` shader header are added to `libSceAgcDriver` and `agc_driver_visual_test` only. No change to the code of this PR; the review points above are still open and will come in a separate update.
adriadam10 commented 2026-10-14 10:34:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T10:34:34Z.

Review: CHANGES_REQUESTED


Thanks for the rebase. It leaves the code unchanged, so the three points from the earlier review are still open:

  • core/libs/prx/libSceVideoOut/src/Output.cpp:313: validate settings->gamma with the same finite 0.1–2.0 range as sceVideoOutColorSettingsSetGamma before it reaches pow in OutputGamma.comp, and note in TechnicalDebt that the range is inferred.
  • core/libs/prx/libSceAgcDriver/tests/Graphics.cpp:404: outputGammaTests only covers ApplyOutputGamma (frame dumps); a test of PresentationGamma::Record on a small image (width not a multiple of 8) compared with it is still missing.
  • The curve: please attach the evidence for in^gamma (recording frame vs. a dump with this PR, or a console measurement) and note in TechnicalDebt that shadPS4 uses a different curve.

The branch also conflicts with main in VulkanDevice.cpp. Since you mentioned an update is coming, I'm leaving the code to you; I'll look again then.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5516588916 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4040#pullrequestreview-5516588916). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T10:34:34Z. **Review:** CHANGES_REQUESTED --- Thanks for the rebase. It leaves the code unchanged, so the three points from the earlier review are still open: - `core/libs/prx/libSceVideoOut/src/Output.cpp:313`: validate `settings->gamma` with the same finite 0.1–2.0 range as `sceVideoOutColorSettingsSetGamma` before it reaches `pow` in `OutputGamma.comp`, and note in TechnicalDebt that the range is inferred. - `core/libs/prx/libSceAgcDriver/tests/Graphics.cpp:404`: `outputGammaTests` only covers `ApplyOutputGamma` (frame dumps); a test of `PresentationGamma::Record` on a small image (width not a multiple of 8) compared with it is still missing. - The curve: please attach the evidence for `in^gamma` (recording frame vs. a dump with this PR, or a console measurement) and note in TechnicalDebt that shadPS4 uses a different curve. The branch also conflicts with `main` in `VulkanDevice.cpp`. Since you mentioned an update is coming, I'm leaving the code to you; I'll look again then.
MarcZX10 commented 2026-11-23 03:11:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T03:11:37Z.

Review: COMMENTED


Reviewed — no blocking findings

Nothing blocks this change; the implementation is coherent in the inspected code, with one compatibility concern to consider.

What I ran

Reviewed head 366c6e4148c0b6267898fda5982b0b75094dc822 using the prepared review bundle and repo_read.py for targeted source context. No build or tests were run. The author reports test results in description.md; they were not independently verified.

Results

Check Result Note
Patch and source review passed Reviewed all 10 changed files
Build and tests not run Author-reported results only
Hardware behavior not run Console transfer curve and range unverified

Findings

Blocking

None.

Non-blocking

  • The surface capability is checked when constructing/resizing the swapchain, but gamma application later throws if transfer-source images are unsupported (VulkanDevice.cpp:2848). This can make a title fail during presentation after sceVideoOutAdjustColor succeeds. Consider returning an error or selecting a fallback when gamma is requested on such a surface.

Not verified

  • No build, test suite, negative control, or physical-console run was performed. The reported Ubuntu tests and PPSA18391 comparison were not independently checked.
  • Read all changed files listed as included in manifest.json: Presentation.hpp, PresentationGamma.hpp, EntryPoints.cpp, PresentationGamma.cpp, VulkanDevice.cpp, OutputGamma.comp, PostCompile.cmake, Graphics.cpp, Output.cpp, and libSceVideoOut.md. No changed files were excluded by the manifest.
  • Did not inspect broader callers or platform-specific behavior beyond the targeted source ranges.

To get this to a good state

Nothing is required. Consider handling surfaces without transfer-source support without failing presentation.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6016150701 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4040#pullrequestreview-6016150701). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T03:11:37Z. **Review:** COMMENTED --- # Reviewed — no blocking findings Nothing blocks this change; the implementation is coherent in the inspected code, with one compatibility concern to consider. ## What I ran Reviewed head `366c6e4148c0b6267898fda5982b0b75094dc822` using the prepared review bundle and `repo_read.py` for targeted source context. No build or tests were run. The author reports test results in `description.md`; they were not independently verified. ## Results | Check | Result | Note | |---|---|---| | Patch and source review | passed | Reviewed all 10 changed files | | Build and tests | not run | Author-reported results only | | Hardware behavior | not run | Console transfer curve and range unverified | ## Findings ### Blocking None. ### Non-blocking - The surface capability is checked when constructing/resizing the swapchain, but gamma application later throws if transfer-source images are unsupported (`VulkanDevice.cpp:2848`). This can make a title fail during presentation after `sceVideoOutAdjustColor` succeeds. Consider returning an error or selecting a fallback when gamma is requested on such a surface. ## Not verified - No build, test suite, negative control, or physical-console run was performed. The reported Ubuntu tests and PPSA18391 comparison were not independently checked. - Read all changed files listed as included in `manifest.json`: `Presentation.hpp`, `PresentationGamma.hpp`, `EntryPoints.cpp`, `PresentationGamma.cpp`, `VulkanDevice.cpp`, `OutputGamma.comp`, `PostCompile.cmake`, `Graphics.cpp`, `Output.cpp`, and `libSceVideoOut.md`. No changed files were excluded by the manifest. - Did not inspect broader callers or platform-specific behavior beyond the targeted source ranges. ## To get this to a good state Nothing is required. Consider handling surfaces without transfer-source support without failing presentation.

Pull request closed

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!4040
No description provided.