SPIRV-Cross/reference
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
..
opt MSL: Support pull-model interpolation on MSL 2.3+. 2020-11-05 11:57:45 -06:00
shaders GLSL: Support a workaround for loading row-major matrices. 2020-10-27 12:07:09 +01:00
shaders-hlsl HLSL: Add regression test for SM3.0 texture samplers 2020-11-03 18:15:05 +01:00
shaders-hlsl-no-opt HLSL: Add option to flatten matrix vertex input semantics. 2020-11-03 11:18:32 +01:00
shaders-msl MSL: Support pull-model interpolation on MSL 2.3+. 2020-11-05 11:57:45 -06:00
shaders-msl-no-opt MSL: Allow framebuffer fetch on Mac in MSL 2.3. 2020-10-29 10:50:59 -05:00
shaders-no-opt Updated ref file for subgroups_basicvoteballot.vk.comp 2020-11-02 18:40:56 +01:00
shaders-reflection Parser: Don't assume OpTypePointer will always take a SPIRType. 2020-11-03 10:53:37 +01:00
shaders-ue4/asm MSL: Allow framebuffer fetch on Mac in MSL 2.3. 2020-10-29 10:50:59 -05:00
shaders-ue4-no-opt/asm Implement context-sensitive expression read tracking. 2020-06-29 12:20:35 +02:00