[pr-performance][memory] Windows of title memory on the card tile by tile (DARNER_WINDOWS_SPARSE; off by default) #62

Closed
Sobo wants to merge 1 commit from Sobo/Darner:windows-sparse into main
Contributor

With DARNER_WINDOWS_SPARSE=1 (and tiled resources tier 2 or more), the
card side of a window of title memory is a reserved buffer: its 64 KiB
tiles get memory from a pool of 64 MiB heaps only when a send first
brings them bytes that are not zero, or when shaders may write them, and
give it back when a send brings a whole tile as zeros. Empty heaps go
back to the card 5 s later. The mappings are made on the queue before
the list that sends. Unset or 0: windows as before.

A window made tile by tile is counted in WINDOW_SPARSE_BYTES, not in
WINDOW_CARD_BYTES, so its drop leaves WINDOW_CARD_BYTES alone: taking its
size off there ran the count below zero a few minutes into a city, and
from then on window_admission refused every new window the card. The
windows line says that count too.

Ported from fxceless/blackbebec b715714 (GPL-3.0), without its
DIRECT/Sources parts.

Co-Authored-By: Claude Opus 5.5 [email protected]
Fluxer-ID: 1577742832095989771

Contributor role (optional)

  • Fluxer ID: 1577742832095989771

What it changes

Switch: DARNER_WINDOWS_SPARSE=1 (off by default).

A window of title memory (memory outside the title's buffers) gets as its card side a reserved buffer (CreateReservedResource) that is given memory in 64 KiB tiles, from a pool of heaps, only where the GPU or the CPU actually touches it. Empty heaps are released after 5 s, not at once (releasing them at once lost the device). Page buffers stay out of tiled windows (buffer_sides(..., direct = !tiled)).

A tiled window is counted in WINDOW_SPARSE_BYTES, not in WINDOW_CARD_BYTES, so its drop leaves WINDOW_CARD_BYTES alone. (Taking its size off there ran that count below zero a few minutes into a city; from then on window_admission refused every new window the card (Fallback::Cap) and placed it in the PC's memory.) The windows line also says that count now.

Ported from fxceless/blackbebec b715714 (GPL-3.0), without its DIRECT/Sources parts.

How it was tested

  • Tested revision: Darner main 4a92569fb (git.gtahub.st) with this patch applied. Build check: cargo clippy -p darner-gpu --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings: clean. cargo test was not run (no Windows machine for the checks). The gameplay numbers below come from my own builds, which carried this change together with other local changes (same scene, settings and hardware before and after).
  • Hardware and setup: i7-10700K (8 cores, 16 threads), RTX 3090 24 GB, 32 GB RAM, Windows 11; page file 128 GB; NVIDIA shader cache 100 GB; shaders prepared with the preload, then darner warm --used --again with DARNER_WARM_SHARED=1.
  • Gameplay: Series X profile (and Series S where said), DLSS quality, FSR 3 frame generation 2x, ray tracing off.
  • Before and after (heavy city scenes): memory shared with the card up to 15.6 GB (it overflowed and the driver crashed, with large card windows) -> about 7.3 GB; the title's GPU work 45.8 -> 36.4 ms a frame.
  • The counter fix: in three runs without it, the windows' card count went below zero after 5 to 6 minutes, each time where the city's stutter and late textures began (seen as buffer mirror span of about 17,592,186,040,000 MB in the compile-memory line). In three runs with it (Series S profile, 1440p output, FSR 3 frame generation 2x, 5 to 6 minutes of city each), the count stayed at 0 MB, the span stayed positive (4.3 to 4.9 GB), and at the end 1,126 windows (6.9 GB) were on the card, none in the PC's memory, none turned away.
  • Coverage gaps: one PC only. DARNER_PAGE_BUFFERS=3 (now on by default) solves a similar problem; the two have not been compared side by side.

Checklist

  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • 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: none for the same problem. Open PRs that share files only: #37 (shadow.rs) and many that touch host.rs or lib.rs.
With DARNER_WINDOWS_SPARSE=1 (and tiled resources tier 2 or more), the card side of a window of title memory is a reserved buffer: its 64 KiB tiles get memory from a pool of 64 MiB heaps only when a send first brings them bytes that are not zero, or when shaders may write them, and give it back when a send brings a whole tile as zeros. Empty heaps go back to the card 5 s later. The mappings are made on the queue before the list that sends. Unset or 0: windows as before. A window made tile by tile is counted in WINDOW_SPARSE_BYTES, not in WINDOW_CARD_BYTES, so its drop leaves WINDOW_CARD_BYTES alone: taking its size off there ran the count below zero a few minutes into a city, and from then on window_admission refused every new window the card. The windows line says that count too. Ported from fxceless/blackbebec b715714 (GPL-3.0), without its DIRECT/Sources parts. Co-Authored-By: Claude Opus 5.5 <[email protected]> Fluxer-ID: 1577742832095989771 <!-- Thanks for the pull request. Please label it (pr-fix, pr-feature, pr-performance, pr-diagnostics, pr-refactor, pr-docs or pr-tests, plus the area labels), or put the label in the title, like [pr-fix]. --> <!-- Use Fixes #N for a complete fix or Refs #N for a partial change. --> ## Contributor role (optional) - Fluxer ID: 1577742832095989771 ## What it changes Switch: `DARNER_WINDOWS_SPARSE=1` (off by default). A window of title memory (memory outside the title's buffers) gets as its card side a reserved buffer (CreateReservedResource) that is given memory in 64 KiB tiles, from a pool of heaps, only where the GPU or the CPU actually touches it. Empty heaps are released after 5 s, not at once (releasing them at once lost the device). Page buffers stay out of tiled windows (`buffer_sides(..., direct = !tiled)`). A tiled window is counted in `WINDOW_SPARSE_BYTES`, not in `WINDOW_CARD_BYTES`, so its drop leaves `WINDOW_CARD_BYTES` alone. (Taking its size off there ran that count below zero a few minutes into a city; from then on `window_admission` refused every new window the card (`Fallback::Cap`) and placed it in the PC's memory.) The windows line also says that count now. Ported from fxceless/blackbebec b715714 (GPL-3.0), without its DIRECT/Sources parts. ## How it was tested - Tested revision: Darner `main` 4a92569fb (git.gtahub.st) with this patch applied. Build check: `cargo clippy -p darner-gpu --all-targets --target x86_64-pc-windows-msvc --locked -- -D warnings`: clean. `cargo test` was not run (no Windows machine for the checks). The gameplay numbers below come from my own builds, which carried this change together with other local changes (same scene, settings and hardware before and after). - Hardware and setup: i7-10700K (8 cores, 16 threads), RTX 3090 24 GB, 32 GB RAM, Windows 11; page file 128 GB; NVIDIA shader cache 100 GB; shaders prepared with the preload, then `darner warm --used --again` with `DARNER_WARM_SHARED=1`. - Gameplay: Series X profile (and Series S where said), DLSS quality, FSR 3 frame generation 2x, ray tracing off. - Before and after (heavy city scenes): memory shared with the card up to 15.6 GB (it overflowed and the driver crashed, with large card windows) -> about 7.3 GB; the title's GPU work 45.8 -> 36.4 ms a frame. - The counter fix: in three runs without it, the windows' card count went below zero after 5 to 6 minutes, each time where the city's stutter and late textures began (seen as `buffer mirror span` of about 17,592,186,040,000 MB in the compile-memory line). In three runs with it (Series S profile, 1440p output, FSR 3 frame generation 2x, 5 to 6 minutes of city each), the count stayed at 0 MB, the span stayed positive (4.3 to 4.9 GB), and at the end 1,126 windows (6.9 GB) were on the card, none in the PC's memory, none turned away. - Coverage gaps: one PC only. `DARNER_PAGE_BUFFERS=3` (now on by default) solves a similar problem; the two have not been compared side by side. ## Checklist - [x] This PR contains one change based on `main`. - [x] The diff follows `docs/asset-policy.md`. - [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: none for the same problem. Open PRs that share files only: #37 (shadow.rs) and many that touch host.rs or lib.rs.
With DARNER_WINDOWS_SPARSE=1 (and tiled resources tier 2 or more), the
card side of a window of title memory is a reserved buffer: its 64 KiB
tiles get memory from a pool of 64 MiB heaps only when a send first
brings them bytes that are not zero, or when shaders may write them, and
give it back when a send brings a whole tile as zeros. Empty heaps go
back to the card 5 s later. The mappings are made on the queue before
the list that sends. Unset or 0: windows as before.

A window made tile by tile is counted in WINDOW_SPARSE_BYTES, not in
WINDOW_CARD_BYTES, so its drop leaves WINDOW_CARD_BYTES alone: taking its
size off there ran the count below zero a few minutes into a city, and
from then on window_admission refused every new window the card. The
windows line says that count too.

Ported from fxceless/blackbebec b715714 (GPL-3.0), without its
DIRECT/Sources parts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fluxer-ID: 1577742832095989771
Sobo changed title from WIP: Windows of title memory on the card tile by tile (DARNER_WINDOWS_SPARSE; off by default) to [pr-performance][memory] Windows of title memory on the card tile by tile (DARNER_WINDOWS_SPARSE; off by default) 2026-12-03 18:34:22 +00:00

One data point from an RTX 5090 (32 GB, driver 621.14, hardware RT, DLSS Quality, Series X profile, 1440p), with #62 merged onto bd0de0c alongside #23, #36, #37, #76, #92 and #98. Two hand-driven city drives of about 6 and 8½ minutes, without and with DARNER_WINDOWS_SPARSE=1:

  • The switch worked as described: tiled windows grew to 1,201 alive (7.7 GB of windows, 3.1 GB of tiles given, pool heaps 3.2 GB), 0 tiles waited for memory, 35,150 mapping calls in 1.6 s in all. No device loss, no picture problems.
  • The card ledger's sum was lower (18.7 GB against 22–23 GB at the same point), but DXGI's local use reached the same 28–29 GB of the 30.6 GB budget, about a minute sooner. Here the pressure seems to come from memory outside the windows; in these runs, the BLAS memory grew to 2.4 GB.
  • Hitches were not fewer: 45 frames over 100 ms in the first 6 minutes, against 29 without the switch. These are unmatched drives, so I would not read that as a regression, only as no improvement here.
One data point from an RTX 5090 (32 GB, driver 621.14, hardware RT, DLSS Quality, Series X profile, 1440p), with #62 merged onto `bd0de0c` alongside #23, #36, #37, #76, #92 and #98. Two hand-driven city drives of about 6 and 8½ minutes, without and with `DARNER_WINDOWS_SPARSE=1`: - The switch worked as described: tiled windows grew to 1,201 alive (7.7 GB of windows, 3.1 GB of tiles given, pool heaps 3.2 GB), 0 tiles waited for memory, 35,150 mapping calls in 1.6 s in all. No device loss, no picture problems. - The card ledger's sum was lower (18.7 GB against 22–23 GB at the same point), but DXGI's local use reached the same 28–29 GB of the 30.6 GB budget, about a minute sooner. Here the pressure seems to come from memory outside the windows; in these runs, the BLAS memory grew to 2.4 GB. - Hitches were not fewer: 45 frames over 100 ms in the first 6 minutes, against 29 without the switch. These are unmatched drives, so I would not read that as a regression, only as no improvement here.
First-time contributor

Mean shared GPU memory fell by 1,141 MB and 1,085 MB in two paired road runs on a 16 GB RTX 4070 Ti SUPER. Both pairs also had fewer frames above 50 ms. The more severe stalls varied between runs.

Pair Build Frames Rendered FPS Mean shared / dedicated GPU memory, MB p99, ms Frames >50 / >100 ms
1 Main 1945 21.63 3815 / 13951 86.03 152 / 3
1 Sparse 2101 23.35 2674 / 14353 73.85 92 / 3
2 Main 1938 21.54 4052 / 13996 74.24 260 / 2
2 Sparse 2046 22.75 2967 / 14349 81.98 136 / 5

Archived runs. Control 1a5286a78d, candidate 39d5c87e53 with only the sparse-window change. Stable patch ID 2c96ddc4dbaa74a9f819b7527f7c5dd73d674665 matches upstream head 60a042218b. DARNER_WINDOWS_SPARSE was 0 on main and 1 on the candidate. i5-13600KF, 32 GB RAM, Windows 11, NVIDIA driver 617.14. Series X, native 2560×1440 SDR, DLSS/FG/hardware RT off, 30 FPS cap.

Same copied save and warm cache. I used the first 90 s of each two-minute drive from the motel parking lot toward a divided road, to exclude a late obstruction in round two. Build order was reversed in the second pair, with other builds run in between. Traffic and steering varied, including a steering correction in the first control. I counted complete successful frame intervals only. All four windows had consecutive present IDs and zero lost rows. FPS uses frame count divided by summed intervals. Memory is the mean of the per-frame shared_used_mb and vram_used_mb counters. Longer-session stability remains open.

Mean shared GPU memory fell by 1,141 MB and 1,085 MB in two paired road runs on a 16 GB RTX 4070 Ti SUPER. Both pairs also had fewer frames above 50 ms. The more severe stalls varied between runs. | Pair | Build | Frames | Rendered FPS | Mean shared / dedicated GPU memory, MB | p99, ms | Frames >50 / >100 ms | |---:|---|---:|---:|---:|---:|---:| | 1 | Main | 1945 | 21.63 | 3815 / 13951 | 86.03 | 152 / 3 | | 1 | Sparse | 2101 | 23.35 | 2674 / 14353 | 73.85 | 92 / 3 | | 2 | Main | 1938 | 21.54 | 4052 / 13996 | 74.24 | 260 / 2 | | 2 | Sparse | 2046 | 22.75 | 2967 / 14349 | 81.98 | 136 / 5 | Archived runs. Control `1a5286a78d`, candidate `39d5c87e53` with only the sparse-window change. Stable patch ID `2c96ddc4dbaa74a9f819b7527f7c5dd73d674665` matches upstream head `60a042218b`. `DARNER_WINDOWS_SPARSE` was 0 on main and 1 on the candidate. i5-13600KF, 32 GB RAM, Windows 11, NVIDIA driver 617.14. Series X, native 2560×1440 SDR, DLSS/FG/hardware RT off, 30 FPS cap. Same copied save and warm cache. I used the first 90 s of each two-minute drive from the motel parking lot toward a divided road, to exclude a late obstruction in round two. Build order was reversed in the second pair, with other builds run in between. Traffic and steering varied, including a steering correction in the first control. I counted complete successful frame intervals only. All four windows had consecutive present IDs and zero lost rows. FPS uses frame count divided by summed intervals. Memory is the mean of the per-frame `shared_used_mb` and `vram_used_mb` counters. Longer-session stability remains open.
Author
Contributor

Closing: on today's main (v2026.12.03.02) this no longer gains anything. With DARNER_WINDOWS_SPARSE=1 against the same settings without it (RTX 3090, Series S profile, city): frame time per 1,000 list calls 1.04 ms against 0.98 ms (0.95 against 0.92 in the heaviest part), GPU time per frame about the same, and no textures waiting for room either way. The overflow it was made for (windows filling the memory shared with the card) is handled on main now (page buffers, DARNER_POOL_SMALL=auto). No image errors in the run with it on; the window count fix in it stays in my notes if it is wanted again.

Closing: on today's main (v2026.12.03.02) this no longer gains anything. With `DARNER_WINDOWS_SPARSE=1` against the same settings without it (RTX 3090, Series S profile, city): frame time per 1,000 list calls 1.04 ms against 0.98 ms (0.95 against 0.92 in the heaviest part), GPU time per frame about the same, and no textures waiting for room either way. The overflow it was made for (windows filling the memory shared with the card) is handled on main now (page buffers, `DARNER_POOL_SMALL=auto`). No image errors in the run with it on; the window count fix in it stays in my notes if it is wanted again.
Sobo closed this pull request 2026-12-04 08:17:43 +00:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
3 participants
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!62
No description provided.