From 1b6750bef837377ce10f6d9cb19202c715d1d724 Mon Sep 17 00:00:00 2001 From: Evan Tang Date: Wed, 10 May 2023 14:48:31 -0500 Subject: [PATCH] Respect the bind point supplied to vkCmdBindDescriptorSets --- MoltenVK/MoltenVK/Commands/MVKCmdPipeline.mm | 2 +- MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.h | 10 ++ MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.mm | 120 ++++++------------ .../MoltenVK/GPUObjects/MVKDescriptorSet.h | 5 + .../MoltenVK/GPUObjects/MVKDescriptorSet.mm | 10 +- MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h | 1 + MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm | 3 +- 7 files changed, 64 insertions(+), 87 deletions(-) diff --git a/MoltenVK/MoltenVK/Commands/MVKCmdPipeline.mm b/MoltenVK/MoltenVK/Commands/MVKCmdPipeline.mm index d68d4f81c..3efcab53c 100644 --- a/MoltenVK/MoltenVK/Commands/MVKCmdPipeline.mm +++ b/MoltenVK/MoltenVK/Commands/MVKCmdPipeline.mm @@ -393,7 +393,7 @@ } void MVKCmdPushDescriptorSet::encode(MVKCommandEncoder* cmdEncoder) { - _pipelineLayout->pushDescriptorSet(cmdEncoder, _descriptorWrites.contents(), _set); + _pipelineLayout->pushDescriptorSet(cmdEncoder, _pipelineBindPoint, _descriptorWrites.contents(), _set); } MVKCmdPushDescriptorSet::~MVKCmdPushDescriptorSet() { diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.h b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.h index 229b65dc8..d3851e6a9 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.h +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.h @@ -120,6 +120,7 @@ class MVKDescriptorSetLayoutBinding : public MVKBaseDeviceObject { /** Encodes the descriptors in the descriptor set that are specified by this layout, */ void bind(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKDescriptorSet* descSet, MVKShaderResourceBinding& dslMTLRezIdxOffsets, MVKArrayRef dynamicOffsets, @@ -127,6 +128,7 @@ class MVKDescriptorSetLayoutBinding : public MVKBaseDeviceObject { /** Encodes this binding layout and the specified descriptor on the specified command encoder immediately. */ void push(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, uint32_t& dstArrayElement, uint32_t& descriptorCount, uint32_t& descriptorsPushed, @@ -207,6 +209,7 @@ class MVKDescriptor : public MVKBaseObject { /** Encodes this descriptor (based on its layout binding index) on the the command encoder. */ virtual void bind(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKDescriptorSetLayoutBinding* mvkDSLBind, uint32_t elementIndex, bool stages[], @@ -273,6 +276,7 @@ class MVKBufferDescriptor : public MVKDescriptor { public: void bind(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKDescriptorSetLayoutBinding* mvkDSLBind, uint32_t elementIndex, bool stages[], @@ -362,6 +366,7 @@ class MVKInlineUniformBlockDescriptor : public MVKDescriptor { VkDescriptorType getDescriptorType() override { return VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT; } void bind(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKDescriptorSetLayoutBinding* mvkDSLBind, uint32_t elementIndex, bool stages[], @@ -411,6 +416,7 @@ class MVKImageDescriptor : public MVKDescriptor { public: void bind(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKDescriptorSetLayoutBinding* mvkDSLBind, uint32_t elementIndex, bool stages[], @@ -491,6 +497,7 @@ class MVKSamplerDescriptorMixin { protected: void bind(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKDescriptorSetLayoutBinding* mvkDSLBind, uint32_t elementIndex, bool stages[], @@ -538,6 +545,7 @@ class MVKSamplerDescriptor : public MVKDescriptor, public MVKSamplerDescriptorMi VkDescriptorType getDescriptorType() override { return VK_DESCRIPTOR_TYPE_SAMPLER; } void bind(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKDescriptorSetLayoutBinding* mvkDSLBind, uint32_t elementIndex, bool stages[], @@ -585,6 +593,7 @@ class MVKCombinedImageSamplerDescriptor : public MVKImageDescriptor, public MVKS VkDescriptorType getDescriptorType() override { return VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER; } void bind(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKDescriptorSetLayoutBinding* mvkDSLBind, uint32_t elementIndex, bool stages[], @@ -630,6 +639,7 @@ class MVKTexelBufferDescriptor : public MVKDescriptor { public: void bind(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKDescriptorSetLayoutBinding* mvkDSLBind, uint32_t elementIndex, bool stages[], diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.mm index c13296d20..a3f02ea89 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptor.mm @@ -20,6 +20,16 @@ #include "MVKDescriptorSet.h" #include "MVKBuffer.h" +#define BIND_GRAPHICS_OR_COMPUTE(cmdEncoder, bind, pipelineBindPoint, stage, ...) \ + do { \ + if ((stage) == kMVKShaderStageCompute) { \ + if ((cmdEncoder) && (pipelineBindPoint) == VK_PIPELINE_BIND_POINT_COMPUTE) \ + (cmdEncoder)->_computeResourcesState.bind(__VA_ARGS__); \ + } else { \ + if ((cmdEncoder) && (pipelineBindPoint) == VK_PIPELINE_BIND_POINT_GRAPHICS) \ + (cmdEncoder)->_graphicsResourcesState.bind(static_cast(stage), __VA_ARGS__); \ + } \ + } while (0) #pragma mark MVKShaderStageResourceBinding @@ -195,6 +205,7 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s // A null cmdEncoder can be passed to perform a validation pass void MVKDescriptorSetLayoutBinding::bind(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKDescriptorSet* descSet, MVKShaderResourceBinding& dslMTLRezIdxOffsets, MVKArrayRef dynamicOffsets, @@ -208,7 +219,7 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s for (uint32_t descIdx = 0; descIdx < descCnt; descIdx++) { MVKDescriptor* mvkDesc = descSet->getDescriptor(getBinding(), descIdx); if (mvkDesc->getDescriptorType() == descType) { - mvkDesc->bind(cmdEncoder, this, descIdx, _applyToStage, mtlIdxs, dynamicOffsets, dynamicOffsetIndex); + mvkDesc->bind(cmdEncoder, pipelineBindPoint, this, descIdx, _applyToStage, mtlIdxs, dynamicOffsets, dynamicOffsetIndex); } } } @@ -220,6 +231,7 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s // A null cmdEncoder can be passed to perform a validation pass void MVKDescriptorSetLayoutBinding::push(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, uint32_t& dstArrayElement, uint32_t& descriptorCount, uint32_t& descriptorsPushed, @@ -271,11 +283,7 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s for (uint32_t i = kMVKShaderStageVertex; i < kMVKShaderStageCount; i++) { if (_applyToStage[i]) { bb.index = mtlIdxs.stages[i].bufferIndex + rezIdx; - if (i == kMVKShaderStageCompute) { - if (cmdEncoder) { cmdEncoder->_computeResourcesState.bindBuffer(bb); } - } else { - if (cmdEncoder) { cmdEncoder->_graphicsResourcesState.bindBuffer(MVKShaderStage(i), bb); } - } + BIND_GRAPHICS_OR_COMPUTE(cmdEncoder, bindBuffer, pipelineBindPoint, i, bb); } } break; @@ -289,11 +297,7 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s for (uint32_t i = kMVKShaderStageVertex; i < kMVKShaderStageCount; i++) { if (_applyToStage[i]) { bb.index = mtlIdxs.stages[i].bufferIndex; - if (i == kMVKShaderStageCompute) { - if (cmdEncoder) { cmdEncoder->_computeResourcesState.bindBuffer(bb); } - } else { - if (cmdEncoder) { cmdEncoder->_graphicsResourcesState.bindBuffer(MVKShaderStage(i), bb); } - } + BIND_GRAPHICS_OR_COMPUTE(cmdEncoder, bindBuffer, pipelineBindPoint, i, bb); } } break; @@ -318,18 +322,10 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s for (uint32_t i = kMVKShaderStageVertex; i < kMVKShaderStageCount; i++) { if (_applyToStage[i]) { tb.index = mtlIdxs.stages[i].textureIndex + rezIdx + planeIndex; - if (i == kMVKShaderStageCompute) { - if (cmdEncoder) { cmdEncoder->_computeResourcesState.bindTexture(tb); } - } else { - if (cmdEncoder) { cmdEncoder->_graphicsResourcesState.bindTexture(MVKShaderStage(i), tb); } - } + BIND_GRAPHICS_OR_COMPUTE(cmdEncoder, bindTexture, pipelineBindPoint, i, tb); if (_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) { bb.index = mtlIdxs.stages[i].bufferIndex + rezIdx; - if (i == kMVKShaderStageCompute) { - if (cmdEncoder) { cmdEncoder->_computeResourcesState.bindBuffer(bb); } - } else { - if (cmdEncoder) { cmdEncoder->_graphicsResourcesState.bindBuffer(MVKShaderStage(i), bb); } - } + BIND_GRAPHICS_OR_COMPUTE(cmdEncoder, bindBuffer, pipelineBindPoint, i, bb); } } } @@ -351,18 +347,10 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s for (uint32_t i = kMVKShaderStageVertex; i < kMVKShaderStageCount; i++) { if (_applyToStage[i]) { tb.index = mtlIdxs.stages[i].textureIndex + rezIdx; - if (i == kMVKShaderStageCompute) { - if (cmdEncoder) { cmdEncoder->_computeResourcesState.bindTexture(tb); } - } else { - if (cmdEncoder) { cmdEncoder->_graphicsResourcesState.bindTexture(MVKShaderStage(i), tb); } - } + BIND_GRAPHICS_OR_COMPUTE(cmdEncoder, bindTexture, pipelineBindPoint, i, tb); if (_info.descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER) { bb.index = mtlIdxs.stages[i].bufferIndex + rezIdx; - if (i == kMVKShaderStageCompute) { - if (cmdEncoder) { cmdEncoder->_computeResourcesState.bindBuffer(bb); } - } else { - if (cmdEncoder) { cmdEncoder->_graphicsResourcesState.bindBuffer(MVKShaderStage(i), bb); } - } + BIND_GRAPHICS_OR_COMPUTE(cmdEncoder, bindBuffer, pipelineBindPoint, i, bb); } } } @@ -381,11 +369,7 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s for (uint32_t i = kMVKShaderStageVertex; i < kMVKShaderStageCount; i++) { if (_applyToStage[i]) { sb.index = mtlIdxs.stages[i].samplerIndex + rezIdx; - if (i == kMVKShaderStageCompute) { - if (cmdEncoder) { cmdEncoder->_computeResourcesState.bindSamplerState(sb); } - } else { - if (cmdEncoder) { cmdEncoder->_graphicsResourcesState.bindSamplerState(MVKShaderStage(i), sb); } - } + BIND_GRAPHICS_OR_COMPUTE(cmdEncoder, bindSamplerState, pipelineBindPoint, i, sb); } } break; @@ -410,13 +394,8 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s if (_applyToStage[i]) { tb.index = mtlIdxs.stages[i].textureIndex + rezIdx + planeIndex; sb.index = mtlIdxs.stages[i].samplerIndex + rezIdx; - if (i == kMVKShaderStageCompute) { - if (cmdEncoder) { cmdEncoder->_computeResourcesState.bindTexture(tb); } - if (cmdEncoder) { cmdEncoder->_computeResourcesState.bindSamplerState(sb); } - } else { - if (cmdEncoder) { cmdEncoder->_graphicsResourcesState.bindTexture(MVKShaderStage(i), tb); } - if (cmdEncoder) { cmdEncoder->_graphicsResourcesState.bindSamplerState(MVKShaderStage(i), sb); } - } + BIND_GRAPHICS_OR_COMPUTE(cmdEncoder, bindTexture, pipelineBindPoint, i, tb); + BIND_GRAPHICS_OR_COMPUTE(cmdEncoder, bindSamplerState, pipelineBindPoint, i, sb); } } } @@ -742,6 +721,7 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s // A null cmdEncoder can be passed to perform a validation pass void MVKBufferDescriptor::bind(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKDescriptorSetLayoutBinding* mvkDSLBind, uint32_t elementIndex, bool stages[], @@ -762,11 +742,7 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s for (uint32_t i = kMVKShaderStageVertex; i < kMVKShaderStageCount; i++) { if (stages[i]) { bb.index = mtlIndexes.stages[i].bufferIndex + elementIndex; - if (i == kMVKShaderStageCompute) { - if (cmdEncoder) { cmdEncoder->_computeResourcesState.bindBuffer(bb); } - } else { - if (cmdEncoder) { cmdEncoder->_graphicsResourcesState.bindBuffer(MVKShaderStage(i), bb); } - } + BIND_GRAPHICS_OR_COMPUTE(cmdEncoder, bindBuffer, pipelineBindPoint, i, bb); } } } @@ -834,6 +810,7 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s // A null cmdEncoder can be passed to perform a validation pass void MVKInlineUniformBlockDescriptor::bind(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKDescriptorSetLayoutBinding* mvkDSLBind, uint32_t elementIndex, bool stages[], @@ -850,11 +827,7 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s for (uint32_t i = kMVKShaderStageVertex; i < kMVKShaderStageCount; i++) { if (stages[i]) { bb.index = mtlIndexes.stages[i].bufferIndex; - if (i == kMVKShaderStageCompute) { - if (cmdEncoder) { cmdEncoder->_computeResourcesState.bindBuffer(bb); } - } else { - if (cmdEncoder) { cmdEncoder->_graphicsResourcesState.bindBuffer(MVKShaderStage(i), bb); } - } + BIND_GRAPHICS_OR_COMPUTE(cmdEncoder, bindBuffer, pipelineBindPoint, i, bb); } } } @@ -923,6 +896,7 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s // A null cmdEncoder can be passed to perform a validation pass void MVKImageDescriptor::bind(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKDescriptorSetLayoutBinding* mvkDSLBind, uint32_t elementIndex, bool stages[], @@ -952,18 +926,10 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s for (uint32_t i = kMVKShaderStageVertex; i < kMVKShaderStageCount; i++) { if (stages[i]) { tb.index = mtlIndexes.stages[i].textureIndex + elementIndex + planeIndex; - if (i == kMVKShaderStageCompute) { - if (cmdEncoder) { cmdEncoder->_computeResourcesState.bindTexture(tb); } - } else { - if (cmdEncoder) { cmdEncoder->_graphicsResourcesState.bindTexture(MVKShaderStage(i), tb); } - } + BIND_GRAPHICS_OR_COMPUTE(cmdEncoder, bindTexture, pipelineBindPoint, i, tb); if (descType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) { bb.index = mtlIndexes.stages[i].bufferIndex + elementIndex + planeIndex; - if (i == kMVKShaderStageCompute) { - if (cmdEncoder) { cmdEncoder->_computeResourcesState.bindBuffer(bb); } - } else { - if (cmdEncoder) { cmdEncoder->_graphicsResourcesState.bindBuffer(MVKShaderStage(i), bb); } - } + BIND_GRAPHICS_OR_COMPUTE(cmdEncoder, bindBuffer, pipelineBindPoint, i, bb); } } } @@ -1048,6 +1014,7 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s // Metal validation requires each sampler in an array of samplers to be populated, // even if not used, so populate a default if one hasn't been set. void MVKSamplerDescriptorMixin::bind(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKDescriptorSetLayoutBinding* mvkDSLBind, uint32_t elementIndex, bool stages[], @@ -1065,11 +1032,7 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s for (uint32_t i = kMVKShaderStageVertex; i < kMVKShaderStageCount; i++) { if (stages[i]) { sb.index = mtlIndexes.stages[i].samplerIndex + elementIndex; - if (i == kMVKShaderStageCompute) { - if (cmdEncoder) { cmdEncoder->_computeResourcesState.bindSamplerState(sb); } - } else { - if (cmdEncoder) { cmdEncoder->_graphicsResourcesState.bindSamplerState(MVKShaderStage(i), sb); } - } + BIND_GRAPHICS_OR_COMPUTE(cmdEncoder, bindSamplerState, pipelineBindPoint, i, sb); } } } @@ -1136,13 +1099,14 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s // A null cmdEncoder can be passed to perform a validation pass void MVKSamplerDescriptor::bind(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKDescriptorSetLayoutBinding* mvkDSLBind, uint32_t elementIndex, bool stages[], MVKShaderResourceBinding& mtlIndexes, MVKArrayRef dynamicOffsets, uint32_t& dynamicOffsetIndex) { - MVKSamplerDescriptorMixin::bind(cmdEncoder, mvkDSLBind, elementIndex, stages, mtlIndexes, dynamicOffsets, dynamicOffsetIndex); + MVKSamplerDescriptorMixin::bind(cmdEncoder, pipelineBindPoint, mvkDSLBind, elementIndex, stages, mtlIndexes, dynamicOffsets, dynamicOffsetIndex); } void MVKSamplerDescriptor::encodeToMetalArgumentBuffer(MVKResourcesCommandEncoderState* rezEncState, @@ -1185,14 +1149,15 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s // A null cmdEncoder can be passed to perform a validation pass void MVKCombinedImageSamplerDescriptor::bind(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKDescriptorSetLayoutBinding* mvkDSLBind, uint32_t elementIndex, bool stages[], MVKShaderResourceBinding& mtlIndexes, MVKArrayRef dynamicOffsets, uint32_t& dynamicOffsetIndex) { - MVKImageDescriptor::bind(cmdEncoder, mvkDSLBind, elementIndex, stages, mtlIndexes, dynamicOffsets, dynamicOffsetIndex); - MVKSamplerDescriptorMixin::bind(cmdEncoder, mvkDSLBind, elementIndex, stages, mtlIndexes, dynamicOffsets, dynamicOffsetIndex); + MVKImageDescriptor::bind(cmdEncoder, pipelineBindPoint, mvkDSLBind, elementIndex, stages, mtlIndexes, dynamicOffsets, dynamicOffsetIndex); + MVKSamplerDescriptorMixin::bind(cmdEncoder, pipelineBindPoint, mvkDSLBind, elementIndex, stages, mtlIndexes, dynamicOffsets, dynamicOffsetIndex); } void MVKCombinedImageSamplerDescriptor::encodeToMetalArgumentBuffer(MVKResourcesCommandEncoderState* rezEncState, @@ -1238,6 +1203,7 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s // A null cmdEncoder can be passed to perform a validation pass void MVKTexelBufferDescriptor::bind(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKDescriptorSetLayoutBinding* mvkDSLBind, uint32_t elementIndex, bool stages[], @@ -1259,18 +1225,10 @@ void mvkPopulateShaderConversionConfig(mvk::SPIRVToMSLConversionConfiguration& s for (uint32_t i = kMVKShaderStageVertex; i < kMVKShaderStageCount; i++) { if (stages[i]) { tb.index = mtlIndexes.stages[i].textureIndex + elementIndex; - if (i == kMVKShaderStageCompute) { - if (cmdEncoder) { cmdEncoder->_computeResourcesState.bindTexture(tb); } - } else { - if (cmdEncoder) { cmdEncoder->_graphicsResourcesState.bindTexture(MVKShaderStage(i), tb); } - } + BIND_GRAPHICS_OR_COMPUTE(cmdEncoder, bindTexture, pipelineBindPoint, i, tb); if (descType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER) { bb.index = mtlIndexes.stages[i].bufferIndex + elementIndex; - if (i == kMVKShaderStageCompute) { - if (cmdEncoder) { cmdEncoder->_computeResourcesState.bindBuffer(bb); } - } else { - if (cmdEncoder) { cmdEncoder->_graphicsResourcesState.bindBuffer(MVKShaderStage(i), bb); } - } + BIND_GRAPHICS_OR_COMPUTE(cmdEncoder, bindBuffer, pipelineBindPoint, i, bb); } } } diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h index 8964c9019..552ca1728 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h @@ -81,6 +81,7 @@ class MVKDescriptorSetLayout : public MVKVulkanAPIDeviceObject { /** Encodes this descriptor set layout and the specified descriptor updates on the specified command encoder immediately. */ void pushDescriptorSet(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKArrayRef descriptorWrites, MVKShaderResourceBinding& dslMTLRezIdxOffsets); @@ -338,6 +339,9 @@ class MVKDescriptorUpdateTemplate : public MVKVulkanAPIDeviceObject { /** Get the type of this template. */ VkDescriptorUpdateTemplateType getType() const; + /** Get the bind point of this template */ + VkPipelineBindPoint getBindPoint() const { return _pipelineBindPoint; } + /** Constructs an instance for the specified device. */ MVKDescriptorUpdateTemplate(MVKDevice* device, const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo); @@ -347,6 +351,7 @@ class MVKDescriptorUpdateTemplate : public MVKVulkanAPIDeviceObject { protected: void propagateDebugName() override {} + VkPipelineBindPoint _pipelineBindPoint; VkDescriptorUpdateTemplateType _type; MVKSmallVector _entries; }; diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm index 5ebeed4b9..679e4005f 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm @@ -43,7 +43,7 @@ dynamicOffsets, dynamicOffsetIndex); } if ( !isUsingMetalArgumentBuffers() ) { for (auto& dslBind : _bindings) { - dslBind.bind(cmdEncoder, descSet, dslMTLRezIdxOffsets, dynamicOffsets, dynamicOffsetIndex); + dslBind.bind(cmdEncoder, pipelineBindPoint, descSet, dslMTLRezIdxOffsets, dynamicOffsets, dynamicOffsetIndex); } } } @@ -91,6 +91,7 @@ // A null cmdEncoder can be passed to perform a validation pass void MVKDescriptorSetLayout::pushDescriptorSet(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKArrayRef descriptorWrites, MVKShaderResourceBinding& dslMTLRezIdxOffsets) { @@ -127,7 +128,7 @@ pBufferInfo, pTexelBufferView, pInlineUniformBlock, stride); uint32_t descriptorsPushed = 0; uint32_t bindIdx = _bindingToIndex[dstBinding]; - _bindings[bindIdx].push(cmdEncoder, dstArrayElement, descriptorCount, + _bindings[bindIdx].push(cmdEncoder, pipelineBindPoint, dstArrayElement, descriptorCount, descriptorsPushed, descWrite.descriptorType, stride, pData, dslMTLRezIdxOffsets); pBufferInfo += descriptorsPushed; @@ -148,6 +149,7 @@ return; if (!cmdEncoder) { clearConfigurationResult(); } + VkPipelineBindPoint bindPoint = descUpdateTemplate->getBindPoint(); for (uint32_t i = 0; i < descUpdateTemplate->getNumberOfEntries(); i++) { const VkDescriptorUpdateTemplateEntry* pEntry = descUpdateTemplate->getEntry(i); uint32_t dstBinding = pEntry->dstBinding; @@ -161,7 +163,7 @@ if (!_bindingToIndex.count(dstBinding)) continue; uint32_t descriptorsPushed = 0; uint32_t bindIdx = _bindingToIndex[dstBinding]; - _bindings[bindIdx].push(cmdEncoder, dstArrayElement, descriptorCount, + _bindings[bindIdx].push(cmdEncoder, bindPoint, dstArrayElement, descriptorCount, descriptorsPushed, pEntry->descriptorType, pEntry->stride, pCurData, dslMTLRezIdxOffsets); pCurData = (const char*)pCurData + pEntry->stride * descriptorsPushed; @@ -876,7 +878,7 @@ MVKDescriptorUpdateTemplate::MVKDescriptorUpdateTemplate(MVKDevice* device, const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo) : - MVKVulkanAPIDeviceObject(device), _type(pCreateInfo->templateType) { + MVKVulkanAPIDeviceObject(device), _type(pCreateInfo->templateType), _pipelineBindPoint(pCreateInfo->pipelineBindPoint) { for (uint32_t i = 0; i < pCreateInfo->descriptorUpdateEntryCount; i++) _entries.push_back(pCreateInfo->pDescriptorUpdateEntries[i]); diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h index efb7c4926..0d763e266 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h +++ b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.h @@ -63,6 +63,7 @@ class MVKPipelineLayout : public MVKVulkanAPIDeviceObject { /** Updates a descriptor set in a command encoder. */ void pushDescriptorSet(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKArrayRef descriptorWrites, uint32_t set); diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm index 19d0d06c1..fb2880e7a 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKPipeline.mm @@ -64,11 +64,12 @@ // A null cmdEncoder can be passed to perform a validation pass void MVKPipelineLayout::pushDescriptorSet(MVKCommandEncoder* cmdEncoder, + VkPipelineBindPoint pipelineBindPoint, MVKArrayRef descriptorWrites, uint32_t set) { if (!cmdEncoder) { clearConfigurationResult(); } MVKDescriptorSetLayout* dsl = _descriptorSetLayouts[set]; - dsl->pushDescriptorSet(cmdEncoder, descriptorWrites, _dslMTLResourceIndexOffsets[set]); + dsl->pushDescriptorSet(cmdEncoder, pipelineBindPoint, descriptorWrites, _dslMTLResourceIndexOffsets[set]); if (!cmdEncoder) { setConfigurationResult(dsl->getConfigurationResult()); } }