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

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.

Merge candidate (large; overlaps other open PRs). Rebased at 9323a74, and it now merges cleanly with main. On a host that cannot make a 2^21-slot view heap, Host::view_heap_limit reports the smaller size, and descriptor::host::host_views passes it to the translator through set_view_heap. The capped HostHeap then holds the title's slots in blocks of 1,024 (Blocks/BlockMap::take, place/vacate). Heap-direct indices in Lower::host_index go through the new VIEW_BLOCKS root SRV, and tables are given their host run through HostHeap::run. Hosts that take 2^21 slots get the same DXIL, and the shader cache key changes only on capped hosts (host_build). I checked that the view-mark, stride and view-address entries are now kept by host slot (mirror uses slot, and make_null on vacate clears them before a block is reused). CI passes.

Points for the maintainer:


Generated by Claude Code

@fiestorra

Copy link
Copy Markdown
Contributor

I offered to resolve the rebase; I tried, and it is not mechanical — here is exactly what collides

Correcting my own offer from the comment above: I said I could push your commits rebased onto main "with the conflicts resolved mechanically". I attempted it, and the four conflicts are semantic, not textual, so a mechanical resolution would produce something neither of us wants. Aborted, nothing pushed.

What collides, file by file (main 940d32f against your a63eb93):

  • crates/victory-shader/src/emit/shader.rs and emit/mod.rs — main now has a view-mark system (VIEW_MARKS, VIEW_WRITES, VIEW_MARK_NONE, VIEW_WRITE_BITS, a t4/u1 pair in MEMORY_SPACE) that your branch does not have, and your branch has dynamic heap sizing (heap_views(), title_views(), set_view_heap(), null_buffer_view()) that main does not. The two are not alternative spellings of the same lines: they both add constants and both change what a translated shader bakes in, so the merged file has to decide both systems' constants and the order they are set in.
  • crates/victory-gpu/src/shader_cache.rs — main calls translate_with(c, Options { view_marks: true }); your branch calls translate(c) and, before it, forces the host so the heap sizes are known. A merged line has to be translate_with(c, Options { view_marks: true, .. }) after the host is made with your heap sizing — which means your Options/heap_views() shape must survive main's Options change, and that is a design decision, not a merge.
  • crates/victory-gpu/src/descriptor/host.rs — main added the write-mark plumbing to the same heap-creation and view code that your branch rewrites around the cap; the two touch the same functions with different purposes.

So the rebase needs someone who knows both changes — which is you, or the maintainer. What I can usefully give instead:

  1. The measurement that says it is worth doing, from this machine (RTX 4090, driver 32.0.16.2124): on the main before these two commits, your branch took title slot past the host heap from 310,720 to 0 and the same 2,048 frames from 94 s to 70 s (three alternating runs each, 93–95 against 70–76, ranges not overlapping). That is the only one of the four heap pull requests I have measured.
  2. The current chain without it, on today's main 940d32f plus the three fixes of mine: device removal gone, no host texture gone, 1,024 frames presented — and the cap plus the 310,720 slots still there, exactly as your branch fixes them.
  3. A conflict list anyone can act on: the four files above, and the fact that shader_cache.rs is the one that decides the shape of the rest.

If you would rather hand it over, say so and I will take the rebase on as a branch of mine with your authorship kept — but I am not going to guess at the Options design in your place.

No game data is involved: file names, constant names and counts.

Written with an AI assistant.

@astrosteveo

Copy link
Copy Markdown

I rebased this onto 940d32f with your commit and authorship kept, in case it saves you the work: https://github.com/astrosteveo/VIctory/commits/rebase/1779 (one commit, b6a9be4).

How I resolved the four conflicts:

  • shader_cache.rs: translate_with with view_marks: true as on main, and your host() call before the cache key and the translation.
  • emit/shader.rs, emit/mod.rs: both sets of items; null_buffer_view() replaces the constant.
  • descriptor/host.rs: both tests; the write-mark table merged on its own.

The write marks are what I looked at hardest. I read the code for this, no test covers the two together:

  • A marked write uses the index heap_handle got, which is after your redirect and clamp, so it looks up the slot it writes.
  • The stride and mark tables are still sized for HEAP_VIEWS, so every index below heap_views() is inside them.
  • mirror returns before it sets a stride or a mark for a title slot past the mirrored ones, so those can't overwrite the entries of the host's own slots there.

Tested on an RTX 5080 (driver 620.73.04), MinGW build under Wine 11.22 with vkd3d-proton 3.1, no game data:

--lib -- --test-threads=1 main 940d32f rebased
victory-gpu 5 failed 142 passed, 3 failed, 2 ignored
victory-shader 243 passed, 4 failed, 3 ignored 244 passed, 3 failed, 3 ignored

Now passing: 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 6 left also fail on main here. Clippy for x86_64-pc-windows-msvc with --all-features: clean. cargo xtask policy: ok.

Not tested: Windows, a host that takes 2^21 slots, and the title. Take it or leave it; I'm not opening a competing PR.

AI-assisted (Claude).

@astrosteveo

Copy link
Copy Markdown

Follow-up to my rebase: the write marks now have tests, in https://github.com/astrosteveo/VIctory/tree/test/1779-write-marks (ad8396d, on b6a9be4). No bug found.

  • Shader side, on the GPU: a write at a heap index at or past title_views() lands nowhere and sets no bit, with a real view and mark entry at that index. Without the bound, the same write lands and marks.
  • Host side: a title view past the mirrored slots leaves the mark and stride entries of the host's slot there alone.

Each fails when I break the redirect (shader) or make mirror write the entries (host).

One interaction: the view-address table has one entry per mirrored slot, so it shrinks to 721,469 here, and tables made afresh index past it. #1906 fixes that. The two merge cleanly after its rebase: https://github.com/astrosteveo/VIctory/tree/test/1779-1906.

RTX 5080, driver 620.73.04, Wine 11.22, vkd3d-proton 3.1. victory-gpu 143 passed, 3 failed; victory-shader 245 passed, 3 failed; the 6 also fail on main here. Not tested: Windows, the title. AI-assisted (Claude).

@wbkepler

Copy link
Copy Markdown
Author

Updated to 1890db5 (one commit, still on 70564ae): the title's slots past the host's are no longer cut off, they are remapped.

A run on a host capped at 1,000,000 view descriptors showed that cutting the title's heap short cannot work: the title's heap is larger than the host's and sparse, with live views and the tables its draws read spread over all of it, so any cut loses views (the previous head presented black frames).

What changed:

  • A capped view heap now holds the title's slots by blocks of 1,024. A block gets a host block when the title first writes a view into it and gives it back with its last view. 703 blocks fit beside the full 2^18 dynamic range, the 2^14 pair slots and the null views.
  • Shaders that take descriptors from the resource heap itself turn the title's index into the host's through a small block table (a new root SRV beside the view-stride table): one extra load, emitted only for hosts that report the cap. Hosts that take 2^21 slots still get the same DXIL as before; the shader cache keys on the host's values as it did.
  • Tables are told where their first used entry lies in the host heap; a table that is not in one run of host slots there is made afresh in dynamic slots, as main does for tables past a cut.
  • The redirect of indices past the mirrored slots to a null slot is gone (the block table's null block covers it).

Verified on Windows 11 with an NVIDIA GPU capped at 1,000,000 slots: clippy with -D warnings clean for victory-gpu, victory-shader and victory with diagnostics; cargo test -p victory-gpu 81 passed; cargo test -p victory-shader 208 passed and the two failures #1744 reports for main on this kind of GPU; cargo xtask policy ok. A live run on that host (with #1775 and #1778 merged locally, which boot needs there) renders the menus: non-black frames from frame 256 on, 13 draws a frame, no device removal, no view left without a host slot, and 192 to 255 of the 703 blocks in use. The world is not checked.

Still open: the branch conflicts with current main (the view-mark table from cd94d35 is another per-slot table that has to follow the host slot), so it needs a rebase; and nothing is evicted when every host block is taken (those writes are counted in a warning).

AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.

A host that makes no shader-visible view heap of HEAP_VIEWS slots (NVIDIA:
1,000,000) had shaders index past its heaps, a small dynamic range, and no
room for a title heap larger than its own.

- The host says how large its view heaps may be (Host::view_heap_limit,
  emit::set_view_heap): view heap indices are clamped below that and the
  null buffer views lie two below the end. A host that takes 2^21 slots
  is told nothing and translates as before (same DXIL). The shader cache
  and the pre-build tag key on the values where they differ.
- A capped heap holds the title's slots by blocks of 1,024: a block gets
  a host block when the title first writes a view into it and gives it
  back with its last view, so a sparse title heap of any size fits in
  the slots the host has (703 blocks beside 2^18 dynamic slots, 2^14 for
  view pairs and the null views). Shaders taking descriptors from the
  resource heap itself turn the title's index into the host's through
  the view-block table (root SRV VIEW_BLOCKS: one load, a shift, a mask
  and an add; emitted only for such hosts). Tables are told where their
  first used entry lies on the host; one whose slots are not in one run
  there is made afresh in dynamic slots, as before.
- Tables made afresh take slots from their first used entry on.

Tests: the capped layout and its dynamic slots, pairs and null views; a
capped heap holding a larger title heap by blocks (a view far past the
host's slots found through the block table and through a table, blocks
given back, a full heap); a translated shader reading through the block
table; the shader cache key.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@wbkepler
wbkepler force-pushed the gpu/capped-view-heap branch from 1890db5 to 9323a74 Compare November 25, 2026 06:37
@wbkepler

Copy link
Copy Markdown
Author

Rebased onto main 940d32f: now 9323a74, still one commit. Thanks @fiestorra for the conflict list and @astrosteveo for the rebase and the write-mark read, which matches what I found.

How the view-mark table (cd94d35) is handled. It is kept by host slot, the same as the stride table and the view addresses:

  • On the shader side, the index a marked store or atomic looks up (view_index, recorded in heap_handle) comes after host_index. So for heap-direct descriptors it is already the host's slot (blocks[index >> 10] + (index & 1023)), and for tables it is the host offset the table was given.
  • mirror now enters the mark at slot, not at the title's index (make_marked(&view, self.cpu(slot)), then set_mark(slot, mark)). make_at and root raw views were already writing at host dynamic slots.
  • Giving a block back: each of its slots goes through make_null(slot) when its view goes, and that now clears the mark at that host slot as well as the stride. A reused host block therefore starts unmarked. The block test checks this.
  • Table size: still max(title count, HEAP_VIEWS) entries, so it covers every host slot of a capped heap.

Other conflicts: shader_cache.rs uses translate_with(.., Options { view_marks: true }) after host() and keys on (views, blocks). emit/mod.rs and emit/shader.rs keep both sets of items, with null_buffer_view() replacing the constant. I checked the heap changes main made since 70564ae (dynamic wraparound/cursor, the descriptor-as-data and stride paths). The heap-direct index computations in the translator all go through heap_index/lane_heap_index → host_index. The new upstream test dynamic_search_can_find_a_run_across_the_cursor assumed dynamic slots start at 4. It now uses heap.count(), like the sibling test, because on a capped host they follow the title block and the null block.

Checked on Windows 11 / RTX 5090 (capped at 1,000,000):

  • clippy -D warnings is clean for victory-gpu, victory-shader, and victory --features diagnostics.
  • cargo test -p victory-gpu: 146 passed, 0 failed.
  • cargo test -p victory-shader: 246 passed, 2 failed (a_heap_buffer_read_by_element_takes_the_views_stride, gathers_at_a_level_match_the_hardware). Both fail the same way on plain 940d32f on this host.
  • cargo xtask policy is ok.

Not re-run live after the rebase. Marked copy-backs through remapped blocks still need a run on a capped host.

AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.

@LocranKing

Copy link
Copy Markdown

Tested the rebased head 9323a74 (on main 940d32f) on an NVIDIA GeForce RTX 3060 Ti 8 GB (Ampere, wave32, driver 32.0.16.1088), AMD Ryzen 5 5500, 32 GB RAM, Windows 11 10.0.26300, Rust 1.98.1.

1. Capped-heap unit tests (NVIDIA 1,000,000 view heap limit)

Test main 940d32f 940d32f + #1779 (9323a74)
victory-gpu descriptor::host::tests::dynamic_slots_are_held_until_released FAILED (NumDescriptors < HEAP_VIEWS) ok
victory-gpu memory::tests::lists_share_a_table_and_copies_keep_their_views FAILED (past the dynamic slots) ok
victory-shader emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros FAILED (0x80070057) ok

2. Title run (Series 1.0.2.1, diag --features diagnostics, VICTORY_D3D12_DRED=1)

  • Plain main 940d32f removes the device at frame 128 (~16 s) with 0x887A0001 (#1754).
  • Combined stack main 940d32f + #1763 (50d91b1) + #1630 (3c036f7) + #1778 (ba67548) + #1779 (9323a74) merges cleanly and runs the full 50 s timed boot/menu test with 0 device removals, 0 title slot past the host heap warnings (was ~310,720 on main), 13,612 buffer views, and 1,907 title-written textures.
  • Note for queue ordering: #1762 (19c8013, structured buffer views as raw views) currently conflicts with this branch in crates/victory-gpu/src/descriptor/host.rs.

AI use: Antigravity (Gemini 4 Carbon) ran the builds and tests on my machine and drafted this report; checked before posting.

@Mericas77

Copy link
Copy Markdown

Re-tested the rebased head 9323a74 on the same RTX 4070 (12 GB, driver 621.01, Windows 11 26300), against main 940d32f. cargo test --workspace --locked --no-fail-fast:

main 940d32f this PR 9323a74
workspace 696 passed, 5 failed, 10 ignored 703 passed, 2 failed, 10 ignored
-p victory-gpu -- --test-threads=1 141 passed, 2 failed 146 passed, 0 failed

Fixed on this card: dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and a_heap_buffer_read_where_no_buffer_view_is_reads_zeros. The two left are a_heap_buffer_read_by_element_takes_the_views_stride and gathers_at_a_level_match_the_hardware, the structured-view issue that #1762 addresses. Each fails 3 out of 3 when run alone, so they're consistent, not flaky. shadow::tests::marked_pages_go_back_by_the_bytes_the_gpu_changed passes. No hangs, device removals or driver resets.

This head conflicts with #1762's 19c8013 in descriptor/host.rs, emit/lower.rs, emit/mod.rs, emit/shader.rs and stride_tests.rs, so I couldn't test the two together.

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.