Pass baseVertex to vertex shader
Bug: b/118386749
Test: dEQP-VK.draw.*
Change-Id: I6064e47825f1dcc2a910fe4be933868a4f3835b5
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/29169
Tested-by: Chris Forbes <chrisforbes@google.com>
Presubmit-Ready: Chris Forbes <chrisforbes@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Device/Renderer.cpp b/src/Device/Renderer.cpp
index 245f219..a3cdac7 100644
--- a/src/Device/Renderer.cpp
+++ b/src/Device/Renderer.cpp
@@ -296,7 +296,7 @@
sw::deallocate(mem);
}
- void Renderer::draw(VkPrimitiveTopology topology, VkIndexType indexType, unsigned int count, bool update)
+ void Renderer::draw(VkPrimitiveTopology topology, VkIndexType indexType, unsigned int count, int baseVertex, bool update)
{
#ifndef NDEBUG
if(count < minPrimitives || count > maxPrimitives)
@@ -425,6 +425,8 @@
data->instanceID = context->instanceID;
}
+ data->baseVertex = baseVertex;
+
if(pixelState.stencilActive)
{
data->stencil[0].set(context->frontStencil.reference, context->frontStencil.compareMask, context->frontStencil.writeMask);
diff --git a/src/Device/Renderer.hpp b/src/Device/Renderer.hpp
index 4a594ad..32301f7 100644
--- a/src/Device/Renderer.hpp
+++ b/src/Device/Renderer.hpp
@@ -99,6 +99,7 @@
const void *indices;
int instanceID;
+ int baseVertex;
float lineWidth;
PixelProcessor::Stencil stencil[2]; // clockwise, counterclockwise
@@ -202,7 +203,7 @@
void *operator new(size_t size);
void operator delete(void * mem);
- void draw(VkPrimitiveTopology topology, VkIndexType indexType, unsigned int count, bool update = true);
+ void draw(VkPrimitiveTopology topology, VkIndexType indexType, unsigned int count, int baseVertex, bool update = true);
void setContext(const sw::Context& context);
diff --git a/src/Pipeline/VertexProgram.cpp b/src/Pipeline/VertexProgram.cpp
index 6ea04f2..ea840f0 100644
--- a/src/Pipeline/VertexProgram.cpp
+++ b/src/Pipeline/VertexProgram.cpp
@@ -57,7 +57,7 @@
{
assert(it->second.SizeInComponents == 1);
routine.getVariable(it->second.Id)[it->second.FirstComponent] =
- As<Float4>(Int4(index) + Int4(0, 1, 2, 3));
+ As<Float4>(Int4(As<Int>(index) + *Pointer<Int>(data + OFFSET(DrawData, baseVertex))) + Int4(0, 1, 2, 3));
}
auto activeLaneMask = SIMD::Int(0xFFFFFFFF); // TODO: Control this.
diff --git a/src/Vulkan/VkCommandBuffer.cpp b/src/Vulkan/VkCommandBuffer.cpp
index 34be31f..b713275 100644
--- a/src/Vulkan/VkCommandBuffer.cpp
+++ b/src/Vulkan/VkCommandBuffer.cpp
@@ -523,7 +523,7 @@
for(uint32_t instance = firstInstance; instance != firstInstance + instanceCount; instance++)
{
executionState.renderer->setInstanceID(instance);
- executionState.renderer->draw(context.topology, executionState.indexType, primitiveCount);
+ executionState.renderer->draw(context.topology, executionState.indexType, primitiveCount, vertexOffset);
executionState.renderer->advanceInstanceAttributes();
}
}