Skip to content

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

Closed
reeledMarek wants to merge 1 commit into
Marvisak:mainfrom
reeledMarek:fix/gpu-present-copy-source-and-lifetime
Closed

reeledMarek wants to merge 1 commit into
Marvisak:mainfrom
reeledMarek:fix/gpu-present-copy-source-and-lifetime

Conversation

@reeledMarek

Copy link
Copy Markdown
Contributor

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
reeledMarek force-pushed the fix/gpu-present-copy-source-and-lifetime branch from 4217a7d to fb0ccca Compare November 25, 2026 16:07
@cloph-dsp

Copy link
Copy Markdown

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 Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@reeledMarek
reeledMarek force-pushed the fix/gpu-present-copy-source-and-lifetime branch from fb0ccca to ba8eab2 Compare November 25, 2026 20:04
@reeledMarek reeledMarek changed the title GPU: avoid illegal COPY_SOURCE self-transition and keep HostTexture alive in Host::present GPU: avoid illegal COPY_SOURCE self-transition in Host::present Nov 25, 2026
@reeledMarek

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants