SPIRV-Cross/reference/shaders-msl/frag/mrt-array.frag
Bill Hollings 9b4defe202 CompilerMSL support matrices & arrays in stage-in & stage-out.
Support flattening StorageOutput & StorageInput matrices and arrays.
No longer move matrix & array inputs to separate buffer.
Add separate SPIRFunction::fixup_statements_in & SPIRFunction::fixup_statements_out
instead of just  SPIRFunction::fixup_statements.
Emit SPIRFunction::fixup_statements at beginning of functions.
CompilerMSL track vars_needing_early_declaration.
Pass global output variables as variables to functions that access them.
Sort input structs by location, same as output structs.
Emit struct declarations in order output, input, uniforms.
Regenerate reference shaders to new formats defined by above.
2018-06-12 11:41:35 -04:00

54 lines
1.2 KiB
GLSL

#pragma clang diagnostic ignored "-Wmissing-prototypes"
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct main0_out
{
float4 FragColor_0 [[color(0)]];
float4 FragColor_1 [[color(1)]];
float4 FragColor_2 [[color(2)]];
float4 FragColor_3 [[color(3)]];
};
struct main0_in
{
float4 vA [[user(locn0)]];
float4 vB [[user(locn1)]];
};
// Implementation of the GLSL mod() function, which is slightly different than Metal fmod()
template<typename Tx, typename Ty>
Tx mod(Tx x, Ty y)
{
return x - y * floor(x / y);
}
void write_deeper_in_function(thread float4 (&FragColor)[4], thread float4& vA, thread float4& vB)
{
FragColor[3] = vA * vB;
}
void write_in_function(thread float4 (&FragColor)[4], thread float4& vA, thread float4& vB)
{
FragColor[2] = vA - vB;
write_deeper_in_function(FragColor, vA, vB);
}
fragment main0_out main0(main0_in in [[stage_in]])
{
main0_out out = {};
float4 FragColor[4] = {};
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];
return out;
}