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
5 changes: 5 additions & 0 deletions runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4300,6 +4300,11 @@ if(TARGET Vulkan::Headers)
target_compile_options(d3d12_mesh_test PRIVATE /W4 /permissive- /utf-8)
add_test(NAME d3d12_mesh COMMAND d3d12_mesh_test)
set_tests_properties(d3d12_mesh PROPERTIES SKIP_RETURN_CODE 77)
# Every console-numbered stream is realized on first use: the deferred path must read it with the console's
# numbering and keep the console-numbered record, or every type 24/26 subobject is refused (CONSOLE-STREAM-ON-DEMAND-REREAD).
add_test(NAME d3d12_mesh_on_demand COMMAND d3d12_mesh_test)
set_tests_properties(d3d12_mesh_on_demand PROPERTIES SKIP_RETURN_CODE 77
ENVIRONMENT "LEONIDA_PIPELINE_COMPILE=on-demand")
# The same draws through the heavy pipeline cache (src/heavy_pipeline_cache.h): every build first asks the
# offline cache without compiling, and a miss is built against the heavy cache in a folder of its own.
add_test(NAME d3d12_mesh_heavy_cache COMMAND d3d12_mesh_test)
Expand Down
67 changes: 44 additions & 23 deletions runtime/shims/d3d12_vulkan_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15331,13 +15331,52 @@ class Device final
return shared_native_graphics(pc, mesh, containers, iid, out);
});
}
// parse_pipeline_stream, plus the console re-read: a stream the PC reading refuses, or leaves with an AS and no MS
// (no valid PC stream), is read again with the console's numbering, and that reading is taken when it holds a mesh
// shader (its 24) and no AS. A stream the PC reading accepts as valid is never read differently.
// LEONIDA_XS_STREAM_ENUM=pc keeps the PC reading alone (such PSOs are then refused, as before). The eager path and
// the deferred one below both read through here: the deferred path is handed console-numbered streams, and used to
// parse them as PC ones alone, which refused every console PSO while a device prepared PSOs on bind.
HRESULT parse_console_or_pc_stream(const D3D12_PIPELINE_STATE_STREAM_DESC& source, PipelineStream& stream,
bool console_first = false) {
// The console entry points (Xbox CreatePipelineState, slot 86) are handed console-numbered streams: read those
// with the console's numbering first, and only fall back to the PC reading when that does not hold a mesh.
if (console_first && console_stream_enum_enabled()) {
PipelineStream console;
if (SUCCEEDED(parse_pipeline_stream(source, console, true)) && !console.as.pShaderBytecode &&
is_mesh_container(console.ms)) {
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;
stream = console;
return S_OK;
}
}
const HRESULT parsed = parse_pipeline_stream(source, stream);
if (!(FAILED(parsed) || (stream.as.pShaderBytecode && !stream.ms.pShaderBytecode)) ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: when console_first == true, if the initial console parse above did not match a console mesh stream and the fallback PC parse fails (or yields AS without MS), this block runs the exact same parse_pipeline_stream(source, console, true) a second time. Guarding this fallback block with if (console_first || ...) / skipping it when console_first is already true (and clearing d3d12_trace::stream_refusal = nullptr; before the PC parse at line 46 so a failed console_first probe cannot leave a stale refusal string on a successful PC parse) would keep both paths tidy.

!console_stream_enum_enabled())
return parsed;
const char* pc_reason = d3d12_trace::stream_refusal;
PipelineStream console;
if (SUCCEEDED(parse_pipeline_stream(source, console, true)) && !console.as.pShaderBytecode &&
is_mesh_container(console.ms)) {
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;
stream = console;
return S_OK;
}
d3d12_trace::stream_refusal = pc_reason;
return parsed;
}

// A fresh public PSO has its own COM identity, private data and name. Equal native descriptions can
// hold one compiled backend PSO while either public object lives. The device only holds weak references.
HRESULT prepare_console_stream(const D3D12_PIPELINE_STATE_STREAM_DESC& source, REFIID iid, void** out,
std::unique_ptr<rt::d3d12_xs::PsoStreamRecord> record) {
if (!out)return E_POINTER;*out=nullptr;
PipelineStream stream{};
if(const auto hr=parse_pipeline_stream(source,stream);FAILED(hr))return hr;
if(const auto hr=parse_console_or_pc_stream(source,stream,true);FAILED(hr))return hr;
const auto* library=state_.library();if(!library)return E_FAIL;
const auto verify=[&](const char* name,const D3D12_SHADER_BYTECODE& code) {
if(!code.BytecodeLength)return true;
Expand All @@ -15359,9 +15398,10 @@ class Device final
const auto& g=stream.graphics;
if(stream.as.BytecodeLength || g.HS.BytecodeLength || g.DS.BytecodeLength)return E_NOTIMPL;
if((bool(g.VS.BytecodeLength)==bool(stream.ms.BytecodeLength)) || g.NumRenderTargets>8 ||
!verify("vs",g.VS)||!verify("gs",g.GS)||!verify("ms",stream.ms)||!verify("ps",g.PS))return E_INVALIDARG;
!verify("vs",g.VS)||!verify("gs",g.GS)||!verify("ms",stream.ms)||!verify("ps",g.PS))
return E_INVALIDARG;
}
if(!record) record=rt::d3d12_xs::PsoStreamRecord::capture(source);
if(!record) record=rt::d3d12_xs::PsoStreamRecord::capture(source, d3d12_xs::used_console_stream);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d3d12_xs::used_console_stream is a thread_local bool (d3d12_xs_pso_stream.h:30), and in create_pso_from_stream() (d3d12_xs_device.cpp:6113-6116) the self->prepare_stream path returns before used_console_stream = false;. Because neither prepare_console_stream() nor parse_console_or_pc_stream() resets d3d12_xs::used_console_stream = false; on entry, once a thread prepares a console-numbered mesh PSO, used_console_stream stays true for subsequent PC-numbered PSOs on that thread.

On the next PC-numbered stream with record == nullptr, PsoStreamRecord::capture(source, true) shifts tags >= 23 via pc_stream_type(raw, true) (MS 25 --> DEPTH_STENCIL2 26, DEPTH_STENCIL2 26 --> RASTERIZER1 27, RASTERIZER1 27 --> RASTERIZER2 28, RASTERIZER2 28 --> unknown 29), causing PsoStreamRecord::walk() to fail and prepare_console_stream() to return E_INVALIDARG for a valid PC stream. d3d12_mesh_on_demand currently misses this because all valid PC-numbered streams in d3d12_mesh_test.cpp are created before the console-numbered loop.

Resetting d3d12_xs::used_console_stream = false; at the start of parse_console_or_pc_stream() (and adding a PC-numbered mesh/RASTERIZER2 creation check after the console loop in d3d12_mesh_test.cpp) would fix and cover this.

if(!record)return E_INVALIDARG;
auto* pipeline=new PipelineState(state_);
pipeline->attach_device(identity());
Expand Down Expand Up @@ -17580,26 +17620,7 @@ class Device final
*out = nullptr;
if (!desc) return finish(E_INVALIDARG);
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
// console's numbering (parse_pipeline_stream), and that reading is taken when it holds a mesh shader (its 24)
// and no AS. A stream the PC reading accepts as valid is never read differently. LEONIDA_XS_STREAM_ENUM=pc
// keeps the PC reading alone (such PSOs are then refused, as before).
if ((FAILED(parsed) || (stream.as.pShaderBytecode && !stream.ms.pShaderBytecode)) &&
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)) {
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;
stream = console;
parsed = S_OK;
} else {
d3d12_trace::stream_refusal = pc_reason;
}
}
const HRESULT parsed = parse_console_or_pc_stream(*desc, stream);
if (FAILED(parsed)) return finish(parsed);
auto* pipeline = new PipelineState(state_);
pipeline->attach_device(identity());
Expand Down
Loading