Fix use-of-uninitialized-value issue for indexType

When rendering using a non indexed draw command, indexBufferBinding
and indexType are not set, but were unconditionally read when calling
setIndexBufferBinding(). They were subsequently unused, but we bypass
that code entirely if the draw isn't indexed.

Bug: b/262589275
Change-Id: I2007d88e039c9e6457428e126b87259b9bd0ca7a
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/70368
Tested-by: Alexis Hétu <sugoi@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexis Hétu <sugoi@google.com>
Presubmit-Ready: Alexis Hétu <sugoi@google.com>
Reviewed-by: Jonah Ryan-Davis <jonahr@google.com>
diff --git a/src/Device/Renderer.cpp b/src/Device/Renderer.cpp
index 12e4027..b79c740 100644
--- a/src/Device/Renderer.cpp
+++ b/src/Device/Renderer.cpp
@@ -262,7 +262,6 @@
 	draw->numBatches = (count + draw->numPrimitivesPerBatch - 1) / draw->numPrimitivesPerBatch;
 	draw->topology = vertexInputInterfaceState.getTopology();
 	draw->provokingVertexMode = preRasterizationState.getProvokingVertexMode();
-	draw->indexType = pipeline->getIndexBuffer().getIndexType();
 	draw->lineRasterizationMode = preRasterizationState.getLineRasterizationMode();
 	draw->descriptorSetObjects = inputs.getDescriptorSetObjects();
 	draw->preRasterizationPipelineLayout = preRasterizationState.getPipelineLayout();
@@ -287,6 +286,11 @@
 	data->instanceID = instanceID;
 	data->baseVertex = baseVertex;
 
+	if(indexBuffer)
+	{
+		draw->indexType = pipeline->getIndexBuffer().getIndexType();
+	}
+
 	draw->vertexRoutine = vertexRoutine;
 
 	vk::DescriptorSet::PrepareForSampling(draw->descriptorSetObjects, draw->preRasterizationPipelineLayout, device);
diff --git a/src/Vulkan/VkCommandBuffer.cpp b/src/Vulkan/VkCommandBuffer.cpp
index 3bfe933..5649c12 100644
--- a/src/Vulkan/VkCommandBuffer.cpp
+++ b/src/Vulkan/VkCommandBuffer.cpp
@@ -932,8 +932,11 @@
 		inputs.setVertexInputBinding(executionState.vertexInputBindings);
 		inputs.bindVertexInputs(firstInstance, hasDynamicVertexStride);
 
-		vk::IndexBuffer &indexBuffer = pipeline->getIndexBuffer();
-		indexBuffer.setIndexBufferBinding(executionState.indexBufferBinding, executionState.indexType);
+		if(indexed)
+		{
+			vk::IndexBuffer &indexBuffer = pipeline->getIndexBuffer();
+			indexBuffer.setIndexBufferBinding(executionState.indexBufferBinding, executionState.indexType);
+		}
 
 		std::vector<std::pair<uint32_t, void *>> indexBuffers;
 		pipeline->getIndexBuffers(executionState.dynamicState, count, first, indexed, &indexBuffers);