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

Manually merged
github merged 1 commit from gh-pr/2261/head into gh-pr/2261/base 2026-11-26 05:24:56 +00:00
Owner

@⁠Decodere on GitHub · 2026-11-25 11:45 UTC · original
Decodere:fix-1991-global-sampler-heap-bugs → main · +154 −3 · 1 files · 1 commits · merged 2026-11-25 18:16 UTC

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 #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.

**@⁠Decodere** on GitHub · 2026-11-25 11:45 UTC · [original](https://github.com/xcl-dev/xcl/pull/2261) `Decodere:fix-1991-global-sampler-heap-bugs` → `main` · +154 −3 · 1 files · 1 commits · merged 2026-11-25 18:16 UTC **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 #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.
Follow-up to #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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:24:53 +00:00
github manually merged commit a45cffdc19 into gh-pr/2261/base 2026-11-26 05:24:56 +00:00
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 16:53 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 16:53 UTC · [original](https://github.com/xcl-dev/xcl/pull/2261#issuecomment-7168688661) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
Author
Owner

@⁠futurepro62 on GitHub · 2026-11-25 15:19 UTC · original · edited 2026-11-25 17:09 UTC

Full-suite run, since this PR has no test report yet. Tested exact head a45cffd (on its base 426a5a7).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 1234 passed, 0 failed, 44 ignored. SKIPPED (no wave64, no xgameruntime.dll): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, test_title_draws_with_a_root_signature_under_the_debug_layer, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: release_global_sampler_merges_adjacent_ranges_and_ignores_zero_count, in_global_excludes_shared_sampler_heaps, sampler_own_index_tracks_mapped_pages_and_fallbacks.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 1175 passed, 1 failed, 26 ignored. The failure is gpu::recomp::tests::gpu_image_get_resinfo_past_last_level (the AMD driver returns the clamped level's sizes, e.g. 2D mip 0x1: [4, 2, 0, 1], where the test expects [0, 0, 0, 1]). It reproduced when run alone. It is not caused by this PR: the PR's base 426a5a7 has that test but not main's AMD fix for it, ea088a5 ("image_get_resinfo past the last level gives 0 sizes on AMD too"). Main 06c9f55 passes it on the same iGPU, so a rebase onto current main should clear it.
  • --skip leaves out tests that fail on main 568e7db too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (#1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests, const_and_null_mask_operands_agree_with_hlsl_on_the_gpu and mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • A release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
**@⁠futurepro62** on GitHub · 2026-11-25 15:19 UTC · [original](https://github.com/xcl-dev/xcl/pull/2261#issuecomment-7166659615) · edited 2026-11-25 17:09 UTC Full-suite run, since this PR has no test report yet. Tested exact head `a45cffd` (on its base `426a5a7`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests`: **1234 passed, 0 failed, 44 ignored**. SKIPPED (no wave64, no xgameruntime.dll): `a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu`, `a_per_lane_2d_or_3d_group_runs_on_the_gpu`, `coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu`, `cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu`, `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`, `test_title_draws_with_a_root_signature_under_the_debug_layer`, `the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu`. - The new tests ran and passed: `release_global_sampler_merges_adjacent_ranges_and_ignores_zero_count`, `in_global_excludes_shared_sampler_heaps`, `sampler_own_index_tracks_mapped_pages_and_fallbacks`. - Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1`: **1175 passed, 1 failed, 26 ignored**. The failure is `gpu::recomp::tests::gpu_image_get_resinfo_past_last_level` (the AMD driver returns the clamped level's sizes, e.g. `2D mip 0x1: [4, 2, 0, 1]`, where the test expects `[0, 0, 0, 1]`). It reproduced when run alone. It is not caused by this PR: the PR's base `426a5a7` has that test but not main's AMD fix for it, `ea088a5` ("image_get_resinfo past the last level gives 0 sizes on AMD too"). Main `06c9f55` passes it on the same iGPU, so a rebase onto current main should clear it. - `--skip` leaves out tests that fail on main `568e7db` too, not because of this PR. On NVIDIA: `heap_window_out_of_memory_falls_back_to_the_switch_form` (#1651), the four `gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu` tests, `const_and_null_mask_operands_agree_with_hlsl_on_the_gpu` and `mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu` ([follow-up on #1651](https://git.gtahub.st/github/xcl-dev--xcl/issues/1651)) fail because `runner::skip_test` turns their skips into failures under `XCL_REQUIRE_GPU=mesh`, and `gpu::dxil::fuzz_tests` seeds 70, 545, 1019 and 1507 fail `CreateComputePipelineState` with `E_OUTOFMEMORY` on this card (drivers 616.64 and 621.40). On AMD: `fuzz_validate_and_gpu_1` fails on seed 540 (`res[833]` 0x7 vs CPU 0x6). The AMD run does not set `XCL_REQUIRE_GPU`. **Not tested** - A release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
This discussion has been locked. Commenting is limited to contributors.
No description provided.