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

Open
github-bot wants to merge 3 commits from github-bot/gh-2905 into main AGit
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 23:32 UTC · original
0xkn0wh3r3:gpu/no-copy-of-a-texture-onto-itself → main · +179 −3 · 1 files · 3 commits · open

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.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 23:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/2905) `0xkn0wh3r3:gpu/no-copy-of-a-texture-onto-itself` → `main` · +179 −3 · 1 files · 3 commits · open ## 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.
Two title textures over one memory share one host texture (decision
0007). A CopyResource between them, or a CopyTextureRegion between the
same subresource of each, was recorded as a copy of that host texture
onto itself, which the host does not allow: the two transitions before
it left the texture in the copy-source state as the copy's destination
(debug layer: "Resource state (0x800: D3D12_RESOURCE_STATE_COPY_SOURCE)
... is invalid for use as a destination resource"). On the title's side
such a copy changes nothing. The transitions and the copy are now left
out; the uploads before them and the host-written note stay as they
were. A copy to another place within its own subresource is left out
too, and said once (it would need a copy through a texture of ours).

Test: two textures at one address share one host copy; a whole copy and
an in-place subresource copy between them are left out, copies between
two memories are recorded, and with VICTORY_D3D12_DEBUG=1 in a
diagnostics build the debug layer reports nothing (on main it reports
the error above).

From avatarmanz/VIctory-7900XTX 51d3f4d (its list.rs part; that commit
names triippywhale 6e502b3b as its source).

Co-authored-by: local <local@localhost>
A copy to another place in its own subresource is not done, so the
destination is not marked host-written for it; an in-place one, which
changes nothing, keeps the note a copy would have left. (Review on
#2905.)
A copy between two title textures over one host texture is left out,
but it still noted the texture as written by the host. Nothing was
written: the texture still shows title memory, and with the note its
later CPU writes were no longer uploaded (andrewpozdnakov7-jpg's report
on #2905: a pixel read after an identity copy and a CPU write kept the
old value). Neither a left-out whole copy nor a left-out region copy
notes it now; the upload of a CPU-written source before the check stays.

The test submits the lists: after the left-out copies the texture is not
noted as the host's, after copies between two memories both are. With
the note put back it fails.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:17:10 +00:00
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 02:13 UTC · original

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]

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 02:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2905#issuecomment-7180586356) 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]>
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-26 02:16 UTC · original

@⁠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
**@⁠0xkn0wh3r3** on GitHub · 2026-11-26 02:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2905#issuecomment-7180642685) @⁠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`
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 02:19 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-26 02:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2905#issuecomment-7180685623) <!-- 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)_
Author
Owner

@⁠pickles976 on GitHub · 2026-11-26 02:44 UTC · original

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.

**@⁠pickles976** on GitHub · 2026-11-26 02:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/2905#issuecomment-7181078807) 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 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/2905/head:github-bot/gh-2905'
git switch 'github-bot/gh-2905'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2905'
git switch 'github-bot/gh-2905'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2905'
git switch 'github-bot/gh-2905'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2905'
git switch 'main'
git merge --squash 'github-bot/gh-2905'
git switch 'main'
git merge --ff-only 'github-bot/gh-2905'
git switch 'main'
git merge 'github-bot/gh-2905'
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!2905
No description provided.