Skip to content

fix(agc): sample a multisampled target whose format differs only in red/blue order - #7253

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
milescoviello:fix/msaa-sample-swapped-format
Oct 17, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
milescoviello:fix/msaa-sample-swapped-format

Conversation

@milescoviello

@milescoviello milescoviello commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

What

MultisampleTargetTexture samples a native multisampled color target only through a texture of the exact format it was rendered in. Any other format is refused.

Rush 2 (PPSA69423) and Wave Race 64 (PPSA69424) render a 3840x2160 8x target as 8_8_8_8 with the alternate component swap, which decodes to B8G8R8A8_UNORM. They then sample it through an 8_8_8_8 UNORM T#, R8G8B8A8_UNORM:

AGC graphics: sampling multisampled color target 0x400c000000 (3840x2160, 8 samples, vk format 44) as a 3840x2160 texture of 8 samples and guest format 56 (vk 37) is not implemented

Both formats store four bytes per sample. A B8G8R8A8 target holds blue, green, red, alpha in that byte order, so reading it as R8G8B8A8 returns blue as red and red as blue.

For the B8G8R8A8/R8G8B8A8 pairs of the same numeric type (UNORM, SRGB, SNORM, UINT, SINT), the texture is now the target's own image. The image keeps its format and gets a component mapping with red and blue exchanged, composed with the T#'s swizzle (swapRedBlue). Every other format difference is still refused. Storage views of the target are unchanged.

Tested

Linux (Ubuntu 24.04, GCC 13.3, Release), RTX 4070 Ti, NVIDIA 595.99.02; main 922dc89.

App base base + this PR
Rush 2 (PPSA69423) stops at 2 s on the line above runs to the 60 s limit, 595 then 600 presents per 10 s
Wave Race 64 (PPSA69424) stops at 2 s on the line above presents 594 to 600 per 10 s, then segfaults at 48 s (not looked at yet)

Not checked on Windows, on AMD, or on a console.

Checklist

🤖 Generated with Claude Code

…ed/blue order

Sampling a native multisampled color target through a texture of
another format was refused even when the two formats store the same
bytes in the other channel order. Rush 2 and Wave Race 64 render a
3840x2160 8x target as 8_8_8_8 with the alternate component swap
(B8G8R8A8_UNORM) and sample it through an 8_8_8_8 UNORM T#
(R8G8B8A8_UNORM), and stopped on "sampling multisampled color target
... (vk format 44) as a ... texture ... guest format 56 (vk 37) is not
implemented".

For the B8G8R8A8/R8G8B8A8 pairs of the same numeric type the texture is
now the target's own image with red and blue exchanged in its component
mapping, composed with the T#'s swizzle. Other format differences are
still refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6635 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp L678-679, L687
core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cpp L303, L305-306
PR 6971 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp L678-679, L687

Some 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.

Pull request Shared files not compared
PR 5987 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
PR 6297 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cpp
PR 6498 core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cpp
PR 6553 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
PR 6628 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cpp
PR 6808 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cpp
PR 6869 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
PR 6973 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cpp
PR 6987 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cpp
PR 6989 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cpp
PR 6995 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cpp
PR 7002 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cpp

@github-actions github-actions Bot added the agc libSceAgc* label Oct 17, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Full CI on 90c3b61 (merged into main 922dc89): the Linux job fails agc_driver_sample_multisample_target on llvmpipe (Mesa, LLVM 20.1.2). The steps before the new case pass, and the new case fails its value check:

AGC graphics: a sample of a BGRA8 target loaded through an RGBA8 texture does not hold the drawn color with red and blue swapped

The swap itself looks right to me. I think the check is too tight for an 8-bit target. Drawn is {0.25, 0.5, 0.125, 1.0}, and the green 0.5 lands exactly halfway between two UNORM8 codes (0.5 × 255 = 127.5). Vulkan only says the float-to-UNORM conversion should round to nearest, so a device may store 127 or 128. In float32:

stored read back difference from 0.5 tolerance 0.5f / 255.0f
127 0.49803922 0.0019607842 within
128 0.50196081 0.0019608140 over, by one float ulp

A device that rounds 127.5 up fails the check even when the red/blue swap is correct. If the device truncates instead, 0.25 → 63 and 0.125 → 31 also fail the check. So this tolerance only passes on a device that rounds to nearest and rounds 127.5 down.

Suggested fix (test only):

  • For this case, draw a color whose channels are exact UNORM8 codes, e.g. {64/255, 128/255, 32/255, 1}. Alternatively, allow 1/255 per channel. R and B differ by 32 codes, so an unswapped read still fails either way.
  • Put the loaded texel and the expected values in the Require message, so a failure on another driver shows whether it's rounding or a real channel-order problem.

One more possibility: llvmpipe could ignore the view's component swizzle on a multisampled fetch. The new message would separate the two cases (R and B unswapped vs off by one code). If it turns out to be the swizzle, we'll need another approach for that driver, so please mention it if you see it.

The case drew 0.5 green, which lies halfway between two UNORM8 codes, so a
device that rounds 127.5 up (llvmpipe, LLVM 20.1.2) failed the half-code
tolerance with red and blue correctly swapped. It now draws 64, 128 and 32
of 255 from its own pixel program and names the loaded and expected codes
when a sample differs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @oneandonlydean, that's what it was. I reproduced it locally on llvmpipe (Mesa, LLVM 20.1.2, through ANYPS5_GPU=llvmpipe): the case fails 3 of 3 on 90c3b61 and passes on NVIDIA.

With your message change and the old color, llvmpipe reports:

a sample of a BGRA8 target loaded through an RGBA8 texture reads (32.000000, 128.000000, 64.000000, 255.000000) in UNORM8 codes instead of the drawn color with red and blue swapped (31.875000, 127.500000, 63.750000, 255.000000)

Red and blue are swapped correctly. The device rounded green's 127.5 up to 128, one float ulp past the half-code tolerance, as you worked out. So the view swizzle works on llvmpipe's multisampled fetch.

7c4bc9a (test only):

  • The case now draws 64, 128 and 32 of 255 from its own pixel program (Unorm8PixelCode). Draw takes the pixel code as an optional parameter, so the other cases still draw Drawn.
  • A failing sample now names the loaded and expected texels in UNORM8 codes.

The tolerance stays at half a code. With exact codes a device has nothing to round, and red and blue are 32 codes apart, so an unswapped read still fails.

agc_driver_sample_multisample_target passes 3 of 3 on llvmpipe and 3 of 3 on NVIDIA (RTX 4070 Ti, 595.99.02). check_conventions.py passes, and the branch still merges cleanly with main c0a7468.

AI-assisted: yes (Claude Code)

@oneandonlydean
oneandonlydean merged commit d42e3e7 into boykopovar:main Oct 17, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants