MVKPipeline: Don't rely on the index buffer to tell apart indexed draws.
This was a good heuristic, because the index buffer must be bound for
indexed draws. However, it may also be bound for non-indexed draws--for
example, if an indexed draw were immediately followed by a non-indexed
draw, as happens in some `dEQP-VK.synchronization.*` tests. Therefore,
we can't tell from the presence or absence of the index buffer what kind
of draw we're in. We'll have to keep track of this state in the command
encoder.
diff --git a/MoltenVK/MoltenVK/Commands/MVKCmdDraw.mm b/MoltenVK/MoltenVK/Commands/MVKCmdDraw.mm
index bd63403..5781936 100644
--- a/MoltenVK/MoltenVK/Commands/MVKCmdDraw.mm
+++ b/MoltenVK/MoltenVK/Commands/MVKCmdDraw.mm
@@ -108,6 +108,8 @@
return;
}
+ cmdEncoder->_isIndexedDraw = false;
+
auto* pipeline = (MVKGraphicsPipeline*)cmdEncoder->_graphicsPipelineState.getPipeline();
MVKPiplineStages stages;
@@ -302,6 +304,8 @@
return;
}
+ cmdEncoder->_isIndexedDraw = true;
+
auto* pipeline = (MVKGraphicsPipeline*)cmdEncoder->_graphicsPipelineState.getPipeline();
MVKPiplineStages stages;
@@ -510,6 +514,8 @@
void MVKCmdDrawIndirect::encode(MVKCommandEncoder* cmdEncoder) {
+ cmdEncoder->_isIndexedDraw = false;
+
auto* pipeline = (MVKGraphicsPipeline*)cmdEncoder->_graphicsPipelineState.getPipeline();
bool needsInstanceAdjustment = cmdEncoder->getSubpass()->isMultiview() &&
cmdEncoder->getDevice()->getPhysicalDevice()->canUseInstancingForMultiview();
@@ -820,6 +826,8 @@
void MVKCmdDrawIndexedIndirect::encode(MVKCommandEncoder* cmdEncoder) {
+ cmdEncoder->_isIndexedDraw = true;
+
MVKIndexMTLBufferBinding& ibb = cmdEncoder->_graphicsResourcesState._mtlIndexBufferBinding;
auto* pipeline = (MVKGraphicsPipeline*)cmdEncoder->_graphicsPipelineState.getPipeline();
bool needsInstanceAdjustment = cmdEncoder->getSubpass()->isMultiview() &&
diff --git a/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.h b/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.h
index 9002d59..9bcbd52 100644
--- a/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.h
+++ b/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.h
@@ -449,6 +449,9 @@
/** Indicates whether the current render subpass is able to render to an array (layered) framebuffer. */
bool _canUseLayeredRendering;
+ /** Indicates whether the current draw is an indexed draw. */
+ bool _isIndexedDraw;
+
#pragma mark Construction
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
index aa7f30d..1e07284 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm
@@ -207,7 +207,7 @@
id<MTLComputePipelineState> plState;
const MVKIndexMTLBufferBinding& indexBuff = cmdEncoder->_graphicsResourcesState._mtlIndexBufferBinding;
- if (!indexBuff.mtlBuffer) {
+ if (!cmdEncoder->_isIndexedDraw) {
plState = getTessVertexStageState();
} else if (indexBuff.mtlIndexType == MTLIndexTypeUInt16) {
plState = getTessVertexStageIndex16State();