Skip to content

GPU: materialize bindless ResourceDescriptorHeap views, refreshing only changed slots - #413

Closed
wbkepler wants to merge 2 commits into
Marvisak:mainfrom
wbkepler:gpu/bindless-heap-materialization-fast
Closed

wbkepler wants to merge 2 commits into
Marvisak:mainfrom
wbkepler:gpu/bindless-heap-materialization-fast

Conversation

@wbkepler

Copy link
Copy Markdown

Summary

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:

  1. Bindless materialization: heap-indexing detection (native layout/used plus the DXIL SFI0 flag), slot tracking by (view index, generation), CBV bounce slices, placed-texture upload/state, and eviction of PLACED_TEXTURES on title_memory_remapped.
  2. Making it cheap. In the first version, every list re-prepared after every title copy, walked every slot, asked the write-watch about each slot's full range, and snapshotted every UAV range for copy-back. On a light menu scene that meant ~16k refreshes, ~6.7 GB of range requests, ~590k page faults and ~1.6 s of CPU per frame. Now:
    • Cached plan per heap: slots are materialized, stale slots pruned, and read/write ranges merged per host copy (reads within 1 MiB coalesced). The plan is rebuilt only when a slot is written, a viewed resource is released, placed textures are evicted, or title memory is mapped or unmapped.
    • Once per submission: lists only note which heaps their draws index. Each heap is prepared once per submission, after all other deferred steps, so title copies no longer re-arm it.
    • Copy-back only when a shader can write: UAV ranges are snapshotted only when a shader using the heap may write memory. That means its decoded native code has a buffer/image/flat/global store or atomic, or its code is not fully known (undecodable, unknown opcode, indirect jump, or PC-layout DXIL), which is treated conservatively as writing. // 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).
    • Placed-texture slots prepared at record time are cached the same way.

Test evidence

  • New tests: an unchanged heap reuses its plan, while a written slot remakes it and nearby reads merge into one range; a list queues each heap once and keeps the "may write" flag. The existing WARP end-to-end test (SRV/CBV/placed/UAV materialization, refresh across submissions, UAV copy-back, stale and garbage-address slots read zero) passes.
  • cargo clippy --workspace --all-targets and cargo clippy -p victory --features diagnostics --all-targets report no new warnings. cargo test --workspace passes. cargo xtask policy passes.
  • Live, RTX 5090, diag build, start menu: 30.0 fps, 33.3 ms/frame, 0.1 ms preparing, 0.0 ms copying back. Per frame: ~15 submissions, ~115 refreshes, 10 watches (0.09 ms, 13 MB checked), 0 page faults in steady state. Before the second commit the same scene ran at ~0.5 fps with ~1.6 s of preparing per frame.

Note: cargo fmt --check does 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

Copy link
Copy Markdown

Tested on Windows 11 + NVIDIA GeForce RTX 3060 Ti (8 GB, MSVC 1.98.1).

Tested

  • Commit: bcc5f60 (pr-413, clean tree)
  • Environment: Windows 11 Home Build 26200, AMD Ryzen 5 5500, 31.8 GB RAM, NVIDIA GeForce RTX 3060 Ti (driver 32.0.16.2101), Rust 1.98.1 (x86_64-pc-windows-msvc)
  • cargo xtask policy: asset policy: 151 files ok
  • cargo test --workspace: 268 passed, 0 failed, 4 ignored
  • diag build (VICTORY_D3D12_DRED=1) live boot/first-screen run (45 s) on RTX 3060 Ti:
    • 29.9–30.1 fps, 33.2–33.4 ms/frame (0.1–0.2 ms preparing, 0.1 ms copies, 5.6–8.4 ms on the GPU, 0.0 ms copying back), 13 draws/frame, 0 dropped (frame=1024: 6656/6656 draws, 512/512 dispatches).
    • Steady-state copystat (frames 512–1024+): 14.7–14.8 submissions, 69–70 title copies (0.1 MB), 74–76 refreshes (62.1–63.7 MB), 10 watches (0.11–0.12 ms, 13.0–13.3 MB checked), 0–1 page faults. crashes.log empty.

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

aycow commented Nov 24, 2026

Copy link
Copy Markdown

The RTX 3070 Ti run in #71 stopped among mesh-only shaders 3a93976a475b8bdb / 1617bda5757a7804 and printed u8 at [heap 329720: null]. On main, op_text computes the title value again, while bind can 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

Copy link
Copy Markdown

Tested bcc5f60 with #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 --workspace passed: 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

Copy link
Copy Markdown
Author

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:

  • full plan rebuilds (every slot re-made, with a slow memory query per slot);
  • placed textures reached through bindless slots being re-hashed in every list;
  • record-time work over every placed slot on every draw.

Changes:

  • Incremental plans: only slots written since the last plan are re-made. Released views are found with one generation check over all slots, at most once a frame. Slots of evicted placed textures are re-made, as are slots of unmapped memory once memory is remapped.
  • Placed textures through bindless: uploaded when a slot first reaches them, then re-checked at most every 60 frames, 8 per frame (// shortcut:). The record pass touches only changed slots, plus slots whose texture was evicted.
  • Fixes a use-after-free: a texture remembered from an earlier pass could be evicted on another thread mid-pass. It is now used only under the placed-texture lock, after an alive check.
  • Budget: making changed slots draws on a time budget (an eighth of wall time, banked up to 8 ms) and takes slots in chunks; the rest wait (// shortcut: they read null until made).
  • Title memory checks ask the kernel only outside title buffers.
  • The fps line now shows bindless plans (submission) and bindless records (recording) times.

Live check (RTX 5090, diag build, start screen → loading → world), per-frame numbers:

phase before after
loading 0.3 fps, 2933 ms/frame, 1520 ms preparing, then hang-watchdog crash 30.0 fps, 33.3 ms/frame, 1–2.5 ms preparing, bindless plans/records 0.0–1.4 ms
world not reached reached (~1,800–2,700 draws/frame) at 0.6–0.9 fps, 1.1–1.6 s/frame; bindless plans ~135 ms, records ~260–470 ms (summed over recording threads); the rest is the existing table-path refresh cost

The run ended with a host device removed in 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 --workspace passes, both clippy runs are clean (no new warnings), and cargo xtask policy passes. 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

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Author

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:

  • Draws with nothing to prepare check a few atomics and take no lock.
  • Only one recording thread prepares placed-texture slots at a time; the others go on. The heap's lock is only tried, so a submission holding it never stalls a draw.
  • A placed texture being uploaded is kept alive by a reference instead of under the placed-texture lock.

Live check (RTX 5090, diag build, an integration build with this branch plus other open GPU PRs, --fps 60), world frames:

  • before: 0.1 fps, 17949.9 ms/frame (... bindless records 31820.1 ms)
  • after: 1.8 fps, 558.5 ms/frame (369.7 preparing ..., bindless plans 153.8 ms ...; bindless records 136.1 ms) and 1.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 --workspace passes, both clippy runs add no new warnings, and cargo xtask policy passes.

🤖 Generated with Claude Code

@marquezinii

Copy link
Copy Markdown
Contributor

Reviewed 126388e on an NVIDIA RTX 5070 (driver 621.24), Windows 11: cargo test -p victory-gpu 48 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 and CopyDescriptors calls; bindless_plan re-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:

review_bindless_slot_copied_by_api_is_materialized      ok (control)
review_bindless_slot_copied_as_bytes_is_materialized    FAILED: plan reads [], made[1] = 0x0
review_bindless_slot_overwritten_as_bytes_is_refreshed  FAILED: plan reads [old view] (old 0x...0060000, new 0x...0260000)

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_TEXTURES entries were never released; now title_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, and host_resource returns a reference into that object, so the ordinary table path (readable() in draw.rs), make(), use_slot and resolve_placed (before hold_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.rs is dead. It tests bit 32, but the emitter sets resource-heap indexing at bit 25 (0x200_0000) and nothing sets bit 32, so dxil_heap is always false. Bit 25 would not work either, since table descriptors are lowered through createHandleFromHeap too; detection really comes from the native layout's ResourceHeap entry, 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

Copy link
Copy Markdown
Author

Thanks @marquezinii for the thorough review and repro tests — pushed a follow-up commit addressing all three findings:

  1. Placed-texture eviction ref-counting: resource::texture_at now calls object::add_ref while still holding PLACED_TEXTURES and returns an owned HeldTexture guard. descriptor::host::placed_texture returns (View, HeldTexture) so draw::readable, descriptor::host::make, use_slot, and resolve_placed / prepare_bindless_record all hold a COM reference for the entire duration of use, preventing title_memory_remapped eviction from freeing a placed resource out from under them. Added placed_texture_handle_survives_eviction.
  2. Byte-copied / byte-overwritten bindless slots: HostHeap now tracks the title heap start address (detached on Heap::drop) and last-seen (generation << 32 | view_index) keys per slot. bindless_plan runs sync_title_slots (scanning dirty write-watch pages via watch::writes(..., false) when available, or comparing all slot tag words otherwise) so slots filled, overwritten, or zeroed as raw bytes without calling mirror() are detected, materialized/refreshed, or cleared. Added bindless_slots_detect_byte_copies_and_overwrites.
  3. Removed dead SFI0 bit-32 check in pipeline.rs: resource_heap now comes directly from the native program's RootType::ResourceHeap detection. (Also folded .rev() into descriptor::shader_slot for most-recent-heap lookup on reused addresses; non-placed texture views are materialized eagerly in mirror() and now also in sync_title_slots when byte-copied.)

Verified: cargo clippy -p victory-gpu --all-targets, cargo test -p victory-gpu --lib (50 passed, 0 failed, 1 ignored), and cargo xtask policy (151 files ok).

@aycow — regarding 3a93976a475b8bdb / 1617bda5757a7804 and [heap 329720: null]: #413's direct-heap path runs when translated().resource_heap is true (RootType::ResourceHeap in the native program's layout/used list). Note that draw.rs::op_text inspects the title's original heap slot (v / 32), whereas draw.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] in op_text even when the shader received a populated dynamic table. I don't have local title shaders here to inspect those two hashes directly, so checking whether translated().resource_heap is set on them (vs a rebuilt table on u8) will distinguish #413's direct-heap path from #336/#420.

@SantannaCarlos

Copy link
Copy Markdown
Contributor

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 with E_OUTOFMEMORY and 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 (comment) (section 7).

@wbkepler

Copy link
Copy Markdown
Author

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:

  1. Unconditional re-copying of every historical misaligned CBV: BindlessPlan::copy_constants() previously ran ReadProcessMemory on 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 checks watch::writes(..., false) so unchanged pages copy 0 bytes, and cleared/overwritten slots recycle their bounce slices through a free list instead of growing bounce_chunks unboundedly.
  2. Partial-page Shadow::update re-copies & 1 MiB READ_GAP bridging:
    • READ_GAP in descriptor/host.rs was 1 MiB, which bridged unrelated hot memory between sparse historical bindless slots; tightened to watch::PAGE (64 KiB).
    • Shadow::update_free previously left *at = 0 on partial 64 KiB pages (almost every small bindless CBV/SRV), causing Shadow::update to 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).
  3. Unbounded PLACED_TEXTURES VRAM growth + re-allocating unmapped evicted textures:
    • use_slot and resolve_placed now check valid_title_address(address, 1) instead of plausible(address, 1) so unmapped/evicted placed textures are not immediately re-created in VRAM.
    • PLACED_TEXTURES in resource.rs now enforces an LRU cap (4096 textures / 1 GiB estimated footprint) with a separate PLACED_LRU_EPOCH so bindless_plan releases 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_slices and verified cargo clippy -p victory-gpu --all-targets, cargo test -p victory-gpu --lib (51 passed, 0 failed, 1 ignored), and cargo xtask policy (151 files ok).

@SantannaCarlos

Copy link
Copy Markdown
Contributor

Retested 51f447b on 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.

Seconds in the world Old head, copies per frame New head, run 1 / run 2
~0 136 MB 71 / 93 MB
~60 1,227 MB 74 / 146 MB
~125 3,939 MB 368 / 366 MB
~185 5,404 MB 371 / 446 MB
~216–230 5,923–5,980 MB 402 MB / –

GPU memory still grows. Process GPU memory (dedicated plus shared, sampled every 10 s), new head, runs 1 / 2:

Seconds in the world New head, run 1 / run 2
~10 12.9 / 12.8 GB
~65 15.2 / 15.3 GB
~121 15.8 / 17.4 GB
~188 18.1 / 18.8 GB
peak 18.9 / 19.2 GB
  • The peak was 11.4 GB dedicated (of 12) plus 7.5–7.7 GB shared, and it was still rising by 1.2–2 GB per minute at the end of both runs.
  • Without this PR, the same stack reaches 15.5 GB at 63 s and then stays flat at about 14.9 GB for 11 minutes. That run had no GPU diagnostics: find what the world hang waits for, and look under a black frame #638 detector, a loop limit of 64 and one compute pass skipped, so it could run that long.
  • Something still accumulates, more slowly than the copies did. I did not run long enough to see where it ends.

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.rs needed a manual merge against #135's pool fields: the HostHeap::new signature and the Bindless init.

@OHHIM

OHHIM commented Nov 24, 2026

Copy link
Copy Markdown

Tested on an RTX 3060 12 GB (driver 621.01, 32-lane waves), Windows 11, diag build with VICTORY_D3D12_DRED=1, merged onto main 8e79c80. The merge needed three small conflict fixes (watch.rs, descriptor.rs, descriptor/host.rs, plus one HostHeap::new test call that needs the new title_start argument). With those, clippy -D warnings (default and diagnostics) and cargo test --workspace pass.

main (+ scripted-keys fix) main + #413
Time to device removal 329 s 407 s
[heap N: null] reads in the DRED report 36 35
host pipeline refused (E_INVALIDARG) 132 120
Slow host submissions / worst 92 / 4.9 s 64 / 7.1 s

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

Altorru commented Nov 24, 2026

Copy link
Copy Markdown

Security review note on the new unsafe impl Send/Sync for HostHeap and BindlessPlan: all mutable state I can see is behind Mutex/atomics, and BindlessPlan is read-only after construction, so I did not find an unsynchronized field. The highest-risk assumption is that every ID3D12* 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 with VICTORY_D3D12_WARP=1 and concurrent frame submissions). No code change requested from this note.

@MichaelSmithAI

Copy link
Copy Markdown

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 on ffe310e + 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_use returned true). We discarded that list before submission. The placed view scheduled the upload, and its shader read 0x78563412 on the RTX 4090 under Wine/vkd3d. After changing the source bytes and advancing the normal refresh interval, it read 0x21436587.

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.

edsuuu added a commit to edsuuu/VI-BR-PORT that referenced this pull request Nov 24, 2026
…, refreshing only changed slots

Resolved: descriptor.rs replays queued writes before publishing the heap (HEAD) and wraps it in an Arc (PR); host.rs runs prepare_bindless then take_retired (#135), Batch::flush keeps HEAD's coalesced ranges; pipeline.rs takes the PR's translate with HEAD's wave target; watch.rs takes the PR's (HEAD's unguarding inside); buffer_uav keeps HEAD's raw-window fallback; tests from both sides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
alexdeliu added a commit to alexdeliu/VIctory that referenced this pull request Nov 24, 2026
No conflicts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@alexdeliu

Copy link
Copy Markdown

This PR (through 6a0c5e9) is now merged onto main @ ffe310eb, with the conflicts resolved: alexdeliu/VIctory:bindless-on-main. These are the same three files @OHHIM hit on 8e79c80:

  • descriptor.rs: keeps main's replay of queued writes inside the OnceLock initializer, 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-heap extra dynamic slots instead of DYNAMIC, plus this PR's bindless fields.
  • watch.rs: this PR's version. It keeps main's saturating end.
  • One test from main calls HostHeap::new(false, 4, 0).

On Windows 11 with an AMD RX 9070 (RDNA4), both CI clippy runs are clean and cargo test --workspace passes 351 tests, including all 12 descriptor::host tests (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.

Xeltax added a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
…Heap[] slots materialized and refreshed)

Brings wbkepler/gpu/bindless-heap-materialization-fast into combo3:
buffer SRVs/UAVs, CBV bounce slices, placed streamed textures and
title-written texture SRVs reached through ResourceDescriptorHeap[] are
made and kept up to date for the draws and dispatches that index the
heap directly.

Conflicts, combined:
- descriptor.rs: Marvisak#413's Arc'd host heap (host_arc, HostHeap::new with
  the title heap start) inside our get_or_init that publishes the heap
  only after replaying the queued writes; our lock-free fast path for a
  made heap restored (Marvisak#413 had dropped it, needed only for the old race).
  Our RTV host_desc(dimension, colour) typeless handling kept as is.
- descriptor/host.rs: Marvisak#413's Bindless tracking fields, budget helpers,
  plausible/valid_title_address and tests, with our guard slot, spare
  (DYNAMIC = 1 << 18, SAMPLER_DYNAMIC), PORTABLE_VIEWS cap and warning,
  VICTORY_VIEW_HEAP_CAP, block_count null fill, free_table/free_space,
  view_fits, raw_window, typeless fits() (Marvisak#876 port), "title slot past
  the host heap" diagnostic and probe_view_heap_sizes. HostHeap::with
  takes the title start and sets up Marvisak#413's bindless state; our tests
  call HostHeap::new with a 0 title start.
- pipeline.rs: Marvisak#413's RootType import and resource_heap/writes_memory
  detection, with our host target passed to host_shader; our
  VICTORY_DEBUG_PS_PROBE and VICTORY_DUMP_SHADERS(_ONLY) /
  VICTORY_DUMP_FAILED_SHADERS around translation unchanged.
- queue.rs: our VICTORY_SHOW_GBUFFER view, GBUFFER note and ungated
  presented(); Marvisak#413's test-only pass_frame. Multi-plane present,
  capture/dump calls and blinks unchanged.
- Outside conflicts: resource.rs tests and pipeline/depth_bounds_test.rs
  follow the new HostHeap::new and Translated fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A4bpLmErkufJL3LGgfR561
Xeltax added a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
- `presented()` is in every build (Marvisak#413's bindless code reads it).
- `bindless_report` is diagnostics-only.
- VICKY.md: the first albedo colours, and the NVIDIA heap cap as the blocker
  for both the black albedo triangles and the black lighting (the lighting's
  160x90 input is written through a UAV past the cap).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A4bpLmErkufJL3LGgfR561
@aycow

aycow commented Nov 24, 2026

Copy link
Copy Markdown

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

aycow commented Nov 24, 2026

Copy link
Copy Markdown

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 and others added 2 commits November 24, 2026 21:38
The eight commits of this branch squashed onto current main:

- Detect SM 6.6 ResourceDescriptorHeap[] use in translated pipelines and
  materialize buffer SRVs/UAVs, CBVs (persistent bounce slices for
  misaligned ones) and placed/ordinary textures reached through
  bindless slots, keeping static table draws zero-overhead.
- Keep a per-heap incremental plan, remade only for slots written,
  released views, evicted placed textures or remapped title memory;
  prepare each heap once per submission.
- Bound bindless work while the world streams in (time budget, one
  recording thread at a time, throttled texture uploads), keep placed
  textures across eviction, detect byte-copied slots, skip unchanged
  bounce copies, bound placed-texture VRAM.
- Schedule CPU uploads for ordinary resource-backed bindless textures.

Conflicts with main resolved as main intends: queued writes are still
replayed inside the OnceLock initializer (now made into an Arc), and the
per-heap dynamic slot count (`extra`) replaces the fixed DYNAMIC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… is submitted

A bindless texture upload was counted as done when a list recorded it.
If that list was dropped, or submitted after another list reading the
texture, later lists skipped the upload until the next recheck and read
the old contents.

- Uploads recorded at draw time wait in a per-heap pending set; every
  list recorded meanwhile carries them too (validated again through the
  slot's view generation or the placed-texture lookup).
- The submission of a list that carries one makes it uploaded (frame
  and recheck as before); dropped or reset lists leave it pending.
- Uploads the texture module declines (host-written textures) count as
  done at once, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wbkepler
wbkepler force-pushed the gpu/bindless-heap-materialization-fast branch from 6a0c5e9 to 42c460a Compare November 24, 2026 20:48
@wbkepler

Copy link
Copy Markdown
Author

Rebased onto current main (ffe310e) and pushed 42c460a.

Rebase (e815993, the branch's commits squashed into one so the conflicts are resolved in a single place). Thanks @alexdeliu, I used your bindless-on-main resolution as a reference and ended up with the same tree, except for one thing:

  • descriptor.rs: kept main's replay of queued writes inside the OnceLock initializer, which now returns an Arc<HostHeap>. I dropped the second pending.drain after get_or_init. Writers queue under the same pending lock and check host.get() first, so nothing can be queued once the heap is initialized, and that drain could never run.
  • descriptor/host.rs: main's per-heap extra dynamic slots, plus the bindless fields. next is sized extra, not DYNAMIC, and the main test now calls HostHeap::new(false, 4, 0).
  • watch.rs: this PR's title_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_due wrote uploaded/recheck). If that list was dropped, or was submitted after another reader, later lists skipped the upload until the next recheck. Now:

  • An upload recorded at draw time goes into a per-heap pending set. Every list recorded while it is pending carries the upload too. Before that, the target is checked again through the slot's view generation, or through the placed-texture lookup for placed textures.
  • When a list that carries the upload is submitted (run_deferred), it counts as uploaded, and the frame and recheck work as before. A dropped or reset list leaves it pending.
  • Host-written textures, whose upload the texture module declines, still count as done right away.

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-gpu clippy and tests pass, and cargo xtask policy passes.

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 eba699d approach (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

Copy link
Copy Markdown

@wbkepler checked 42c460a merged onto main @ ffe310eb (merges cleanly) on an AMD RX 9070 (RDNA4), Windows 11:

  • both CI clippy runs are clean;
  • cargo test --workspace --locked passes (351);
  • all nine tests this PR adds ran and passed, including the GPU ones (bindless_slots_materialize_refresh_and_copy_back_on_gpu and ordinary_bindless_texture_srv_uploads_and_refreshes_on_gpu);
  • all 12 descriptor::host tests pass.

Agreed on the dropped second pending.drain. With writers checking host.get() under the same lock, it was unreachable. My bindless-on-main branch is superseded by this rebase.

@marquezinii

Copy link
Copy Markdown
Contributor

I checked the follow-up at 42c460a on the RTX 5070 (driver 621.40, Windows 11, Rust 1.98.1 MSVC, its own target directory). cargo test -p victory-gpu --lib gives 59 passed, 0 failed and 1 ignored. That includes the new placed_texture_handle_survives_eviction and bindless_slots_detect_byte_copies_and_overwrites.

In the code, the three points read as described:

  • texture_at takes the reference while it still holds PLACED_TEXTURES and hands out a HeldTexture.
  • sync_title_slots picks up slots copied or zeroed as raw bytes.
  • The SFI0 bit-32 check is gone.

From my side, nothing is left open on those three. One note: the branch now conflicts with main (70564ae).

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.