Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions docs/d3d12_vulkan.md
Original file line number Diff line number Diff line change
Expand Up @@ -3358,9 +3358,12 @@ 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 with its reason, so a skipped pipeline shows in
the log without tracing. The console re-read of a stream (the paragraph above) keeps its own reason out of
the log, because that reading may be discarded.
- `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
Expand All @@ -3370,7 +3373,12 @@ 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. The stream's own refusals name their case,
in the log and in the trace: no subobjects, the stream ending inside a subobject type or inside its payload,
an unknown subobject type, two subobjects of one family, too many render targets, 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, and no description. The refusals of the graphics state itself (what
`create_graphics` and `create_compute` refuse) keep one generic 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:
Expand Down
78 changes: 61 additions & 17 deletions runtime/shims/d3d12_vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18046,10 +18046,29 @@ HRESULT stream_unsupported(const char* reason, int type = 0) {
return E_NOTIMPL;
}

// The console re-read of a stream (CreatePipelineState) is a second reading of the same stream: a reason it
// gives is not the call's refusal, so it is kept out of the log. The reason of the PC reading is kept.
thread_local bool quiet_refusal = false;

// Sets it for the time it lives, and clears it again even if the reading throws.
struct QuietRefusal {
QuietRefusal() { quiet_refusal = true; }
~QuietRefusal() { quiet_refusal = false; }
};

// 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;
if (!quiet_refusal) 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;
Expand Down Expand Up @@ -18078,7 +18097,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
Expand All @@ -18090,7 +18110,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) {
Expand Down Expand Up @@ -18134,7 +18156,8 @@ HRESULT parse_pipeline_stream(const D3D12_PIPELINE_STATE_STREAM_DESC& desc, Pipe
case D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_RENDER_TARGET_FORMATS: {
D3D12_RT_FORMAT_ARRAY formats{};
take(formats);
if (formats.NumRenderTargets > D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT) return E_INVALIDARG;
if (formats.NumRenderTargets > D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT)
return stream_invalid("too many render targets in the pipeline state stream", int(type));
g.NumRenderTargets = formats.NumRenderTargets;
std::copy(std::begin(formats.RTFormats), std::end(formats.RTFormats), std::begin(g.RTVFormats));
break;
Expand Down Expand Up @@ -18210,13 +18233,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;
}

Expand Down Expand Up @@ -18956,10 +18979,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);
}
Expand Down Expand Up @@ -27960,6 +27985,8 @@ class Device final
// PC slot 11; the Xbox ABI reaches it through device slots 62 and 67 (the proxy forwards).
HRESULT STDMETHODCALLTYPE CreateComputePipelineState(const D3D12_COMPUTE_PIPELINE_STATE_DESC* desc, REFIID riid,
void** out) override {
// The classic path is not a stream call: it does not leave a stream's reason behind.
d3d12_trace::stream_refusal = nullptr;
if (!out) return E_POINTER;
*out = nullptr;
if (!desc) return E_INVALIDARG;
Expand All @@ -27977,6 +28004,8 @@ class Device final

HRESULT STDMETHODCALLTYPE CreateGraphicsPipelineState(const D3D12_GRAPHICS_PIPELINE_STATE_DESC* desc, REFIID riid,
void** out) override {
// The classic path is not a stream call: it does not leave a stream's reason behind.
d3d12_trace::stream_refusal = nullptr;
if (!out) return E_POINTER;
*out = nullptr;
if (!desc) return E_INVALIDARG;
Expand Down Expand Up @@ -28077,14 +28106,22 @@ 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.
reason = "a pipeline state stream this layer refuses";
// The console audit reads the field, so the reason is left there for it.
d3d12_trace::stream_refusal = reason;
log_once(reason, 0);
}
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
Expand All @@ -28095,8 +28132,15 @@ class Device final
console_stream_enum_enabled()) {
const char* pc_reason = d3d12_trace::stream_refusal;
PipelineStream console;
if (SUCCEEDED(parse_pipeline_stream(*desc, console, true)) && !console.as.pShaderBytecode &&
is_mesh_container(console.ms)) {
bool console_read = false;
{
// The re-read's reason is not the call's refusal (the reading may be discarded), so it is
// kept out of the log; the PC reading's reason is the one that is kept.
const QuietRefusal quiet;
console_read = SUCCEEDED(parse_pipeline_stream(*desc, console, true)) && !console.as.pShaderBytecode &&
is_mesh_container(console.ms);
}
if (console_read) {
log_once("console pipeline stream: type 24 contains a mesh shader; DXIL kind", 13);
d3d12_xs::used_console_stream = true;
d3d12_trace::stream_refusal = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion runtime/shims/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6476,7 +6476,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&) {}
Expand Down