From 07c2054cc866b2ca7285a437b38c903c6410fdca Mon Sep 17 00:00:00 2001 From: Chip Davis Date: Thu, 13 Aug 2020 14:39:18 -0500 Subject: [PATCH] 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. --- MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm | 2 +- MoltenVK/MoltenVK/Commands/MVKCommandBuffer.h | 4 ++-- MoltenVK/MoltenVK/Commands/MVKCommandBuffer.mm | 13 +++++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm b/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm index 0022a577..52b49a99 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm +++ b/MoltenVK/MoltenVK/Commands/MVKCmdTransfer.mm @@ -1035,7 +1035,7 @@ void MVKCmdClearAttachments::encode(MVKCommandEncoder* cmdEncoder) { // 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 54f6c9b6..d841d978 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.h +++ b/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.h @@ -432,8 +432,8 @@ public: /** 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 c9e5bffd..0aca31b2 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.mm +++ b/MoltenVK/MoltenVK/Commands/MVKCommandBuffer.mm @@ -237,7 +237,7 @@ void MVKCommandBuffer::recordDraw(MVKLoadStoreOverrideMixin* mvkDraw) { void MVKCommandEncoder::encode(id mtlCmdBuff) { _subpassContents = VK_SUBPASS_CONTENTS_INLINE; _renderSubpassIndex = 0; - _isUsingLayeredRendering = false; + _canUseLayeredRendering = false; _mtlCmdBuffer = mtlCmdBuff; // not retained @@ -286,10 +286,9 @@ void MVKCommandEncoder::setSubpass(VkSubpassContents subpassContents, uint32_t s _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 @@ void MVKCommandEncoder::beginMetalRenderPass(bool loadOverride, bool storeOverri 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());