Do not indent C++ namespace contents

This is a style change. Visual Studio defaults to indenting namespace
contents, and this was adopted for a long time, but with the new Vulkan
implementation this was abandoned. However the legacy code borrowed from
the OpenGL ES implementation still used indentation so it was
inconsistent.

The justification for not indenting namespace contents is that
namespaces are merely a way to avoid name clashes with other projects
we don't control directly (and in rare cases internal subprojects when
we want to reuse the same names). Hence the vast majority of files have
a single namespace, and unlike indentation used for ease of discerning
control flow blocks, class contents, or function contents, which can
become highly nested, there is no such readability advantage to
indenting namespace contents.

This is also the Google style recommendation (though no justification or
discussion is provided):
https://google.github.io/styleguide/cppguide.html#Namespace_Formatting

One reasonable counter-argument is consistency with other blocks of
curly brackets, but considering that most namespaces span almost the
entire file, it's a substantial waste of line length.

Because there is no indentation, there's also no need to have the open
and closing brackets line up as a visual aid, like we prefer for other
uses of curly brackets. So we place the open bracket on the same line as
the namespace keyword.

A comment is added to the closing bracket to discern it from other
closing brackets. It also makes it easier to find the end of anonymous
namespaces which typically go at the top of the source file.

This change is make separately from applying clang-format because diff
tools mark all these unindented lines as changes and this makes it hard
to review the smaller style changes made by clang-format. The OpenGL ES
and Direct3D code is left untouched because it is in maintenance mode
and in case of regressions we want easy 'blame' tool usage.

Bug: b/144825072
Change-Id: Ie2925ebd697e1ffa7c4cbdc9a946531f11f4d934
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/39348
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Device/Context.cpp b/src/Device/Context.cpp
index 49505c9..e41ce74 100644
--- a/src/Device/Context.cpp
+++ b/src/Device/Context.cpp
@@ -22,552 +22,553 @@
 
 #include <string.h>
 
-namespace sw
+namespace sw {
+
+Context::Context()
 {
-	Context::Context()
+	init();
+}
+
+bool Context::isDrawPoint(bool polygonModeAware) const
+{
+	switch(topology)
 	{
-		init();
-	}
-
-	bool Context::isDrawPoint(bool polygonModeAware) const
-	{
-		switch(topology)
-		{
-		case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
-			return true;
-		case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
-		case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
-			return false;
-		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
-		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
-		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
-			return polygonModeAware ? (polygonMode == VK_POLYGON_MODE_POINT) : false;
-		default:
-			UNIMPLEMENTED("topology %d", int(topology));
-		}
-		return false;
-	}
-
-	bool Context::isDrawLine(bool polygonModeAware) const
-	{
-		switch(topology)
-		{
-		case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
-			return false;
-		case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
-		case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
-			return true;
-		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
-		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
-		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
-			return polygonModeAware ? (polygonMode == VK_POLYGON_MODE_LINE) : false;
-		default:
-			UNIMPLEMENTED("topology %d", int(topology));
-		}
-		return false;
-	}
-
-	bool Context::isDrawTriangle(bool polygonModeAware) const
-	{
-		switch(topology)
-		{
-		case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
-		case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
-		case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
-			return false;
-		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
-		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
-		case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
-			return polygonModeAware ? (polygonMode == VK_POLYGON_MODE_FILL) : true;
-		default:
-			UNIMPLEMENTED("topology %d", int(topology));
-		}
-		return false;
-	}
-
-	void Context::init()
-	{
-		for(int i = 0; i < RENDERTARGETS; ++i)
-		{
-			renderTarget[i] = nullptr;
-		}
-
-		depthBuffer = nullptr;
-		stencilBuffer = nullptr;
-
-		stencilEnable = false;
-		frontStencil = {};
-		backStencil = {};
-
-		robustBufferAccess = false;
-
-		rasterizerDiscard = false;
-
-		depthCompareMode = VK_COMPARE_OP_LESS;
-		depthBoundsTestEnable = false;
-		depthBufferEnable = false;
-		depthWriteEnable = false;
-
-		cullMode = VK_CULL_MODE_FRONT_BIT;
-		frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
-		provokingVertexMode = VK_PROVOKING_VERTEX_MODE_FIRST_VERTEX_EXT;
-		lineRasterizationMode = VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT;
-
-		depthBias = 0.0f;
-		slopeDepthBias = 0.0f;
-
-		for(int i = 0; i < RENDERTARGETS; i++)
-		{
-			colorWriteMask[i] = 0x0000000F;
-		}
-
-		pipelineLayout = nullptr;
-
-		pixelShader = nullptr;
-		vertexShader = nullptr;
-
-		occlusionEnabled = false;
-
-		lineWidth = 1.0f;
-
-		sampleMask = 0xFFFFFFFF;
-		alphaToCoverage = false;
-	}
-
-	bool Context::depthWriteActive() const
-	{
-		if(!depthBufferActive()) return false;
-
-		return depthWriteEnable;
-	}
-
-	bool Context::depthBufferActive() const
-	{
-		return depthBuffer && depthBufferEnable;
-	}
-
-	bool Context::stencilActive() const
-	{
-		return stencilBuffer && stencilEnable;
-	}
-
-	void Context::setBlendState(int index, BlendState state)
-	{
-		ASSERT((index >= 0) && (index < RENDERTARGETS));
-
-		blendState[index] = state;
-	}
-
-	BlendState Context::getBlendState(int index) const
-	{
-		ASSERT((index >= 0) && (index < RENDERTARGETS));
-
-		BlendState activeBlendState;
-		activeBlendState.alphaBlendEnable = alphaBlendActive(index);
-		activeBlendState.sourceBlendFactor = sourceBlendFactor(index);
-		activeBlendState.destBlendFactor = destBlendFactor(index);
-		activeBlendState.blendOperation = blendOperation(index);
-		activeBlendState.sourceBlendFactorAlpha = sourceBlendFactorAlpha(index);
-		activeBlendState.destBlendFactorAlpha = destBlendFactorAlpha(index);
-		activeBlendState.blendOperationAlpha = blendOperationAlpha(index);
-		return activeBlendState;
-	}
-
-	bool Context::alphaBlendActive(int index) const
-	{
-		ASSERT((index >= 0) && (index < RENDERTARGETS));
-
-		if(!blendState[index].alphaBlendEnable)
-		{
-			return false;
-		}
-
-		if(!colorUsed())
-		{
-			return false;
-		}
-
-		bool colorBlend = !(blendOperation(index) == VK_BLEND_OP_SRC_EXT && sourceBlendFactor(index) == VK_BLEND_FACTOR_ONE);
-		bool alphaBlend = !(blendOperationAlpha(index) == VK_BLEND_OP_SRC_EXT && sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ONE);
-
-		return colorBlend || alphaBlend;
-	}
-
-	VkBlendFactor Context::sourceBlendFactor(int index) const
-	{
-		ASSERT((index >= 0) && (index < RENDERTARGETS));
-
-		if(!blendState[index].alphaBlendEnable) return VK_BLEND_FACTOR_ONE;
-
-		switch(blendState[index].blendOperation)
-		{
-		case VK_BLEND_OP_ADD:
-		case VK_BLEND_OP_SUBTRACT:
-		case VK_BLEND_OP_REVERSE_SUBTRACT:
-			return blendState[index].sourceBlendFactor;
-		case VK_BLEND_OP_MIN:
-			return VK_BLEND_FACTOR_ONE;
-		case VK_BLEND_OP_MAX:
-			return VK_BLEND_FACTOR_ONE;
-		default:
-			ASSERT(false);
-		}
-
-		return blendState[index].sourceBlendFactor;
-	}
-
-	VkBlendFactor Context::destBlendFactor(int index) const
-	{
-		ASSERT((index >= 0) && (index < RENDERTARGETS));
-
-		if(!blendState[index].alphaBlendEnable) return VK_BLEND_FACTOR_ONE;
-
-		switch(blendState[index].blendOperation)
-		{
-		case VK_BLEND_OP_ADD:
-		case VK_BLEND_OP_SUBTRACT:
-		case VK_BLEND_OP_REVERSE_SUBTRACT:
-			return blendState[index].destBlendFactor;
-		case VK_BLEND_OP_MIN:
-			return VK_BLEND_FACTOR_ONE;
-		case VK_BLEND_OP_MAX:
-			return VK_BLEND_FACTOR_ONE;
-		default:
-			ASSERT(false);
-		}
-
-		return blendState[index].destBlendFactor;
-	}
-
-	bool Context::allTargetsColorClamp() const
-	{
-		// TODO: remove all of this and support VkPhysicalDeviceFeatures::independentBlend instead
-		for (int i = 0; i < RENDERTARGETS; i++)
-		{
-			if (renderTarget[i] && renderTarget[i]->getFormat().isFloatFormat())
-			{
-				return false;
-			}
-		}
-
+	case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
 		return true;
+	case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
+	case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
+		return false;
+	case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
+	case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
+	case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
+		return polygonModeAware ? (polygonMode == VK_POLYGON_MODE_POINT) : false;
+	default:
+		UNIMPLEMENTED("topology %d", int(topology));
+	}
+	return false;
+}
+
+bool Context::isDrawLine(bool polygonModeAware) const
+{
+	switch(topology)
+	{
+	case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
+		return false;
+	case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
+	case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
+		return true;
+	case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
+	case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
+	case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
+		return polygonModeAware ? (polygonMode == VK_POLYGON_MODE_LINE) : false;
+	default:
+		UNIMPLEMENTED("topology %d", int(topology));
+	}
+	return false;
+}
+
+bool Context::isDrawTriangle(bool polygonModeAware) const
+{
+	switch(topology)
+	{
+	case VK_PRIMITIVE_TOPOLOGY_POINT_LIST:
+	case VK_PRIMITIVE_TOPOLOGY_LINE_LIST:
+	case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP:
+		return false;
+	case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST:
+	case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP:
+	case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN:
+		return polygonModeAware ? (polygonMode == VK_POLYGON_MODE_FILL) : true;
+	default:
+		UNIMPLEMENTED("topology %d", int(topology));
+	}
+	return false;
+}
+
+void Context::init()
+{
+	for(int i = 0; i < RENDERTARGETS; ++i)
+	{
+		renderTarget[i] = nullptr;
 	}
 
-	VkBlendOp Context::blendOperation(int index) const
+	depthBuffer = nullptr;
+	stencilBuffer = nullptr;
+
+	stencilEnable = false;
+	frontStencil = {};
+	backStencil = {};
+
+	robustBufferAccess = false;
+
+	rasterizerDiscard = false;
+
+	depthCompareMode = VK_COMPARE_OP_LESS;
+	depthBoundsTestEnable = false;
+	depthBufferEnable = false;
+	depthWriteEnable = false;
+
+	cullMode = VK_CULL_MODE_FRONT_BIT;
+	frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
+	provokingVertexMode = VK_PROVOKING_VERTEX_MODE_FIRST_VERTEX_EXT;
+	lineRasterizationMode = VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT;
+
+	depthBias = 0.0f;
+	slopeDepthBias = 0.0f;
+
+	for(int i = 0; i < RENDERTARGETS; i++)
 	{
-		ASSERT((index >= 0) && (index < RENDERTARGETS));
+		colorWriteMask[i] = 0x0000000F;
+	}
 
-		if(!blendState[index].alphaBlendEnable) return VK_BLEND_OP_SRC_EXT;
+	pipelineLayout = nullptr;
 
-		switch(blendState[index].blendOperation)
+	pixelShader = nullptr;
+	vertexShader = nullptr;
+
+	occlusionEnabled = false;
+
+	lineWidth = 1.0f;
+
+	sampleMask = 0xFFFFFFFF;
+	alphaToCoverage = false;
+}
+
+bool Context::depthWriteActive() const
+{
+	if(!depthBufferActive()) return false;
+
+	return depthWriteEnable;
+}
+
+bool Context::depthBufferActive() const
+{
+	return depthBuffer && depthBufferEnable;
+}
+
+bool Context::stencilActive() const
+{
+	return stencilBuffer && stencilEnable;
+}
+
+void Context::setBlendState(int index, BlendState state)
+{
+	ASSERT((index >= 0) && (index < RENDERTARGETS));
+
+	blendState[index] = state;
+}
+
+BlendState Context::getBlendState(int index) const
+{
+	ASSERT((index >= 0) && (index < RENDERTARGETS));
+
+	BlendState activeBlendState;
+	activeBlendState.alphaBlendEnable = alphaBlendActive(index);
+	activeBlendState.sourceBlendFactor = sourceBlendFactor(index);
+	activeBlendState.destBlendFactor = destBlendFactor(index);
+	activeBlendState.blendOperation = blendOperation(index);
+	activeBlendState.sourceBlendFactorAlpha = sourceBlendFactorAlpha(index);
+	activeBlendState.destBlendFactorAlpha = destBlendFactorAlpha(index);
+	activeBlendState.blendOperationAlpha = blendOperationAlpha(index);
+	return activeBlendState;
+}
+
+bool Context::alphaBlendActive(int index) const
+{
+	ASSERT((index >= 0) && (index < RENDERTARGETS));
+
+	if(!blendState[index].alphaBlendEnable)
+	{
+		return false;
+	}
+
+	if(!colorUsed())
+	{
+		return false;
+	}
+
+	bool colorBlend = !(blendOperation(index) == VK_BLEND_OP_SRC_EXT && sourceBlendFactor(index) == VK_BLEND_FACTOR_ONE);
+	bool alphaBlend = !(blendOperationAlpha(index) == VK_BLEND_OP_SRC_EXT && sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ONE);
+
+	return colorBlend || alphaBlend;
+}
+
+VkBlendFactor Context::sourceBlendFactor(int index) const
+{
+	ASSERT((index >= 0) && (index < RENDERTARGETS));
+
+	if(!blendState[index].alphaBlendEnable) return VK_BLEND_FACTOR_ONE;
+
+	switch(blendState[index].blendOperation)
+	{
+	case VK_BLEND_OP_ADD:
+	case VK_BLEND_OP_SUBTRACT:
+	case VK_BLEND_OP_REVERSE_SUBTRACT:
+		return blendState[index].sourceBlendFactor;
+	case VK_BLEND_OP_MIN:
+		return VK_BLEND_FACTOR_ONE;
+	case VK_BLEND_OP_MAX:
+		return VK_BLEND_FACTOR_ONE;
+	default:
+		ASSERT(false);
+	}
+
+	return blendState[index].sourceBlendFactor;
+}
+
+VkBlendFactor Context::destBlendFactor(int index) const
+{
+	ASSERT((index >= 0) && (index < RENDERTARGETS));
+
+	if(!blendState[index].alphaBlendEnable) return VK_BLEND_FACTOR_ONE;
+
+	switch(blendState[index].blendOperation)
+	{
+	case VK_BLEND_OP_ADD:
+	case VK_BLEND_OP_SUBTRACT:
+	case VK_BLEND_OP_REVERSE_SUBTRACT:
+		return blendState[index].destBlendFactor;
+	case VK_BLEND_OP_MIN:
+		return VK_BLEND_FACTOR_ONE;
+	case VK_BLEND_OP_MAX:
+		return VK_BLEND_FACTOR_ONE;
+	default:
+		ASSERT(false);
+	}
+
+	return blendState[index].destBlendFactor;
+}
+
+bool Context::allTargetsColorClamp() const
+{
+	// TODO: remove all of this and support VkPhysicalDeviceFeatures::independentBlend instead
+	for (int i = 0; i < RENDERTARGETS; i++)
+	{
+		if (renderTarget[i] && renderTarget[i]->getFormat().isFloatFormat())
 		{
-		case VK_BLEND_OP_ADD:
-			if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
-			{
-				if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
-				{
-					return VK_BLEND_OP_ZERO_EXT;
-				}
-				else
-				{
-					return VK_BLEND_OP_DST_EXT;
-				}
-			}
-			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_ADD;
-				}
-			}
-			else
-			{
-				if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
-				{
-					return VK_BLEND_OP_SRC_EXT;
-				}
-				else
-				{
-					return VK_BLEND_OP_ADD;
-				}
-			}
-		case VK_BLEND_OP_SUBTRACT:
-			if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
-			{
-				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
-				{
-					return VK_BLEND_OP_DST_EXT;
-				}
-			}
-			else if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ONE)
-			{
-				if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
-				{
-					return VK_BLEND_OP_ZERO_EXT;   // Negative, clamped to zero
-				}
-				else
-				{
-					return VK_BLEND_OP_REVERSE_SUBTRACT;
-				}
-			}
-			else
-			{
-				if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
-				{
-					return VK_BLEND_OP_ZERO_EXT;   // Negative, clamped to zero
-				}
-				else
-				{
-					return VK_BLEND_OP_REVERSE_SUBTRACT;
-				}
-			}
-		case VK_BLEND_OP_MIN:
-			return VK_BLEND_OP_MIN;
-		case VK_BLEND_OP_MAX:
-			return VK_BLEND_OP_MAX;
-		default:
-			ASSERT(false);
+			return false;
 		}
-
-		return blendState[index].blendOperation;
 	}
 
-	VkBlendFactor Context::sourceBlendFactorAlpha(int index) const
+	return true;
+}
+
+VkBlendOp Context::blendOperation(int index) const
+{
+	ASSERT((index >= 0) && (index < RENDERTARGETS));
+
+	if(!blendState[index].alphaBlendEnable) return VK_BLEND_OP_SRC_EXT;
+
+	switch(blendState[index].blendOperation)
 	{
-		ASSERT((index >= 0) && (index < RENDERTARGETS));
-
-		switch (blendState[index].blendOperationAlpha)
+	case VK_BLEND_OP_ADD:
+		if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
 		{
-		case VK_BLEND_OP_ADD:
-		case VK_BLEND_OP_SUBTRACT:
-		case VK_BLEND_OP_REVERSE_SUBTRACT:
-			return blendState[index].sourceBlendFactorAlpha;
-		case VK_BLEND_OP_MIN:
-			return VK_BLEND_FACTOR_ONE;
-		case VK_BLEND_OP_MAX:
-			return VK_BLEND_FACTOR_ONE;
-		default:
-			ASSERT(false);
-		}
-
-		return blendState[index].sourceBlendFactorAlpha;
-	}
-
-	VkBlendFactor Context::destBlendFactorAlpha(int index) const
-	{
-		ASSERT((index >= 0) && (index < RENDERTARGETS));
-
-		switch (blendState[index].blendOperationAlpha)
-		{
-		case VK_BLEND_OP_ADD:
-		case VK_BLEND_OP_SUBTRACT:
-		case VK_BLEND_OP_REVERSE_SUBTRACT:
-			return blendState[index].destBlendFactorAlpha;
-		case VK_BLEND_OP_MIN:
-			return VK_BLEND_FACTOR_ONE;
-		case VK_BLEND_OP_MAX:
-			return VK_BLEND_FACTOR_ONE;
-		default:
-			ASSERT(false);
-		}
-
-		return blendState[index].destBlendFactorAlpha;
-	}
-
-	VkBlendOp Context::blendOperationAlpha(int index) const
-	{
-		ASSERT((index >= 0) && (index < RENDERTARGETS));
-
-		switch (blendState[index].blendOperationAlpha)
-		{
-		case VK_BLEND_OP_ADD:
-			if (sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
+			if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
 			{
-				if (destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
-				{
-					return VK_BLEND_OP_ZERO_EXT;
-				}
-				else
-				{
-					return VK_BLEND_OP_DST_EXT;
-				}
-			}
-			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_ADD;
-				}
+				return VK_BLEND_OP_ZERO_EXT;
 			}
 			else
 			{
-				if (destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
-				{
-					return VK_BLEND_OP_SRC_EXT;
-				}
-				else
-				{
-					return VK_BLEND_OP_ADD;
-				}
+				return VK_BLEND_OP_DST_EXT;
 			}
-		case VK_BLEND_OP_SUBTRACT:
-			if (sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
-			{
-				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
-				{
-					return VK_BLEND_OP_DST_EXT;
-				}
-			}
-			else if (sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ONE)
-			{
-				if (destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
-				{
-					return VK_BLEND_OP_ZERO_EXT;   // Negative, clamped to zero
-				}
-				else
-				{
-					return VK_BLEND_OP_REVERSE_SUBTRACT;
-				}
-			}
-			else
-			{
-				if (destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
-				{
-					return VK_BLEND_OP_ZERO_EXT;   // Negative, clamped to zero
-				}
-				else
-				{
-					return VK_BLEND_OP_REVERSE_SUBTRACT;
-				}
-			}
-		case VK_BLEND_OP_MIN:
-			return VK_BLEND_OP_MIN;
-		case VK_BLEND_OP_MAX:
-			return VK_BLEND_OP_MAX;
-		default:
-			ASSERT(false);
 		}
-
-		return blendState[index].blendOperationAlpha;
-	}
-
-	VkFormat Context::renderTargetInternalFormat(int index) const
-	{
-		ASSERT((index >= 0) && (index < RENDERTARGETS));
-
-		if(renderTarget[index])
+		else if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ONE)
 		{
-			return renderTarget[index]->getFormat();
+			if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
+			{
+				return VK_BLEND_OP_SRC_EXT;
+			}
+			else
+			{
+				return VK_BLEND_OP_ADD;
+			}
 		}
 		else
 		{
-			return VK_FORMAT_UNDEFINED;
-		}
-	}
-
-	bool Context::colorWriteActive() const
-	{
-		for (int i = 0; i < RENDERTARGETS; i++)
-		{
-			if (colorWriteActive(i))
+			if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO)
 			{
-				return true;
+				return VK_BLEND_OP_SRC_EXT;
+			}
+			else
+			{
+				return VK_BLEND_OP_ADD;
 			}
 		}
-
-		return false;
+	case VK_BLEND_OP_SUBTRACT:
+		if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
+		{
+			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
+			{
+				return VK_BLEND_OP_DST_EXT;
+			}
+		}
+		else if(sourceBlendFactor(index) == VK_BLEND_FACTOR_ONE)
+		{
+			if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
+			{
+				return VK_BLEND_OP_ZERO_EXT;   // Negative, clamped to zero
+			}
+			else
+			{
+				return VK_BLEND_OP_REVERSE_SUBTRACT;
+			}
+		}
+		else
+		{
+			if(destBlendFactor(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
+			{
+				return VK_BLEND_OP_ZERO_EXT;   // Negative, clamped to zero
+			}
+			else
+			{
+				return VK_BLEND_OP_REVERSE_SUBTRACT;
+			}
+		}
+	case VK_BLEND_OP_MIN:
+		return VK_BLEND_OP_MIN;
+	case VK_BLEND_OP_MAX:
+		return VK_BLEND_OP_MAX;
+	default:
+		ASSERT(false);
 	}
 
-	int Context::colorWriteActive(int index) const
+	return blendState[index].blendOperation;
+}
+
+VkBlendFactor Context::sourceBlendFactorAlpha(int index) const
+{
+	ASSERT((index >= 0) && (index < RENDERTARGETS));
+
+	switch (blendState[index].blendOperationAlpha)
 	{
-		ASSERT((index >= 0) && (index < RENDERTARGETS));
-
-		if(!renderTarget[index] || renderTarget[index]->getFormat() == VK_FORMAT_UNDEFINED)
-		{
-			return 0;
-		}
-
-		if(blendOperation(index) == VK_BLEND_OP_DST_EXT && destBlendFactor(index) == VK_BLEND_FACTOR_ONE &&
-		   (blendOperationAlpha(index) == VK_BLEND_OP_DST_EXT && destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ONE))
-		{
-			return 0;
-		}
-
-		return colorWriteMask[index];
+	case VK_BLEND_OP_ADD:
+	case VK_BLEND_OP_SUBTRACT:
+	case VK_BLEND_OP_REVERSE_SUBTRACT:
+		return blendState[index].sourceBlendFactorAlpha;
+	case VK_BLEND_OP_MIN:
+		return VK_BLEND_FACTOR_ONE;
+	case VK_BLEND_OP_MAX:
+		return VK_BLEND_FACTOR_ONE;
+	default:
+		ASSERT(false);
 	}
 
-	bool Context::colorUsed() const
+	return blendState[index].sourceBlendFactorAlpha;
+}
+
+VkBlendFactor Context::destBlendFactorAlpha(int index) const
+{
+	ASSERT((index >= 0) && (index < RENDERTARGETS));
+
+	switch (blendState[index].blendOperationAlpha)
 	{
-		return colorWriteActive() || (pixelShader && pixelShader->getModes().ContainsKill);
+	case VK_BLEND_OP_ADD:
+	case VK_BLEND_OP_SUBTRACT:
+	case VK_BLEND_OP_REVERSE_SUBTRACT:
+		return blendState[index].destBlendFactorAlpha;
+	case VK_BLEND_OP_MIN:
+		return VK_BLEND_FACTOR_ONE;
+	case VK_BLEND_OP_MAX:
+		return VK_BLEND_FACTOR_ONE;
+	default:
+		ASSERT(false);
+	}
+
+	return blendState[index].destBlendFactorAlpha;
+}
+
+VkBlendOp Context::blendOperationAlpha(int index) const
+{
+	ASSERT((index >= 0) && (index < RENDERTARGETS));
+
+	switch (blendState[index].blendOperationAlpha)
+	{
+	case VK_BLEND_OP_ADD:
+		if (sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
+		{
+			if (destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
+			{
+				return VK_BLEND_OP_ZERO_EXT;
+			}
+			else
+			{
+				return VK_BLEND_OP_DST_EXT;
+			}
+		}
+		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_ADD;
+			}
+		}
+		else
+		{
+			if (destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO)
+			{
+				return VK_BLEND_OP_SRC_EXT;
+			}
+			else
+			{
+				return VK_BLEND_OP_ADD;
+			}
+		}
+	case VK_BLEND_OP_SUBTRACT:
+		if (sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
+		{
+			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
+			{
+				return VK_BLEND_OP_DST_EXT;
+			}
+		}
+		else if (sourceBlendFactorAlpha(index) == VK_BLEND_FACTOR_ONE)
+		{
+			if (destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
+			{
+				return VK_BLEND_OP_ZERO_EXT;   // Negative, clamped to zero
+			}
+			else
+			{
+				return VK_BLEND_OP_REVERSE_SUBTRACT;
+			}
+		}
+		else
+		{
+			if (destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ZERO && allTargetsColorClamp())
+			{
+				return VK_BLEND_OP_ZERO_EXT;   // Negative, clamped to zero
+			}
+			else
+			{
+				return VK_BLEND_OP_REVERSE_SUBTRACT;
+			}
+		}
+	case VK_BLEND_OP_MIN:
+		return VK_BLEND_OP_MIN;
+	case VK_BLEND_OP_MAX:
+		return VK_BLEND_OP_MAX;
+	default:
+		ASSERT(false);
+	}
+
+	return blendState[index].blendOperationAlpha;
+}
+
+VkFormat Context::renderTargetInternalFormat(int index) const
+{
+	ASSERT((index >= 0) && (index < RENDERTARGETS));
+
+	if(renderTarget[index])
+	{
+		return renderTarget[index]->getFormat();
+	}
+	else
+	{
+		return VK_FORMAT_UNDEFINED;
 	}
 }
+
+bool Context::colorWriteActive() const
+{
+	for (int i = 0; i < RENDERTARGETS; i++)
+	{
+		if (colorWriteActive(i))
+		{
+			return true;
+		}
+	}
+
+	return false;
+}
+
+int Context::colorWriteActive(int index) const
+{
+	ASSERT((index >= 0) && (index < RENDERTARGETS));
+
+	if(!renderTarget[index] || renderTarget[index]->getFormat() == VK_FORMAT_UNDEFINED)
+	{
+		return 0;
+	}
+
+	if(blendOperation(index) == VK_BLEND_OP_DST_EXT && destBlendFactor(index) == VK_BLEND_FACTOR_ONE &&
+	   (blendOperationAlpha(index) == VK_BLEND_OP_DST_EXT && destBlendFactorAlpha(index) == VK_BLEND_FACTOR_ONE))
+	{
+		return 0;
+	}
+
+	return colorWriteMask[index];
+}
+
+bool Context::colorUsed() const
+{
+	return colorWriteActive() || (pixelShader && pixelShader->getModes().ContainsKill);
+}
+
+}  // namespace sw