Repository navigation
fix(agc): reimport a multisampled target recreated with another pipe-bank XOR - #7641
Conversation
MarcZX10
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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.
|
@MarcZX10 yes, that's the guarantee. 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) |
|
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.
|
|
@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:
So the cost isn't small in the first case. An 864x864 4x RGBA8 image is about 12 MiB, so AI-assisted: yes (Claude Code) |
…bank XOR
RADV gives each image its own pipe-bank XOR when it creates it. When Ruffle
recreates a 4x render target on the same memory, the next draw names the
same surface, DCC and CMASK with another XOR, and the resident target refused
it as a changed layout ("multisampled DCC target layout or metadata
changed"). A use that differs from a resident DCC target only in that XOR now
keeps the target's image, views and cached textures, takes the new layout,
and reimports its contents from the current DCC and CMASK metadata the way a
first use does, clearing the image to that color after the work already
recorded against it. Any other layout change is still refused.
Reusing the image keeps memory flat: Ruffle's cache_as_bitmap__avm2_button
recreates its 864x864 4x target 28 times in 32 s.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
b01a2bf to
388527d
Compare
|
@MarcZX10 pushed 388527d, 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:
The frames match the retiring version's (avm2_button was 2.4 before too). AI-assisted: yes (Claude Code) |
|
Intel and AMD Windows data: Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built,
I also ran full CTest with AI-assisted: yes (Claude Code) |
|
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) |
|
Re-checked against current |
|
Thanks @adriadam10 for checking it against the new DCC fill absorption, and for the merge. AI-assisted: yes (Claude Code) |
What
acquireinMultisampleTarget.cppreuses a resident multisampled target for any use with the same surface address, format, extent and sample count.checkDccCurrentthen requires every other layout field to match, and refuses withmultisampled DCC target layout or metadata changed.In Ruffle (PPSA68091), 7 of Ruffle's own
cache_as_bitmapvisual 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: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:
recreatedis true when a use differs from a resident target only in its pipe-bank XOR.acquirethen 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.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_buttonrecreates 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).
DccFastClearTests(agc_driver_msaa_dcc_clear_{2,4,8}) runs for each sample count:dccAlphaOnMsbmust still be refused.main'sMultisampleTarget.cpp, all three fail withmultisampled DCC target layout or metadata changed.^agc_driver_graphics$|msaa|multisample|dcc|cmask|fmask|alpha_to_coverage|fill|dispatchpass.tests/tests/swfs/visual), each the only game in the library, 32 s. These cases need fix(agc): take RADV's fill-memory kernel as a buffer fill #6543 and feat(agc): take a full DCC fill of a resident multisampled target as its fast clear #7250 to get this far, so the stack ismain385ed71 + fix(agc): take RADV's fill-memory kernel as a buffer fill #6543 + feat(agc): take a full DCC fill of a resident multisampled target as its fast clear #7250 + fix(agc): separate possible writes from complete coverage #7233 + feat(agc): take RADV's comp-to-single clear of a multisampled DCC target #7600. "Coarse" is the mean difference of 32x24-cell averages between the last frame and the test'soutput.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:
cache_as_bitmap__avm2_buttonmultisampled DCC target layout or metadata changedcache_as_bitmap__avm2_button_statecache_as_bitmap__edittext_hscrollcache_as_bitmap__morphcache_as_bitmap__children_changed,__shape_changed,__cab_bitmapdata_invalidatetools/check_conventions.py --base upstream/mainpasses.tools/pr_overlap.pylists no overlapping lines with open pull requests. The retirement sits insideacquire's loop, andrecreatedbesidesameTarget, away from the lines that #6215, #6973, #6987, #6989, #6995 and #7002 change.mainf305942,agc_driver_alpha_to_coverage,agc_driver_dithered_alpha_to_coverageandagc_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 onmain, the threemsaa_dcc_cleartests fail withmultisampled DCC target layout or metadata changed.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest -R '^agc_' -Vonmainf29546a and onmain+ this PR (388527d, a local merge).main: 812 of 812 pass; with this PR: 812 of 812 pass. Neither log reports the layer missing. VUIDs onmain: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 ofmain's is the subject of an open PR: 00118 fix(agc): give copied guest buffer regions transfer-source usage #7961, 04553 fix(shader): point-filter direct samplers paired with unsigned integer images #7707, 07285 fix(agc): copy a linked pipeline's color sample counts only when it has color attachments #7985, 01158 and 09543 fix(agc): hold a pending producer batch with a timeline semaphore #7913, 00605 fix(agc): enable independentBlend for color targets with different blend states #6782, 02275 fix(agc): restrict sampled storage texture view usage #862.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code