Fix linear to sRGB conversion functions

These functions didn't work for the whole range, causing numerical
errors. Added an explicit boundary check to fix the issue.

Without this change, we were failing these SwANGLE tests:
dEQP-GLES3.functional.fragment_ops.blend.fbo_srgb.equation_src_func_dst_func.*

I logged https://gitlab.khronos.org/Tracker/vk-gl-cts/-/issues/4133 to address the lack of coverage for sRGB values in dEQP-VK.

Bug: b/204322086
Change-Id: I6b7f78e76caefd9cb778200ff3ba51c437a921f3
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/69768
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexis Hétu <sugoi@google.com>
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Pipeline/ShaderCore.cpp b/src/Pipeline/ShaderCore.cpp
index 1ce4980..28c1e4b 100644
--- a/src/Pipeline/ShaderCore.cpp
+++ b/src/Pipeline/ShaderCore.cpp
@@ -672,10 +672,11 @@
 
 SIMD::Float linearToSRGB(const SIMD::Float &c)
 {
-	SIMD::Float lc = Min(c, 0.0031308f) * 12.92f;
+	SIMD::Float lc = c * 12.92f;
 	SIMD::Float ec = MulAdd(1.055f, Pow<Mediump>(c, (1.0f / 2.4f)), -0.055f);  // TODO(b/149574741): Use a custom approximation.
 
-	return Max(lc, ec);
+	SIMD::Int linear = CmpLT(c, 0.0031308f);
+	return As<SIMD::Float>((linear & As<SIMD::Int>(lc)) | (~linear & As<SIMD::Int>(ec)));  // TODO: IfThenElse()
 }
 
 SIMD::Float sRGBtoLinear(const SIMD::Float &c)
@@ -899,10 +900,11 @@
 
 Float4 linearToSRGB(const Float4 &c)
 {
-	Float4 lc = Min(c, 0.0031308f) * 12.92f;
+	Float4 lc = c * 12.92f;
 	Float4 ec = MulAdd(1.055f, Pow<Mediump>(c, (1.0f / 2.4f)), -0.055f);  // TODO(b/149574741): Use a custom approximation.
 
-	return Max(lc, ec);
+	Int4 linear = CmpLT(c, 0.0031308f);
+	return As<Float4>((linear & As<Int4>(lc)) | (~linear & As<Int4>(ec)));  // TODO: IfThenElse()
 }
 
 Float4 sRGBtoLinear(const Float4 &c)