Repository navigation
d3d12: give host sampler heaps every slot the shaders can reach (D3D12-GPU-SAMPLER-HEAP-2048) - #2766
Conversation
Shaders clamp a sampler index to 2,047 (leonida-shader emit/shader.rs: "not the bound heap's own count, which a title heap smaller than 2,048 would need"), but HostHeap::new made a sampler heap with exactly the title's count. With a title sampler heap of fewer than 2,048 samplers, an index between its count and 2,047 (a number read from memory the host has not got yet) read past the end of the host heap. A host sampler heap now always has 2,048 slots; fill_null already makes every slot a null point sampler, so the slots past the title's count read as that. The title's own count is kept (up to 2,048): unlike the sibling tree's version, slot 2,047 is not taken from a title heap that uses it, since any clamped index now lands inside the heap anyway. Test: sampler_heaps_have_every_slot_the_shaders_can_reach (a 16-sampler title heap gets 2,048 host slots and keeps count 16; a 2,048 one keeps 2,048). On main it fails: the 16-sampler heap has 16 slots. After ESAT's fix in the sibling VIctory tree (TaynanGT/Vice-Tay dd67ae7, GPL-3.0). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent check on Windows (not the author), at
Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, NVIDIA RTX 4070 Ti SUPER (driver 621.01), Rust 1.98.1 pinned. AI-assisted: yes (opencode). |
|
Verified on Windows, for a merge (not the author). AI-assisted (Claude Code agent Head
One run of several pull requests together covers each at its head ( |
|
Merging (after #2589). Head |
KelboLive
left a comment
There was a problem hiding this comment.
Verified here: the new test passes and fails with the old sizing (left: 16, right: 2048), and full cargo test -p leonida-gpu --lib is 573 passed / 0 failed / 52 ignored.
The sizing is exactly right: the shader clamp is umin(index, 2047) (emit/shader.rs:650), so 2,048 slots is the reachable set, last slot included, no off-by-one; mirror refuses index >= self.count (:4544), samplers_again loops 0..self.count (:4521), and sync_heaps uses min(title, host) (descriptor.rs:411), so a title heap larger than 2,048 cannot write past it. Cost measured here: 32 B per sampler descriptor, 64 KiB per shader-visible sampler heap, made once per title heap through the OnceLock (descriptor.rs:97) — noise against a 10-13 GB run. No root-table or budget change.
Two test gaps worth closing, because the second is the PR's whole point:
- Nothing asserts that slots past the title's count are the null point sampler — passing
countinstead ofsizetofill_null(descriptor.rs/host.rs:2442) still passes the test while leaving those slots undefined. - Nothing covers the 2,047 boundary or a title heap larger than 2,048 (the
mincap). The test also returns silently when no D3D12 device exists, so a GPU-less run passes vacuously.
For the record, this does not touch the fallback we see in the logs: slot=368463 is the view heap (sized to the view limit, one million slots on this device), so those misses are store-marking, not a 2,048 sampler bound — that is #2831's territory.
|
finding: fill_null's null POINT samplers in past-count slots change visible pixels in GTA VI — faces go to noise Where: Evidence: past the title's sampler count the slots get POINT-filtered null samplers, and character faces (which sample past-count slots) render as noise; making null samplers LINEAR (local arm Question for the maintainers: what should past-count slots hold — a linear-ish default, or is past-count sampling considered title error? |
Claimed in the coordination issue as: D3D12-GPU-SAMPLER-HEAP-2048 (#2570 (comment))
What and why
Shaders clamp a sampler index to 2,047.
leonida-shaderemit/shader.rsnotes this is "not the bound heap's own count, which a title heap smaller than 2,048 would need". ButHostHeap::new(d3d12/crates/leonida-gpu/src/descriptor/host.rs) made a host sampler heap with exactly the title's count. With a title sampler heap of fewer than 2,048 samplers, an index between its count and 2,047 read past the end of the host heap. Such an index comes from a number read out of memory the host hasn't got yet, which happens while streaming.The change:
fill_nullalready makes every slot a null point sampler, so the slots past the title's count read as that.This ports ESAT's fix from the sibling VIctory tree (TaynanGT/Vice-Tay
dd67ae7, GPL-3.0).Tested
descriptor::host::tests::sampler_heaps_have_every_slot_the_shaders_can_reach: a 16-sampler title heap gets 2,048 host slots and keeps count 16, and a 2,048 one keeps 2,048. Onmain(7663c34fc) it fails (a 16-sampler heap backs 2,048 slots,left: 16,right: 2048); with the change it passes.cargo test -p leonida-gpu --lib: 573 passed, 0 failed, 52 ignored (main: 572).cargo clippy -p leonida-gpu --lib --tests: no warning in the changed lines.GPUs tested: the test makes its heaps on the local hardware D3D12 device; no game run.
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)🤖 Generated with Claude Code