MVKImagePlane::getMTLTexture() protect against

crash when image has no device memory bound.
This commit is contained in:
Bill Hollings 2021-05-05 16:37:16 -04:00
parent 26ff3e594a
commit f781ee720a
2 changed files with 7 additions and 5 deletions

View File

@ -25,6 +25,7 @@ Released TBD
- Improve cache hits when matching `SPIRVToMSLConversionConfiguration` structs to each other
to find a cached shader, by only considering resources from the current shader stage.
- Rename `kMVKShaderStageMax` to `kMVKShaderStageCount`.
- Protect against crash when retrieving `MTLTexture` when `VkImage` has no `VkDeviceMemory` bound.
- 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
MVKImageMemoryBinding* memoryBinding = getMemoryBinding();
MVKDeviceMemory* dvcMem = memoryBinding->_deviceMemory;
if (_image->_ioSurface) {
_mtlTexture = [_image->getMTLDevice()
@ -55,19 +56,19 @@ id<MTLTexture> MVKImagePlane::getMTLTexture() {
newTextureWithDescriptor: mtlTexDesc
offset: memoryBinding->_mtlTexelBufferOffset + _subresources[0].layout.offset
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
_mtlTexture = [memoryBinding->_deviceMemory->getMTLHeap()
_mtlTexture = [dvcMem->getMTLHeap()
newTextureWithDescriptor: mtlTexDesc
offset: memoryBinding->getDeviceMemoryOffset() + _subresources[0].layout.offset];
if (_image->_isAliasable) { [_mtlTexture makeAliasable]; }
} else if (_image->_isAliasable && memoryBinding->_deviceMemory->isDedicatedAllocation() &&
!contains(memoryBinding->_deviceMemory->_imageMemoryBindings, memoryBinding)) {
} else if (_image->_isAliasable && dvcMem && dvcMem->isDedicatedAllocation() &&
!contains(dvcMem->_imageMemoryBindings, memoryBinding)) {
// This is a dedicated allocation, but it belongs to another aliasable 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
// 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 {
_mtlTexture = [_image->getMTLDevice() newTextureWithDescriptor: mtlTexDesc];
}