Skip to content

feat(agc): write a multisampled color target through a storage image - #5881

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
codingreapermaps:feat/agc-msaa-storage-write
Oct 16, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
codingreapermaps:feat/agc-msaa-storage-write

Conversation

@codingreapermaps

@codingreapermaps codingreapermaps commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

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.

  • A storage binding of a 2D multisampled T# now resolves to a storage view of the host multisampled color target at its address (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.
  • Storage usage is added lazily. A multisampled target is created with the flags it has on main, plus TRANSFER_SRC. The first storage binding that resolves to it moves it to a new image with VK_IMAGE_USAGE_STORAGE_BIT, and with MUTABLE_FORMAT/EXTENDED_USAGE only when the storage format differs from the attachment format. Its samples are copied once with vkCmdCopyImage. 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.
  • The storage image needs the device's shaderStorageImageMultisample feature, which now reaches Context, and the combined usage at the target's sample count, checked with vkGetPhysicalDeviceImageFormatProperties. Without either, a store throws.
  • A surface no draw rendered to is created the way fix(agc): sample a multisampled texture no draw rendered to from its uniform color memory #5445 creates it for sampling (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".
  • A draw or sample after the stores waits for them (SettleStorageWrites). A target created from a T# takes the CMASK of the first draw that renders to it, instead of failing CheckAddress because it was created without one.
  • These still throw: storage atomics on a multisampled texture, a storage view in another format than the target's storage format, a target with a CMASK fast clear no draw has applied, and stores outside a recorded dispatch.

#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:
    • a compute program stores a color into sample 1 of every pixel of the drawn 4x RGBA16F target; loading every sample back finds the color in sample 1 and the drawn triangle unchanged in samples 0, 2 and 3;
    • stores into samples 1 to 3 of the left half of a surface no draw rendered to, whose color memory is zero, are found there, and every other sample loads zero;
    • a store into a surface no draw rendered to whose color memory is not uniform is refused.
  • 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 on main that expected the store to be refused.
  • Rebased on main at 44df21632: both tests pass on NVIDIA. The full agc_driver_recorder_tests stops at (9) a scan under a pending write was kept (Recorder.cpp:1332) on this machine, also on plain main at the same commit.
  • Before the rebase, on fix(agc): sample a multisampled texture no draw rendered to from its uniform color memory #5445's head without this commit, the test stops with 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_tests passes.
  • PPSA12361: on main it 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

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed build shader core/shader agc libSceAgc* labels Oct 14, 2026

@CnRJay CnRJay left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.jsonl pair 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.

This was referenced Oct 15, 2026

@adriadam10 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:74 adds VK_IMAGE_USAGE_STORAGE_BIT (and MUTABLE_FORMAT/EXTENDED_USAGE at :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.

@codingreapermaps
codingreapermaps force-pushed the feat/agc-msaa-storage-write branch from f71756e to 9666c3e Compare October 15, 2026 19:22
@codingreapermaps

Copy link
Copy Markdown
Contributor Author

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).

  • A multisampled target is created with the same flags as on main: no STORAGE_BIT, no MUTABLE_FORMAT/EXTENDED_USAGE. The only addition is TRANSFER_SRC_BIT, which the one-time copy below needs.
  • The first storage binding that resolves to a target moves it to a new image with storage usage (and the mutable flags when the storage format differs). Its samples are copied once with vkCmdCopyImage (same format and sample count on both sides). Targets that are never stored to keep their current image.
  • The old image, memory and view are kept until the target is released, as main already 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.
  • Creating a multisampled image with storage usage also needs shaderStorageImageMultisample, which the previous version did not check. The device's enabled value now reaches Context, and without it a storage access throws the device cannot write the multisampled color target's format as a storage image at its sample count.
  • @CnRJay, on SAMPLED_BIT: that comes from feat(agc): sample a multisampled color target through its 2D MSAA texture #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 on main that 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 main at 44df21632, Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA GeForce MX450 (driver 581.83): agc_driver_sample_multisample_target_tests and agc_driver_recorder_tests --multisample-only pass. tools/check_conventions.py passes. The full agc_driver_recorder_tests stops 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 plain main at 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 drop TRANSFER_SRC from the default flags too, the copy could go through a sampled read instead. Tell me if you want that.

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

Amoenus commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Independent validation and a recorder-test correction

@codingreapermaps, tested your head 9666c3e102f46e4fa601e7c5c11712b3c83df858 on 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.

One test correction: tests/Recorder.cpp queries VkPhysicalDeviceFeatures, but neither enables shaderStorageImageMultisample nor propagates it to context.storageImageMultisample. Consequently the new if (context.storageImageMultisample) positive upgrade assertion is unreachable. A diagnostic-only control passes 5/5 NVIDIA runs with feature-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 with feature-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.

@screamm

screamm commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Cross-validation on Windows 11 Pro 26220, NVIDIA RTX 4070 (596.21), WinLibs MinGW-w64 GCC 15.2, PR head 9666c3e10 merged on main 5d9dcc42d (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.

  • Build: full build and libs pass except the known 64 KiB alignas AGC test (test(agc): align the indirect arguments block at run time #6452/fix(agc): allocate indirect arguments test block dynamically on Windows #6478).
  • agc_driver_sample_multisample_target and agc_multisample_guest_access, --repeat until-fail:3: 3 of 3 each. Negative control: with MultisampleTarget.cpp, ShaderResources.cpp and Texture.cpp reverted to main (headers and tests kept), agc_driver_sample_multisample_target fails 3 of 3 with AGC graphics: storage image access to a multisampled texture is not implemented; restored, it passes.
  • 86 related GPU tests (multisample, msaa, storage, cmask, dcc, sample mask, resolve, fills, agc_storage_*, agc_recorder_*, serial): 86 of 86 pass. Non-GPU suite (837 tests): 835 pass; conventions_function_bodies_shard_4 and hardware_oracle_compare time out under load and pass serially. tools/check_conventions.py and git diff --check pass.
  • Title: Middle Ages Ping Pong PPSA28319 creates one 1920x1080 2-sample color target and never stores to it (a throwaway print in the MultisampleTarget constructor and in the move to the storage image: one created, 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.
  • No local title stores to an MSAA target. vkQuake with vid_fsaa 4 creates a 3840x2160 4-sample target and then stops after 14 s on main's AGC graphics: DCC over a multisampled color target is unsupported; Ruffle (idle and demo) creates none; ProsperoPuzzles stops earlier on AGC: since #6060, ProsperoPuzzles (PPSA99006) stops at 5 s with the storage-image write-back throw on Windows #6301.
  • tests/Recorder.cpp never sets context.storageImageMultisample (the only use is the new if at line 6317), so the positive upgrade assertions in agc_multisample_guest_access are not reached and the refusal branch runs; this is what Amoenus described. agc_driver_sample_multisample_target covers the positive path.
  • Not checked: AMD, Intel, Linux, Transport Fever 2, any title that stores to an MSAA target.

Written with Claude Code assistance (validation by a subagent, reviewed in this session).

@MarcZX10

Copy link
Copy Markdown
Contributor

Cross-PR test interaction to coordinate with #6590: nicolasfalesy reports that agc_driver_sample_multisample_target passes 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.

codingreapermaps and others added 2 commits October 16, 2026 14:08
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 adriadam10 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 enables shaderStorageImageMultisample and sets context.storageImageMultisample, so the if (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.

@adriadam10
adriadam10 force-pushed the feat/agc-msaa-storage-write branch from 9666c3e to 6c67548 Compare October 16, 2026 12:14
@MarcZX10

Copy link
Copy Markdown
Contributor

A composition report on #6590 points to a test-order interaction with this PR: the combined SampleMultisampleTarget.cpp runs StoreSamples against block and writes Written to sample 1 of every pixel, then #6590’s later CheckNativeIndices reuses block as its source while asserting every sample is still Ones. 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 is b8e65cb4e40e254c62f16ceb48608236b4672797. I could not run the test locally because this Linux host fails the project’s AVX2/BMI CPU guard.

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

Labels

agc libSceAgc* build shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants