SPIRV-Cross/shaders-msl
Chip Davis aca9b6879a MSL: Support pull-model interpolation on MSL 2.3+.
New in MSL 2.3 is a template that can be used in the place of a scalar
type in a stage-in struct. This template has methods which interpolate
the varying at the given points. Curiously, you can't set interpolation
attributes on such a varying; perspective-correctness is encoded in the
type, while interpolation must be done using one of the methods. This
makes using this somewhat awkward from SPIRV-Cross, requiring us to jump
through a bunch of hoops to make this all work.

Using varyings from functions in particular is a pain point, requiring
us to pass the stage-in struct itself around. An alternative is to pass
references to the interpolants; except this will fall over badly with
composite types, which naturally must be flattened.  As with
tessellation, dynamic indexing isn't supported with pull-model
interpolation. This is because of the need to reference the original
struct member in order to call one of the pull-model interpolation
methods on it. Also, this is done at the variable level; this means that
if one varying in a struct is used with the pull-model functions, then
the entire struct is emitted as pull-model interpolants.

For some reason, this was not documented in the MSL spec, though there
is a property on `MTLDevice`, `supportsPullModelInterpolation`,
indicating support for this, which *is* documented. This does not appear
to be implemented yet for AMD: it returns `NO` from
`supportsPullModelInterpolation`, and pipelines with shaders using the
templates fail to compile. It *is* implemeted for Intel. It's probably
also implemented for Apple GPUs: on Apple Silicon, OpenGL calls down to
Metal, and it wouldn't be possible to use the interpolation functions
without this implemented in Metal.

Based on my testing, where SPIR-V and GLSL have the offset relative to
the pixel center, in Metal it appears to be relative to the pixel's
upper-left corner, as in HLSL. Therefore, I've added an offset 0.4375,
i.e. one half minus one sixteenth, to all arguments to
`interpolate_at_offset()`.

This also fixes a long-standing bug: if a pull-model interpolation
function is used on a varying, make sure that varying is declared. We
were already doing this only for the AMD pull-model function,
`interpolateAtVertexAMD()`; for reasons which are completely beyond me,
we weren't doing this for the base interpolation functions. I also note
that there are no tests for the interpolation functions for GLSL or
HLSL.
2020-11-05 11:57:45 -06:00
..
amd MSL: Support the SPV_AMD_shader_trinary_minmax extension. 2019-07-13 16:43:57 -05:00
asm MSL: Support pull-model interpolation on MSL 2.3+. 2020-11-05 11:57:45 -06:00
comp MSL: Support atomic access to images from argument buffers. 2020-10-13 02:37:18 -05:00
desktop-only MSL: Add support for processing more than one patch per workgroup. 2020-07-23 17:59:54 -05:00
flatten Use declared binding in SPIR-V as a fallback for explicit MSL binds. 2018-04-04 12:25:11 +02:00
frag MSL: Allow Bias and Grad arguments with comparison on Mac in MSL 2.3. 2020-10-30 11:14:59 -05:00
intel MSL: Support the SPV_INTEL_shader_integer_functions2 extension. 2019-07-15 09:42:36 -05:00
legacy/vert Enhance MSL testing and add numerous MSL test cases. 2017-01-30 22:55:21 -05:00
tesc MSL: Don't use a bitcast for tessellation levels in tesc shaders. 2020-10-14 18:35:59 -05:00
tese MSL: Rewrite tessellation_access_chain. 2019-10-26 16:10:12 +02:00
vert MSL: Add support for processing more than one patch per workgroup. 2020-07-23 17:59:54 -05:00
vulkan MSL: Support SPV_EXT_demote_to_helper_invocation for MSL 2.3. 2020-10-13 00:25:32 -05:00