GPU: fix CopyTextureRegion between mips of the same texture #3816

Closed
senduora wants to merge 1 commit from upstream-pr/3816 into main
senduora commented 2026-11-30 08:15:27 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by senduora on 2026-11-30T08:15:27Z.


What it changes

When the source and destination name different subresources of the same native D3D12 texture, the whole-resource transition to COPY_DEST also changes the source mip. CopyTextureRegion requires that source subresource to be in COPY_SOURCE. D3D12 copy rules

Keep the existing whole-resource state tracking. Transition just the source subresource to COPY_SOURCE for the copy, then restore it to COPY_DEST. If an additional placed twin needs the source, transition the texture back to the usual read state before copying to that twin. Copies between distinct native textures keep their existing path.

How it was tested

  • Windows, NVIDIA GeForce RTX 5070 (driver 621.40), native D3D12 test against main at 41adb55 (v2026.11.29.05).
  • The regression uploads generated RGBA8 texels to mip 0, copies an offset rectangle into mip 1 of the same native texture, and checks both mips byte for byte after the fence.
  • cargo test --locked --release -p victory-gpu --lib list::tests -- --test-threads=1 passed all 12 tests. The existing depth-twin copy test also passed separately.
  • The PR addresses the D3D12 copy-state violation. The command responsible for the observed gameplay device hang remains unconfirmed.

Checked for overlap

  • Checked #3043, #3062 and #3488 for related copy changes. The same-native, different-subresource state transition is independent of format conversion and region fitting.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5561539706 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3816). Originally posted by [senduora](https://github.com/senduora) on 2026-11-30T08:15:27Z. --- ## What it changes When the source and destination name different subresources of the same native D3D12 texture, the whole-resource transition to `COPY_DEST` also changes the source mip. `CopyTextureRegion` requires that source subresource to be in `COPY_SOURCE`. [D3D12 copy rules](https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nf-d3d12-id3d12graphicscommandlist-copytextureregion) Keep the existing whole-resource state tracking. Transition just the source subresource to `COPY_SOURCE` for the copy, then restore it to `COPY_DEST`. If an additional placed twin needs the source, transition the texture back to the usual read state before copying to that twin. Copies between distinct native textures keep their existing path. ## How it was tested - Windows, NVIDIA GeForce RTX 5070 (driver 621.40), native D3D12 test against `main` at `41adb55` (`v2026.11.29.05`). - The regression uploads generated RGBA8 texels to mip 0, copies an offset rectangle into mip 1 of the same native texture, and checks both mips byte for byte after the fence. - `cargo test --locked --release -p victory-gpu --lib list::tests -- --test-threads=1` passed all 12 tests. The existing depth-twin copy test also passed separately. - The PR addresses the D3D12 copy-state violation. The command responsible for the observed gameplay device hang remains unconfirmed. ## Checked for overlap - [x] Checked #3043, #3062 and #3488 for related copy changes. The same-native, different-subresource state transition is independent of format conversion and region fitting.
tyr0nsur commented 2026-11-30 09:13:58 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tyr0nsur on 2026-11-30T09:13:58Z.


A placed twin can be the original copy source. On head 61d03c1, I reproduced three cases using two title views of the same backing. The whole-resource copy and the same-native-subresource region copy both try to mirror a resource back onto itself. The different-mip mirror changes the tracked state of the source to COPY_DEST while it still needs to be read.

Follow-up commit aedb634 skips the redundant mirrors before write tracking. It keeps the different-mip mirror, temporarily transitions just the native source subresource, and restores the source to a readable state before recording another mirror.

The regression checks source state before submission in all three cases and reads back the destination mip byte for byte from both views. The targeted list:: and resource:: diagnostics suite passed on an RTX 4060 (66 passed, 1 ignored). Both mip-copy regressions also passed on WARP. The staged asset policy check passed.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7273920078 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3816#issuecomment-7273920078). Originally posted by [tyr0nsur](https://github.com/tyr0nsur) on 2026-11-30T09:13:58Z. --- A placed twin can be the original copy source. On head `61d03c1`, I reproduced three cases using two title views of the same backing. The whole-resource copy and the same-native-subresource region copy both try to mirror a resource back onto itself. The different-mip mirror changes the tracked state of the source to `COPY_DEST` while it still needs to be read. [Follow-up commit aedb634](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/aedb634502311fd07242727250e8a23579a8e5fa) skips the redundant mirrors before write tracking. It keeps the different-mip mirror, temporarily transitions just the native source subresource, and restores the source to a readable state before recording another mirror. The regression checks source state before submission in all three cases and reads back the destination mip byte for byte from both views. The targeted `list::` and `resource::` diagnostics suite passed on an RTX 4060 (66 passed, 1 ignored). Both mip-copy regressions also passed on WARP. The staged asset policy check passed.
Freeman022026 commented 2026-11-30 13:53:50 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Freeman022026 on 2026-11-30T13:53:50Z.


Tested on RTX 4090 24 GB (driver 621.14, Windows 11) on top of v2026.11.29.05 (41adb551) alongside #3043 and #3792. The new GPU test copy_region_between_mips_of_one_texture passes, and an 81-minute gameplay run completed with 0 0x80070057 crashes.

In copy_texture_region, checking only src.footprint.offset as u32 == u32::MAX || dst.footprint.offset as u32 == u32::MAX still lets any other out-of-range subresource index reach transition_subresource(to, ..., src.footprint.offset as u32). Comparing both indices against the texture's actual subresource count from to.GetDesc() (MipLevels * layers * planes, matching subresource_count in #3043) avoids emitting an invalid subresource barrier for out-of-range indices below u32::MAX as well.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7280528169 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3816#issuecomment-7280528169). Originally posted by [Freeman022026](https://github.com/Freeman022026) on 2026-11-30T13:53:50Z. --- Tested on RTX 4090 24 GB (driver 621.14, Windows 11) on top of v2026.11.29.05 (`41adb551`) alongside #3043 and #3792. The new GPU test `copy_region_between_mips_of_one_texture` passes, and an 81-minute gameplay run completed with 0 `0x80070057` crashes. In `copy_texture_region`, checking only `src.footprint.offset as u32 == u32::MAX || dst.footprint.offset as u32 == u32::MAX` still lets any other out-of-range subresource index reach `transition_subresource(to, ..., src.footprint.offset as u32)`. Comparing both indices against the texture's actual subresource count from `to.GetDesc()` (`MipLevels * layers * planes`, matching `subresource_count` in #3043) avoids emitting an invalid subresource barrier for out-of-range indices below `u32::MAX` as well.
trustno1-coder commented 2026-12-01 18:48:28 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:48:28Z.


Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7321582209 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3816#issuecomment-7321582209). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-12-01T18:48:28Z. --- Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

Pull request closed

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
trustno1-coder/VIctory-NVIDIA!3816
No description provided.