SPIRV-Cross/reference/shaders-msl/frag/mrt-array.frag

95 lines
2.2 KiB
GLSL
Raw Normal View History

2018-03-13 12:17:17 +00:00
#pragma clang diagnostic ignored "-Wmissing-prototypes"
2019-09-17 19:11:19 +00:00
#pragma clang diagnostic ignored "-Wmissing-braces"
2018-03-13 12:17:17 +00:00
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
2019-09-17 19:11:19 +00:00
template<typename T, size_t Num>
struct spvUnsafeArray
{
T elements[Num ? Num : 1];
thread T& operator [] (size_t pos) thread
{
return elements[pos];
}
constexpr const thread T& operator [] (size_t pos) const thread
{
return elements[pos];
}
device T& operator [] (size_t pos) device
{
return elements[pos];
}
constexpr const device T& operator [] (size_t pos) const device
{
return elements[pos];
}
constexpr const constant T& operator [] (size_t pos) const constant
{
return elements[pos];
}
threadgroup T& operator [] (size_t pos) threadgroup
{
return elements[pos];
}
constexpr const threadgroup T& operator [] (size_t pos) const threadgroup
{
return elements[pos];
}
};
// Implementation of the GLSL mod() function, which is slightly different than Metal fmod()
template<typename Tx, typename Ty>
inline Tx mod(Tx x, Ty y)
{
return x - y * floor(x / y);
}
2018-03-13 12:17:17 +00:00
struct main0_out
{
2018-03-13 13:03:35 +00:00
float4 FragColor_0 [[color(0)]];
float4 FragColor_1 [[color(1)]];
float4 FragColor_2 [[color(2)]];
float4 FragColor_3 [[color(3)]];
2018-03-13 12:17:17 +00:00
};
struct main0_in
{
float4 vA [[user(locn0)]];
float4 vB [[user(locn1)]];
};
2019-09-17 19:11:19 +00:00
static inline __attribute__((always_inline))
void write_deeper_in_function(thread spvUnsafeArray<float4, 4>& FragColor, thread float4& vA, thread float4& vB)
2018-03-13 13:03:35 +00:00
{
FragColor[3] = vA * vB;
}
2019-09-17 19:11:19 +00:00
static inline __attribute__((always_inline))
void write_in_function(thread spvUnsafeArray<float4, 4>& FragColor, thread float4& vA, thread float4& vB)
2018-03-13 13:03:35 +00:00
{
FragColor[2] = vA - vB;
write_deeper_in_function(FragColor, vA, vB);
}
2018-03-13 12:17:17 +00:00
fragment main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
2019-09-17 19:11:19 +00:00
spvUnsafeArray<float4, 4> FragColor = {};
2018-03-13 13:03:35 +00:00
FragColor[0] = mod(in.vA, in.vB);
FragColor[1] = in.vA + in.vB;
write_in_function(FragColor, in.vA, in.vB);
out.FragColor_0 = FragColor[0];
out.FragColor_1 = FragColor[1];
out.FragColor_2 = FragColor[2];
out.FragColor_3 = FragColor[3];
2018-03-13 12:17:17 +00:00
return out;
}