SPIRV-Cross/reference/opt/shaders-msl/tese/water_tess.raw-tess-in.tese
Chip Davis a171087180 MSL: Support "raw" buffer input in tessellation evaluation shaders.
Using vertex-style stage input is complex, and it doesn't support
nesting of structures or arrays. By using raw buffer input instead, we
get this support "for free," and everything becomes much simpler.
Arguably, this is the way I should've done this in the first place.

Eventually, I'd like to make this the default, and then remove the
option altogether. (And I still need to do that with
`multi_patch_workgroup`...)

Should help fix 66 tests in the Vulkan CTS, under the following trees:

 - `dEQP-VK.pipeline.*.interface_matching.*`
 - `dEQP-VK.tessellation.user_defined_io.*`
 - `dEQP-VK.clipping.user_defined.*`
2022-10-18 14:58:59 -07:00

47 lines
1.8 KiB
GLSL

#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct UBO
{
float4x4 uMVP;
float4 uScale;
float2 uInvScale;
float3 uCamPos;
float2 uPatchSize;
float2 uInvHeightmapSize;
};
struct main0_out
{
float3 vWorld [[user(locn0)]];
float4 vGradNormalTex [[user(locn1)]];
float4 gl_Position [[position]];
};
struct main0_patchIn
{
float2 vOutPatchPosBase;
float4 vPatchLods;
};
[[ patch(quad, 0) ]] vertex main0_out main0(constant UBO& _31 [[buffer(0)]], texture2d<float> uHeightmapDisplacement [[texture(0)]], sampler uHeightmapDisplacementSmplr [[sampler(0)]], float2 gl_TessCoordIn [[position_in_patch]], uint gl_PrimitiveID [[patch_id]], const device main0_patchIn* spvPatchIn [[buffer(20)]])
{
main0_out out = {};
const device main0_patchIn& patchIn = spvPatchIn[gl_PrimitiveID];
float3 gl_TessCoord = float3(gl_TessCoordIn.x, gl_TessCoordIn.y, 0.0);
float2 _202 = fma(gl_TessCoord.xy, _31.uPatchSize, patchIn.vOutPatchPosBase);
float2 _216 = mix(patchIn.vPatchLods.yx, patchIn.vPatchLods.zw, float2(gl_TessCoord.x));
float _223 = mix(_216.x, _216.y, gl_TessCoord.y);
float _225 = floor(_223);
float2 _141 = _31.uInvHeightmapSize * exp2(_225);
out.vGradNormalTex = float4(fma(_202, _31.uInvHeightmapSize, _31.uInvHeightmapSize * 0.5), (_202 * _31.uInvHeightmapSize) * _31.uScale.zw);
float3 _256 = mix(uHeightmapDisplacement.sample(uHeightmapDisplacementSmplr, fma(_202, _31.uInvHeightmapSize, _141 * 0.5), level(_225)).xyz, uHeightmapDisplacement.sample(uHeightmapDisplacementSmplr, fma(_202, _31.uInvHeightmapSize, _141 * 1.0), level(_225 + 1.0)).xyz, float3(_223 - _225));
float2 _171 = fma(_202, _31.uScale.xy, _256.yz);
out.vWorld = float3(_171.x, _256.x, _171.y);
out.gl_Position = _31.uMVP * float4(out.vWorld, 1.0);
return out;
}