GPU: no copy of a host texture onto itself #2903

Open
0xkn0wh3r3 wants to merge 3 commits from upstream-pr/2905 into main
0xkn0wh3r3 commented 2026-11-25 23:32:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-25T23:32:53Z.


What

Two title textures over one memory share one host texture (decision 0007). This PR stops recording a copy of that host texture onto itself:

  • CopyResource between two such textures: the two transitions and the copy are left out.
  • CopyTextureRegion between the same subresource of each: also left out.

Uploads of a CPU-written source still happen before the check. A skipped copy doesn't mark the destination host-written, since nothing was written: the texture still shows title memory, so later CPU writes keep being uploaded. A copy to another place inside the same subresource is also left out, with a one-time warning: the host can't do that in one copy, and so far no title has been seen doing it.

Why

Main recorded COPY_DEST and then COPY_SOURCE transitions on the same host texture, then CopyResource(t, t). That left the texture in the copy-source state as the copy's destination, and the debug layer reports:

CopyResource: Resource state (0x800: D3D12_RESOURCE_STATE_COPY_SOURCE) of resource ... (subresource: 0) is invalid for use as a destination resource.

In the title's terms the copy moves memory onto itself, which changes nothing. The fork logged this 37 times in one run, on a 2560x1440 depth texture.

Where it comes from

From the avatarmanz/VIctory-7900XTX fork, commit 51d3f4d, only its list.rs part (that commit's comment credits triippywhale 6e502b3b, a commit I couldn't see). I rewrote it against main's copy_resource and copy_texture_region and added a test. The same commit's efficiency-mode opt-out duplicates #2569, so it's left out.

Tested (Windows 11, RTX 5070 Ti)

  • New test list::tests::a_copy_between_textures_over_one_memory_is_left_out: two textures at one address share one host copy. A whole copy and an in-place subresource copy between them are left out, while copies between two memories are still recorded. The test also asserts the debug layer reported nothing. With VICTORY_D3D12_DEBUG=1 --features diagnostics it passes on this branch. The same calls on main fail with the debug-layer error quoted above.
  • cargo test -p victory-gpu: 230 passed. The only 2 failures (dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views) are this NVIDIA card's descriptor-heap cap and fail on main too (#2121).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings, with and without --features diagnostics: clean.

Not tested

  • Not run with the title on this machine.
  • Copies between different subresources of one shared host texture still transition the whole texture, so the source ends up in COPY_DEST. Fixing that needs per-subresource states (#594). This PR doesn't change it.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6615952470 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2905). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-25T23:32:53Z. --- ## What Two title textures over one memory share one host texture (decision 0007). This PR stops recording a copy of that host texture onto itself: - **`CopyResource` between two such textures:** the two transitions and the copy are left out. - **`CopyTextureRegion` between the same subresource of each:** also left out. Uploads of a CPU-written source still happen before the check. A skipped copy doesn't mark the destination host-written, since nothing was written: the texture still shows title memory, so later CPU writes keep being uploaded. A copy to another place inside the same subresource is also left out, with a one-time warning: the host can't do that in one copy, and so far no title has been seen doing it. ## Why Main recorded `COPY_DEST` and then `COPY_SOURCE` transitions on the same host texture, then `CopyResource(t, t)`. That left the texture in the copy-source state as the copy's destination, and the debug layer reports: > CopyResource: Resource state (0x800: D3D12_RESOURCE_STATE_COPY_SOURCE) of resource ... (subresource: 0) is invalid for use as a destination resource. In the title's terms the copy moves memory onto itself, which changes nothing. The fork logged this 37 times in one run, on a 2560x1440 depth texture. ## Where it comes from From the avatarmanz/VIctory-7900XTX fork, commit [`51d3f4d`](https://github.com/avatarmanz/VIctory-7900XTX/commit/51d3f4da001b0d7e1f438f03533a101f6b32668b), only its list.rs part (that commit's comment credits triippywhale `6e502b3b`, a commit I couldn't see). I rewrote it against main's `copy_resource` and `copy_texture_region` and added a test. The same commit's efficiency-mode opt-out duplicates #2569, so it's left out. ## Tested (Windows 11, RTX 5070 Ti) - New test `list::tests::a_copy_between_textures_over_one_memory_is_left_out`: two textures at one address share one host copy. A whole copy and an in-place subresource copy between them are left out, while copies between two memories are still recorded. The test also asserts the debug layer reported nothing. With `VICTORY_D3D12_DEBUG=1 --features diagnostics` it passes on this branch. The same calls on main fail with the debug-layer error quoted above. - `cargo test -p victory-gpu`: 230 passed. The only 2 failures (`dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views`) are this NVIDIA card's descriptor-heap cap and fail on main too (#2121). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`, with and without `--features diagnostics`: clean. ## Not tested - Not run with the title on this machine. - Copies between *different* subresources of one shared host texture still transition the whole texture, so the source ends up in `COPY_DEST`. Fixing that needs per-subresource states (#594). This PR doesn't change it.
kotekompotek commented 2026-11-26 00:03:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T23:35:42Z.

Review: COMMENTED


Correct: CopyResource on identical COM pointers is both illegal and a semantic no-op when two title textures alias one host texture — skipping it after host_writes is fine since dst's host copy is already the authoritative bytes. The once-logged counter keeps the skip observable. LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6066484638 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2905#pullrequestreview-6066484638). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T23:35:42Z. **Review:** COMMENTED --- Correct: CopyResource on identical COM pointers is both illegal and a semantic no-op when two title textures alias one host texture — skipping it after host_writes is fine since dst's host copy is already the authoritative bytes. The once-logged counter keeps the skip observable. LGTM.
fuzeofficlal commented 2026-11-26 00:03:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T23:43:17Z.

Review: COMMENTED


Verified head 4cd4b002 cleanly on origin/main (63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + VICTORY_D3D12_DEBUG=1).

Code Review

  • Comparing ID3D12Resource::as_raw in same_texture and requiring dst.kind != FOOTPRINT && src.footprint.offset as u32 == dst.footprint.offset as u32 in copy_texture_region preserves cross-mip / cross-slice copies on the same host texture and leaves distinct aliased host resources (alias_source) untouched.
  • Minor edge case (non-blocking): When same == true in copy_texture_region with non-identical source/dest offsets (an intra-subresource move), the copy is skipped with a warning after crate::texture::host_writes(list, dst.resource) has already marked dst as host_written = true. Moving or skipping host_writes when the copy is omitted avoids marking an unexecuted copy as a host write.

Local Verification (--features diagnostics, VICTORY_D3D12_DEBUG=1)

  • RTX 5090 & WARP: list::tests 5/5 (including a_copy_between_textures_over_one_memory_is_left_out), texture::tests 2/2, draw::tests 20/20, resource::tests 18/18, zero debug-layer errors.
  • cargo clippy --locked -p victory-gpu --tests -- -D warnings (default and --features diagnostics) & cargo xtask policy (191 files ok): clean.
<!-- greyfinch-sync:Marvisak/VIctory:review:6066556955 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2905#pullrequestreview-6066556955). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T23:43:17Z. **Review:** COMMENTED --- Verified head `4cd4b002` cleanly on `origin/main` (`63bcca43`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + D3D12 WARP + `VICTORY_D3D12_DEBUG=1`). ### Code Review - Comparing `ID3D12Resource::as_raw` in `same_texture` and requiring `dst.kind != FOOTPRINT && src.footprint.offset as u32 == dst.footprint.offset as u32` in `copy_texture_region` preserves cross-mip / cross-slice copies on the same host texture and leaves distinct aliased host resources (`alias_source`) untouched. - **Minor edge case (non-blocking)**: When `same == true` in `copy_texture_region` with non-identical source/dest offsets (an intra-subresource move), the copy is skipped with a warning *after* `crate::texture::host_writes(list, dst.resource)` has already marked `dst` as `host_written = true`. Moving or skipping `host_writes` when the copy is omitted avoids marking an unexecuted copy as a host write. ### Local Verification (`--features diagnostics`, `VICTORY_D3D12_DEBUG=1`) - **RTX 5090 & WARP**: `list::tests` **5/5** (including `a_copy_between_textures_over_one_memory_is_left_out`), `texture::tests` **2/2**, `draw::tests` **20/20**, `resource::tests` **18/18**, zero debug-layer errors. - `cargo clippy --locked -p victory-gpu --tests -- -D warnings` (default and `--features diagnostics`) & `cargo xtask policy` (`191 files ok`): clean.
Dukestar69 commented 2026-11-26 03:04:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T02:27:19Z.

Review: APPROVED


Tested merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090):

  • cargo test -p victory-gpu --lib list::tests: 5 passed, 0 failed (including new a_copy_between_textures_over_one_memory_is_left_out).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Skipping self-copies when source and destination resolve to the same host texture avoids invalid same-resource copy transitions cleanly.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6067750847 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2905#pullrequestreview-6067750847). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T02:27:19Z. **Review:** APPROVED --- Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090): - `cargo test -p victory-gpu --lib list::tests`: **5 passed, 0 failed** (including new `a_copy_between_textures_over_one_memory_is_left_out`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Skipping self-copies when source and destination resolve to the same host texture avoids invalid same-resource copy transitions cleanly. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
andrewpozdnakov7-jpg commented 2026-11-26 03:05:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-26T02:13:35Z.


I verified that 0ac5f55 addresses the displaced-region note. There is a related case for identity copies on a CPU-written texture. An identity copy records no GPU write, but calling host_writes for it prevents later CPU updates from being uploaded.

67474ec is one commit directly on 0ac5f55966798c4c4c6a0ac87ecba4c8c3776a0b. It keeps the upload and the skip diagnostic, and leaves the host-written flag untouched for skipped copies.

The same synthetic Windows/WARP test reads an RGBA8 pixel through the guest command list, submits an identity copy between distinct guest objects that share one host texture, writes new bytes from the CPU, and reads the pixel again. For both CopyResource and in-place CopyTextureRegion, the second pixel stays at [23,23,23,23] before the change and reaches [42,42,42,42] after it. Six paired runs. The existing alias-copy test and full GPU diagnostics passed (248 passed, 1 ignored), plus strict Clippy and asset policy. Clean composition with main 63bcca4.

If you take the patch or test, please preserve its Git author. If you fold it into another commit, please add:

Co-authored-by: andrewpozdnakov7-jpg [email protected]

<!-- greyfinch-sync:Marvisak/VIctory:comment:7180586356 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2905#issuecomment-7180586356). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-26T02:13:35Z. --- I verified that `0ac5f55` addresses the displaced-region note. There is a related case for identity copies on a CPU-written texture. An identity copy records no GPU write, but calling `host_writes` for it prevents later CPU updates from being uploaded. [67474ec](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/67474ecac473bdb09893cf0ca5c40495ad28773a) is one commit directly on `0ac5f55966798c4c4c6a0ac87ecba4c8c3776a0b`. It keeps the upload and the skip diagnostic, and leaves the host-written flag untouched for skipped copies. The same synthetic Windows/WARP test reads an RGBA8 pixel through the guest command list, submits an identity copy between distinct guest objects that share one host texture, writes new bytes from the CPU, and reads the pixel again. For both `CopyResource` and in-place `CopyTextureRegion`, the second pixel stays at `[23,23,23,23]` before the change and reaches `[42,42,42,42]` after it. Six paired runs. The existing alias-copy test and full GPU diagnostics passed (248 passed, 1 ignored), plus strict Clippy and asset policy. Clean composition with main `63bcca4`. If you take the patch or test, please preserve its Git author. If you fold it into another commit, please add: Co-authored-by: andrewpozdnakov7-jpg <[email protected]>
0xkn0wh3r3 commented 2026-11-26 03:05:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T02:16:51Z.


@andrewpozdnakov7-jpg thanks, you're right: a skipped identity copy writes nothing, so marking the texture host-written stopped later CPU writes from being uploaded.

Fixed in 73a2895 (my own change, not your commit): neither a skipped CopyResource nor a skipped CopyTextureRegion calls host_writes any more. The upload of a CPU-written source before the check and the skip counter stay.

The test now submits its lists. After the skipped copies, the shared host texture is not marked host-written; after copies between two different memories, both textures are. With the old host_writes calls put back, the test fails.

Tested on Windows 11 with an RTX 5070 Ti:

  • the test passes, also with VICTORY_D3D12_DEBUG=1 --features diagnostics
  • cargo test -p victory-gpu: 230 passed; the only 2 failures are this card's descriptor-heap cap (#2121), which fail on main too
  • clippy is clean with and without diagnostics
<!-- greyfinch-sync:Marvisak/VIctory:comment:7180642685 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2905#issuecomment-7180642685). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T02:16:51Z. --- @andrewpozdnakov7-jpg thanks, you're right: a skipped identity copy writes nothing, so marking the texture host-written stopped later CPU writes from being uploaded. Fixed in 73a2895 (my own change, not your commit): neither a skipped `CopyResource` nor a skipped `CopyTextureRegion` calls `host_writes` any more. The upload of a CPU-written source before the check and the skip counter stay. The test now submits its lists. After the skipped copies, the shared host texture is not marked host-written; after copies between two different memories, both textures are. With the old `host_writes` calls put back, the test fails. Tested on Windows 11 with an RTX 5070 Ti: - the test passes, also with `VICTORY_D3D12_DEBUG=1 --features diagnostics` - `cargo test -p victory-gpu`: 230 passed; the only 2 failures are this card's descriptor-heap cap (#2121), which fail on main too - clippy is clean with and without `diagnostics`
Marvisak commented 2026-11-26 03:05:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T02:19:08Z.


Automated triage for the maintainers.

Merge candidate (a recommendation to look, not an approval). In list.rs, copy_resource and copy_texture_region now skip a copy when both title textures resolve to the same host texture (same_texture). On main this recorded CopyResource(t, t) with the texture left in COPY_SOURCE, which the debug layer reports as an error. The fix in 73a2895 is in: a skipped copy no longer calls host_writes, so later CPU writes keep being uploaded, and the test checks that. The one real behaviour cost is the documented shortcut: a copy to a different place inside the same subresource is dropped with a one-time warning. CI check was still running at review time.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7180685623 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2905#issuecomment-7180685623). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T02:19:08Z. --- <!-- victory-triage v1 head=73a2895798d4f1e6ff937d403234347341487156 verdict=merge-candidate at=2026-11-26T02:19:01Z --> Automated triage for the maintainers. **Merge candidate** (a recommendation to look, not an approval). In `list.rs`, `copy_resource` and `copy_texture_region` now skip a copy when both title textures resolve to the same host texture (`same_texture`). On `main` this recorded `CopyResource(t, t)` with the texture left in COPY_SOURCE, which the debug layer reports as an error. The fix in 73a2895 is in: a skipped copy no longer calls `host_writes`, so later CPU writes keep being uploaded, and the test checks that. The one real behaviour cost is the documented shortcut: a copy to a different place inside the same subresource is dropped with a one-time warning. CI `check` was still running at review time. --- _Generated by [Claude Code](https://claude.ai/code)_
pickles976 commented 2026-11-26 03:05:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pickles976 on 2026-11-26T02:44:38Z.


Independent Wine/vkd3d-proton 3.2.0 check on NVIDIA RTX 4060 Laptop GPU (590.48.1, vendor masking disabled), exact head 73a28957: list::tests::a_copy_between_textures_over_one_memory_is_left_out 1/1 passed against the actual adapter. It covered aliasing two title textures to one host resource, skipped whole-resource and same-subresource copies without falsely marking host-written, and still recorded distinct-memory copies. This is an offscreen fixture result, not a title/debug-layer check; cross-subresource shared-host transitions remain outside this fix. Local log: .compat-runtime/logs/verify-pr2905-wine-rtx4060-alias-self-copy.log.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7181078807 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2905#issuecomment-7181078807). Originally posted by [pickles976](https://github.com/pickles976) on 2026-11-26T02:44:38Z. --- Independent Wine/vkd3d-proton 3.2.0 check on NVIDIA RTX 4060 Laptop GPU (590.48.1, vendor masking disabled), exact head 73a28957: `list::tests::a_copy_between_textures_over_one_memory_is_left_out` 1/1 passed against the actual adapter. It covered aliasing two title textures to one host resource, skipped whole-resource and same-subresource copies without falsely marking host-written, and still recorded distinct-memory copies. This is an offscreen fixture result, not a title/debug-layer check; cross-subresource shared-host transitions remain outside this fix. Local log: `.compat-runtime/logs/verify-pr2905-wine-rtx4060-alias-self-copy.log`.
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/2905:upstream-pr/2905'
git switch 'upstream-pr/2905'

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/2905'
git switch 'upstream-pr/2905'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2905'
git switch 'upstream-pr/2905'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2905'
git switch 'main'
git merge --squash 'upstream-pr/2905'
git switch 'main'
git merge --ff-only 'upstream-pr/2905'
git switch 'main'
git merge 'upstream-pr/2905'
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!2903
No description provided.