Skip to content

Host: harden write-back scratch scope, fallback, and buffer residency - #1392

Open
Bazovsky wants to merge 1 commit into
trustno1-coder:mainfrom
Bazovsky:pr/writeback-scratch-and-submit-hotpaths
Open

Bazovsky wants to merge 1 commit into
trustno1-coder:mainfrom
Bazovsky:pr/writeback-scratch-and-submit-hotpaths

Conversation

@Bazovsky

@Bazovsky Bazovsky commented Nov 28, 2026 •

Copy link
Copy Markdown

Fixes #

What it changes

Follow-up hardening for writeback_upload_buffer / VICTORY_SCRATCH_WB (introduced in f67a453):

  • Use buffer residency helpers (crates/victory-gpu/src/host.rs): switch writeback_upload_buffer from not_resident() / resident() to buffer_not_resident() / buffer_resident() (matching upload_buffer_own) so VICTORY_WAIT_RESIDENT=textures skips residency waits on write-back scratch buffers as reported by @GreekNinja.
  • Scope write-back default to discrete NVIDIA adapters & pooled <= SCRATCH_CHUNK chunks: scratch_wb(host) now defaults on only when VendorId == 0x10DE && !arch.UMA (still overridden by VICTORY_SCRATCH_WB=1 / 0). Oversized > 4 MiB scratch allocations and streaming plane_upload buffers always stay write-combined (upload_buffer / take_chunk(..., false)).
  • Clean fallback & pool separation: upload_buffer_maybe_wb latches write-back off only on capability refusal (E_INVALIDARG, E_NOTIMPL, DXGI_ERROR_UNSUPPORTED), avoids calling residency::allocation_error before the write-combined fallback is tried, and counts MADE[0..2] on success only (preventing double-counting on fallback). Spare::take_if + take_spare_wb keep plane_upload strictly on write-combined chunks while allowing write-back scratch callers to prefer write-back chunks and still reuse write-combined fallback chunks in SPARE.
  • Unit test: added host::tests::spare_pool_separates_streaming_and_reuses_wb_fallbacks.

How it was tested

  • GPU and profile (Series X or S, resolution, DLSS, frame generation, ray tracing): NVIDIA RTX 5090 32 GB (driver 610.88), AMD Ryzen 9 9950X3D (16C/32T, 96 MB 3D V-Cache), 62 GB RAM, Windows 11; Series X profile, 1440p SDR, DLSS Quality, Frame Generation OFF, RT default.
  • Before: writeback_upload_buffer called not_resident()/resident() directly (ignoring VICTORY_WAIT_RESIDENT=textures), defaulted on for non-NVIDIA/UMA adapters, used write-back for > 4 MiB scratch & plane_upload chunks, logged allocation_error on fallback, and retried unsupported drivers every chunk.
  • After: rebased onto d4b5d51 (3407c8d), cargo xwin clippy --target x86_64-pc-windows-msvc --locked --no-deps -p victory-gpu --all-targets and --features diagnostics check clean (0 new warnings), native Windows unit tests pass including the new SPARE pool separation/fallback test.
  • For shader changes, the wave sizes tested (32 and/or 64 lanes): N/A (no shader changes).
  • cargo test passed for the crates it touches: yes (victory-gpu: 551 passed, 0 failed — 514 non-watch + 37 watch::tests serial).

Checked for overlap

@Bazovsky
Bazovsky marked this pull request as draft November 28, 2026 18:50
@Bazovsky
Bazovsky marked this pull request as ready for review November 28, 2026 19:10
trustno1-coder added a commit that referenced this pull request Nov 28, 2026
trustno1-coder added a commit that referenced this pull request Nov 28, 2026
#1392 gave Chunk the buffer's GPU address (no COM call per use); the
upload pool's fresh chunk in Host::upload was made without it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X5CFykxe6G44cMPrmExrcw
@Bazovsky Bazovsky changed the title gpu: write-back L0 HostList scratch buffers, zero-COM Chunk.gpu, lock-free Card::before, and unified parallel send::take gpu: harden write-back scratch fallback/pool scope and add mapped() barrier (follow-up to f67a453) Nov 28, 2026
@Bazovsky
Bazovsky force-pushed the pr/writeback-scratch-and-submit-hotpaths branch from 38fd3d9 to 438622a Compare November 28, 2026 20:02
@GreekNinja

GreekNinja commented Nov 28, 2026 •

Copy link
Copy Markdown

Great hardening work on writeback_upload_buffer! One additional issue we measured on 923e38c (RTX 3060 12 GB + 16 GB RAM, VICTORY_WAIT_RESIDENT=textures):

  • crates/victory-gpu/src/host.rs:10031, 10039: writeback_upload_buffer still calls not_resident() and resident(&self.device, b)? directly instead of buffer_not_resident() / buffer_resident() (unlike upload_buffer_own, shared_buffer_own, mapped_card_buffer, and uav_buffer).
  • crates/victory-gpu/src/pool.rs:1133, 1143-1146: pool::cpu_buffer likewise calls host::not_resident() / resident() / mapped() directly.

On our 16 GB rig with VICTORY_WAIT_RESIDENT=textures, this caused 16,000 MakeResident waits (12.7 s, max 665.1 ms) in ~6 minutes before any OOM occurred; setting VICTORY_SCRATCH_WB=0 dropped new memory waited for from 16,000+ to 0 (and eliminated 81,489 no write-back upload buffer errors during memory pressure).

Suggestion for this PR or a small follow-up:

  1. Switch writeback_upload_buffer (and pool::cpu_buffer) to buffer_not_resident() / buffer_resident().
  2. Optionally sub-allocate <= 4 MiB write-back scratch buffers from &SHARED in pool::cpu_buffer (same CUSTOM / WRITE_BACK / L0 heap with D3D12_RESOURCE_FLAG_NONE) so 256 KiB / 4 MiB scratch chunks don't each create a committed L0 heap.

Note: This report/comment was generated and submitted automatically by an AI assistant analyzing real local play logs and source code on behalf of the user.

@Bazovsky
Bazovsky force-pushed the pr/writeback-scratch-and-submit-hotpaths branch from 438622a to 3407c8d Compare November 28, 2026 22:39
@Bazovsky Bazovsky changed the title gpu: harden write-back scratch fallback/pool scope and add mapped() barrier (follow-up to f67a453) [pr-fix][memory][NVIDIA] Host: harden write-back scratch scope, fallback, and buffer residency Nov 28, 2026
@Bazovsky

Copy link
Copy Markdown
Author

Thanks @GreekNinja! Rebased onto d4b5d51 (3407c8d) and updated:

  • Switched writeback_upload_buffer to buffer_not_resident() / buffer_resident() (matching upload_buffer_own, without an extra buffer_mapped() barrier).
  • Scoped default write-back scratch to discrete NVIDIA (0x10DE, !UMA) and pooled <= 4 MiB chunks, keeping plane_upload strictly write-combined while still reusing write-combined fallback chunks in SPARE.
  • Left pool.rs untouched here to avoid conflicting with perf(host): honor VICTORY_WAIT_RESIDENT=textures for buffer pools and coalesce mapped() waits #1553.
  • Verified with clippy (default + --features diagnostics) and victory-gpu native Windows tests (551 passed, 0 failed).

@github-actions github-actions Bot added memory RAM or VRAM use, out of memory, leaks NVIDIA pr-fix Pull request: fixes a bug labels Nov 28, 2026
@github-actions github-actions Bot changed the title [pr-fix][memory][NVIDIA] Host: harden write-back scratch scope, fallback, and buffer residency Host: harden write-back scratch scope, fallback, and buffer residency Nov 28, 2026
@GreekNinja

Copy link
Copy Markdown

Awesome, thanks @Bazovsky for the super fast update and for keeping pool.rs conflict-free with #1553! That cleanly addresses the VICTORY_WAIT_RESIDENT=textures bypass we hit on RTX 3060 12 GB + 16 GB RAM — we'll re-test with default VICTORY_SCRATCH_WB once merged.


Note: This comment was generated and submitted automatically by an AI assistant on behalf of the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

memory RAM or VRAM use, out of memory, leaks NVIDIA pr-fix Pull request: fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants