Fix passthrough blend operations

VK_BLEND_OP_SRC_EXT and VK_BLEND_OP_DST_EXT blend operations must not
use the VkBlendFactor state.

Bug: b/204583457
Change-Id: I6d485a679616ea970658f3267b971e96d9064a1b
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/58948
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Device/Context.cpp b/src/Device/Context.cpp
index 64148a5..00f0f4b 100644
--- a/src/Device/Context.cpp
+++ b/src/Device/Context.cpp
@@ -728,10 +728,8 @@
 		return false;
 	}
 
-	bool colorBlend = !(blendOperation(index, attachments) == VK_BLEND_OP_SRC_EXT &&
-	                    sourceBlendFactor(index) == VK_BLEND_FACTOR_ONE);
-	bool alphaBlend = !(blendOperationAlpha(index, attachments) == VK_BLEND_OP_SRC_EXT &&
-	                    sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ONE);
+	bool colorBlend = blendOperation(index, attachments) != VK_BLEND_OP_SRC_EXT;
+	bool alphaBlend = blendOperationAlpha(index, attachments) != VK_BLEND_OP_SRC_EXT;
 
 	return colorBlend || alphaBlend;
 }
@@ -825,7 +823,7 @@
 			{
 				return VK_BLEND_OP_ZERO_EXT;
 			}
-			else
+			else if(destBlendFactor(index) == VK_BLEND_FACTOR_ONE)
 			{
 				return VK_BLEND_OP_DST_EXT;
 			}
@@ -836,83 +834,48 @@
 			{
 				return VK_BLEND_OP_SRC_EXT;
 			}
-			else
-			{
-				return VK_BLEND_OP_ADD;
-			}
 		}
-		else
-		{
-			if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
-			{
-				return VK_BLEND_OP_SRC_EXT;
-			}
-			else
-			{
-				return VK_BLEND_OP_ADD;
-			}
-		}
+		break;
 	case VK_BLEND_OP_SUBTRACT:
-		if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ZERO && attachments.isColorClamped(index))
-		{
-			return VK_BLEND_OP_ZERO_EXT;  // Negative, clamped to zero
-		}
-		else if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ONE)
-		{
-			if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
-			{
-				return VK_BLEND_OP_SRC_EXT;
-			}
-			else
-			{
-				return VK_BLEND_OP_SUBTRACT;
-			}
-		}
-		else
-		{
-			if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
-			{
-				return VK_BLEND_OP_SRC_EXT;
-			}
-			else
-			{
-				return VK_BLEND_OP_SUBTRACT;
-			}
-		}
-	case VK_BLEND_OP_REVERSE_SUBTRACT:
 		if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
 		{
 			if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
 			{
 				return VK_BLEND_OP_ZERO_EXT;
 			}
-			else
+			else if(attachments.isColorClamped(index))
 			{
-				return VK_BLEND_OP_DST_EXT;
+				return VK_BLEND_OP_ZERO_EXT;  // Negative, clamped to zero
 			}
 		}
 		else if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ONE)
 		{
-			if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO && attachments.isColorClamped(index))
+			if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
 			{
-				return VK_BLEND_OP_ZERO_EXT;  // Negative, clamped to zero
-			}
-			else
-			{
-				return VK_BLEND_OP_REVERSE_SUBTRACT;
+				return VK_BLEND_OP_SRC_EXT;
 			}
 		}
-		else
+		break;
+	case VK_BLEND_OP_REVERSE_SUBTRACT:
+		if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
 		{
-			if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO && attachments.isColorClamped(index))
+			if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
+			{
+				return VK_BLEND_OP_ZERO_EXT;
+			}
+			else if(attachments.isColorClamped(index))
 			{
 				return VK_BLEND_OP_ZERO_EXT;  // Negative, clamped to zero
 			}
-			else
+		}
+		else if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
+		{
+			if(destBlendFactor(index) == VK_BLEND_FACTOR_ONE)
 			{
-				return VK_BLEND_OP_REVERSE_SUBTRACT;
+				return VK_BLEND_OP_DST_EXT;
 			}
 		}
+		break;
 	case VK_BLEND_OP_MIN:
 	case VK_BLEND_OP_MAX:
 	case VK_BLEND_OP_MULTIPLY_EXT:
@@ -1021,7 +984,7 @@
 			{
 				return VK_BLEND_OP_ZERO_EXT;
 			}
-			else
+			else if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ONE)
 			{
 				return VK_BLEND_OP_DST_EXT;
 			}
@@ -1032,83 +995,48 @@
 			{
 				return VK_BLEND_OP_SRC_EXT;
 			}
-			else
-			{
-				return VK_BLEND_OP_ADD;
-			}
 		}
-		else
-		{
-			if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
-			{
-				return VK_BLEND_OP_SRC_EXT;
-			}
-			else
-			{
-				return VK_BLEND_OP_ADD;
-			}
-		}
+		break;
 	case VK_BLEND_OP_SUBTRACT:
-		if(sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO && attachments.isColorClamped(index))
-		{
-			return VK_BLEND_OP_ZERO_EXT;  // Negative, clamped to zero
-		}
-		else if(sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ONE)
-		{
-			if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
-			{
-				return VK_BLEND_OP_SRC_EXT;
-			}
-			else
-			{
-				return VK_BLEND_OP_SUBTRACT;
-			}
-		}
-		else
-		{
-			if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
-			{
-				return VK_BLEND_OP_SRC_EXT;
-			}
-			else
-			{
-				return VK_BLEND_OP_SUBTRACT;
-			}
-		}
-	case VK_BLEND_OP_REVERSE_SUBTRACT:
 		if(sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
 		{
 			if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
 			{
 				return VK_BLEND_OP_ZERO_EXT;
 			}
-			else
+			else if(attachments.isColorClamped(index))
 			{
-				return VK_BLEND_OP_DST_EXT;
+				return VK_BLEND_OP_ZERO_EXT;  // Negative, clamped to zero
 			}
 		}
 		else if(sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ONE)
 		{
-			if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO && attachments.isColorClamped(index))
+			if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
 			{
-				return VK_BLEND_OP_ZERO_EXT;  // Negative, clamped to zero
-			}
-			else
-			{
-				return VK_BLEND_OP_REVERSE_SUBTRACT;
+				return VK_BLEND_OP_SRC_EXT;
 			}
 		}
-		else
+		break;
+	case VK_BLEND_OP_REVERSE_SUBTRACT:
+		if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
 		{
-			if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO && attachments.isColorClamped(index))
+			if(sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
+			{
+				return VK_BLEND_OP_ZERO_EXT;
+			}
+			else if(attachments.isColorClamped(index))
 			{
 				return VK_BLEND_OP_ZERO_EXT;  // Negative, clamped to zero
 			}
-			else
+		}
+		else if(sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
+		{
+			if(destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ONE)
 			{
-				return VK_BLEND_OP_REVERSE_SUBTRACT;
+				return VK_BLEND_OP_DST_EXT;
 			}
 		}
+		break;
 	case VK_BLEND_OP_MIN:
 		return VK_BLEND_OP_MIN;
 	case VK_BLEND_OP_MAX:
@@ -1160,8 +1088,8 @@
 		return 0;
 	}
 
-	if(blendOperation(index, attachments) == VK_BLEND_OP_DST_EXT && destBlendFactor(index) == VK_BLEND_FACTOR_ONE &&
-	   (blendOperationAlpha(index, attachments) == VK_BLEND_OP_DST_EXT && destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ONE))
+	if(blendOperation(index, attachments) == VK_BLEND_OP_DST_EXT &&
+	   blendOperationAlpha(index, attachments) == VK_BLEND_OP_DST_EXT)
 	{
 		return 0;
 	}
diff --git a/src/Pipeline/PixelRoutine.cpp b/src/Pipeline/PixelRoutine.cpp
index d729472..f1c1572 100644
--- a/src/Pipeline/PixelRoutine.cpp
+++ b/src/Pipeline/PixelRoutine.cpp
@@ -2477,14 +2477,14 @@
 		blendedColor.z = Max(sourceColor.z, destColor.z);
 		break;
 	case VK_BLEND_OP_SRC_EXT:
-		blendedColor.x = sourceColor.x * sourceFactor.x;  // TODO(b/204583457)
-		blendedColor.y = sourceColor.y * sourceFactor.y;  // TODO(b/204583457)
-		blendedColor.z = sourceColor.z * sourceFactor.z;  // TODO(b/204583457)
+		blendedColor.x = sourceColor.x;
+		blendedColor.y = sourceColor.y;
+		blendedColor.z = sourceColor.z;
 		break;
 	case VK_BLEND_OP_DST_EXT:
-		blendedColor.x = destColor.x * destFactor.x;  // TODO(b/204583457)
-		blendedColor.y = destColor.y * destFactor.y;  // TODO(b/204583457)
-		blendedColor.z = destColor.z * destFactor.z;  // TODO(b/204583457)
+		blendedColor.x = destColor.x;
+		blendedColor.y = destColor.y;
+		blendedColor.z = destColor.z;
 		break;
 	case VK_BLEND_OP_ZERO_EXT:
 		blendedColor.x = Float4(0.0f);
@@ -2530,10 +2530,10 @@
 		blendedColor.w = Max(sourceColor.w, destColor.w);
 		break;
 	case VK_BLEND_OP_SRC_EXT:
-		blendedColor.w = sourceColor.w * sourceFactor.w;  // TODO(b/204583457)
+		blendedColor.w = sourceColor.w;
 		break;
 	case VK_BLEND_OP_DST_EXT:
-		blendedColor.w = destColor.w * destFactor.w;  // TODO(b/204583457)
+		blendedColor.w = destColor.w;
 		break;
 	case VK_BLEND_OP_ZERO_EXT:
 		blendedColor.w = Float4(0.0f);