GPU: materialize bindless ResourceDescriptorHeap views, refreshing only changed slots #413
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!413
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/413/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?
@wbkepler on GitHub · 2026-11-24 03:03 UTC · original
wbkepler:gpu/bindless-heap-materialization-fast→main· +3055 −169 · 9 files · 2 commits · closed without mergingSummary
Materializes bindless SM 6.6
ResourceDescriptorHeap[]slots (buffer SRVs/UAVs, 256 B and 16 B-aligned CBVs through persistent bounce slices, placed streamed textures) for draws and dispatches whose shaders index the heap directly. Unlike a naive version, it costs next to nothing when nothing changed.Two commits:
(view index, generation), CBV bounce slices, placed-texture upload/state, and eviction ofPLACED_TEXTURESontitle_memory_remapped.// shortcut:UAV ranges over 8 MiB are not copied back (a view of a title's big shared heap would otherwise cost a full snapshot and compare per submission).Test evidence
cargo clippy --workspace --all-targetsandcargo clippy -p victory --features diagnostics --all-targetsreport no new warnings.cargo test --workspacepasses.cargo xtask policypasses.Note:
cargo fmt --checkdoes not pass on the base either (pre-existing formatting in several crates), so changed lines follow the surrounding style and unrelated code is not reformatted.🤖 Generated with Claude Code
@LocranKing on GitHub · 2026-11-24 03:29 UTC · original
Tested on Windows 11 + NVIDIA GeForce RTX 3060 Ti (8 GB, MSVC
1.98.1).Tested
bcc5f60(pr-413, clean tree)32.0.16.2101), Rust1.98.1(x86_64-pc-windows-msvc)cargo xtask policy:asset policy: 151 files okcargo test --workspace: 268 passed, 0 failed, 4 ignoreddiagbuild (VICTORY_D3D12_DRED=1) live boot/first-screen run (45 s) on RTX 3060 Ti:33.2–33.4 ms/frame(0.1–0.2 mspreparing,0.1 mscopies,5.6–8.4 mson the GPU,0.0 mscopying back),13draws/frame,0dropped (frame=1024:6656/6656draws,512/512dispatches).copystat(frames 512–1024+):14.7–14.8submissions,69–70title copies (0.1 MB),74–76refreshes (62.1–63.7 MB),10watches (0.11–0.12 ms,13.0–13.3 MBchecked),0–1page faults.crashes.logempty.Not tested:
cargo clippy, world streaming past the first screens, AMD GPUs.AI use: Antigravity (
Gemini 4 Hydrogen) ran the builds, tests, and diagnostics run and drafted this report from the logs.@aycow on GitHub · 2026-11-24 04:22 UTC · original
The RTX 3070 Ti run in #71 stopped among mesh-only shaders
3a93976a475b8bdb/1617bda5757a7804and printedu8at[heap 329720: null]. On main,op_textcomputes the title value again, whilebindcan send a fresh host base. This leaves open whether the actual handle came from a rebuilt table or a directly indexed heap slot.Would you be able to check whether either hash takes #413’s direct-heap materialization path? A matched diagnostic run with only #413 added could report whether the selected slot has a valid title view, whether its actual host descriptor was materialized with the expected kind, and whether the same stop persists. If both use rebuilt tables, #336’s allocation fallback and #420’s selected-entry coverage are closer controls. We can track a missing compute producer separately once there’s a specific producer-to-consumer resource. Aggregate slot outcomes and shader hashes are sufficient. Ampere report
@miniongk on GitHub · 2026-11-24 04:23 UTC · original
Tested
bcc5f60with #320 (a5ba4a4), #483 (65a161d) and #89 (081afbd) on an RTX 5080, driver 621.24, Windows 11 26300, using a local Xbox Series 1.0.2.1 copy.The pipeline and descriptor-method overlaps were resolved locally without dropping either side.
cargo test --workspacepassed: 290 passed, 0 failed, 4 ignored.On the real title path there were zero host-pipeline refusals and zero packed-format texture-creation failures. This run did not hit the previous
DXGI_ERROR_DEVICE_HUNG; it later stopped on a null write in translated title code instead. That is a different failure boundary, not a claim that the world is working. The usual #97 GPU failure therefore needs a separate comparison after this crash is addressed.Only aggregate counts and error classes shared, no game data or raw game logs. AI-assisted (Kimi Code).
@wbkepler on GitHub · 2026-11-24 04:24 UTC · original
Follow-up: world loading regression fixed (2 commits)
While the world streams in, bindless slots change at nearly every submission. Loading went to ~0.3 fps, and the title's hang watchdog then fired, for three reasons:
Changes:
// shortcut:). The record pass touches only changed slots, plus slots whose texture was evicted.// shortcut:they read null until made).bindless plans(submission) andbindless records(recording) times.Live check (RTX 5090, diag build, start screen → loading → world), per-frame numbers:
The run ended with a host
device removedin the world, which is a separate known issue on this GPU. The menu is unchanged at a locked 30 fps with 0.1 ms preparing.Tests:
cargo test --workspacepasses, both clippy runs are clean (no new warnings), andcargo xtask policypasses. There are new unit tests for incremental plan re-making (an unwritten slot is not re-made) and for upload throttling.🤖 Generated with Claude Code
@miniongk on GitHub · 2026-11-24 04:42 UTC · original
Follow-up to the combination test above: a second run with read-only value observation reproduced the same null write in title code and again had no host-device removal.
Static inspection of the local executable shows that this is an explicit absolute-null write on a fatal path, not an arbitrary corrupted pointer. The associated global pointer is updated repeatedly during execution, so "the callback was never registered" would not explain it. The remaining question is why that particular thread takes the fatal path.
No disassembly, game addresses, game data or raw game logs shared. AI-assisted (Kimi Code).
@wbkepler on GitHub · 2026-11-24 04:45 UTC · original
Follow-up: record-time contention (126388e)
In a build with many recording threads, the world spent 10–32 s per frame in bindless record work (summed over threads). Draws were serializing on the heap's lock, and that lock is also held while a submission makes its plan; placed textures were held under the global placed-texture lock across their uploads. Changes:
Live check (RTX 5090, diag build, an integration build with this branch plus other open GPU PRs,
--fps 60), world frames:0.1 fps, 17949.9 ms/frame (... bindless records 31820.1 ms)1.8 fps, 558.5 ms/frame (369.7 preparing ..., bindless plans 153.8 ms ...; bindless records 136.1 ms)and1.6 fps, 641.3 ms/frame (... bindless records 231.7 ms)Loading holds the 60 fps cap with 0.1–1.9 ms preparing and bindless work at 0.0 ms. The run ended with the separate known host
device removed.cargo test --workspacepasses, both clippy runs add no new warnings, andcargo xtask policypasses.🤖 Generated with Claude Code
@marquezinii on GitHub · 2026-11-24 05:17 UTC · original
Reviewed
126388eon an NVIDIA RTX 5070 (driver 621.24), Windows 11:cargo test -p victory-gpu48 passed, 1 ignored, including the four bindless tests. Three things, each with a temporary test against the PR's own code (not pushed):Slots the title copies as bytes never reach bindless shaders. A slot is marked changed only when
mirror()runs, which happens for our view-creation andCopyDescriptorscalls;bindless_planre-makes only changed, stale-generation and evicted slots and never re-reads the title's slot records. The descriptor module expects titles to copy descriptors themselves ("a title that copies descriptors itself moves whole ones"), and the table path catches that by mirroring again at draw time, but the bindless path has no equivalent:So a slot filled by a byte copy stays null, and a tracked slot overwritten by a byte copy keeps viewing the old resource.
Eviction can free a placed texture someone still holds. Before this PR
PLACED_TEXTURESentries were never released; nowtitle_memory_remapped(from the title's memory mapping calls) releases them, and that can drop the last reference.texture_at/placed_texture()hand out a raw pointer after dropping the lock without taking a reference, andhost_resourcereturns a reference into that object, so the ordinary table path (readable()indraw.rs),make(),use_slotandresolve_placed(beforehold_placed) can run on a freed object. A test that takes the pointer, then evicts, shows the refcount going 1 -> 0 and the box freed while the pointer is still in hand. A 5 s stress race did not crash (freed memory stayed readable), so this is by construction, not a reproduced crash.The SFI0 heap check in
pipeline.rsis dead. It tests bit 32, but the emitter sets resource-heap indexing at bit 25 (0x200_0000) and nothing sets bit 32, sodxil_heapis always false. Bit 25 would not work either, since table descriptors are lowered throughcreateHandleFromHeaptoo; detection really comes from the native layout'sResourceHeapentry, so the SFI0 branch could go.Smaller: textures behind real resource objects are not tracked for bindless (
View::is_buffer), only placed ones, so "covers texture slots" is narrower than the description suggests.Not covered: the title (no game data here).
@wbkepler on GitHub · 2026-11-24 06:47 UTC · original
Thanks @marquezinii for the thorough review and repro tests — pushed a follow-up commit addressing all three findings:
resource::texture_atnow callsobject::add_refwhile still holdingPLACED_TEXTURESand returns an ownedHeldTextureguard.descriptor::host::placed_texturereturns(View, HeldTexture)sodraw::readable,descriptor::host::make,use_slot, andresolve_placed/prepare_bindless_recordall hold a COM reference for the entire duration of use, preventingtitle_memory_remappedeviction from freeing a placed resource out from under them. Addedplaced_texture_handle_survives_eviction.HostHeapnow tracks the title heap start address (detached onHeap::drop) and last-seen(generation << 32 | view_index)keys per slot.bindless_planrunssync_title_slots(scanning dirty write-watch pages viawatch::writes(..., false)when available, or comparing all slot tag words otherwise) so slots filled, overwritten, or zeroed as raw bytes without callingmirror()are detected, materialized/refreshed, or cleared. Addedbindless_slots_detect_byte_copies_and_overwrites.pipeline.rs:resource_heapnow comes directly from the native program'sRootType::ResourceHeapdetection. (Also folded.rev()intodescriptor::shader_slotfor most-recent-heap lookup on reused addresses; non-placed texture views are materialized eagerly inmirror()and now also insync_title_slotswhen byte-copied.)Verified:
cargo clippy -p victory-gpu --all-targets,cargo test -p victory-gpu --lib(50 passed, 0 failed, 1 ignored), andcargo xtask policy(151 files ok).@aycow — regarding
3a93976a475b8bdb/1617bda5757a7804and[heap 329720: null]:#413's direct-heap path runs whentranslated().resource_heapis true (RootType::ResourceHeapin the native program's layout/used list). Note thatdraw.rs::op_textinspects the title's original heap slot (v / 32), whereasdraw.rs::tables()rebuilds CBV tables (and tables past the host heap cap) into dynamic slots and sends the dynamic offset to the shader — so a rebuilt table can print[heap <orig>: null]inop_texteven when the shader received a populated dynamic table. I don't have local title shaders here to inspect those two hashes directly, so checking whethertranslated().resource_heapis set on them (vs a rebuilt table onu8) will distinguish#413's direct-heap path from#336/#420.@SantannaCarlos on GitHub · 2026-11-24 06:55 UTC · original
Tested on an RTX 4070 (Windows 11, driver 621.01), diag build of
d2a4bae+ #136 #173 #176 #164 #180 #179 #177 #138 #116 #145 #135 #100 + this PR, one run into the world: the per-frame copy volume grew steadily from 136 MB to 5.98 GB over 4 minutes (0.1 fps). Then texture creation failed withE_OUTOFMEMORYand the device was removed (0x887A0005, no TDR). The same stack without this PR copies 100–400 MB per frame. #135 is in the stack, so it may be an interaction rather than this PR alone. One run; details in #71 (section 7).@wbkepler on GitHub · 2026-11-24 07:04 UTC · original
Thanks @SantannaCarlos for flagging the monotonic copy-volume growth (136 MB -> 5.98 GB/frame) and
E_OUTOFMEMORY! That pointed straight to four leaks/amplifiers in#413, now fixed in the latest commit:BindlessPlan::copy_constants()previously ranReadProcessMemoryon every misaligned CBV ever written into the heap on every submission (even untouched slots from minutes earlier). It now groups bounces by title address and checkswatch::writes(..., false)so unchanged pages copy 0 bytes, and cleared/overwritten slots recycle their bounce slices through a free list instead of growingbounce_chunksunboundedly.Shadow::updatere-copies & 1 MiBREAD_GAPbridging:READ_GAPindescriptor/host.rswas1 MiB, which bridged unrelated hot memory between sparse historical bindless slots; tightened towatch::PAGE(64 KiB).Shadow::update_freepreviously left*at = 0on partial 64 KiB pages (almost every small bindless CBV/SRV), causingShadow::updateto re-copy them on every single submission forever. When a buffer is write-watched and no pending GPU write overlaps the enclosing 64 KiB pages, stale pages are now copied whole once and marked clean (*at = now).PLACED_TEXTURESVRAM growth + re-allocating unmapped evicted textures:use_slotandresolve_placednow checkvalid_title_address(address, 1)instead ofplausible(address, 1)so unmapped/evicted placed textures are not immediately re-created in VRAM.PLACED_TEXTURESinresource.rsnow enforces an LRU cap (4096textures /1 GiBestimated footprint) with a separatePLACED_LRU_EPOCHsobindless_planreleases retained refs and nulls out LRU-trimmed slots (freeing VRAM) without triggering a re-allocation storm.Added
bindless_cbv_bounce_skips_unchanged_watched_pages_and_recycles_slicesand verifiedcargo clippy -p victory-gpu --all-targets,cargo test -p victory-gpu --lib(51 passed, 0 failed, 1 ignored), andcargo xtask policy(151 files ok).@SantannaCarlos on GitHub · 2026-11-24 09:15 UTC · original
Retested
51f447bon the same RTX 4070 (Windows 11, driver 621.01) with the same stack as before:d2a4bae+ #136 #173 #176 #164 #180 #179 #177 #138 #116 #145 #135 #100, plus #638's detector. Only this PR's head changed. Two runs into the world, with the same input as before.Copy volume: fixed. Per-frame copies now settle at 360–450 MB and stay there. That is the level of the same stack without this PR (380–420 MB). Neither run hit
E_OUTOFMEMORY.MS_VS_TransformDdraw. The stack hits that stop without this PR too (#71).GPU memory still grows. Process GPU memory (dedicated plus shared, sampled every 10 s), new head, runs 1 / 2:
Frame cost. Copies still take 1.0–1.6 s per frame (0.5–0.9 s without this PR). On top of that, "bindless plans" take 0.2–0.25 s and "bindless records" up to 1.1 s per frame. World frame rate: 0.2–0.3 fps, against 0.4–0.8 without this PR and 0.1 with the old head.
On this stack, two hunks in
descriptor/host.rsneeded a manual merge against #135's pool fields: theHostHeap::newsignature and theBindlessinit.@OHHIM on GitHub · 2026-11-24 09:28 UTC · original
Tested on an RTX 3060 12 GB (driver 621.01, 32-lane waves), Windows 11,
diagbuild withVICTORY_D3D12_DRED=1, merged onto main8e79c80. The merge needed three small conflict fixes (watch.rs,descriptor.rs,descriptor/host.rs, plus oneHostHeap::newtest call that needs the newtitle_startargument). With those, clippy-D warnings(default and diagnostics) andcargo test --workspacepass.[heap N: null]reads in the DRED reporthost pipeline refused(E_INVALIDARG)Both runs: the world renders black (subtitles and credits only), then
DXGI_ERROR_DEVICE_HUNG. With #413, the commands in flight at the hang moved from indirect mesh draws to compute dispatches ([compute a3d1a26ad0c8c2cd]30x17x16,[compute 577248728544d74b]320x180x1).On this card #413 did not remove the null heap reads behind the hang (for example
u8=0xa51580 [heap 338092: null]). It survived about 80 s longer, but this is one run of each and the earlier run pressed A for longer, so I would not read much into the timing.@Altorru on GitHub · 2026-11-24 09:55 UTC · original
Security review note on the new
unsafe impl Send/SyncforHostHeapandBindlessPlan: all mutable state I can see is behindMutex/atomics, andBindlessPlanis read-only after construction, so I did not find an unsynchronized field. The highest-risk assumption is that everyID3D12*COM object is free-threaded and that a heap/plan is not used by two submission threads at once. Please document that invariant next to the impls and run a Windows stress/race test (especially withVICTORY_D3D12_WARP=1and concurrent frame submissions). No code change requested from this note.@MichaelSmithAI on GitHub · 2026-11-24 10:40 UTC · original
One remaining case from #754 is an ordinary resource-backed texture SRV reached through
ResourceDescriptorHeap. We compared two views of the same CPU-backed texture onffe310e+51f447b. Each view had its own shader-visible heap so the placed view could not schedule an upload for the ordinary one.The ordinary slot retained a host SRV. After
prepare_bindless_record, the texture was still unused on that command list (first_usereturned true). We discarded that list before submission. The placed view scheduled the upload, and its shader read0x78563412on the RTX 4090 under Wine/vkd3d. After changing the source bytes and advancing the normal refresh interval, it read0x21436587.This narrows the remaining question to how an ordinary bindless texture gets its first upload when there is no earlier copy or table use. We haven't identified a world material that takes that path. If one turns up in a capture, the view kind and the last upload or copy for the same texture would distinguish this case.
@alexdeliu on GitHub · 2026-11-24 17:21 UTC · original
This PR (through
6a0c5e9) is now merged ontomain@ffe310eb, with the conflicts resolved:alexdeliu/VIctory:bindless-on-main. These are the same three files @OHHIM hit on8e79c80:descriptor.rs: keeps main's replay of queued writes inside theOnceLockinitializer, so the heap is published only after the replay. Writes queued while the heap is being made are drained after it.descriptor/host.rs: main's per-heapextradynamic slots instead ofDYNAMIC, plus this PR's bindless fields.watch.rs: this PR's version. It keeps main's saturating end.maincallsHostHeap::new(false, 4, 0).On Windows 11 with an AMD RX 9070 (RDNA4), both CI clippy runs are clean and
cargo test --workspacepasses 351 tests, including all 12descriptor::hosttests (bindless_slots_materialize_refresh_and_copy_back_on_gpu,ordinary_bindless_texture_srv_uploads_and_refreshes_on_gpu).It also passes together with #632, #539, #334 and #453 (366 tests):
stack-ffe310e. Feel free to take the merge commit as is.@aycow on GitHub · 2026-11-24 18:16 UTC · original
I reproduced two ordering failures on exact 6a0c5e9 merged with
ffe310e(769d625). A dropped or later-submitted first recording made all 12 ordinary/placed bindless reads return the old texture contents on AMD, NVIDIA and WARP. Also, a CPU upload recorded before an intervening native GPU producer overwrote that producer in all six ordinary/placed controls.Composing exact #230 8d81f61 preserved all 12 GPU producer controls by deciding the CPU upload at submission. The ordinary #413 scheduler still reproduced stale reads on AMD. A fixture-only rearm on the actual consuming list restored all 12 discard/reorder cases. This points to retaining requests until submission and tracking the native resource generation, together with #230's ordered upload decision. Blindly recording extra copies on #413 alone regresses GPU-produced textures. Full GBV and source links are in the reproduction.
@aycow on GitHub · 2026-11-24 18:54 UTC · original
I advanced the earlier control into submission-owned refreshes on the existing #413+#230 composition branch. The production changes are isolated in eba699d. Pending requests keep the native backing/staging and validate slot generations. Dropping/resetting a recording does not consume its request, and a submitted list can deliver it after #230 decides whether the GPU copy is already authoritative. Completion owns retirement.
All 42 synthetic cases passed on AMD Radeon Graphics, RTX 5070 Laptop and WARP with full GBV. They cover discard, reordered submit, reset, descriptor replacement, same-native aliases, and the #230-marked copies/resolves path. Strict package Clippy and the no-default-feature build passed. The existing #413 discovery/recheck policy stays in place. Shader UAV writers and independently backed aliases still need separate ownership tracking. Would you prefer to take the production hunk into this PR after #230, or review the shared composition first?
@wbkepler on GitHub · 2026-11-24 20:48 UTC · original
Rebased onto current
main(ffe310e) and pushed42c460a.Rebase (
e815993, the branch's commits squashed into one so the conflicts are resolved in a single place). Thanks @alexdeliu, I used yourbindless-on-mainresolution as a reference and ended up with the same tree, except for one thing:descriptor.rs: kept main's replay of queued writes inside theOnceLockinitializer, which now returns anArc<HostHeap>. I dropped the secondpending.drainafterget_or_init. Writers queue under the samependinglock and checkhost.get()first, so nothing can be queued once the heap is initialized, and that drain could never run.descriptor/host.rs: main's per-heapextradynamic slots, plus the bindless fields.nextis sizedextra, notDYNAMIC, and the main test now callsHostHeap::new(false, 4, 0).watch.rs: this PR'stitle_memory_remapped, keeping main's saturating end.@aycow bug (a), fixed in
42c460a. A bindless texture upload used to count as done as soon as a list recorded it (upload_duewroteuploaded/recheck). If that list was dropped, or was submitted after another reader, later lists skipped the upload until the next recheck. Now:run_deferred), it counts as uploaded, and the frame and recheck work as before. A dropped or reset list leaves it pending.New tests:
ordinary_bindless_texture_srv_uploads_and_refreshes_on_gpu: the first recording is dropped, and the next list that reads the texture gets the new contents. Once a list is submitted, later lists don't upload the texture again before its recheck.bindless_texture_uploads_are_throttled: covers the pending-until-submitted rule.The
victory-gpuclippy and tests pass, andcargo xtask policypasses.Bug (b) is not fixed here. That's a CPU upload recorded before a GPU producer on the native side, which then overwrites that producer's output. Fixing it means deciding at submission whether the CPU copy or the GPU copy is authoritative, which needs #230's ordered submission-time prelude. I've left it for #230 rather than bring that machinery into this PR. Your
eba699dapproach (keep the request until submission, check slot generations, completion owns retirement) fits once both PRs land.AI-assisted (Claude Code); checked on Windows 11 / RTX 5090.
@alexdeliu on GitHub · 2026-11-24 21:11 UTC · original
@wbkepler checked
42c460amerged ontomain@ffe310eb(merges cleanly) on an AMD RX 9070 (RDNA4), Windows 11:cargo test --workspace --lockedpasses (351);bindless_slots_materialize_refresh_and_copy_back_on_gpuandordinary_bindless_texture_srv_uploads_and_refreshes_on_gpu);descriptor::hosttests pass.Agreed on the dropped second
pending.drain. With writers checkinghost.get()under the same lock, it was unreachable. Mybindless-on-mainbranch is superseded by this rebase.@marquezinii on GitHub · 2026-11-24 22:01 UTC · original
I checked the follow-up at
42c460aon the RTX 5070 (driver 621.40, Windows 11, Rust 1.98.1 MSVC, its own target directory).cargo test -p victory-gpu --libgives 59 passed, 0 failed and 1 ignored. That includes the newplaced_texture_handle_survives_evictionandbindless_slots_detect_byte_copies_and_overwrites.In the code, the three points read as described:
texture_attakes the reference while it still holdsPLACED_TEXTURESand hands out aHeldTexture.sync_title_slotspicks up slots copied or zeroed as raw bytes.From my side, nothing is left open on those three. One note: the branch now conflicts with
main(70564ae).Pull request closed