GPU: cap a sampler heap past the host's limit, with dynamic slots for tables past it #86
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!86
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/86/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@faultzonsol on GitHub · 2026-11-24 00:21 UTC · original
faultzonsol:fix/sampler-heap-cap→main· +103 −13 · 2 files · 1 commits · closed without mergingFixes #65. Covers the half #74 leaves open; the two conflict in
HostHeap::new, so one of them should go in.What
A title sampler heap larger than
D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE(2,048) madeHostHeap::newreturnNone, whichDescriptor::host()cached for good.Such a heap is now capped at 2,048 host slots up front: the title's first 1,792 and 256 dynamic ones. Tables reaching past the kept title slots go through the existing
State::tablespath (#21) and are made afresh in the dynamic slots, as tables past a capped view heap already are.HostHeapcounts its dynamic slots per heap (spare):DYNAMICfor view heaps,SAMPLER_DYNAMICfor capped sampler heaps, none for sampler heaps within the limit.dynamic/releaseuse it instead ofDYNAMIC.make_aton a sampler heap falls back to a null sampler, not a null view, when the host cannot make the slot (same guardmirroralready has).HostHeap::with.Difference from #74
#74 retries at 2,048 only when the host refuses the bigger heap, and keeps no dynamic slots, so sampler tables past the cap still read past the heap. Here the cap is applied whenever the title asks for more than the spec limit, so behaviour does not depend on whether a driver accepts an out-of-spec heap (the RX 7600 in #74 does).
#83 (null-fill staging heap sized for samplers) is independent and still applies on top.
Verification
large_sampler_heap_is_capped(count, dynamic allocation up toSAMPLER_DYNAMIC, release and reuse) andsmall_sampler_heap_has_no_dynamic_slots. They run on the host device (RX 6700 XT, Windows 11) and skip without one.cargo test --workspace: all pass.cargo clippy -p victory-gpu --all-targets: nothing new.cargo xtask policy: ok.@WallasSCRIPTS on GitHub · 2026-11-24 00:25 UTC · original
You got there first and the design is better than mine in #74: capping at
the spec limit up front avoids the driver-dependent behaviour my retry-on-
refusal had (the RX 7600 here accepts an out-of-spec 2,049-slot heap). I am
closing #74 so #65 has one PR.
Small suggestion from my branch: the cap warning logs only
count. Addingwanted,madeandlostfields, as the view-heap warning does in #35,makes the log self-explanatory. Purely optional.
My branch also used
saturating_addfor the requested size so a titleasking for
u32::MAXreaches the cap instead of overflowing in a debugbuild — worth checking in your constructor.
@lordon1a on GitHub · 2026-11-24 00:38 UTC · original
Verified
a80eb17c4on Windows 11 (x86_64-pc-windows-gnullvm,rustc 1.100.0, applied cleanly tomain@35b054ec0):cargo xtask policy: 150 files okcargo test -p victory-gpu: 41 passed, 0 failed (including both new testslarge_sampler_heap_is_cappedandsmall_sampler_heap_has_no_dynamic_slots).Important finding in
crates/victory-gpu/src/draw.rs(State::tables)The heap-side changes in
descriptor/host.rslook clean (including theself.samplerbranch inmake_at), butState::tablesindraw.rsstill hardcodes the 32-byte (8-dword) view descriptor stride when remaking tables into dynamic slots:draw.rs:664:u.table_offset_dwords / 8 + 1(sampler descriptors are 16 bytes / 4 dwords, perdescriptor.rs:4, sonis half the required sampler slot count)draw.rs:672&draw.rs:699:table + u64::from(k) * 32(skips every odd sampler slot in title memory)draw.rs:698:u.table_offset_dwords / 8 == kdraw.rs:685&draw.rs:722:made.push((slot, first * 32))(hands the shader double the byte offset for a sampler table, which would index out of bounds in the 2,048-slot sampler heap)Using
let stride_dwords = if heap.samplers() { 4 } else { 8 };andlet stride_bytes = u64::from(stride_dwords) * 4;acrossdraw.rs:662-723would make the capped sampler table remapping path actually match the 16-byte sampler layout.AI-assisted.
@WallasSCRIPTS on GitHub · 2026-11-24 00:41 UTC · original
Verified on Windows 11 with an AMD RX 7600 (driver 32.0.32029.2010), Rust 1.98.1:
cargo test -p victory-gpu: 41 passed, includinglarge_sampler_heap_is_cappedandsmall_sampler_heap_has_no_dynamic_slots.cargo clippy -p victory-gpu --all-targets: clean.This driver accepts an out-of-spec 2,049-slot sampler heap, so the up-front cap handles a case the retry-on-refusal approach missed. The tests do not exercise table remapping. Static inspection confirms the review finding:
State::tablesstill divides offsets by 8 and steps 32 bytes, while sampler descriptors are 4 dwords / 16 bytes. That path needs correction before the capped sampler-table remapping is validated.@DaviTostes on GitHub · 2026-11-24 00:47 UTC · original
Tested
a80eb17under Wine 11.22 + vkd3d-proton 3.1 on Arch Linux x86_64 (AMD RX 9060 XT, RADV 26.3.1), Windows build withcargo xwin ... --target x86_64-pc-windows-msvc: pass, no regression.victory_gputest binary: 38 passed, 3 failed, same baseline (36) plus this PR's two new tests:descriptor::host::tests::large_sampler_heap_is_capped— okdescriptor::host::tests::small_sampler_heap_has_no_dynamic_slots— okmain: Wine'sd3dcompiler_47cannot compile the indirect clamp shader, vkd3d-proton returnsE_INVALIDARGwhen creating an empty pipeline library, and #128 (VirtualQueryreports vkd3d-mapped memory asMEM_FREE, so the deferred texture upload is skipped).No game data used. AI-assisted (DeepSeek V4.1 Flash coding agent).
@Luislariosss on GitHub · 2026-11-24 00:51 UTC · original
Two small things from reading this against #100 and the note from @WallasSCRIPTS, both about the constructor.
1.
count + extracan still overflow on the view path. The cap you add for samplers is exact, but a view heap still reachesmake(count + extra)andPORTABLE_VIEWSthrough the bare sum, as onmain:A title that asks for
u32::MAXdescriptors overflows there in a debug build before the cap can answer.saturating_addon the requested total (and on thePORTABLE_VIEWScomparison) is enough, and it keeps every other answer identical: my version of this change doeslet requested = count.saturating_add(extra);andlet total = count.saturating_add(extra);in the cap decision, and the two cap tests below pass either way.2. The cap warning logs only
count. @WallasSCRIPTS suggestedwanted/made/lost, matching the view-heap warning in #35; I agree, it makes a log line self-explanatory when a title loses slots.What #100 has that is worth folding in here
cap_for(sampler, count, extra) -> Option<(total, mirrored)>, pure, with two unit tests: sampler at 2,048 / 2,049 / 100,000, view under / at / overPORTABLE_VIEWSwithextrasubtracted, andu32::MAXfor both. No device needed, so they run everywhere.State::bind, a one-shotwarn!when a bound heap has no host heap at all, instead of dropping it fromSetDescriptorHeapssilently.I would rather send both as a patch on top of your branch than keep a second PR open for them. Say the word and I will post the diff here; if you would rather keep the change single-authored, that is fine too and I will close #100 - your design with the 256 dynamic sampler slots is the better one, and I said so on #100.
Verified here on
a80eb17c4, AMD Radeon RX 9060 XT (RDNA4, gfx1200), Adrenalin 26.10.1 (Windows driver 32.0.32015.7029), Windows 11 26200, MSVC 2022:No game files. AI-assisted.
@Luislariosss on GitHub · 2026-11-24 00:51 UTC · original
Independent full-suite run on an AMD RDNA4 Windows machine, since #86 has no AMD run yet.
Head a80eb17c4, no local changes Machine AMD Radeon RX 9060 XT (RDNA4, gfx1200), Adrenalin 26.10.1 (Windows driver 32.0.32015.7029) Windows 11 26200, MSVC 2022, Windows SDK 10.0.26100.0 Command cargo test --workspace Result 229 passed, 0 failed, 3 ignoredThe 3 ignored are the BCPack/XMA cases that want reference data outside the repository. For comparison, main gives the same 229 / 0 / 3 here, so this PR costs nothing in the suite. No game files were used and no title was run.
AI-assisted.
@Marvisak on GitHub · 2026-11-25 00:00 UTC · original
Automated triage for the maintainers. Closing because another open pull request covers the same change.
See #1032. Same issue (#65, title sampler heap past 2,048) as #1032, with extra dynamic-slot machinery for sampler tables; no test title has a sampler heap past 2,048 (Grand Theft Auto VI's are 128), so the 15-line cap is enough.
If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed