Skip to content

d3d12: the deferred path reads console streams with the console's numbering (CONSOLE-STREAM-ON-DEMAND-REREAD) - #2292

Open
star41905453-coder wants to merge 1 commit into
ProjectLeonida:mainfrom
star41905453-coder:console-stream-on-demand
Open

star41905453-coder wants to merge 1 commit into
ProjectLeonida:mainfrom
star41905453-coder:console-stream-on-demand

Conversation

@star41905453-coder

Copy link
Copy Markdown
Contributor

With LEONIDA_PIPELINE_COMPILE=on-demand every PSO from a console-numbered stream is refused, and this is the switch a title with console PSOs needs.

prepare_console_stream — the deferred entry point Xbox CreatePipelineState uses when a device prepares PSOs on bind — parsed the stream with PC numbering and returned before the console re-read that the eager path does, so a console type 24 arrived as an AS and answered E_NOTIMPL. The record capture right after had the same fault one level down: it walked the stream as a PC one, found no console subobject and gave E_INVALIDARG — the case the rasterizer subobject in d3d12_mesh_test hits.

What changes:

  • one helper, parse_console_or_pc_stream, used by both entry points. The deferred one is handed console streams, so it reads console-first and falls back to the PC reading; the eager one keeps its existing PC-first rule, so a stream the PC reading accepts is never read differently.
  • the record is captured with the numbering actually taken, instead of always as a PC stream. Slot 55 (derive) needs that record.

Out of scope but worth knowing: on-demand also exercises the depth-bounds extras path, so this and #2234 meet.

Test — the existing console-stream step of d3d12_mesh_test now also runs under the switch, as d3d12_mesh_on_demand (new ctest). On main it stops at SUCCEEDED(console_hr) with the refusal; with this it passes, both console streams created, and the derived PSO through slot 55 still works.

Run: d3d12_mesh and d3d12_mesh_on_demand both pass here; the wider group (write_back, title_va, geometry_views, compute) passes.

Item: CONSOLE-STREAM-ON-DEMAND-REREAD, claimed in #1608.

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 26, 2026
…bering (CONSOLE-STREAM-ON-DEMAND-REREAD)

With LEONIDA_PIPELINE_COMPILE=on-demand every PSO from a console-numbered
stream was refused with E_NOTIMPL: prepare_console_stream parsed the stream with
PC numbering and returned before the console re-read CreatePipelineState does,
so a console type 24 arrived as an AS. The record capture that follows had the
same fault - it walked the stream as a PC one, found no console subobject and
gave E_INVALIDARG, which is what the rasterizer subobject case hit.

Both parsers now share one helper. It reads console-first where the stream is
known to be the console's (the deferred entry point, which is handed console
streams by Xbox CreatePipelineState) and keeps the PC-first rule elsewhere, so a
PC stream is never read differently. The record is captured with the numbering
that was actually taken, which is what slot 55 needs to derive from these PSOs.

Test: the console-stream step of d3d12_mesh_test now runs under
LEONIDA_PIPELINE_COMPILE=on-demand as its own ctest (d3d12_mesh_on_demand); on
main it stops there with the refusal above.
@star41905453-coder
star41905453-coder marked this pull request as ready for review November 27, 2026 03:25
@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 27, 2026

@lixonik lixonik left a comment

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.

Reviewed and locally tested at 7d23021d6 (merged cleanly onto main ec91d695c).

Verification

  • Environment: Windows 11, MSVC 19.44, NVIDIA GeForce RTX 5070 (driver 610.88, Vulkan 1.4.341; VK_LAYER_KHRONOS_validation not installed locally).
  • ctest: pso_stream, d3d12_mesh, d3d12_mesh_on_demand, and d3d12_mesh_heavy_cache all passed (4/4).
  • scripts/check_no_game_data.py and git diff --check: clean.

Findings

  • Found one thread-local state bug on the deferred (prepare_console_stream) path: d3d12_xs::used_console_stream is not reset to false before parse_console_or_pc_stream, so preparing a PC-numbered stream on the same thread after a console-numbered mesh PSO passes stale console = true to PsoStreamRecord::capture() (details inline). Also noted a redundant console re-parse when console_first == true.

AI-assisted.

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.

}
}
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.

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.

2 participants