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

Open
github-bot wants to merge 2 commits from github-bot/gh-2341 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 11:07 UTC · original
andrewpozdnakov7-jpg:fix/refresh-gpu-alias-after-source-write → main · +183 −22 · 3 files · 2 commits · open

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 [email protected]

Coordination claim

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 11:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/2341) `andrewpozdnakov7-jpg:fix/refresh-gpu-alias-after-source-write` → `main` · +183 −22 · 3 files · 2 commits · open 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 <[email protected]> [Coordination claim](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633)
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:02:49 +00:00
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 11:28 UTC · original

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 [email protected]

AI-assisted. Synthetic tests only.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 11:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/2341#issuecomment-7161084274) 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`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/76381a53a80a726eb6a2b9d4a9ba6660e9f08db5) 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 <[email protected]> AI-assisted. Synthetic tests only.
Author
Owner

@⁠Machad3x on GitHub · 2026-11-25 13:00 UTC · original · edited 2026-11-25 13:16 UTC

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

**@⁠Machad3x** on GitHub · 2026-11-25 13:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/2341#issuecomment-7163149245) · edited 2026-11-25 13:16 UTC **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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:27 UTC · original · edited 2026-11-25 18:44 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 15:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2341#issuecomment-7166868505) · edited 2026-11-25 18:44 UTC <!-- victory-triage v1 head=075b2ac4d1c15d4902bfe231346585998ffdb2e3 verdict=merge-candidate at=2026-11-25T18:43:58Z --> 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](https://claude.ai/code)_
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 16:15 UTC · original

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 [email protected]

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 16:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2341#issuecomment-7167726396) 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](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/075b2ac4d1c15d4902bfe231346585998ffdb2e3) 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 <[email protected]>
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 17:54 UTC · original

I checked the direct MSAA path on a composition of main 13f91caee2, #2314 at 8c8cfb4f85 and #2341 at 075b2ac4d1. 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 [email protected]

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 17:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/2341#issuecomment-7170176002) I checked the direct MSAA path on a composition of main 13f91caee25f2fdf2c062be5f7a27f058e51cbca, #2314 at 8c8cfb4f8559bb43ea08fa0d4d3a922db868ab19 and #2341 at 075b2ac4d1c15d4902bfe231346585998ffdb2e3. 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](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/aea413d3ac06759ac1a77ec991155ecbf4031432) 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 <[email protected]>
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 11:26 UTC · original · approved these changes

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

**@⁠DenRakEiw** on GitHub · 2026-11-25 11:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/2341#pullrequestreview-6056762190) · **approved these changes** 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).
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 11:51 UTC · original · reviewed

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.

**@⁠catminou4** on GitHub · 2026-11-25 11:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/2341#pullrequestreview-6057089535) · **reviewed** 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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 18:18 UTC · original · approved these changes

Looks good. Verified merged onto main (63bcca43) on an RTX 5090 and Microsoft WARP under the D3D12 Debug Layer (VICTORY_D3D12_DEBUG=1):

  • Tracking write_version (bumped on WRITE_STATES transitions in HostList::track and on UAV twin routes where twin::route returns true) and alias_source in TextureState (crates/victory-gpu/src/host.rs) ensures texture::alias_copy refreshes an alias whenever its source is written again in the same command list while preserving writes made directly to the alias destination.
  • cargo xtask policy (191 files ok), cargo clippy --locked -p victory-gpu --all-targets -- -D warnings (default and --all-features), and all 21 resource::tests:: (19, including a_second_gpu_write_reaches_the_placed_alias_in_the_same_list) + texture::tests:: (2) tests pass on both RTX 5090 and WARP under VICTORY_D3D12_DEBUG=1 with zero Debug Layer messages.
  • An additional probe verified on both RTX 5090 and WARP under VICTORY_D3D12_DEBUG=1 that ALIAS_COPIES stays at +1 across repeated alias_copy calls and after a destination write (preserving 0x3333_4444), and that HostList::reset() clears alias_source so a reused list copies the source again cleanly (0x1111_2222).
  • Also confirmed clean co-merge with #2509 on main.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 18:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2341#pullrequestreview-6078893922) · **approved these changes** Looks good. Verified merged onto `main` (`63bcca43`) on an RTX 5090 and Microsoft WARP under the D3D12 Debug Layer (`VICTORY_D3D12_DEBUG=1`): - Tracking `write_version` (bumped on `WRITE_STATES` transitions in `HostList::track` and on UAV twin routes where `twin::route` returns `true`) and `alias_source` in `TextureState` (`crates/victory-gpu/src/host.rs`) ensures `texture::alias_copy` refreshes an alias whenever its source is written again in the same command list while preserving writes made directly to the alias destination. - `cargo xtask policy` (`191 files ok`), `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings` (default and `--all-features`), and all 21 `resource::tests::` (19, including `a_second_gpu_write_reaches_the_placed_alias_in_the_same_list`) + `texture::tests::` (2) tests pass on both RTX 5090 and WARP under `VICTORY_D3D12_DEBUG=1` with zero Debug Layer messages. - An additional probe verified on both RTX 5090 and WARP under `VICTORY_D3D12_DEBUG=1` that `ALIAS_COPIES` stays at `+1` across repeated `alias_copy` calls and after a destination write (preserving `0x3333_4444`), and that `HostList::reset()` clears `alias_source` so a reused list copies the source again cleanly (`0x1111_2222`). - Also confirmed clean co-merge with `#2509` on `main`.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2341/head:github-bot/gh-2341'
git switch 'github-bot/gh-2341'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2341'
git switch 'github-bot/gh-2341'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2341'
git switch 'github-bot/gh-2341'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2341'
git switch 'main'
git merge --squash 'github-bot/gh-2341'
git switch 'main'
git merge --ff-only 'github-bot/gh-2341'
git switch 'main'
git merge 'github-bot/gh-2341'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2341
No description provided.