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

Open
AscilCH wants to merge 1 commit from upstream-pr/784 into main
AscilCH commented 2026-11-25 07:35:25 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by AscilCH on 2026-11-25T07:35:25Z.


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.)

<!-- greyfinch-sync:fxceless/victory-fork:issue:6599575675 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/784). Originally posted by [AscilCH](https://github.com/AscilCH) on 2026-11-25T07:35:25Z. --- ### 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.)*
cafeoh commented 2026-11-25 08:09:05 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by cafeoh on 2026-11-25T07:54:49Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7156392284 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/784#issuecomment-7156392284). Originally posted by [cafeoh](https://github.com/cafeoh) on 2026-11-25T07:54:49Z. --- 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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/784:upstream-pr/784'
git switch 'upstream-pr/784'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/784'
git switch 'upstream-pr/784'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/784'
git switch 'upstream-pr/784'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/784'
git switch 'main'
git merge --squash 'upstream-pr/784'
git switch 'main'
git merge --ff-only 'upstream-pr/784'
git switch 'main'
git merge 'upstream-pr/784'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
fxceless/victory-fork!784
No description provided.