Skip to content

Commit

Permalink
Merge pull request #2320 from billhollings/imgview-retain-img
Browse files Browse the repository at this point in the history
Fix race condition when VkImage destroyed while used by descriptor.
  • Loading branch information
billhollings authored Aug 28, 2024
2 parents 03f2896 + 188a21a commit 18f2b84
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions Docs/Whats_New.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Released TBD
end of a descriptor binding count, including inline uniform block descriptors.
- Update `VkFormat` capabilities based on latest Metal docs.
- Fix rendering issue with render pass that immediately follows a kernel dispatch.
- Fix race condition when `VkImage` destroyed while used by descriptor.
- Ensure all MoltenVK config info set by `VK_EXT_layer_settings` is used.
- Move primitive-restart-disabled warning from renderpass to pipeline creation, to reduce voluminous log noise.
- iOS: Support storage images in _Metal_ argument buffers.
Expand Down
3 changes: 3 additions & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,8 @@ static void signalAndUntrack(const MVKSwapchainSignaler& signaler) {

MVKImageView::MVKImageView(MVKDevice* device, const VkImageViewCreateInfo* pCreateInfo) : MVKVulkanAPIDeviceObject(device) {
_image = (MVKImage*)pCreateInfo->image;
_image->retain(); // Ensure image sticks around while this image view is in flight.

_mtlTextureType = mvkMTLTextureTypeFromVkImageViewType(pCreateInfo->viewType,
_image->getSampleCount() != VK_SAMPLE_COUNT_1_BIT);

Expand Down Expand Up @@ -2306,6 +2308,7 @@ static void signalAndUntrack(const MVKSwapchainSignaler& signaler) {
// Memory detached in destructor too, as a fail-safe.
MVKImageView::~MVKImageView() {
detachMemory();
_image->release();
}

// Overridden to detach from the resource memory when the app destroys this object.
Expand Down

0 comments on commit 18f2b84

Please sign in to comment.