Skip to content

GPU: refresh a texture alias after its source is written again - #2341

Open
andrewpozdnakov7-jpg wants to merge 2 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:fix/refresh-gpu-alias-after-source-write
Open

andrewpozdnakov7-jpg wants to merge 2 commits into
Marvisak:mainfrom
andrewpozdnakov7-jpg:fix/refresh-gpu-alias-after-source-write

Conversation

@andrewpozdnakov7-jpg

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

Copy link
Copy Markdown
Contributor

A placed texture alias was copied once per command list. A later GPU write to its source could leave the next alias read on older contents. Recopying after a write to the alias itself can also overwrite that newer destination data.

Keep the source host texture and its write version from the last alias copy. A write to the destination keeps that record. A new source version makes another copy necessary.

The synthetic WARP test records a red write to the R32G32_UINT source, a blue write to the BC1 alias destination, then a green write to the source. It reads the alias after each write and directly verifies the final source block.

Implementation First alias read After destination write After second source write
Main 67e8ae1401df112248aed36d0024483181b718b7 red blue blue
Previous destination-invalidation rule on the same base red red green
Updated 075b2ac4d1c15d4902bfe231346585998ffdb2e3 red blue green

Full GPU suite on WARP had 199 passes and 1 ignored under both D3D12 debug flag settings. Strict GPU Clippy passed with default and all features, and the asset policy passed. AI-assisted. Test data is synthetic.

Please preserve the Git author if you cherry-pick the change. If you fold the code or regression into another commit, please include the trailer below.

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

Coordination claim

Cache an alias by the source texture and its last write in the command list. A write-capable use invalidates that record even after another read changes the source state. Exercise both GPU writes and read the placed alias twice in a single WARP submission.

@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:

  • Refreshing a texture alias when its source is written again in the same command list cleanly prevents stale placed reads after subsequent GPU writes.
  • cargo test -p victory-gpu resource::tests: 11/11 passed on RTX 5090, 11/11 passed on WARP (including live GPU test a_second_gpu_write_reaches_the_placed_alias_in_the_same_list).
  • cargo test -p victory-gpu texture::tests: 2/2 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

I tested this change together with #2314 at 1735610. Git combines both branches cleanly. The direct multisampled path also needs to record the completed alias copy so another read can reuse it until the next write.

Combined branch and test 76381a5 preserves both PR heads. The WARP fixture records two depth clears. It checks that the second write invalidates the original copy, its resolve reads 0.625, and each completed copy satisfies a subsequent read. The reuse assertion failed in the plain merge and passed with the added recording call. Both alias tests passed together. The full GPU suite gave 148 passed, 2 ignored. Strict GPU Clippy in both modes and repository policy passed.

If the code or tests are folded into another commit, please add:

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

AI-assisted. Synthetic tests only.

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

Texture alias refreshed after its source is written — TextureState tracks write_version and alias_source. 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. Aliasing coherence fix; ties to #2226/#2276 cluster.

@Machad3x

Machad3x commented Nov 25, 2026 •

Copy link
Copy Markdown

Correction: please disregard this as evidence against this PR.

Later runs of stacks without this PR showed an equally dark picture, so the single pair of runs I compared does not attribute it to this PR. I have no result for or against this change.

AI-assisted (Claude Code).

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. HostList in crates/victory-gpu/src/host.rs now keeps a TextureState per texture, with a write_version that track raises on each move into a write state (render target, UAV, depth write, copy or resolve destination) and that a twin route also raises. Each alias destination stores alias_source, the source and its version at the last copy. texture::alias_copy copies again only when the source has a newer version (alias_copy_is_current), where before it copied once per list (first_use(to | 1)). So a second GPU write to the source reaches the alias, and a write to the alias itself survives until the source changes. Both textures are tracked before record_alias_copy runs. The copy moves the source to copy-source, so its next write is a new transition and raises the version. The WARP test in resource.rs covers the source, alias, source write sequence and reads the final source directly.

On your reply: the #2314 integration (the direct multisampled path also calling record_alias_copy) belongs to whichever of the two PRs lands second. It does not block this one.

CI: check passing.


Generated by Claude Code

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

Updated the branch to main 67e8ae1401df112248aed36d0024483181b718b7 and kept the original HEAD in its history. The new fixture writes to the alias destination between two source writes. The main baseline reads red/blue/blue. Applying the previous destination-invalidation rule to the same test reads red/red/green. The updated code reads red/blue/green, and the direct final source read is green. Updated commit

The source's version now controls whether to recopy. The destination's own write leaves that record in place. Full GPU suite on WARP passed with 199 passed and 1 ignored in both D3D12 debug flag settings. Strict GPU Clippy and the asset policy passed.

Please preserve our Git author if taking the change or test into another branch. If folding them into another commit, please include this trailer.

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

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

I checked the direct MSAA path on a composition of main 13f91ca, #2314 at 8c8cfb4 and #2341 at 075b2ac. The combined path needs both the updated CopyResource arguments and the alias version record used by the footprint path.

With the argument adjustment alone, the same WARP test resolves 0.375, then overwrites a destination-only clear of 0.625 with 0.375. With the version record, all 16 texels resolve to 0.375, then 0.625, then 0.875 after a new source write. Six paired runs across both debug settings reproduced the difference. The serial GPU suite passed 200 tests with one ignored in each setting, and strict GPU Clippy and asset policy passed.

Integration commit aea413d contains the small adaptation and extended readback test above the two exact PR heads. If you fold the adaptation or test into another commit, please keep the Git attribution with:

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

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