Support for instanceCount, firstVertex and firstInstance in Draw 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>
diff --git a/src/Vulkan/VkCommandBuffer.cpp b/src/Vulkan/VkCommandBuffer.cpp index 59f77fc..432edf9 100644 --- a/src/Vulkan/VkCommandBuffer.cpp +++ b/src/Vulkan/VkCommandBuffer.cpp
@@ -140,7 +140,8 @@ 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 @@ { 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 @@ 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::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)