fix(shader,gpu): add heap slot lookup tables and partial dispatch thread counts #3426
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!3426
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3426"
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?
@legayclightning22 on GitHub · 2026-11-27 00:45 UTC · original
legayclightning22:fix/heap-slot-tables-and-partial-dispatch→main· +690 −37 · 13 files · 1 commits · openSummary
Adds host-uploaded shader heap slot lookup tables (
t252) for computed descriptor indices and preservesDispatchX(..., flags & 0x20)partial-dispatch thread counts (74974eb, 11 files,+497/-34).Changes
State::heap_views) and clamp/read them via root SRVt252(SLOT_VIEWS,Lower::view_address_indexed).USER_DISPATCH_THREADS_X(emit/lower/partial.rs) and exit out-of-range lanes before wave/LDS/store operations.Verification
victory-shaderandvictory-gputest suitescargo clippy --locked -p victory-shader -p victory-gpu --all-targets --all-features -- -D warningscargo xtask policy@Dukestar69 on GitHub · 2026-11-27 00:50 UTC · original · approved these changes
LGTM — verified on Windows (RTX 5090):
cargo test -p victory-shader --lib emit::tests::passed (17/17) andemit::lower::tests::passed (34/34, includingpartial_dispatch_guards_threads_past_the_tail)cargo test -p victory-gpu --libpassed (230/230, skipping the 2 pre-existingorigin/mainRTX 5090 failures)cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warningspassed with 0 warningscargo xtask policypassed (192 files ok)Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@fuzeofficlal on GitHub · 2026-11-27 01:02 UTC · original · requested changes
Four concrete issues reproduced locally need to be fixed before this can merge:
Library build fails
clippy --lib -- -D warnings(crates/victory-shader/src/emit/lower.rs:99):Since
emit_withnow callslower::lower_with_thread_limit(...),pub(crate) fn lower(parts: &Parts)is only referenced by#[cfg(test)]code. Runningcargo clippy --lib -p victory-shader -- -D warningsfails to compile:Marking
lower#[cfg(test)](or routing through a single entry point) fixes the build.view_address_indexedcorrupts the buffer virtual address by adding the descriptor-table byte offseta.offset(crates/victory-shader/src/emit/lower/partial.rs:95):self.heap_index(site, first, false)(lower.rs:5813-5823) already adds the instruction's immediateoffsetinto the descriptor table address before shifting by>> 5to compute the heap slot index.read_view_slot(c, slot)then loads the descriptor's buffer virtual address(lo, hi). Calling:adds the descriptor table byte offset (
a.offset) onto the buffer's virtual address. Reproduced ons_load_dwordx4 s[8:11], s[4:5], s0 offset:64(scalar = (offset=64, dynamic=Some(Value(0)))), which shifts the loaded buffer base pointer forward by 64 bytes.Intercepting
count == 8inview_addressesbreaks dynamically indexed image descriptor loads and duplicates dwords0..3into4..7(crates/victory-shader/src/emit/lower.rs:4836-4861):s_load_dwordx8loads fell through toview_addresses_handle()(t1inMEMORY_SPACE), which providesimage_words(width, height, mip levels, type) for textures. Nowif count <= 8 && count.is_multiple_of(4)routescount == 8toSLOT_VIEWS(t252), whereHostHeap::write_viewonly recordsview.and_then(buffer_range)— returning(0, 0, 0, 0)for every image/texture view and breaking dynamically indexed texture size queries.for group in 0..count / 4,group = 1(first = 4) passesfirst = 4toheap_index, which computes(addr + 16) >> 5— the same 32-byte descriptor slot asgroup = 0— duplicating(lo, hi, len, stride)into dwords4..7instead of marking themVal::Missing. Reproduced by lowerings_load_dwordx8 s[8:15], s[4:5], s0readings12(dword 4): it lowered withroot_srvs = [252]andview_addresses = false.s_load_dwordx4), placing raw bytestridein dword 3 and raw byte length in dword 2 does not match the hardwareV#descriptor layout (where stride lives in dword 1 bits 16..29, dword 2 isnum_records, and dword 3 holds format/swizzle/OOB fields).HostHeap::raw_view_atandraw_pair_atleave stale entries inself.views(crates/victory-gpu/src/descriptor/host.rs:489,717-718):Both methods call
self.write_stride(index, 4)andself.note_address(index, None)directly without clearingself.views(self.write_view(index, None, 0)). Reproduced live on RTX 5090: overwriting aView::Placedbuffer slot withraw_view_at(slot, None, 0, 0, false)leaves the previous buffer's address, length, and stride intact inself.views.(Additional note on
DispatchXpartial dispatches):draw.rs:1164-1180converts thread counts todiv_ceil(size)for any compute pipeline dispatched withflags & 0x20, whereasemit/mod.rs:506-510only emitspartial_dispatch_prologue(USER_DISPATCH_THREADS_X) for two hardcoded shader digests (and only guards X, not Y/Z). Any other compute shader dispatched withflags & 0x20will run trailing lanes past the thread count unguarded.74974eb059to3f477b13b0@legayclightning22 on GitHub · 2026-11-27 02:23 UTC · original
Pushed
<NEW_SHA>fixing all four blocking issues and theDispatchXnote:lowerunder#[cfg(test)]incrates/victory-shader/src/emit/lower.rssocargo clippy --locked -p victory-shader --lib -- -D warningsbuilds with zero unused-function errors.self.address_plus(lo, hi, a.offset as i32)inview_address_indexed(crates/victory-shader/src/emit/lower/partial.rs) sinceself.heap_indexalready includesa.offset.count == 8(s_load_dwordx8) inview_addresses(crates/victory-shader/src/emit/lower.rs) so dynamically indexed texture/image descriptors continue usingview_addresses_handle()(t1), and aligned 4-dwordSLOT_VIEWS(t252) descriptor layout with hardwareV#fields (num_recordsin dword 2, stride in dword 3 bits 16..29) without duplicating dwords0..3into4..7.self.viewsviaself.write_view(index, None, 0)inHostHeap::raw_view_atandraw_pair_at(crates/victory-gpu/src/descriptor/host.rs) so overwriting aView::Placedbuffer slot does not leave stale buffer metadata behind.draw.rsDispatchXthread-to-group conversion to shaders where the partial-dispatch prologue is emitted so otherflags & 0x20dispatches are never left with unguarded trailing lanes.Added regression tests covering each of these cases and re-verified
victory-shader,victory-gpu,clippy --all-targets --all-features -- -D warnings, andcargo xtask policy.@fuzeofficlal on GitHub · 2026-11-27 02:40 UTC · original · requested changes
Good progress on the previous items (
cargo clippy -p victory-shader --lib -- -D warningsis now clean,partial.rsno longer adds the table offset tolo,count == 8falls through toview_addresses,raw_view_atclearsself.views, andemit/lower.rsstays under 512 KiB at523,797bytes), but there are three remaining correctness bugs in the new 4-dwordSLOT_VIEWSpath:Blocking Issues
Wrong RDNA2
V#4-dword buffer descriptor bit layout (crates/victory-shader/src/emit/lower.rs:561, 4837-4859)V#), the 14-bit byte stride(stride & 0x3FFF) << 16lives in dword 1 bits[29:16](hi | ((stride & 0x3FFF) << 16)— as already parsed atcrates/victory-shader/src/emit/lower.rs:9464-9474), and the identity component swizzleDST_SEL_X/Y/Z/Win dword 3 is0xFAC(as used atlower.rs:4423anddescriptor/host.rs:1148).lower.rs:4846-4855leaves dword 1 (hi) with0in bits[29:16](verified locally:bin_of(word(1)) == None), so shaders extracting stride via(V#[1] >> 16) & 0x3FFFread0, while placing(stride & 0x3FFF) << 16into dword 3 (mapped) — clobberingFORMAT/INDEX_STRIDE/ADD_TID_ENABLE/OOB_SELECT— and ORing it withSLOT_VIEW_MAPPING = 0x1688(which is the D3D12 API constantD3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING, not an RDNA2V#[3]encoding).((stride & 0x3FFF) << 16)into dword 1 (hi = (hi & 0xFFFF) | ((stride & 0x3FFF) << 16)), and construct dword 3 with valid RDNA2V#[3]bits (DST_SEL0xFACplus appropriate format/OOB bits).count == 4does not checka.offset.is_multiple_of(32)(crates/victory-shader/src/emit/lower.rs:4837)a.offset = 16(the upper half, dwords 4–7, of an 8-dword image descriptor) satisfiescount == 4and is currently hijacked toSLOT_VIEWS(verified locally withoffset = 16,count = 4), overwriting image descriptor words 4–7 with[lo, hi, records, mapped].SLOT_VIEWSpath oncount == 4 && a.offset.is_multiple_of(32).HostHeap::write_viewrecords[0, 0, 0, 4]forView::Constantslots (crates/victory-gpu/src/descriptor/host.rs:514-536, 1154)buffer_range(view)returnsNoneforView::Constant(address, size), whileview_stride(&View::Constant(..))returns4. Verified locally onHostHeap::make_at(5, &View::Constant(0x1_0000_0000, 256)):self.viewsstores[0, 0, 0, 4], losing the constant buffer's address and byte length.View::Constant(address, size)when writingself.views(and consider lazy-allocating the 32 MiBself.viewsupload buffer on demand likeself.addresses, rather than eagerly on everyHostHeap::new).@CocoBeans64 on GitHub · 2026-11-27 17:16 UTC · original
DispatchXflag0x20(FIND-38) checked in the title on an RX 6800 XT (RDNA 2, 32..64 lanes): with this PR the builder's two thread-count programs run about the threads they ask for, instead of 64× as many. Two other programs that set the flag (as0x8020) are not converted and still run 32× theirs.Setup:
main63bcca4+ #2118 (78f36cf), with and without this PR at3f477b1.VICTORY_GPU_TIMING=1, DRED, default Series X output. Menus by hand, then a few minutes in the opening world area.dispatch_x(not part of any PR), for each program and flag value:calls;numthreads;main, and, with this PR, its owndispatch_countsrule;partial_dispatch).Over 300 frames while the builder runs:
main28918b7150a7aad5(64,0x20)caa78b8ca62bc3d6(64,0x20)5062bc7a48e842f8(32,0x8020)4ddd6f9702fab2a7(32,0x8020)caa78b8ca62bc3d6averages about 13 threads per call, so most of each 64-thread group exits at the guard.0x8020programs: they getguarded = false, sodispatch_countskeeps the counts as groups. Both set bit0x20too.a root view's offset: no root view, or outside title buffers. So total GPU time is the same within noise (158 vs 160 ms of commands per frame), and this run cannot show the builder's own cost with and without the fix.Not covered: the image effect of the builder running fully, which is blocked here by the hold above; your heap-slot lookup tables (
t252), which I did not look at separately; the test suites at this head.No title data in this comment. AI-assisted (Claude).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.