OSDN Git Service

Support for instanceCount, firstVertex and firstInstance in Draw
authorAlexis Hetu <sugoi@google.com>
Thu, 24 Jan 2019 21:36:53 +0000 (16:36 -0500)
committerAlexis Hétu <sugoi@google.com>
Wed, 30 Jan 2019 15:01:16 +0000 (15:01 +0000)
The simple Draw command now supports all of the input parameters.

Bug b/118619338

Change-Id: I51c3680dcc6497296e00000ad3e80f302629af3c
Reviewed-on: https://swiftshader-review.googlesource.com/c/24049
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Chris Forbes <chrisforbes@google.com>
src/Vulkan/VkCommandBuffer.cpp

index 59f77fc..432edf9 100644 (file)
@@ -140,7 +140,8 @@ struct VertexBufferBind : public CommandBuffer::Command
 
 struct Draw : public CommandBuffer::Command
 {
-       Draw(uint32_t pVertexCount) : vertexCount(pVertexCount)
+       Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
+               : vertexCount(vertexCount), instanceCount(instanceCount), firstVertex(firstVertex), firstInstance(firstInstance)
        {
        }
 
@@ -154,7 +155,7 @@ struct Draw : public CommandBuffer::Command
                {
                        const auto& vertexInput = executionState.vertexInputBindings[i];
                        Buffer* buffer = Cast(vertexInput.buffer);
-                       context.input[i].buffer = buffer ? buffer->getOffsetPointer(vertexInput.offset) : nullptr;
+                       context.input[i].buffer = buffer ? buffer->getOffsetPointer(vertexInput.offset + context.input[i].stride * firstVertex) : nullptr;
                }
 
                executionState.renderer->setContext(context);
@@ -162,10 +163,19 @@ struct Draw : public CommandBuffer::Command
                executionState.renderer->setViewport(pipeline->getViewport());
                executionState.renderer->setBlendConstant(pipeline->getBlendConstants());
 
-               executionState.renderer->draw(context.drawType, 0, pipeline->computePrimitiveCount(vertexCount));
+               const uint32_t primitiveCount = pipeline->computePrimitiveCount(vertexCount);
+               const uint32_t lastInstance = firstInstance + instanceCount - 1;
+               for(uint32_t instance = firstInstance; instance <= lastInstance; instance++)
+               {
+                       executionState.renderer->setInstanceID(instance);
+                       executionState.renderer->draw(context.drawType, 0, primitiveCount);
+               }
        }
 
        uint32_t vertexCount;
+       uint32_t instanceCount;
+       uint32_t firstVertex;
+       uint32_t firstInstance;
 };
 
 struct ImageToImageCopy : public CommandBuffer::Command
@@ -737,12 +747,7 @@ void CommandBuffer::waitEvents(uint32_t eventCount, const VkEvent* pEvents, VkPi
 
 void CommandBuffer::draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex, uint32_t firstInstance)
 {
-       if(instanceCount > 1 || firstVertex != 0 || firstInstance != 0)
-       {
-               UNIMPLEMENTED();
-       }
-
-       addCommand<Draw>(vertexCount);
+       addCommand<Draw>(vertexCount, instanceCount, firstVertex, firstInstance);
 }
 
 void CommandBuffer::drawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t vertexOffset, uint32_t firstInstance)