darner-gpu: free-block dynamic_texture_cap admission, inline compute/graphics RootArgs, IndexedSweep, and AES-NI texture digest #545

Open
darner_lover wants to merge 3 commits from darner_lover/Darner:upstream-pr-clean into Main
First-time contributor

Summary

On 8 GB GDDR6 GPUs and 6-core/12-thread CPUs, profiling showed three independent bottlenecks:

  1. Spurious FirstUpload::ExplicitBudget refusals (807,465 in a ~31-minute session) and premature SOFT_SWEEPS while free texture-heap holes existed, leaving character/world texture slots black.
  2. Redundant D3D12 root-argument and IA buffer re-binding (10.90% root-view skip and 17.05% index-buffer skip) caused by resetting all RootArgs state twice around execute_indirect and allocating/clearing root-arg state outside graphics/compute sides.
  3. Per-pass O(N) ByCopy HashMap reconstruction across ~72k–80k descriptor slots in heap_buffer_pass (4.90 ms avg per heap buffers pass) plus scalar texture hashing on unchanging guarded textures.

The three attached patches address each bottleneck cleanly and independently against f3840d7 (main).


Test Environment

  • CPU: AMD Ryzen 5 5600XT (6 cores / 12 threads)
  • GPU: NVIDIA GeForce RTX 3060 Ti (8 GB GDDR6, Resizable BAR enabled)
  • RAM / OS: 32 GB DDR4, Windows 11 Build 26300
  • Profile & Output: Xbox Series S profile, 1920x1080 output via DLSS Quality, Ray Tracing Off, Frame Generation Off

Patches

0001-resource-dynamic-texture-cap-free-blocks.patch

Files: crates/darner-gpu/src/resource.rs

  • Exclude non-VRAM host textures from card-local counters: Track HostTexture.vram_bytes (0 for parked L0, aliased, and tiled allocations) in HOST_TEXTURES[1] and KINDS[1] so L0-parked copies never inflate VRAM pressure metrics or trigger false SOFT_SWEEPS.
  • Measure title-filled VRAM for explicit soft budgets: Add soft_sweep_target() so DARNER_TEXTURE_SOFT_MB checks KINDS[1] + tiles::given_total() rather than including render targets held inside HOST_TEXTURES[1].
  • Account for free texture-heap blocks in dynamic_texture_cap: Refactor dynamic_cap_for() and dynamic_cap_allows_first_upload() so room_for_first_upload() subtracts free_blocks (reserve.saturating_sub(free_blocks))—matching first_upload_decision()—and admits first-upload textures that fit inside an existing contiguous free heap range (new_card_bytes == 0 && reserve <= widest_free) even when process VRAM usage is inside the keep-free zone.
  • Unit tests: soft_sweep_target_uses_filled_vram_for_soft_budget, dynamic_cap_admits_first_upload_fitting_in_free_blocks.

0002-root-args-compute-side-invalidation.patch

Files: crates/darner-gpu/src/root_args.rs, crates/darner-gpu/src/draw.rs

  • Zero-allocation inline RootArgs + independent graphics/compute Sides: Store root constants (INLINE_CONSTS) and root views/tables (INLINE_VIEWS) in fixed inline arrays per side (graphics / compute), cache vertex/index buffers (MAX_VB_SLOTS) across root-signature changes (clear_side(compute) vs clear_vb() / clear_all()), and buffer per-list counters locally before flushing on clear/drop.
  • Targeted compute-only invalidation across execute_indirect: Because indirect clamping dispatches run only compute root signatures (clear_side(true) inside batched, bound, bound_ahead, ambient, and USER_DISPATCH_THREADS_X), removing the blanket double clear_all() around execute_indirect preserves graphics root arguments and VB/IB bindings across indirect draws without risking stale compute state.
  • Unit tests: graphics_and_compute_sides_are_independent, index_buffer_deduplicates_and_survives_clear_roots, vertex_buffers_deduplicates_exact_and_prefix_slots, overflow_params_and_large_constants_work_identically.

0003-heap-sweep-indexed-and-aes-texture-digest.patch

Files: crates/darner-gpu/src/draw/heap_sweep.rs, crates/darner-gpu/src/draw.rs, crates/darner-gpu/src/texture.rs

  • Incremental IndexedSweep<T> for heap_buffer_pass: Replace per-pass ByCopy HashMap aggregation across active heap slots with IndexedSweep<T>, linking each active slot into intrusive doubly-linked part_heads (PARTS = 16) and CopySpan lists. finish() recomputes [from, to] bounds only for copy spans whose extrema changed, and values() iterates active copies directly (slots_where and for_each_member handle taken-over windows and conditional read diagnostics).
  • 8-lane AES-NI texture digest + adaptive hash backoff: Add runtime-dispatched digest_aes() (with digest_folded() fallback) in texture.rs, make the blind-hit hot window configurable via DARNER_VIDEO_HOT_FRAMES (default 1024), and back off unchanged blind-turn hashes via hash_backoff() / turn_skipped() (DARNER_TEXTURE_HASH_BACKOFF, BACKOFF_AFTER = 4, BACKOFF_EVERY = 16, resetting Last.quiet on writes or detected changes).
  • Unit tests: matches_reference_oracle_across_updates_and_forget_parts, digest_detects_single_byte_and_length_changes, turn_skipped_backs_off_after_quiet_threshold.

Measured Telemetry Results (RTX 3060 Ti 8 GB / Ryzen 5 5600XT, Series S 1080p DLSS Quality)

Comparing baseline gameplay (3,453 in-game intervals, 1,868 s, avg 4,024 draws/frame) against a patched run (1,892 in-game intervals, 1,031 s, avg 4,308 draws/frame):

Metric Baseline Patched Delta
FirstUpload::ExplicitBudget refusals 807,465 0 Eliminated (-100%)
Shared system VRAM (p50 / avg) 7.055 / 6.252 GB 4.465 / 4.451 GB -36.7% p50 (-2.59 GB)
Dedicated VRAM (p50 / avg) 6.114 / 6.060 GB 5.720 / 5.692 GB -0.394 GB p50
Submit time (p50 / avg / p95) 28.91 / 30.88 / 47.36 ms 24.50 / 25.47 / 36.36 ms -17.5% avg (-23.2% p95)
Copy-stage time (cpy_ms p50 / avg) 8.04 / 8.36 ms 4.63 / 4.76 ms -43.1% avg
Heap-stage time (hep_ms p50 / avg) 1.24 / 1.50 ms 0.93 / 0.94 ms -37.6% avg
heap buffers log pass time (avg / p50) 4.90 / 3.80 ms 2.86 / 2.20 ms -41.6% avg (-42.1% p50)
DARNER_ROOT_ARG_SKIP views skipped 10.90% (1,140.5 / 10,460.6) 63.24% (7,625.6 / 12,059.0) +52.3 pp
DARNER_ROOT_ARG_SKIP IBs skipped 17.05% (42.3 / 247.9) 73.72% (198.5 / 269.3) +56.7 pp
DARNER_ROOT_ARG_SKIP constants skipped 0.17% (11.4 / 6,575.9) 2.83% (223.6 / 7,913.4) +2.66 pp
Texture refreshes (avg / p50 / max) 2.44 / 2.10 / 13.90 ms 2.15 / 1.70 / 8.50 ms -38.8% max spike
PC CPU usage (p50 / avg / p95) 85.0% / 83.5% / 99.3% 76.1% / 75.4% / 92.8% -8.9 pp p50
Worst frame hitch (max frame_ms) 737.83 ms 97.71 ms -86.8%
## Summary On 8 GB GDDR6 GPUs and 6-core/12-thread CPUs, profiling showed three independent bottlenecks: 1. Spurious `FirstUpload::ExplicitBudget` refusals (`807,465` in a ~31-minute session) and premature `SOFT_SWEEPS` while free texture-heap holes existed, leaving character/world texture slots black. 2. Redundant D3D12 root-argument and IA buffer re-binding (`10.90%` root-view skip and `17.05%` index-buffer skip) caused by resetting all `RootArgs` state twice around `execute_indirect` and allocating/clearing root-arg state outside graphics/compute sides. 3. Per-pass `O(N)` `ByCopy` `HashMap` reconstruction across ~72k–80k descriptor slots in `heap_buffer_pass` (`4.90 ms` avg per `heap buffers` pass) plus scalar texture hashing on unchanging guarded textures. The three attached patches address each bottleneck cleanly and independently against `f3840d7` (`main`). --- ## Test Environment - **CPU:** AMD Ryzen 5 5600XT (6 cores / 12 threads) - **GPU:** NVIDIA GeForce RTX 3060 Ti (8 GB GDDR6, Resizable BAR enabled) - **RAM / OS:** 32 GB DDR4, Windows 11 Build 26300 - **Profile & Output:** Xbox Series S profile, 1920x1080 output via DLSS Quality, Ray Tracing Off, Frame Generation Off --- ## Patches ### `0001-resource-dynamic-texture-cap-free-blocks.patch` **Files:** `crates/darner-gpu/src/resource.rs` - **Exclude non-VRAM host textures from card-local counters:** Track `HostTexture.vram_bytes` (`0` for parked L0, aliased, and tiled allocations) in `HOST_TEXTURES[1]` and `KINDS[1]` so L0-parked copies never inflate VRAM pressure metrics or trigger false `SOFT_SWEEPS`. - **Measure title-filled VRAM for explicit soft budgets:** Add `soft_sweep_target()` so `DARNER_TEXTURE_SOFT_MB` checks `KINDS[1] + tiles::given_total()` rather than including render targets held inside `HOST_TEXTURES[1]`. - **Account for free texture-heap blocks in `dynamic_texture_cap`:** Refactor `dynamic_cap_for()` and `dynamic_cap_allows_first_upload()` so `room_for_first_upload()` subtracts `free_blocks` (`reserve.saturating_sub(free_blocks)`)—matching `first_upload_decision()`—and admits first-upload textures that fit inside an existing contiguous free heap range (`new_card_bytes == 0 && reserve <= widest_free`) even when process VRAM usage is inside the keep-free zone. - **Unit tests:** `soft_sweep_target_uses_filled_vram_for_soft_budget`, `dynamic_cap_admits_first_upload_fitting_in_free_blocks`. ### `0002-root-args-compute-side-invalidation.patch` **Files:** `crates/darner-gpu/src/root_args.rs`, `crates/darner-gpu/src/draw.rs` - **Zero-allocation inline `RootArgs` + independent graphics/compute `Side`s:** Store root constants (`INLINE_CONSTS`) and root views/tables (`INLINE_VIEWS`) in fixed inline arrays per side (`graphics` / `compute`), cache vertex/index buffers (`MAX_VB_SLOTS`) across root-signature changes (`clear_side(compute)` vs `clear_vb()` / `clear_all()`), and buffer per-list counters locally before flushing on clear/drop. - **Targeted compute-only invalidation across `execute_indirect`:** Because indirect clamping dispatches run only compute root signatures (`clear_side(true)` inside `batched`, `bound`, `bound_ahead`, `ambient`, and `USER_DISPATCH_THREADS_X`), removing the blanket double `clear_all()` around `execute_indirect` preserves graphics root arguments and VB/IB bindings across indirect draws without risking stale compute state. - **Unit tests:** `graphics_and_compute_sides_are_independent`, `index_buffer_deduplicates_and_survives_clear_roots`, `vertex_buffers_deduplicates_exact_and_prefix_slots`, `overflow_params_and_large_constants_work_identically`. ### `0003-heap-sweep-indexed-and-aes-texture-digest.patch` **Files:** `crates/darner-gpu/src/draw/heap_sweep.rs`, `crates/darner-gpu/src/draw.rs`, `crates/darner-gpu/src/texture.rs` - **Incremental `IndexedSweep<T>` for `heap_buffer_pass`:** Replace per-pass `ByCopy` `HashMap` aggregation across active heap slots with `IndexedSweep<T>`, linking each active slot into intrusive doubly-linked `part_heads` (`PARTS = 16`) and `CopySpan` lists. `finish()` recomputes `[from, to]` bounds only for copy spans whose extrema changed, and `values()` iterates active copies directly (`slots_where` and `for_each_member` handle taken-over windows and conditional read diagnostics). - **8-lane AES-NI texture digest + adaptive hash backoff:** Add runtime-dispatched `digest_aes()` (with `digest_folded()` fallback) in `texture.rs`, make the blind-hit hot window configurable via `DARNER_VIDEO_HOT_FRAMES` (default `1024`), and back off unchanged blind-turn hashes via `hash_backoff()` / `turn_skipped()` (`DARNER_TEXTURE_HASH_BACKOFF`, `BACKOFF_AFTER = 4`, `BACKOFF_EVERY = 16`, resetting `Last.quiet` on writes or detected changes). - **Unit tests:** `matches_reference_oracle_across_updates_and_forget_parts`, `digest_detects_single_byte_and_length_changes`, `turn_skipped_backs_off_after_quiet_threshold`. --- ## Measured Telemetry Results (RTX 3060 Ti 8 GB / Ryzen 5 5600XT, Series S 1080p DLSS Quality) Comparing baseline gameplay (`3,453` in-game intervals, `1,868 s`, avg `4,024` draws/frame) against a patched run (`1,892` in-game intervals, `1,031 s`, avg `4,308` draws/frame): | Metric | Baseline | Patched | Delta | | :--- | :--- | :--- | :--- | | **`FirstUpload::ExplicitBudget` refusals** | `807,465` | `0` | **Eliminated (`-100%`)** | | **Shared system VRAM (`p50 / avg`)** | `7.055 / 6.252 GB` | `4.465 / 4.451 GB` | **`-36.7% p50` (`-2.59 GB`)** | | **Dedicated VRAM (`p50 / avg`)** | `6.114 / 6.060 GB` | `5.720 / 5.692 GB` | **`-0.394 GB p50`** | | **Submit time (`p50 / avg / p95`)** | `28.91 / 30.88 / 47.36 ms` | `24.50 / 25.47 / 36.36 ms` | **`-17.5% avg` (`-23.2% p95`)** | | **Copy-stage time (`cpy_ms` `p50 / avg`)** | `8.04 / 8.36 ms` | `4.63 / 4.76 ms` | **`-43.1% avg`** | | **Heap-stage time (`hep_ms` `p50 / avg`)** | `1.24 / 1.50 ms` | `0.93 / 0.94 ms` | **`-37.6% avg`** | | **`heap buffers` log pass time (`avg / p50`)** | `4.90 / 3.80 ms` | `2.86 / 2.20 ms` | **`-41.6% avg` (`-42.1% p50`)** | | **`DARNER_ROOT_ARG_SKIP` views skipped** | `10.90%` (`1,140.5 / 10,460.6`) | `63.24%` (`7,625.6 / 12,059.0`) | **`+52.3 pp`** | | **`DARNER_ROOT_ARG_SKIP` IBs skipped** | `17.05%` (`42.3 / 247.9`) | `73.72%` (`198.5 / 269.3`) | **`+56.7 pp`** | | **`DARNER_ROOT_ARG_SKIP` constants skipped** | `0.17%` (`11.4 / 6,575.9`) | `2.83%` (`223.6 / 7,913.4`) | **`+2.66 pp`** | | **Texture refreshes (`avg / p50 / max`)** | `2.44 / 2.10 / 13.90 ms` | `2.15 / 1.70 / 8.50 ms` | **`-38.8% max spike`** | | **PC CPU usage (`p50 / avg / p95`)** | `85.0% / 83.5% / 99.3%` | `76.1% / 75.4% / 92.8%` | **`-8.9 pp p50`** | | **Worst frame hitch (`max frame_ms`)** | `737.83 ms` | `97.71 ms` | **`-86.8%`** |
- Exclude parked L0 (and aliased/tiled) allocations from `HOST_TEXTURES[1]` and `KINDS[1]` via `HostTexture.vram_bytes` so L0 allocations never trigger false `SOFT_SWEEPS` or inflate soft-budget checks.
- Measure title-filled VRAM against `DARNER_TEXTURE_SOFT_MB` when explicitly set (`soft_sweep_target`).
- Factor `free_blocks` (`reserve.saturating_sub(free_blocks)`) and contiguous free-range fit (`widest_free`) into `dynamic_texture_cap` / `dynamic_cap_allows_first_upload` inside `room_for_first_upload`, preventing spurious `FirstUpload::ExplicitBudget` refusals when card usage is inside the keep-free zone but the upload fits in existing heap holes.
- Add unit tests `soft_sweep_target_uses_filled_vram_for_soft_budget` and `dynamic_cap_admits_first_upload_fitting_in_free_blocks`.
- Replace dynamic `Vec`/allocator tracking in `RootArgs` with inline fixed arrays (`INLINE_CONSTS`, `INLINE_VIEWS`, `MAX_VB_SLOTS`) plus list-local counters flushed on clear/drop.
- Track graphics and compute `Side`s independently and cache IA vertex/index buffer bindings across root-signature changes (`clear_side(compute)` vs `clear_vb()`/`clear_all()`).
- Clear only the compute side around internal compute passes (`open_batch`, `bound`, `bound_ahead`, `ambient`, `USER_DISPATCH_THREADS_X`) and remove the redundant double `clear_all()` around `execute_indirect` so graphics root args, VBs, and IBs stay cached across indirect draws.
- Add unit tests covering inline overflow, VB/IB persistence across `clear_side(false)`, and independent graphics/compute invalidation.
- Replace per-pass `ByCopy` `HashMap` rebuild in `heap_buffer_pass` with incremental `IndexedSweep<T>` (`draw/heap_sweep.rs`) maintaining intrusive part and copy-span lists (`finish()`, `slots_where()`, `for_each_member()`), plus differential oracle test `matches_reference_oracle_across_updates_and_forget_parts`.
- Add runtime-dispatched 8-lane AES-NI `digest_aes` with `digest_folded` fallback in `texture.rs`, configurable `blind_hot_frames` (`DARNER_VIDEO_HOT_FRAMES`, default 1024), and adaptive `hash_backoff` (`DARNER_TEXTURE_HASH_BACKOFF`, `BACKOFF_AFTER = 4`, `BACKOFF_EVERY = 16`).
- Add unit tests `digest_detects_single_byte_and_length_changes` and `turn_skipped_backs_off_after_quiet_threshold`.
Author
First-time contributor

I tried my best to optimize darner, i will continue to do so. My next steps are to check what other ports do better or have that darner doesnt .

I tried my best to optimize darner, i will continue to do so. My next steps are to check what other ports do better or have that darner doesnt .
Owner

Test needed — commit d6d56a1b; what to check: the change described above

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `d6d56a1b`; what to check: the change described above Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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 'upstream-pr-clean:darner_lover-upstream-pr-clean'
git switch 'darner_lover-upstream-pr-clean'

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 'Main'
git merge --no-ff 'darner_lover-upstream-pr-clean'
git switch 'darner_lover-upstream-pr-clean'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'darner_lover-upstream-pr-clean'
git switch 'darner_lover-upstream-pr-clean'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'darner_lover-upstream-pr-clean'
git switch 'Main'
git merge --squash 'darner_lover-upstream-pr-clean'
git switch 'Main'
git merge --ff-only 'darner_lover-upstream-pr-clean'
git switch 'Main'
git merge 'darner_lover-upstream-pr-clean'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 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!545
No description provided.