rebar: pool GPU_UPLOAD heaps, direct ReBAR uploads, and configurable large-BAR caps #689

Open
Canigia wants to merge 1 commit from Canigia/Darner:pr/rebar-gpu-upload-pool into post-merge
First-time contributor

Contributor role (optional)

  • Fluxer ID:

What it changes

  • The problem on post-merge: On 24 GB Resizable BAR GPUs (RTX 3090, 23.55 GiB DXGI budget), three hardcoded caps and unpooled GPU_UPLOAD allocations leave large amounts of VRAM unused while spilling buffers and staging to system RAM:
    • WINDOW_MAPPED_MOST in crates/darner-gpu/src/shadow.rs is hardcoded to 4096 MiB: in gameplay telemetry (cardledger), window-mapped hits 4092 MiB and spills 3,286 MiB (530 windows) out of ReBAR into non-mapped copies, even with ~11 GiB of VRAM still free.
    • CARD_MOST in crates/darner-gpu/src/shadow.rs is hardcoded to 1024 MiB: in higher-demand profiles buffer-copy reaches 935+ MiB against the 1 GiB cap.
    • Host::card_mapped_buffer_as in crates/darner-gpu/src/host.rs calls CreateCommittedResource for every non-UAV GPU_UPLOAD buffer (list scratch chunks, bind tables, etc.), bypassing the 128 MiB placed-buffer heap pool in crates/darner-gpu/src/heaps.rs.
    • Host::upload_buffer always allocates from D3D12_HEAP_TYPE_UPLOAD (system RAM) even on large-BAR GPUs with abundant VRAM headroom.

What this PR does (keeping Darner's write-watch guards and shader-write copy-back completely intact — zero coherency regressions):

  1. crates/darner-gpu/src/heaps.rs: Adds Kind::GpuUpload (D3D12_HEAP_TYPE_GPU_UPLOAD, accounted under hostmem::Place::Card) to the 128 MiB placed-buffer heap suballocator.
  2. crates/darner-gpu/src/host.rs:
    • Pools non-UAV card_mapped_buffer_as allocations (where the CPU writes every byte before GPU read) via heaps::Kind::GpuUpload (D3D12_RESOURCE_STATE_COMMON), keeping UAV mapped windows committed so D3D12 guarantees zeroed memory for unmapped holes.
    • Adds a ReBAR fast-path in Host::upload_buffer (DARNER_REBAR_UPLOAD=0 to disable; active only when GPUUploadHeapSupported is true and cardmem::may_place(size) has VRAM headroom) routing CPU-write / GPU-read-only staging uploads directly into pooled GPU_UPLOAD VRAM.
    • Raises SPARE_MOST from 128 MiB to 256 MiB to reduce list-scratch churn.
    • Adds a periodic ReBAR GPU_UPLOAD: info telemetry line reporting live mapped windows, spilled count, scratch chunks, and ReBAR uploads.
  3. crates/darner-gpu/src/shadow.rs: Makes WINDOW_MAPPED_MOST and CARD_MOST configurable via DARNER_WINDOW_MAPPED_MB (default 12288 MiB) and DARNER_CARD_MOST_MB (default 4096 MiB), while remaining strictly bounded under 80% of the actual adapter budget by cardmem::may_place().

(Note for maintainer: if you prefer DARNER_REBAR_UPLOAD and/or the raised caps to be opt-in off-by-default until tested on 8–12 GB cards, I am happy to flip the defaults in a follow-up commit.)

How it was tested

  • Tested revision: b710605 (based on post-merge 28a9b42)

  • Commands and results:

    • cargo build --release --locked -p darner — passed (0 errors, MSVC, Windows 11 24H2, DXC 1.10)
    • cargo test --release --locked -p darner-gpu --lib — 13 passed, 0 failed, 0 ignored
    • cargo clippy --release --locked -p darner-gpu -p darner-core --no-deps — 0 warnings in modified files (heaps.rs, host.rs, shadow.rs)
  • Changes a default: yes, on GPUs where D3D12_FEATURE_DATA_D3D12_OPTIONS16::GPUUploadHeapSupported == true and cardmem::may_place reports headroom (all switches can be overridden via DARNER_REBAR_UPLOAD=0, DARNER_WINDOW_MAPPED_MB=4096, DARNER_CARD_MOST_MB=1024).

  • Observed gameplay result (single-rig measurements on RTX 3090 24 GB + Ryzen 9 5950X + 32 GB DDR4-3600, Windows 11 24H2, ReBAR ON):

    Metric Stock release baseline (v2026.12.04.01) This PR (b710605 on post-merge)
    System RAM working set in gameplay ~16.0 GB (22–29 GB commit) ~6.0 GB (staging/windows/scratch placed in ReBAR VRAM)
    Series S + DLSS Quality + FSR 3 FG 2x + Hardware RT ON Unplayable (0.2–0.3 fps before post-merge RT rewrite) Smooth gameplay, up to 52 fps peak (with darner nv-profile --mb 2048)
    Visual artifacts / flickering None None (0 flicker, 0 geometry corruption)

    (Note: formal same-commit A/B table on post-merge with DARNER_REBAR_UPLOAD=0 + 4096/1024 vs 1 + 12288/4096 can be added on request, or switches can be made opt-in.)

  • Checks run on that revision (b710605): cargo build --release --locked -p darner, cargo test --release --locked -p darner-gpu --lib, cargo clippy --release --locked -p darner-gpu -p darner-core --no-deps.

  • Gameplay: NVIDIA GeForce RTX 3090 24 GB (Ampere, ReBAR ON, driver 630.20, darner nv-profile --mb 2048), AMD Ryzen 9 5950X, 32 GB DDR4-3600, Series S profile, DLSS Quality, FSR 3 Frame Generation 2x, Hardware RT ON, Reflex Boost.

  • Hardware dependence: Benefits GPUs with Resizable BAR (GPUUploadHeapSupported == true), especially 16–24 GB cards; on 8–12 GB cards cardmem::may_place caps placement at 80% of VRAM budget, though those cards are untested.

  • Coverage gaps: Untested on 8–12 GB NVIDIA cards, AMD GPUs, Intel Arc, and Linux/vkd3d-proton; formal same-commit A/B run on post-merge not yet recorded.

Checklist

  • I ran this change in the game, or say below why it can't be (docs, tests only).
  • This PR contains one change based on post-merge.
  • The diff contains no game files, code or assets.
  • I recorded this PR's dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #668 (rebar: direct GPU_UPLOAD writes for fed heap, bufobj and taken buffers also adds a GPU_UPLOAD heap pool in heaps.rs and touches host.rs/shadow.rs for fed heap, bufobj, and taken buffers).
  • Replaces or overlaps: #668 overlaps on heaps.rs (Kind::GpuUpload vs Kind::CardMapped); this PR focuses on lifting the hardcoded WINDOW_MAPPED_MOST/CARD_MOST caps for high-VRAM ReBAR cards, pooling non-UAV card_mapped_buffer_as allocations, and routing Host::upload_buffer staging into ReBAR VRAM (DARNER_REBAR_UPLOAD), and can be cleanly rebased on top of #668 if #668 merges first.

AI-assisted analysis, profiling, and patch authoring: Antigravity (Google DeepMind); all code reviewed, built, and validated in-game on local hardware by the author.

## Contributor role (optional) - Fluxer ID: <!-- Optional: paste your Fluxer ID if desired --> ## What it changes - The problem on `post-merge`: On 24 GB Resizable BAR GPUs (RTX 3090, 23.55 GiB DXGI budget), three hardcoded caps and unpooled `GPU_UPLOAD` allocations leave large amounts of VRAM unused while spilling buffers and staging to system RAM: - `WINDOW_MAPPED_MOST` in `crates/darner-gpu/src/shadow.rs` is hardcoded to `4096 MiB`: in gameplay telemetry (`cardledger`), `window-mapped` hits `4092 MiB` and spills `3,286 MiB` (`530` windows) out of ReBAR into non-mapped copies, even with ~11 GiB of VRAM still free. - `CARD_MOST` in `crates/darner-gpu/src/shadow.rs` is hardcoded to `1024 MiB`: in higher-demand profiles `buffer-copy` reaches `935+ MiB` against the 1 GiB cap. - `Host::card_mapped_buffer_as` in `crates/darner-gpu/src/host.rs` calls `CreateCommittedResource` for every non-UAV `GPU_UPLOAD` buffer (list scratch chunks, bind tables, etc.), bypassing the 128 MiB placed-buffer heap pool in `crates/darner-gpu/src/heaps.rs`. - `Host::upload_buffer` always allocates from `D3D12_HEAP_TYPE_UPLOAD` (system RAM) even on large-BAR GPUs with abundant VRAM headroom. What this PR does (keeping Darner's write-watch guards and shader-write copy-back completely intact — zero coherency regressions): 1. **`crates/darner-gpu/src/heaps.rs`:** Adds `Kind::GpuUpload` (`D3D12_HEAP_TYPE_GPU_UPLOAD`, accounted under `hostmem::Place::Card`) to the 128 MiB placed-buffer heap suballocator. 2. **`crates/darner-gpu/src/host.rs`:** - Pools non-UAV `card_mapped_buffer_as` allocations (where the CPU writes every byte before GPU read) via `heaps::Kind::GpuUpload` (`D3D12_RESOURCE_STATE_COMMON`), keeping UAV mapped windows committed so D3D12 guarantees zeroed memory for unmapped holes. - Adds a ReBAR fast-path in `Host::upload_buffer` (`DARNER_REBAR_UPLOAD=0` to disable; active only when `GPUUploadHeapSupported` is true and `cardmem::may_place(size)` has VRAM headroom) routing CPU-write / GPU-read-only staging uploads directly into pooled `GPU_UPLOAD` VRAM. - Raises `SPARE_MOST` from `128 MiB` to `256 MiB` to reduce list-scratch churn. - Adds a periodic `ReBAR GPU_UPLOAD:` `info` telemetry line reporting live mapped windows, spilled count, scratch chunks, and ReBAR uploads. 3. **`crates/darner-gpu/src/shadow.rs`:** Makes `WINDOW_MAPPED_MOST` and `CARD_MOST` configurable via `DARNER_WINDOW_MAPPED_MB` (default `12288` MiB) and `DARNER_CARD_MOST_MB` (default `4096` MiB), while remaining strictly bounded under 80% of the actual adapter budget by `cardmem::may_place()`. *(Note for maintainer: if you prefer `DARNER_REBAR_UPLOAD` and/or the raised caps to be opt-in off-by-default until tested on 8–12 GB cards, I am happy to flip the defaults in a follow-up commit.)* ## How it was tested - **Tested revision:** `b710605` (based on `post-merge` `28a9b42`) - **Commands and results:** - `cargo build --release --locked -p darner` — passed (0 errors, MSVC, Windows 11 24H2, DXC 1.10) - `cargo test --release --locked -p darner-gpu --lib` — **13 passed, 0 failed, 0 ignored** - `cargo clippy --release --locked -p darner-gpu -p darner-core --no-deps` — **0 warnings** in modified files (`heaps.rs`, `host.rs`, `shadow.rs`) - **Changes a default:** yes, on GPUs where `D3D12_FEATURE_DATA_D3D12_OPTIONS16::GPUUploadHeapSupported == true` and `cardmem::may_place` reports headroom (all switches can be overridden via `DARNER_REBAR_UPLOAD=0`, `DARNER_WINDOW_MAPPED_MB=4096`, `DARNER_CARD_MOST_MB=1024`). - **Observed gameplay result (single-rig measurements on RTX 3090 24 GB + Ryzen 9 5950X + 32 GB DDR4-3600, Windows 11 24H2, ReBAR ON):** | Metric | Stock release baseline (`v2026.12.04.01`) | This PR (`b710605` on `post-merge`) | |---|---|---| | System RAM working set in gameplay | ~16.0 GB (22–29 GB commit) | **~6.0 GB** (staging/windows/scratch placed in ReBAR VRAM) | | Series S + DLSS Quality + FSR 3 FG 2x + Hardware RT ON | Unplayable (`0.2–0.3 fps` before `post-merge` RT rewrite) | Smooth gameplay, **up to 52 fps peak** (with `darner nv-profile --mb 2048`) | | Visual artifacts / flickering | None | **None (0 flicker, 0 geometry corruption)** | *(Note: formal same-commit A/B table on `post-merge` with `DARNER_REBAR_UPLOAD=0` + `4096/1024` vs `1` + `12288/4096` can be added on request, or switches can be made opt-in.)* - **Checks run on that revision (`b710605`):** `cargo build --release --locked -p darner`, `cargo test --release --locked -p darner-gpu --lib`, `cargo clippy --release --locked -p darner-gpu -p darner-core --no-deps`. - **Gameplay:** NVIDIA GeForce RTX 3090 24 GB (Ampere, ReBAR ON, driver 630.20, `darner nv-profile --mb 2048`), AMD Ryzen 9 5950X, 32 GB DDR4-3600, Series S profile, DLSS Quality, FSR 3 Frame Generation 2x, Hardware RT ON, Reflex Boost. - **Hardware dependence:** Benefits GPUs with Resizable BAR (`GPUUploadHeapSupported == true`), especially 16–24 GB cards; on 8–12 GB cards `cardmem::may_place` caps placement at 80% of VRAM budget, though those cards are untested. - **Coverage gaps:** Untested on 8–12 GB NVIDIA cards, AMD GPUs, Intel Arc, and Linux/vkd3d-proton; formal same-commit A/B run on `post-merge` not yet recorded. ## Checklist - [x] I ran this change in the game, or say below why it can't be (docs, tests only). - [x] This PR contains one change based on `post-merge`. - [x] The diff contains no game files, code or assets. - [x] I recorded this PR's dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #668 (`rebar: direct GPU_UPLOAD writes for fed heap, bufobj and taken buffers` also adds a `GPU_UPLOAD` heap pool in `heaps.rs` and touches `host.rs`/`shadow.rs` for fed heap, `bufobj`, and `taken` buffers). - Replaces or overlaps: #668 overlaps on `heaps.rs` (`Kind::GpuUpload` vs `Kind::CardMapped`); this PR focuses on lifting the hardcoded `WINDOW_MAPPED_MOST`/`CARD_MOST` caps for high-VRAM ReBAR cards, pooling non-UAV `card_mapped_buffer_as` allocations, and routing `Host::upload_buffer` staging into ReBAR VRAM (`DARNER_REBAR_UPLOAD`), and can be cleanly rebased on top of #668 if #668 merges first. --- *AI-assisted analysis, profiling, and patch authoring: Antigravity (Google DeepMind); all code reviewed, built, and validated in-game on local hardware by the author.*
TrustNo1 changed title from [pr-performance][rendering] rebar: pool GPU_UPLOAD heaps, direct ReBAR uploads, and configurable large-BAR caps to rebar: pool GPU_UPLOAD heaps, direct ReBAR uploads, and configurable large-BAR caps 2026-12-06 03:25:09 +00:00
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'pr/rebar-gpu-upload-pool:Canigia-pr/rebar-gpu-upload-pool'
git switch 'Canigia-pr/rebar-gpu-upload-pool'

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 'post-merge'
git merge --no-ff 'Canigia-pr/rebar-gpu-upload-pool'
git switch 'Canigia-pr/rebar-gpu-upload-pool'
git rebase 'post-merge'
git switch 'post-merge'
git merge --ff-only 'Canigia-pr/rebar-gpu-upload-pool'
git switch 'Canigia-pr/rebar-gpu-upload-pool'
git rebase 'post-merge'
git switch 'post-merge'
git merge --no-ff 'Canigia-pr/rebar-gpu-upload-pool'
git switch 'post-merge'
git merge --squash 'Canigia-pr/rebar-gpu-upload-pool'
git switch 'post-merge'
git merge --ff-only 'Canigia-pr/rebar-gpu-upload-pool'
git switch 'post-merge'
git merge 'Canigia-pr/rebar-gpu-upload-pool'
git push origin 'post-merge'
Sign in to join this conversation.
No reviewers
No milestone
No project
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.

Dependencies

No dependencies set

Reference
TrustNo1/Darner!689
No description provided.