Repository navigation
feat(agc): write a multisampled color target through a storage image - #5881
Conversation
CnRJay
left a comment
There was a problem hiding this comment.
Resolving the store to the host multisampled target, so nothing goes through guest memory, is the right model for a compute clear. The vkGetPhysicalDeviceImageFormatProperties check 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_BIT is added to every multisampled color target whose format the device can store at that sample count. MUTABLE_FORMAT_BIT | EXTENDED_USAGE_BIT is 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:
- Create the storage-capable image only on first use. When a storage binding first resolves to a target created without the usage, recreate (or alias) it with storage usage, copying the samples once. Targets that are never stored to keep their current flags.
- Or measure it. A before/after
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_BIT whenever that is supported. If that comes from #4820/#5445, it's outside this PR's own commit. Otherwise it has the same compression question.
adriadam10
left a comment
There was a problem hiding this comment.
Checked on the PR rebased onto current main (only the last commit is new; conflict was adjacency with MaterializeMultisampleTargetClear): builds, agc_driver_sample_multisample_target passes 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.
f71756e to
9666c3e
Compare
|
Thanks both. The storage usage is now lazy, and the branch is rebased onto current
Tests:
On I have no AMD card here, so I can't post an AMD frame-time pair. With the default path unchanged apart from |
Independent validation and a recorder-test correction@codingreapermaps, tested your head
One test correction: The private recorder fixture selects NVIDIA on this machine independently of |
|
Cross-validation on Windows 11 Pro 26220, NVIDIA RTX 4070 (596.21), WinLibs MinGW-w64 GCC 15.2, PR head On the ask (lazy storage usage or a before/after from an MSAA title that never stores): the lazy part is in
Written with Claude Code assistance (validation by a subagent, reviewed in this session). |
|
Cross-PR test interaction to coordinate with #6590: nicolasfalesy reports that |
A program that stores to a 2D multisampled texture writes the samples of its host multisampled color target through a storage view. Targets are created without storage usage; the first storage binding that resolves to a target moves it to an image with storage usage, copying its samples once, and keeps the previous image until the target is released. Storage usage needs the device's shaderStorageImageMultisample feature and its format at the target's sample count. A surface no draw rendered to is created from its uniform color memory, as for sampling; other color memory still throws. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…device Co-Authored-By: Claude <noreply@anthropic.com>
adriadam10
left a comment
There was a problem hiding this comment.
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_target passes, the only failure is agc_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.
9666c3e to
6c67548
Compare
|
A composition report on #6590 points to a test-order interaction with this PR: the combined |
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 feat(agc): sample a multisampled color target through its 2D MSAA texture #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, fix(agc): sample a multisampled texture no draw rendered to from its uniform color memory #5445, feat(agc): sample a multisampled color target through its 2D MSAA texture #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)