GPU: replay pending descriptors before publishing the host heap #365

Merged
FIocker merged 1 commit from upstream-pr/365 into main 2026-11-24 08:02:47 +00:00
FIocker commented 2026-11-24 02:37:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by FIocker on 2026-11-24T02:37:30Z.


Publish the host heap only after replaying the descriptors queued before first use. Previously the OnceLock was initialized before the pending loop ran. A concurrent caller could take the fast path, bind the heap, and proceed before its queued descriptor writes became visible.

Replay the queued writes inside the OnceLock initializer while holding the existing pending mutex. The fast path remains unchanged after initialization. This is independent of #52, which covers heap lifetime during descriptor mirroring.

On Windows WARP, cargo test --locked -p victory-gpu --features diagnostics -- --test-threads=1 passed 45 tests with one existing ignored test. The staged asset policy and diff checks passed.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6573359757 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/365). Originally posted by [FIocker](https://github.com/FIocker) on 2026-11-24T02:37:30Z. --- Publish the host heap only after replaying the descriptors queued before first use. Previously the OnceLock was initialized before the pending loop ran. A concurrent caller could take the fast path, bind the heap, and proceed before its queued descriptor writes became visible. Replay the queued writes inside the OnceLock initializer while holding the existing pending mutex. The fast path remains unchanged after initialization. This is independent of #52, which covers heap lifetime during descriptor mirroring. On Windows WARP, `cargo test --locked -p victory-gpu --features diagnostics -- --test-threads=1` passed 45 tests with one existing ignored test. The staged asset policy and diff checks passed.
jeremygold02 commented 2026-11-24 06:55:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-24T03:58:11Z.


Thanks @FIocker for this change. I tested head a4e7f1d004bff927c205981c623142c8e7dbb4a4 with:

cargo test --locked -p victory-gpu --features diagnostics --lib descriptor -- --test-threads=1

Result: 5 passed, 0 failed (41 filtered out). This exercised descriptor heap slot allocation/release, heap start placement, and descriptor-view lifetime across resource destruction and copies. The filtered tests do not directly stress concurrent first-use publication, and I did not run the broader WARP suite described in the PR body.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7121586425 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/365#issuecomment-7121586425). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-24T03:58:11Z. --- Thanks @FIocker for this change. I tested head `a4e7f1d004bff927c205981c623142c8e7dbb4a4` with: ``` cargo test --locked -p victory-gpu --features diagnostics --lib descriptor -- --test-threads=1 ``` Result: 5 passed, 0 failed (41 filtered out). This exercised descriptor heap slot allocation/release, heap start placement, and descriptor-view lifetime across resource destruction and copies. The filtered tests do not directly stress concurrent first-use publication, and I did not run the broader WARP suite described in the PR body.
mercuryVM commented 2026-11-24 08:02:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T07:42:37Z.

Review: APPROVED


Tested a4e7f1d on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (264 passed, 0 failed), and cargo test -p victory-gpu --features diagnostics --lib passes (45, 1 ignored).

  • The race is real. OnceLock::get_or_init published the heap before the pending replay, so a recorder on the get() fast path could bind a heap whose queued slots were still unwritten. Replaying inside the initializer means get() only ever sees a fully mirrored heap, because OnceLock makes other callers wait until the closure returns.
  • Re-entrancy: HostHeap::mirror reads the title's descriptor and writes the host slot. It doesn't go back through Heap::host, so running it inside get_or_init can't recurse into the same OnceLock.
  • Small behaviour difference: if increment(kind) were None, the OnceLock now stores None where it used to store the heap. That never happens for the four real heap kinds.

No issues found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6035406287 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/365#pullrequestreview-6035406287). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T07:42:37Z. **Review:** APPROVED --- Tested a4e7f1d on Windows 11, RTX 5070, MSVC: `cargo test --workspace --no-fail-fast` passes (264 passed, 0 failed), and `cargo test -p victory-gpu --features diagnostics --lib` passes (45, 1 ignored). - The race is real. `OnceLock::get_or_init` published the heap before the `pending` replay, so a recorder on the `get()` fast path could bind a heap whose queued slots were still unwritten. Replaying inside the initializer means `get()` only ever sees a fully mirrored heap, because OnceLock makes other callers wait until the closure returns. - Re-entrancy: `HostHeap::mirror` reads the title's descriptor and writes the host slot. It doesn't go back through `Heap::host`, so running it inside `get_or_init` can't recurse into the same OnceLock. - Small behaviour difference: if `increment(kind)` were `None`, the OnceLock now stores `None` where it used to store the heap. That never happens for the four real heap kinds. No issues found. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-24 09:05:24 +00:00
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
Marvisak/VIctory!365
No description provided.