Skip to content

GPU: keep heap indices and the null views inside a host heap the driver caps - #1848

Closed
fiestorra wants to merge 1 commit into
Marvisak:mainfrom
fiestorra:gpu/clamp-bound-fits-the-capped-heap
Closed

fiestorra wants to merge 1 commit into
Marvisak:mainfrom
fiestorra:gpu/clamp-bound-fits-the-capped-heap

Conversation

@fiestorra

Copy link
Copy Markdown
Contributor

The null views did not exist on a capped heap, and that is now fixed and measured

Following the numbers in this issue: the emitted clamp bound and the null buffer views are HEAP_VIEWS - 1 and HEAP_VIEWS - 2 with HEAP_VIEWS = 2^21 = 2,097,152, while the host heap is capped at 1,000,000 and its dynamic slots were set to fill it exactly. So on a capped heap the null views the clamp is supposed to fall back to were outside the heap, which is what no room for the null buffer views was saying, and any computed index between the cap and the clamp read a descriptor that was not there.

Two changes, both about fitting inside the heap the driver allows:

  • HEAP_VIEWS is now 1,000,000 — the smallest cap the host meets in practice — so the clamp and the null slots are inside any heap we can bind;
  • the capped creation keeps two slots free for the null views, and the check that places them accepts being the first slots past the title-and-dynamic ones (a capped heap ends exactly where they used to end).

Measured on the machine that caps (integrated AMD Radeon(TM) Graphics, driver 32.0.21045.29003, session 1, real window 3840×2160, empty cache), same scenario before and after:

no room for the null buffer views title slot past the host heap
main 70564ae 1 310,720
with this 0 310,722 (the two reserved slots)

so the null views now exist and the shader's fallback has somewhere to land. Everything else in that log is unchanged, including the device removal — which is the chain in #1754 (the UAV description's id 599 and the sampler heap's id 1419), not this. This change is about the heap being consistent with itself, not about the removal.

Verification: cargo test -p victory-shader 209 passed, cargo test -p victory-gpu 78 passed / 1 ignored, cargo clippy --workspace --all-targets with and without --all-features clean, rustfmt --check on both files at the same hunk counts as main (2 and 33 before, 32 after because two were mine).

What it does not do, and I would rather say than imply: it does not remap the 310,722 title slots above the cap. Those slots still have no host descriptor, so a shader that computes such an index still reads the null instead of its real descriptor — the design's stated behaviour for a slot that has none, and a real rendering loss on a title heap this large. Making them work needs the heap remapped (or the clamp given a runtime bound), which is a bigger change than this one.

Pull request: #1837

No game data is involved: counts and warnings only.

Written with an AI assistant.

…er caps

A shader-visible view heap can be capped by the driver (NVIDIA refuses more
than 1,000,000 descriptors, Marvisak#1760), and the host then makes a heap of exactly
that size with its dynamic slots filling it to the end. Two things were sized
for an uncapped heap: the emitted clamp and the null buffer views, at
HEAP_VIEWS - 1 and HEAP_VIEWS - 2 with HEAP_VIEWS = 2^21. On a capped heap
that put both of them outside it: 'no room for the null buffer views' in the
log, and a computed descriptor index between the cap and the clamp reading a
descriptor that was not there.

HEAP_VIEWS is now 1,000,000, the smallest cap the host meets, and the capped
creation keeps two slots free for the null views. Measured on the machine
that caps: the warning is gone and the null slots exist, where before they
did not.
@0xKaji

0xKaji commented Nov 24, 2026

Copy link
Copy Markdown

Verified a3caa6b on Linux + Wine 11.22 + vkd3d-proton 3.2.0 (GE-Proton11-14) + NVIDIA RTX 3060 8 GB, cross-built with cargo xwin (x86_64-pc-windows-msvc, VKD3D_DISABLE_EXTENSIONS=VK_NV_raw_access_chains):

Verification

  • cargo xtask policy: asset policy: 174 files ok
  • Linux cargo test -p victory-shader --offline: 118 passed, 0 failed, 1 ignored
  • cargo xwin clippy -p victory-gpu -p victory-shader --tests --target x86_64-pc-windows-msvc --offline -- -D warnings: 0 warnings
  • Wine GPU tests (descriptor::host::tests --test-threads=1): 4 passed, 0 failed (0.62s) — dynamic_slots_are_held_until_released flips from FAIL on 70564ae to PASS on a3caa6b.

Code review note

  • In HostHeap::new (crates/victory-gpu/src/descriptor/host.rs:217), when capped at PORTABLE_VIEWS (1_000_000), count + extra = (1_000_000 - MIN_DYNAMIC - 2) + MIN_DYNAMIC = 999_998 and null = HEAP_VIEWS - 1 = 999_999. Since null > count + extra already holds (999_999 > 999_998, matching pairs_end at line 189), changing > to >= isn't needed — and if null == count + extra were ever reached, h.raw_view_at(null - 1, ...) would overwrite the last dynamic slot (count + extra - 1). Keeping > (matching pairs_end) is slightly safer.
  • Note for maintainers: overlaps with GPU: capped view heaps keep the full dynamic range (NVIDIA) #1751 on the capped-heap layout (a3caa6b brings HEAP_VIEWS and NULL_BUFFER_VIEW inside 1_000_000 with MIN_DYNAMIC, whereas GPU: capped view heaps keep the full dynamic range (NVIDIA) #1751 keeps HEAP_VIEWS at 2^21 and preserves DYNAMIC).

@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, a3caa6b (on main 70564ae).

That is exactly what #1779 gives here, also on 70564ae. Both keep the indices and null views inside the capped heap: this PR in 23 lines across 2 files, #1779 more broadly across victory-gpu and victory-shader.

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

@fiestorra

Copy link
Copy Markdown
Contributor Author

Withdrawing in favour of #1779, which does more, and here is the measurement that says so

I ran both on the machine that caps (integrated AMD Radeon(TM) Graphics, driver 32.0.21045.29003, session 1, real window 3840×2160, empty cache, release build, main 70564ae as the base):

build no room for the null buffer views title slot past the host heap
main 1 310,720
this pull request 0 310,722
#1779 (a63eb93) 0 0

So #1779 covers what this one does and the slots above the cap, which mine left in place (I said so in the body: remapping them was the bigger change I was not doing). Two pull requests for the same constant is exactly what should not be in the queue, so I am closing this one rather than asking a reviewer to compare them.

What I would keep from here, if you want it in #1779 or in a follow-up: the fault I had written down — a capped heap is created with its dynamic slots filling it to the last descriptor, so the null views at HEAP_VIEWS - 2 fall outside it even when HEAP_VIEWS itself is small enough. That is the shape of the no room warning, and the two-slot reservation is the smallest change that fixes it. Your branch fixes it a better way; I am just noting the mechanism in case a regression test is worth having for it, since the warning is easy to reintroduce by charging the heap to the last descriptor.

Also, since it may be useful as a second data point: on this machine #1779's build still removes the device (twice, in the same window), and that is expected — the removal here is the id 599 in #1754 (a B5G5R5A1_UNORM description with ALLOW_UNORDERED_ACCESS passed to GetResourceAllocationInfo), which is a different fix (#1832). Your title slot past the host heap going from 310,720 to 0 is the part I can independently confirm.

No game data is involved: counts and warnings only.

Written with an AI assistant.

@fiestorra fiestorra closed this Nov 24, 2026

@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.

Mixed PR: victory-shader part macOS-tested in batch; victory-gpu part Windows-only static.

Heap indices and null views inside…: gpu+shader mixed — shader half in batch, GPU half Windows-only.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants