Skip to content

Add explicit FLOAT32, INT32, and UINT32 to MSLShaderVariableFormat#2639

Open
alexdremov wants to merge 1 commit into
KhronosGroup:mainfrom
alexdremov:dtypes
Open

Add explicit FLOAT32, INT32, and UINT32 to MSLShaderVariableFormat#2639
alexdremov wants to merge 1 commit into
KhronosGroup:mainfrom
alexdremov:dtypes

Conversation

@alexdremov

@alexdremov alexdremov commented Jun 6, 2026

Copy link
Copy Markdown

This PR addresses failures in MoltenVK:

[mvk-error] VK_ERROR_INITIALIZATION_FAILED: Render pipeline compile failed (Error code 3):
   Fragment input(s) `user(locn10)` mismatching vertex shader output type(s) or not written by vertex shader.

MSLShaderVariableFormat previously only supported ANY32, forcing to default to UInt. This causes a Metal compiler crash (invalid return type or mismatching type) if the fragment shader actually expects a float input. By introducing explicit 32-bit types, MoltenVK can instruct SPIRV-Cross on the exact data type to use.

  • Added MSL_SHADER_VARIABLE_FORMAT_FLOAT32, INT32, and UINT32 to the MSLShaderVariableFormat enum and the corresponding SPVC_MSL_SHADER_VARIABLE_FORMAT_* C-API definitions.
  • Relaxed the dummy output generation condition in add_interface_block() to no longer strictly require capture_output_to_buffer. Previously, SPIRV-Cross would only generate missing interface variables if the pipeline was explicitly capturing output. This prevented MoltenVK from padding StageOut structs in standard rasterization pipelines, leading to linker failures when a Fragment shader expected an input that the Vertex shader didn't explicitly write.
  • Replaced the capture_output_to_buffer requirement with get_entry_point().model != ExecutionModelFragment. This ensures that dummy output generation safely applies to all standard Vertex, Geometry, and Tessellation stages to satisfy downstream Metal linkers, while strictly preventing generic [[user(locn)]] variables from being illegally injected into the return structs of Fragment shaders.

AI use disclosure:
I am not a computer graphics expert and AI was used to help debug and prepare fixes for this issue. I confirm that I have manually tested this and a scene that was crashing before in "Detroit: Become Human" is not crashing after this fix.

@CLAassistant

CLAassistant commented Jun 6, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@alexdremov alexdremov marked this pull request as ready for review June 6, 2026 00:43
Comment thread spirv_msl.cpp
}

if (capture_output_to_buffer && storage == StorageClassOutput)
if (storage == StorageClassOutput && get_entry_point().model != ExecutionModelFragment)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

maybe is_vertex_like_shader() can be used here, I am not sure

@cdavis5e

cdavis5e commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

This seems awfully familiar...

@alexdremov

Copy link
Copy Markdown
Author

This seems awfully familiar...

Hey! Seems like you have linked this PR. Perhaps you meant something else.

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.

3 participants