Skip to content

Commit

Permalink
Merge pull request #2358 from billhollings/desc-set-layout-retain
Browse files Browse the repository at this point in the history
Fix crash when VkDescriptorSetLayout is destroyed while descriptor set is in use.
  • Loading branch information
billhollings authored Sep 30, 2024
2 parents 2307b08 + 2c334ac commit ff82a82
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ class MVKDescriptorSet : public MVKVulkanAPIDeviceObject {

MVKDescriptorSet(MVKDescriptorPool* pool);

~MVKDescriptorSet() override;

protected:
friend class MVKDescriptorSetLayoutBinding;
friend class MVKDescriptorPool;
Expand Down
6 changes: 6 additions & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKDescriptorSet.mm
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ static void populateAuxBuffer(mvk::SPIRVToMSLConversionConfiguration& shaderConf
NSUInteger mtlArgBufferOffset,
id<MTLArgumentEncoder> mtlArgEnc) {
_layout = layout;
_layout->retain();
_variableDescriptorCount = variableDescriptorCount;
_argumentBuffer.setArgumentBuffer(_pool->_metalArgumentBuffer, mtlArgBufferOffset, mtlArgEnc);

Expand Down Expand Up @@ -574,6 +575,7 @@ static void populateAuxBuffer(mvk::SPIRVToMSLConversionConfiguration& shaderConf
}

void MVKDescriptorSet::free(bool isPoolReset) {
if(_layout) { _layout->release(); }
_layout = nullptr;
_dynamicOffsetDescriptorCount = 0;
_variableDescriptorCount = 0;
Expand Down Expand Up @@ -613,6 +615,10 @@ static void populateAuxBuffer(mvk::SPIRVToMSLConversionConfiguration& shaderConf
free(true);
}

MVKDescriptorSet::~MVKDescriptorSet() {
if(_layout) { _layout->release(); }
}


#pragma mark -
#pragma mark MVKDescriptorTypePool
Expand Down

0 comments on commit ff82a82

Please sign in to comment.