Pass draw-to-draw varying state directly to Renderer::draw
There is no reason to plumb this through Context.
Bug: b/132280877
Change-Id: I92819af587505b75b279a6aed70aa8067455df8d
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/35549
Reviewed-by: Nicolas Capens <nicolascapens@google.com>
Kokoro-Presubmit: kokoro <noreply+kokoro@google.com>
Tested-by: Chris Forbes <chrisforbes@google.com>
diff --git a/src/Device/Context.cpp b/src/Device/Context.cpp
index 14e4049..c0f8ec1 100644
--- a/src/Device/Context.cpp
+++ b/src/Device/Context.cpp
@@ -128,8 +128,6 @@
pixelShader = nullptr;
vertexShader = nullptr;
- instanceID = 0;
-
occlusionEnabled = false;
lineWidth = 1.0f;
diff --git a/src/Device/Context.hpp b/src/Device/Context.hpp
index 4f31d00..fa79416 100644
--- a/src/Device/Context.hpp
+++ b/src/Device/Context.hpp
@@ -82,7 +82,6 @@
vk::DescriptorSet::Bindings descriptorSets = {};
vk::DescriptorSet::DynamicOffsets descriptorDynamicOffsets = {};
Stream input[MAX_INTERFACE_COMPONENTS / 4];
- void *indexBuffer;
vk::ImageView *renderTarget[RENDERTARGETS];
vk::ImageView *depthBuffer;
@@ -94,10 +93,6 @@
const SpirvShader *pixelShader;
const SpirvShader *vertexShader;
- // Instancing
- int instanceID;
- int viewID;
-
bool occlusionEnabled;
// Pixel processor states
@@ -123,8 +118,6 @@
unsigned int multiSampleMask;
int sampleCount;
bool alphaToCoverage;
-
- PushConstantStorage pushConstants;
};
}
diff --git a/src/Device/Renderer.cpp b/src/Device/Renderer.cpp
index 4df1b3c..7030897 100644
--- a/src/Device/Renderer.cpp
+++ b/src/Device/Renderer.cpp
@@ -233,7 +233,9 @@
sw::deallocate(mem);
}
- void Renderer::draw(const sw::Context* context, VkIndexType indexType, unsigned int count, int baseVertex, TaskEvents *events, bool update)
+ void Renderer::draw(const sw::Context* context, VkIndexType indexType, unsigned int count, int baseVertex,
+ TaskEvents *events, int instanceID, int viewID, void *indexBuffer,
+ PushConstantStorage const & pushConstants, bool update)
{
if(count == 0) { return; }
@@ -347,10 +349,9 @@
data->stride[i] = context->input[i].vertexStride;
}
- data->indices = context->indexBuffer;
- data->viewID = context->viewID;
- data->instanceID = context->instanceID;
-
+ data->indices = indexBuffer;
+ data->viewID = viewID;
+ data->instanceID = instanceID;
data->baseVertex = baseVertex;
if(pixelState.stencilActive)
@@ -457,7 +458,7 @@
// Push constants
{
- data->pushConstants = context->pushConstants;
+ data->pushConstants = pushConstants;
}
draw->primitive = 0;
diff --git a/src/Device/Renderer.hpp b/src/Device/Renderer.hpp
index a8fb74a..e714d37 100644
--- a/src/Device/Renderer.hpp
+++ b/src/Device/Renderer.hpp
@@ -167,7 +167,9 @@
bool hasOcclusionQuery() const { return occlusionQuery != nullptr; }
- void draw(const sw::Context* context, VkIndexType indexType, unsigned int count, int baseVertex, TaskEvents *events, bool update = true);
+ void draw(const sw::Context* context, VkIndexType indexType, unsigned int count, int baseVertex,
+ TaskEvents *events, int instanceID, int viewID, void *indexBuffer,
+ PushConstantStorage const & pushConstants, bool update = true);
// Viewport & Clipper
void setViewport(const VkViewport &viewport);
diff --git a/src/Vulkan/VkCommandBuffer.cpp b/src/Vulkan/VkCommandBuffer.cpp
index bad25fc..34e17b0 100644
--- a/src/Vulkan/VkCommandBuffer.cpp
+++ b/src/Vulkan/VkCommandBuffer.cpp
@@ -523,7 +523,6 @@
context.descriptorSets = pipelineState.descriptorSets;
context.descriptorDynamicOffsets = pipelineState.descriptorDynamicOffsets;
- context.pushConstants = executionState.pushConstants;
// Apply either pipeline state or dynamic state
executionState.renderer->setScissor(pipeline->hasDynamicState(VK_DYNAMIC_STATE_SCISSOR) ?
@@ -569,7 +568,6 @@
executionState.bindAttachments(context);
- context.multiSampleMask = context.sampleMask & ((unsigned) 0xFFFFFFFF >> (32 - context.sampleCount));
context.occlusionEnabled = executionState.renderer->hasOcclusionQuery();
std::vector<std::pair<uint32_t, void *>> indexBuffers;
@@ -603,21 +601,18 @@
for (uint32_t instance = firstInstance; instance != firstInstance + instanceCount; instance++)
{
- context.instanceID = instance;
-
// FIXME: reconsider instances/views nesting.
auto viewMask = executionState.renderPass->getViewMask(executionState.subpassIndex);
while (viewMask)
{
- context.viewID = sw::log2i(viewMask);
- viewMask &= ~(1 << context.viewID);
+ int viewID = sw::log2i(viewMask);
+ viewMask &= ~(1 << viewID);
for (auto indexBuffer : indexBuffers)
{
- const uint32_t primitiveCount = indexBuffer.first;
- context.indexBuffer = indexBuffer.second;
- executionState.renderer->draw(&context, executionState.indexType, primitiveCount, vertexOffset,
- executionState.events);
+ executionState.renderer->draw(&context, executionState.indexType, indexBuffer.first, vertexOffset,
+ executionState.events, instance, viewID, indexBuffer.second,
+ executionState.pushConstants);
}
}
diff --git a/src/Vulkan/VkPipeline.cpp b/src/Vulkan/VkPipeline.cpp
index 5558223..31c0ebf 100644
--- a/src/Vulkan/VkPipeline.cpp
+++ b/src/Vulkan/VkPipeline.cpp
@@ -478,6 +478,8 @@
context.sourceBlendFactorState = attachment.srcColorBlendFactor;
}
}
+
+ context.multiSampleMask = context.sampleMask & ((unsigned) 0xFFFFFFFF >> (32 - context.sampleCount));
}
void GraphicsPipeline::destroyPipeline(const VkAllocationCallbacks* pAllocator)