| 1 |
#pragma clang diagnostic ignored "-Wmissing-prototypes" |
| 2 |
#pragma clang diagnostic ignored "-Wmissing-braces" |
| 3 |
|
| 4 |
#include <metal_stdlib> |
| 5 |
#include <simd/simd.h> |
| 6 |
|
| 7 |
using namespace metal; |
| 8 |
|
| 9 |
template<typename T, size_t Num> |
| 10 |
struct spvUnsafeArray |
| 11 |
{ |
| 12 |
T elements[Num ? Num : 1]; |
| 13 |
|
| 14 |
thread T& operator [] (size_t pos) thread |
| 15 |
{ |
| 16 |
return elements[pos]; |
| 17 |
} |
| 18 |
constexpr const thread T& operator [] (size_t pos) const thread |
| 19 |
{ |
| 20 |
return elements[pos]; |
| 21 |
} |
| 22 |
|
| 23 |
device T& operator [] (size_t pos) device |
| 24 |
{ |
| 25 |
return elements[pos]; |
| 26 |
} |
| 27 |
constexpr const device T& operator [] (size_t pos) const device |
| 28 |
{ |
| 29 |
return elements[pos]; |
| 30 |
} |
| 31 |
|
| 32 |
constexpr const constant T& operator [] (size_t pos) const constant |
| 33 |
{ |
| 34 |
return elements[pos]; |
| 35 |
} |
| 36 |
|
| 37 |
threadgroup T& operator [] (size_t pos) threadgroup |
| 38 |
{ |
| 39 |
return elements[pos]; |
| 40 |
} |
| 41 |
constexpr const threadgroup T& operator [] (size_t pos) const threadgroup |
| 42 |
{ |
| 43 |
return elements[pos]; |
| 44 |
} |
| 45 |
}; |
| 46 |
|
| 47 |
struct FVertexFactoryInterpolantsVSToPS |
| 48 |
{ |
| 49 |
float4 TangentToWorld0; |
| 50 |
float4 TangentToWorld2; |
| 51 |
}; |
| 52 |
|
| 53 |
struct FVertexFactoryInterpolantsVSToDS |
| 54 |
{ |
| 55 |
FVertexFactoryInterpolantsVSToPS InterpolantsVSToPS; |
| 56 |
}; |
| 57 |
|
| 58 |
struct FSharedBasePassInterpolants |
| 59 |
{ |
| 60 |
}; |
| 61 |
struct FBasePassInterpolantsVSToDS |
| 62 |
{ |
| 63 |
FSharedBasePassInterpolants _m0; |
| 64 |
}; |
| 65 |
|
| 66 |
struct FBasePassVSToDS |
| 67 |
{ |
| 68 |
FVertexFactoryInterpolantsVSToDS FactoryInterpolants; |
| 69 |
FBasePassInterpolantsVSToDS BasePassInterpolants; |
| 70 |
float4 Position; |
| 71 |
}; |
| 72 |
|
| 73 |
struct FFlatTessellationHSToDS |
| 74 |
{ |
| 75 |
FBasePassVSToDS PassSpecificData; |
| 76 |
float3 DisplacementScale; |
| 77 |
float TessellationMultiplier; |
| 78 |
float WorldDisplacementMultiplier; |
| 79 |
}; |
| 80 |
|
| 81 |
struct type_Primitive |
| 82 |
{ |
| 83 |
float4x4 Primitive_LocalToWorld; |
| 84 |
float4 Primitive_InvNonUniformScaleAndDeterminantSign; |
| 85 |
float4 Primitive_ObjectWorldPositionAndRadius; |
| 86 |
float4x4 Primitive_WorldToLocal; |
| 87 |
float4x4 Primitive_PreviousLocalToWorld; |
| 88 |
float4x4 Primitive_PreviousWorldToLocal; |
| 89 |
packed_float3 Primitive_ActorWorldPosition; |
| 90 |
float Primitive_UseSingleSampleShadowFromStationaryLights; |
| 91 |
packed_float3 Primitive_ObjectBounds; |
| 92 |
float Primitive_LpvBiasMultiplier; |
| 93 |
float Primitive_DecalReceiverMask; |
| 94 |
float Primitive_PerObjectGBufferData; |
| 95 |
float Primitive_UseVolumetricLightmapShadowFromStationaryLights; |
| 96 |
float Primitive_DrawsVelocity; |
| 97 |
float4 Primitive_ObjectOrientation; |
| 98 |
float4 Primitive_NonUniformScale; |
| 99 |
packed_float3 Primitive_LocalObjectBoundsMin; |
| 100 |
uint Primitive_LightingChannelMask; |
| 101 |
packed_float3 Primitive_LocalObjectBoundsMax; |
| 102 |
uint Primitive_LightmapDataIndex; |
| 103 |
packed_float3 Primitive_PreSkinnedLocalBounds; |
| 104 |
int Primitive_SingleCaptureIndex; |
| 105 |
uint Primitive_OutputVelocity; |
| 106 |
uint PrePadding_Primitive_420; |
| 107 |
uint PrePadding_Primitive_424; |
| 108 |
uint PrePadding_Primitive_428; |
| 109 |
float4 Primitive_CustomPrimitiveData[4]; |
| 110 |
}; |
| 111 |
|
| 112 |
struct type_Material |
| 113 |
{ |
| 114 |
float4 Material_VectorExpressions[3]; |
| 115 |
float4 Material_ScalarExpressions[1]; |
| 116 |
}; |
| 117 |
|
| 118 |
constant float4 _182 = {}; |
| 119 |
|
| 120 |
struct main0_out |
| 121 |
{ |
| 122 |
float3 out_var_Flat_DisplacementScales; |
| 123 |
float out_var_Flat_TessellationMultiplier; |
| 124 |
float out_var_Flat_WorldDisplacementMultiplier; |
| 125 |
float4 out_var_TEXCOORD10_centroid; |
| 126 |
float4 out_var_TEXCOORD11_centroid; |
| 127 |
float4 out_var_VS_To_DS_Position; |
| 128 |
}; |
| 129 |
|
| 130 |
struct main0_in |
| 131 |
{ |
| 132 |
float4 in_var_TEXCOORD10_centroid [[attribute(0)]]; |
| 133 |
float4 in_var_TEXCOORD11_centroid [[attribute(1)]]; |
| 134 |
float4 in_var_VS_To_DS_Position [[attribute(2)]]; |
| 135 |
}; |
| 136 |
|
| 137 |
kernel void main0(main0_in in [[stage_in]], constant type_Primitive& Primitive [[buffer(0)]], constant type_Material& Material [[buffer(1)]], uint gl_InvocationID [[thread_index_in_threadgroup]], uint gl_PrimitiveID [[threadgroup_position_in_grid]], device main0_out* spvOut [[buffer(28)]], constant uint* spvIndirectParams [[buffer(29)]], device MTLTriangleTessellationFactorsHalf* spvTessLevel [[buffer(26)]], threadgroup main0_in* gl_in [[threadgroup(0)]]) |
| 138 |
{ |
| 139 |
threadgroup FFlatTessellationHSToDS temp_var_hullMainRetVal[3]; |
| 140 |
device main0_out* gl_out = &spvOut[gl_PrimitiveID * 3]; |
| 141 |
if (gl_InvocationID < spvIndirectParams[0]) |
| 142 |
gl_in[gl_InvocationID] = in; |
| 143 |
threadgroup_barrier(mem_flags::mem_threadgroup); |
| 144 |
if (gl_InvocationID >= 3) |
| 145 |
return; |
| 146 |
spvUnsafeArray<float4, 3> _90 = spvUnsafeArray<float4, 3>({ gl_in[0].in_var_TEXCOORD10_centroid, gl_in[1].in_var_TEXCOORD10_centroid, gl_in[2].in_var_TEXCOORD10_centroid }); |
| 147 |
spvUnsafeArray<float4, 3> _91 = spvUnsafeArray<float4, 3>({ gl_in[0].in_var_TEXCOORD11_centroid, gl_in[1].in_var_TEXCOORD11_centroid, gl_in[2].in_var_TEXCOORD11_centroid }); |
| 148 |
spvUnsafeArray<float4, 3> _104 = spvUnsafeArray<float4, 3>({ gl_in[0].in_var_VS_To_DS_Position, gl_in[1].in_var_VS_To_DS_Position, gl_in[2].in_var_VS_To_DS_Position }); |
| 149 |
spvUnsafeArray<FBasePassVSToDS, 3> _111 = spvUnsafeArray<FBasePassVSToDS, 3>({ FBasePassVSToDS{ FVertexFactoryInterpolantsVSToDS{ FVertexFactoryInterpolantsVSToPS{ _90[0], _91[0] } }, FBasePassInterpolantsVSToDS{ { } }, _104[0] }, FBasePassVSToDS{ FVertexFactoryInterpolantsVSToDS{ FVertexFactoryInterpolantsVSToPS{ _90[1], _91[1] } }, FBasePassInterpolantsVSToDS{ { } }, _104[1] }, FBasePassVSToDS{ FVertexFactoryInterpolantsVSToDS{ FVertexFactoryInterpolantsVSToPS{ _90[2], _91[2] } }, FBasePassInterpolantsVSToDS{ { } }, _104[2] } }); |
| 150 |
spvUnsafeArray<FBasePassVSToDS, 3> param_var_I; |
| 151 |
param_var_I = _111; |
| 152 |
float3 _128 = Primitive.Primitive_NonUniformScale.xyz * float3x3(param_var_I[gl_InvocationID].FactoryInterpolants.InterpolantsVSToPS.TangentToWorld0.xyz, cross(param_var_I[gl_InvocationID].FactoryInterpolants.InterpolantsVSToPS.TangentToWorld2.xyz, param_var_I[gl_InvocationID].FactoryInterpolants.InterpolantsVSToPS.TangentToWorld0.xyz) * float3(param_var_I[gl_InvocationID].FactoryInterpolants.InterpolantsVSToPS.TangentToWorld2.w), param_var_I[gl_InvocationID].FactoryInterpolants.InterpolantsVSToPS.TangentToWorld2.xyz); |
| 153 |
gl_out[gl_InvocationID].out_var_TEXCOORD10_centroid = param_var_I[gl_InvocationID].FactoryInterpolants.InterpolantsVSToPS.TangentToWorld0; |
| 154 |
gl_out[gl_InvocationID].out_var_TEXCOORD11_centroid = param_var_I[gl_InvocationID].FactoryInterpolants.InterpolantsVSToPS.TangentToWorld2; |
| 155 |
gl_out[gl_InvocationID].out_var_VS_To_DS_Position = param_var_I[gl_InvocationID].Position; |
| 156 |
gl_out[gl_InvocationID].out_var_Flat_DisplacementScales = _128; |
| 157 |
gl_out[gl_InvocationID].out_var_Flat_TessellationMultiplier = Material.Material_ScalarExpressions[0].x; |
| 158 |
gl_out[gl_InvocationID].out_var_Flat_WorldDisplacementMultiplier = 1.0; |
| 159 |
temp_var_hullMainRetVal[gl_InvocationID] = FFlatTessellationHSToDS{ param_var_I[gl_InvocationID], _128, Material.Material_ScalarExpressions[0].x, 1.0 }; |
| 160 |
threadgroup_barrier(mem_flags::mem_device | mem_flags::mem_threadgroup); |
| 161 |
if (gl_InvocationID == 0u) |
| 162 |
{ |
| 163 |
float4 _154 = _182; |
| 164 |
_154.x = 0.5 * (temp_var_hullMainRetVal[1u].TessellationMultiplier + temp_var_hullMainRetVal[2u].TessellationMultiplier); |
| 165 |
float4 _160 = _154; |
| 166 |
_160.y = 0.5 * (temp_var_hullMainRetVal[2u].TessellationMultiplier + temp_var_hullMainRetVal[0u].TessellationMultiplier); |
| 167 |
float4 _165 = _160; |
| 168 |
_165.z = 0.5 * (temp_var_hullMainRetVal[0u].TessellationMultiplier + temp_var_hullMainRetVal[1u].TessellationMultiplier); |
| 169 |
float4 _172 = _165; |
| 170 |
_172.w = 0.333000004291534423828125 * ((temp_var_hullMainRetVal[0u].TessellationMultiplier + temp_var_hullMainRetVal[1u].TessellationMultiplier) + temp_var_hullMainRetVal[2u].TessellationMultiplier); |
| 171 |
float4 _173 = fast::clamp(_172, float4(1.0), float4(15.0)); |
| 172 |
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[0u] = half(_173.x); |
| 173 |
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[1u] = half(_173.y); |
| 174 |
spvTessLevel[gl_PrimitiveID].edgeTessellationFactor[2u] = half(_173.z); |
| 175 |
spvTessLevel[gl_PrimitiveID].insideTessellationFactor = half(_173.w); |
| 176 |
} |
| 177 |
} |
| 178 |
|