From b4248517064d487be9bdaf729f448248fec66432 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Sat, 16 Apr 2016 09:25:14 +0200 Subject: [PATCH] Fix floating point OpMod. Floating point mod uses separate builtin in GLSL. --- reference/shaders/comp/mod.comp | 24 ++++++++++++++++++++++++ shaders/comp/mod.comp | 26 ++++++++++++++++++++++++++ spirv_glsl.cpp | 5 ++++- 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 reference/shaders/comp/mod.comp create mode 100644 shaders/comp/mod.comp diff --git a/reference/shaders/comp/mod.comp b/reference/shaders/comp/mod.comp new file mode 100644 index 00000000..eee2bd97 --- /dev/null +++ b/reference/shaders/comp/mod.comp @@ -0,0 +1,24 @@ +#version 310 es +layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; + +layout(binding = 0, std430) buffer SSBO +{ + vec4 in_data[]; +} _23; + +layout(binding = 1, std430) buffer SSBO2 +{ + vec4 out_data[]; +} _33; + +void main() +{ + uint ident = gl_GlobalInvocationID.x; + vec4 v = mod(_23.in_data[ident], _33.out_data[ident]); + _33.out_data[ident] = v; + uvec4 vu = (floatBitsToUint(_23.in_data[ident]) % floatBitsToUint(_33.out_data[ident])); + _33.out_data[ident] = uintBitsToFloat(vu); + ivec4 vi = (floatBitsToInt(_23.in_data[ident]) % floatBitsToInt(_33.out_data[ident])); + _33.out_data[ident] = intBitsToFloat(vi); +} + diff --git a/shaders/comp/mod.comp b/shaders/comp/mod.comp new file mode 100644 index 00000000..1631456e --- /dev/null +++ b/shaders/comp/mod.comp @@ -0,0 +1,26 @@ +#version 310 es +layout(local_size_x = 1) in; + +layout(std430, binding = 0) readonly buffer SSBO +{ + vec4 in_data[]; +}; + +layout(std430, binding = 1) writeonly buffer SSBO2 +{ + vec4 out_data[]; +}; + +void main() +{ + uint ident = gl_GlobalInvocationID.x; + vec4 v = mod(in_data[ident], out_data[ident]); + out_data[ident] = v; + + uvec4 vu = floatBitsToUint(in_data[ident]) % floatBitsToUint(out_data[ident]); + out_data[ident] = uintBitsToFloat(vu); + + ivec4 vi = floatBitsToInt(in_data[ident]) % floatBitsToInt(out_data[ident]); + out_data[ident] = intBitsToFloat(vi); +} + diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index 84497a11..a4c2b4e4 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -2718,10 +2718,13 @@ void CompilerGLSL::emit_instruction(const Instruction &i) case OpUMod: case OpSMod: - case OpFMod: BOP(%); break; + case OpFMod: + BFOP(mod); + break; + // Relational case OpAny: UFOP(any);