Factor out vertex attribute binding from Draw*::play

I'm about to build some more on top of this; don't want to write it
multiple times.

Change-Id: I9ca84536f47b886e9f03edcaa6dc5dfe6e34091d
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/26688
Tested-by: Chris Forbes <chrisforbes@google.com>
Presubmit-Ready: Chris Forbes <chrisforbes@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
diff --git a/src/Vulkan/VkCommandBuffer.cpp b/src/Vulkan/VkCommandBuffer.cpp
index 2bf215d..f860482 100644
--- a/src/Vulkan/VkCommandBuffer.cpp
+++ b/src/Vulkan/VkCommandBuffer.cpp
@@ -185,6 +185,21 @@
 	const VkIndexType indexType;
 };
 
+void CommandBuffer::ExecutionState::bindVertexInputs(sw::Context& context, int firstVertex)
+{
+	for(uint32_t i = 0; i < MAX_VERTEX_INPUT_BINDINGS; i++)
+	{
+		auto &attrib = context.input[i];
+		if (attrib.count)
+		{
+			const auto &vertexInput = vertexInputBindings[attrib.binding];
+			Buffer *buffer = Cast(vertexInput.buffer);
+			attrib.buffer = buffer ? buffer->getOffsetPointer(
+					attrib.offset + vertexInput.offset + attrib.stride * firstVertex) : nullptr;
+		}
+	}
+}
+
 void CommandBuffer::ExecutionState::bindAttachments()
 {
 	// Binds all the attachments for the current subpass
@@ -230,17 +245,7 @@
 			executionState.pipelines[VK_PIPELINE_BIND_POINT_GRAPHICS]);
 
 		sw::Context context = pipeline->getContext();
-		for(uint32_t i = 0; i < MAX_VERTEX_INPUT_BINDINGS; i++)
-		{
-			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.bindVertexInputs(context, firstVertex);
 
 		context.pushConstants = executionState.pushConstants;
 
@@ -279,17 +284,7 @@
 				executionState.pipelines[VK_PIPELINE_BIND_POINT_GRAPHICS]);
 
 		sw::Context context = pipeline->getContext();
-		for(uint32_t i = 0; i < MAX_VERTEX_INPUT_BINDINGS; i++)
-		{
-			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 * vertexOffset) : nullptr;
-			}
-		}
+		executionState.bindVertexInputs(context, vertexOffset);
 
 		context.pushConstants = executionState.pushConstants;
 
diff --git a/src/Vulkan/VkCommandBuffer.hpp b/src/Vulkan/VkCommandBuffer.hpp
index 4f86071..66f9de0 100644
--- a/src/Vulkan/VkCommandBuffer.hpp
+++ b/src/Vulkan/VkCommandBuffer.hpp
@@ -23,6 +23,7 @@
 
 namespace sw
 {
+	class Context;
 	class Renderer;
 }
 
@@ -139,6 +140,7 @@
 		VkIndexType indexType;
 
 		void bindAttachments();
+		void bindVertexInputs(sw::Context& context, int firstVertex);
 	};
 
 	void submit(CommandBuffer::ExecutionState& executionState);