GPU: preserve pre-init dynamic and concurrent view_addresses updates #3175

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

@⁠fuzeofficlal on GitHub · 2026-11-26 11:10 UTC · original
fuzeofficlal:fix/gpu-view-addresses-init → main · +287 −19 · 1 files · 1 commits · open

Summary

Fixes two correctness bugs in HostHeap::view_addresses and HostHeap::note_address (crates/victory-gpu/src/descriptor/host.rs) where descriptor view-address entries were silently zeroed or permanently lost around lazy upload-buffer initialization:

  1. Dynamic slots populated before first view_addresses() call were overwritten with zeros: HostHeap::note_address dropped every update while self.addresses (OnceLock) was still uninitialized, and view_addresses() unconditionally zeroed self.count..self.address_slots() on first use. When an earlier draw/dispatch or an earlier shader stage in the same pipeline populated dynamic slots via make_at and cached them in State::fresh_tables (draw.rs), a subsequent stage/draw requiring view_addresses hit fresh_tables without calling make_at again and read [0, 0, 0, 0] instead of the buffer GPU address or texture size words.
  2. Concurrent mirror / make_at updates racing OnceLock publication were permanently lost: view_addresses() released self.made at the end of the get_or_init closure before OnceLock published self.addresses. Any concurrent mirror() or make_at() running in that window saw self.addresses.get() == None and skipped write_address; for title slots, self.made[index] already held the new key so later mirror() calls took the fast path and left view_addresses[index] permanently stale.

Fix

  • Add address_state: Mutex<AddressState> (Pending(HashMap<u32, [u32; 4]>) -> Ready(usize)) alongside the existing OnceLock in HostHeap.
  • Keep the lock-free self.addresses.get() fast path in note_address once published. Before publication, record dynamic-slot words (index >= self.count) in Pending (removing cleared [0; 4] entries) or write directly once Ready(data).
  • In view_addresses(), fill title slots under made, zero dynamic slots, then transition address_state to Ready(data) and replay all pending dynamic-slot words before releasing address_state and made (preserving lock order made -> address_state).

Testing

Added two deterministic regression tests in crates/victory-gpu/src/descriptor/host.rs:

  • dynamic_slots_made_before_view_addresses_keep_their_entries (fails on main with Some(0) instead of the latest dynamic buffer address / texture words; passes after fix).
  • concurrent_updates_during_view_addresses_init_are_not_lost (fails on main with stale pre-init title-slot address even after re-mirroring; passes after fix for title overwrite, title clear, and dynamic slot creation during the init window).

Verified on Windows x64:

  • cargo test -p victory-gpu --locked view_addresses (RTX 5090): 3/3 passed
  • VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked view_addresses (RTX 5090): 3/3 passed, 0 debug-layer messages
  • VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked descriptor::host::tests -- --test-threads=1: 17/17 passed, 0 debug-layer messages
  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --locked: 248 passed, 0 failed, 1 ignored
  • cargo clippy --workspace --all-targets --locked -- -D warnings & --all-features: clean
  • cargo test -p xtask --locked policy::tests::repository_passes_policy: passed
**@⁠fuzeofficlal** on GitHub · 2026-11-26 11:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/3175) `fuzeofficlal:fix/gpu-view-addresses-init` → `main` · +287 −19 · 1 files · 1 commits · open ### Summary Fixes two correctness bugs in `HostHeap::view_addresses` and `HostHeap::note_address` (`crates/victory-gpu/src/descriptor/host.rs`) where descriptor view-address entries were silently zeroed or permanently lost around lazy upload-buffer initialization: 1. **Dynamic slots populated before first `view_addresses()` call were overwritten with zeros**: `HostHeap::note_address` dropped every update while `self.addresses` (`OnceLock`) was still uninitialized, and `view_addresses()` unconditionally zeroed `self.count..self.address_slots()` on first use. When an earlier draw/dispatch or an earlier shader stage in the same pipeline populated dynamic slots via `make_at` and cached them in `State::fresh_tables` (`draw.rs`), a subsequent stage/draw requiring `view_addresses` hit `fresh_tables` without calling `make_at` again and read `[0, 0, 0, 0]` instead of the buffer GPU address or texture size words. 2. **Concurrent `mirror` / `make_at` updates racing `OnceLock` publication were permanently lost**: `view_addresses()` released `self.made` at the end of the `get_or_init` closure before `OnceLock` published `self.addresses`. Any concurrent `mirror()` or `make_at()` running in that window saw `self.addresses.get() == None` and skipped `write_address`; for title slots, `self.made[index]` already held the new key so later `mirror()` calls took the fast path and left `view_addresses[index]` permanently stale. ### Fix - Add `address_state: Mutex<AddressState>` (`Pending(HashMap<u32, [u32; 4]>)` -> `Ready(usize)`) alongside the existing `OnceLock` in `HostHeap`. - Keep the lock-free `self.addresses.get()` fast path in `note_address` once published. Before publication, record dynamic-slot words (`index >= self.count`) in `Pending` (removing cleared `[0; 4]` entries) or write directly once `Ready(data)`. - In `view_addresses()`, fill title slots under `made`, zero dynamic slots, then transition `address_state` to `Ready(data)` and replay all pending dynamic-slot words before releasing `address_state` and `made` (preserving lock order `made -> address_state`). ### Testing Added two deterministic regression tests in `crates/victory-gpu/src/descriptor/host.rs`: - `dynamic_slots_made_before_view_addresses_keep_their_entries` (fails on `main` with `Some(0)` instead of the latest dynamic buffer address / texture words; passes after fix). - `concurrent_updates_during_view_addresses_init_are_not_lost` (fails on `main` with stale pre-init title-slot address even after re-mirroring; passes after fix for title overwrite, title clear, and dynamic slot creation during the init window). Verified on Windows x64: - `cargo test -p victory-gpu --locked view_addresses` (RTX 5090): 3/3 passed - `VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked view_addresses` (RTX 5090): 3/3 passed, 0 debug-layer messages - `VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked descriptor::host::tests -- --test-threads=1`: 17/17 passed, 0 debug-layer messages - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --locked`: 248 passed, 0 failed, 1 ignored - `cargo clippy --workspace --all-targets --locked -- -D warnings` & `--all-features`: clean - `cargo test -p xtask --locked policy::tests::repository_passes_policy`: passed
HostHeap::view_addresses lazily allocates the view-address upload buffer in a OnceLock, while HostHeap::note_address dropped every update until OnceLock::get returned Some. Dynamic slots populated via make_at before the first view_addresses call (for example cached fresh tables from an earlier draw or pipeline stage) were then overwritten with zeros, and concurrent mirror or make_at calls racing OnceLock publication after made was released were lost permanently.

Track pending dynamic-slot words in HostHeap::address_state until view_addresses populates the upload buffer, replay them under lock while transitioning to Ready(data), and forward pre-publication note_address calls through Ready(data) while keeping the lock-free OnceLock::get fast path once published.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 11:32:48 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 11:28 UTC · original · approved these changes

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

  • cargo test -p victory-gpu --lib descriptor::host:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released: 16/16 passed on RTX 5090 and WARP (including concurrent_updates_during_view_addresses_init_are_not_lost and dynamic_slots_made_before_view_addresses_keep_their_entries).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly preserves pre-init dynamic entries and concurrent updates during view_addresses initialization.

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

**@⁠Dukestar69** on GitHub · 2026-11-26 11:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/3175#pullrequestreview-6073363734) · **approved these changes** Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-gpu --lib descriptor::host:: -- --test-threads=1 --skip dynamic_slots_are_held_until_released`: 16/16 passed on RTX 5090 and WARP (including `concurrent_updates_during_view_addresses_init_are_not_lost` and `dynamic_slots_made_before_view_addresses_keep_their_entries`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly preserves pre-init dynamic entries and concurrent updates during `view_addresses` initialization. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 11:42 UTC · original

@⁠fuzeofficlal I tested the upload-table allocation independently on main 63bcca43 and your exact 12a89d2. Both retain the first allocation refusal for the heap's lifetime. A draw needing the table can keep getting dropped after upload memory becomes available.

With the same synthetic WARP test, a four-slot title heap first requests 4,194,368 bytes and the fixture refuses that request once. On both baselines there is no second allocator call and the table remains unavailable. The follow-up requests the same 4,194,368 bytes again, obtains a GPU address, reuses it on the next lookup, and updates and clears a dynamic descriptor. It also adds an initial refusal to your pending-slot test, which still recovers the previously recorded buffer and texture words.

Your concurrent writer test passed on app-local SDK 620 and WARP 1.0.22. Full GPU diagnostics passed 249 tests with 1 ignored. Strict GPU Clippy passed in both configurations, and the repository asset policy passed.

Follow-up commit on your current head. Please retain the Git author if you cherry-pick it, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if you fold it into your commit.

AI-assisted with Codex. Synthetic descriptors only.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 11:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/3175#issuecomment-7191066038) @⁠fuzeofficlal I tested the upload-table allocation independently on main `63bcca43` and your exact `12a89d2`. Both retain the first allocation refusal for the heap's lifetime. A draw needing the table can keep getting dropped after upload memory becomes available. With the same synthetic WARP test, a four-slot title heap first requests 4,194,368 bytes and the fixture refuses that request once. On both baselines there is no second allocator call and the table remains unavailable. The follow-up requests the same 4,194,368 bytes again, obtains a GPU address, reuses it on the next lookup, and updates and clears a dynamic descriptor. It also adds an initial refusal to your pending-slot test, which still recovers the previously recorded buffer and texture words. Your concurrent writer test passed on app-local SDK 620 and WARP 1.0.22. Full GPU diagnostics passed 249 tests with 1 ignored. Strict GPU Clippy passed in both configurations, and the repository asset policy passed. [Follow-up commit on your current head](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/6ceee44ff041cacc04ddf162d8b01d8317bbf765). Please retain the Git author if you cherry-pick it, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if you fold it into your commit. AI-assisted with Codex. Synthetic descriptors only.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 18:27 UTC · original

I also tested the address-table retry together with #3276’s descriptor recovery. The combined result on #3276 keeps the original heads and adds a test that makes the two allocations fail independently. On WARP, the address table recovers while the descriptor slot is still null, and the next make_read recovers the actual texture with the expected view-address words. The focused test passed 3/3 and the full GPU suite passed 252 with one ignored.

The follow-up to this PR is still 6ceee44 if you want to review it separately. If you fold our change or test into another commit, please preserve its Git author or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 18:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/3175#issuecomment-7200477727) I also tested the address-table retry together with #3276’s descriptor recovery. The [combined result on #3276](https://git.gtahub.st/github/Marvisak--VIctory/pulls/3276) keeps the original heads and adds a test that makes the two allocations fail independently. On WARP, the address table recovers while the descriptor slot is still null, and the next `make_read` recovers the actual texture with the expected view-address words. The focused test passed 3/3 and the full GPU suite passed 252 with one ignored. The follow-up to this PR is still [`6ceee44`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/6ceee44ff041cacc04ddf162d8b01d8317bbf765) if you want to review it separately. If you fold our change or test into another commit, please preserve its Git author or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>`.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3175'
git switch 'github-bot/gh-3175'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3175'
git switch 'github-bot/gh-3175'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3175'
git switch 'main'
git merge --squash 'github-bot/gh-3175'
git switch 'main'
git merge --ff-only 'github-bot/gh-3175'
git switch 'main'
git merge 'github-bot/gh-3175'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3175
No description provided.