From d4727fe696e2cf2e91ba066e5165ed0ad458ad7e Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Fri, 6 Oct 2017 13:21:42 +0200 Subject: [PATCH] Stamp out all variants for mod(). --- reference/shaders-hlsl/frag/mod.frag | 71 ++++++++++++++++++++++++++++ shaders-hlsl/frag/mod.frag | 22 +++++++++ spirv_hlsl.cpp | 17 +++++-- 3 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 reference/shaders-hlsl/frag/mod.frag create mode 100644 shaders-hlsl/frag/mod.frag diff --git a/reference/shaders-hlsl/frag/mod.frag b/reference/shaders-hlsl/frag/mod.frag new file mode 100644 index 00000000..43407cbb --- /dev/null +++ b/reference/shaders-hlsl/frag/mod.frag @@ -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; +} diff --git a/shaders-hlsl/frag/mod.frag b/shaders-hlsl/frag/mod.frag new file mode 100644 index 00000000..32edb618 --- /dev/null +++ b/shaders-hlsl/frag/mod.frag @@ -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; +} diff --git a/spirv_hlsl.cpp b/spirv_hlsl.cpp index bc00235d..492f99aa 100644 --- a/spirv_hlsl.cpp +++ b/spirv_hlsl.cpp @@ -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)