From 28f9123cc3964344f4002e5a01feb6b240f89b82 Mon Sep 17 00:00:00 2001 From: Shang Li <144836394+Mby159@users.noreply.github.com> Date: Wed, 25 Nov 2026 18:29:35 +0800 Subject: [PATCH] d3d12: log the pipeline state stream refusal reason for E_INVALIDARG (RT-PSO-STREAM-EINVALIDARG-REASON) The PC CreatePipelineState refuses a pipeline state stream with E_INVALIDARG without saying why: the finish lambda records a PipelineStream::Refused trace for E_NOTIMPL only, and every E_INVALIDARG from parse_pipeline_stream returns a bare HRESULT, so d3d12_trace::stream_refusal stays null. The console audit gate fires for E_NOTIMPL and E_FAIL only, and audit_pso_stream is called from that console proxy path only, so the PC path prints no audit line either. Each refusal now names its case and is logged once, next to stream_unsupported: the stream has no subobjects, ends inside a subobject type or payload, an unknown subobject type, two subobjects of one family, a compute stage with graphics stages, no shader stage, a mesh pipeline with a vertex, tessellation or geometry stage, a graphics pipeline with no vertex stage. The PC path records the E_INVALIDARG refusals in the trace, LEONIDA_PSO_STREAM_AUDIT=1 prints them, and the remaining graphics-state refusals keep one generic reason. docs/d3d12_vulkan.md follows. No game files: a stream is read from the caller's own description. --- docs/d3d12_vulkan.md | 11 +++--- runtime/shims/d3d12_vulkan_device.cpp | 48 +++++++++++++++++++-------- runtime/shims/d3d12_xs_device.cpp | 2 +- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/docs/d3d12_vulkan.md b/docs/d3d12_vulkan.md index d988a45f14..f823f4e54f 100644 --- a/docs/d3d12_vulkan.md +++ b/docs/d3d12_vulkan.md @@ -2360,9 +2360,11 @@ The trace will enumerate them. - The Vulkan backend selects console numbering when the PC reading fails or gives AS without MS and the console reading has a verified DXIL kind-13 mesh stage. Slot 86 keeps that selected layout with canonical tags and owned shader bytes so slot 55 can derive another PSO. `LEONIDA_XS_STREAM_ENUM=pc` selects PC only. - - With D3D12 tracing, each unsupported stream has one `PipelineStream::Refused` reason. Accepted mesh PSOs - have a separate `PipelineStream::Mesh` count. `LEONIDA_PSO_STREAM_AUDIT=1` also prints raw tags, - shader stages and FSSM hashes for unsupported or failed streams. The call number joins to the backend result. + - With D3D12 tracing, each refused stream has one `PipelineStream::Refused` reason: the `E_NOTIMPL` and the + `E_INVALIDARG` refusals both carry it. Accepted mesh PSOs have a separate `PipelineStream::Mesh` count. + `LEONIDA_PSO_STREAM_AUDIT=1` also prints raw tags, shader stages and FSSM hashes for refused streams. The call + number joins to the backend result. A refusal is also logged once with its reason, so a skipped pipeline shows + in the log without tracing. - `LEONIDA_PSO_PROFILE=1` measures wall time and calling-thread CPU time for each Vulkan pipeline creation. Begin and end records share an ID. Compute records distinguish warmup, dispatch and eager creation. Graphics records name the lazy recipe's @@ -2372,7 +2374,8 @@ The trace will enumerate them. - The stream becomes the same descriptions `CreateGraphicsPipelineState` and `CreateComputePipelineState` take, so a VS stream builds the same PSO as the classic call. - `E_INVALIDARG`, as on the PC runtime: a type given twice, an unknown type, a truncated stream, MS with VS, - tessellation or GS, CS with a graphics stage, or no stage at all. + tessellation or GS, CS with a graphics stage, or no stage at all. Each of these refusals is logged once with + its reason. - `E_NOTIMPL` with a log, for what is not built yet: an AS, a depth-bounds test, view instancing. - `DEPTH_STENCIL2`'s per-face read and write masks go to each face's `VkStencilOpState` (the front face's in the description, the back face's beside it), so `OPTIONS14.IndependentFrontAndBackStencilRefMaskSupported` is TRUE: diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index 5dd6b42e47..cb87cb151c 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -6814,10 +6814,19 @@ HRESULT stream_unsupported(const char* reason, int type = 0) { return E_NOTIMPL; } +// A stream this layer refuses with E_INVALIDARG, with the reason: without one the refusal is silent, so the +// pipelines it skips are not visible in the log. +HRESULT stream_invalid(const char* reason, int type = 0) { + d3d12_trace::stream_refusal = reason; + log_once(reason, type); + return E_INVALIDARG; +} + // The console numbering lacks the gap at 23 in the PC enumeration. HRESULT parse_pipeline_stream(const D3D12_PIPELINE_STATE_STREAM_DESC& desc, PipelineStream& out, bool console_enum = false) { - if (!desc.pPipelineStateSubobjectStream || !desc.SizeInBytes) return E_INVALIDARG; + if (!desc.pPipelineStateSubobjectStream || !desc.SizeInBytes) + return stream_invalid("the pipeline state stream has no subobjects"); D3D12_GRAPHICS_PIPELINE_STATE_DESC& g = out.graphics; for (auto& target : g.BlendState.RenderTarget) { target.SrcBlend = target.SrcBlendAlpha = D3D12_BLEND_ONE; @@ -6846,7 +6855,8 @@ HRESULT parse_pipeline_stream(const D3D12_PIPELINE_STATE_STREAM_DESC& desc, Pipe std::size_t at = 0; while (at < size) { D3D12_PIPELINE_STATE_SUBOBJECT_TYPE type; - if (size - at < sizeof(type)) return E_INVALIDARG; + if (size - at < sizeof(type)) + return stream_invalid("the pipeline state stream ends inside a subobject type"); std::memcpy(&type, base + at, sizeof(type)); type = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE(d3d12_xs::pc_stream_type(unsigned(type), console_enum)); // The versioned depth-stencil and rasterizer subobjects describe the same state as their base type, so the @@ -6858,7 +6868,9 @@ HRESULT parse_pipeline_stream(const D3D12_PIPELINE_STATE_STREAM_DESC& desc, Pipe else if (type == D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RASTERIZER1 || type == D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RASTERIZER2) family = D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RASTERIZER; - if (unsigned(type) >= 64 || (seen >> unsigned(family) & 1)) return E_INVALIDARG; + if (unsigned(type) >= 64) return stream_invalid("unknown pipeline state stream subobject type", int(type)); + if (seen >> unsigned(family) & 1) + return stream_invalid("two subobjects of one family in the pipeline state stream", int(type)); seen |= std::uint64_t(1) << unsigned(family); bool ok = true; const auto take = [&](auto& value) { @@ -6982,13 +6994,13 @@ HRESULT parse_pipeline_stream(const D3D12_PIPELINE_STATE_STREAM_DESC& desc, Pipe break; } default: - log_once("unknown pipeline state stream subobject type:", int(type)); - return E_INVALIDARG; + return stream_invalid("unknown pipeline state stream subobject type", int(type)); } - if (!ok) return E_INVALIDARG; + if (!ok) return stream_invalid("the pipeline state stream ends inside a subobject payload"); } - if (out.has_cs && out.has_graphics_stage) return E_INVALIDARG; // a compute stage with graphics stages - if (!out.has_cs && !out.has_graphics_stage) return E_INVALIDARG; + if (out.has_cs && out.has_graphics_stage) return stream_invalid("a compute stage with graphics stages"); + if (!out.has_cs && !out.has_graphics_stage) + return stream_invalid("no shader stage in the pipeline state stream"); return S_OK; } @@ -7168,10 +7180,12 @@ class PipelineState final return stream_unsupported("amplification shaders are not supported; stream subobject", D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_AS); } + // D3D12: a mesh PSO has no vertex, tessellation or geometry stage if (mesh && (desc.VS.BytecodeLength || desc.HS.BytecodeLength || desc.DS.BytecodeLength || desc.GS.BytecodeLength || desc.StreamOutput.NumEntries)) - return E_INVALIDARG; // D3D12: a mesh PSO has no vertex, tessellation or geometry stage - if (!mesh && (!desc.VS.pShaderBytecode || !desc.VS.BytecodeLength)) return E_INVALIDARG; + return stream_invalid("a mesh pipeline with a vertex, tessellation or geometry stage"); + if (!mesh && (!desc.VS.pShaderBytecode || !desc.VS.BytecodeLength)) + return stream_invalid("a graphics pipeline with no vertex stage"); if (mesh && (!device_.info.mesh_shader || !vk.vkCmdDrawMeshTasksEXT)) { return stream_unsupported("mesh-shader PSOs need VK_EXT_mesh_shader, which the device has not enabled; stage", 1); } @@ -12125,14 +12139,20 @@ class Device final d3d12_trace::stream_refusal = nullptr; d3d12_xs::used_console_stream = false; const auto finish = [&](HRESULT hr) { - if (hr == E_NOTIMPL) - d3d12_trace::record("PipelineStream::Refused", d3d12_trace::stream_refusal ? - d3d12_trace::stream_refusal : "other backend state"); + if (hr == E_NOTIMPL || hr == E_INVALIDARG) { + const char* reason = d3d12_trace::stream_refusal; + if (!reason && hr == E_INVALIDARG) { + // A refusal from the graphics state itself (create_graphics) carries no reason of its own. + log_once("a pipeline state stream this layer refuses", 0); + reason = "a pipeline state stream this layer refuses"; + } + d3d12_trace::record("PipelineStream::Refused", reason ? reason : "other backend state"); + } return d3d12_trace::result(method, hr); }; if (!out) return finish(E_POINTER); *out = nullptr; - if (!desc) return finish(E_INVALIDARG); + if (!desc) return finish(stream_invalid("no pipeline state stream description")); PipelineStream stream; HRESULT parsed = parse_pipeline_stream(*desc, stream); // A stream the PC reading refuses, or leaves with an AS and no MS (no valid PC stream), is read again with the diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index f4611ca449..3f324b9443 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp @@ -4726,7 +4726,7 @@ HRESULT create_pso_from_stream(DeviceProxy* self, const D3D12_PIPELINE_STATE_STR char value[2]{}; return GetEnvironmentVariableA("LEONIDA_PSO_STREAM_AUDIT", value, sizeof(value)) == 1 && value[0] == '1'; }(); - if (audit && desc && (hr == E_NOTIMPL || hr == E_FAIL)) { + if (audit && desc && (hr == E_NOTIMPL || hr == E_FAIL || hr == E_INVALIDARG)) { try { audit_pso_stream(*desc, hr, used_console_stream); } catch (const std::bad_alloc&) {}