Skip to content

GPU/host: preserve UpdateTileMappings order across multi-list submissions - #784

Open
AscilCH wants to merge 1 commit into
fxceless:mainfrom
AscilCH:fix/gpu-host-tile-mappings-multi-list-order
Open

AscilCH wants to merge 1 commit into
fxceless:mainfrom
AscilCH:fix/gpu-host-tile-mappings-multi-list-order

Conversation

@AscilCH

@AscilCH AscilCH commented Nov 25, 2026

Copy link
Copy Markdown

Problem

In Host::submit(), list.run_deferred(&mut batch) ran for every command list in runs before self.queue.ExecuteCommandLists(&lists) executed any of them. Both texture::upload() and texture::card_writes() queued on_demand.uploaded() / on_demand.card_wrote() — which execute ID3D12CommandQueue::UpdateTileMappings immediately on the queue — via list.defer_host().

When a multi-list submission [List 0, List 1] read an unmapped/existing tiled texture in List 0 and mapped recycled heap tiles onto that texture in List 1, List 1's UpdateTileMappings ran on the command queue ahead of List 0, exposing uninitialized recycled VRAM tiles from previous owners to List 0 before List 1's copy or zero-fill ran.

Fix

  • Add Step::Tiles and HostList::defer_tiles() for queue-timeline tile-mapping callbacks, and use it from texture::upload() and texture::card_writes().
  • In Host::submit(), partition lists via tile_segments() before any subsequent run (k > 0) that has Step::Tiles, submitting preceding lists to self.queue before running runs[k].run_tile_steps(). When no later list has tile steps, submission stays a single ExecuteCommandLists call.

Verification

  • cargo test -p victory-gpu --locked -- host::batch: 6 passed; 0 failed; 1 ignored (benchmark), including new unit test tile_segments_split_only_at_subsequent_tile_lists and real D3D12 hardware test deferred_tile_mappings_on_second_list_do_not_expose_stale_vram_to_first_list (verifying List 0 reads 0x00 rather than recycled 0xa5 VRAM while List 1 writes and reads back 0x3c).
  • cargo clippy -p victory-gpu --all-targets --all-features --locked: 0 warnings in host.rs and texture.rs (only pre-existing 8dd30ab warnings in draw.rs:2377 and indirect.rs:1322).
  • cargo xtask policy: 171 files ok.

(AI-assisted; synthetic unit tests only, no game data.)

… submissions

In Host::submit(), every command list's `run_deferred()` ran before
`ExecuteCommandLists(&lists)` executed any of them. Both `texture::upload()`
and `texture::card_writes()` queued `on_demand.uploaded()` /
`on_demand.card_wrote()` (which execute `ID3D12CommandQueue::UpdateTileMappings`)
via `list.defer_host()`.

When a multi-list submission `[List 0, List 1]` sampled a tiled texture in
`List 0` and mapped recycled heap tiles onto that texture in `List 1`, `List 1`'s
`UpdateTileMappings` ran on the command queue ahead of `List 0`, exposing
uninitialized recycled VRAM tiles from previous owners to `List 0` before
`List 1`'s copy or zero-fill ran.

Add `Step::Tiles` / `HostList::defer_tiles()` for queue-timeline tile mapping
steps and use it from `texture::upload()` and `texture::card_writes()`. In
`Host::submit()`, split `ExecuteCommandLists` before any `runs[k]` (`k > 0`)
that has `Step::Tiles`, submitting preceding lists before running `runs[k]`'s
tile mappings. When no subsequent list carries tile steps, submission remains
a single `ExecuteCommandLists` call.
@cafeoh

cafeoh commented Nov 25, 2026 •

Copy link
Copy Markdown

Tested on an RTX 2080 Ti (11 GB) + Windows 10, in the prologue up to the prison cell scene, with VICTORY_LEVELS_ON_DEMAND=1. This fixes a bug we saw in every run.

Setup: fork main a26859f + #683, #644, #487, #606, #559, #701, #687, #142, then this PR (which also brought in main 9376fd6). It merged with no conflicts. Same switches in every run (VICTORY_DEBUG_NULL_VIEWS=1, VICTORY_SKIP_BINK=1, every frame captured from the first cutscene on).

Runs Levels on demand This PR Face of a character in the first cutscene
5 runs on no random noise (multicoloured speckle), every run, every frame
1 run off no debug magenta (texture missing)
1 run on yes correct face, in every captured frame

So the noise was recycled tile memory, as the PR describes. With this PR the prison cell scene was also the cleanest we have had: no magenta on the walls, and correct lighting on the character's hair.

Frame times were about the same with and without the PR (about 0.4–1.0 s a frame on this card; the game's own timing line puts most of it in GPU work and copying back, and our picture capture adds about 60 ms a frame), so I saw no slowdown from the split submissions.

Tested: the first cutscene and the cell scene, 1 run with the PR against 5 without. Not tested: later scenes, the unit tests, cargo clippy.

AI use: tested and written with Claude Code.

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.

2 participants