Initialize the blend state using memset

The BlendState structure is part of the cache key used to look up pixel
routines, which must not contain any uninitialized bits. The
PixelProcessor::States structure gets zero-initialized as a whole by
the Memset<> base class, but when writing BlendState structures into it
any uninitialized bits may get copied over.

Thus BlendState must also be zero-initialized, using Memset<>.

Bug: b/140286664
Bug: b/140193782
Change-Id: I031ec1a5f3be4329ae16366bfd4c8f17e2371384
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/35768
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
diff --git a/src/Device/Context.cpp b/src/Device/Context.cpp
index af55417..f517e6b 100644
--- a/src/Device/Context.cpp
+++ b/src/Device/Context.cpp
@@ -24,19 +24,6 @@
 
 namespace sw
 {
-	void BlendState::init()
-	{
-		alphaBlendEnable = false;
-
-		sourceBlendFactor = VK_BLEND_FACTOR_ONE;
-		destBlendFactor = VK_BLEND_FACTOR_ZERO;
-		blendOperation = VK_BLEND_OP_ADD;
-
-		sourceBlendFactorAlpha = VK_BLEND_FACTOR_ONE;
-		destBlendFactorAlpha = VK_BLEND_FACTOR_ZERO;
-		blendOperationAlpha = VK_BLEND_OP_ADD;
-	}
-
 	Context::Context()
 	{
 		init();
@@ -101,9 +88,8 @@
 		for(int i = 0; i < RENDERTARGETS; ++i)
 		{
 			renderTarget[i] = nullptr;
-
-			blendState[i].init();
 		}
+
 		depthBuffer = nullptr;
 		stencilBuffer = nullptr;
 
diff --git a/src/Device/Context.hpp b/src/Device/Context.hpp
index 502eacf..c86d956 100644
--- a/src/Device/Context.hpp
+++ b/src/Device/Context.hpp
@@ -18,6 +18,7 @@
 #include "Vulkan/VkConfig.h"
 #include "Vulkan/VkDescriptorSet.hpp"
 #include "Config.hpp"
+#include "Memset.hpp"
 #include "Stream.hpp"
 #include "System/Types.hpp"
 
@@ -36,9 +37,26 @@
 		unsigned char data[vk::MAX_PUSH_CONSTANT_SIZE];
 	};
 
-	struct BlendState
+	struct BlendState : Memset<BlendState>
 	{
-		void init();
+		BlendState() : Memset(this, 0) {}
+
+		BlendState(bool alphaBlendEnable,
+		           VkBlendFactor sourceBlendFactor,
+		           VkBlendFactor destBlendFactor,
+		           VkBlendOp blendOperation,
+		           VkBlendFactor sourceBlendFactorAlpha,
+		           VkBlendFactor destBlendFactorAlpha,
+		           VkBlendOp blendOperationAlpha) :
+			Memset(this, 0),
+			alphaBlendEnable(alphaBlendEnable),
+			sourceBlendFactor(sourceBlendFactor),
+			destBlendFactor(destBlendFactor),
+			blendOperation(blendOperation),
+			sourceBlendFactorAlpha(sourceBlendFactorAlpha),
+			destBlendFactorAlpha(destBlendFactorAlpha),
+			blendOperationAlpha(blendOperationAlpha)
+		{}
 
 		bool alphaBlendEnable;
 		VkBlendFactor sourceBlendFactor;