Skip to content

GPU: page view heaps a host caps below the slots shaders index - #2121

Open
0xkn0wh3r3 wants to merge 5 commits into
Marvisak:mainfrom
0xkn0wh3r3:gpu/view-heap-pages
Open

0xkn0wh3r3 wants to merge 5 commits into
Marvisak:mainfrom
0xkn0wh3r3:gpu/view-heap-pages

Conversation

@0xkn0wh3r3

@0xkn0wh3r3 0xkn0wh3r3 commented Nov 25, 2026 •

Copy link
Copy Markdown

Towards #1835, #1808 and #1760.

The problem

On NVIDIA, views the title puts in the upper part of its descriptor heap read null. Issue reports put 61,000 to 173,000 live slots past the cap in the world (#1760), and two view-heap unit tests failed on NVIDIA (#1835).

The mechanism: NVIDIA takes shader-visible view heaps of at most 1,000,000 descriptors. The title lays out 1,245,184 slots, and translated shaders index up to HEAP_VIEWS (2^21). The host heap holds title slot i at host slot i, so the capped heap kept 934,464 title slots and left the rest out ("title slot past the host heap").

slots
NVIDIA's cap on a shader-visible view heap 1,000,000
title's heap 1,245,184
indices translated shaders take (HEAP_VIEWS) 2^21
title slots the capped heap kept on main 934,464

The fix

A host that refuses a view heap of every index shaders take plus the dynamic slots (descriptor::host::view_pages, asked once; set VICTORY_VIEW_PAGES=1 to page on any host) keeps the title's order in a virtual heap of 256-slot pages:

  • The host heap is 1,000,000 slots. Host page 0 stays null (where pages with no place read). Page 1 takes writes once there is no room left. The dynamic slots' pages are placed together after them (tables of them are bound as host ranges).
  • Placement: any other page is placed in turn when a slot of it is first written, and entered in the page table: a dword per page past the view-stride table (VIEW_PAGE_TABLE), which shaders already have bound. A null made in a page with no place takes none.
  • Shaders: translated shaders take each view heap index through the table when Options::view_pages is set (Shader::heap_handle: per handle, one table load plus a shift, a multiply and an add to address it and a shift, an and and an or to place the slot; samplers are not paged). The host sets it where it pages (shader_cache::options), and the shader cache key carries it, so a host that does not page translates as before.
  • Draws bind the stride (and page) table of whichever view heap they bind: the title's, else our own (as write marks already do). Before, the stride table was taken from the title's heap only.

Limits:

  • Pages are not given back yet.
  • The host has 3,906 pages, of which 1,026 are fixed (null, scratch, dynamic): 2,880 for the title's 4,864 virtual pages, that is 737,280 slots.
  • When they run out, further pages read null with a warning. The pages in use are logged at each power of two, so a run shows whether a title's live slots fit.

Testing

  • New test descriptor::host::tests::pages_are_placed_once_on_first_write: page placement, its table entries, reads placing none, running out.
  • New test emit::stride_tests::a_heap_index_in_a_paged_view_heap_reads_where_its_page_is: a program translated with pages reads its buffer at virtual slot 1,099,777 through the table exactly as the plain program reads slot 1, on an RTX 5070 Ti (driver 621.24) and WARP.
  • On the RTX 5070 Ti, which pages, dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views now pass (both fail on main there).
  • emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros now passes on NVIDIA too. The shader test host made a 2^21-slot heap for its null buffer views, which the driver refuses. It now pages them where the device caps the heap, and the test translates with view pages there (Host::null_buffer_page, second commit).
  • cargo test -p victory-gpu and -p victory-shader: all pass on the RTX 5070 Ti except emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride and emit::synthetic_tests::gathers_at_a_level_match_the_hardware, which fail on main there too (the test host's structured views, Shader tests: the test host's structured buffer views are raw (#1835) #1887).

Not verified

  • No title run here: whether the world's live slots fit in 2,880 pages is what the page-count log lines will show. Pages are not given back yet.

Related: how this differs from the open heap PRs

#1751, #1133, #1548, #1777, #1779 and #1349 change how the capped heap is laid out or clamp indices past the cap. None maps title slots past it to host slots, so 300,000+ title slots still have no descriptor under each (measured in #1760). This one keeps every title slot addressable as long as the slots the title actually writes fit in 2,880 host pages (737,280 slots).

NVIDIA takes shader-visible view heaps of at most 1,000,000 descriptors;
the title lays out 1,245,184 slots, and translated shaders index up to
`HEAP_VIEWS` (2^21). The capped heap kept 934,464 title slots and left the
rest out ("title slot past the host heap"): views there read null. Issue
reports put 61,000 to 173,000 live slots past the cap in the world
(Marvisak#1760), and two view-heap unit tests failed on NVIDIA (Marvisak#1835).

A host that refuses a view heap of every index shaders take and the
dynamic slots (`descriptor::host::view_pages`, asked once; set
`VICTORY_VIEW_PAGES=1` to page on any host) keeps the title's order in a
virtual heap of 256-slot pages:

- The host heap is 1,000,000 slots. Host page 0 stays null (where pages
  with no place read), page 1 takes writes once there is no room left,
  and the dynamic slots' pages are placed together after them (tables of
  them are bound as host ranges). Any other page is placed in turn when a
  slot of it is first written, and entered in the page table: a dword per
  page past the view-stride table (`VIEW_PAGE_TABLE`), which shaders
  already have bound. A null made in a page with no place takes none.
- Translated shaders take each view heap index through the table when
  `Options::view_pages` is set (`Shader::heap_handle`: one table load, a
  shift and an or per handle; samplers are not paged). The host sets it
  where it pages (`shader_cache::options`), and the shader cache key
  carries it, so a host that does not page translates as before.
- Draws bind the stride (and page) table of whichever view heap they
  bind: the title's, else our own (as write marks already do), where the
  stride table was taken from the title's heap only.

Pages are not given back yet, and the host has 3,906, of which 1,026 are
fixed (null, scratch, dynamic): 2,880 for the title's 4,864 virtual
pages. When they run out, further pages read null with a warning; the
pages in use are logged at each power of two, so a run shows whether a
title's live slots fit.

Tests:
- `descriptor::host::tests::pages_are_placed_once_on_first_write`: page
  placement, its table entries, reads placing none, running out.
- `emit::stride_tests::a_heap_index_in_a_paged_view_heap_reads_where_its_page_is`:
  a program translated with pages reads its buffer at virtual slot
  1,099,777 through the table exactly as the plain program reads slot 1,
  on an RTX 5070 Ti and WARP (expected values on WARP).
- On the RTX 5070 Ti, which pages, `dynamic_slots_are_held_until_released`
  and `lists_share_a_table_and_copies_keep_their_views` now pass (both
  fail on main there); the second's HLSL stand-in for a translated shader
  now indexes the heap as they do, through the page table.
…he heap

`a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` failed on NVIDIA
before the program ran: `View::NullBuffers` made the test host's view
heap `HEAP_VIEWS` (2^21) slots, to put the null buffer views at
`NULL_BUFFER_VIEW`, and the driver takes at most 1,000,000.

Where the device refuses that heap, the test host now puts them in one
256-slot page after the dispatch's other views, at their offsets in
`NULL_BUFFER_VIEW`'s page (`Host::null_buffer_page` says which), and the
test translates the program with view pages and maps that page there,
as the runtime pages such heaps. A device that takes the whole heap
(AMD, WARP) runs as before.

On the RTX 5070 Ti the test now passes (it read through the page table
to the null view: zeros); `a_heap_index_in_a_paged_view_heap_reads_where_its_page_is`
still passes.

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu — 144 passed, 0 failed (2 ignored) on NVIDIA RTX 5090! Directly resolves both NVIDIA 1M view-heap cap failures (dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views) on main 940d32f!
  • cargo test -p victory-shader --lib emit::stride_tests:: — 6 passed, 1 failed (directly fixes a_heap_buffer_read_where_no_buffer_view_is_reads_zeros on RTX 5090; the 1 remaining failure, a_heap_buffer_read_by_element_takes_the_views_stride, is the separate NVIDIA structured-view issue covered by #1887)
  • cargo clippy -p victory-gpu -p victory-shader -p victory --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Huge NVIDIA/Blackwell compatibility win. Looks great!

AI-assisted (Gemini 4 Neon).

@yualk

yualk commented Nov 25, 2026

Copy link
Copy Markdown

Independent owned texture check at 442632413ce4 on Windows RTX 5070 Ti (10de:2c05, driver 610.88, auto-paged) and explicit WARP (1414:008c, forced paging). Used the real HostHeap::new(false, 1245184) with a 1,000,000-slot physical heap, and its normal cpu(index) page allocator/write destination. Two same-shaped RGBA8 textures with distinct bit patterns occupied virtual slots 17 and 1,126,417 (same in-page offset). A DXC 6.6 shader read the actual upload-backed page table and echoed the chosen physical slots plus sampled texels in each fence-completed arm. The upper slot returned the correct typed null until publication, then its own texel cb683b2e, with low 617fa5c3 unchanged. After reducing the allocator's remaining capacity to zero (only in the fixture), a real third texture descriptor write went to scratch and the third virtual slot still read zero; neither admitted neighbor changed. This check doesn't fill a title's real page capacity and doesn't measure title frames or use translated shader code.

One source-level failure case: the stride upload returns None on Create/Map failure, but paged initialization substitutes zero for the base and writes at VIEW_PAGE_TABLE. Could reject a paged heap with no mapped stride/page table before publishing its GPU range. I did not induce OOM. Also, the unplaced page is filled with a Texture2D null; my test deliberately used that dimension and doesn't establish safe null fallbacks for other resource kinds (D3D12 null descriptor rules). AI-assisted; no title data or captures used.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

View heaps paged when a host caps below shader-indexed slots — paging for capped heaps; mixed gpu+shader+apps, Windows-only overall.

RecompLive added a commit to RecompLive/victory-fork that referenced this pull request Nov 25, 2026
Ported Marvisak/VIctory#2121 (GPL-3.0-or-later), commits fb770da and
4426324. A host that refuses a view heap of every index shaders take
(NVIDIA takes 1,000,000 slots; the title lays out 1,245,184 and shaders
index up to HEAP_VIEWS = 2^21) now keeps the title's order in a virtual
heap of 256-slot pages:

- each page the title first writes is placed in the host heap and entered
  in a page table past the view-stride table, which shaders already bind;
- translated shaders take every view heap index through that table when
  `Options::view_pages` is set; the cache key carries it;
- draws bind the stride (and page) table of the heap they bind.

Our earlier host-cap clamp is kept: `probe_view_count` still sets the
non-paged clamp, and a paged heap clamps at HEAP_VIEWS before the page
lookup. The test host pages its null buffer views where the device caps
the heap (`Host::null_buffer_page`).

Adaptation: the PR's two hardware tests assert a device exists; here they
skip as every other hardware test does, because this PC has no SM 6.6
device. No game run: the page-count log lines are the check on a title.
@fiestorra

Copy link
Copy Markdown
Contributor

Measured on the card the cap affects: the slots past the heap go from 310,720 to zero, and the cap line disappears

I ran this branch on the machine where the problem reproduces — RTX 4090, driver 32.0.16.2124, session 1, release build, empty cache, 70 s, no other pull request applied:

title slot past the host heap      0        (main: 310,720)
host view heap capped              0        (main: 1)
device removed                     2
no host texture … 2560x1440 …      1
dropping unordered access          0
frame=64 draws=96

So both symptoms the description is about are gone here: no slot is left outside the host heap, and the "capped" line does not appear at all — the heap is not capped from the title's point of view, which is a stronger result than the fix I had measured before (#1779 took the same 310,720 to 0 but still logged the cap).

The remaining lines are the ones this pull request is not about, and I would keep them out of the review: the device removal and the missing 1440p B5G5R5A1_UNORM/format-115 texture are the format ground (#1630 and #1832). Worth knowing when someone measures this branch: on main they hide its value, because the boot dies at frame 64 regardless. With those two applied, the boot reaches 2,048 frames and 13,312 draws in 120 s — which is where this change's effect on the world would actually be visible, and where I would look next.

A few things I checked that are not in the diff:

  • it merges cleanly with the two open changes that touch the same emitter files (Shaders: a vertex shader that declares a UAV says so in its flags and SFI0 (fixes #1987) #2016, the vertex UAV flag; Shaders: a compute shader samples at level 0, not with derivatives (735 programs) #2027, sampling in compute) — I merged both orders, they apply and build. That matters because this change adds to emit/host.rs, emit/mod.rs and emit/shader.rs, which is the same corner, and a conflict there would be a reason to sequence the three.
  • the fixed 256-slot page and the emitter's baked page maths are the risk I would want stated: an index computed a page wrong reads null silently, and the symptom of a wrong page is "some views read zero", which is exactly what the cap looked like before. If there is a log line or counter that says the heap is paged (and how many pages are placed), it did not appear at info on this run — view pages was 0 matches. I would ask for one: it is the difference between "we think it paged" and "the log said so", and this week has shown how much a missing line costs.

What I have not reviewed: the 212 lines of descriptor/host.rs and the paging algebra itself, in any depth. I measured the outcome; the reasoning inside would take a session of its own, and the outcome is the part I can be sure of here.

No game data is involved: counts from the title's own log.

Written with an AI assistant.

A paged heap's page table lives in the view-stride table's buffer. When
that upload buffer could not be made, the paged setup took 0 as its
address and wrote the table at `VIEW_PAGE_TABLE` from there. A paged heap
is now refused (with a warning) when the buffer is missing, before its
GPU range is recorded.

A paged heap logs it when it is made, at info: "view heap paged", with
the title's slots, the host's slots, its pages and how many are fixed.
The probe's own line can come before logging is set up; this one comes
when the title makes its heap.
@0xkn0wh3r3

Copy link
Copy Markdown
Author

Thanks both, this is very useful.

@yualk: the missing-buffer case was real. In 907922c, when the stride buffer can't be made, a paged heap is now refused with a warning before its GPU range is recorded. Before, it wrote the page table relative to address 0. On the null descriptors: unplaced pages read slots filled with a Texture2D null. That's the same as every unwritten slot on main today (fill_null), so this PR doesn't change it. Matching the null to the kind a shader reads would be a separate change, and I'd keep it out of this one.

@fiestorra: thanks for the 4090 run, and for checking the merges with #2016 and #2027. The probe's line (host view heaps, paged=true) can come before logging is set up, which is probably why nothing matched. 907922c adds a line when the title's heap is made: view heap paged: the host caps view heaps, title slots are placed by page, with slots, host_slots, pages and fixed. After that, host view heap pages in use logs the count at each power of two, and no room left in the host view heap warns if pages run out. A run with #1630 and #1832 applied should show whether the world's pages fit.

@iGoldenNinja

iGoldenNinja commented Nov 25, 2026 •

Copy link
Copy Markdown

Independent RTX 5080 hardware check. Driver 617.14, Windows 11 Pro 25H2 build 26200.9974, Ryzen 9 5900X, Rust 1.98.1 MSVC, DXIL 1.9.2609.5, diag, paging and WARP overrides unset.

On clean main 940d32f69b22265690a0b5a15d6ded572ba33baf, dynamic_slots_are_held_until_released failed the NumDescriptors >= HEAP_VIEWS assertion. On clean PR head 442632413ce4e8b081b8c4ae4174a51a3682e7f4 it passed, along with pages_are_placed_once_on_first_write, the high-virtual-slot translated shader read on hardware and WARP, and the null buffer read. In total, 4 passed, 0 failed or ignored on the PR. These were synthetic fixtures.

Test commands and per-fixture outcomes

OpenAI Codex (GPT-6) ran the tests and drafted this report.

Title replay follow-up on RTX 5080 / 617.14 and Windows 11 26200.9974. I adapted 907922c onto the NVIDIA fork's 7e7bb18 diagnostics build with the previous integer-blend and descriptor-read fixes. The local port binds the page table through its own root view to preserve that fork's buffer refresh behavior.

The 1,245,184-slot title heap used 1,000,000 physical slots and logged pages=3906 fixed=1026. The available 2,880 title pages filled during world loading, 150.5 s after player selection, followed by the heap-exhaustion warning. The port retains allocated pages for the heap lifetime. This observes saturation on this fork and route.

It reached player control in the prison. The five-minute replay averaged 4.007 presented FPS, 658.550 ms P99, compared with 4.543 FPS and 435.072 ms on the unpaged control. Ten of 54 host samples still reported pending pipelines on the paged run. Wall and ceiling gaps persisted. The run ended deliberately with no DRED device removal logged.

Reproduction, capacity math and timing split

@JurajSimicevic

JurajSimicevic commented Nov 25, 2026 •

Copy link
Copy Markdown

On main 940d32f (RTX 5080) the pages also fill as the world loads; afterwards the device was removed within 1-3 minutes in both runs

Following @iGoldenNinja's fork replay above, the same on upstream main with no fork. RTX 5080, driver 32.0.16.1742, Windows 11 26200, diag build, VICTORY_D3D12_DRED=1, shader cache and pipeline library made first. Base: 940d32f + #1775's typed-UAV check (to boot, #1753) + #1762 + this PR at 907922c. The second run adds #1906 (astrosteveo's rebase 01ba70d) and #2098. Nothing skipped. One run each.

base + #1906 + #2098
pages in use 2,049 before the world; all 3,906 two seconds into it, then "no room left in the host view heap" the same: 2,049, then all 3,906 three seconds before the first world frame
title slot past the host heap, draws dropped for dynamic slots 0, 0 0, 0
end 0x887A0006 188 s into the world; DRED stops at #1968's program C (the one #984 addresses) 0x887A0006 70 s into the world; DRED stops at a mesh program's indirect draw
#1968's program A runs for the 3 minutes, never in a slow submission runs, never in a slow submission

No game data attached: counters, timings and log warnings only.

AI-assisted (Claude Code).

The page-use log, the no-room warning and a new log of pages written
with no room left say how many slots of the pages placed on a write
were written: whether smaller pages would fit more of a title, or the
title writes that many views.
@0xkn0wh3r3

Copy link
Copy Markdown
Author

Thanks both, this is the measurement the PR needed.

What I take from it:

Whether a different page size helps depends on how full the placed pages are. If most placed pages hold only a few written slots, smaller pages (64 slots) would fit far more of the title. If they're mostly full, the title really writes more than about 740k distinct descriptors, and the next step is reclaiming pages, or growing the title's share at the dynamic region's expense, not resizing them. I'd rather measure than guess. c5d33e8 adds that count: host view heap pages in use and the no room left warning now carry written (slots written in pages placed on a write) and of / of_slots (slots in those pages). A new view heap pages written with no room left log counts the pages and slots that missed out. If either of you can run it again, the ratio at the warning settles it in one run.

On the removals: in the first run DRED stops at #1968's program C, which #984 addresses. In the second it stops at a mesh program's indirect draw. Neither points at a null descriptor read; a null SRV/UAV reads zeros and drops writes. With one run each, though, I agree it can't be ruled out yet.

Thanks for the conflict notes with #1762, #1906 and #2098. I'll resolve them in whichever order those land.

Clippy's manual_is_multiple_of lint (Rust 1.98) flags the % in the
compile-time check of the page size.
@GaussianGuaicai

Copy link
Copy Markdown

Independent title smoke test on a Windows Hyper-V guest with an RTX 5070 Ti, using diagnostic builds, the same save snapshot and input, and separate cold caches:

  • Baseline 940d32f: Only frame 1 was logged before the 110 s watchdog. The run emitted 262,329 title slot past the host heap warnings.
  • Paging build 907922c: Paging activated automatically for the 1,245,184-slot title heap on the 1,000,000-slot host heap. I saw zero instances of that warning. The page-use log reported 2049 of 3906, and no page exhaustion was logged before exit. The run reached at least frame 1625, then exited on D3D12 device removal.

Separately, I compared unmodified 907922c with the same revision plus a local workaround excluding the R32_UINT to R9G9B9E5_SHAREDEXP cast. With matched debug-layer and capture settings, the unmodified build reproduced the rejected SRV and device removal. The workaround build reached the first detected world frame and ran until the watchdog without either error in that run, but the captured final image remained dark. The format workaround is not part of this PR.

This confirms automatic paging and provides one in-game page-use sample. It does not establish long-run page capacity, playable rendering, or a performance gain.

Test report prepared with assistance from GitHub Copilot.

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head 40bd210 onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

The paging is consistent as I read it. Pages::slot in crates/victory-gpu/src/descriptor/host.rs places a page on first write and enters it in the page table at VIEW_PAGE_TABLE. Shader::heap_handle in emit/shader.rs looks the page up before createHandleFromHeap, and the shader-cache key carries view_pages. The author's measurements and two independent runs show that title slot past the host heap goes to 0. However, two independent RTX 5080 runs, one of them on main, show the title filling all 2,880 title pages during world loading. Both runs then ended in device removal. Pages are never given back, so on this title the PR moves the cap rather than removing it, and the author agrees.

What would change the verdict: a run with c5d33e8's written/of_slots counters showing whether smaller pages or page reclamation would make the world fit, and the resulting change. A choice among this PR and the other open heap PRs (#1751, #1779, …) is also needed, which is the maintainer's call. CI has not run on this head.


Generated by Claude Code

@crissuper20

Copy link
Copy Markdown

GTX 1650 (Turing, 4 GB, driver 32.0.16.2124), diag build, Series S, 940d32f + #2016 #1775 #454 #1731, with and without this PR at 40bd210, 18 min each, same save and input:

without with
paging no on automatically (paged=true)
title slot past the host heap 310,720 0
reaches the world yes yes
device removed (~11 min in the world) no no

So on Turing there's no device removal in the world, unlike the 5080 report above. The world image is black on this card with or without the PR. One run each.

AI-assisted (Claude Code); measured on my own machine.

@sinan-cmyk

Copy link
Copy Markdown

Shader tests on NVIDIA Ada

I ran cargo test --locked -p victory-shader --lib on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, VICTORY_WARP unset.

Build Passed Failed
main 940d32f 244 3: stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, synthetic_tests::gathers_at_a_level_match_the_hardware
this PR (head 40bd210) merged onto 940d32f 246 2: a_heap_buffer_read_by_element_takes_the_views_stride, gathers_at_a_level_match_the_hardware

So on Ada this PR fixes a_heap_buffer_read_where_no_buffer_view_is_reads_zeros, one of the three NVIDIA failures that #1835 tracks. #2177 fixes the same test, and #2178 fixes the stride one (details in #1835).

Offline, on the retail dump, this PR does not change the counts (posted above).

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.