d3d12_xs: match mesh PSO primitive topology to PSV0 and drop empty legacy stages #176

Closed
github-bot wants to merge 1 commit from gh-pr/176/head into gh-pr/176/base
Owner

@⁠GDAgent on GitHub · 2026-11-22 18:08 UTC · original
GDAgent:fix/d3d12-mesh-pso-drop-topology → main · +169 −3 · 1 files · 1 commits · closed without merging

Library / area: d3d12_xs (mesh_pso.rs)

Exports changed (exports.txt rows): none

Source of the behaviour: console mesh shader PSO streams frequently carry subobject 14 (D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY) set to 0 (D3D12_PRIMITIVE_TOPOLOGY_TYPE_UNDEFINED), omit it altogether, or include empty (null bytecode) legacy VS/HS/DS/GS subobjects alongside SUB_MS. On PC D3D12, ID3D12Device2::CreatePipelineState fires D3D12 error #673 (CreateMeshShader_TopologyMismatch) if PRIMITIVE_TOPOLOGY is omitted/0 rather than matching the mesh shader's PSV0 output topology.

Changes:

  • Add mesh_dxil_topology to read PSV0 MeshInfo::topology (1 -> LINE = 2, 2 -> TRIANGLE = 3) via tombox_xshader::meta::parse_psv0_mesh.
  • In mesh_pso::translate_stream:
    • drop empty (null pointer or zero length) VS/HS/DS/GS subobjects when SUB_MS is present;
    • overwrite an existing SUB_PRIMITIVE_TOPOLOGY (14) or append one when SUB_MS provides a PSV0 topology (and drop SUB_PRIMITIVE_TOPOLOGY if no PSV0 topology is available), while keeping SUB_PRIMITIVE_TOPOLOGY untouched on non-mesh graphics streams.
  • In mesh_pso::create_pipeline_state, log a compact subobject summary (subs=[ty:w0,...]) when the PC driver rejects a stream.
  • Expand unit test mesh_stream_sets_primitive_topology_from_psv0_and_drops_empty_legacy_stages to cover SUB_PRIMITIVE_TOPOLOGY before SUB_MS, after SUB_MS, omitted, without PSV0, empty legacy stage removal, and vertex-shader passthrough.

Tests:

  • cargo test -p d3d12_xs mesh_pso: 7 passed, 0 failed.
  • Native Windows 11; not run under Proton.

Not verified in a title: verified by the unit tests above on main (and previously observed resolving D3D12 #673 on mesh PSOs in a local test run with a mesh-shader title).

  • cargo test -p d3d12_xs mesh_pso passes (7 passed)
  • No game or console files and no binaries included
  • No fake success; vertex-shader PSO streams keep subobject 14 untouched
**@⁠GDAgent** on GitHub · 2026-11-22 18:08 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/176) `GDAgent:fix/d3d12-mesh-pso-drop-topology` → `main` · +169 −3 · 1 files · 1 commits · closed without merging **Library / area:** d3d12_xs (`mesh_pso.rs`) **Exports changed (exports.txt rows):** none **Source of the behaviour:** console mesh shader PSO streams frequently carry subobject `14` (`D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_PRIMITIVE_TOPOLOGY`) set to `0` (`D3D12_PRIMITIVE_TOPOLOGY_TYPE_UNDEFINED`), omit it altogether, or include empty (null bytecode) legacy VS/HS/DS/GS subobjects alongside `SUB_MS`. On PC D3D12, `ID3D12Device2::CreatePipelineState` fires D3D12 error `#673` (`CreateMeshShader_TopologyMismatch`) if `PRIMITIVE_TOPOLOGY` is omitted/0 rather than matching the mesh shader's `PSV0` output topology. Changes: - Add `mesh_dxil_topology` to read `PSV0` `MeshInfo::topology` (`1` -> `LINE = 2`, `2` -> `TRIANGLE = 3`) via `tombox_xshader::meta::parse_psv0_mesh`. - In `mesh_pso::translate_stream`: - drop empty (null pointer or zero length) `VS`/`HS`/`DS`/`GS` subobjects when `SUB_MS` is present; - overwrite an existing `SUB_PRIMITIVE_TOPOLOGY (14)` or append one when `SUB_MS` provides a `PSV0` topology (and drop `SUB_PRIMITIVE_TOPOLOGY` if no `PSV0` topology is available), while keeping `SUB_PRIMITIVE_TOPOLOGY` untouched on non-mesh graphics streams. - In `mesh_pso::create_pipeline_state`, log a compact subobject summary (`subs=[ty:w0,...]`) when the PC driver rejects a stream. - Expand unit test `mesh_stream_sets_primitive_topology_from_psv0_and_drops_empty_legacy_stages` to cover `SUB_PRIMITIVE_TOPOLOGY` before `SUB_MS`, after `SUB_MS`, omitted, without `PSV0`, empty legacy stage removal, and vertex-shader passthrough. Tests: - `cargo test -p d3d12_xs mesh_pso`: 7 passed, 0 failed. - Native Windows 11; not run under Proton. **Not verified in a title:** verified by the unit tests above on `main` (and previously observed resolving D3D12 `#673` on mesh PSOs in a local test run with a mesh-shader title). - [x] `cargo test -p d3d12_xs mesh_pso` passes (7 passed) - [x] No game or console files and no binaries included - [x] No fake success; vertex-shader PSO streams keep subobject `14` untouched
On PC D3D12, ID3D12Device2::CreatePipelineState rejects a mesh shader PSO stream with E_INVALIDARG (error #673, CreateMeshShader_TopologyMismatch) when PRIMITIVE_TOPOLOGY (subobject 14) is UNDEFINED (0) or missing, instead of matching the mesh shader's declared output topology.

Extract the output topology from the mesh DXIL PSV0 chunk (MeshInfo::topology: 1=line -> LINE (2), 2=triangle -> TRIANGLE (3)) and populate or append SUB_PRIMITIVE_TOPOLOGY (14), drop empty VS/HS/DS/GS subobjects when SUB_MS is present, and log a compact subobject summary when the PC driver rejects a stream.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:12:51 +00:00
github-bot closed this pull request 2026-11-26 06:12:51 +00:00
Author
Owner

@⁠GDAgent on GitHub · 2026-11-22 18:45 UTC · original

Updated and rebased onto current main after testing against PC D3D12 validation (#673 CreateMeshShader_TopologyMismatch):

  • Simply dropping SUB_PRIMITIVE_TOPOLOGY (14) still leaves PC D3D12 defaulting it to UNDEFINED (0) and firing #673 on mesh PSOs. translate_stream now reads the mesh shader's DXIL PSV0 MeshInfo::topology (1 -> LINE (2), 2 -> TRIANGLE (3)) and populates or appends SUB_PRIMITIVE_TOPOLOGY (14) accordingly.
  • Drops empty (zero-ptr/zero-len) VS/HS/DS/GS subobjects when SUB_MS is present.
  • Logs a compact subs=[ty:w0,...] summary when the PC driver rejects a stream.
  • Updated unit tests to cover all ordering cases (before SUB_MS, after SUB_MS, omitted, no PSV0, empty legacy stages, and VS passthrough).

Ready for review!

**@⁠GDAgent** on GitHub · 2026-11-22 18:45 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/176#issuecomment-7083845994) Updated and rebased onto current `main` after testing against PC D3D12 validation (`#673` `CreateMeshShader_TopologyMismatch`): - Simply dropping `SUB_PRIMITIVE_TOPOLOGY (14)` still leaves PC D3D12 defaulting it to `UNDEFINED (0)` and firing `#673` on mesh PSOs. `translate_stream` now reads the mesh shader's DXIL `PSV0` `MeshInfo::topology` (`1` -> `LINE (2)`, `2` -> `TRIANGLE (3)`) and populates or appends `SUB_PRIMITIVE_TOPOLOGY (14)` accordingly. - Drops empty (zero-ptr/zero-len) `VS`/`HS`/`DS`/`GS` subobjects when `SUB_MS` is present. - Logs a compact `subs=[ty:w0,...]` summary when the PC driver rejects a stream. - Updated unit tests to cover all ordering cases (before `SUB_MS`, after `SUB_MS`, omitted, no `PSV0`, empty legacy stages, and VS passthrough). Ready for review!
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 18:48 UTC · original

Applied in 7047013 (merged in 190a4b3) with your authorship kept, thanks. #168 touches the same file and will be rebased onto this when it's updated.

**@⁠omonkeyz** on GitHub · 2026-11-22 18:48 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/176#issuecomment-7083883538) Applied in 7047013 (merged in 190a4b3) with your authorship kept, thanks. #168 touches the same file and will be rebased onto this when it's updated.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 18:53 UTC · original

Your updated version (PSV0 topology + dropping empty legacy stages, SUB_PRIMITIVE_TOPOLOGY fixed to 14) is applied in 7748afd (merged in 0d5f02a) with your authorship kept, thanks. The first version had already landed in 190a4b3; this one supersedes it. d3d12_xs lib tests pass (548/0).

**@⁠omonkeyz** on GitHub · 2026-11-22 18:53 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/176#issuecomment-7083948766) Your updated version (PSV0 topology + dropping empty legacy stages, SUB_PRIMITIVE_TOPOLOGY fixed to 14) is applied in 7748afd (merged in 0d5f02a) with your authorship kept, thanks. The first version had already landed in 190a4b3; this one supersedes it. d3d12_xs lib tests pass (548/0).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.