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

Open
github-bot wants to merge 1 commit from github-bot/gh-784 into main AGit
Owner

@⁠AscilCH on GitHub · 2026-11-25 07:35 UTC · original
AscilCH:fix/gpu-host-tile-mappings-multi-list-order → main · +383 −11 · 2 files · 1 commits · open

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

**@⁠AscilCH** on GitHub · 2026-11-25 07:35 UTC · [original](https://github.com/fxceless/victory-fork/pull/784) `AscilCH:fix/gpu-host-tile-mappings-multi-list-order` → `main` · +383 −11 · 2 files · 1 commits · open ### 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.)*
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:51:05 +00:00
Author
Owner

@⁠cafeoh on GitHub · 2026-11-25 07:54 UTC · original · edited 2026-11-25 07:57 UTC

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.

**@⁠cafeoh** on GitHub · 2026-11-25 07:54 UTC · [original](https://github.com/fxceless/victory-fork/pull/784#issuecomment-7156392284) · edited 2026-11-25 07:57 UTC 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 has changes conflicting with the target branch.
  • crates/victory-gpu/src/host.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/784/head:github-bot/gh-784'
git switch 'github-bot/gh-784'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-784'
git switch 'github-bot/gh-784'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-784'
git switch 'github-bot/gh-784'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-784'
git switch 'main'
git merge --squash 'github-bot/gh-784'
git switch 'main'
git merge --ff-only 'github-bot/gh-784'
git switch 'main'
git merge 'github-bot/gh-784'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.