gpu/heap_worker: add race-safe opt-in VICTORY_HEAP_WORKER (#66) #257

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

@⁠mint17 on GitHub · 2026-11-27 12:38 UTC · original
mint17:feat/heap-worker-race-safe → main · +1172 −66 · 9 files · 1 commits · open

Addresses the VICTORY_HEAP_WORKER item in #66 (porting fxceless/victory-fork's opt-in texture upload worker, off by default and gated by host::late()) while closing the descriptor-publication TOCTOU race called out on #66 and preserving Vice-Tay's bake, residency, and relay guards.

Key Changes

  • Dedicated victory-heap worker (heap_worker.rs): Opt-in via VICTORY_HEAP_WORKER=1 (off by default), 128 MiB / 80 ms batch flush, fast-core pinning (cores::keep_on_fast_cores), AtomicUsize urgent waiter guard with RAII decrement, Ready.list: Option<HostList> so same-only batches publish cleanly without allocating an empty list, plus split take_ready_for_late() and drain_for_bake(gpu) (settling in-flight GPU work via settle_for_fence() even on list-less batches).
  • Key-pinned TOCTOU-free descriptor publication (descriptor/host.rs): Refactors publish_uploaded_slot around publish_uploaded_slot_with(index, handle, key, ...) which re-verifies record_key(handle) == key under self.made.lock(index) and resolves View strictly from key (view_at) without re-reading handle or calling mirror(). Fixes the latent note_buffer re-queue loop with a RAII PublishingGuard checked in queue_texture(), restores lock-free quick_is and residency::upload_deferred_during, and preserves VICTORY_SHOW_AFTER=1, VICTORY_SHOW_NEW_LATER=1, and VICTORY_HELD_LEVELS=1 shows_other mip-upgrade deferral in publish_for_late().
  • COM lifetime pinning (object.rs, resource.rs, draw.rs): Adds object::add_ref_alive (AcqRel/Acquire CAS with checked_add) and resource::hold / Held to pin live texture and heap objects across worker execution, including State::card_accounting.
  • VICTORY_JOIN_PARTS & VICTORY_TEXTURE_ONCE compatibility (host.rs, list.rs, texture.rs): Hooks take_ready_for_late() in Host::send_late() via prepend_ahead_order() so joined-part split indices shift cleanly alongside prepended worker lists; adds Staging::refresh_ahead() using self.read / digest(read) / keep_whole(read) while skipping write-watching on self.once textures.

Verification

  • Deterministic TOCTOU regression test requested in #66 plus targeted unit tests (rebased on 5b2dc68):
    • descriptor::host::bake_flip_tests::publish_rejects_slot_replaced_between_reads
    • descriptor::host::bake_flip_tests::published_slot_stays_out_of_texture_queue
    • descriptor::host::bake_flip_tests::publish_for_late_same_after_combines_show_after_and_new_later
    • descriptor::host::bake_flip_tests::publish_for_late_defers_shows_other_mip_upgrade
    • host::submission_tests::prepend_ahead_lists_shifts_join_parts
    • object::tests::add_ref_alive_rejects_zero_refcount
    • heap_worker::tests::urgent_stops_worker_and_ready_drains_cleanly
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings (default + --all-features) and cargo test --locked -p xtask passed with zero warnings.
  • Verified with synthetic unit and concurrency tests only (no title files locally); opt-in flag stays off by default.
**@⁠mint17** on GitHub · 2026-11-27 12:38 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/257) `mint17:feat/heap-worker-race-safe` → `main` · +1172 −66 · 9 files · 1 commits · open Addresses the `VICTORY_HEAP_WORKER` item in #66 (porting `fxceless/victory-fork`'s opt-in texture upload worker, off by default and gated by `host::late()`) while closing the descriptor-publication TOCTOU race called out on #66 and preserving Vice-Tay's bake, residency, and relay guards. ### Key Changes - **Dedicated `victory-heap` worker ([`heap_worker.rs`](crates/victory-gpu/src/heap_worker.rs)):** Opt-in via `VICTORY_HEAP_WORKER=1` (off by default), 128 MiB / 80 ms batch flush, fast-core pinning (`cores::keep_on_fast_cores`), `AtomicUsize` urgent waiter guard with RAII decrement, `Ready.list: Option<HostList>` so `same`-only batches publish cleanly without allocating an empty list, plus split `take_ready_for_late()` and `drain_for_bake(gpu)` (settling in-flight GPU work via `settle_for_fence()` even on list-less batches). - **Key-pinned TOCTOU-free descriptor publication (`descriptor/host.rs`):** Refactors `publish_uploaded_slot` around `publish_uploaded_slot_with(index, handle, key, ...)` which re-verifies `record_key(handle) == key` under `self.made.lock(index)` and resolves `View` strictly from `key` (`view_at`) without re-reading `handle` or calling `mirror()`. Fixes the latent `note_buffer` re-queue loop with a RAII `PublishingGuard` checked in `queue_texture()`, restores lock-free `quick_is` and `residency::upload_deferred_during`, and preserves `VICTORY_SHOW_AFTER=1`, `VICTORY_SHOW_NEW_LATER=1`, and `VICTORY_HELD_LEVELS=1` `shows_other` mip-upgrade deferral in `publish_for_late()`. - **COM lifetime pinning (`object.rs`, `resource.rs`, `draw.rs`):** Adds `object::add_ref_alive` (`AcqRel`/`Acquire` CAS with `checked_add`) and `resource::hold` / `Held` to pin live texture and heap objects across worker execution, including `State::card_accounting`. - **`VICTORY_JOIN_PARTS` & `VICTORY_TEXTURE_ONCE` compatibility (`host.rs`, `list.rs`, `texture.rs`):** Hooks `take_ready_for_late()` in `Host::send_late()` via `prepend_ahead_order()` so joined-part split indices shift cleanly alongside prepended worker lists; adds `Staging::refresh_ahead()` using `self.read` / `digest(read)` / `keep_whole(read)` while skipping write-watching on `self.once` textures. ### Verification - Deterministic TOCTOU regression test requested in #66 plus targeted unit tests (rebased on `5b2dc68`): - `descriptor::host::bake_flip_tests::publish_rejects_slot_replaced_between_reads` - `descriptor::host::bake_flip_tests::published_slot_stays_out_of_texture_queue` - `descriptor::host::bake_flip_tests::publish_for_late_same_after_combines_show_after_and_new_later` - `descriptor::host::bake_flip_tests::publish_for_late_defers_shows_other_mip_upgrade` - `host::submission_tests::prepend_ahead_lists_shifts_join_parts` - `object::tests::add_ref_alive_rejects_zero_refcount` - `heap_worker::tests::urgent_stops_worker_and_ready_drains_cleanly` - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` (default + `--all-features`) and `cargo test --locked -p xtask` passed with zero warnings. - Verified with synthetic unit and concurrency tests only (no title files locally); opt-in flag stays off by default.
Port fxceless/victory-fork's opt-in VICTORY_HEAP_WORKER=1 texture upload
worker to Vice-Tay while closing the descriptor publication TOCTOU race
noted in #66 and preserving Vice-Tay's bake, residency, and relay guards:

- Add crates/victory-gpu/src/heap_worker.rs (off by default, gated by
  host::late(), 128 MiB / 80 ms batch flush, fast-core pinning,
  AtomicUsize urgent waiter guard, Ready.list: Option<HostList> for
  same-only passes, take_ready_for_late and drain_for_bake with
  settle_for_fence).
- Add object::add_ref_alive and resource::hold/Held to pin live texture
  and heap COM objects safely across worker execution (including
  State::card_accounting).
- Close the #66 TOCTOU race in HostHeap::publish_uploaded_slot_with and
  publish_for_late: re-verify record_key(handle) == key under
  self.made.lock(index), resolve View strictly from key without
  re-reading handle or calling mirror(), fix the latent note_buffer
  re-queue loop with a RAII PublishingGuard, restore quick_is/residency
  deferral, and preserve VICTORY_SHOW_AFTER=1, VICTORY_SHOW_NEW_LATER=1,
  and VICTORY_HELD_LEVELS=1 shows_other mip-upgrade deferral.
- Hook take_ready_for_late() in Host::send_late() with
  prepend_ahead_order() so VICTORY_JOIN_PARTS split indices stay aligned,
  and add Staging::refresh_ahead() preserving VICTORY_TEXTURE_ONCE=1.
- Add deterministic TOCTOU regression test
  publish_rejects_slot_replaced_between_reads plus unit tests for
  queue retention, show-after/mip-upgrade deferral, join-parts shifting,
  add_ref_alive, and urgent waiter handoff.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 12:41:28 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 12:42 UTC · original

@⁠mint17 Rechecking the recorded key under the same slot lock is the important part of the publication fix. I’ll check the fence and resource lifetime alongside the replacement regression, especially when a batch has no command list and when joined parts shift. The opt-in path gives us a separate A/B once those checks are in place.

**@⁠TaynanGT** on GitHub · 2026-11-27 12:42 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/257#issuecomment-7218568839) @⁠mint17 Rechecking the recorded key under the same slot lock is the important part of the publication fix. I’ll check the fence and resource lifetime alongside the replacement regression, especially when a batch has no command list and when joined parts shift. The opt-in path gives us a separate A/B once those checks are in place.
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/257/head:github-bot/gh-257'
git switch 'github-bot/gh-257'

Merge

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