Skip to content

D3D12.X: coalesce released shared sampler ranges and fix view/census checks in console_heap - #2261

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-1991-global-sampler-heap-bugs
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-1991-global-sampler-heap-bugs

Conversation

@Decodere

Copy link
Copy Markdown
Contributor

What is in it

Follow-up to #1991 fixing three bugs in crates/xcl/src/hle/d3d12x/console_heap.rs (GLOBAL_SAMPLER shared shader-visible PC sampler heap):

  1. Coalesce released shared sampler ranges and ignore zero-count releases (release_global_sampler): release_global_sampler previously pushed raw (first, count) entries onto s.free without guarding count == 0 or calling merge_release(&mut s.free, first, count) (unlike release_global). Because D3D12 caps GLOBAL_SAMPLER at 2048 descriptors (2047 usable) and small/tail sampler pages reserve < 8 slots, freeing adjacent small sampler heaps left unmerged shards (e.g. [(1, 4), (5, 4)]) that could not satisfy an 8-slot SAMPLER_PAGE_SLOTS request, causing premature exhaustion and fallback to reserved zero-sampler slot 0. Guard if count == 0 { return; } and coalesce via merge_release(&mut s.free, first, count).
  2. Exclude shared sampler heaps from in_global(obj): in_global(obj) checked h.obj == obj && !h.pages.is_empty() without !h.sampler. Once D3D12.X: global shader-visible sampler heap, typed UAV validation, and occlusion/query VA fixes #1991 populated h.pages for shared sampler heaps, in_global falsely returned true for every shared sampler heap (even though it queries membership in the shared view heap). Add && !h.sampler.
  3. Use shared sampler page indices in census() (sampler_own_index): census() compared sampler w[3] & 0xFFF == k instead of the slot's actual index in GLOBAL_SAMPLER, misreporting live shared samplers as "with another" under XCL_TRACE_FRAME. Extract sampler_own_index(&h.pages, k) (returning f + (k % SAMPLER_PAGE_SLOTS) when mapped, or sampler_unmapped_index(!pages.is_empty(), k) when unmapped/unhosted — matching slot() and view-heap own_index) and use it in census().

Tested

  • Hardware / toolchain: NVIDIA GeForce RTX 4060 (8 GB, 32-lane waves, driver 621.14), Intel Core i5-11400F, 32 GB RAM, Windows 11 Home build 26200, Rust 1.100.0, DXC 1.9.2609.5 (01b62ad4), release build.
  • Failing-first verification before the fixes: running the three new pure-CPU unit tests against pre-fix behavior failed all three (0 passed, 3 failed: release_global_sampler_merges_adjacent_ranges_and_ignores_zero_count saw unmerged [(5, 4), (1, 4), (1, 0)] instead of [(1, 8)], in_global_excludes_shared_sampler_heaps failed !in_global(0xC100), and sampler_own_index_tracks_mapped_pages_and_fallbacks returned 0 instead of 1).
  • Targeted unit tests (cargo test --release -p xcl --lib hle::d3d12x::console_heap::tests -- --test-threads=4 --nocapture): 12 passed, 0 failed, 0 ignored (0.24 s; all 9 existing console_heap tests including real RTX 4060 shared-heap tests + 3 new pure-CPU CI-safe tests: release_global_sampler_merges_adjacent_ranges_and_ignores_zero_count, in_global_excludes_shared_sampler_heaps, and sampler_own_index_tracks_mapped_pages_and_fallbacks).
  • Full workspace release build and test suite (cargo build --release --workspace and cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture): 23 test binaries, 1246 passed, 0 failed, 46 ignored, plus 27 runtime SKIPPED lines (20 no wave64 on RTX 4060, 3 wave32 per-lane form refused by driver, 2 missing d3d12SDKLayers.dll / D3D12 debug layer, 1 driver shader cache toggle unavailable, 1 no heap windows).

Regression run

Baseline (origin/main 426a5a74):

xcl-smoke v1
commit: 426a5a745db4d5e4b037449ede0b70cb342f5192
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1548 (PresentX 1548)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14464 MB

PR head (a45cffdc):

xcl-smoke v1
commit: a45cffdc19b121fa1de0983a079b4da096acf9e2
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1568 (PresentX 1568)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14433 MB

Not tested

  • AMD and Intel GPUs, native wave64 hardware, the 27 runtime-skipped GPU/driver tests, and the 46 #[ignore] tests on this machine.
  • Live XCL_TRACE_FRAME log output from a retail title saturating GLOBAL_SAMPLER (the sampler_own_index mapping, in_global separation, and release_global_sampler coalescing/unregister paths are verified by the new deterministic unit tests, while normal shared sampler/view heap runtime operation is verified by console_heap::tests and the 60 s RTX 4060 smoke run).

AI use

Implemented and verified with Google Antigravity (Gemini 4 Neon). All code changes, failing-first and post-fix unit tests, full workspace release tests, and paired 60 s RTX 4060 smoke runs were reviewed and executed locally.

…checks in console_heap

Follow-up to xcl-dev#1991 (shared shader-visible PC sampler heap `GLOBAL_SAMPLER`)
fixing three bugs in `crates/xcl/src/hle/d3d12x/console_heap.rs`:

1. `release_global_sampler` pushed raw `(first, count)` entries into `s.free`
   without guarding `count == 0` or coalescing via `merge_release` (unlike
   `release_global`). Freeing adjacent small sampler pages (< 8 slots) left
   unmerged shards that could not satisfy an 8-slot `SAMPLER_PAGE_SLOTS`
   request, prematurely exhausting the 2048-descriptor `GLOBAL_SAMPLER` heap
   and dropping new pages onto reserved zero-sampler slot 0. Guard `count == 0`
   and coalesce through `merge_release(&mut s.free, first, count)`.
2. `in_global(obj)` checked `h.obj == obj && !h.pages.is_empty()` without
   `!h.sampler`, so shared sampler heaps (which now populate `h.pages`) falsely
   reported true for the shared view heap. Add `&& !h.sampler`.
3. `census()` compared sampler `w[3] & 0xFFF == k` instead of the shared
   sampler page index, misreporting live shared samplers as "with another" in
   `XCL_TRACE_FRAME`. Extract `sampler_own_index(&h.pages, k)` (matching
   `slot()` and view-heap `own_index`) and use it in `census()`.

Assisted-by: Google Antigravity (Gemini 4 Neon)
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.

1 participant