Merge pull request #1354 from billhollings/fix-1329-2

MVKImagePlane::getMTLTexture() protect against crash when image has no device memory bound.
This commit is contained in:
Bill Hollings 2021-05-06 08:21:13 -04:00 committed by GitHub
commit a6e73c7937
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -26,6 +26,7 @@ Released TBD
to find a cached shader, by only considering resources from the current shader stage. to find a cached shader, by only considering resources from the current shader stage.
- Rename `kMVKShaderStageMax` to `kMVKShaderStageCount`. - Rename `kMVKShaderStageMax` to `kMVKShaderStageCount`.
- Fix crash when requesting `MTLCommandBuffer` logs in runtime debug mode on older OS versions. - Fix crash when requesting `MTLCommandBuffer` logs in runtime debug mode on older OS versions.
- Protect against crash when retrieving `MTLTexture` when `VkImage` has no `VkDeviceMemory` bound.
- Fix internal reference from `SPIRV_CROSS_NAMESPACE_OVERRIDE` to `SPIRV_CROSS_NAMESPACE`. - Fix internal reference from `SPIRV_CROSS_NAMESPACE_OVERRIDE` to `SPIRV_CROSS_NAMESPACE`.

View File

@ -44,6 +44,7 @@ id<MTLTexture> MVKImagePlane::getMTLTexture() {
MTLTextureDescriptor* mtlTexDesc = newMTLTextureDescriptor(); // temp retain MTLTextureDescriptor* mtlTexDesc = newMTLTextureDescriptor(); // temp retain
MVKImageMemoryBinding* memoryBinding = getMemoryBinding(); MVKImageMemoryBinding* memoryBinding = getMemoryBinding();
MVKDeviceMemory* dvcMem = memoryBinding->_deviceMemory;
if (_image->_ioSurface) { if (_image->_ioSurface) {
_mtlTexture = [_image->getMTLDevice() _mtlTexture = [_image->getMTLDevice()
@ -55,19 +56,19 @@ id<MTLTexture> MVKImagePlane::getMTLTexture() {
newTextureWithDescriptor: mtlTexDesc newTextureWithDescriptor: mtlTexDesc
offset: memoryBinding->_mtlTexelBufferOffset + _subresources[0].layout.offset offset: memoryBinding->_mtlTexelBufferOffset + _subresources[0].layout.offset
bytesPerRow: _subresources[0].layout.rowPitch]; bytesPerRow: _subresources[0].layout.rowPitch];
} else if (memoryBinding->_deviceMemory->getMTLHeap() && !_image->getIsDepthStencil()) { } else if (dvcMem && dvcMem->getMTLHeap() && !_image->getIsDepthStencil()) {
// Metal support for depth/stencil from heaps is flaky // Metal support for depth/stencil from heaps is flaky
_mtlTexture = [memoryBinding->_deviceMemory->getMTLHeap() _mtlTexture = [dvcMem->getMTLHeap()
newTextureWithDescriptor: mtlTexDesc newTextureWithDescriptor: mtlTexDesc
offset: memoryBinding->getDeviceMemoryOffset() + _subresources[0].layout.offset]; offset: memoryBinding->getDeviceMemoryOffset() + _subresources[0].layout.offset];
if (_image->_isAliasable) { [_mtlTexture makeAliasable]; } if (_image->_isAliasable) { [_mtlTexture makeAliasable]; }
} else if (_image->_isAliasable && memoryBinding->_deviceMemory->isDedicatedAllocation() && } else if (_image->_isAliasable && dvcMem && dvcMem->isDedicatedAllocation() &&
!contains(memoryBinding->_deviceMemory->_imageMemoryBindings, memoryBinding)) { !contains(dvcMem->_imageMemoryBindings, memoryBinding)) {
// This is a dedicated allocation, but it belongs to another aliasable image. // This is a dedicated allocation, but it belongs to another aliasable image.
// In this case, use the MTLTexture from the memory's dedicated image. // In this case, use the MTLTexture from the memory's dedicated image.
// We know the other image must be aliasable, or I couldn't have been bound // We know the other image must be aliasable, or I couldn't have been bound
// to its memory: the memory object wouldn't allow it. // to its memory: the memory object wouldn't allow it.
_mtlTexture = [memoryBinding->_deviceMemory->_imageMemoryBindings[0]->_image->getMTLTexture(_planeIndex, mtlTexDesc.pixelFormat) retain]; _mtlTexture = [dvcMem->_imageMemoryBindings[0]->_image->getMTLTexture(_planeIndex, mtlTexDesc.pixelFormat) retain];
} else { } else {
_mtlTexture = [_image->getMTLDevice() newTextureWithDescriptor: mtlTexDesc]; _mtlTexture = [_image->getMTLDevice() newTextureWithDescriptor: mtlTexDesc];
} }