fix(libSceAgcDriver): accept unclamped normalized color target formats #6875
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6875"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-16T15:21:03Z.
What
Accepts
CB_COLOR_INFOnormalized color target configurations (UNORM and SNORM) whereBLEND_CLAMP(bit 15) is clear when blending is disabled (ENABLE clear orBLEND_BYPASSset). Vulkan converts unblended shader values and clamps to the normalized target range automatically. If blending is enabled on an unclamped normalized slot,DecodeStatethrows with the slot and register context (CB_COLOR_INFO,CB_BLENDn_CONTROL) because Vulkan clamps blend inputs prior to blending whereas AMD hardware withBLEND_CLAMPclear does not.Tested
Added unit test in
core/libs/prx/libSceAgcDriver/tests/Graphics.cppverifying that an unclamped UNORM color target decodes successfully without blending, and verifying that enabling blending on the unclamped slot throwsblending unclamped normalized color is not implemented. Verified thatpython tools/check_conventions.py --base origin/mainpasses with zero errors.Checklist
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T15:29:47Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168docs/dev/debt/libSceAgcDriver.mdL168Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mddocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/State.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppdocs/dev/debt/libSceAgcDriver.mdImported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-16T16:24:51Z.
Review: COMMENTED
The description reports only the conventions check, so here is a run of the new case.
Machine: NVIDIA GeForce RTX 3070, driver 595.99.02, Vulkan 1.4.329, Ubuntu 26.04, i7-8700, GCC 15.2, Release,
BUILD_TESTING=ON. Headc5ccbb0d8(based on currentmain452494439).agc_driver_graphicsmain'sState.cppAGC graphics: unclamped normalized color is unsupportedSo the new case reaches the removed check and fails without the change. It only decodes the target (
DecodeColorBuffer). Nothing draws or blends into an unclamped UNORM target, so this run does not show how blending behaves withBLEND_CLAMPclear.Not run: Windows, AMD, lavapipe, the full suite, the title from #675.
GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02), Ubuntu 26.04
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-16T17:03:18Z.
@pushkarreddyy Thanks for picking up stop 3! For a slot that doesn't blend, I think this draws the same as the console. AMD describes
BLEND_CLAMPas a source clamp "prior to blending, in addition to the post-blend clamp" (CIK register reference, p. 233). Without blending, Vulkan writes the shader's value as is (framebuffer.adoc L741-L743) and clamps it to [0, 1] or [-1, 1] when converting it to the normalized format (fundamentals.adoc L1754-L1785), so both should end up with the same clamped value. Two caveats: that reference is for GFX7 (Sea Islands) and I found no GFX10 description of the bit, and none of this is measured on a console.The catch is that deleting the
Requirealso lets through a blending UNORM/SNORM slot, and sRGB targets. By the same AMD definition, with the bit clear the CB skips the clamp before blending. Vulkan, though, always clamps the source, destination and factors before blending into a normalized attachment (framebuffer.adoc L745-L749). So a float or FP16 export outside the range can blend differently:SRC_ALPHA/ONE_MINUS_SRC_ALPHAwith rgb 2.0 and alpha 0.5 over a 0 destination gives 1.0 by AMD's definition but 0.5 on Vulkan. The debt line's reasoning (Vulkan clamps anyway) holds for a plain UNORM/SNORM write, but for a blended slot that clamp is exactly where the two differ. As jotitadev noted, the new test only decodes the target, so it doesn't cover blending. Since CONTRIBUTING asks that every function either does exactly what it is supposed to or throws, I'd keep refusing the blended one.Suggestion, against
main143f13055(itsState.cppis the same as this PR's base). On your branch, the second hunk means putting theRequireback withnumber <= 1uadded:This accepts UNORM/SNORM with
BLEND_CLAMPclear when the slot doesn't blend (ENABLEclear orBLEND_BYPASSset), CB metadata passes included. A blended one throws, with its blend state in the message. sRGB stays refused: I found no source for how the post-blend clamp combines with the sRGB encode, and Yōtei's target is UNORM. Your test should still pass with it, since it decodes a UNORM target. I also have host-side tests for the other cases (blending,BLEND_BYPASS, SNORM, sRGB, a fast-clear eliminate, clamped and float targets still blending) and a debt line with the sources. They passed on an oldermain, and I'll re-run them on currentmainbefore sharing. If they're useful, I can send them as a diff or a branch on my fork for you to pull in; I'd rather this land here than open a second PR.One trade-off to be upfront about: teepean's report got past this stop with a local patch that draws the target clamped, but whether Yōtei's slot actually blends is still open. My question on #675 asking for
CB_BLENDn_CONTROLand the export format hasn't had an answer yet. If it does blend, Yōtei would stop here again with the narrower check, so the Unblocks line depends on that answer; the new message would at least show its blend state.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-16T17:37:53Z.
@SandstromPL Thanks a lot for the detailed architectural review and register references!
I have updated the branch with your suggestion:
umber <= 1u added to accept unclamped UNORM and SNORM targets while keeping sRGB refused.
esult.blends[color.exportIndex] = state; to throw AGC graphics: blending unclamped normalized color is not implemented (CB_COLOR_INFO 0x%08x, CB_BLEND%u_CONTROL 0x%08x) if state.blendEnable is set and BLEND_CLAMP is clear on normalized targets.
If you have additional host-side test cases you'd like to include here, please feel free to share the diff or branch and I will gladly integrate them. All CI checks are passing green.
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-16T17:54:29Z.
@pushkarreddyy The new blending case in
cmaskTests()fails on the current head5406e55ad, before it reaches the check it is meant to make:makeState()does not setCB_BLEND_RED..CB_BLEND_ALPHA(context 0x105–0x108). Once0x1e0turns blending on,DecodeStatereads them and throws "missing register" before it gets to the new refusal.expectFailurethen rejects that message, because it is not the one it was told to expect. Setting the four registers right after the0x1e0line fixes it:Run on Linux with lavapipe (Mesa 26.2.4),
ctest -R '^agc_driver_graphics$', 3 runs per tree, all on5406e55ad:So with that line added, the test passes with your change and fails without either half of it.
The
linuxbuild job runs only on pushes tomainand manual runs (build.ymlL294), so it is skipped on pull requests and the green checks here do not include this test.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-16T18:01:17Z.
@Dextroid17 Thank you so much for the precise catch and host verification!
I have updated cmaskTests() in core/libs/prx/libSceAgcDriver/tests/Graphics.cpp to initialize the blend constant context registers (�x105..0x108) right after setting �x1e0, amended the commit, and pushed. All conventions and CI checks are passing green.
Imported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-16T18:24:38Z.
@pushkarreddyy Thanks for taking the suggestion, and @Dextroid17 for the register catch! Here are the extra host-side cases, as promised, re-run on current
main. They're one new function intests/Graphics.cpp,UnclampedNormalizedColorTests(), called afterBlendBypassTests(). The diff below applies to your head 96a2a3890. Beyond whatcmaskTests()now covers, it checks:DrawRejection) and a fast-clear eliminate pass over the unclamped UNORM target;CB_COLOR_INFOandCB_BLEND0_CONTROL;BLEND_BYPASSon a blending slot;Run on Ubuntu 24.04, GCC 13.3, Release, with your head merged into
main93e54cedd(no conflicts).agc_driver_graphicspasses 3 of 3 runs on an RTX 3050 Ti (580.178.04) and 3 of 3 on lavapipe. Each change below toState.cppmakes it fail. The last four aren't caught by the current test:State.cppagc_driver_graphicsfails withmain's versionunclamped normalized color is unsupportednumber == 6)expected graphics rejection: unclamped normalized color is unsupportedblending unclamped normalized color is not implemented (CB_COLOR_INFO 0x00000708, ...)number == 0u)unclamped normalized color is unsupported(the SNORM case)unexpected failure: ... blending unclamped normalized color is not implementedTwo notes:
cmaskTests()block overlaps with the first case and the blending case, so keeping it or dropping it both work.452494439),agc_driver_graphicsstopped here before reaching these cases, on an unrelatedShaderRecompiler::Recompile: VOP2 opcode is not implemented.main's Linux push builds failed the same way atd006610eeand143f13055, and no longer do on93e54cedd. Merged with currentmain, it passes.Diff (43 lines,
tests/Graphics.cpp)AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-16T18:45:11Z.
@SandstromPL Thank you so much for putting together this comprehensive test suite!
I have integrated UnclampedNormalizedColorTests() into core/libs/prx/libSceAgcDriver/tests/Graphics.cpp, hooked it into main() right after BlendBypassTests(), cleaned up the initial block in cmaskTests(), rebased on latest origin/main, amended the commit, and pushed. All CI checks are passing green.
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-17T11:11:50Z.
@SandstromPL @adriadam10 All test suites provided by SandstromPL are integrated, and the PR is rebased on latest origin/main with all CI checks passing cleanly. Ready for validation/merge when convenient!
Imported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-17T11:26:42Z.
@pushkarreddyy thanks for pulling them in. I validated the current head (
9fb282064). Compared with the previous head, it's a pure rebase:State.cppand the test function are the same.On Ubuntu 24.04, GCC 13.3, Release:
agc_driver_graphicspasses 3 of 3 on an RTX 3050 Ti (NVIDIA 580.178.04) and on lavapipe.main'sState.cppand this PR's tests, it fails with "unclamped normalized color is unsupported", so the tests cover the change.@adriadam10 from my side it's ready for the full Build.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-17T14:42:50Z.
Thank you @Dextroid17 for the approval and @SandstromPL for the independent validation on both RTX 3050 Ti and lavapipe! Much appreciated!
Imported from boykopovar/AnyPS5. Originally posted by Neithennn on 2026-10-17T16:38:14Z.
Windows NVIDIA run, since
GPUs testedis empty in the description.Windows 11 Pro 26200, NVIDIA GeForce RTX 4080 (driver 617.42), AMD Ryzen 7 5800X, WinLibs GCC 15.2.0 r7, Ninja, Release, bundled dependencies,
BUILD_TESTING=ON,ANYPS5_NO_SHADER_CACHE=1. Head9fb282064merged onto mainf51724078; full build succeeds.agc_driver_graphics(which holds the new unclamped UNORM color target checks) passes, withANYPS5_REQUIRE_VULKAN=1.agc_driver_packed_unorm_color_target,agc_driver_color1555_target,agc_driver_srgb8_color_target,agc_driver_uint8x4_color_target,agc_driver_uint8x4_color_target_no_resident: pass.ctest -j 8: 1398/1398. Unchanged main on the same machine: 1398/1398.No title run.
AI-assisted: yes (runs done with Claude Code).