Skip to content

Runtime: link sparse mesh varyings at graphics pipeline creation (BUILD-1463) - #4954

Closed
jeremygold02 wants to merge 10 commits into
ProjectLeonida:mainfrom
jeremygold02:codex/runtime-mesh-ps-link
Closed

jeremygold02 wants to merge 10 commits into
ProjectLeonida:mainfrom
jeremygold02:codex/runtime-mesh-ps-link

Conversation

@jeremygold02

@jeremygold02 jeremygold02 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

BUILD-1463

The native mesh pipeline first reviewed in #1712 is present on main through #2359. The current diff against f4cd3061 contains seven linkage and test files. Linkage diff | Claim

An ordinary mesh pipeline can compile successfully and still interpolate the wrong value. The translator numbers fragment attributes densely, while the mesh keeps native export numbers. When the fragment skips an export, two compatible vec4 outputs can both satisfy Vulkan's type check.

At CreatePipelineState the submitted mesh and fragment programs identify the pair. This change reads their existing FSSM tables, cross-checks both translated interfaces and edits only the fragment input Location operands for this PSO. It supports direct vec4 and PerVertexKHR triangle-array inputs. Other pipelines sharing the fragment still receive their own original words. The offline utility remains independently usable. Offline linker

Verification

At 333ae0fb, both the CPU linkage test and the normal D3D12 mesh draw passed after a one-worker MSVC 19.44 rebuild. The synthetic mesh and vertex draws shared a pixel shader and matched all 4,096 pixels on the NVIDIA GeForce RTX 5070 (621.01, subgroup 32). The upstream pipeline-statistics assertions also ran and passed. Host: Intel Core Ultra 7 265K, Windows 11 Home 25H2.

The new 64×64 synthetic fixture submits two graphics pipeline streams through the normal D3D12 device. The mesh writes distinct colors at locations 0 and 1. Its pixel shader requests the second export. The VS pipeline then reuses that pixel shader and supplies its color at location 0.

  • Native Windows, Intel Core Ultra 7 265K, NVIDIA GeForce RTX 5070 driver 621.01, subgroup 32, Windows 11 Home 25H2 build 26200.9974. On Runtime: mesh-shader PSOs from pipeline state streams and DispatchMesh (D3D-29) #1712 with this fixture and the unchanged runtime, 1,536 of 4,096 pixels differed (first pixel magenta instead of red, exit 1). With the runtime at effca4a28b94b8c7d4234794f2d06750ac8cdb32, all 4,096 pixels matched (exit 0): 1,024 red and 512 green mesh pixels, 1,024 yellow VS-control pixels and 1,536 clear blue pixels. The three shader binaries had identical hashes for the two runs and all three passed Vulkan 1.3 SPIR-V validation. The runtime was built with MSVC 19.44 and CMake 3.31.6 in RelWithDebInfo.
  • All 11 CPU controls passed a native MSVC 14.44 C++20 build with /W4. They cover a sparse map, a render target sharing an input's original location, identity, malformed/contradictory rows, unsupported types, a dense permutation, repeated linkage, and a mix of ordinary and vertex-indexed inputs. The hand-written mesh, original mixed fragment, linked mixed fragment, and undecorated-array negative all passed spirv-val --target-env vulkan1.2.
  • In two locally retained reference pairs, the runtime helper reproduced the independent offline linker's output byte for byte. Each fragment required a single byte change. These were CPU comparisons. All fixtures in the PR are synthetic.

Run ctest --test-dir <build> -C RelWithDebInfo -R "^(spirv_mesh_inputs|d3d12_mesh)$" --output-on-failure with Vulkan headers, glslang and a mesh-capable GPU. This change covers native MeshEXT graphics pipeline creation. Compute fallback and decoded-half placement have separate interfaces.

AI-assisted by GPT-6.2 Astra.

LloydNicholson and others added 4 commits November 23, 2026 06:17
…h (D3D-29)

The device enables VK_EXT_mesh_shader (meshShader) where the GPU has it
and reports MeshShaderTier 1 only then.

ID3D12Device2::CreatePipelineState parses pipeline state streams in the
d3dx12.h layout into the descriptions the existing PSO creators take, with
the runtime's defaults for missing subobjects. Streams the PC runtime
refuses are E_INVALIDARG; AS, depth bounds, split stencil masks and view
instancing are E_NOTIMPL with a log.

A mesh PSO is MS + PS with no vertex input or input assembly, and no
dynamic topology or strides. Its output sizes and workgroup are checked
against VkPhysicalDeviceMeshShaderPropertiesEXT.

DispatchMesh records a Draw with mesh set and replays as
vkCmdDrawMeshTasksEXT; a draw of the wrong kind for its pipeline fails
with ReplayResult::invalid_draw.

d3d12_mesh_test covers the refusals and checks a 2x2x1 and a 1x1x2 mesh
grid plus a VS PSO from a stream, pixel by pixel.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ates; mesh test skips without Vulkan

The stream parser keyed its duplicate check on the raw subobject type, so DEPTH_STENCIL with DEPTH_STENCIL1
(either order) or RASTERIZER with RASTERIZER2 was accepted; D3D12_PIPELINE_STATE_STREAM_DESC counts versions of
one subobject as the same one. The check now uses the base type, while the payload still follows the original
type. d3d12_mesh_test covers both mixed orders, RASTERIZER + RASTERIZER2, and each description alone.
Reported by Vonsek in review.

d3d12_mesh_test failed on a machine without a Vulkan device (the Windows CI runner) instead of exiting 77; it
now skips there like d3d12_draw_test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use both submitted FSSM tables and translated interface declarations to connect dense fragment inputs to native mesh exports. Keep the fragment module local to its pipeline and cover shared-fragment draws and unsupported layouts.

Refs: ProjectLeonida#1712, ProjectLeonida#4816
A PerVertexKHR triangle array consumes the location of one vec4. Recognize this shape alongside ordinary inputs and keep plain arrays outside the supported mapping.

Refs: ProjectLeonida#1712, ProjectLeonida#4816
@tupacfan04

Copy link
Copy Markdown
Contributor

Independent Windows/Vulkan check at effca4a28b94b8c7d4234794f2d06750ac8cdb32 (the two commits after dependency 9c4bff42).

Environment: Windows 11 build 26300, MSVC 19.51.36260.0, NVIDIA GeForce RTX 5070 driver 621.24, Vulkan SDK 1.4.363.0, RelWithDebInfo, Vulkan validation enabled.

  • Built d3d12_mesh_test and spirv_mesh_inputs_test from runtime with -DBUILD_TESTING=ON; both link and exit 0.
  • d3d12_mesh_test: mesh tier 1; 9 PSOs refused as invalid and 2 as not implemented; the sparse mesh input and the shared-PS vertex draw matched all 4,096 pixels; wrong-kind draws failed at execution and oversized grids at Close. This is the same result the PR body reports, independently reproduced.
  • Re-ran the mesh test with LEONIDA_VK_VALIDATION=1: device line says NVIDIA GeForce RTX 5070 (validation on), exit 0, no VUID/validation errors in the log.
  • spirv_mesh_inputs_test: exit 0.

Non-blocking: the test-only Subobject<D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_DEPTH_STENCIL1/RASTERIZER2> template produces two /W4 C4324 alignment-padding warnings (runtime/test/d3d12_mesh_test.cpp:45); the runtime sources build clean.

No game data; synthetic shaders and pixels only. AI-assisted.

@whattheflop whattheflop 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.

Independent Windows CPU verification, AI-assisted. The exact #1712 dependency and this head each dry-merged cleanly with 3faac557. MSVC 19.38 built spirv_mesh_inputs_test. In a separate valid synthetic harness, linking fresh copies of one fragment in A → B → A order remapped its input locations to (4, 2), (3, 5), and (4, 2). All three matched independently assembled expected modules. Exactly two words changed per call; render targets, FragCoord, the original fragment and the first linked result stayed intact. All eight modules passed spirv-val for Vulkan 1.2.

One docs detail: the runtime guide can mention that a nonidentity dense permutation is refused even when the tables agree, because its occupied location set cannot distinguish an already-linked interface. This check used no GPU or game inputs.

@SphyserX

Copy link
Copy Markdown

Linux check of effca4a (Arch, in a VM, GCC, Ninja, RelWithDebInfo, Mesa llvmpipe): the runtime builds, and the full Linux CTest passes 51 of 51, including the new spirv_mesh_inputs test. d3d12_mesh_test isn't registered on Linux, so the end-to-end mesh/pixel case still rests on the Windows runs. Diff read for build-time side effects: the only new add_custom_command compiles test/glsl/ms_draw.mesh with glslang.

@tupacfan04

Copy link
Copy Markdown
Contributor

Non-blocking addendum after reading the rest of the diff (tests and GPU result above still stand):

  • runtime/src/spirv_mesh_inputs.h:130 rejects a genuine dense permutation such as 0<->1, where every location is present but in a different row; the error says the table is "not dense". If that spelling is legal in a DXIL/SPIR-V input signature, the guard should key on set equality, not on location == row.
  • :108 hard-codes row offsets 0x1dc/0x29c and a 6-byte row without a corpus or doc citation, so the layout cannot be re-derived by a reviewer.
  • :119 treats byte 3 as the table position, while docs/design.md:538 calls it the per-semantic index. Worth reconciling before this becomes the reference.

The branch also carries #1712 (4 commits, 1,251 insertions); the PR diff is only the last commit.

AI-assisted review, no game data.

@Atomic258

Copy link
Copy Markdown
Contributor

Independent check of effca4a2 — pass on NVIDIA hardware, the check this PR most needed.

Environment: Windows 11, MSVC 19.44 (RelWithDebInfo, Ninja), NVIDIA GeForce RTX 5090 (driver 617.42), Vulkan SDK 1.4.363.0, LEONIDA_VK_DEVICE="rtx 5090", LEONIDA_VK_VALIDATION=1. Synthetic mesh fixture (ms_draw.mesh), no game files.

Built d3d12_mesh_test + spirv_mesh_inputs_test targets only — all compile/link clean (only pre-existing C4324 padding warnings in the test's Subobject<> helper).

d3d12_mesh_test.exe on the 5090 with validation layers on → exit 0, zero failures. Result line:

mesh tier 1; mesh and VS PSOs from pipeline state streams (9 refused as invalid, 2 as not implemented); sparse mesh input and a shared-PS vertex draw matched all 4096 pixels; wrong-kind draws fail at execution, oversized grids at Close

So sparse (vertex-indexed) fragment inputs now link at pipeline creation and rasterize correctly on the newest NVIDIA arch — previously the varyings were dropped/unbound. The wrong-kind-draw and oversized-grid refusal paths also verified live.

Not run: negative control — the change is header-coupled across d3d12_com/vulkan_* so the PR's test doesn't compile against the parent's headers; a source-swap rebuild wasn't practical for a targeted check.

AI-assisted (Devin).

@Exopus-0x65f7ad0

Exopus-0x65f7ad0 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested effca4a2 on Windows 11 (26300), RTX 5060 Ti / 621.14, MSVC 14.51 (VS 2026), Vulkan SDK 1.4.363.0, RelWithDebInfo, clean build with -DLEONIDA_LLVM_MC. Full LEONIDA_VK_VALIDATION=1 ctest -j4: 165/165 pass, 0 VUIDs, including d3d12_mesh (the new location-remap fixture) and spirv_mesh_inputs. So the validation layer's interface checks also accept the pipeline built with the remapped fragment input Locations on this card.

AI-assisted (Claude Code). Synthetic data only, no game files.

LloydNicholson and others added 2 commits November 23, 2026 13:41
…h (D3D-29)

The device enables VK_EXT_mesh_shader (meshShader) where the GPU has it
and reports MeshShaderTier 1 only then.

ID3D12Device2::CreatePipelineState parses pipeline state streams in the
d3dx12.h layout into the descriptions the existing PSO creators take, with
the runtime's defaults for missing subobjects. Streams the PC runtime
refuses are E_INVALIDARG; AS, depth bounds, split stencil masks and view
instancing are E_NOTIMPL with a log.

A mesh PSO is MS + PS with no vertex input or input assembly, and no
dynamic topology or strides. Its output sizes and workgroup are checked
against VkPhysicalDeviceMeshShaderPropertiesEXT.

DispatchMesh records a Draw with mesh set and replays as
vkCmdDrawMeshTasksEXT; a draw of the wrong kind for its pipeline fails
with ReplayResult::invalid_draw.

d3d12_mesh_test covers the refusals and checks a 2x2x1 and a 1x1x2 mesh
grid plus a VS PSO from a stream, pixel by pixel.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ates; mesh test skips without Vulkan

The stream parser keyed its duplicate check on the raw subobject type, so DEPTH_STENCIL with DEPTH_STENCIL1
(either order) or RASTERIZER with RASTERIZER2 was accepted; D3D12_PIPELINE_STATE_STREAM_DESC counts versions of
one subobject as the same one. The check now uses the base type, while the payload still follows the original
type. d3d12_mesh_test covers both mixed orders, RASTERIZER + RASTERIZER2, and each description alone.
Reported by Vonsek in review.

d3d12_mesh_test failed on a machine without a Vulkan device (the Windows CI runner) instead of exiting 77; it
now skips there like d3d12_draw_test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The parent pipeline was rebased upstream. The first parent carries the verified seven-file change on the refreshed dependency.

Refs: ProjectLeonida#4954
Verify the sparse mesh input and shared vertex-stage pixel shader while retaining main's query checks around the same draws.

Refs: ItsNotRexed#2359, ItsNotRexed#4954
@thehollowedone

Copy link
Copy Markdown

Independent Windows check of 333ae0fb. RTX 3080 Ti, NVIDIA 621.35, MSVC 19.44, Vulkan SDK 1.4.363.0.

In the focused d3d12_mesh fixture, the mesh draw used its sparse varying and the vertex draw reused the same pixel shader. All 4,096 pixels matched the expected colors, including the vertex control and untouched background. Khronos core and synchronization validation reported zero errors. The run covered the two rendering cases with the published runtime.

AI-assisted.

@kapitche

Copy link
Copy Markdown
Collaborator

Tested 333ae0f merged with main 8575d36 on Linux (WSL2) / Python 3.12.16, g++ (C++20): pass
Real merge is clean (auto-merged docs/d3d12_vulkan.md, runtime/CMakeLists.txt, runtime/shims/d3d12_vulkan_device.cpp); git diff --check clean.
I compiled runtime/test/spirv_mesh_inputs_test.cpp on its own with g++ -std=c++20 -Wall -Wextra (no warnings) and it exits 0. I did not build the runtime, d3d12_mesh_test or run any GPU test; the Vulkan/D3D12 side needs Windows.
Mutation controls on runtime/src/spirv_mesh_inputs.h: disabling the by_key[keys[i]] != slots[i] check makes the test fail ("line 127: verify(mesh, broken, false, original)", exit 1). Disabling the entry-point-name check (ins[3] != 0x6e69616du || ins[4] != 0) does not fail it: the fixtures only use the entry name main, so a module with another entry name is untested. Not blocking.
Restored the header afterwards.

@fuzeofficlal

Copy link
Copy Markdown

Independent native Windows GPU check of 333ae0fb on RTX 5090 (616.56) and Radeon integrated graphics (32.0.21042.62). The CPU linkage test passed, and all three synthetic SPIR-V modules validated. AI-assisted (Codex).

I used the same three shader binaries and the same test object with the exact PR and dde82f27 runtime builds. In the scratch fixture I moved the existing pixel comparison ahead of the fail-fast statistics assertions. Both adapters matched 4,096/4,096 pixels on the PR. Both matched 2,560/4,096 on main. All 1,536 differences were in the two mesh regions. The shared-fragment vertex control and clear region matched on both.

The original full test also hits VUID-07076 on both adapters and the mixed-statistics assertion on Radeon. Unmodified main reproduces both. Clipping-statistics fix #7112 · AMD statistics assertion fix #7256

@fuzeofficlal

Copy link
Copy Markdown

Combined validation follow-up on native Windows 11 with RTX 5090 (616.56) and Radeon gfx1036 (32.0.21042.62). The original, un-reordered pixel comparison now passes together with the statistics assertions.

I started at #4954 333ae0fb, applied the patch deltas from #7112 9e9bb637 and #7256 e83aa4e6 in that order, and reconciled their overlapping test assertions so both the feature-conditional clipping check and the mixed-versus-vertex invocation comparison run. No other changes were made. The three mesh-test SPIR-V binaries are byte-identical to the exact #4954 build.

  • Both adapters passed 4/4 (spirv_mesh_inputs, d3d12_mesh, replay_query_edges, replay_query_predication), with Khronos core and synchronization validation 1.4.369, zero errors and no skips. Both matched 4,096/4,096 pixels.
  • Radeon reported mixed/vertex-only GS counts of 2/2 and mesh-only clipping 0/0 (meshShaderQueries=false). NVIDIA reported GS 0/0 and mesh-only clipping 8/8.

AI-assisted (Codex). Synthetic inputs.

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.