Value-initialize all vk::GraphicsState members

The vk::GraphicsState constructor does not initialize all members in all
code paths. We were relying on the zero-initializing done by
vk::allocate() which is used to allocate vk::GraphicsPipeline which in
turn contains a GraphicsState member.

We want to change vk::allocate() to no longer zero-initialize all
memory, to catch more MemorySanitizer errors made by applications. Thus
we must also not rely on such automatic initialization ourselves.

Note that this change might also hide MemorySantizer violations
committed by the application side. For example some state is only copied
from VkGraphicsPipelineCreateInfo into vk::GraphicsState on construction
when flags indicate they're not dynamic state. If the application
forgets to makerecord commands that set the dynamic state, their value
is undefined:

Vulkan 1.2.178 section 6. Command Buffers:
"When a command buffer begins recording, all state in that command
buffer is undefined."

Vulkan 1.2.178 section 10.11. Dynamic State:
"If the state is specified as dynamic in the new pipeline object, then
that command buffer state is not disturbed. Before any draw or dispatch
call with this pipeline there must have been at least one call to each
of the corresponding dynamic state setting commands since the command
buffer recording was begun, or the last bound pipeline object with that
state specified as static, whichever was the latter."

Thus once sw::allocate() no longer also zeroes this data, we should
revert the value-initialization where possible and ensure we don't
touch the uninitialized data ourselves, unless as a consequence of an
application bug.

Bug: b/140991626
Change-Id: I060e8d8a79e93b0676669eed361fab4f86ab1b56
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/53089
Presubmit-Ready: Nicolas Capens <nicolascapens@google.com>
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.hpp b/src/Device/Context.hpp
index 4c30b0e..d9475cd 100644
--- a/src/Device/Context.hpp
+++ b/src/Device/Context.hpp
@@ -204,55 +204,55 @@
 	bool alphaBlendActive(int index, const Attachments &attachments, bool fragmentContainsKill) const;
 	bool colorWriteActive(const Attachments &attachments) const;
 
-	const PipelineLayout *pipelineLayout;
-	const bool robustBufferAccess = true;
+	const PipelineLayout *pipelineLayout = nullptr;
+	const bool robustBufferAccess = false;
 	uint32_t dynamicStateFlags = 0;
-	VkPrimitiveTopology topology;
+	VkPrimitiveTopology topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
 
-	VkProvokingVertexModeEXT provokingVertexMode;
+	VkProvokingVertexModeEXT provokingVertexMode = VK_PROVOKING_VERTEX_MODE_FIRST_VERTEX_EXT;
 
-	bool stencilEnable;
-	VkStencilOpState frontStencil;
-	VkStencilOpState backStencil;
+	bool stencilEnable = false;
+	VkStencilOpState frontStencil = {};
+	VkStencilOpState backStencil = {};
 
 	// Pixel processor states
-	VkCullModeFlags cullMode;
-	VkFrontFace frontFace;
-	VkPolygonMode polygonMode;
-	VkLineRasterizationModeEXT lineRasterizationMode;
+	VkCullModeFlags cullMode = 0;
+	VkFrontFace frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
+	VkPolygonMode polygonMode = VK_POLYGON_MODE_FILL;
+	VkLineRasterizationModeEXT lineRasterizationMode = VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT;
 
-	float constantDepthBias;
-	float slopeDepthBias;
-	float depthBiasClamp;
-	float minDepthBounds;
-	float maxDepthBounds;
-	bool depthRangeUnrestricted;
+	float constantDepthBias = 0.0f;
+	float slopeDepthBias = 0.0f;
+	float depthBiasClamp = 0.0f;
+	float minDepthBounds = 0.0f;
+	float maxDepthBounds = 0.0f;
+	bool depthRangeUnrestricted = false;
 
 	// Pixel processor states
-	bool rasterizerDiscard;
-	bool depthBoundsTestEnable;
-	bool depthBufferEnable;
-	VkCompareOp depthCompareMode;
-	bool depthWriteEnable;
-	bool depthClampEnable;
-	bool depthClipEnable;
+	bool rasterizerDiscard = false;
+	bool depthBoundsTestEnable = false;
+	bool depthBufferEnable = false;
+	VkCompareOp depthCompareMode = VK_COMPARE_OP_NEVER;
+	bool depthWriteEnable = false;
+	bool depthClampEnable = false;
+	bool depthClipEnable = false;
 
-	float lineWidth;
+	float lineWidth = 0.0f;
 
-	int colorWriteMask[sw::RENDERTARGETS];  // RGBA
-	unsigned int multiSampleMask;
-	int sampleCount;
-	bool alphaToCoverage;
+	int colorWriteMask[sw::RENDERTARGETS] = {};  // RGBA
+	unsigned int multiSampleMask = 0;
+	int sampleCount = 0;
+	bool alphaToCoverage = false;
 
 	bool sampleShadingEnable = false;
 	float minSampleShading = 0.0f;
 
 	bool primitiveRestartEnable = false;
-	VkRect2D scissor;
-	VkViewport viewport;
-	sw::float4 blendConstants;
+	VkRect2D scissor = {};
+	VkViewport viewport = {};
+	sw::float4 blendConstants = {};
 
-	BlendState blendState[sw::RENDERTARGETS];
+	BlendState blendState[sw::RENDERTARGETS] = {};
 };
 
 }  // namespace vk