Skip to content

GPU: copy compatible multisampled texture aliases directly - #2314

Open
andrewpozdnakov7-jpg wants to merge 2 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:fix/msaa-texture-alias-copy
Open

andrewpozdnakov7-jpg wants to merge 2 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:fix/msaa-texture-alias-copy

Conversation

@andrewpozdnakov7-jpg

@andrewpozdnakov7-jpg andrewpozdnakov7-jpg commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

A multisampled alias could go through the linear-buffer path in alias_copy. D3D12 requires matching sample counts for the copy. The multisampled path now uses CopyResource when the actual host dimensions, mip counts, sample descriptions and format families match. It keeps the current main's deferred host writes. D3D12 copy rules

The same WARP test clears a synthetic 4x MSAA D32_FLOAT texture to 0.375 and its R32_FLOAT alias to -0.5. On main at 67e8ae1, closing the list after the alias copy returns E_INVALIDARG. With 8c8cfb4, the list closes and all 16 resolved pixels read 0.375. Serial victory-gpu on WARP passed with 199 passed and 1 ignored in both debug flag settings. Strict GPU Clippy in both modes and repository policy passed. In five parallel runs per arm, the existing submission-copy test failed twice on main and three times on the patch. The descriptor rewrite test also failed once on the patch.

Coordination claim

Please preserve the Git author when reapplying the change. If you fold the code or test into another commit, please add this trailer.

Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com

AI-assisted. Synthetic tests only.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Allowing compatible multisampled texture aliases to copy directly via CopyResource cleanly preserves all samples without going through a staging buffer.
  • cargo test -p victory-gpu resource::tests: 11/11 passed on RTX 5090 (including multisampled_aliases_copy_all_samples).
  • cargo test -p victory-gpu texture::tests: 2/2 passed on RTX 5090, 2/2 passed on WARP.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

@catminou4 catminou4 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.

Copy-compatible multisampled texture aliases copy all samples directly (+104 host-GPU test). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

I checked the overlap with #2275 at b6a9ebe. Git reports a conflict beside the start of alias_copy. The tested combination dac5b2b keeps the direct MSAA path first and checks the array mip count before the single-sample footprint path. It preserves both original histories and includes both WARP readback tests.

Both regressions passed together. Full forced-WARP GPU suite gave 149 passed, 2 ignored. GPU Clippy in both feature modes and repository policy passed. #2274 at 8a88297 merges cleanly with this PR individually (textual merge checked).

If you fold our changes or tests into another commit, please keep:

Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com

AI-assisted. Synthetic tests only.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate.

On main, texture::alias_copy sends multisampled aliases through the single-sample buffer-footprint path, which gives an invalid list (E_INVALIDARG at Close). This PR copies them with CopyResource when the sample description, dimensions, mip and array counts and format family (resource::family) match. Otherwise it logs once and skips the copy. The checks match D3D12's CopyResource rules, and the existing host-write and state transitions are kept through prepare. The WARP test multisampled_aliases_copy_all_samples clears a 4x D32 depth texture and its R32 alias to different values, copies, resolves and checks every pixel, so it tests what is correct rather than what the code does.

This overlaps alias_copy in #2275. Whichever merges second will need a small rebase; the author has posted a tested combination.

CI (check): passing.


Generated by Claude Code

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

Updated the branch for current main at 67e8ae1. The same WARP test fails at native command list Close with E_INVALIDARG on main and resolves all 16 pixels to 0.375 with the patch. Serial GPU tests passed in both debug flag settings (199 passed, 1 ignored). The existing submission-copy test was intermittent in parallel on both revisions. The descriptor rewrite test failed once in the patched parallel runs. Strict GPU Clippy and repository policy passed.

Updated branch commit

If you fold the change or test into another commit, please preserve the Git author or add this trailer.

Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com

@fuzeofficlal fuzeofficlal 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.

Reviewed 8c8cfb4f8559 merged cleanly onto 63bcca43.

The direct multisampled copy path in crates/victory-gpu/src/texture.rs:252-290 handles MSAA texture aliases cleanly:

  • Guards CopyResource behind exact agreement on SampleDesc, (Dimension, Width, Height, DepthOrArraySize, MipLevels), and resource::family(Format) (texture.rs:274-284), falling back to a logged skip for incompatible multisampled aliases instead of routing them through a single-sample linear staging buffer.
  • Shares the prepare helper (texture.rs:268-272) so host_writes(list, to) and COPY_SOURCE/COPY_DEST transitions stay consistent with the single-sample path.

Hardware & D3D12 Debug Layer verification (RTX 5090 + Microsoft WARP, VICTORY_D3D12_DEBUG=1):

  • cargo xtask policy and cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --all-features) pass cleanly.
  • resource::tests::multisampled_aliases_copy_all_samples passes on both RTX 5090 and WARP under VICTORY_D3D12_DEBUG=1.
  • Verified an additional Debug Layer probe exercising 4 incompatible MSAA pairs (4x->1x, 4x->2x, 4x4->8x8, and R32_TYPELESS->R8G8B8A8_UNORM 4x) and 2 compatible 4x MSAA pairs (D32_FLOAT->R32_FLOAT and D16_UNORM->R16_UNORM): all 4 incompatible cases skipped without incrementing ALIAS_COPIES, both compatible cases copied directly via CopyResource, GetDeviceRemovedReason().is_ok(), and host.log_messages() == None on both RTX 5090 and WARP.
  • Also verified a clean 3-way co-merge with #2319 and #2358 on 63bcca43 with all three GPU tests passing under VICTORY_D3D12_DEBUG=1 on both adapters.

LGTM.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants