Fix various issues in vertex fetch setup

There are still some minor sins in here -- we should really unfuse
attributes from buffers completely -- but this is enough to have vertex
fetch work for all per-vertex attribute scenarios.

Bug: b/124177079

Change-Id: I2a7a1a6f049aa80c1a527e9fa9643bb33701d165
Reviewed-on: https://swiftshader-review.googlesource.com/c/25448
Reviewed-by: Alexis Hétu <sugoi@google.com>
Tested-by: Chris Forbes <chrisforbes@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Vulkan/VkCommandBuffer.cpp b/src/Vulkan/VkCommandBuffer.cpp
index 4578fe5..5113021 100644
--- a/src/Vulkan/VkCommandBuffer.cpp
+++ b/src/Vulkan/VkCommandBuffer.cpp
@@ -155,9 +155,14 @@
 		sw::Context context = pipeline->getContext();
 		for(uint32_t i = 0; i < MAX_VERTEX_INPUT_BINDINGS; i++)
 		{
-			const auto& vertexInput = executionState.vertexInputBindings[i];
-			Buffer* buffer = Cast(vertexInput.buffer);
-			context.input[i].buffer = buffer ? buffer->getOffsetPointer(vertexInput.offset + context.input[i].stride * firstVertex) : nullptr;
+			auto &attrib = context.input[i];
+			if (attrib.count)
+			{
+				const auto &vertexInput = executionState.vertexInputBindings[attrib.binding];
+				Buffer *buffer = Cast(vertexInput.buffer);
+				attrib.buffer = buffer ? buffer->getOffsetPointer(
+						attrib.offset + vertexInput.offset + attrib.stride * firstVertex) : nullptr;
+			}
 		}
 
 		executionState.renderer->setContext(context);
@@ -567,9 +572,9 @@
 void CommandBuffer::bindVertexBuffers(uint32_t firstBinding, uint32_t bindingCount,
                                       const VkBuffer* pBuffers, const VkDeviceSize* pOffsets)
 {
-	for(uint32_t i = firstBinding; i < (firstBinding + bindingCount); ++i)
+	for(uint32_t i = 0; i < bindingCount; ++i)
 	{
-		addCommand<VertexBufferBind>(i, pBuffers[i], pOffsets[i]);
+		addCommand<VertexBufferBind>(i + firstBinding, pBuffers[i], pOffsets[i]);
 	}
 }