You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
D3D12.X: sanitize optimized clear values against PC resource descriptors - #3418
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.
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.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
area:d3d12D3D12.X runtime, command lists, resources, sparse memorygpu:bothCode affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)
2 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is in it
pc_clear_for_descincrates/xcl/src/hle/d3d12x/device_x.rspreviously only remapped promotedB5G6R5/B8G8R8X8UAV target formats and console-only formats inD3D12_CLEAR_VALUE, passing other combinations straight through to PC D3D12 whereCreateCommittedResource/CreatePlacedResourcereject them withE_INVALIDARG:pc_clear_for_resource_desc(and extendspc_clear_format) incrates/xcl/src/hle/d3d12x/device_x.rs:D3D12_RESOURCE_DIMENSION_BUFFER) or a texture withoutALLOW_RENDER_TARGETorALLOW_DEPTH_STENCIL.ALLOW_DEPTH_STENCIL), mapsDXGI_FORMAT_UNKNOWN(0) or typeless depth clear formats (19/39/44/53, whichpc_resource_descitself produces for depth buffers) to their unique typed depth format (20/40/45/55).DXGI_FORMAT_UNKNOWN(0) or typeless clear formats to the resource's concretepc_format.R32_TYPELESSwithoutALLOW_DEPTH_STENCIL), preserves concrete clear formats such asR8G8B8A8_UNORM_SRGBorR32_FLOAT, while dropping unresolvableUNKNOWN/typeless clear values to null rather than failing resource creation.pc_clear_for_resource_descintocreate_placed_resource_x(device_x.rs) anddev_create_committed_resource_x(real.rs), and passes nullpOptimizedClearValuefor coherent UMA buffer placements inplace_console_bufferandplace_at_title_address(real.rs). The existingpc_clear_for_descsignature is kept intact (and benefits from thepc_clear_formatimprovements) so open PR D3D12.X: sanitize reserved and placed resource descriptions and initial states #3291 has zero merge conflict.pc_clear_for_resource_desc_sanitizes_formats_and_non_targetsand D3D12 verification testgpu_pc_clear_for_resource_desc_sanitizes_invalid_clear_valuescovering 11 invalid clear-value cases (all rejected raw byCreateCommittedResourceand accepted after sanitization) plus 3 preserved valid concrete clear cases.Tested
cargo test -p xcl --lib -- hle::d3d12x::device_x::tests::):pc_clear_for_descfailedID3D12Device::CreateCommittedResourcewithE_INVALIDARG.22 passed, 0 failed, includingpc_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, andgpu_promoted_uav_clear_values_pass_create_committed_resource.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 onmain(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, andgpu::dxil::lower_mem::stage_guard_tests::geometry_export_rejected.Regression run
Not tested
22wave64 tests skipped on RTX 5070 Ti).ea3b5e4dor paths requiringuma_driver::tests::kernel driver tests.placed_in_heap_xfallback andown_memory_if_larger_on_the_pcinreal.rsstill callpc_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 thepc_clear_formatimprovements).AI use
Used an AI coding assistant to audit optimized clear-value handling across
device_x.rsandreal.rs, reproduce theCreateCommittedResourcerejections on D3D12, implement the fix and synthetic unit/GPU tests, and run local verification.