SpirvShader: Implement GLSLstd450NClamp
Beware: the dEQP tests here are very weak - they do not seem to properly test the NaN handling of this instruction.
Bug: b/126873455
Tests: dEQP-VK.spirv_assembly.instruction.compute.opnclamp.all
Change-Id: I8d1f80f5536996ca46c30ee4895d9f6e2c29a03e
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28711
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Tested-by: Ben Clayton <bclayton@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index 412a0af..3c785cf 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -3593,7 +3593,14 @@
}
case GLSLstd450NClamp:
{
- UNIMPLEMENTED("GLSLstd450NClamp");
+ auto x = GenericValue(this, routine, insn.word(5));
+ auto minVal = GenericValue(this, routine, insn.word(6));
+ auto maxVal = GenericValue(this, routine, insn.word(7));
+ for (auto i = 0u; i < type.sizeInComponents; i++)
+ {
+ auto clamp = NMin(NMax(x.Float(i), minVal.Float(i)), maxVal.Float(i));
+ dst.move(i, clamp);
+ }
break;
}
default: