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

Merged
Bazovsky merged 1 commit from upstream-pr/1392 into main 2026-11-29 08:16:56 +00:00
Bazovsky commented 2026-11-28 18:44:29 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Bazovsky on 2026-11-28T18:44:29Z.


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

  • I searched the open pull requests for the same issue and for the files this touches. Related: #1553 (deliberately leaves pool.rs untouched to avoid conflicting with #1553).
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5543444365 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1392). Originally posted by [Bazovsky](https://github.com/Bazovsky) on 2026-11-28T18:44:29Z. --- 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 - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #1553 (deliberately leaves `pool.rs` untouched to avoid conflicting with #1553).
GreekNinja commented 2026-11-28 21:11:09 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by GreekNinja on 2026-11-28T21:11:09Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7245833709 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1392#issuecomment-7245833709). Originally posted by [GreekNinja](https://github.com/GreekNinja) on 2026-11-28T21:11:09Z. --- 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 commented 2026-11-28 22:39:27 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Bazovsky on 2026-11-28T22:39:27Z.


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 #1553.
  • Verified with clippy (default + --features diagnostics) and victory-gpu native Windows tests (551 passed, 0 failed).
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7246889536 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1392#issuecomment-7246889536). Originally posted by [Bazovsky](https://github.com/Bazovsky) on 2026-11-28T22:39:27Z. --- 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 #1553. - Verified with `clippy` (default + `--features diagnostics`) and `victory-gpu` native Windows tests (551 passed, 0 failed).
GreekNinja commented 2026-11-28 22:45:17 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by GreekNinja on 2026-11-28T22:45:17Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7246956929 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1392#issuecomment-7246956929). Originally posted by [GreekNinja](https://github.com/GreekNinja) on 2026-11-28T22:45:17Z. --- 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.*
Bazovsky commented 2026-11-29 01:43:28 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Bazovsky on 2026-11-29T01:43:28Z.


Rebased onto origin/main (d585f88 -> 837bae7) after 15ad118 + 34672ad landed the earlier revision on main. This PR now carries only the follow-up hardening delta (buffer_not_resident/buffer_resident per @GreekNinja, take_spare_wb fallback reuse in SPARE + unit test, discrete NVIDIA 0x10DE && !UMA default, and narrower WB_OK latch codes). Verified with clippy (default + --features diagnostics, 0 new warnings) and native Windows victory-gpu tests (590/590 pass).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7248971777 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1392#issuecomment-7248971777). Originally posted by [Bazovsky](https://github.com/Bazovsky) on 2026-11-29T01:43:28Z. --- Rebased onto `origin/main` (`d585f88` -> `837bae7`) after `15ad118` + `34672ad` landed the earlier revision on `main`. This PR now carries only the follow-up hardening delta (`buffer_not_resident`/`buffer_resident` per @GreekNinja, `take_spare_wb` fallback reuse in `SPARE` + unit test, discrete NVIDIA `0x10DE && !UMA` default, and narrower `WB_OK` latch codes). Verified with `clippy` (default + `--features diagnostics`, 0 new warnings) and native Windows `victory-gpu` tests (590/590 pass).
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!1392
No description provided.