Stamp out all variants for mod().

This commit is contained in:
Hans-Kristian Arntzen 2017-10-06 13:21:42 +02:00
parent 52a33bf2a5
commit d4727fe696
3 changed files with 105 additions and 5 deletions

View File

@ -0,0 +1,71 @@
static float4 a4;
static float4 b4;
static float3 a3;
static float3 b3;
static float2 a2;
static float2 b2;
static float a1;
static float b1;
static float4 FragColor;
struct SPIRV_Cross_Input
{
float4 a4 : TEXCOORD0;
float3 a3 : TEXCOORD1;
float2 a2 : TEXCOORD2;
float a1 : TEXCOORD3;
float4 b4 : TEXCOORD4;
float3 b3 : TEXCOORD5;
float2 b2 : TEXCOORD6;
float b1 : TEXCOORD7;
};
struct SPIRV_Cross_Output
{
float4 FragColor : SV_Target0;
};
float mod(float x, float y)
{
return x - y * floor(x / y);
}
float2 mod(float2 x, float2 y)
{
return x - y * floor(x / y);
}
float3 mod(float3 x, float3 y)
{
return x - y * floor(x / y);
}
float4 mod(float4 x, float4 y)
{
return x - y * floor(x / y);
}
void frag_main()
{
float4 m0 = mod(a4, b4);
float3 m1 = mod(a3, b3);
float2 m2 = mod(a2, b2);
float m3 = mod(a1, b1);
FragColor = ((m0 + m1.xyzx) + m2.xyxy) + float4(m3, m3, m3, m3);
}
SPIRV_Cross_Output main(SPIRV_Cross_Input stage_input)
{
a4 = stage_input.a4;
b4 = stage_input.b4;
a3 = stage_input.a3;
b3 = stage_input.b3;
a2 = stage_input.a2;
b2 = stage_input.b2;
a1 = stage_input.a1;
b1 = stage_input.b1;
frag_main();
SPIRV_Cross_Output stage_output;
stage_output.FragColor = FragColor;
return stage_output;
}

View File

@ -0,0 +1,22 @@
#version 310 es
precision mediump float;
layout(location = 0) in vec4 a4;
layout(location = 1) in vec3 a3;
layout(location = 2) in vec2 a2;
layout(location = 3) in float a1;
layout(location = 4) in vec4 b4;
layout(location = 5) in vec3 b3;
layout(location = 6) in vec2 b2;
layout(location = 7) in float b1;
layout(location = 0) out vec4 FragColor;
void main()
{
vec4 m0 = mod(a4, b4);
vec3 m1 = mod(a3, b3);
vec2 m2 = mod(a2, b2);
float m3 = mod(a1, b1);
FragColor = m0 + m1.xyzx + m2.xyxy + m3;
}

View File

@ -905,11 +905,18 @@ void CompilerHLSL::emit_resources()
if (requires_op_fmod)
{
statement("float mod(float x, float y)");
begin_scope();
statement("return x - y * floor(x / y);");
end_scope();
statement("");
static const char *types[] = {
"float", "float2", "float3", "float4",
};
for (auto &type : types)
{
statement(type, " mod(", type, " x, ", type, " y)");
begin_scope();
statement("return x - y * floor(x / y);");
end_scope();
statement("");
}
}
if (requires_textureProj)