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

Open
andrewpozdnakov7-jpg wants to merge 2 commits from upstream-pr/2341 into main
andrewpozdnakov7-jpg commented 2026-11-25 11:07:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T11:07:58Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6603097463 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2341). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-25T11:07:58Z. --- 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://github.com/Marvisak/VIctory/issues/1633#issuecomment-7160501846)
DenRakEiw commented 2026-11-25 11:26:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T11:26:30Z.

Review: APPROVED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6056762190 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2341#pullrequestreview-6056762190). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T11:26:30Z. **Review:** APPROVED --- 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).
catminou4 commented 2026-11-25 11:51:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T11:51:58Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6057089535 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2341#pullrequestreview-6057089535). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T11:51:58Z. **Review:** COMMENTED --- 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.
andrewpozdnakov7-jpg commented 2026-11-25 12:03:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T11:28:01Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7161084274 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2341#issuecomment-7161084274). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-25T11:28:01Z. --- 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.
Machad3x commented 2026-11-25 13:03:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Machad3x on 2026-11-25T13:00:03Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163149245 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2341#issuecomment-7163149245). Originally posted by [Machad3x](https://github.com/Machad3x) on 2026-11-25T13:00:03Z. --- **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 2026-11-25 16:09:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:27:19Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7166868505 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2341#issuecomment-7166868505). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:27:19Z. --- <!-- 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)_
andrewpozdnakov7-jpg commented 2026-11-25 17:05:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T16:15:14Z.


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]

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167726396 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2341#issuecomment-7167726396). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-25T16:15:14Z. --- 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]>
andrewpozdnakov7-jpg commented 2026-11-25 18:02:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T17:54:53Z.


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]

<!-- greyfinch-sync:Marvisak/VIctory:comment:7170176002 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2341#issuecomment-7170176002). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-25T17:54:53Z. --- 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]>
fuzeofficlal commented 2026-11-26 18:18:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T18:18:51Z.

Review: APPROVED


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.
<!-- greyfinch-sync:Marvisak/VIctory:review:6078893922 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2341#pullrequestreview-6078893922). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T18:18:51Z. **Review:** APPROVED --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2341:upstream-pr/2341'
git switch 'upstream-pr/2341'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2341'
git switch 'upstream-pr/2341'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2341'
git switch 'upstream-pr/2341'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2341'
git switch 'main'
git merge --squash 'upstream-pr/2341'
git switch 'main'
git merge --ff-only 'upstream-pr/2341'
git switch 'main'
git merge 'upstream-pr/2341'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2339
No description provided.