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

Closed
mint17 wants to merge 554 commits from upstream-pr/257 into main
mint17 commented 2026-11-27 12:38:10 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by mint17 on 2026-11-27T12:38:10Z.


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.
<!-- greyfinch-sync:TaynanGT/Vice-Tay:issue:5526759240 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/257). Originally posted by [mint17](https://github.com/mint17) on 2026-11-27T12:38:10Z. --- 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.
TaynanGT commented 2026-11-27 12:42:03 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-27T12:42:03Z.


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

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7218568839 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/257#issuecomment-7218568839). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-27T12:42:03Z. --- @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 commented 2026-11-30 17:14:33 +00:00 (Migrated from github.com)

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-30T17:14:33Z.


main has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current main and open a new PR; I'll review it there.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7285947214 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/pull/257#issuecomment-7285947214). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-30T17:14:33Z. --- `main` has moved to a new line of the code and everything is now named Vice-Tay, so this PR no longer applies as it is (details in #468). If you'd like this change in, please rebuild it on the current `main` and open a new PR; I'll review it there.

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
TaynanGT/Vice-Tay!257
No description provided.