perf(descriptor): defer TextureQueue WRITE ops to per-heap pending inbox with inline QueueBatch #3104

Open
qlfu wants to merge 2 commits from upstream-pr/3104 into main
qlfu commented 2026-11-29 20:02:12 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-29T20:02:12Z.


Summary

Eliminates ~98% of global TextureQueue mutex traffic (TextureQueue::WRITE) caused by per-slot mirror(handle) calls during descriptor::record and sync_heaps:

  • Per-HostHeap pending_ops inbox + pending_count (on by default; VICTORY_QUEUE_PENDING=0 disables): single-slot mirror writes append into a per-heap inbox rather than locking the global TextureQueue on every descriptor slot.
  • 2-bit STATE_KEEPS | STATE_PENDING SeqCst CAS Dekker handshake: guarantees draining readers never miss a newly queued op while keeping the uncontended fast path lock-free.
  • Inline [QueueOp; 64] QueueBatch: avoids heap allocation for normal batches.
  • Direct host.mirror fast path in single-slot mirror_in_heaps.

Verification

  • cargo +1.98.1-x86_64-pc-windows-msvc clippy -p victory-gpu --lib --tests --no-deps --locked: 0 new warnings.
  • cargo +1.98.1-x86_64-pc-windows-msvc test -p victory-gpu --lib --locked -- descriptor::host::tests --test-threads=1: 71/71 passed.
  • Live 90s benchmarks (1440p DLSS Balanced, 0 WARNs / 0 ERRORs):
    • TextureQueue locks/5s: 84,418–85,323 -> 1,538–1,682 (-98.0%).
    • TextureQueue lock wait/5s: 376–492 ms -> 8–12 ms (-97.5%), noting 342–470 ms -> 0 ms.
    • sync_heaps wait: 1.55–1.75 ms -> 0.72–1.33 ms.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5554562669 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3104). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-29T20:02:12Z. --- ## Summary Eliminates ~98% of global `TextureQueue` mutex traffic (`TextureQueue::WRITE`) caused by per-slot `mirror(handle)` calls during `descriptor::record` and `sync_heaps`: - **Per-`HostHeap` `pending_ops` inbox + `pending_count`** (on by default; `VICTORY_QUEUE_PENDING=0` disables): single-slot `mirror` writes append into a per-heap inbox rather than locking the global `TextureQueue` on every descriptor slot. - **2-bit `STATE_KEEPS | STATE_PENDING` `SeqCst` CAS Dekker handshake**: guarantees draining readers never miss a newly queued op while keeping the uncontended fast path lock-free. - **Inline `[QueueOp; 64]` `QueueBatch`**: avoids heap allocation for normal batches. - **Direct `host.mirror` fast path** in single-slot `mirror_in_heaps`. ## Verification - `cargo +1.98.1-x86_64-pc-windows-msvc clippy -p victory-gpu --lib --tests --no-deps --locked`: 0 new warnings. - `cargo +1.98.1-x86_64-pc-windows-msvc test -p victory-gpu --lib --locked -- descriptor::host::tests --test-threads=1`: `71/71` passed. - Live 90s benchmarks (1440p DLSS Balanced, `0 WARNs / 0 ERRORs`): - `TextureQueue` locks/5s: `84,418–85,323` -> **`1,538–1,682` (`-98.0%`)**. - `TextureQueue` lock wait/5s: `376–492 ms` -> **`8–12 ms` (`-97.5%`)**, `noting` `342–470 ms` -> **`0 ms`**. - `sync_heaps` wait: `1.55–1.75 ms` -> **`0.72–1.33 ms`**.
qlfu commented 2026-11-30 12:36:48 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-30T12:36:48Z.


Fixed a concurrency race in drain_pending_into / enqueue_pending: pending_count now increments via fetch_add(ops.len(), Release) and decrements via fetch_sub(drained, Release) strictly after apply_queue_ops completes, so concurrent texture_news() checks never observe pending_count == 0 while drained ops are still being applied. Verified with descriptor:: tests (105 passed) and clean merge-tree against 41adb551.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7278680065 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3104#issuecomment-7278680065). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-30T12:36:48Z. --- Fixed a concurrency race in `drain_pending_into` / `enqueue_pending`: `pending_count` now increments via `fetch_add(ops.len(), Release)` and decrements via `fetch_sub(drained, Release)` strictly *after* `apply_queue_ops` completes, so concurrent `texture_news()` checks never observe `pending_count == 0` while drained ops are still being applied. Verified with `descriptor::` tests (105 passed) and clean `merge-tree` against `41adb551`.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3104:upstream-pr/3104'
git switch 'upstream-pr/3104'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3104'
git switch 'upstream-pr/3104'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3104'
git switch 'upstream-pr/3104'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3104'
git switch 'main'
git merge --squash 'upstream-pr/3104'
git switch 'main'
git merge --ff-only 'upstream-pr/3104'
git switch 'main'
git merge 'upstream-pr/3104'
git push origin 'main'
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
trustno1-coder/VIctory-NVIDIA!3104
No description provided.