fix(agc): reimport a multisampled target recreated with another pipe-bank XOR #7641

Merged
milescoviello merged 1 commit from upstream-pr/7641 into main 2026-10-20 11:18:15 +00:00
milescoviello commented 2026-10-18 19:03:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T19:03:11Z.


What

acquire in MultisampleTarget.cpp reuses a resident multisampled target for any use with the same surface address, format, extent and sample count. checkDccCurrent then requires every other layout field to match, and refuses with multisampled DCC target layout or metadata changed.

In Ruffle (PPSA68091), 7 of Ruffle's own cache_as_bitmap visual tests stop on that refusal. A temporary print of both layouts at the refusal showed that only the pipe-bank XOR differs. Address, DCC and CMASK addresses, DCC control, CMASK size, tile mode and element size are all the same:

surface 0x4004c60000 864x864 fmt 37 s4 | ... xor 0xc000/0x4000
surface 0x4004b40000 1080x1080 fmt 37 s4 | ... xor 0xc000/0x0

RADV gives each image its pipe-bank XOR (its tile swizzle) when it creates it, and doesn't change it afterwards. So the same surface with another XOR is a new image on recycled memory. Here Ruffle recreates the render target of a cached bitmap. The resident target's contents belong to the old image.

This PR:

  • recreated is true when a use differs from a resident target only in its pipe-bank XOR.
  • acquire then reimports the resident target into its own image (Recreate). The target keeps its image, views and cached textures, takes the use's layout, drops its old guard ranges and DCC ranges, and imports its contents from the current DCC and CMASK metadata, as a first use does. The image is cleared to that color with a transfer clear recorded after the work already recorded against it, then the use's fast clear is applied as usual.
  • Any other layout change is still refused as before.

An earlier head of this PR retired the resident target and created a new one. Retired targets stay allocated until device teardown, and cache_as_bitmap__avm2_button recreates its 864x864 4x RGBA8 target (about 12 MiB) 28 times in 32 s, so that kept about 330 MiB. Reimporting into the same image keeps the number of multisampled targets flat (see Tested).

Tested

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

  • A new case in DccFastClearTests (agc_driver_msaa_dcc_clear_{2,4,8}) runs for each sample count:
    • It draws to an RGBA16F target whose DCC keys are 0000, so the target becomes resident.
    • It rewrites the keys to 1111 with a driver store, as RADV's clear of a new image does.
    • It draws to the same surface with pipe-bank XOR 0x4000, then resolves. Undrawn samples must hold the new clear (1.0).
    • A further use that also changes dccAlphaOnMsb must still be refused.
    • With this change: 3 of 3 runs for each sample count. With main's MultisampleTarget.cpp, all three fail with multisampled DCC target layout or metadata changed.
  • The 39 tests matching ^agc_driver_graphics$|msaa|multisample|dcc|cmask|fmask|alpha_to_coverage|fill|dispatch pass.
  • Ruffle (PPSA68091) with Ruffle's own visual test SWFs (ruffle-rs/ruffle tests/tests/swfs/visual), each the only game in the library, 32 s. These cases need #6543 and #7250 to get this far, so the stack is main 385ed71f2c + #6543 + #7250 + #7233 + #7600. "Coarse" is the mean difference of 32x24-cell averages between the last frame and the test's output.expected.png, from 0 to 255.

With this head, a temporary print counted the recreations and the number of multisampled targets the driver holds after each one:

Test SWF without this PR with it recreations in 32 s targets held (max) coarse
cache_as_bitmap__avm2_button stops at 12 s: multisampled DCC target layout or metadata changed runs to the limit 28 2 2.4
cache_as_bitmap__avm2_button_state stops at 11 s on the same line runs to the limit 35 2 1.1
cache_as_bitmap__edittext_hscroll stops at 12 s on the same line runs to the limit 43 2 no expected image in Ruffle's tree
cache_as_bitmap__morph stops at 11 s on the same line runs to the limit 2 2 0.5
cache_as_bitmap__children_changed, __shape_changed, __cab_bitmapdata_invalidate stop at 11 s on the same line run to the limit 1 each 2 0.1, 0.1, 0.0

tools/check_conventions.py --base upstream/main passes. tools/pr_overlap.py lists no overlapping lines with open pull requests. The retirement sits inside acquire's loop, and recreated beside sameTarget, away from the lines that #6215, #6973, #6987, #6989, #6995 and #7002 change.

  • @savvaniss tested on Windows. At 388527d6b on main f3059421f, agc_driver_alpha_to_coverage, agc_driver_dithered_alpha_to_coverage and agc_driver_msaa_dcc_clear_{2,4,8} pass three times each on an Intel UHD 770 and an AMD RX 9070 XT. With only this PR's test files on main, the three msaa_dcc_clear tests fail with multisampled DCC target layout or metadata changed.
  • Khronos validation layer (LunarG SDK 1.4.363), NVIDIA RTX 4070 Ti (595.99.02), Ubuntu 24.04: VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest -R '^agc_' -V on main f29546ac4e and on main + this PR (388527d6b2, a local merge). main: 812 of 812 pass; with this PR: 812 of 812 pass. Neither log reports the layer missing. VUIDs on main: VUID-VkImageViewCreateInfo-usage-02275 ×6, VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 ×18, VUID-vkCmdCopyBuffer-srcBuffer-00118 ×2, VUID-vkCmdDispatch-magFilter-04553 ×2, VUID-vkCmdDraw-multisampledRenderToSingleSampled-07285 ×2, VUID-vkCmdWaitEvents-srcStageMask-01158 ×2, VUID-vkSetEvent-event-09543 ×2; with this PR: VUID-VkImageViewCreateInfo-usage-02275 ×6, VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605 ×18, VUID-vkCmdCopyBuffer-srcBuffer-00118 ×2, VUID-vkCmdDispatch-magFilter-04553 ×2, VUID-vkCmdDraw-multisampledRenderToSingleSampled-07285 ×2, VUID-vkCmdWaitEvents-srcStageMask-01158 ×2, VUID-vkSetEvent-event-09543 ×2. None is new with this PR. Each of main's is the subject of an open PR: 00118 #7961, 04553 #7707, 07285 #7985, 01158 and 09543 #7913, 00605 #6782, 02275 #862.

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
  • Generic behaviour, not specific to one title
  • Depends on: none (the Ruffle cases also need #6543 and #7250 to get this far)
  • Fixes: none
  • Unblocks: none on its own
  • GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 595.99.02, Ubuntu 24.04 (Linux 6.8); Intel UHD 770, 32.0.101.7088, and AMD RX 9070 XT, 32.0.31041.1004, Windows 11 (by @savvaniss)
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4911931910 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7641). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-18T19:03:11Z. --- ### What `acquire` in `MultisampleTarget.cpp` reuses a resident multisampled target for any use with the same surface address, format, extent and sample count. `checkDccCurrent` then requires every other layout field to match, and refuses with `multisampled DCC target layout or metadata changed`. In Ruffle (PPSA68091), 7 of Ruffle's own `cache_as_bitmap` visual tests stop on that refusal. A temporary print of both layouts at the refusal showed that only the pipe-bank XOR differs. Address, DCC and CMASK addresses, DCC control, CMASK size, tile mode and element size are all the same: ``` surface 0x4004c60000 864x864 fmt 37 s4 | ... xor 0xc000/0x4000 surface 0x4004b40000 1080x1080 fmt 37 s4 | ... xor 0xc000/0x0 ``` RADV gives each image its pipe-bank XOR (its tile swizzle) when it creates it, and doesn't change it afterwards. So the same surface with another XOR is a new image on recycled memory. Here Ruffle recreates the render target of a cached bitmap. The resident target's contents belong to the old image. This PR: - **`recreated`** is true when a use differs from a resident target only in its pipe-bank XOR. - **`acquire`** then reimports the resident target into its own image (`Recreate`). The target keeps its image, views and cached textures, takes the use's layout, drops its old guard ranges and DCC ranges, and imports its contents from the current DCC and CMASK metadata, as a first use does. The image is cleared to that color with a transfer clear recorded after the work already recorded against it, then the use's fast clear is applied as usual. - Any other layout change is still refused as before. An earlier head of this PR retired the resident target and created a new one. Retired targets stay allocated until device teardown, and `cache_as_bitmap__avm2_button` recreates its 864x864 4x RGBA8 target (about 12 MiB) 28 times in 32 s, so that kept about 330 MiB. Reimporting into the same image keeps the number of multisampled targets flat (see Tested). ### Tested Ubuntu 24.04 (Linux 6.8), GCC 13.3, NVIDIA RTX 4070 Ti (595.99.02). - A new case in `DccFastClearTests` (`agc_driver_msaa_dcc_clear_{2,4,8}`) runs for each sample count: - It draws to an RGBA16F target whose DCC keys are 0000, so the target becomes resident. - It rewrites the keys to 1111 with a driver store, as RADV's clear of a new image does. - It draws to the same surface with pipe-bank XOR 0x4000, then resolves. Undrawn samples must hold the new clear (1.0). - A further use that also changes `dccAlphaOnMsb` must still be refused. - With this change: 3 of 3 runs for each sample count. With `main`'s `MultisampleTarget.cpp`, all three fail with `multisampled DCC target layout or metadata changed`. - The 39 tests matching `^agc_driver_graphics$|msaa|multisample|dcc|cmask|fmask|alpha_to_coverage|fill|dispatch` pass. - Ruffle (PPSA68091) with Ruffle's own visual test SWFs (ruffle-rs/ruffle `tests/tests/swfs/visual`), each the only game in the library, 32 s. These cases need #6543 and #7250 to get this far, so the stack is `main` 385ed71f2c + #6543 + #7250 + #7233 + #7600. "Coarse" is the mean difference of 32x24-cell averages between the last frame and the test's `output.expected.png`, from 0 to 255. With this head, a temporary print counted the recreations and the number of multisampled targets the driver holds after each one: | Test SWF | without this PR | with it | recreations in 32 s | targets held (max) | coarse | |---|---|---|---|---|---| | `cache_as_bitmap__avm2_button` | stops at 12 s: `multisampled DCC target layout or metadata changed` | runs to the limit | 28 | 2 | 2.4 | | `cache_as_bitmap__avm2_button_state` | stops at 11 s on the same line | runs to the limit | 35 | 2 | 1.1 | | `cache_as_bitmap__edittext_hscroll` | stops at 12 s on the same line | runs to the limit | 43 | 2 | no expected image in Ruffle's tree | | `cache_as_bitmap__morph` | stops at 11 s on the same line | runs to the limit | 2 | 2 | 0.5 | | `cache_as_bitmap__children_changed`, `__shape_changed`, `__cab_bitmapdata_invalidate` | stop at 11 s on the same line | run to the limit | 1 each | 2 | 0.1, 0.1, 0.0 | `tools/check_conventions.py --base upstream/main` passes. `tools/pr_overlap.py` lists no overlapping lines with open pull requests. The retirement sits inside `acquire`'s loop, and `recreated` beside `sameTarget`, away from the lines that #6215, #6973, #6987, #6989, #6995 and #7002 change. - @savvaniss [tested on Windows](https://github.com/boykopovar/AnyPS5/pull/7641#issuecomment-6255601984). At 388527d6b on `main` f3059421f, `agc_driver_alpha_to_coverage`, `agc_driver_dithered_alpha_to_coverage` and `agc_driver_msaa_dcc_clear_{2,4,8}` pass three times each on an Intel UHD 770 and an AMD RX 9070 XT. With only this PR's test files on `main`, the three `msaa_dcc_clear` tests fail with `multisampled DCC target layout or metadata changed`. - Khronos validation layer (LunarG SDK 1.4.363), NVIDIA RTX 4070 Ti (595.99.02), Ubuntu 24.04: `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest -R '^agc_' -V` on `main` f29546ac4e and on `main` + this PR (388527d6b2, a local merge). `main`: 812 of 812 pass; with this PR: 812 of 812 pass. Neither log reports the layer missing. VUIDs on `main`: `VUID-VkImageViewCreateInfo-usage-02275` ×6, `VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605` ×18, `VUID-vkCmdCopyBuffer-srcBuffer-00118` ×2, `VUID-vkCmdDispatch-magFilter-04553` ×2, `VUID-vkCmdDraw-multisampledRenderToSingleSampled-07285` ×2, `VUID-vkCmdWaitEvents-srcStageMask-01158` ×2, `VUID-vkSetEvent-event-09543` ×2; with this PR: `VUID-VkImageViewCreateInfo-usage-02275` ×6, `VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605` ×18, `VUID-vkCmdCopyBuffer-srcBuffer-00118` ×2, `VUID-vkCmdDispatch-magFilter-04553` ×2, `VUID-vkCmdDraw-multisampledRenderToSingleSampled-07285` ×2, `VUID-vkCmdWaitEvents-srcStageMask-01158` ×2, `VUID-vkSetEvent-event-09543` ×2. None is new with this PR. Each of `main`'s is the subject of an open PR: 00118 #7961, 04553 #7707, 07285 #7985, 01158 and 09543 #7913, 00605 #6782, 02275 #862. ### 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 - [x] Generic behaviour, not specific to one title - [x] Depends on: none (the Ruffle cases also need #6543 and #7250 to get this far) - [x] Fixes: none - [x] Unblocks: none on its own - [x] GPUs tested: NVIDIA GeForce RTX 4070 Ti, driver 595.99.02, Ubuntu 24.04 (Linux 6.8); Intel UHD 770, 32.0.101.7088, and AMD RX 9070 XT, 32.0.31041.1004, Windows 11 (by @savvaniss) - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-18 19:12:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T19:12:56Z.

Review: COMMENTED


The recreation path clears the old target's active flag and guard ranges, then leaves the object in the global target list so commands already recorded against its image remain valid. Could you point to the ownership/lifetime guarantee for the old resources after becomes false, especially if those recorded commands have not yet been submitted? The comment in the PR body explains the intent, but I could not verify from this diff whether a later cleanup path can destroy or reuse those resources before the queue completes. If it is retained until process teardown or otherwise fenced, documenting that invariant here would make the new retirement path easier to audit.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5564527578 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7641#pullrequestreview-5564527578). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T19:12:56Z. **Review:** COMMENTED --- The recreation path clears the old target's active flag and guard ranges, then leaves the object in the global target list so commands already recorded against its image remain valid. Could you point to the ownership/lifetime guarantee for the old resources after becomes false, especially if those recorded commands have not yet been submitted? The comment in the PR body explains the intent, but I could not verify from this diff whether a later cleanup path can destroy or reuse those resources before the queue completes. If it is retained until process teardown or otherwise fenced, documenting that invariant here would make the new retirement path easier to audit.
MarcZX10 commented 2026-10-18 19:13:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T19:13:00Z.

Review: COMMENTED


Clarification: the concern is whether the old MultisampleTarget resources remain alive until previously recorded GPU commands complete after active is set false. The backticks in my prior comment were interpreted by the shell, but the question is unchanged.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5564528106 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7641#pullrequestreview-5564528106). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T19:13:00Z. **Review:** COMMENTED --- Clarification: the concern is whether the old MultisampleTarget resources remain alive until previously recorded GPU commands complete after active is set false. The backticks in my prior comment were interpreted by the shell, but the question is unchanged.
MarcZX10 commented 2026-10-18 19:13:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T19:13:24Z.

Review: COMMENTED


Follow-up after tracing the ownership path: targets() retains the inactive unique_ptr<MultisampleTarget>; inactive entries are not erased by acquire. The Vulkan device teardown waits for vkDeviceWaitIdle before ClearMultisampleTargets(device) erases them. That resolves my lifetime question: recorded commands keep their referenced image alive until teardown. I did not find a defect here.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5564531678 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7641#pullrequestreview-5564531678). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T19:13:24Z. **Review:** COMMENTED --- Follow-up after tracing the ownership path: `targets()` retains the inactive `unique_ptr<MultisampleTarget>`; inactive entries are not erased by `acquire`. The Vulkan device teardown waits for `vkDeviceWaitIdle` before `ClearMultisampleTargets(device)` erases them. That resolves my lifetime question: recorded commands keep their referenced image alive until teardown. I did not find a defect here.
milescoviello commented 2026-10-18 19:15:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T19:15:02Z.


@MarcZX10 yes, that's the guarantee. ClearMultisampleTargets(device) is the only place that erases from targets(), and the device teardown reaches it after vkDeviceWaitIdle. The retired object, with its image, memory, views and any textures it still holds, stays alive until then, whether or not the commands recorded against it have been submitted. The unmap retirement (retireUnmapped) already relies on the same invariant. The libSceAgcDriver debt entry for multisampled color targets states it: "Retired Vulkan images remain allocated until device teardown to preserve outstanding references."

The cost is memory. A title that recreates a target many times keeps every retired image until teardown. I haven't counted how many recreations the Ruffle tests make over a run yet. I'll measure it and post the number here. If a title turns out to recreate targets every frame, the follow-up would be to free a retired target once a fence after its last use has signalled. I left that out to keep this change small.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254022052 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7641#issuecomment-6254022052). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-18T19:15:02Z. --- @MarcZX10 yes, that's the guarantee. `ClearMultisampleTargets(device)` is the only place that erases from `targets()`, and the device teardown reaches it after `vkDeviceWaitIdle`. The retired object, with its image, memory, views and any textures it still holds, stays alive until then, whether or not the commands recorded against it have been submitted. The unmap retirement (`retireUnmapped`) already relies on the same invariant. The libSceAgcDriver debt entry for multisampled color targets states it: "Retired Vulkan images remain allocated until device teardown to preserve outstanding references." The cost is memory. A title that recreates a target many times keeps every retired image until teardown. I haven't counted how many recreations the Ruffle tests make over a run yet. I'll measure it and post the number here. If a title turns out to recreate targets every frame, the follow-up would be to free a retired target once a fence after its last use has signalled. I left that out to keep this change small. AI-assisted: yes (Claude Code)
github-actions[bot] commented 2026-10-18 19:31:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T19:31:42Z.


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 6683 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
PR 6808 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
PR 6971 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
PR 7002 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
PR 7948 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
PR 8223 core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254193862 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7641#issuecomment-6254193862). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T19:31:42Z. --- <!-- pr-overlap --> 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 6683](https://www.github.com/boykopovar/AnyPS5/pull/6683) | `core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp` | | [PR 6808](https://www.github.com/boykopovar/AnyPS5/pull/6808) | `core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp` | | [PR 6971](https://www.github.com/boykopovar/AnyPS5/pull/6971) | `core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp` | | [PR 7002](https://www.github.com/boykopovar/AnyPS5/pull/7002) | `core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp` | | [PR 7948](https://www.github.com/boykopovar/AnyPS5/pull/7948) | `core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp` | | [PR 8223](https://www.github.com/boykopovar/AnyPS5/pull/8223) | `core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cpp` |
milescoviello commented 2026-10-18 19:42:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T19:42:54Z.


@MarcZX10 the count I owed, measured with a temporary print in the new retirement path. Ruffle on the same stack plus this head, 32 s each:

Test Recreations Target
cache_as_bitmap__avm2_button 28 864x864, 4x RGBA8
cache_as_bitmap__morph 2 160x130, 4x
cache_as_bitmap__shape_changed 1 160x130, 4x

So the cost isn't small in the first case. An 864x864 4x RGBA8 image is about 12 MiB, so avm2_button keeps about 330 MiB of retired images after 32 s, and a movie that recreates a cached bitmap about once a second keeps growing until teardown. The unmap retirement has the same retention, but a recreation can happen every frame, which an unmap can't, so I don't think this PR should merge with it. I'm working on freeing a retired target once the commands recorded against it have completed, through Recorder::Keep. First I'm checking what else can still hold its image, such as the sampled views it hands out. I'll push that here with a test and a memory reading on the same Ruffle case.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254304914 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7641#issuecomment-6254304914). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-18T19:42:54Z. --- @MarcZX10 the count I owed, measured with a temporary print in the new retirement path. Ruffle on the same stack plus this head, 32 s each: | Test | Recreations | Target | |---|---|---| | `cache_as_bitmap__avm2_button` | 28 | 864x864, 4x RGBA8 | | `cache_as_bitmap__morph` | 2 | 160x130, 4x | | `cache_as_bitmap__shape_changed` | 1 | 160x130, 4x | So the cost isn't small in the first case. An 864x864 4x RGBA8 image is about 12 MiB, so `avm2_button` keeps about 330 MiB of retired images after 32 s, and a movie that recreates a cached bitmap about once a second keeps growing until teardown. The unmap retirement has the same retention, but a recreation can happen every frame, which an unmap can't, so I don't think this PR should merge with it. I'm working on freeing a retired target once the commands recorded against it have completed, through `Recorder::Keep`. First I'm checking what else can still hold its image, such as the sampled views it hands out. I'll push that here with a test and a memory reading on the same Ruffle case. AI-assisted: yes (Claude Code)
milescoviello commented 2026-10-18 20:31:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-18T20:31:36Z.


@MarcZX10 pushed 388527d6b2, one commit replacing the retirement. A recreated target is now reimported into its own image instead of being replaced. It keeps its image, views and cached textures, takes the new layout, and imports its contents from the current DCC and CMASK metadata the way a first use does. That means a transfer clear to that color, recorded after the work already recorded against the image. Nothing is retired, so the retention question doesn't come up.

The same Ruffle runs (same stack, 32 s each), with a temporary print counting the multisampled targets the driver holds after each recreation:

Test Recreations Targets held (max) Coarse vs. reference
cache_as_bitmap__avm2_button 28 2 2.4
cache_as_bitmap__avm2_button_state 35 2 1.1
cache_as_bitmap__edittext_hscroll 43 2 no reference image
cache_as_bitmap__morph 2 2 0.5
children_changed, shape_changed, cab_bitmapdata_invalidate 1 each 2 0.1, 0.1, 0.0

The frames match the retiring version's (avm2_button was 2.4 before too). agc_driver_msaa_dcc_clear_{2,4,8} pass 3 of 3, and the 39-test area set passes. The test case is unchanged: the recreated XOR-0x4000 target must start from the new 1111 clear, and a further dccAlphaOnMsb change must still be refused. I updated the description.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6254797192 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7641#issuecomment-6254797192). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-18T20:31:36Z. --- @MarcZX10 pushed 388527d6b2, one commit replacing the retirement. A recreated target is now reimported into its own image instead of being replaced. It keeps its image, views and cached textures, takes the new layout, and imports its contents from the current DCC and CMASK metadata the way a first use does. That means a transfer clear to that color, recorded after the work already recorded against the image. Nothing is retired, so the retention question doesn't come up. The same Ruffle runs (same stack, 32 s each), with a temporary print counting the multisampled targets the driver holds after each recreation: | Test | Recreations | Targets held (max) | Coarse vs. reference | |---|---|---|---| | `cache_as_bitmap__avm2_button` | 28 | 2 | 2.4 | | `cache_as_bitmap__avm2_button_state` | 35 | 2 | 1.1 | | `cache_as_bitmap__edittext_hscroll` | 43 | 2 | no reference image | | `cache_as_bitmap__morph` | 2 | 2 | 0.5 | | `children_changed`, `shape_changed`, `cab_bitmapdata_invalidate` | 1 each | 2 | 0.1, 0.1, 0.0 | The frames match the retiring version's (avm2_button was 2.4 before too). `agc_driver_msaa_dcc_clear_{2,4,8}` pass 3 of 3, and the 39-test area set passes. The test case is unchanged: the recreated XOR-0x4000 target must start from the new 1111 clear, and a further `dccAlphaOnMsb` change must still be refused. I updated the description. AI-assisted: yes (Claude Code)
savvaniss commented 2026-10-18 21:53:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-18T21:53:00Z.


Intel and AMD Windows data: agc_driver_msaa_dcc_clear_2, _4 and _8 fail on main and pass with this PR, 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 388527d6b merged into main f3059421f. "Without" means this PR's test files on main f3059421f, with none of its other changes. That run used the previous head b01a2bfcd, whose test files are the same.

Tests, ×3 UHD 770 RX 9070 XT
This head: agc_driver_alpha_to_coverage, agc_driver_dithered_alpha_to_coverage, agc_driver_msaa_dcc_clear_2, _4, _8 5 of 5 pass 5 of 5 pass
Without the three msaa_dcc_clear tests fail: multisampled DCC target layout or metadata changed same

I also ran full CTest with b01a2bfcd and the 14 other open AGC PRs I tested in the same batch merged together (#7647, #7630, #7627, #7603, #7600, #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)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6255601984 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7641#issuecomment-6255601984). Originally posted by [savvaniss](https://github.com/savvaniss) on 2026-10-18T21:53:00Z. --- Intel and AMD Windows data: `agc_driver_msaa_dcc_clear_2`, `_4` and `_8` fail on `main` and pass with this PR, 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 `388527d6b` merged into `main` `f3059421f`. "Without" means this PR's test files on `main` `f3059421f`, with none of its other changes. That run used the previous head `b01a2bfcd`, whose test files are the same. | Tests, ×3 | UHD 770 | RX 9070 XT | |---|---|---| | This head: `agc_driver_alpha_to_coverage`, `agc_driver_dithered_alpha_to_coverage`, `agc_driver_msaa_dcc_clear_2`, `_4`, `_8` | 5 of 5 pass | 5 of 5 pass | | Without | the three `msaa_dcc_clear` tests fail: `multisampled DCC target layout or metadata changed` | same | I also ran full CTest with `b01a2bfcd` and the 14 other open AGC PRs I tested in the same batch merged together (#7647, #7630, #7627, #7603, #7600, #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 commented 2026-10-19 01:06:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-19T01:06:16Z.


Thanks @savvaniss, the before and after on Intel and AMD is useful. Added to the description. The title now matches the commit: it reimports the target rather than replacing it.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6257475708 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7641#issuecomment-6257475708). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-19T01:06:16Z. --- Thanks @savvaniss, the before and after on Intel and AMD is useful. Added to the description. The title now matches the commit: it reimports the target rather than replacing it. AI-assisted: yes (Claude Code)
adriadam10 commented 2026-10-20 11:18:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T11:18:38Z.


Re-checked against current main: the merge is clean, and the new DCC fill absorption (absorbDccFill) composes with Recreate. A fill noted before the recreation either clears to the same uniform key initialDccClear already imported, or is not taken and the normal fast-clear path runs. The recreated condition, the Recreate clear ordering and the refusal of any other layout change are unchanged, and agc_driver_msaa_dcc_clear_{2,4,8} still fails on main with the refusal message; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6289664450 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7641#issuecomment-6289664450). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-20T11:18:38Z. --- Re-checked against current `main`: the merge is clean, and the new DCC fill absorption (`absorbDccFill`) composes with `Recreate`. A fill noted before the recreation either clears to the same uniform key `initialDccClear` already imported, or is not taken and the normal fast-clear path runs. The `recreated` condition, the `Recreate` clear ordering and the refusal of any other layout change are unchanged, and `agc_driver_msaa_dcc_clear_{2,4,8}` still fails on `main` with the refusal message; merged.
milescoviello commented 2026-10-20 11:26:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-20T11:26:07Z.


Thanks @adriadam10 for checking it against the new DCC fill absorption, and for the merge.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6289786491 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7641#issuecomment-6289786491). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-10-20T11:26:07Z. --- Thanks @adriadam10 for checking it against the new DCC fill absorption, and for the merge. AI-assisted: yes (Claude Code)
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!7641
No description provided.