Skip to content

GPU: populate unbound table slots with typed null descriptors - #2128

Open
fuzeofficlal wants to merge 3 commits into
Marvisak:mainfrom
fuzeofficlal:fix/gpu-unbound-uav-null-descriptors-508
Open

fuzeofficlal wants to merge 3 commits into
Marvisak:mainfrom
fuzeofficlal:fix/gpu-unbound-uav-null-descriptors-508

Conversation

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Problem

HostHeap initializes empty view slots to a null 2D float texture SRV (null_view). While RootType::ResourceHeap direct buffer accesses are guarded via VIEW_STRIDES, descriptor-table (RootType::Table) accesses to unbound, unmakeable, or mismatched slots still bind the shared title slot directly when all indices lie below host.count(). When a compute or graphics shader writes or executes atomics on an unbound table UAV (or reads an empty/mismatched slot as another buffer or texture dimension), hardware executes unordered writes against a 2D SRV descriptor, removing the device on RDNA GPUs and failing D3D12 validation.

Changes

  • victory-shader + shader_cache: Record constant-offset descriptor-table handle annotations (TableView { slot, dword, props }) during Lower::handle (including Phi / Select leaves, preferring UAV when annotated both ways, and skipping waterfall/dynamic offsets) and round-trip them through shader_cache.
  • descriptor::host: Add null_desc_for_props and HostHeap::make_null_for to synthesize matching null SRV and UAV descriptors across typed, raw, and structured buffers (StructureByteStride + VIEW_STRIDES) and 1D/2D/2DMS/3D/Cube/array texture dimensions (F32 / SINT / UINT), and preserve raw/structured buffer UAV flags in null_for.
  • draw::State::tables: Keep fully bound tables and plain 2D float SRV empty slots on the in-place zero-copy path (683ad7a), while rebuilding tables whose accessed entries lack a compatible live view in dynamic slots (deduplicated in fresh_tables, with heap.index(at) bounds checks for tables near the end of a title heap) so shared empty title slots in HostHeap are never mutated.

Verification

  • victory-shader: stride_tests::table_views_record_constant_entries_prefer_uav_and_skip_dynamic (dxil.dll validated).
  • victory-gpu: descriptor::host::tests::null_desc_for_props_covers_buffers_and_textures, shader_cache round-trip, and draw::tests::unbound_table_uavs_and_shared_null_slots_execute_cleanly (in-place shared slot 0 2D SRV read, 5 unbound compute UAVs + mismatched explicit-null SRV, PAGE_NOACCESS heap-tail guard page table, and pixel-shader unbound UAV draw) verified with VICTORY_D3D12_DEBUG=1 and VICTORY_D3D12_DRED=1 across AMD Radeon Graphics (RDNA2 iGPU), NVIDIA RTX 5090, and D3D12 WARP.

Closes #508.

HostHeap initializes empty view slots to a null 2D texture SRV. When a shader writes an unbound or unmakeable table UAV (or reads an empty or mismatched slot as another buffer or texture dimension), indexing the shared slot directly executes unordered writes against an SRV descriptor, faulting RDNA GPUs and failing D3D12 validation.

Record constant-offset table handle annotations (TableView) during DXIL lowering and in the shader cache, and rebuild tables whose accessed slots lack a compatible live view in dynamic slots populated with matching null UAV or SRV descriptors while clamping per-entry reads to the guest heap bounds and leaving shared empty title slots untouched.

Closes Marvisak#508

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Unbound table slots populated with typed null descriptors — descriptor completeness fix; mixed gpu+shader, shader side untested here (Windows D3D12 descriptors).

@andrewpozdnakov7-jpg

Copy link
Copy Markdown

One remaining case on 6498c28 is a live SRV in a slot the shader annotates as a UAV. The live-view check accepts the slot, and the dynamic-table path also copies the SRV if another slot already caused a rebuild.

c4edbb5 checks the SRV/UAV access kind in both paths and uses the existing typed null for a mismatch. The test failed before submission because VIctory left the raw SRV bound in place. After, the same test kept the original slot live, reused the replacement table on a second lookup and dispatched with WARP GPU-based validation. The null raw UAV read back zero and the output buffer recorded the shader's completion sentinel.

The GPU suite went from 148 passed, 1 failed and 2 ignored to 149 passed and 2 ignored. Your unbound-table compute and pixel test also passed with GPU-based validation. Strict GPU Clippy with diagnostics and staged asset policy passed. The check covers SRV versus UAV access kind.

@fuzeofficlal

Copy link
Copy Markdown
Contributor Author

Thanks @andrewpozdnakov7-jpg — good catch. A live SRV in a slot the shader annotates as a UAV got through both the live-view check and the copy into a rebuilt dynamic table. Your commit c4edbb5 is now on the branch as-is with your authorship (it fast-forwarded from our head), plus a rustfmt-only follow-up (4ec3f5f). It leaves CBV entries, sampler heaps and read-only SRV tables unchanged. Your test passes on hardware, on WARP with diagnostics and under the D3D12 debug layer; clippy is clean in both modes.

@Xvania7 Xvania7 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, head 4ec3f5f, Windows 10 x64 19045, NVIDIA GeForce RTX 5060, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib -- --test-threads=1 descriptor:: — 10 passed, 1 failed (unrelated baseline #1835 NVIDIA 1M heap limit in dynamic_slots_are_held_until_released; new null_desc_for_props_covers_buffers_and_textures passed)
  • cargo test -p victory-gpu --lib -- --test-threads=1 list::tests:: — 4 passed, 0 failed
  • cargo test -p victory-gpu --lib -- --test-threads=1 draw::tests:: — 6 passed, 1 failed (unrelated baseline #1999 Win10 in-box ID3D12Device10 failure in a_texture_written_in_one_format_reads_in_another_through_a_placed_view; new a_live_srv_in_a_uav_table_gets_a_typed_null and unbound_table_uavs_and_shared_null_slots_execute_cleanly passed)
  • cargo test -p victory-shader --lib emit::lower::tests:: — 21 passed, 0 failed
  • cargo clippy -p victory-gpu --all-targets -- -D warnings — 0 warnings
  • cargo xtask policy — 182 files ok

Clean typed null descriptors for unbound table slots.

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head 4ec3f5f onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. The shader now records which table entries it loads at constant offsets, and with what SRV/UAV kind (Lower::note_table_views, carried through HostShader::table_views and shader_cache). draw::State::tables uses this to rebuild a table in dynamic slots when an entry the shader uses is empty or holds the wrong access kind. The empty slot then gets a typed null descriptor (HostHeap::make_null_for / null_desc_for_props), so the shared empty title slots are left alone. I read the shader, draw and descriptor changes. The shader cache is versioned by the build fingerprint, so the new encoded field is safe. CI passes, and the offline count on the retail shaders is unchanged.

Points for the reviewer:

  • table_entry_props maps a table Cbv entry to a raw-buffer SRV null.
  • A UAV that is not a buffer defaults to a 2D float null.
  • The in-place path now calls mirror for each accessed entry on every draw, and no per-draw cost was measured.
  • The branch includes a commit by andrewpozdnakov7-jpg (c4edbb5).

Generated by Claude Code

@andrewpozdnakov7-jpg

Copy link
Copy Markdown

I measured the table-recording cost raised in triage. The same Windows/WARP synthetic fixture uses a direct table of live R8G8B8A8_UNORM Texture2D SRVs. On the PR, the constant-offset metadata describes those same slots. The timed section is CPU time in State::tables, with the list and textures already created and a check that the table uses its original slots. The GPU crate was built with opt-level=3.

Live SRVs main 940d32f PR 4ec3f5f
4 0.81 µs 1.63 µs
32 6.37 µs 13.84 µs

These are the medians of five alternating process runs per revision. Each process warms up 1,000 calls and measures seven batches of 25,000 calls. This measures CPU recording for these tables. A trial that saved the first pass's descriptor record to skip a second mirror lock ran slower in a separate paired replay (1.31 → 1.55 µs and 12.44 → 13.90 µs).

I also checked the overlap with #2158. The exact heads 4ec3f5f and f346d1d conflict in draw.rs. b91d430 retains both parents and resolves it by allowing either reason to create a fresh table and keeping both the typed-null annotations and placed-buffer backing in the key. All three focused WARP GPU tests passed with the D3D12 debug layer enabled. The full WARP GPU suite had 150 passed and 2 ignored. Both strict GPU Clippy modes and staged asset policy passed.

If you reuse the conflict resolution in a squashed commit, please preserve our attribution with this trailer:

Co-authored-by: andrewpozdnakov7-jpg andrewpozdnakov7-jpg@users.noreply.github.com

@Xvania7 Xvania7 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardware verification on real hardware: NVIDIA GeForce RTX 5060, Windows 10 x64, Rust 1.98.1.

Tested 4ec3f5f checked out into an isolated tree:

  • cargo clippy -p victory-gpu -- -D warnings: 0 warnings, clean.
  • cargo clippy -p victory-shader -- -D warnings: 0 warnings, clean.
  • cargo run -p xtask -- policy: clean (asset policy: 182 files ok).
  • cargo test -p victory-shader table_views: passed (emit::stride_tests::table_views_record_constant_entries_prefer_uav_and_skip_dynamic ... ok).
  • cargo test -p victory-gpu descriptor::host::tests:
    • null_desc_for_props_covers_buffers_and_textures: ok
    • null_3d_uav_is_accepted_by_the_device: ok
    • null_uavs_keep_the_titles_dimension: ok
    • dynamic_search_can_find_a_run_across_the_cursor: ok
    • empty_and_overlong_buffer_views_are_refused: ok
      (Note on NVIDIA: dynamic_slots_are_held_until_released asserts NumDescriptors >= 1<<20, which fails on NVIDIA's 1,000,000 cap until #1777 lands; typed null descriptor allocation itself runs completely clean).

Populating unbound table slots with typed null descriptors accurately eliminates device removal on unmapped UAV/SRV table reads/writes. LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GPU: writing unbound UAVs removes the device on an RDNA3 iGPU

6 participants