Skip to content

Commit

Permalink
Release image from view from both destroy and destructor (#2341)
Browse files Browse the repository at this point in the history
  • Loading branch information
warmenhoven committed Sep 24, 2024
1 parent 1c0b0f2 commit a745ee5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions MoltenVK/MoltenVK/GPUObjects/MVKImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,12 @@
if (_deviceMemory) { _deviceMemory->removeImageMemoryBinding(this); }
MVKResource::bindDeviceMemory(mvkMem, memOffset);

if (!_deviceMemory) {
return VK_SUCCESS;
}

auto& mtlFeats = getMetalFeatures();
bool usesTexelBuffer = mtlFeats.texelBuffers && _deviceMemory; // Texel buffers available
bool usesTexelBuffer = mtlFeats.texelBuffers; // Texel buffers available
usesTexelBuffer = usesTexelBuffer && (isMemoryHostAccessible() || mtlFeats.placementHeaps) && _image->_isLinear && !_image->getIsCompressed(); // Applicable memory layout

// macOS before 10.15.5 cannot use shared memory for texel buffers.
Expand All @@ -425,7 +429,7 @@
_mtlTexelBufferOffset = getDeviceMemoryOffset();
} else {
// Create our own buffer for this.
if (_deviceMemory && _deviceMemory->_mtlHeap && _image->getMTLStorageMode() == _deviceMemory->_mtlStorageMode) {
if (_deviceMemory->_mtlHeap && _image->getMTLStorageMode() == _deviceMemory->_mtlStorageMode) {
_mtlTexelBuffer = [_deviceMemory->_mtlHeap newBufferWithLength: _byteCount options: _deviceMemory->getMTLResourceOptions() offset: getDeviceMemoryOffset()];
if (_image->_isAliasable) { [_mtlTexelBuffer makeAliasable]; }
} else {
Expand All @@ -443,7 +447,7 @@
}

flushToDevice(getDeviceMemoryOffset(), getByteCount());
return _deviceMemory ? _deviceMemory->addImageMemoryBinding(this) : VK_SUCCESS;
return _deviceMemory->addImageMemoryBinding(this);
}

void MVKImageMemoryBinding::applyMemoryBarrier(MVKPipelineBarrier& barrier,
Expand Down

0 comments on commit a745ee5

Please sign in to comment.