Skip to content

D3D12.X: global shader-visible sampler heap, typed UAV validation, and occlusion/query VA fixes - #1991

Open
raylitebull wants to merge 1 commit into
xcl-dev:mainfrom
raylitebull:feat/victory-main-world-fixes-v2
Open

raylitebull wants to merge 1 commit into
xcl-dev:mainfrom
raylitebull:feat/victory-main-world-fixes-v2

Conversation

@raylitebull

@raylitebull raylitebull commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Fixes three D3D12.X runtime issues across shared sampler heaps, typed UAV validation, and occlusion/query tracking (multi-plane PresentX compositing has been dropped from this PR and deferred cleanly to #615):

  1. Global shader-visible sampler heap (console_heap.rs, list_x.rs, real.rs): enables a shared PC sampler heap (shared_sampler_heap, global_sampler_heap, SAMPLER_PAGE_SLOTS = 8 with overflow mapped cleanly to reserved zero-sampler slot 0), tracks Bindings::has_sampler_heap so default_bound_heaps always binds GLOBAL_SAMPLER even alongside non-global view heaps or heap_windows() == false, and avoids short-circuiting CPU-only sampler heaps in set_descriptor_heaps_x.
  2. Typed UAV format validation & buffer SRV V# fast path (device_x.rs, real.rs): adds dev_create_uav_checked_x (pc_uav_linear_format, pc_typed_uav_supported keyed by GetAdapterLuid(), handling desc == NULL / Format == 0 sRGB/view mapping and matching null-view ViewDimension to resource dimension) to bind a null view when host hardware lacks TYPED_UNORDERED_ACCESS_VIEW support, plus writing a valid null PC buffer SRV in dev_create_srv_x when buffer_delta != 0.
  3. Occlusion query & resolve_query_data_x tracking (list_x.rs, bind.rs): tracks active occlusion query state and dropped draws (note_dropped_draw) so skipped draws and resolve_query_data_x stay coherent, guarding orig_fn with real::is_adopted (falling back to GetGPUVirtualAddress) and aligning unbinding_all_heaps_lets_the_shared_heap_be_bound_again with shared sampler heap binding.

Part of #1833.

What is in it

  • crates/xcl/src/hle/d3d12x/console_heap.rs, list_x.rs, bind.rs, device_x.rs, real.rs (5 files; 0 changes in present.rs):
    • shared_sampler_pages_preserve_zero_slot_and_clamp_tails
    • uav_format_promotion_and_linearization
    • occlusion_tracks_dropped_draws_and_active_counter
    • default_bound_heaps_always_includes_sampler_heap_when_available

Tested

  • Toolchain: Windows 11 x64, rustc 1.99.1 (58cf8f9c3 2026-10-13), rebased cleanly onto 0f293be (71639e0).
  • cargo check --workspace --tests: passed.
  • XCL_ADAPTER=warp cargo test -p xcl --lib hle::d3d12x:: -- --test-threads=4: passed (shared_sampler_pages_preserve_zero_slot_and_clamp_tails, uav_format_promotion_and_linearization, occlusion_tracks_dropped_draws_and_active_counter, default_bound_heaps_always_includes_sampler_heap_when_available, and unbinding_all_heaps_lets_the_shared_heap_be_bound_again included and passed).

Regression run

  • Standalone scripts/smoke.ps1 pair on 71639e0 vs 0f293be has not been run locally. AMD and NVIDIA reviewers are invited to test on 71639e0 vs 0f293be (including scripts/smoke.ps1 and shared sampler heaps / typed UAVs) and post results in the comments.

Not tested

  • 60 s scripts/smoke.ps1 pair on 71639e0, full cargo test --workspace suite, runtime GPU execution across AMD / NVIDIA / Intel hardware, and Linux/Wine/vkd3d-proton.

AI use

  • Antigravity assisted with implementation and unit tests; the author reviewed the diff and test output.

@yinx080

yinx080 commented Nov 25, 2026

Copy link
Copy Markdown

A data point for the 2-plane path, from the retail title in Series S mode on Windows (RTX 3060 Laptop, NVIDIA
610.91):

  • It presents 2 planes: plane 0 is a 1920×1080 game plane (black until there is a scene), plane 1 a 3840×2160
    UI plane with the menus (the account prompt). With only plane 0 shown, the window stays black on the prompt.
  • A plane is 0x48 bytes (9 qwords: token, resource count at +8, ID3D12Resource** at +0x10, …). Reading
    plane 1 at +0x40 found nothing.
  • Drawing plane 1's first resource over the copied plane 0 (full-screen triangle, linear clamp, premultiplied
    alpha ONE / INV_SRC_ALPHA) showed the prompt.

Glad to test this PR on the same setup when it is ready.

AI use: Claude Code (Claude Opus 5.5).

@raylitebull

Copy link
Copy Markdown
Member Author

Overlap note: full credit to #615 (@0x6461726B) for multi-plane PresentX overlay compositing (present.rs).

We will drop the duplicate present.rs 2-plane compositing changes from #1991 in favor of #615 so #1991 stays scoped strictly to its independent D3D12.X fixes: the global shader-visible PC sampler heap, typed UAV sRGB/cap validation, and resolve_query_data_x / occlusion dropped-draw fallback.

@gsucristo

Copy link
Copy Markdown
Contributor

Technical review findings:

Blocking

  1. set_descriptor_heaps_x forwards CPU-only sampler heaps when global_heap() is None (list_x.rs, pc_heaps + real.rs, dev_create_descriptor_heap_x): dev_create_descriptor_heap_x strips SHADER_VISIBLE from title sampler heaps whenever shared_sampler_heap(dev) is true, but set_descriptor_heaps_x still short-circuits when global_heap().is_none(), forwarding the downgraded CPU-only sampler heap directly to PC SetDescriptorHeaps.
  2. 2048-sampler exhaustion silently aliases wrong samplers (console_heap.rs, GLOBAL_SAMPLER_MAX, SAMPLER_PAGE_SLOTS, slot): Once the 63 pages (SAMPLER_PAGE_SLOTS = 32, wasting 31 slots at the tail and up to 31 per small heap) fill up, reserve_global_sampler returns None, slot() falls back to (k, 0), and publish() becomes a no-op — while shaders still bind GLOBAL_SAMPLER and index k into unrelated samplers.
  3. default_bound_heaps skips binding GLOBAL_SAMPLER when a non-global view heap is bound or heap_windows() is false (list_x.rs, default_bound_heaps): Only appends sampler when current.is_empty() or current == [v], leaving 0 sampler heaps bound for SAMPLER_HEAP_DIRECTLY_INDEXED whenever view == None or a non-global view heap is bound.

Major

  1. dev_create_uav_checked_x (real.rs): When desc is non-null with desc.Format == DXGI_FORMAT_UNKNOWN (0) (or desc is null), eff_fmt != raw_fmt && raw_fmt != 0 skips patching sRGB/promoted formats. Also the null-view fallback hardcodes D3D12_UAV_DIMENSION_TEXTURE2D regardless of resource dimension, and TYPED_UAV_SUPPORT caches by raw device pointer without invalidation.
  2. dev_create_srv_x buffer SRV early-return (real.rs): Leaves slot.pc_srv (and its GLOBAL slot) uninitialized/stale for any PC/fallback shader reading that slot, and leaves the duplicate D3D12_SRV_DIMENSION_BUFFER branch below dead.
  3. present.rs 2-plane compositor (if kept): try_composite_two_planes checks ui_desc for MSAA/TEXTURE2D but not src_desc; build_compositor calls real::orig_fn without real::is_adopted; failed build_compositor retries full RS/heap/PSO creation every frame.

@futurepro62

futurepro62 commented Nov 25, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head fbbd982 (on its base 6567c5f).

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::dxil::fuzz_tests: 992 passed, 0 failed, 43 ignored. SKIPPED (no wave64): 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, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: shared_sampler_pages_preserve_zero_slot_and_clamp_tails, uav_format_promotion_and_linearization, occlusion_tracks_dropped_draws_and_active_counter, default_bound_heaps_always_includes_sampler_heap_when_available, extract_present_planes_reads_series_s_two_plane_stride, composite_shaders_compile_to_sm5_dxbc.
  • 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: 1002 passed, 0 failed, 45 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 7994cd1 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests and const_and_null_mask_operands_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.

@raylitebull
raylitebull force-pushed the feat/victory-main-world-fixes-v2 branch from fbbd982 to 71639e0 Compare November 25, 2026 01:15
@raylitebull raylitebull changed the title D3D12.X: global shader-visible sampler heap, typed UAV validation, occlusion, and 2-plane PresentX compositing D3D12.X: global shader-visible sampler heap, typed UAV validation, and occlusion/query VA fixes Nov 25, 2026
@raylitebull

Copy link
Copy Markdown
Member Author

Thanks for the thorough review and pointers, @gsucristo and @0x6461726B!

Updated #1991 cleanly onto 0f293be (71639e0):

  • Dropped present.rs 2-plane compositing hunks: 0 changes in present.rs now, deferring multi-plane compositing cleanly to #615 and eliminating overlap with #1988.
  • Descriptor heap & sampler safety (list_x.rs, console_heap.rs, real.rs):
    • set_descriptor_heaps_x no longer short-circuits when global_sampler_heap().is_some() (never forwarding SHADER_VISIBLE-stripped CPU-only sampler heaps).
    • Reduced SAMPLER_PAGE_SLOTS (32 -> 8) and mapped GLOBAL_SAMPLER exhaustion on hosted sampler heaps to reserved zero-sampler slot 0 instead of aliasing (k, 0).
    • Tracked Bindings::has_sampler_heap so default_bound_heaps appends GLOBAL_SAMPLER even with non-global view heaps or heap_windows() == false (and prepends the shared view heap when only a sampler heap is bound).
    • dev_create_uav_checked_x handles desc == NULL / desc.Format == 0 sRGB/view mapping, matches null-view ViewDimension to resource dimension, and keys TYPED_UAV_SUPPORT by GetAdapterLuid().
    • dev_create_srv_x writes a valid null PC buffer SRV (and publishes) when buffer_delta != 0 so slot.pc_srv / GLOBAL are never stale, and drops the dead duplicate buffer branch.
    • Also includes real::is_adopted guard on resolve_query_data_x + unbinding_all_heaps test alignment.

Verified locally (cargo check --workspace --tests + XCL_ADAPTER=warp cargo test -p xcl --lib hle::d3d12x:: -- --test-threads=4).

@Anon64

Anon64 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run for this PR: head 76d2681, based on main 80f4819. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s, scripts/smoke.ps1 on a retail title for 60 s, in one batch with the main run.

main 80f4819:

xcl-smoke v1
commit: 80f4819098e921f2e1ab371144d4832f68ffedd6
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1588 (PresentX 1589)
presents per 2 s (last 3): 47 56 27
device removals: 0
crashes: 0
peak commit: 25184 MB

this PR:

xcl-smoke v1
commit: 76d26815ffb0454733c7e1be50eb781142f8d4dc
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1579 (PresentX 1579)
presents per 2 s (last 3): 39 48 18
device removals: 0
crashes: 0
peak commit: 26203 MB

No device removals or crashes; 99 % of main's frames, 104 % of its peak commit.

Not tested: the whole suite; world loading; whether the title reaches all of the changed code in these 60 s (default settings: XCL_DIRECT_DXIL and XCL_HEAP_WINDOWS unset).

Written with Claude Code (Claude Opus 5.5) from runs on this machine.

@JJAutoCompare

Copy link
Copy Markdown

PR #1991 empirical verification

Tested xcl-dev/xcl PR #1991 at 71639e02ba90f85d8ba36ef638402e8ee2971e28. The live PR ref still matched after the run, and the worktree was clean before and after testing.

git merge-tree --write-tree origin/main HEAD exited 0 against the initial origin/main at aaa093657bd96a146c05c0c1a9b61149fe761453 (tree b10a58c30a14c5f6c7f2c337fc87448065f78e10). The recheck against the updated origin/main at cbc296ab65a2661a61e3e2da109134bcd5319f60 also exited 0 (tree a1b8f61cdd9b7453c47356c6ed6862fc92e7f7de).

What is in it

  • Shared shader-visible sampler heap and default sampler binding (console_heap.rs, list_x.rs).
  • Typed UAV format and capability checks (device_x.rs, real.rs).
  • Occlusion tracking for dropped draws and query resolve GPU virtual address handling (bind.rs, list_x.rs).

Tested

  • STOR-WINLAB, Intel Arc A770 16 GiB (driver 32.0.101.9175, DoublePrecisionFloatShaderOps=0, wave size 8–32), AMD Ryzen 7 3800X, Windows 11 Enterprise Evaluation build 26200.9974.
  • rustc 1.100.0 (0ef1bc386 2026-11-09), DXC/DXIL 1.9.2609.5, unoptimized dev and test profiles with debug info and incremental compilation disabled. XCL_ADAPTER=A770.
  • cargo build --workspace and cargo test --workspace --no-run both exited 0 outside the GPU lock.
  • Six focused CPU unit tests passed outside the lock (0 failed, 0 ignored, 0 SKIPPED markers). The same six also passed in the workspace run.
cargo test -p xcl --lib -- --show-output shared_sampler_pages_preserve_zero_slot_and_clamp_tails uav_format_promotion_and_linearization occlusion_tracks_dropped_draws_and_active_counter default_bound_heaps_always_includes_sampler_heap_when_available nested_occlusion_queries_end_the_outer_one_early resolve_query_data_applies_buffer_delta_to_pc_resolve_and_occlusion_writeback

One full suite run under the shared GPU lock:

Set-ExecutionPolicy -Scope Process Bypass -Force
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test { cargo test --workspace --no-fail-fast -- --test-threads=4 --show-output }
  • Cargo exited 101. Across 20 target summaries, libtest reported 1,043 passed, 26 failed, 45 ignored. The log contains 26 SKIPPED markers across 16 named tests, including tests that skipped individual cases. Skipped cases do not add coverage. See pr1991-suite.log in this directory for the complete run.
  • xcl --lib reported 25 failures. In 21, CreateComputePipelineState returned 0x80070057. The other four were result mismatches in gpu_nonfused_mad_and_mac_prevent_fma_contraction, gpu_ps_image_sample_offset_implicit_lod_between_mips, gpu_valu_16_and_64_bit, and gpu_wave64_ps_whole_wave_reductions.
  • xcl --test e2e reported one failure in test_title_runs_and_game_folder_is_untouched. The dynamic depth bias check (Split wave64: masks read only lane by lane stay in their half #94) read blue [0, 0, 255, 255] where it expected green after RSSetDepthBiasX(-1000.5).

All SKIPPED lines from the suite:

SKIPPED gpu::recomp::lower::tests::a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower::tests::cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower::tests::coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower::tests::the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::a_per_lane_2d_or_3d_group_runs_on_the_gpu: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu: const_mask, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its #1426 semantics differ from the console's))
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 arithmetic, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 arithmetic, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its #1426 semantics differ from the console's))
SKIPPED gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu: f16 packed, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 compares, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its #1426 semantics differ from the console's))
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 conversions, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu: integer arithmetic, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 rounding, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu: integer carries, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 transcendentals, wave64: no wave64
SKIPPED gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu: f32 three-source, wave64: no wave64
SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64
SKIPPED gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64
SKIPPED shaders::tests::pso_measurement_compiles_an_exact_synthetic_record: cannot disable the driver cache (Windows Developer Mode is required): The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D)
SKIPPED placed_title_textures_share_vram_and_preserve_pixels: tiled tier < 2
SKIPPED test_title_draws_with_a_root_signature_under_the_debug_layer: no d3d12SDKLayers.dll
SKIPPED heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows
SKIPPED uploads_start_from_each_subresources_state: no D3D12 debug layer (The application requested an operation that depends on an SDK component that is missing or mismatched. (0x887A002D))

Not tested

  • No main test run or retail-title smoke comparison. The suite alone does not establish which failures reproduce on main.
  • No AMD or NVIDIA GPU run or release build. Debug-layer and other hardware-gated paths listed above were unavailable.
  • Sample-dependent paths that returned early, including retail shader tests with XCL_SAMPLE_RPF unset, yielded no sample coverage. The suite also reported early returns for missing audio and system XGameRuntime.

AI use

Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified the counts against pr1991-suite.log and published this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

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.

7 participants