MVKCommandBuffer: Don't set renderTargetArrayLength on devices that don't support it.
It's a hard validation error to do so. We originally had a check for
this, but it was erroneously completely removed in #988, instead of
being limited to `renderTargetArrayLength`.
Fixes #991.
diff --git a/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm b/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm
index 0022a57..52b49a9 100644
--- a/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm
+++ b/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm
@@ -1035,7 +1035,7 @@
// Populate the render pipeline state attachment key with info from the subpass and framebuffer.
_rpsKey.mtlSampleCount = mvkSampleCountFromVkSampleCountFlagBits(subpass->getSampleCount());
- if (cmdEncoder->_isUsingLayeredRendering) { _rpsKey.enableLayeredRendering(); }
+ if (cmdEncoder->_canUseLayeredRendering && cmdEncoder->_framebuffer->getLayerCount() > 1) { _rpsKey.enableLayeredRendering(); }
uint32_t caCnt = subpass->getColorAttachmentCount();
for (uint32_t caIdx = 0; caIdx < caCnt; caIdx++) {
diff --git a/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.h b/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.h
index 54f6c9b..d841d97 100644
--- a/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.h
+++ b/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.h
@@ -432,8 +432,8 @@
/** The size of the threadgroup for the compute shader. */
MTLSize _mtlThreadgroupSize;
- /** Indicates whether the current render subpass is rendering to an array (layered) framebuffer. */
- bool _isUsingLayeredRendering;
+ /** Indicates whether the current render subpass is able to render to an array (layered) framebuffer. */
+ bool _canUseLayeredRendering;
#pragma mark Construction
diff --git a/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.mm b/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.mm
index c9e5bff..0aca31b 100644
--- a/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.mm
+++ b/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.mm
@@ -237,7 +237,7 @@
void MVKCommandEncoder::encode(id<MTLCommandBuffer> mtlCmdBuff) {
_subpassContents = VK_SUBPASS_CONTENTS_INLINE;
_renderSubpassIndex = 0;
- _isUsingLayeredRendering = false;
+ _canUseLayeredRendering = false;
_mtlCmdBuffer = mtlCmdBuff; // not retained
@@ -286,10 +286,9 @@
_subpassContents = subpassContents;
_renderSubpassIndex = subpassIndex;
- _isUsingLayeredRendering = ((_framebuffer->getLayerCount() > 1) &&
- _device->_pMetalFeatures->layeredRendering &&
- (_device->_pMetalFeatures->multisampleLayeredRendering ||
- (getSubpass()->getSampleCount() == VK_SAMPLE_COUNT_1_BIT)));
+ _canUseLayeredRendering = (_device->_pMetalFeatures->layeredRendering &&
+ (_device->_pMetalFeatures->multisampleLayeredRendering ||
+ (getSubpass()->getSampleCount() == VK_SAMPLE_COUNT_1_BIT)));
beginMetalRenderPass(loadOverride, storeOverride);
}
@@ -306,7 +305,9 @@
VkExtent2D fbExtent = _framebuffer->getExtent2D();
mtlRPDesc.renderTargetWidthMVK = min(_renderArea.offset.x + _renderArea.extent.width, fbExtent.width);
mtlRPDesc.renderTargetHeightMVK = min(_renderArea.offset.y + _renderArea.extent.height, fbExtent.height);
- mtlRPDesc.renderTargetArrayLengthMVK = _framebuffer->getLayerCount();
+ if (_canUseLayeredRendering) {
+ mtlRPDesc.renderTargetArrayLengthMVK = _framebuffer->getLayerCount();
+ }
_mtlRenderEncoder = [_mtlCmdBuffer renderCommandEncoderWithDescriptor: mtlRPDesc]; // not retained
setLabelIfNotNil(_mtlRenderEncoder, getMTLRenderCommandEncoderName());