Skip to content

perf(descriptor): batch TextureQueue writes across CopyDescriptors, sync_heaps, mirror_range, and heap_buffer_pass - #1675

Open
qlfu wants to merge 1 commit into
trustno1-coder:mainfrom
qlfu:pr/batch-descriptor-queue-writes
Open

qlfu wants to merge 1 commit into
trustno1-coder:mainfrom
qlfu:pr/batch-descriptor-queue-writes

Conversation

@qlfu

@qlfu qlfu commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

What it changes

Enables concurrency-safe TextureQueue write batching (QueueBatch / QueueFlusher) across bulk descriptor mirroring paths and removes per-call allocations in CopyDescriptors:

  • crates/victory-gpu/src/descriptor/host.rs:
    • Adds per-slot slot_state: Box<[AtomicU32]> ((seq << 1) | keeps) bumped on queue state transitions (queue_texture_inner, tabled_in_as, stale eviction in note_buffer_inner, and texture_slot_sampled_again) so deferred QueueBatch flushes can safely run on already-published heaps without resurrecting stale or tabled slots.
    • Uses a two-pass Dekker verification inside QueueBatch::apply with a single fence(SeqCst) per batch, keeping QueueMarks::set/get on Release/Acquire under the TextureQueue mutex.
    • Replaces QueueFlusher::new_unpublished(&mut HostHeap) with QueueFlusher::new(&HostHeap).
    • Adds multi-threaded consistency stress test queue_batch_concurrent_published_writes_and_removes_stay_consistent.
  • crates/victory-gpu/src/descriptor.rs:
    • Enables QueueFlusher::new(host) in Heap::host, mirror_range, and sync_heaps (before and make parallel chunks).
    • Rewrites copy (ID3D12Device::CopyDescriptors) to walk source/destination range pointers directly without temporary Vec allocations and mirror all destination ranges under a single hoisted SHADER_HEAPS.read() + QueueFlusher (mirror_ranges).
    • Adds unit test copy_multi_range_preserves_bytes_and_mirrors_single_slot_ranges and overlap regression coverage in mirror_range_overlap_falls_back_per_slot.
  • crates/victory-gpu/src/draw.rs:
    • Uses a per-chunk QueueFlusher::new(host) inside heap_buffer_pass's parallel each_view workers.

How it was tested

  • GPU and profile: RTX 4070 Ti 12 GB + Ryzen 7 5700X, Series X (game_scarlett_master.exe), 1440p DLSS Balanced, -NoFrameGenReady, VICTORY_PORT_CONSTANTS=1, VICTORY_WAIT_RESIDENT=textures, clean 90s gameplay runs (0 WARNs / 0 ERRORs).
  • Before (stack7 without this PR):
    • TextureQueue WRITE lock takes: 58,530 / 5s median (59,375 mean)
    • Frame times: med 44.2 ms, p95 65.4 ms, p99 74.6 ms, >100 ms: 16/2484 (0.6%)
    • Submitting thread sub_all: 38.65 ms median, VICTORY_THIN: 248.25 ms, title present-wait: 10.70 ms
  • After (stack8v2 with this PR):
    • TextureQueue WRITE lock takes: 44,418 / 5s median (45,784 mean, -24.1%)
    • Frame times: med 43.7 ms, p95 63.0 ms (-2.4 ms), p99 72.9 ms (-1.7 ms), >100 ms: 8/2417 (0.3%) (-50%)
    • Submitting thread sub_all: 36.25 ms median (-2.4 ms), VICTORY_THIN: 237.30 ms (-11.0 ms), title present-wait: 5.90 ms (-4.8 ms)
  • cargo clippy -p victory-gpu --lib --tests --locked (default & --all-features): 0 new warnings.
  • cargo test passed for the crates it touches: yes (552 passed; 0 failed in cargo test -p victory-gpu --lib --locked -- --test-threads=1).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: perf(gpu): avoid temporary allocations in single-range descriptor copies #1616 (also removes temporary allocations in single-range CopyDescriptors; this PR additionally batches multi-range CopyDescriptors and enables concurrency-safe QueueBatch across sync_heaps, mirror_range, and heap_buffer_pass).

…ync_heaps, mirror_range, and heap_buffer_pass
@github-actions github-actions Bot added the pr-performance Pull request: makes it faster or use less memory label Nov 28, 2026
@github-actions github-actions Bot changed the title [pr-performance] perf(descriptor): batch TextureQueue writes across CopyDescriptors, sync_heaps, mirror_range, and heap_buffer_pass perf(descriptor): batch TextureQueue writes across CopyDescriptors, sync_heaps, mirror_range, and heap_buffer_pass Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-performance Pull request: makes it faster or use less memory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant