Skip to content

gpu: take the presented texture's move to COPY_SOURCE through its list (VIctory #2545) - #158

Merged
pablogonz12 merged 2 commits into
mainfrom
int/copy-source-state
Nov 25, 2026
Merged

pablogonz12 merged 2 commits into
mainfrom
int/copy-source-state

Conversation

@pablogonz12

@pablogonz12 pablogonz12 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

What

A presented texture the title already left in COPY_SOURCE got an illegal COPY_SOURCE -> COPY_SOURCE barrier
before and after the copy up, and its recorded state was swapped from the presenting thread, outside
Host::submitted.

  • queue::present no longer calls resource::host_transition (which swapped HostTexture::state outside the
    submission lock) and no longer reads the texture through an un-owned &'static ID3D12Resource: it passes the
    Arc<HostTexture> from resource::host_copy, which the present list now holds until it is reset.
  • Host::present records the move with the present list's own state bookkeeping (HostList::settle, one list's
    first use of a texture records nothing) instead of writing two barriers by hand. The list's prelude makes the
    move from the texture's real state at submission, under the lock, and records no barrier at all when the
    texture is there already. The copy leaves it in COPY_SOURCE, which is what the prelude then records as its
    real state, so the title's own lists move it from there.
  • resource::host_transition is now test-only (#[cfg(all(windows, test))]), as in #2545.

What this changes under vkd3d-proton (why it is not cosmetic on RADV)

vkd3d-proton turns each D3D12 transition into a Vulkan pipeline barrier whose srcStage/srcAccess come from the
transition's StateBefore and whose dstStage/dstAccess come from StateAfter. Two consequences:

  • COPY_SOURCE -> COPY_SOURCE is an invalid transition in D3D12 (debug layer error) and, translated, is a barrier
    from the copy stage to the copy stage that nobody needed: no writer's cache is flushed by it, and the case only
    appeared because the state was moved for the caller rather than tracked.
  • Worse, moving HostTexture::state from the presenting thread meant a list submitted at the same time could
    record its prelude barriers from a state the resource was not in. vkd3d-proton then derives srcStage/
    srcAccess from that wrong StateBefore, so the barrier does not order the real writer's writes before the
    read: on RADV (real caches) that is a stale or torn presented frame or omitted depth/colour sync, while WARP,
    whose "caches" are a host-side buffer, would look fine. With the move inside the prelude the swap happens under
    Host::submitted, in submission order, exactly once.

The fill path (title content uploaded into the presented texture in the present's own list) now starts in
COPY_DEST and is given back to COPY_SOURCE inside the list, which is where the extra barrier stays.

Test

cargo xwin test -p victory-gpu under Wine on the RADV card (VICTORY_TEST_ADAPTER=hw, real vkd3d-proton
device), hand-built committed 64x64 textures, no game data:

  • a_copy_source_texture_is_moved_nowhere_by_the_present_list: a texture left in COPY_SOURCE — the present
    list's prelude is None (no self-transition is recorded) and the recorded state stays COPY_SOURCE.
  • a_texture_in_another_state_is_moved_to_copy_source_once: from RENDER_TARGET the prelude is recorded once and
    the state becomes COPY_SOURCE; a second list records nothing.
  • a_filled_present_starts_in_copy_dest_and_ends_in_copy_source.

Gates: 180 passed / 0 failed (2 ignored) for victory-gpu; cargo xwin clippy --workspace --all-targets -- -D warnings clean; release build dry run (no --execute): build.toml matched, 2 hooks, 5 modules, every one
missing=0; cargo xtask policy 236 files ok; name check clean

Off switch

VICTORY_PRESENT_PRELUDE=0 records the copy-up's barrier by hand again (from the state it is recorded in, and
back), which is the old sequence; a line is in xcl-bin/notes/joint-session.md for the next session.

Credit

Reimplementation of Marvisak/VIctory #2545 by
@reeledMarek (GPL-3.0), not a cherry-pick: their fix adds move_texture on the
present's copy list, this tree already tracks the same thing per list (HostList::settle/prelude), so only the
present had to stop bypassing it. Co-authored-by: trailer and a CREDITS.md line.

Not tested in a game run.

Summary by CodeRabbit

  • Bug Fixes
    • Improved graphics resource state handling during frame presentation, including filled frames. Presentation now tracks state changes consistently, which can help prevent rendering issues caused by incorrect transitions.
    • Back-buffer transition behavior remains unchanged.

A presented texture the title already left in COPY_SOURCE was given an
illegal COPY_SOURCE -> COPY_SOURCE barrier before and after the copy up,
and its recorded state was swapped from the presenting thread, outside
Host::submitted: a list submitted meanwhile could record a move from a
state the card was not in.

The present's list now records the move as any list does (settle: its
first use records nothing), and the list's prelude makes it from the
texture's real state at submission, under the lock, recording no barrier
when it is there already. The copy leaves it in COPY_SOURCE, which is
what the prelude then records as its real state.

Reimplementation of Marvisak/VIctory #2545, whose fix moves the state
from a move_texture call on the present's copy list; this tree already
had that bookkeeping, so only the present had to stop bypassing it.

Co-authored-by: shh <marek8788@proton.me>
VICTORY_PRESENT_PRELUDE=0 records the barrier by hand again.
Not tested in a game run.
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Present state tracking

Layer / File(s) Summary
Pass the host texture copy
crates/victory-gpu/src/queue.rs, crates/victory-gpu/src/host.rs
Queue::present obtains and passes the host copy. Host::present reads the source state from that copy.
Track present transitions
crates/victory-gpu/src/host.rs, crates/victory-gpu/src/resource.rs
Host::present uses HostList::settle for source transitions by default. With VICTORY_PRESENT_PRELUDE=0, it uses explicit barriers and restores the source state. Tests cover tracked states for regular and filled presents.

Possibly related PRs

  • pablogonz12/Scarlight#177: Adds Host::present_overlay and a second-plane compositor that uses the same present-list and source-texture state flow.

Suggested reviewers: fxceless

Change: Bug fix

Merge Risk: Minimal · up to 78a25

The present path now tracks the presented texture's state through its command list instead of queue-side barriers. No concrete defect was found, and the old barrier sequence stays available via VICTORY_PRESENT_PRELUDE=0. It has not been exercised in a game run.

Security architecture risk: Low · up to 78a25

The default behavior improves texture lifetime and state ordering without widening access. The opt-in fallback is not a clean rollback: after a texture upload, it can leave the recorded state out of sync with the GPU and disrupt later rendering.

Retained concerns

  • Low · reliability · inferred: When VICTORY_PRESENT_PRELUDE=0 and a fill records an upload, upload still tracks COPY_DEST. The prelude can therefore move the texture before the manual opening barrier and publishes COPY_DEST as the list's final state, even though the manual closing barrier restores the captured prior state. The base also mixed manual and tracked transitions, but its queue caller restored the prior tracked state after present returns. Head removes that restoration, so a mismatch can persist into later submissions and cause invalid transitions or a local GPU failure.
Security review details

Security Blast Radius

  • inferred — The supported effect is on the selected host texture and work sharing the local GPU submission path. The compared code does not establish a new route to resources outside that path.

Trust Boundaries and Controls

  • observed — The title still supplies the resource reference. The backend resolves it through the same host lookup as before, but now passes a reference-counted host copy instead of a borrowed GPU resource and separate state value.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

  • Mode: Continue automatically
  • Reviewed files: 1
  • Waived: $0.25 (charged $0.00)
  • View usage details

Note

This review exceeded your plan’s limits and used usage-based reviews—free during trial, billed after paid activation unless disabled. Manage usage-based reviews.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4392b96e-6599-44a4-8f50-ac436181b446
Commits

Reviewing files that changed from the base of the PR and between b1446d5 and 78a2534.

Files selected for processing: 1

  • crates/victory-gpu/src/host.rs

Limit details: You’ve used all 10 included reviews currently available.

@pablogonz12

Copy link
Copy Markdown
Owner Author

On the retained concern (present lists keep their source texture until reset): that is deliberate, and it is what
every list in this tree does — HostList::states holds an Arc per texture it names and releases them in
reset(), which only runs once the list's submission has finished (an ahead slot is picked by
FINISHED, p.copy is reset at the next present). Clearing the map right after execute instead would drop the
last reference to a texture whose copy is still running on the card, which is a use-after-free — the exact bug this
PR removes. The cost is bounded: one source per present list (p.copy plus one per ahead slot), and those are
reused, not grown.

@pablogonz12
pablogonz12 merged commit 6e2f9f6 into main Nov 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant