gpu: preserve dynamic descriptor budget on capped heaps #3860

Closed
sofiane-wattiez wants to merge 1 commit from upstream-pr/3860 into main
sofiane-wattiez commented 2026-11-29 21:26:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sofiane-wattiez on 2026-11-29T21:26:51Z.


No description provided.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5555295015 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3860). Originally posted by [sofiane-wattiez](https://github.com/sofiane-wattiez) on 2026-11-29T21:26:51Z. --- _No description provided._
AurumCarlos commented 2026-11-29 21:31:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-29T21:31:21Z.

Code review location: crates/victory-gpu/src/descriptor/host.rs; line 120

@@ -99,6 +99,26 @@ const DYNAMIC: u32 = 1 << 18;
 /// (a capped heap, NVIDIA): the title's slots keep their room first.
 const MIN_DYNAMIC: u32 = 1 << 16;
 
+/// Dynamic descriptor budget on a heap capped at [`PORTABLE_VIEWS`].
+/// Defaults to [`DYNAMIC`] (up to half the heap via `VICTORY_DYNAMIC_SLOTS`).
+fn dynamic_capped_slots() -> u32 {
+    static BUDGET: std::sync::OnceLock<u32> = std::sync::OnceLock::new();
+    *BUDGET.get_or_init(|| {
+        std::env::var("VICTORY_DYNAMIC_SLOTS")
+            .ok()
+            .and_then(|v| v.trim().parse::<u32>().ok())
+            .map_or(DYNAMIC, |n| n.clamp(MIN_DYNAMIC, PORTABLE_VIEWS / 2))
+    })
+}
+
+/// Title and dynamic slot counts `(kept_title, dynamic)` when the host caps
+/// shader-visible view heaps at [`PORTABLE_VIEWS`].
+fn capped_heap_slots(count: u32, dynamic_budget: u32) -> (u32, u32) {
+    let dynamic = dynamic_budget.clamp(MIN_DYNAMIC, PORTABLE_VIEWS / 2);
+    let kept = count.min(PORTABLE_VIEWS - dynamic);
+    (kept, dynamic)
+}

[blocking] This gives the dynamic budget its room first and cuts the title's slots to fit, the opposite of MIN_DYNAMIC's rule on main ("the title's slots keep their room first"). A title slot left out reads nothing. On a heap that fits under the cap, this drops slots main keeps: 900,000 → 737,856. Give the title its slots first, and the dynamic slots what's left, up to the budget:

fn capped_heap_slots(count: u32, dynamic_budget: u32) -> (u32, u32) {
    // The title's slots first (each one left out reads nothing); the dynamic
    // slots take what the cap leaves, up to the budget, MIN_DYNAMIC at least.
    let kept = count.min(PORTABLE_VIEWS - MIN_DYNAMIC);
    let budget = dynamic_budget.clamp(MIN_DYNAMIC, PORTABLE_VIEWS / 2);
    (kept, (PORTABLE_VIEWS - kept).min(budget))
}

Small heaps still get the larger budget (500,000 → 262,144 dynamic), and past the cap the split is main's.

<!-- greyfinch-sync:Marvisak/VIctory:review-comment:4733265176 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3860#discussion_r4733265176). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-29T21:31:21Z. **Code review location:** `crates/victory-gpu/src/descriptor/host.rs`; line 120 ~~~~diff @@ -99,6 +99,26 @@ const DYNAMIC: u32 = 1 << 18; /// (a capped heap, NVIDIA): the title's slots keep their room first. const MIN_DYNAMIC: u32 = 1 << 16; +/// Dynamic descriptor budget on a heap capped at [`PORTABLE_VIEWS`]. +/// Defaults to [`DYNAMIC`] (up to half the heap via `VICTORY_DYNAMIC_SLOTS`). +fn dynamic_capped_slots() -> u32 { + static BUDGET: std::sync::OnceLock<u32> = std::sync::OnceLock::new(); + *BUDGET.get_or_init(|| { + std::env::var("VICTORY_DYNAMIC_SLOTS") + .ok() + .and_then(|v| v.trim().parse::<u32>().ok()) + .map_or(DYNAMIC, |n| n.clamp(MIN_DYNAMIC, PORTABLE_VIEWS / 2)) + }) +} + +/// Title and dynamic slot counts `(kept_title, dynamic)` when the host caps +/// shader-visible view heaps at [`PORTABLE_VIEWS`]. +fn capped_heap_slots(count: u32, dynamic_budget: u32) -> (u32, u32) { + let dynamic = dynamic_budget.clamp(MIN_DYNAMIC, PORTABLE_VIEWS / 2); + let kept = count.min(PORTABLE_VIEWS - dynamic); + (kept, dynamic) +} ~~~~ --- [blocking] This gives the dynamic budget its room first and cuts the title's slots to fit, the opposite of `MIN_DYNAMIC`'s rule on `main` ("the title's slots keep their room first"). A title slot left out reads nothing. On a heap that fits under the cap, this drops slots `main` keeps: 900,000 → 737,856. Give the title its slots first, and the dynamic slots what's left, up to the budget: ```suggestion fn capped_heap_slots(count: u32, dynamic_budget: u32) -> (u32, u32) { // The title's slots first (each one left out reads nothing); the dynamic // slots take what the cap leaves, up to the budget, MIN_DYNAMIC at least. let kept = count.min(PORTABLE_VIEWS - MIN_DYNAMIC); let budget = dynamic_budget.clamp(MIN_DYNAMIC, PORTABLE_VIEWS / 2); (kept, (PORTABLE_VIEWS - kept).min(budget)) } ``` Small heaps still get the larger budget (500,000 → 262,144 dynamic), and past the cap the split is `main`'s.
AurumCarlos commented 2026-11-29 21:31:21 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-29T21:31:21Z.

Code review location: crates/victory-gpu/src/descriptor/host.rs; line 2263

@@ -2213,6 +2245,23 @@ mod tests {
         assert!(unsafe { host.device.GetDeviceRemovedReason() }.is_ok());
     }
 
+    #[test]
+    fn capped_heap_slots_preserves_dynamic_budget_and_clamps() {
+        assert_eq!(super::capped_heap_slots(500_000, super::DYNAMIC), (500_000, super::DYNAMIC));
+        assert_eq!(
+            super::capped_heap_slots(900_000, super::DYNAMIC),
+            (super::PORTABLE_VIEWS - super::DYNAMIC, super::DYNAMIC)
+        );
+        assert_eq!(
+            super::capped_heap_slots(900_000, 1024),
+            (900_000, super::MIN_DYNAMIC)
+        );
+        assert_eq!(
+            super::capped_heap_slots(900_000, 800_000),
+            (super::PORTABLE_VIEWS / 2, super::PORTABLE_VIEWS / 2)
+        );
+    }

[suggestion] This test pins the slot loss (900_000 → PORTABLE_VIEWS - DYNAMIC). It should pin the title-first rule instead. I ran this one against a copy of both versions of capped_heap_slots (not a build of the PR): it fails on this head with left: (737856, 262144), right: (900000, 100000) and passes with the change above.

    fn capped_heaps_keep_the_titles_slots_first() {
        use super::{DYNAMIC, MIN_DYNAMIC, PORTABLE_VIEWS, capped_heap_slots as slots};
        // Room for the whole budget: every title slot and the budget.
        assert_eq!(slots(500_000, DYNAMIC), (500_000, DYNAMIC));
        // A heap that fits: every title slot, the dynamic slots take the rest.
        assert_eq!(slots(900_000, DYNAMIC), (900_000, 100_000));
        assert_eq!(slots(900_000, 1024), (900_000, MIN_DYNAMIC));
        // Past the cap: the title keeps what `main` keeps.
        assert_eq!(slots(1_245_184, DYNAMIC), (PORTABLE_VIEWS - MIN_DYNAMIC, MIN_DYNAMIC));
        // The budget's own bound.
        assert_eq!(slots(100_000, 800_000), (100_000, PORTABLE_VIEWS / 2));
    }
<!-- greyfinch-sync:Marvisak/VIctory:review-comment:4733265186 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3860#discussion_r4733265186). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-29T21:31:21Z. **Code review location:** `crates/victory-gpu/src/descriptor/host.rs`; line 2263 ~~~~diff @@ -2213,6 +2245,23 @@ mod tests { assert!(unsafe { host.device.GetDeviceRemovedReason() }.is_ok()); } + #[test] + fn capped_heap_slots_preserves_dynamic_budget_and_clamps() { + assert_eq!(super::capped_heap_slots(500_000, super::DYNAMIC), (500_000, super::DYNAMIC)); + assert_eq!( + super::capped_heap_slots(900_000, super::DYNAMIC), + (super::PORTABLE_VIEWS - super::DYNAMIC, super::DYNAMIC) + ); + assert_eq!( + super::capped_heap_slots(900_000, 1024), + (900_000, super::MIN_DYNAMIC) + ); + assert_eq!( + super::capped_heap_slots(900_000, 800_000), + (super::PORTABLE_VIEWS / 2, super::PORTABLE_VIEWS / 2) + ); + } ~~~~ --- [suggestion] This test pins the slot loss (`900_000` → `PORTABLE_VIEWS - DYNAMIC`). It should pin the title-first rule instead. I ran this one against a copy of both versions of `capped_heap_slots` (not a build of the PR): it fails on this head with `left: (737856, 262144), right: (900000, 100000)` and passes with the change above. ```suggestion fn capped_heaps_keep_the_titles_slots_first() { use super::{DYNAMIC, MIN_DYNAMIC, PORTABLE_VIEWS, capped_heap_slots as slots}; // Room for the whole budget: every title slot and the budget. assert_eq!(slots(500_000, DYNAMIC), (500_000, DYNAMIC)); // A heap that fits: every title slot, the dynamic slots take the rest. assert_eq!(slots(900_000, DYNAMIC), (900_000, 100_000)); assert_eq!(slots(900_000, 1024), (900_000, MIN_DYNAMIC)); // Past the cap: the title keeps what `main` keeps. assert_eq!(slots(1_245_184, DYNAMIC), (PORTABLE_VIEWS - MIN_DYNAMIC, MIN_DYNAMIC)); // The budget's own bound. assert_eq!(slots(100_000, 800_000), (100_000, PORTABLE_VIEWS / 2)); } ```
AurumCarlos commented 2026-11-29 21:31:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-29T21:31:22Z.

Review: CHANGES_REQUESTED


Requesting changes: on a capped host this takes title slots to make room for dynamic ones, including on heaps that fit. Details on the lines.

  • [blocking] host.rs:116-120: kept = count.min(PORTABLE_VIEWS - dynamic) sizes the dynamic budget first. A 900,000-slot heap, which main keeps whole (900,000 + MIN_DYNAMIC), loses 162,144 title slots. The world's 1,245,184-slot heap keeps 737,856 instead of main's 934,464.
  • [suggestion] host.rs:2249: a test that pins "title slots first", which fails on this head.
  • [question] The description is empty. Did MIN_DYNAMIC (65,536) run out on a capped host, and where? DYNAMIC's comment records 2^16 running out on an RX 9070 XT, but that host wasn't capped. If NVIDIA runs out too, the right trade between dynamic slots and the title's past-cap slots needs that measurement. #3518 (remapping the slots past the cap) is the other open way around it.

Split per title heap size, from a port of the three versions of the logic:

title heap main kept / dynamic this PR suggested
500,000 500,000 / 65,536 500,000 / 262,144 500,000 / 262,144
900,000 900,000 / 65,536 737,856 / 262,144 900,000 / 100,000
1,245,184 934,464 / 65,536 737,856 / 262,144 934,464 / 65,536
<!-- greyfinch-sync:Marvisak/VIctory:review:6104897573 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3860#pullrequestreview-6104897573). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-29T21:31:22Z. **Review:** CHANGES_REQUESTED --- Requesting changes: on a capped host this takes title slots to make room for dynamic ones, including on heaps that fit. Details on the lines. - **[blocking]** `host.rs:116-120`: `kept = count.min(PORTABLE_VIEWS - dynamic)` sizes the dynamic budget first. A 900,000-slot heap, which `main` keeps whole (900,000 + `MIN_DYNAMIC`), loses 162,144 title slots. The world's 1,245,184-slot heap keeps 737,856 instead of `main`'s 934,464. - **[suggestion]** `host.rs:2249`: a test that pins "title slots first", which fails on this head. - **[question]** The description is empty. Did `MIN_DYNAMIC` (65,536) run out on a capped host, and where? `DYNAMIC`'s comment records 2^16 running out on an RX 9070 XT, but that host wasn't capped. If NVIDIA runs out too, the right trade between dynamic slots and the title's past-cap slots needs that measurement. #3518 (remapping the slots past the cap) is the other open way around it. Split per title heap size, from a port of the three versions of the logic: | title heap | `main` kept / dynamic | this PR | suggested | |---|---|---|---| | 500,000 | 500,000 / 65,536 | 500,000 / 262,144 | 500,000 / 262,144 | | 900,000 | 900,000 / 65,536 | **737,856** / 262,144 | 900,000 / 100,000 | | 1,245,184 | 934,464 / 65,536 | **737,856** / 262,144 | 934,464 / 65,536 |
cloph-dsp commented 2026-11-30 10:38:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-30T10:38:27Z.


Independent verification (AI-assisted: Hy4 flash) — Windows, rustc 1.100.0 (MSVC), source + synthetic inputs only, no game data.

PR #3860 (1 file, +61/-12, gpu: preserve dynamic descriptor budget on capped heaps) is OPEN, non-draft, MERGEABLE/CLEAN, zero formal APPROVED reviews, no prior comment from me.

Checked in a dedicated worktree D:\Victory-Contrib\pr-3860-watch with its own CARGO_TARGET_DIR=D:\Victory-Contrib\NVIDIA-Contrib\target-3860 (never shared).

  • Negative control on the PR's base 63bcca43c6a00a758510398fa43096ce7e4f7df0: git grep -F capped_heap_slots_preserves_dynamic_budget_and_clamps <base> -- crates/victory-gpu/src/descriptor/host.rs → no match (test is new).
  • git diff --check <base>..HEAD → exit 0, clean.
  • cargo test --locked -p victory-gpu --lib -- descriptor::host::tests::capped_heap_slots_preserves_dynamic_budget_and_clamps --exact --test-threads=1 --quiet → test result: ok. 1 passed; 0 failed; 232 filtered out, exit 0.

GPU/driver: N/A — the new test exercises pure slot-accounting helpers (capped_heap_slots), no device or title required.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7275877149 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3860#issuecomment-7275877149). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-30T10:38:27Z. --- Independent verification (AI-assisted: Hy4 flash) — Windows, rustc 1.100.0 (MSVC), source + synthetic inputs only, no game data. PR #3860 (1 file, +61/-12, `gpu: preserve dynamic descriptor budget on capped heaps`) is OPEN, non-draft, MERGEABLE/CLEAN, zero formal APPROVED reviews, no prior comment from me. Checked in a dedicated worktree `D:\Victory-Contrib\pr-3860-watch` with its own `CARGO_TARGET_DIR=D:\Victory-Contrib\NVIDIA-Contrib\target-3860` (never shared). - Negative control on the PR's base `63bcca43c6a00a758510398fa43096ce7e4f7df0`: `git grep -F capped_heap_slots_preserves_dynamic_budget_and_clamps <base> -- crates/victory-gpu/src/descriptor/host.rs` → no match (test is new). - `git diff --check <base>..HEAD` → exit 0, clean. - `cargo test --locked -p victory-gpu --lib -- descriptor::host::tests::capped_heap_slots_preserves_dynamic_budget_and_clamps --exact --test-threads=1 --quiet` → `test result: ok. 1 passed; 0 failed; 232 filtered out`, exit 0. GPU/driver: N/A — the new test exercises pure slot-accounting helpers (`capped_heap_slots`), no device or title required.
sofiane-wattiez commented 2026-11-30 11:27:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sofiane-wattiez on 2026-11-30T11:27:17Z.

Code review location: crates/victory-gpu/src/descriptor/host.rs; line 2263

@@ -2213,6 +2245,23 @@ mod tests {
         assert!(unsafe { host.device.GetDeviceRemovedReason() }.is_ok());
     }
 
+    #[test]
+    fn capped_heap_slots_preserves_dynamic_budget_and_clamps() {
+        assert_eq!(super::capped_heap_slots(500_000, super::DYNAMIC), (500_000, super::DYNAMIC));
+        assert_eq!(
+            super::capped_heap_slots(900_000, super::DYNAMIC),
+            (super::PORTABLE_VIEWS - super::DYNAMIC, super::DYNAMIC)
+        );
+        assert_eq!(
+            super::capped_heap_slots(900_000, 1024),
+            (900_000, super::MIN_DYNAMIC)
+        );
+        assert_eq!(
+            super::capped_heap_slots(900_000, 800_000),
+            (super::PORTABLE_VIEWS / 2, super::PORTABLE_VIEWS / 2)
+        );
+    }

Thanks @AurumCarlos for the detailed review and @cloph-dsp for the independent verification.

You're right about the title-first allocation rule. The current implementation prioritizes the dynamic descriptor budget at the expense of title descriptors, which introduces an unintended regression.

The initial motivation came from my RTX 3060 investigations, where I observed:

  • Requested descriptor heap: 1,245,184 slots
  • Host descriptor heap cap: 1,000,000 slots
  • Dynamic descriptor budget: 65,536 slots
  • A significant number of out-of-range title descriptors
  • Severe rendering and performance issues

However, I haven't conclusively demonstrated that the dynamic descriptor allocator itself exhausts its 65,536 slots on NVIDIA hardware. Increasing the dynamic budget was an experimental approach rather than a confirmed fix.

I agree with preserving title descriptors first and allocating additional dynamic slots only when sufficient capacity remains.

I'll update the implementation and regression tests accordingly. I'll also investigate dynamic allocator occupancy and exhaustion separately, and look into the remapping approach discussed in #3518.

Thanks again for the constructive feedback.

<!-- greyfinch-sync:Marvisak/VIctory:review-comment:4738500186 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3860#discussion_r4738500186). Originally posted by [sofiane-wattiez](https://github.com/sofiane-wattiez) on 2026-11-30T11:27:17Z. **Code review location:** `crates/victory-gpu/src/descriptor/host.rs`; line 2263 ~~~~diff @@ -2213,6 +2245,23 @@ mod tests { assert!(unsafe { host.device.GetDeviceRemovedReason() }.is_ok()); } + #[test] + fn capped_heap_slots_preserves_dynamic_budget_and_clamps() { + assert_eq!(super::capped_heap_slots(500_000, super::DYNAMIC), (500_000, super::DYNAMIC)); + assert_eq!( + super::capped_heap_slots(900_000, super::DYNAMIC), + (super::PORTABLE_VIEWS - super::DYNAMIC, super::DYNAMIC) + ); + assert_eq!( + super::capped_heap_slots(900_000, 1024), + (900_000, super::MIN_DYNAMIC) + ); + assert_eq!( + super::capped_heap_slots(900_000, 800_000), + (super::PORTABLE_VIEWS / 2, super::PORTABLE_VIEWS / 2) + ); + } ~~~~ --- Thanks @AurumCarlos for the detailed review and @cloph-dsp for the independent verification. You're right about the title-first allocation rule. The current implementation prioritizes the dynamic descriptor budget at the expense of title descriptors, which introduces an unintended regression. The initial motivation came from my RTX 3060 investigations, where I observed: - Requested descriptor heap: 1,245,184 slots - Host descriptor heap cap: 1,000,000 slots - Dynamic descriptor budget: 65,536 slots - A significant number of out-of-range title descriptors - Severe rendering and performance issues However, I haven't conclusively demonstrated that the dynamic descriptor allocator itself exhausts its 65,536 slots on NVIDIA hardware. Increasing the dynamic budget was an experimental approach rather than a confirmed fix. I agree with preserving title descriptors first and allocating additional dynamic slots only when sufficient capacity remains. I'll update the implementation and regression tests accordingly. I'll also investigate dynamic allocator occupancy and exhaustion separately, and look into the remapping approach discussed in #3518. Thanks again for the constructive feedback.

Pull request closed

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
Marvisak/VIctory!3860
No description provided.