feat(agc): write a multisampled color target through a storage image #5881
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5881"
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 codingreapermaps on 2026-10-14T14:39:56Z.
What
A program that stores to a 2D multisampled texture (T# type 14) stopped with
storage image access to a multisampled texture is not implemented. PPSA12361 (Transport Fever 2: Console Edition) clears its multisampled color target from a compute program that way when a map loads.MultisampleTargetStorageView). It requires the same format, size and sample count, as the sampled lookup of #4820 does. The program's stores reach the target's samples directly; nothing goes through guest memory.main, plusTRANSFER_SRC. The first storage binding that resolves to it moves it to a new image withVK_IMAGE_USAGE_STORAGE_BIT, and withMUTABLE_FORMAT/EXTENDED_USAGEonly when the storage format differs from the attachment format. Its samples are copied once withvkCmdCopyImage. The previous image, memory and view are kept until the target is released, so a cached framebuffer that names the old view stays valid. Targets nothing stores to keep their image and flags.shaderStorageImageMultisamplefeature, which now reachesContext, and the combined usage at the target's sample count, checked withvkGetPhysicalDeviceImageFormatProperties. Without either, a store throws.createFilled): only when its color memory repeats one 32-bit value, cleared to that value. Other color memory, unmodeled footprints and values without an exact clear color still throw, now saying "writing" instead of "sampling".SettleStorageWrites). A target created from a T# takes the CMASK of the first draw that renders to it, instead of failingCheckAddressbecause it was created without one.#4820 and #5445, which this PR built on, are merged; the branch is one commit on
main.Tested
Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA GeForce MX450 (driver 581.83) and lavapipe (Mesa 26.2.4, mesa-dist-win).
agc_driver_sample_multisample_target_tests, extended with three cases:agc_driver_recorder_tests --multisample-only: a target nothing stored to has no storage usage, also after it is sampled. A storage binding moves it to an image with storage usage and a new view. Without the feature the store is refused. This replaces the check onmainthat expected the store to be refused.mainat44df21632: both tests pass on NVIDIA. The fullagc_driver_recorder_testsstops at(9) a scan under a pending write was kept(Recorder.cpp:1332) on this machine, also on plainmainat the same commit.storage image access to a multisampled texture is not implemented. With it, the suite passes twice in a row on NVIDIA and on lavapipe.agc_driver_graphics_testspasses.mainit stops with the error above while a map loads. On a local branch with this change, #5445, #4820 and the other changes the title still needs, the map loads and renders, and the camera moves. No store was refused: the surface the compute program clears held uniform color memory.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)Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T17:19:19Z.
Review: COMMENTED
Resolving the store to the host multisampled target, so nothing goes through guest memory, is the right model for a compute clear. The
vkGetPhysicalDeviceImageFormatPropertiescheck before adding the usage is careful.My concern is cost on every title that renders MSAA, not only Transport Fever 2. In
MultisampleTarget's constructor,VK_IMAGE_USAGE_STORAGE_BITis added to every multisampled color target whose format the device can store at that sample count.MUTABLE_FORMAT_BIT | EXTENDED_USAGE_BITis added as well whenever the storage format differs from the attachment format. This happens at creation, before anything is known to store to the target. Drivers commonly drop color compression for images created with storage usage or a mutable format: RADV on several GFX levels skips DCC for storage-capable or mutable images whose formats aren't DCC-compatible, and other vendors make similar choices. For MSAA targets that means more bandwidth on every draw and every resolve. The effect wouldn't show in this PR's tests, only as a lower frame rate in MSAA-heavy scenes.Two ways to keep the default path unchanged:
aps5-summary.jsonlpair from an MSAA title that never stores to its targets, on AMD and NVIDIA, would show whether any driver here actually loses compression.A smaller point: the image also gains
SAMPLED_BITwhenever that is supported. If that comes from #4820/#5445, it's outside this PR's own commit. Otherwise it has the same compression question.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:11:02Z.
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)core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cppL92-107, L190-191, L335-336core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cppL85-86core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cppL92-107, L113-116, L133, L190-191, L278-279, L335-336core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cppL187, L336core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cppL220-221, L343core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cppL85-86core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cppL72, L343core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cppL128-129, L190-191, L481core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cppL72, L202, L208, L220-221core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cppL61, L65-66, L68, L91-107, L128, L195-198core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cppL187, L336core/libs/prx/libSceAgcDriver/tests/execution/SampleMultisampleTarget.cppL220-221, L343core/libs/prx/libSceAgcDriver/Graphics/src/MultisampleTarget.cppL92-107, L190-191, L335-336Some 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/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Context.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/include/Texture.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T14:11:11Z.
Review: CHANGES_REQUESTED
Checked on the PR rebased onto current main (only the last commit is new; conflict was adjacency with
MaterializeMultisampleTargetClear): builds,agc_driver_sample_multisample_targetpasses and fails without the change.One blocking point, the same one @CnRJay raised and that is still unanswered:
MultisampleTarget.cpp:74addsVK_IMAGE_USAGE_STORAGE_BIT(andMUTABLE_FORMAT/EXTENDED_USAGEat :68/:77 when the storage format differs) to every multisampled color target at creation, before anything stores to it. Drivers may drop color compression for such images, which would cost bandwidth in every title that renders MSAA, and none of the tests would show it. Either create the storage-capable image only when a storage binding first resolves to the target (keeping the default path unchanged), or post a before/after frame-time comparison from an MSAA title that never stores to its targets, on AMD and NVIDIA.Not covered by us: Transport Fever 2 and the Windows/MX450 runs. Happy to re-review once the usage is lazy or measured.
Imported from boykopovar/AnyPS5. Originally posted by codingreapermaps on 2026-10-15T19:22:55Z.
Thanks both. The storage usage is now lazy, and the branch is rebased onto current
main(#4820 and #5445 are merged, so this PR is now only its own commit).main: noSTORAGE_BIT, noMUTABLE_FORMAT/EXTENDED_USAGE. The only addition isTRANSFER_SRC_BIT, which the one-time copy below needs.vkCmdCopyImage(same format and sample count on both sides). Targets that are never stored to keep their current image.mainalready does for targets retired by an unmap. Cached framebuffers can still name the old view, so it is never destroyed while one of them could be used, and no recycled handle can match them. Sampled textures of the old image are kept by the recorder.shaderStorageImageMultisample, which the previous version did not check. The device's enabled value now reachesContext, and without it a storage access throwsthe device cannot write the multisampled color target's format as a storage image at its sample count.SAMPLED_BIT: that comes from #4820 (now merged), so it is outside this PR.Tests:
agc_driver_recorder_tests: a target nothing stored to has no storage usage. That stays true after it is sampled. After a storage binding resolves to it, it has storage usage and a new view. The test onmainthat expected storage access to a multisampled texture to be refused now checks this instead. Without the feature, the new refusal is checked.agc_driver_sample_multisample_target_tests: the store into one sample of each pixel of a drawn target goes through the copy, and the samples it does not store to are compared with their drawn values.On
mainat44df21632, Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA GeForce MX450 (driver 581.83):agc_driver_sample_multisample_target_testsandagc_driver_recorder_tests --multisample-onlypass.tools/check_conventions.pypasses. The fullagc_driver_recorder_testsstops at(9) a scan under a pending write was kept(Recorder.cpp:1332, the DCC key scan) on this machine, both with this branch and with plainmainat the same commit, so it is unrelated to this PR.I have no AMD card here, so I can't post an AMD frame-time pair. With the default path unchanged apart from
TRANSFER_SRC, I hope that isn't needed any more. If you'd rather dropTRANSFER_SRCfrom the default flags too, the copy could go through a sampled read instead. Tell me if you want that.Imported from boykopovar/AnyPS5. Originally posted by Amoenus on 2026-10-15T20:35:21Z.
Independent validation and a recorder-test correction
@codingreapermaps, tested your head
9666c3e102f46e4fa601e7c5c11712b3c83df858on Windows 11 Enterprise 26200, WinLibs GCC15.2r7 Release, NVIDIA RTX5080 /32.0.16.1062 and AMD Radeon Graphics /32.0.21036.18. Shader cache disabled, Vulkan required, serial runs and a 30s limit.6d427676f). Eleven related groups pass five iterations per GPU selector: 55 per selector, ten groups with physical GPU identity verified per selector and one CPU-only group. Maximum test 11.14s.ce991f1ec2eb71a1f30459b4442a0730a0a4861b, the same extended storage fixture fails 5/5 per GPU withstorage image access to a multisampled texture is not implemented. Only test code and #6452 differ from main.One test correction:
tests/Recorder.cppqueriesVkPhysicalDeviceFeatures, but neither enablesshaderStorageImageMultisamplenor propagates it tocontext.storageImageMultisample. Consequently the newif (context.storageImageMultisample)positive upgrade assertion is unreachable. A diagnostic-only control passes 5/5 NVIDIA runs withfeature-enabled=0, taking the refusal branch. This two-line correction enables the supported feature and records the enabled value in the context; the positive view-replacement/storage-usage assertions then pass 5/5 withfeature-enabled=1(and again after restoration).The private recorder fixture selects NVIDIA on this machine independently of
ANYPS5_GPU, so its results above are NVIDIA-only. The end-to-end storage/redraw fixture separately verifies both vendors. No Linux, Transport Fever 2 launch, compression or frame-time claim. Cppcheck reports the same 45 advisories on the pinned baseline and corrected test files with matching messages/source contexts; clang-tidy reports none. Existing advisories remain unresolved. AI-assisted: Codex.Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-16T11:11:22Z.
Cross-validation on Windows 11 Pro 26220, NVIDIA RTX 4070 (596.21), WinLibs MinGW-w64 GCC 15.2, PR head
9666c3e10merged on main5d9dcc42d(clean). NVIDIA only; I have no AMD card either.On the ask (lazy storage usage or a before/after from an MSAA title that never stores): the lazy part is in
9666c3e10, and here is the measurement.libspass except the known 64 KiBalignasAGC test (#6452/#6478).agc_driver_sample_multisample_targetandagc_multisample_guest_access,--repeat until-fail:3: 3 of 3 each. Negative control: withMultisampleTarget.cpp,ShaderResources.cppandTexture.cppreverted to main (headers and tests kept),agc_driver_sample_multisample_targetfails 3 of 3 withAGC graphics: storage image access to a multisampled texture is not implemented; restored, it passes.agc_storage_*,agc_recorder_*, serial): 86 of 86 pass. Non-GPU suite (837 tests): 835 pass;conventions_function_bodies_shard_4andhardware_oracle_comparetime out under load and pass serially.tools/check_conventions.pyandgit diff --checkpass.MultisampleTargetconstructor and in the move to the storage image: onecreated, no move, 50 s). 3 runs of 120 s on main and 3 on the PR, interleaved,APS5_TRACE_SUMMARY_EVERY=10, no input, no stop line in any run. The title is paced at 60 FPS, so frame time is the same: p50 16.68 ms in all six runs; p90 16.91 ms (16.89 to 17.22) on main, 16.90 ms (16.88 to 16.91) with the PR; p99 17.38 ms (17.10 to 26.10) vs 17.25 ms (17.07 to 18.52). GPU busy per present, which is where a lost compression would show: 1.89 ms (1.51 to 1.95) on main, 1.76 ms (1.40 to 1.85) with the PR. Host CPU load (shared machine): main 81% median (47 to 85), PR 61% (52 to 73). The frame dumps match. So on NVIDIA the default path shows no cost; a 2-sample 1080p target is a weak test of the compression concern, and it says nothing about AMD.vid_fsaa 4creates a 3840x2160 4-sample target and then stops after 14 s on main'sAGC graphics: DCC over a multisampled color target is unsupported; Ruffle (idle and demo) creates none; ProsperoPuzzles stops earlier on #6301.tests/Recorder.cppnever setscontext.storageImageMultisample(the only use is the newifat line 6317), so the positive upgrade assertions inagc_multisample_guest_accessare not reached and the refusal branch runs; this is what Amoenus described.agc_driver_sample_multisample_targetcovers the positive path.Written with Claude Code assistance (validation by a subagent, reviewed in this session).
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T12:00:39Z.
Cross-PR test interaction to coordinate with #6590: nicolasfalesy reports that
agc_driver_sample_multisample_targetpasses on main and on each PR head separately, but fails 2/2 on the combined tree at the final sample check after #6590's four refused native-index draws. Their report is on #6590. I confirmed the current #5881 (9666c3e) and #6590 (881facc4) heads merge cleanly; I have not localized the runtime cause. I asked for the exact base pin and composition details so we can determine whether the current heads still reproduce it.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T12:14:33Z.
Review: APPROVED
Re-checked on current main: the diff is unchanged and storage usage stays lazy.
Added on your branch (fix-merge):
tests/Recorder.cpp: the test device now enablesshaderStorageImageMultisampleand setscontext.storageImageMultisample, so theif (context.storageImageMultisample)branch is reachable (found by @Amoenus).Checked: build + ctest on the PR rebased onto main;
agc_driver_sample_multisample_targetpasses, the only failure isagc_driver_tessellation, which also fails on main. Not verified here: the title run, AMD/NVIDIA frame times, and the interaction with #6590 reported by @MarcZX100. Merging.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T12:15:39Z.
A composition report on #6590 points to a test-order interaction with this PR: the combined
SampleMultisampleTarget.cpprunsStoreSamplesagainstblockand writesWrittento sample 1 of every pixel, then #6590’s laterCheckNativeIndicesreusesblockas its source while asserting every sample is stillOnes. The reported first differing sample is exactly the value written by this PR’s test. This looks like the #6590 fixture should run before those stores or restore its input state, rather than a production-path regression. The combined tree isb8e65cb4e40e254c62f16ceb48608236b4672797. I could not run the test locally because this Linux host fails the project’s AVX2/BMI CPU guard.