Skip to content

GPU: view heaps on hosts capped below 2^21 descriptors - #1779

Open
wbkepler wants to merge 1 commit into
Marvisak:mainfrom
wbkepler:gpu/capped-view-heap
Open

wbkepler wants to merge 1 commit into
Marvisak:mainfrom
wbkepler:gpu/capped-view-heap

Conversation

@wbkepler

@wbkepler wbkepler commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A host that makes no shader-visible view heap of HEAP_VIEWS (2^21) descriptors (NVIDIA: 1,000,000) is left in four kinds of trouble on main at 70564ae:

  • Indices past the heap. Translated shaders clamp view heap indices to HEAP_VIEWS - 1 and read the null buffer views at the constant index NULL_BUFFER_VIEW = 2^21 - 2. Neither exists in a 1,000,000-slot heap (HostHeap::new logs "no room for the null buffer views"), and an index past a heap is undefined.
  • A title heap larger than the host's. The title's slots past the host's are left out, and a title keeps live views there: its heap is larger than 1,000,000 slots and sparse, with views (and the tables its draws read) spread over the whole of it. Cutting it short at any index loses views shaders read; a run of this PR's previous head on such a host stayed black.
  • A small dynamic range. The heap falls back to MIN_DYNAMIC (2^16) dynamic slots, the size that ran out in the world in RX 9060 XT (RDNA4) | Host GPU device removed (DXGI_ERROR_DEVICE_HUNG) with page fault at 0x1a00b0000 in world #59, while dynamic slots now also feed root-view runs and unordered-access clears. Tables made afresh take slots from entry 0 even when the first used entry is far into the table.
  • Tests. descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views fail on every such host, as does emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros in victory-shader (Test report: RTX 5070 (Blackwell), Windows 11, 70564ae: 471 passed, 5 failed, 7 ignored (4 from the 1,000,000 view heap cap) #1744).

Fix

  • The host says how large its view heaps may be. emit::host::Host::view_heap_limit asks the device once, when the host device is made; emit::set_view_heap(views, blocks) tells the translator. View heap indices are clamped below heap_views() and the null buffer views are read at null_buffer_view() (two below the end), instead of the constants. A host that takes 2^21 slots is told nothing and translates exactly as before (same DXIL). The shader cache keys its entries on the two values only where they differ from the default, and the pre-build list's tag covers them, in the way the loop limit is already handled.
  • A capped heap holds the title's slots by blocks (descriptor::host::Blocks), 1,024 title slots each. A block's slots follow each other in the host heap in the title's order; the block itself lies wherever a host block was free when the title first wrote a view into it, and gives its host block back when its last view is gone. A sparse title heap of any size therefore fits as long as the blocks that hold views do. The layout for 1,000,000 slots (capped_layout): 703 blocks for the title's slots and one that stays null, the full DYNAMIC (2^18) range, 2^14 slots for host copies' view pairs, then the null unordered-access view, the null buffer view and the clamp's slot. A title heap that fits whole keeps the title's order (every block has its host block from the start), so small heaps behave as before.
  • Shaders taking descriptors from the resource heap itself (root type 5) get the title's index from data, and turn it into the host's through the view-block table, a new root SRV t254 (VIEW_BLOCKS) beside the view-stride table: table[index >> 10] + (index & 1023), one extra load. A block without host slots leads to the null block. This is emitted only when the host says its heaps hold the title's slots by blocks, at the point where the index is computed (Lower::host_index), so handles, the view-stride lookup and view addresses all read at the host's index, and descriptors chosen between a table and the heap by control flow stay right.
  • Tables need nothing in the shader. The host already passes each table's offset as user data; for a table whose used entries lie in one run of host slots it passes where that run is (HostHeap::run). A table reaching into a block without host slots, or across blocks that lie apart, is made afresh in dynamic slots, which main already does for tables past a cut. Host blocks are taken so that neighbouring title blocks lie side by side where they can (BlockMap::take).
  • Tables made afresh take slots from their first used entry on (fresh_range); the offset given to the shader is the table's entry 0, as before.

Not done

  • With every host block taken, a view in a block without one is left out, as slots past the cut were (HostHeap::mirror counts those writes in a warning). Blocks whose views only went stale, without the title rewriting the slot, keep their host block; nothing is evicted.
  • A draw that reads a table before the title's byte-copied records were mirrored (the next submission) gets that table afresh once.
  • victory translate --cache now makes the host device before translating, since entries depend on it.
  • This branch is on 70564ae and conflicts with main since the view-mark table landed (cd94d35): that table is a third per-slot table and has to be kept by host slot as well. It needs a rebase onto current main.

Tests

  • a_capped_heap_holds_the_titles_slots_by_blocks: a heap made as on a host capped at 65,536 slots for a title heap of 100,000. A view written far past the host's slots is where a shader finds it through the block table (and the view-stride table says a buffer view is there) and where a table over it is told to read; the next title block lies beside it; a table into a block without host slots is not in one run; a block gives its host block back with its last view; with every block taken a further block gets none.
  • a_heap_index_goes_through_the_view_block_table (victory-shader): a compute program translated for such a host reads a buffer whose title index lies past the test heap, through the block table, on hardware and WARP; translated for other hosts the program lists no block table.
  • a_capped_heap_keeps_dynamic_slots_pairs_and_null_views: the layout; the whole dynamic range leases, pairs go up to the null views, the null buffer views are where shaders read them, a small title heap keeps its order.
  • a_fresh_table_takes_slots_from_its_first_used_entry.
  • dynamic_slots_are_held_until_released takes the heap size and the first dynamic slot from what the host makes; the shader cache key test covers the host part of the key; the stride test translates for each host's heap (through a per-thread setting, so tests beside it are not affected).

Verification host: Windows 11, NVIDIA GPU with a 1,000,000-descriptor view heap cap.

Supersedes #1349. #1751 and #1548 address the dynamic range alone; this also covers the indices past the heap that #1133 set out to bound before the clamp landed.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown

On an NVIDIA host with the 1,000,000 cap: RTX 3070 8 GB, driver 616.56, Windows 11, debug, a63eb93 (on main 70564ae).

  • cargo test -p victory-gpu --locked: 80 passed, 0 failed, 1 ignored. main has 76 passed and 2 failed here (dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views).
  • cargo test -p victory-shader --locked: 207 passed, 2 failed, 2 ignored. Of Test report: RTX 5070 (Blackwell), Windows 11, 70564ae: 471 passed, 5 failed, 7 ignored (4 from the 1,000,000 view heap cap) #1744's three, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros now passes (on main its dispatch fails with "The parameter is incorrect"). The other two fail with exactly the same data as on main, so they are not this PR:
    • a_heap_buffer_read_by_element_takes_the_views_stride: [101, 104, 107, …, 131, 0, …] against [200, …, 231];
    • gathers_at_a_level_match_the_hardware: lane 0 [0, 1, 0, 0] against [0, 0, 0, 0].

AI-assisted (Claude Code). Synthetic tests only.

@Vedoxdev123

Copy link
Copy Markdown

Tested on Windows with AMD Ryzen 5 5600X + NVIDIA GeForce RTX 4060:

cargo test -p victory-gpu --lib -> 80 passed; 0 failed; 1 ignored

Both previously failing descriptor heap tests (dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views) now pass.

@DesertGamer

Copy link
Copy Markdown

VIctory V2: community PRs, merged and tested

Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.

Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).

⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.

Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2

Unofficial community fork of Marvisak/VIctory, GPL-3.0.

@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 work on hosts capped below 2^21 descriptors: 37K diff gpu+shader — largest of this cluster with #1777; both touch heap sizing, possible overlap/conflict between them.

@rminzao

rminzao commented Nov 24, 2026

Copy link
Copy Markdown

Question: title slots cut to 721,469 for every heap on a capped host

capped_layout(views) derives the mirrored title range only from the host's limit: room - dynamic - pairs, so 721,469 at the NVIDIA cap, regardless of how many slots the title's heap has. If I read it right, a title heap of, say, 800,000 slots, which main mirrors in full on a host that can make it, now loses its last ~78,500 slots, and heap-direct indices into them go to the null views.

Is that intended (the translator needs one fixed layout for all heaps), or should the layout follow the heap's count when it fits? If it's intended, a log line when a title heap is cut would help.

Also, stride_tests.rs (~320/350) change the process-wide set_view_heap during a test. A panic before the reset leaves later tests in the same process translating for a capped heap.

Static review (AI-assisted), read against main at 70564ae; nothing was run on a GPU.

@Mericas77

Copy link
Copy Markdown

Tested a63eb93 on an NVIDIA host with the 1,000,000 view heap cap: RTX 4070 12 GB, driver 621.01, Windows 11 (build 26300), i5-13500, debug build.

main 70564ae this PR a63eb93
cargo test --workspace --locked --no-fail-fast 471 passed, 5 failed, 7 ignored 476 passed, 2 failed, 7 ignored
-p victory-gpu 76 passed, 2 failed, 1 ignored 80 passed, 0 failed, 1 ignored
-p victory-shader 206 passed, 3 failed, 2 ignored 207 passed, 2 failed, 2 ignored

#1744's five on this card:

  • descriptor::host::tests::dynamic_slots_are_held_until_released: fails on main, passes here
  • memory::tests::lists_share_a_table_and_copies_keep_their_views: fails on main, passes here
  • emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros: fails on main (hardware: dispatch failed, E_INVALIDARG), passes here
  • emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride: still fails, same output as on main
  • emit::synthetic_tests::gathers_at_a_level_match_the_hardware: still fails, same output as on main
---- emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride stdout ----
panicked at crates\victory-shader\src\emit\stride_tests.rs:293:9:
assertion `left == right` failed: hardware
  left: [101, 104, 107, 110, 113, 116, 119, 122, 125, 128, 131, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
 right: [200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231]

---- emit::synthetic_tests::gathers_at_a_level_match_the_hardware stdout ----
panicked at crates\victory-shader\src\emit\synthetic_tests.rs:261:13:
assertion `left == right` failed: hardware: lane 0
  left: [0.0, 1.0, 0.0, 0.0]
 right: [0.0, 0.0, 0.0, 0.0]

Both fail on the hardware pass, so their WARP pass never runs. Neither changes with this PR, so they don't look related to the heap cap.

Unrelated and also on main: watch::tests flake when memory::tests runs in parallel. With this PR, cargo test -p victory-gpu --lib failed 1 run in 10 (writes_through_another_mapping_mark_the_tracker). On main it was 3 in 8. With --test-threads=1: 80 passed, 0 failed. No hangs, device removals or driver resets during any run.

@fiestorra

Copy link
Copy Markdown
Contributor

Measured on an RTX 4090 on top of the other three fixes: same 2,048 frames in 76 s instead of 94 s

I had this branch built and ran it, because the question it answers is the one that decides whether the capped heap is worth attention: does removing the 310,720 slots past the cap change throughput?

Build: main 70564ae + #1778 + #1832 + #1630 + this branch (a63eb93), diag with the D3D12 debug layer and DRED, session 1, real window 3840×2160, empty cache, RTX 4090 (driver 32.0.16.2124), 120 s.

build title slot past the host heap no room for the null buffer views start → frame 2,048
main 310,720 1 never (device removed at frame 64)
the other three, without this 310,720 1 23:52:11 → 23:53:44 = 93 s
the other three, with this 0 0 23:56:00 → 23:57:16 = 76 s

That is ~21.8 fps → ~26.9 fps for the same frames, about 23% more, and it is the only change of the four that moves the pace: #1778 and #1630 together are within a second of #1832 alone.

Two caveats, because the number is better than my evidence for it:

  • one run each; the 17-second difference is far larger than the run-to-run jitter I have seen (a second or two), but it is not a distribution.
  • the frames are the early ones (menu and streaming), so this says the cap costs throughput early, not what it costs once the world is up.

On this machine the branch also removes no room for the null buffer views, which is what makes the null views exist at all, and it takes the slots past the cap to zero — both of which I could confirm independently of the speed.

No game data is involved: counters, timings and warnings only.

Written with an AI assistant.

@fiestorra

Copy link
Copy Markdown
Contributor

Repeated, alternating, three runs each: 93–95 s without this branch, 70–76 s with it

My earlier comment said the 17-second difference was one run each and not a distribution. Here is the distribution — both builds kept as executables and run alternately, same card (RTX 4090, driver 32.0.16.2124), same diag build flags with the debug layer and DRED, session 1, empty cache, 120 s per run, measured as frame=1 → frame=2048 from the log's own timestamps:

build run 1 run 2 run 3 median
the three, without this branch 93 s 95 s 94 s 94 s (≈21.8 fps)
the three, with this branch 76 s 70 s 70 s 70 s (≈29.3 fps)

The ranges do not overlap: 93–95 against 70–76. That is about 34% more frames per second for the same 2,048 frames, not the 23% I estimated from a single pair, and the jitter within each build is a couple of seconds.

The mechanism it belongs to, from the same runs: without the branch the log says host view heap capped at 1000000 and 310,720 title slot past the host heap with no room for the null buffer views; with it, all three are 0.

Two limits I want to keep attached to the number rather than argue later:

  • these are the early frames (menus and streaming); it says the capped heap costs throughput in the first two minutes, not what it costs once the world is up;
  • the other three fixes are held constant in both arms on purpose — on their own they are within a second of each other (93–95 s), so the difference is this branch's and not theirs.

No game data is involved: timings, counters and warnings only.

Written with an AI assistant.

@fiestorra

Copy link
Copy Markdown
Contributor

Correction to the numbers I gave earlier: they measure a static screen, not the world

The 93 s to 95 s against 70 s to 76 s I reported above is real, but I have to say what was on the screen while those frames were counted: one image, repeated. I captured the frames of the same build today (VICTORY_CAPTURE, diag, session 1, same card and driver) and every power-of-two frame from 256 onwards is byte-identical — and it is the profile selector, a dark screen with white text, waiting for a key.

So the honest version of the finding:

  • What the number measures: host throughput of the same per-frame work — the draws and dispatches that screen issues — over 2,048 frames. A 34% difference there is still a real cost of the capped view heap, because the work per frame and the frames are the same in both arms.
  • What it does not measure: the world, or anything that changes between frames. I wrote "about 29 fps" as if it were a frame rate of the running title; it is the rate of a title that is idle on a menu. The comparison between the two builds stands; the impression it gives about playable performance does not.

To get past the profile selector the run has to press keys, and with VICTORY_KEYS the picture does change (the loading artwork appears, 75,654 distinct colours in the captured frame), which is how I noticed — the earlier runs had no scripted input at all.

If you want a number that speaks about the world rather than a menu, that needs the world to be reached first, and on this machine the menu sequence is as far as I can drive it today.

No game data is involved: frame statistics and counts only.

Written with an AI assistant.

carlos-seiffert pushed a commit to carlos-seiffert/VIctory that referenced this pull request Nov 25, 2026
…ak#1835)

`Stride::Structured` made a structured SRV (`DXGI_FORMAT_UNKNOWN` with a
`StructureByteStride`), while the GPU host makes every buffer view it hands
a translated shader raw (`victory-gpu`, `descriptor::host`: R32_TYPELESS,
stride 0, `D3D12_BUFFER_SRV_FLAG_RAW`). The element size reaches the shader
through the stride table, and the translated read is a byte-addressed load
of the view. WARP ignores the view's stride for that load; NVIDIA applies it
a second time, so `a_heap_buffer_read_by_element_takes_the_views_stride` and
`gathers_at_a_level_match_the_hardware` read the wrong elements on the
hardware device. The test host now makes the same raw view as the GPU host.

On an RTX 2060 (Turing, driver 621.40), `cargo test -p victory-shader` goes
from 206 passed / 3 failed to 208 / 1; the one left is the 1,000,000-view
heap cap (Marvisak#1779 fixes it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-gpu/src/descriptor/host.rs, crates/victory-gpu/src/draw.rs, crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/mod.rs, crates/victory-shader/src/emit/shader.rs, crates/victory-shader/src/emit/stride_tests.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (merge candidate) was for an older state of main.


Generated by Claude Code

@fabianocoder

Copy link
Copy Markdown

Tested on NVIDIA GeForce RTX 3060 12 GB (driver 610.88, Windows 11).

cargo test -p victory-shader -p victory-gpu --lib --locked --no-fail-fast -- --test-threads=1

Branch victory-gpu victory-shader
main (940d32f) 141 passed, 2 failed 244 passed, 3 failed
#1777 144 passed, 0 failed 245 passed, 2 failed
#1779 (9323a74) 146 passed, 0 failed 246 passed, 2 failed
#1848 merged onto main 143 passed, 0 failed 245 passed, 2 failed
#1779 + #2357 146 passed, 0 failed 248 passed, 0 failed

All three PRs fix the heap-cap failures (dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros). The two remaining failures are the structured/raw fixtures that #2357 fixes; with both PRs the suites are fully green on this card.

Pierrot1398 added a commit to Pierrot1398/VIctory that referenced this pull request Nov 25, 2026
…n: capped view heaps with lazy placed-texture views

Marvisak#1779's head 9323a74 on main 13f91ca. Conflicts with today's main resolved:

- descriptor/host.rs mirror(): main's flow (placed textures made lazily
  when a draw reads them, prepared outside the slot lock, the record
  re-read and the slot remade if the title wrote it meanwhile) with
  Marvisak#1779's mapping: host arrays (made, kept, strides, addresses, marks, CPU
  handles) by host slot, the title's bookkeeping (viewed, vacate) by title
  slot.
- Shaders mark their reads by heap index, the host slot: make_read and
  evict map it back with the new HostHeap::title_of. evict looks the title
  slots up before locking made, since mirror takes the blocks' map first.
- The view-address buffer: main's 16-byte entries, for every host slot
  under blocks (Marvisak#1779), else the title's.
- draw.rs, lower.rs, mod.rs, shader.rs, stride_tests.rs: both sides' items.

Co-Authored-By: wrothgaril <211408787+wrothgaril@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011f6R3kMoarujHzzA1AvSBb
Slay326 pushed a commit to Slay326/VIctory that referenced this pull request Nov 26, 2026
… the version a63eb93 as in s20)

GPU: view heaps on hosts capped below 2^21 descriptors, the version of
a63eb93 (wrothgaril, on 70564ae) that was in test/nv3 and f7/bundle: a
capped heap mirrors the title's first 721,469 slots in place (title
slot = host slot), 2^18 dynamic slots, 2^14 pair slots, null views at
the end; shaders clamp below heap_views() and read null past
title_views(). No blocks, no view-block table (that is Marvisak#1779's newer
head 9323a74, which regressed in run 20261125-185042).

Conflicts, both sides kept: main's view marks/read marks/VIEW_* consts
beside heap_views()/title_views()/null_buffer_view(); buffer_guard does
the title clamp first, then Marvisak#2342's clamp_view_index (below
heap_views()) and the stride lookup; shader_cache: main's view_marks
options and Marvisak#1890's cache() with this version's host_build(views,
title); draw.rs fresh_range (main moved the fixed-function helpers);
descriptor tests of main and this version.

Ported from 48ba524 (Marvisak#1779 in the version active in s20 (a63eb93 port), not its head 9323a74; on main, whose own cap at 1,000,000 left about 310,000 title slots past the host heap per run (senior 24, main24); Host::from_device as on main).
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.