Skip to content

GPU: sync aliased texture sources before copy commands - #3170

Open
fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/copy-aliased-texture-source
Open

fuzeofficlal wants to merge 1 commit into
Marvisak:mainfrom
fuzeofficlal:fix/copy-aliased-texture-source

Conversation

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Summary

Sync GPU-written aliased texture sources via resource::alias_source and texture::alias_copy before CopyResource, texture-to-texture CopyTextureRegion, and texture-to-buffer read_back in crates/victory-gpu/src/list.rs.

Root Cause

When a title places two format-incompatible textures over the same console memory (for example, an R32G32B32A32_FLOAT / R32G32_UINT render target or UAV aliased by a block-compressed BC* texture, or a texture retaining a pre-replacement host copy), they receive separate HostTexture instances. draw.rs already bridges them with resource::alias_source and texture::alias_copy before sampling an SRV, but the three texture-reading copy paths in list.rs (copy_resource, texture-to-texture copy_texture_region, and read_back) only checked texture::title_written / texture::upload. Copies and read-backs from the aliased texture therefore observed stale or zeroed title memory instead of GPU-written texels.

Changes

  • crates/victory-gpu/src/list.rs: add a small sync_copy_source helper calling resource::alias_source / texture::alias_copy before texture::upload (matching draw.rs), and call it from copy_resource, copy_texture_region (texture-to-texture), and read_back.
  • Add an end-to-end GPU regression test (list::tests::copy_commands_sync_aliased_texture_sources) covering all three copy paths on independent R32G32B32A32_FLOAT / BC3_UNORM aliased pairs plus cross-submission updates.

Verification

  • Verified the new test fails on unmodified main (63bcca43) with all-zero output bytes while alias_source(alias) == Some(writer), and passes after the fix on native D3D12 (with and without VICTORY_D3D12_DEBUG=1 --features diagnostics) and WARP (VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 --features diagnostics).
  • cargo test -p victory-gpu --lib --features diagnostics --locked on WARP: 247 passed, 0 failed, 1 ignored.
  • cargo clippy --workspace --all-targets --locked -- -D warnings and --all-features: clean.
  • cargo test -p xtask --locked policy::tests::repository_passes_policy: passed.

draw.rs already calls resource::alias_source and texture::alias_copy before
sampling a texture whose console memory is GPU-written through an incompatible
alias (such as a block-compressed view aliasing an uncompressed render target
or UAV, or a texture keeping a replaced host copy).

list::copy_resource, texture-to-texture list::copy_texture_region, and
list::read_back only checked texture::title_written / texture::upload and never
synced from resource::alias_source, causing copies and read-backs of aliased
textures to observe stale or zeroed title memory instead of GPU-written texels.

Route all three copy source paths through a shared sync_copy_source helper that
calls resource::alias_source / texture::alias_copy before texture::upload,
matching draw.rs.

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-gpu --lib list:: -- --test-threads=1: passed on RTX 5090 and WARP.
  • cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 20/20 passed; resource::: 18/18 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly syncs aliased texture sources before copy commands.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

@steven-seagull27

Copy link
Copy Markdown

@fuzeofficlal I found a same-list case where this PR and #2341 cover different parts of the operation. I extended your fixture to clear the RTV, copy from its BC3 alias, clear the same RTV to a second colour, then copy the same alias again. Both snapshots go to distinct offsets of the readback buffer before the command list is closed and submitted once.

The RTX 5080 and Windows inbox WARP gave the same counts in two fresh runs per build and adapter. Each column totals 64 checked 32-bit words for each of the three routes: CopyResource, texture-to-texture CopyTextureRegion, and direct texture-to-buffer readback.

Build on 63bcca43 First snapshot correct Second snapshot correct
Main 0/192 0/192
#2341 alone (075b2ac) 0/192 0/192
#3170 alone (97683bb) 192/192 0/192
Both PRs together 192/192 192/192

On #3170 alone, all 192 words of the second snapshot still matched the first colour. This PR adds the missing copy-time sync. #2341's source-write tracking makes that sync run again after the second clear. The current heads merge cleanly and the combined run also passes your existing cross-submission checks.

The test-only commit applies to 97683bb. Commit · Downloadable patch

git fetch https://github.com/steven-seagull27/VIctory.git codex/pr3170-repeated-alias-copy
git cherry-pick 1ca407f
cargo test -p victory-gpu --features diagnostics --lib copy_commands_sync_aliased_texture_sources -- --nocapture

Set VICTORY_D3D12_WARP=1 for the WARP run. AI-assisted synthetic readbacks.

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.

3 participants