Skip to content

d3d12: fix pipeline state stream validation and UB against live Windows D3D12 - #9613

Closed
DenRakEiw wants to merge 1 commit into
ProjectLeonida:mainfrom
DenRakEiw:fix/d3d12-pipeline-stream-validation
Closed

DenRakEiw wants to merge 1 commit into
ProjectLeonida:mainfrom
DenRakEiw:fix/d3d12-pipeline-stream-validation

Conversation

@DenRakEiw

Copy link
Copy Markdown
Contributor

Fixes parse_pipeline_stream and ID3D12Device2::CreatePipelineState validation and undefined behavior in runtime/shims/d3d12_vulkan_device.cpp, verified empirically against live Windows 11 D3D12 (both WARP and native NVIDIA GeForce RTX 5090).

Claim: #9522 (comment)

Changes

  • ID3D12Device2::CreatePipelineState null desc / null out / riid precedence:
    • Zeroes *out when non-null and rejects desc == nullptr with E_INVALIDARG before checking out.
    • Validates/creates the pipeline even when out == nullptr, returning S_FALSE on valid descriptors (matching live Windows 11 WARP + RTX 5090, including when riid is unrelated) and the exact validation HRESULT (E_INVALIDARG) on invalid descriptors.
  • Stage & subobject validation in parse_pipeline_stream:
    • Checks active shader stages by non-empty bytecode (pShaderBytecode && BytecodeLength), matching live Windows 11 D3D12 where empty shader bytecodes in other stages (e.g. CS with empty VS/MS/AS, or VS+PS with empty CS/MS/AS) and graphics-only state subobjects alongside a compute stream are ignored while structural checks (e.g. NumRenderTargets > 8, duplicates, truncation) still return E_INVALIDARG.
    • Rejects compute streams combined with non-empty VS/MS/AS with E_INVALIDARG.
    • Rejects mesh/amplification streams (MS/AS) mixed with legacy geometry stages (VS/HS/DS/GS) or StreamOutput, as well as AS without non-empty MS, with E_INVALIDARG before E_NOTIMPL checks.
    • Defers E_NOTIMPL checks (DepthBoundsTestEnable, separate front/back stencil masks, ViewInstanceCount > 0) to graphics pipelines after stream validation so compute streams match live Windows 11 (S_OK).
  • C++ UB & integer overflow fixes:
    • Replaces round_up with overflow-checked arithmetic (checked_round_up) and checks at + sizeof(type) against SIZE_MAX.
    • Checks if (!ok) break; before reading/converting RASTERIZER1/RASTERIZER2 and RENDER_TARGET_FORMATS payloads.
    • Safely handles non-finite (NaN, +Inf, -Inf) and out-of-range (±1e20f, ±FLT_MAX, ±2^31) float DepthBias values without C++ FP-to-int UB (both for r.DepthBias and log_once), matching live Windows 11 D3D12 (S_OK).
  • Tests:
    • Added runtime/test/d3d12_pipeline_stream_validation_test.cpp registered in runtime/CMakeLists.txt with SKIP_RETURN_CODE 77 and FAIL_REGULAR_EXPRESSION "Validation Error;VUID-", comparing Leonida Vulkan directly against live WARP and native HW D3D12.

Verification (Windows 11, NVIDIA GeForce RTX 5090 + WARP)

  • d3d12_pipeline_stream_validation (LEONIDA_VK_VALIDATION=1): PASS (66 checks, 122 host parity comparisons across RTX 5090 + WARP, 0 VUIDs)
  • d3d12_pso_validation (LEONIDA_VK_VALIDATION=1): PASS (60 layer checks, 100 host comparisons across 2 host devices, 0 VUIDs)
  • d3d12_com (LEONIDA_VK_VALIDATION=1): PASS (0 VUIDs)
  • d3d12_mesh: PASS (note: pre-existing VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076 under validation is unrelated to this PR)
  • git diff --check origin/main..HEAD: clean

AI-assisted (Gemini 4 Neon).

@adorted

adorted commented Nov 23, 2026

Copy link
Copy Markdown

Tested 37def9522 merged onto main 5d74c2723 (clean merge) on Windows 10 Pro 19045 (in-box d3d12.dll 10.0.19041.7291, no Agility SDK), NVIDIA GeForce RTX 5090, driver 610.88, MSVC 19.44.35230, Vulkan SDK 1.4.363.0. No game files. The new d3d12_pipeline_stream_validation fails here, from a host-runtime difference rather than the layer:

FAIL [raster1_depth_bias_0.0f]: layer 0x00000000 != host NVIDIA GeForce RTX 5090 0x80070057
line 672: check_parity(lbl1, S_OK, ... RASTERIZER1 ... default_raster1(b.value) ...)

The Windows 10 runtime rejects a RASTERIZER1 subobject even with DepthBias = 0.0f; Windows 11 accepts it, which is what the test expects. The run stops at this first mismatch, so the later cases were not reached on this host.

A CheckFeatureSupport probe on the same device shows this runtime doesn't recognise the newer option queries at all:

Query hr value
D3D12_OPTIONS7 S_OK MeshShaderTier 10
D3D12_OPTIONS12 0x80070057 n/a
D3D12_OPTIONS16 (DynamicDepthBiasSupported) 0x80070057 n/a
D3D12_OPTIONS19 (RasterizerDesc2Supported) 0x80070057 n/a

So host parity cases for RASTERIZER1/RASTERIZER2 (and probably other newer subobjects) could compare against the host only when it answers those queries, or skip that row when the host returns E_INVALIDARG for a stream that's otherwise minimal, as Windows 10 does. main's d3d12_pso_validation already fails on this host for the same reason (DYNAMIC_DEPTH_BIAS: layer S_OK, host 0x80070057).

Otherwise no regression: full runtime ctest -j4 gives 257/266. The 8 failures besides the new test are the ones plain main 5d74c2723 has on this machine (root_signature_oracle, d3d12_vulkan_device, d3d12_close_parity, d3d12_execute_indirect_validation, d3d12_depth_resolve, d3d12_indirect_rt, d3d12_pso_validation, d3d12_set_descriptor_heaps), most of them the same older-runtime class. d3d12_mesh passes. No new compiler warnings in d3d12_vulkan_device.cpp or the new test.

AI-assisted (Claude Code).

@adriaespii

Copy link
Copy Markdown
Contributor

Tested 37def95 merged onto main 5d74c27 (clean merge) on Windows 11 Pro 24H2 (build 26100), AMD Radeon RX 9070 (RDNA4 / GFX1201), AMD Software 26.10.1 (Vulkan 1.4.359), MSVC 14.44 (VS 2022 Community 17.14.40), RelWithDebInfo: pass.

This confirms that the host parity failure reported on Windows 10 by @adorted (
aster1_depth_bias_0.0f, where Windows 10's in-box runtime lacks newer OPTIONS12/16/19 queries and rejects RASTERIZER1) is purely due to the older OS runtime; on Windows 11 under AMD D3D12 + WARP, all host comparisons pass cleanly.

Results

  • d3d12_pipeline_stream_validation_test (LEONIDA_VK_VALIDATION=1 and

@ikurta92-png

Copy link
Copy Markdown

Tested 37def9522 on NVIDIA GeForce RTX 3060 (Ampere), driver 617.42, Windows 11 Pro 26300, MSVC 19.51 (VS 2026), RelWithDebInfo, Vulkan SDK 1.4.363.1: pass, with a control. This is the NVIDIA counterpart on Windows 11 to the Windows 10 result above.

  • This PR, LEONIDA_VK_VALIDATION off and on, 2 runs each: d3d12_pipeline_stream_validation_test: PASS (66 checks, 122 host parity comparisons), so the host column ran against the native RTX 3060 and WARP. raster1_depth_bias_0.0f and the other RASTERIZER1/2 rows match the Windows 11 runtime here. The MS/AS rows are real cases, since Ampere has VK_EXT_mesh_shader.
  • Regressions: d3d12_pso_validation passes (60 layer checks, 100 host comparisons across 2 host device(s)), even though this PR removes has_graphics_stage. d3d12_com passes. d3d12_mesh passes with validation off. With validation on it fails only on VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076, the existing Runtime: mesh-draw statistics segments count no clipping (VUID-07076); clipping from mesh-primitives queries #7112 case, which this PR doesn't touch.
  • Control (runtime/shims/d3d12_vulkan_device.cpp from the parent 5d74c2723, new test kept, validation on): exit 1 at line 338: layer_dev->CreatePipelineState(nullptr, __uuidof(ID3D12PipelineState), nullptr) == E_INVALIDARG, which is the first stream-validation check. Restored afterwards; the test passes again.

AI-assisted (Claude Code). Synthetic test only, no game files.

@Zipettte

Copy link
Copy Markdown

Tested on AMD Radeon RX 7700 XT (RDNA3), AMD Windows driver 32.0.32029.2010, Windows 11, MSVC 14.51 Release, at 37def95. Full ctest -j 8, out of 239 tests:

No regression. The only failures are the same 5 as on main dde82f2 on this card (vk_queue_query_sync, d3d12_vulkan_device tiles == 1, d3d12_texture_tiles, d3d12_depth_resolve, d3d12_pipeline_library_host; tracked in #8426). Every test this PR adds or touches passes.

AI-assisted (Claude Code).

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.

6 participants