Skip to content

D3D12.X: sanitize optimized clear values against PC resource descriptors - #3418

Open
Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:samplers/clear-value-sanitize
Open

Kalmarv wants to merge 1 commit into
xcl-dev:mainfrom
Kalmarv:samplers/clear-value-sanitize

Conversation

@Kalmarv

@Kalmarv Kalmarv commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

What is in it

pc_clear_for_desc in crates/xcl/src/hle/d3d12x/device_x.rs previously only remapped promoted B5G6R5 / B8G8R8X8 UAV target formats and console-only formats in D3D12_CLEAR_VALUE, passing other combinations straight through to PC D3D12 where CreateCommittedResource / CreatePlacedResource reject them with E_INVALIDARG:

  • Adds pc_clear_for_resource_desc (and extends pc_clear_format) in crates/xcl/src/hle/d3d12x/device_x.rs:
    • Returns null when the PC resource is a buffer (D3D12_RESOURCE_DIMENSION_BUFFER) or a texture without ALLOW_RENDER_TARGET or ALLOW_DEPTH_STENCIL.
    • For depth textures (ALLOW_DEPTH_STENCIL), maps DXGI_FORMAT_UNKNOWN (0) or typeless depth clear formats (19/39/44/53, which pc_resource_desc itself produces for depth buffers) to their unique typed depth format (20/40/45/55).
    • For concrete render-target textures, maps DXGI_FORMAT_UNKNOWN (0) or typeless clear formats to the resource's concrete pc_format.
    • For typeless color render targets (including R32_TYPELESS without ALLOW_DEPTH_STENCIL), preserves concrete clear formats such as R8G8B8A8_UNORM_SRGB or R32_FLOAT, while dropping unresolvable UNKNOWN/typeless clear values to null rather than failing resource creation.
  • Wires pc_clear_for_resource_desc into create_placed_resource_x (device_x.rs) and dev_create_committed_resource_x (real.rs), and passes null pOptimizedClearValue for coherent UMA buffer placements in place_console_buffer and place_at_title_address (real.rs). The existing pc_clear_for_desc signature is kept intact (and benefits from the pc_clear_format improvements) so open PR D3D12.X: sanitize reserved and placed resource descriptions and initial states #3291 has zero merge conflict.
  • Adds unit test pc_clear_for_resource_desc_sanitizes_formats_and_non_targets and D3D12 verification test gpu_pc_clear_for_resource_desc_sanitizes_invalid_clear_values covering 11 invalid clear-value cases (all rejected raw by CreateCommittedResource and accepted after sanitization) plus 3 preserved valid concrete clear cases.

Tested

  • Causal reproduction + fix verification (cargo test -p xcl --lib -- hle::d3d12x::device_x::tests::):
    • Before fix: all 10 invalid clear-value cases passed through pc_clear_for_desc failed ID3D12Device::CreateCommittedResource with E_INVALIDARG.
    • After fix: 22 passed, 0 failed, including pc_clear_for_resource_desc_sanitizes_formats_and_non_targets, gpu_pc_clear_for_resource_desc_sanitizes_invalid_clear_values, pc_clear_for_desc_aligns_promoted_uav_targets_only, and gpu_promoted_uav_clear_values_pass_create_committed_resource.
  • Full workspace test suite (cargo test --workspace --no-fail-fast -j 2 -- --test-threads=4 --skip test_title_runs_and_game_folder_is_untouched --skip uma_driver::tests::, RTX 5070 Ti + DXC 1.9): 41 binaries, 2713 passed, 4 failed, 49 ignored, 9 filtered; 27 SKIPPED (22 no wave64, 3 refused #1426, 2 no heap windows). All 4 failures are pre-existing geometry test failures on main (3b6a91ed, tracked in Tests: fix 4 geometry tests broken on main by split-ES safe-barrier and no-store epilogue merges #3411): gpu::dxil::geometry_tests::gpu_geometry_msg_gs_done_records, gpu::dxil::geometry_tests::msg_gs_done_emits_in_dxil, gpu::dxil::lower_geom::tests::gpu_epilogue_filters_oob_triangles_and_no_store_emits, and gpu::dxil::lower_mem::stage_guard_tests::geometry_export_rejected.

Regression run

xcl-smoke v1
commit: f0e8fdd5c3942ddd399d5ee11384c8595c5aacff
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1695 (PresentX 1695)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 31546 MB
xcl-smoke v1
commit: 5c616e862c175eafc21db1aa2cd8497c4c9db72f
gpu: NVIDIA GeForce RTX 5070 Ti
title: ea3b5e4d
seconds: 150
exit: 0x0
frames shown: 1701 (PresentX 1701)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 32748 MB

Not tested

  • Hardware adapters with wave64-only shaders or non-NVIDIA drivers (22 wave64 tests skipped on RTX 5070 Ti).
  • Full title execution for games other than ea3b5e4d or paths requiring uma_driver::tests:: kernel driver tests.
  • placed_in_heap_x fallback and own_memory_if_larger_on_the_pc in real.rs still call pc_clear_for_desc (leaving those lines untouched to avoid conflicting with D3D12.X: sanitize reserved and placed resource descriptions and initial states #3291; they still inherit the pc_clear_format improvements).

AI use

Used an AI coding assistant to audit optimized clear-value handling across device_x.rs and real.rs, reproduce the CreateCommittedResource rejections on D3D12, implement the fix and synthetic unit/GPU tests, and run local verification.

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) labels Nov 29, 2026
@Kalmarv Kalmarv closed this Nov 29, 2026
@Kalmarv Kalmarv reopened this Nov 29, 2026
@Kalmarv Kalmarv closed this Nov 29, 2026
@Kalmarv Kalmarv reopened this Nov 29, 2026
@Kalmarv Kalmarv closed this Nov 29, 2026
@Kalmarv Kalmarv reopened this Nov 29, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: d0832e6
head: 5c616e8
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2892 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none
review: read the whole diff (device_x.rs, real.rs). It changes the default path: console committed and placed resources that aren't render targets or depth buffers are now created without an optimized clear value, and a missing or typeless clear format is filled in. Every case I traced was one the PC already refused with E_INVALIDARG (the WARP test checks that); I found none where an accepted clear value is now changed or dropped. Findings: (1) the real.rs changes passing a null clear for buffers (place_console_buffer ~2173, place_at_title_address ~2271) have no test; the tests only call pc_clear_for_resource_desc directly. Both functions only handle buffers, so the change is right. (2) The readability check runs before the buffer check (~1072), so an unreadable clear pointer still reaches buffers (as on main). (3) is_typeless_format leaves out 21/22 and 46/47, so pc_target_format(120) = 47 would still be refused as a depth clear format (unlikely from a title). (4) Nits: let _ = clear; leaves an unused parameter; make_desc is copied into both tests; the description says 10 invalid cases in one place and 11 in another. (5) AI use names no tool or model. The PR's CI run failed on hle::kernelx::tests::a_page_whose_move_fails_stays_mapped_where_it_was, outside this diff; it passes in the run above on this tree, so that CI failure looks flaky. Fine: the typeless and depth format mappings match DXGI and what pc_resource_desc makes of depth buffers, the promoted formats 85/88/67/118 behave as before, place_at_title_address callers only pass buffers, and #3376 / #3291 edit other lines of the same functions.
performance: 60 s smoke of a retail title, main d0832e6 vs this merge (0b01bb0e): 1516 -> 1685 frames shown (111 %; last presents per 2 s: 60 60 60), peak commit 18133 -> 17130 MB, 0 device removals, 0 crashes.
verdict: safe to merge (after a CI rerun; the description should name the AI model)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5

AI-written and posted by Foniass without a human check of each point.

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

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants