Skip to content

feat(agc): take RADV's comp-to-single clear of a multisampled DCC target - #7600

Merged
adriadam10 merged 3 commits into
boykopovar:mainfrom
milescoviello:feat/msaa-dcc-comp-to-single
Oct 21, 2026
Merged

adriadam10 merged 3 commits into
boykopovar:mainfrom
milescoviello:feat/msaa-dcc-comp-to-single

Conversation

@milescoviello

@milescoviello milescoviello commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

What

PS5 Mesa's RADV fast-clears a multisampled DCC color target to a color other than 0000/0001/1110/1111 with a comp-to-single clear (#7582). radv_clear_dcc_comp_to_single dispatches meta_clear_dcc_comp_to_single. That shader stores the clear color in sample 0 of the first pixel of every DCC block, through a storage view in a uint format of the texel's size (R32_UINT for 4-byte texels). RADV then sets the DCC keys to GFX9_DCC_CLEAR_SINGLE (0x10). The driver handles comp-to-single keys of single-sample surfaces (#2939, #4700) but not of multisampled targets:

  • A resident target refuses the clear shader's R32_UINT storage view (storage image access to multisampled color target ... guest format 20 (vk 98) is not implemented).
  • With no resident target, the storage path creates a multisampled target in the view's format, which the later draw in the color format doesn't match.
  • MultisampledDccClear refuses 0x10 keys (initial multisampled DCC contents are not a supported uniform fast clear).

This PR:

  • Recognizing the clear. MatchMultisampledSingleClear recognizes the multisampled variant of that shader by its 22 code words, taken from a dump of PPSA68091's, with 8x8 groups and 9 user data dwords. The image descriptor is at (2 << 32) | user[2], because the shader sets the high dword to 2. The block size is in user[3..4] and the color in user[5..8].
  • Taking the dispatch. For a multisampled image, TakeMultisampledSingleClear reads and decodes the descriptor, records the color for that surface (address, pipe-bank XOR, size and sample count), and skips the dispatch, counted as a fill HLE. In the resolve-ahead path the dispatch returns early, as the fill kernels do.
  • Record lifetime. RADV assigns each image its pipe-bank XOR, so a target of a new image on the same memory doesn't match an old record. The unmap/allocation-removal observer (retireUnmapped) drops every record whose surface base the removed range covers, and it is installed while any record exists. RADV writes 0x10 keys only in a fast clear that runs this dispatch for the same image right after, and initializes DCC to 0x00 or 0xff on an image's first use, so a new image gets its own record before it can show 0x10 keys.
  • Importing 0x10 keys. MultisampledDccClear takes 0x10 keys as a clear to the recorded color when the target's surface, pipe-bank XOR, size and sample count match a recorded clear. This covers texels of 1 to 16 bytes. The shader stores user[5..8] as the four dwords of sample 0's texel: v_mov_b32 v0, s5, v_lshrrev_b64 v[1:2], 0, s[6:7] and v_mov_b32 v3, s8. RADV binds the image through a uint view of the texel's size, R8_UINT up to R32G32B32A32_UINT, so a texel takes as many of those dwords as it holds. 0x10 keys with no recorded clear are refused with their own message.
  • Debt. A new entry records what isn't modeled: the guest's color memory doesn't get the color at the blocks' first pixels, and the recorded color is assumed to be the one the keys refer to. The one reuse case left: a new image on memory reused within one mapping, with the same address, XOR, size and sample count, whose clear runs a comp-to-single shader other than the recognized one.

With #7250, the same import path takes a whole-range 0x10 fill of a resident target's DCC, since absorbDccFill calls MultisampledDccClear. That is how the resident-target cases below clear.

Tested

Ubuntu 24.04 (Linux 6.8), GCC 13.3, NVIDIA RTX 4070 Ti (595.99.02).

Test SWF without this PR (that stack without #7233) with it
opaque_background stops at 11 s: initial multisampled DCC contents are not a supported uniform fast clear runs to the limit; coarse 0.6
color_transform_issue_9698, gradient_issue_9892, blend_modes__masked_layer_cached_children, blend_modes__overlay_onto_stage stop at 10 to 11 s: compute shader 0x201d95e00: AGC graphics: storage image access to multisampled color target 0x40023a0000 (1920x1080, 4 samples, vk format 37) as a 1920x1080 texture of 4 samples and guest format 20 (vk 98) is not implemented run to the limit; coarse 0.1 to 0.5

On main alone Ruffle doesn't reach these: it stops at RADV's fill kernel, which #6543 takes.

@akkadbakkad89 ran agc_driver_graphics at 8345be67c on Windows (RTX 3070, 617.42, WinLibs GCC 15.2.0): it passes, the matcher cases included.

tools/check_conventions.py --base upstream/main passes. tools/pr_overlap.py lists #5497 and #6804, which add includes near the same Dispatch.cpp line. It also lists open pull requests that conflict with main and touch tests/Graphics.cpp or the debt file; the debt entry sits away from the lines those edit.

Checklist

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 18, 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 7910 docs/dev/debt/libSceAgcDriver.md L68-69
PR 8105 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp L2429, L10876
PR 8932 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp L533-534, L705

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 1395 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 2434 docs/dev/debt/libSceAgcDriver.md
PR 4040 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 4448 docs/dev/debt/libSceAgcDriver.md
PR 4449 docs/dev/debt/libSceAgcDriver.md
PR 5058 docs/dev/debt/libSceAgcDriver.md
PR 5372 docs/dev/debt/libSceAgcDriver.md
PR 5441 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 5499 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 5925 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6194 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6223 docs/dev/debt/libSceAgcDriver.md
PR 6235 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 6280 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6300 docs/dev/debt/libSceAgcDriver.md
PR 6412 docs/dev/debt/libSceAgcDriver.md
PR 6481 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6548 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6549 docs/dev/debt/libSceAgcDriver.md
PR 6628 core/libs/prx/libSceAgcDriver/Graphics/include/MultisampleTarget.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
PR 6636 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6801 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6808 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6867 docs/dev/debt/libSceAgcDriver.md
PR 6868 docs/dev/debt/libSceAgcDriver.md
PR 6946 docs/dev/debt/libSceAgcDriver.md
PR 6947 docs/dev/debt/libSceAgcDriver.md
PR 6971 core/libs/prx/libSceAgcDriver/Graphics/include/MultisampleTarget.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
PR 6973 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6977 docs/dev/debt/libSceAgcDriver.md
PR 6987 core/libs/prx/libSceAgcDriver/Graphics/include/MultisampleTarget.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6989 core/libs/prx/libSceAgcDriver/Graphics/include/MultisampleTarget.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
docs/dev/debt/libSceAgcDriver.md
PR 6995 core/libs/prx/libSceAgcDriver/Graphics/include/MultisampleTarget.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7002 core/libs/prx/libSceAgcDriver/Graphics/include/MultisampleTarget.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7201 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp
PR 7256 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7410 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp
core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 7449 docs/dev/debt/libSceAgcDriver.md
PR 7505 docs/dev/debt/libSceAgcDriver.md
PR 7604 docs/dev/debt/libSceAgcDriver.md
PR 7642 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Dispatch/Dispatch.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7659 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7800 docs/dev/debt/libSceAgcDriver.md
PR 7803 core/libs/prx/libSceAgcDriver/Graphics/include/MultisampleTarget.hpp
core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
docs/dev/debt/libSceAgcDriver.md
PR 7911 docs/dev/debt/libSceAgcDriver.md
PR 8014 docs/dev/debt/libSceAgcDriver.md
PR 8180 docs/dev/debt/libSceAgcDriver.md
PR 8212 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 8564 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 8592 docs/dev/debt/libSceAgcDriver.md
PR 8658 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
PR 8847 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
PR 8971 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md
PR 9020 core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
docs/dev/debt/libSceAgcDriver.md

@milescoviello

Copy link
Copy Markdown
Contributor Author

Pushed de1f5e5. I decoded the clear shader with agc_shader_replay --asm. It stores user[5..8] as the four dwords of sample 0's texel: v0 from s5, v[1:2] from s[6:7] through v_lshrrev_b64 by 0, and v3 from s8. The address is (x * user[3], y * user[4], group z, sample 0). RADV binds the image through a uint view of the texel's size, so 8- and 16-byte texels take the first two dwords or all four. 0x10 keys of such targets now import as the recorded color instead of being refused. The unit test checks RGBA16F and RGBA32F, and the description is updated. agc_driver_graphics passes 3 of 3 and the 38 area tests pass. With the first commit's MultisampleTarget.cpp, the new cases fail with the old refusal.

AI-assisted: yes (Claude Code)

@akkadbakkad89

Copy link
Copy Markdown
Contributor

Verified at head 8345be67c: agc_driver_graphics passes on NVIDIA RTX 3070 (driver 617.42), Windows 11, MinGW (WinLibs GCC 15.2.0), Release - including the new multisampledSingleClearTests matcher cases (recognized kernel/userdata, and all negative variants). The runtime fast-clear path itself is RADV-only, so NVIDIA coverage here is the matcher plus no-regression of the surrounding suite.

@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @akkadbakkad89, I added it to the description. One note: the clear dispatch comes from the guest's RADV, but AnyPS5's side runs on any host GPU. So the MultisampledDccClear cases with 0x10 keys in that test, which don't need a device, are covered by your run too. Since then de1f5e5 has extended them to RGBA16F and RGBA32F targets (64- and 128-bit texels).

AI-assisted: yes (Claude Code)

@MarcZX10

Copy link
Copy Markdown
Contributor

I checked the clear record's lifetime as well as the shader match. singleClears is static and NoteMultisampledSingleClear removes an entry only when another recognized clear reuses the same base address. I do not see this record invalidated when the guest range/target is unmapped or reused; recordedSingleClear then accepts a matching address, extent and sample count.

Could a freed multisampled surface be reallocated at the same address with the same shape, but without this recognized clear, and later expose 0x10 DCC keys? In that case the new allocation could inherit the old recorded color. If that sequence is possible, please tie the record to the target/allocation lifetime or add an invalidation path, with a regression that retires and reuses the same surface tuple. If 0x10 provenance or allocator invariants rule it out, documenting that would answer the concern.

AI-assisted: yes

@milescoviello

Copy link
Copy Markdown
Contributor Author

@MarcZX10 yes, that sequence is possible, and the record should be tied to the image. I have a fix (038f050) that I'm testing now and will push with the results:

  • The record also stores the image's pipe-bank XOR from the clear's descriptor, and the lookup requires the target's XOR to match. RADV assigns the XOR per image when it creates it. fix(agc): reimport a multisampled target recreated with another pipe-bank XOR #7641 is the case where Ruffle recreates a target on the same memory and the XOR changes (0xc000 to 0x4000).
  • retireUnmapped, the unmap/allocation-removal observer, now drops every record whose surface base the removed range covers. The observer is also installed while any record exists.
  • For reuse inside one mapping without an unmap: RADV writes 0x10 keys only in a fast clear that runs this dispatch for the same image right after (radv_clear_dcc, then radv_clear_dcc_comp_to_single). It initializes DCC to 0x00 or 0xff on an image's first use (radv_init_color_image_metadata). So a new image gets a new record before it can show 0x10 keys again. The one case left: the same address, XOR, size and sample count, plus a clear whose shader isn't the recognized one. The debt entry will state that.

Regression in agc_driver_graphics: a mismatched XOR is refused. A surface on real guest memory is recorded and imported, then removed through GuestAllocationsRemove and mapped again at the same tuple, and the import must now be refused. Another surface's record must survive that removal.

AI-assisted: yes (Claude Code)

@MarcZX10

Copy link
Copy Markdown
Contributor

Thanks, the RADV metadata initialization detail narrows the concern, and the remaining unrecognized-clear/reused-tuple case is the one that matters. For the reuse regression, please make sure the remapped target is presented with 0x10 DCC keys before the import attempt and without a new NoteMultisampledSingleClear; otherwise default 0x00/0xff metadata would not exercise consumption of a stale record. Keeping another surface record valid is a useful control for range-specific invalidation.

@milescoviello

Copy link
Copy Markdown
Contributor Author

@MarcZX10 that's how the regression is written. After GuestAllocationsRemove and a new GuestAllocationsAdd of the same block, the remapped target is the same tuple: address, XOR 0, 581x729, 4 samples. It's presented with the same all-0x10 key buffer, and there's no NoteMultisampledSingleClear in between. The import must then refuse with comp-to-single keys without a recorded clear color. Before the removal, the same call on the same keys must import the recorded color, so the refusal comes from the invalidation. The control is the earlier surface at 0x40010000: it's outside the removed block and must still import its color afterwards. I'll post red and green runs when the build is through.

AI-assisted: yes (Claude Code)

@milescoviello

Copy link
Copy Markdown
Contributor Author

@MarcZX10 pushed 038f050 (it fast-forwards from de1f5e5):

  • agc_driver_graphics with it: 3 of 3.
  • With de1f5e5's MultisampleTarget.cpp under the new test, it fails with expected graphics rejection: comp-to-single keys without a recorded clear color. That's the first new check, the XOR mismatch.
  • The 38-test MSAA/DCC area set passes.

A separate red run that keeps the XOR in the record and removes only the unmap drop is queued, so the remap regression is shown failing on its own. I'll add it here when it's done. The description now covers the record's lifetime and the one case left in the debt entry.

AI-assisted: yes (Claude Code)

@milescoviello

Copy link
Copy Markdown
Contributor Author

@MarcZX10 the separate red run: on 038f050 with only retireUnmapped's forgetSingleClears call removed, the record still carries the XOR. agc_driver_graphics then fails with expected graphics rejection: comp-to-single keys without a recorded clear color, which is the remapped surface importing the stale color. So the unmap drop is what the remap regression tests, independently of the XOR. Added to the description.

AI-assisted: yes (Claude Code)

@savvaniss

Copy link
Copy Markdown
Contributor

Intel and AMD Windows data: with this PR the 18 tests built from tests/Graphics.cpp pass on an Intel UHD 770 and an AMD RX 9070 XT.

Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built, ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, with VkCache emptied first. This head 038f050c7 merged into main f3059421f.

Tests, ×3 UHD 770 RX 9070 XT
This head: the 18 tests built from tests/Graphics.cpp 18 of 18 pass 18 of 18 pass

The test file doesn't build on main without the rest of the PR, so there is no before-run. The previous head de1f5e527 also passed all 18 on both GPUs. I also ran full CTest with de1f5e527 and the 14 other open AGC PRs I tested in the same batch merged together (#7647, #7641, #7630, #7627, #7603, #7591, #7579, #7535, #7533, #7474, #7462, #7050, #7048, #7650). Neither GPU showed a failure beyond main's own, except #7650's new test.

AI-assisted: yes (Claude Code)

@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @savvaniss for the Intel and AMD runs on the current head. Added to the description.

AI-assisted: yes (Claude Code)

milescoviello and others added 3 commits October 19, 2026 21:23
RADV clears a multisampled DCC target to a color other than 0000, 0001,
1110 or 1111 with radv_clear_dcc_comp_to_single: a compute dispatch stores
the color at the first pixel of every DCC block through a uint storage view,
and the DCC keys become 0x10. The driver refused that view of a resident
target, made a separate target in the view's format otherwise, and couldn't
import 0x10 keys.

The dispatch is now recognized by its code and not run. Its clear color is
recorded for the surface its image descriptor names, and 0x10 keys on a
multisampled target of that surface, size and sample count import as a clear
to that color, for texels up to 32 bits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RADV's comp-to-single shader stores user data 5 to 8 as the four dwords of
sample 0's texel: v0 from s5, v1 and v2 from s[6:7] through a 64-bit shift by
zero, and v3 from s8. RADV binds the image through a uint view of the texel's
size, up to R32G32B32A32_UINT, so a 64-bit texel takes the first two dwords
and a 128-bit texel all four. 0x10 keys of RGBA16F and RGBA32F targets now
import as a clear to the recorded color instead of being refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A recorded comp-to-single clear stayed valid for its surface address,
size and sample count until another recognized clear replaced it, so a
surface freed and reallocated on the same memory could import the old
color for its 0x10 DCC keys. The record now also carries the image's
pipe-bank XOR, which RADV assigns per image, and is dropped when an
unmap or allocation removal covers the surface's base.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@milescoviello
milescoviello force-pushed the feat/msaa-dcc-comp-to-single branch from 038f050 to d6cd6de Compare October 19, 2026 21:43
@milescoviello

milescoviello commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased onto main bf2c63f (d6cd6de). The only conflict was an include in Dispatch.cpp, next to the Recorder.hpp include #5497 added. The Khronos validation comparison CONTRIBUTING.md now asks for is in the description: the PR's focused tests on main and on this head. 52 of 54 pass on each; the other two are newer tests my script didn't build (Not Run on both), and a rerun with them is queued. Neither log has a VUID- error.

AI-assisted: yes (Claude Code)

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 19, 2026
@JJenkx

JJenkx commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Related: #8123 adds DCC register-clear key 0x20; this PR adds the separate comp-to-single key 0x10. I checked the current diff at d6cd6de586b44fbee6d344b9f51a5607fd52333d: the singleClearColor dispatch is immediately above the switch where #8123 adds its case, and the debt entries are adjacent. Neither implementation depends on the other. I can rebase #8123 and rerun its focused tests if this lands first. Please let me know if you prefer a different order.

AI-assisted: yes.

@milescoviello

Copy link
Copy Markdown
Contributor Author

@JJenkx thanks for checking. I have no preference on the order. The two keys are independent (comp-to-single 0x10 here, register clear 0x20 in #8123), and the overlap is only neighbouring lines in that switch and the debt file. If #8123 lands first, I'll rebase this one and rerun its tests. If this lands first, your offer to rebase #8123 works for me.

AI-assisted: yes (Claude Code)

@adriadam10
adriadam10 merged commit 2cca5c0 into boykopovar:main Oct 21, 2026
17 of 18 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Rechecked against current main (#7650, #7683, #7862 and the sample-order change landed in the same files): the merge is clean, the XOR-keyed record and the unmap drop don't interact with them, and the matcher, 0x10 import and debt entry are unchanged. Merged.

@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @adriadam10 for rechecking it against the newer main changes and merging.

AI-assisted: yes (Claude Code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs fix error Closes an issue (Fixes #N)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AGC: RADV's comp-to-single fast clear of a multisampled DCC target stops Ruffle (PPSA68091)

6 participants