Fix bugs with VK_EXT_extended_dynamic_state2

Fragment states are no longer discarded if rasterizer discard can be set
dynamically.  Additonally, the dynamic state for primitive restart is
now taken into account.

Bug: b/204502923
Bug: b/246064773
Change-Id: I97e2da631ce307d6f9f58a4698dc947b90199d34
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/68129
Presubmit-Ready: Shahbaz Youssefi <syoussefi@google.com>
Commit-Queue: Shahbaz Youssefi <syoussefi@google.com>
Tested-by: Shahbaz Youssefi <syoussefi@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
diff --git a/src/Device/Context.cpp b/src/Device/Context.cpp
index 65b9d97..cf440af 100644
--- a/src/Device/Context.cpp
+++ b/src/Device/Context.cpp
@@ -498,7 +498,7 @@
 	sampleCount = 1;
 
 	// Only access rasterization state if rasterization is not disabled.
-	if(rasterizationState->rasterizerDiscardEnable == VK_FALSE)
+	if(rasterizationState->rasterizerDiscardEnable == VK_FALSE || dynamicStateFlags.dynamicRasterizerDiscardEnable)
 	{
 		const VkPipelineViewportStateCreateInfo *viewportState = pCreateInfo->pViewportState;
 		const VkPipelineMultisampleStateCreateInfo *multisampleState = pCreateInfo->pMultisampleState;
diff --git a/src/Device/Context.hpp b/src/Device/Context.hpp
index cbd4a0b..8263477 100644
--- a/src/Device/Context.hpp
+++ b/src/Device/Context.hpp
@@ -213,6 +213,7 @@
 
 	inline bool hasDynamicVertexStride() const { return dynamicStateFlags.dynamicVertexInputBindingStride; }
 	inline bool hasDynamicTopology() const { return dynamicStateFlags.dynamicPrimitiveTopology; }
+	inline bool hasDynamicPrimitiveRestartEnable() const { return dynamicStateFlags.dynamicPrimitiveRestartEnable; }
 
 private:
 	struct DynamicStateFlags
diff --git a/src/Vulkan/VkPipeline.cpp b/src/Vulkan/VkPipeline.cpp
index 07701c5..b7ec77e 100644
--- a/src/Vulkan/VkPipeline.cpp
+++ b/src/Vulkan/VkPipeline.cpp
@@ -350,8 +350,9 @@
 
 void GraphicsPipeline::getIndexBuffers(const vk::DynamicState &dynamicState, uint32_t count, uint32_t first, bool indexed, std::vector<std::pair<uint32_t, void *>> *indexBuffers) const
 {
-	VkPrimitiveTopology topology = state.hasDynamicTopology() ? dynamicState.primitiveTopology : state.getTopology();
-	indexBuffer.getIndexBuffers(topology, count, first, indexed, state.hasPrimitiveRestartEnable(), indexBuffers);
+	const VkPrimitiveTopology topology = state.hasDynamicTopology() ? dynamicState.primitiveTopology : state.getTopology();
+	const bool hasPrimitiveRestartEnable = state.hasDynamicPrimitiveRestartEnable() ? dynamicState.primitiveRestartEnable : state.hasPrimitiveRestartEnable();
+	indexBuffer.getIndexBuffers(topology, count, first, indexed, hasPrimitiveRestartEnable, indexBuffers);
 }
 
 bool GraphicsPipeline::containsImageWrite() const