KhronosGroup / KhronosGroup/SPIRV-Cross

Support multiple SPIR-V modules compiled together into one MSL shader

Open
#719 11 comments 0 reactions 0 assignees View on GitHub
enhancement Portability Initiative
Dominant language
GLSL
Stars
2.5k
Forks
713
Avg merge
2d 18h
Merged PRs (30d)
16

Description

This is unfortunately necessary for #120. Tessellation works differently in Metal vs. Vulkan (and D3D). In Vulkan, two shader stages (tessellation control and tessellation evaluation) and a fixed function stage (tessellation proper) are inserted between the vertex shader and rasterization (or the geometry shader, if present). In Metal, however, the vertex and tess. control stages are omitted entirely. Instead, you are expected to run a compute shader that populates the buffer(s) used by the tessellator. The tess. evaluation stage is then run as a "post-tessellation vertex function." Therefore, for Vulkan->Metal translation, as MoltenVK is doing, the vertex shader and tess. control shader must be compiled together into one Metal compute kernel, which is responsible for running the original vertex and tess. control functions and using their output to populate the tessellation input buffers. (See also [Apple's guidance for porting D3D11 shaders to Metal](https://developer.apple.com/library/archive/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/Tessellation/Tessellation.html#//apple_ref/doc/uid/TP40014221-CH15-DontLinkElementID_51).)

Geometry shaders are another place where this may be necessary, since Metal does not yet support them natively. The geometry shader must thus run as a compute kernel, feeding its output through a buffer and a pass-through vertex shader to the rasterizer. But the original vertex shader must run prior to the geometry shader. If the original vertex shader and geometry shader (assuming no tessellation) were run normally, it would require one render pipeline with `rasterizationDisabled`, followed by a compute pipeline running the geometry shader, followed by yet another render pipeline for the rest of the rendering process. (And indeed, this is what we'll likely end up doing for combined geometry and tessellation shaders.) But if the vertex and geometry shaders were combined into one compute kernel, the first render pipeline could be omitted (along with a buffer needed to hold the output of the vertex shader to pass to the geometry shader).

Contributor guide

No contributing guide indexed for this repository

Research direction

Begin with issue #120 and Apple's linked tessellation guidance, then compare the Vulkan stage model with Metal's compute and post-tessellation model. Done means SPIR-V-Cross can compile the relevant multiple modules into a single MSL shader, covering the vertex and tessellation case described here and accounting for the geometry-shader case.

Written by the indexing model from the issue text.

Assessment

Domain
compilers, computer-graphics
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.