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

Closed
github-bot wants to merge 1 commit from github-bot/gh-2545 into main AGit
Owner

@⁠reeledMarek on GitHub · 2026-11-25 15:33 UTC · original
reeledMarek:fix/gpu-present-copy-source-and-lifetime → main · +101 −30 · 3 files · 1 commits · closed without merging

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.
**@⁠reeledMarek** on GitHub · 2026-11-25 15:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2545) `reeledMarek:fix/gpu-present-copy-source-and-lifetime` → `main` · +101 −30 · 3 files · 1 commits · closed without merging ### 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:08:49 +00:00
github-bot closed this pull request 2026-11-26 06:31:03 +00:00
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-25 16:08 UTC · original

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.

**@⁠cloph-dsp** on GitHub · 2026-11-25 16:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/2545#issuecomment-7167635446) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 16:14 UTC · original · edited 2026-11-25 22:16 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 16:14 UTC · [original](https://github.com/Marvisak/VIctory/pull/2545#issuecomment-7167717808) · edited 2026-11-25 22:16 UTC <!-- 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)_
Author
Owner

@⁠reeledMarek on GitHub · 2026-11-25 20:05 UTC · original

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.
**@⁠reeledMarek** on GitHub · 2026-11-25 20:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2545#issuecomment-7173177334) 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.
Author
Owner

@⁠reeledMarek on GitHub · 2026-11-26 05:49 UTC · original

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.

**@⁠reeledMarek** on GitHub · 2026-11-26 05:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2545#issuecomment-7183842811) 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

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!2545
No description provided.