Fixed sRGB multisample tests

The blitter was not doing the sRGB conversion on the first of
N source samples when accumulating samples for doing an sRGB
resolve.

This cl also includes Chris' initial fix for PixelRoutine and
SpirvShader. See:
https://swiftshader-review.googlesource.com/c/SwiftShader/+/31928

Change-Id: I97ce06fb39788fd623eb9b5c0203e45fd911c1dd
Tests: dEQP-VK.renderpass.suballocation.multisample.*.samples_4
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/32848
Tested-by: Alexis Hétu <sugoi@google.com>
Presubmit-Ready: Alexis Hétu <sugoi@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Chris Forbes <chrisforbes@google.com>
diff --git a/src/Device/Blitter.cpp b/src/Device/Blitter.cpp
index ce4a2b0..63c6040 100644
--- a/src/Device/Blitter.cpp
+++ b/src/Device/Blitter.cpp
@@ -1441,6 +1441,11 @@
 
 							if(state.srcSamples > 1) // Resolve multisampled source
 							{
+								if(state.convertSRGB && state.sourceFormat.isSRGBformat()) // sRGB -> RGB
+								{
+									if(!ApplyScaleAndClamp(color, state)) return nullptr;
+									preScaled = true;
+								}
 								Float4 accum = color;
 								for(int i = 1; i < state.srcSamples; i++)
 								{
diff --git a/src/Pipeline/PixelRoutine.cpp b/src/Pipeline/PixelRoutine.cpp
index 2eb9359..5438b52 100644
--- a/src/Pipeline/PixelRoutine.cpp
+++ b/src/Pipeline/PixelRoutine.cpp
@@ -1913,13 +1913,6 @@
 			UNIMPLEMENTED("VkFormat: %d", int(state.targetFormat[index]));
 		}
 
-		if(isSRGB(index))
-		{
-			sRGBtoLinear(pixel.x);
-			sRGBtoLinear(pixel.y);
-			sRGBtoLinear(pixel.z);
-		}
-
 		// Final Color = ObjectColor * SourceBlendFactor + PixelColor * DestinationBlendFactor
 		Vector4f sourceFactor;
 		Vector4f destFactor;
diff --git a/src/Pipeline/SpirvShader.cpp b/src/Pipeline/SpirvShader.cpp
index 3c48413..05e1623 100644
--- a/src/Pipeline/SpirvShader.cpp
+++ b/src/Pipeline/SpirvShader.cpp
@@ -274,10 +274,7 @@
 
 		sw::SIMD::Int linear = CmpLT(c, sw::SIMD::Float(0.04045f));
 
-		sw::SIMD::Float s = c;
-		s.xyz = rr::As<sw::SIMD::Float>((linear & rr::As<sw::SIMD::Int>(lc)) | (~linear & rr::As<sw::SIMD::Int>(ec)));   // TODO: IfThenElse()
-
-		return s;
+		return rr::As<sw::SIMD::Float>((linear & rr::As<sw::SIMD::Int>(lc)) | (~linear & rr::As<sw::SIMD::Int>(ec)));   // TODO: IfThenElse()
 	}
 
 } // anonymous namespace
@@ -5310,7 +5307,7 @@
 			dst.move(0, ::sRGBtoLinear(SIMD::Float((packed[0] & SIMD::Int(0xFF))) * SIMD::Float(1.0f / 255.f)));
 			dst.move(1, ::sRGBtoLinear(SIMD::Float(((packed[0]>>8) & SIMD::Int(0xFF))) * SIMD::Float(1.0f / 255.f)));
 			dst.move(2, ::sRGBtoLinear(SIMD::Float(((packed[0]>>16) & SIMD::Int(0xFF))) * SIMD::Float(1.0f / 255.f)));
-			dst.move(3, ::sRGBtoLinear(SIMD::Float(((packed[0]>>24) & SIMD::Int(0xFF))) * SIMD::Float(1.0f / 255.f)));
+			dst.move(3, SIMD::Float(((packed[0]>>24) & SIMD::Int(0xFF))) * SIMD::Float(1.0f / 255.f));
 			break;
 		case VK_FORMAT_B8G8R8A8_UNORM:
 			dst.move(0, SIMD::Float(((packed[0]>>16) & SIMD::Int(0xFF))) * SIMD::Float(1.0f / 255.f));
@@ -5322,7 +5319,7 @@
 			dst.move(0, ::sRGBtoLinear(SIMD::Float(((packed[0]>>16) & SIMD::Int(0xFF))) * SIMD::Float(1.0f / 255.f)));
 			dst.move(1, ::sRGBtoLinear(SIMD::Float(((packed[0]>>8) & SIMD::Int(0xFF))) * SIMD::Float(1.0f / 255.f)));
 			dst.move(2, ::sRGBtoLinear(SIMD::Float((packed[0] & SIMD::Int(0xFF))) * SIMD::Float(1.0f / 255.f)));
-			dst.move(3, ::sRGBtoLinear(SIMD::Float(((packed[0]>>24) & SIMD::Int(0xFF))) * SIMD::Float(1.0f / 255.f)));
+			dst.move(3, SIMD::Float(((packed[0]>>24) & SIMD::Int(0xFF))) * SIMD::Float(1.0f / 255.f));
 			break;
 		case VK_FORMAT_R8G8B8A8_UINT:
 		case VK_FORMAT_A8B8G8R8_UINT_PACK32: