GPU: avoid illegal COPY_SOURCE self-transition in Host::present #2543

Closed
reeledMarek wants to merge 1 commit from upstream-pr/2545 into main
reeledMarek commented 2026-11-25 15:33:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T15:33:50Z.


Problem

  1. In queue::present and Host::present, if the presented texture was already in D3D12_RESOURCE_STATE_COPY_SOURCE (0x800), Host::present emitted illegal COPY_SOURCE -> COPY_SOURCE before/after resource barriers.
  2. queue::present obtained an un-owned &'static ID3D12Resource via host_resource() and mutated HostTexture::state via host_transition() outside Host::submitted, racing with concurrent submissions and risking use-after-free if the resource was released during presentation.

Fix

  • Pass an owned &Arc<HostTexture> from queue::present (via resource::host_copy) into Host::present.
  • Record the source texture transition through p.copy.move_texture(copy, COPY_SOURCE) so p.copy.prelude() swaps copy.state atomically under Host::submitted and skips emitting any barrier when copy is already in COPY_SOURCE.
  • Gate now test-only resource::host_transition with #[cfg(all(windows, test))].

Testing

  • Added move_texture_to_copy_source_skips_prelude_when_already_copy_source in crates/victory-gpu/src/host.rs.
  • Verified cargo test -p xtask --locked passes asset policy.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6608065779 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2545). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T15:33:50Z. --- ### Problem 1. In `queue::present` and `Host::present`, if the presented texture was already in `D3D12_RESOURCE_STATE_COPY_SOURCE` (`0x800`), `Host::present` emitted illegal `COPY_SOURCE -> COPY_SOURCE` before/after resource barriers. 2. `queue::present` obtained an un-owned `&'static ID3D12Resource` via `host_resource()` and mutated `HostTexture::state` via `host_transition()` outside `Host::submitted`, racing with concurrent submissions and risking use-after-free if the resource was released during presentation. ### Fix - Pass an owned `&Arc<HostTexture>` from `queue::present` (via `resource::host_copy`) into `Host::present`. - Record the source texture transition through `p.copy.move_texture(copy, COPY_SOURCE)` so `p.copy.prelude()` swaps `copy.state` atomically under `Host::submitted` and skips emitting any barrier when `copy` is already in `COPY_SOURCE`. - Gate now test-only `resource::host_transition` with `#[cfg(all(windows, test))]`. ### Testing - Added `move_texture_to_copy_source_skips_prelude_when_already_copy_source` in `crates/victory-gpu/src/host.rs`. - Verified `cargo test -p xtask --locked` passes asset policy.
cloph-dsp commented 2026-11-25 16:09:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T16:08:56Z.


Status check (2026-11-25, no game data): gh pr view 2545 --json mergeable,mergeStateStatus reports mergeable=CONFLICTING, mergeStateStatus=DIRTY against main — this PR cannot merge as-is and needs a rebase. No formal review and no comments were present at check time. Other PRs checked in the same pass are not in that state: #2543 is MERGEABLE (status UNSTABLE, CI pending) and #2542 is transient UNKNOWN. Flagging only because the conflict is real, not because CI is red. AI-assisted (Hy4 flash); GPU/driver N/A (status check only); no game data.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167635446 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2545#issuecomment-7167635446). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-25T16:08:56Z. --- Status check (2026-11-25, no game data): `gh pr view 2545 --json mergeable,mergeStateStatus` reports `mergeable=CONFLICTING`, `mergeStateStatus=DIRTY` against `main` — this PR cannot merge as-is and needs a rebase. No formal review and no comments were present at check time. Other PRs checked in the same pass are not in that state: #2543 is `MERGEABLE` (status UNSTABLE, CI pending) and #2542 is transient `UNKNOWN`. Flagging only because the conflict is real, not because CI is red. AI-assisted (Hy4 flash); GPU/driver N/A (status check only); no game data.
Marvisak commented 2026-11-25 17:05:13 +00:00 (Migrated from github.com)

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


Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main: main has moved since the last triage, and the branch now conflicts in crates/victory-gpu/src/host.rs and crates/victory-gpu/src/queue.rs. It will be reviewed again once it is rebased onto current main.

Previous verdict for this head: merge candidate.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167717808 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2545#issuecomment-7167717808). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T16:14:38Z. --- <!-- victory-triage v1 head=ba8eab2f79fc3c8674600eec44c618908c8a9786 verdict=needs-rebase at=2026-11-25T22:18:00Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main`: `main` has moved since the last triage, and the branch now conflicts in `crates/victory-gpu/src/host.rs` and `crates/victory-gpu/src/queue.rs`. It will be reviewed again once it is rebased onto current `main`. Previous verdict for this head: merge candidate. --- _Generated by [Claude Code](https://claude.ai/code)_
reeledMarek commented 2026-11-25 20:06:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T20:05:28Z.


Updated to address the triage feedback and CI failure:

  • Moved move_texture_to_copy_source_skips_prelude_when_already_copy_source into its own mod present_tests with proper imports and added list.close() before list.reset().
  • Confirming both questions:
    1. Yes, after present, the texture remains in COPY_SOURCE with copy.state updated by p.copy's prelude (so later draws/copies transition cleanly from COPY_SOURCE without an extra barrier).
    2. Yes, clearing p.copy.states right after self.execute(&[&p.copy]) is safe because Host::execute waits for the submission fence to finish before returning.
  • Also corrected the PR note about host_resource returning an owned clone.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7173177334 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2545#issuecomment-7173177334). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T20:05:28Z. --- Updated to address the triage feedback and CI failure: - Moved `move_texture_to_copy_source_skips_prelude_when_already_copy_source` into its own `mod present_tests` with proper imports and added `list.close()` before `list.reset()`. - Confirming both questions: 1. Yes, after `present`, the texture remains in `COPY_SOURCE` with `copy.state` updated by `p.copy`'s prelude (so later draws/copies transition cleanly from `COPY_SOURCE` without an extra barrier). 2. Yes, clearing `p.copy.states` right after `self.execute(&[&p.copy])` is safe because `Host::execute` waits for the submission fence to finish before returning. - Also corrected the PR note about `host_resource` returning an owned clone.
upstream-sync changed title from [PR #2545] GPU: avoid illegal COPY_SOURCE self-transition and keep HostTexture alive in Host::present to [PR #2545] GPU: avoid illegal COPY_SOURCE self-transition in Host::present 2026-11-25 21:02:34 +00:00
upstream-sync closed this pull request 2026-11-26 06:02:30 +00:00
reeledMarek commented 2026-11-26 06:03:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-26T05:49:47Z.


Closing as superseded by #1997 (0736f8b): Host::present now skips the COPY_SOURCE -> COPY_SOURCE self-transition and queue.rs keeps owned ID3D12Resource handles alive across host.present.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7183842811 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2545#issuecomment-7183842811). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-26T05:49:47Z. --- Closing as superseded by #1997 (`0736f8b`): `Host::present` now skips the `COPY_SOURCE -> COPY_SOURCE` self-transition and `queue.rs` keeps owned `ID3D12Resource` handles alive across `host.present`.

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
Marvisak/VIctory!2543
No description provided.