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 from upstream-pr/2292 into main
star41905453-coder commented 2026-11-26 12:52:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by star41905453-coder on 2026-11-26T12:52:18Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5510361172 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2292). Originally posted by [star41905453-coder](https://github.com/star41905453-coder) on 2026-11-26T12:52:18Z. --- 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.
lixonik commented 2026-11-27 15:48:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T15:48:22Z.

Code review location: runtime/shims/d3d12_vulkan_device.cpp; line 15404

@@ -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);

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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4721343867 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2292#discussion_r4721343867). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-27T15:48:22Z. **Code review location:** `runtime/shims/d3d12_vulkan_device.cpp`; line 15404 ~~~~diff @@ -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); ~~~~ --- `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.
lixonik commented 2026-11-27 15:48:22 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T15:48:22Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6090573267 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2292#pullrequestreview-6090573267). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-27T15:48:22Z. **Review:** COMMENTED --- 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.
lixonik commented 2026-11-27 15:48:23 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-27T15:48:23Z.

Code review location: runtime/shims/d3d12_vulkan_device.cpp; line 15356

@@ -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)) ||

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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4721343874 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2292#discussion_r4721343874). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-27T15:48:23Z. **Code review location:** `runtime/shims/d3d12_vulkan_device.cpp`; line 15356 ~~~~diff @@ -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)) || ~~~~ --- 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.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2292:upstream-pr/2292'
git switch 'upstream-pr/2292'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2292'
git switch 'upstream-pr/2292'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2292'
git switch 'upstream-pr/2292'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2292'
git switch 'main'
git merge --squash 'upstream-pr/2292'
git switch 'main'
git merge --ff-only 'upstream-pr/2292'
git switch 'main'
git merge 'upstream-pr/2292'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2292
No description provided.