GPU: stage HostHeap descriptor updates until submission flush #2046

Closed
fuzeofficlal wants to merge 1 commit from upstream-pr/2048 into main
fuzeofficlal commented 2026-11-25 04:06:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T04:06:45Z.


Refs #1348.

Summary

  • Stage HostHeap descriptor writes (mirror, make_at, make_null, raw_view_at, raw_pair_at) into CPU-only staging chunks and publish each slot atomically alongside its strides, marks, and addresses side-table entries in HostHeap::flush, called under Host::execute's submission lock right before ExecuteCommandLists and again after the submission finishes waiting, before release_retired.
  • Keep HostHeap::view_addresses synchronized with HostHeap::flush via Staged::published_addresses (under the staged mutex) rather than reading self.made directly, so unflushed made updates never leak into the view-address buffer ahead of their staged descriptors.
  • Log a one-time warning and fall back to writing descriptors and side tables directly when alloc_staged (CreateDescriptorHeap) fails instead of dropping slot updates.

Verification

  • descriptor::host::tests::concurrent_slot_rewrites_do_not_corrupt_in_flight_32_list_submission
  • descriptor::host::tests::staged_slots_publish_descriptors_and_side_tables_atomically
  • descriptor::host::tests::view_addresses_stays_synchronized_with_staged_flushes
  • descriptor::host::tests::alloc_staged_failure_falls_back_to_direct_writes
  • cargo clippy -p victory-gpu --tests --locked -- -D warnings and cargo xtask policy: passed.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6596976398 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2048). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T04:06:45Z. --- Refs #1348. ### Summary - Stage `HostHeap` descriptor writes (`mirror`, `make_at`, `make_null`, `raw_view_at`, `raw_pair_at`) into CPU-only staging chunks and publish each slot atomically alongside its `strides`, `marks`, and `addresses` side-table entries in `HostHeap::flush`, called under `Host::execute`'s submission lock right before `ExecuteCommandLists` and again after the submission finishes waiting, before `release_retired`. - Keep `HostHeap::view_addresses` synchronized with `HostHeap::flush` via `Staged::published_addresses` (under the `staged` mutex) rather than reading `self.made` directly, so unflushed `made` updates never leak into the view-address buffer ahead of their staged descriptors. - Log a one-time warning and fall back to writing descriptors and side tables directly when `alloc_staged` (`CreateDescriptorHeap`) fails instead of dropping slot updates. ### Verification - `descriptor::host::tests::concurrent_slot_rewrites_do_not_corrupt_in_flight_32_list_submission` - `descriptor::host::tests::staged_slots_publish_descriptors_and_side_tables_atomically` - `descriptor::host::tests::view_addresses_stays_synchronized_with_staged_flushes` - `descriptor::host::tests::alloc_staged_failure_falls_back_to_direct_writes` - `cargo clippy -p victory-gpu --tests --locked -- -D warnings` and `cargo xtask policy`: passed.
catminou4 commented 2026-11-25 05:05:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T04:17:29Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

HostHeap descriptor writes staged until GPU idle — fixes a descriptor-tearing race; perf cost on every heap write, check how often the idle wait triggers.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051789035 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2048#pullrequestreview-6051789035). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T04:17:29Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. HostHeap descriptor writes staged until GPU idle — fixes a descriptor-tearing race; perf cost on every heap write, check how often the idle wait triggers.
jeremygold02 commented 2026-11-25 05:06:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T04:14:56Z.


Triage verdict — Keep the staging approach, publish each slot atomically (da8574b)

Evidence

  • @fuzeofficlal defers writes to the GPU-visible heap, but slot creation enqueues descriptor, stride, and mark changes separately. The mirror path can enqueue side-table changes before the descriptor. A flush between queue operations can publish a descriptor with stale metadata or metadata for a descriptor that has yet to be copied. Slot staging · Mirror staging

Checks and limits

  • The submitted 32-list synthetic test passed on WARP. A disposable deterministic test forced a flush between the existing staging calls. The descriptor op was drained while the stride and mark still held the old values. A second flush was needed to publish the matching stride and mark. This reproduced the split without changing production code.
  • The existing 32-list shader checks a single result dword and does not consume the side tables. Local debug messages were unavailable, so this run does not independently establish a clean debug-layer result or resolution of #1348. Existing test

Next step

  • Enqueue the descriptor, stride, mark, address, and associated resource ownership as one publication unit. Include both descriptors in that unit for paired slots. Retain the deterministic interleaving test and give the GPU fixture distinct output for each list so it can check every read.

This verification was AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7152668172 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2048#issuecomment-7152668172). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-25T04:14:56Z. --- **Triage verdict — Keep the staging approach, publish each slot atomically** (`da8574b`) **Evidence** - @fuzeofficlal defers writes to the GPU-visible heap, but slot creation enqueues descriptor, stride, and mark changes separately. The mirror path can enqueue side-table changes before the descriptor. A flush between queue operations can publish a descriptor with stale metadata or metadata for a descriptor that has yet to be copied. [Slot staging](https://github.com/Marvisak/VIctory/blob/da8574ba542debc39f456a19fce3f5626cdef593/crates/victory-gpu/src/descriptor/host.rs#L449-L542) · [Mirror staging](https://github.com/Marvisak/VIctory/blob/da8574ba542debc39f456a19fce3f5626cdef593/crates/victory-gpu/src/descriptor/host.rs#L828-L858) **Checks and limits** - The submitted 32-list synthetic test passed on WARP. A disposable deterministic test forced a flush between the existing staging calls. The descriptor op was drained while the stride and mark still held the old values. A second flush was needed to publish the matching stride and mark. This reproduced the split without changing production code. - The existing 32-list shader checks a single result dword and does not consume the side tables. Local debug messages were unavailable, so this run does not independently establish a clean debug-layer result or resolution of #1348. [Existing test](https://github.com/Marvisak/VIctory/blob/da8574ba542debc39f456a19fce3f5626cdef593/crates/victory-gpu/src/descriptor/host.rs#L1951-L2019) **Next step** - Enqueue the descriptor, stride, mark, address, and associated resource ownership as one publication unit. Include both descriptors in that unit for paired slots. Retain the deterministic interleaving test and give the GPU fixture distinct output for each list so it can check every read. This verification was AI-assisted.
fuzeofficlal commented 2026-11-25 05:06:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T04:50:19Z.


Updated in cdc6fbd0 — thanks @jeremygold02 for catching the split staging window:

  • Replaced separate StagedOp queue pushes with composite StagedSlot { index, descriptor, stride, mark, address } records committed in a single commit_staged lock scope across mirror, make_at, make_null, raw_pair_at (both pair slots together), and raw_view_at(..., mark) (eliminating the separate set_mark call in State::root_view).
  • Added staged_slots_publish_descriptors_and_side_tables_atomically testing deterministic pre/post-flush isolation, 4,000 interleaved flushes against concurrent slot rewrites, and 16 GPU compute dispatches reading HostHeap and all three side tables simultaneously across RTX 5090, AMD RDNA2, and WARP.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7153209984 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2048#issuecomment-7153209984). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T04:50:19Z. --- Updated in `cdc6fbd0` — thanks @jeremygold02 for catching the split staging window: - Replaced separate `StagedOp` queue pushes with composite `StagedSlot { index, descriptor, stride, mark, address }` records committed in a single `commit_staged` lock scope across `mirror`, `make_at`, `make_null`, `raw_pair_at` (both pair slots together), and `raw_view_at(..., mark)` (eliminating the separate `set_mark` call in `State::root_view`). - Added `staged_slots_publish_descriptors_and_side_tables_atomically` testing deterministic pre/post-flush isolation, 4,000 interleaved flushes against concurrent slot rewrites, and 16 GPU compute dispatches reading `HostHeap` and all three side tables simultaneously across RTX 5090, AMD RDNA2, and WARP.
Marvisak commented 2026-11-25 10:07:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T09:20:16Z.


Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-gpu/src/descriptor.rs, crates/victory-gpu/src/descriptor/host.rs, crates/victory-gpu/src/host.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs-work) was for an older state of main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7158194826 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2048#issuecomment-7158194826). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T09:20:16Z. --- <!-- victory-triage v1 head=dfb8093370e5a5e396f1f584a14c4efb96f6241b verdict=needs-rebase at=2026-11-25T15:56:00Z --> Automated triage for the maintainers. This pull request no longer merges cleanly into `main` (conflicts in `crates/victory-gpu/src/descriptor.rs`, `crates/victory-gpu/src/descriptor/host.rs`, `crates/victory-gpu/src/host.rs`). It will be reviewed once it is rebased onto the current `main`. The earlier verdict (needs-work) was for an older state of `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
upstream-sync changed title from [PR #2048] GPU: stage HostHeap descriptor writes until the GPU is idle to [PR #2048] GPU: stage HostHeap descriptor updates until submission flush 2026-11-25 11:03:37 +00:00
fuzeofficlal commented 2026-11-25 11:05:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T10:34:31Z.


Updated in 40d0bcec per triage feedback:

  • view_addresses synchronization: HostHeap::view_addresses now initializes from Staged::published_addresses under the staged lock (and updates published_addresses + addresses_data atomically inside write_side_tables during flush), rather than reading self.made directly ahead of staged descriptors. Covered by view_addresses_stays_synchronized_with_staged_flushes.
  • alloc_staged fallback & warning: When CreateDescriptorHeap fails in alloc_staged, it now logs a one-time tracing::warn! and falls back (target_handles + finish_slots(..., false)) to writing descriptors and side tables directly instead of dropping the update. Covered by alloc_staged_failure_falls_back_to_direct_writes.
  • Title, doc comments & issue link: Updated the title and doc comments across descriptor.rs, descriptor/host.rs, host.rs, and memory.rs to state accurately that staged updates are published under Host::execute's submission lock before ExecuteCommandLists and again after completion before release_retired, and changed Closes #1348 to Refs #1348.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7159882504 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2048#issuecomment-7159882504). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T10:34:31Z. --- Updated in `40d0bcec` per triage feedback: - **`view_addresses` synchronization**: `HostHeap::view_addresses` now initializes from `Staged::published_addresses` under the `staged` lock (and updates `published_addresses` + `addresses_data` atomically inside `write_side_tables` during `flush`), rather than reading `self.made` directly ahead of staged descriptors. Covered by `view_addresses_stays_synchronized_with_staged_flushes`. - **`alloc_staged` fallback & warning**: When `CreateDescriptorHeap` fails in `alloc_staged`, it now logs a one-time `tracing::warn!` and falls back (`target_handles` + `finish_slots(..., false)`) to writing descriptors and side tables directly instead of dropping the update. Covered by `alloc_staged_failure_falls_back_to_direct_writes`. - **Title, doc comments & issue link**: Updated the title and doc comments across `descriptor.rs`, `descriptor/host.rs`, `host.rs`, and `memory.rs` to state accurately that staged updates are published under `Host::execute`'s submission lock before `ExecuteCommandLists` and again after completion before `release_retired`, and changed `Closes #1348` to `Refs #1348`.
fuzeofficlal commented 2026-11-25 14:07:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T13:15:17Z.


Updated in dfb80933 (rebased onto 940d32f) to fix the fallback-ordering issue noted above:

  • target_handles / finish_slots(.., false): When alloc_staged falls back to direct writes, queued StagedSlot entries for those slot indices are dropped under self.staged before writing directly and before updating side tables, so a subsequent flush cannot overwrite the newer direct descriptor or side-table entries.
  • Test: Added direct_fallback_drops_older_queued_updates_for_the_same_slot covering queued staged writes followed by fail_alloc direct writes and flush.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7163510653 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2048#issuecomment-7163510653). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T13:15:17Z. --- Updated in `dfb80933` (rebased onto `940d32f`) to fix the fallback-ordering issue noted above: - **`target_handles` / `finish_slots(.., false)`**: When `alloc_staged` falls back to direct writes, queued `StagedSlot` entries for those slot indices are dropped under `self.staged` before writing directly and before updating side tables, so a subsequent `flush` cannot overwrite the newer direct descriptor or side-table entries. - **Test**: Added `direct_fallback_drops_older_queued_updates_for_the_same_slot` covering queued staged writes followed by `fail_alloc` direct writes and `flush`.
andrewpozdnakov7-jpg commented 2026-11-25 14:07:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T13:20:26Z.


I verified the updated dfb8093 on Windows app-local WARP. All 10 descriptor::host::tests passed, including direct_fallback_drops_older_queued_updates_for_the_same_slot. The readbacks cover both the direct replacement in slot 0 and the unrelated staged update in slot 1. I also reproduced the stale replay on the previous 40d0bce with an independent two-slot fixture.

AI-assisted with Codex. Synthetic buffers only.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7163634539 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2048#issuecomment-7163634539). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-25T13:20:26Z. --- I verified the updated `dfb8093` on Windows app-local WARP. All 10 `descriptor::host::tests` passed, including `direct_fallback_drops_older_queued_updates_for_the_same_slot`. The readbacks cover both the direct replacement in slot 0 and the unrelated staged update in slot 1. I also reproduced the stale replay on the previous `40d0bce` with an independent two-slot fixture. AI-assisted with Codex. Synthetic buffers only.
upstream-sync closed this pull request 2026-11-25 17:03:22 +00:00
fuzeofficlal commented 2026-11-25 17:05:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T16:11:24Z.


Closing for now: da82e444 refactored HostHeap descriptor creation/eviction and 16-byte view-address side tables (42ea09f, f809521, 52d14b1, e790217), and we do not have an in-title A/B run past #1348 to justify rebasing this core-path staging layer.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167671757 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2048#issuecomment-7167671757). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T16:11:24Z. --- Closing for now: `da82e444` refactored `HostHeap` descriptor creation/eviction and 16-byte view-address side tables (`42ea09f`, `f809521`, `52d14b1`, `e790217`), and we do not have an in-title A/B run past `#1348` to justify rebasing this core-path staging layer.

Pull request closed

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!2046
No description provided.