OSDN Git Service

Factor out vertex attribute binding from Draw*::play
authorChris Forbes <chrisforbes@google.com>
Sat, 9 Mar 2019 01:10:41 +0000 (17:10 -0800)
committerChris Forbes <chrisforbes@google.com>
Wed, 20 Mar 2019 15:08:27 +0000 (15:08 +0000)
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>

src/Vulkan/VkCommandBuffer.cpp
src/Vulkan/VkCommandBuffer.hpp

index 2bf215d..f860482 100644 (file)
@@ -185,6 +185,21 @@ struct IndexBufferBind : public CommandBuffer::Command
        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 @@ struct Draw : public CommandBuffer::Command
                        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 @@ struct DrawIndexed : public CommandBuffer::Command
                                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;
 
index 4f86071..66f9de0 100644 (file)
@@ -23,6 +23,7 @@
 
 namespace sw
 {
+       class Context;
        class Renderer;
 }
 
@@ -139,6 +140,7 @@ public:
                VkIndexType indexType;
 
                void bindAttachments();
+               void bindVertexInputs(sw::Context& context, int firstVertex);
        };
 
        void submit(CommandBuffer::ExecutionState& executionState);