Skip to content

Commit c77f53e

Browse files
austinEngDawn LUCI CQ
authored andcommitted
Fix leak of VkImage handle
track explicitly whether the handle is owned and should be deleted Bug: chromium:1473001 Change-Id: I239b392571cc6d21ccfb392e6124df08b3283c33 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/147081 Kokoro: Kokoro <[email protected]> Commit-Queue: Austin Eng <[email protected]> Reviewed-by: Loko Kung <[email protected]>
1 parent 4ec0a0b commit c77f53e

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/dawn/native/vulkan/TextureVk.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ MaybeError Texture::InitializeAsInternalTexture(VkImageUsageFlags extraUsages) {
736736
DAWN_TRY(CheckVkSuccess(
737737
device->fn.CreateImage(device->GetVkDevice(), &createInfo, nullptr, &*mHandle),
738738
"CreateImage"));
739+
mOwnsHandle = true;
739740

740741
// Create the image memory and associate it with the container
741742
VkMemoryRequirements requirements;
@@ -847,6 +848,7 @@ MaybeError Texture::InitializeFromExternal(const ExternalImageDescriptorVk* desc
847848
}
848849

849850
DAWN_TRY_ASSIGN(mHandle, externalMemoryService->CreateImage(descriptor, baseCreateInfo));
851+
mOwnsHandle = true;
850852

851853
SetLabelHelper("Dawn_ExternalTexture");
852854

@@ -998,13 +1000,7 @@ void Texture::SetLabelImpl() {
9981000
void Texture::DestroyImpl() {
9991001
Device* device = ToBackend(GetDevice());
10001002

1001-
// The VkImage is only allocated if it is backed by a valid memory allocation.
1002-
// It is not allocated if the Texture was initialized from an external VkImage,
1003-
// like a swapchin.
1004-
bool allocatedVkImage = (mMemoryAllocation.GetInfo().mMethod != AllocationMethod::kInvalid ||
1005-
mExternalAllocation != VK_NULL_HANDLE) &&
1006-
mHandle != VK_NULL_HANDLE;
1007-
if (allocatedVkImage) {
1003+
if (mOwnsHandle) {
10081004
device->GetFencedDeleter()->DeleteWhenUnused(mHandle);
10091005
}
10101006

src/dawn/native/vulkan/TextureVk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class Texture final : public TextureBase {
142142
bool CanReuseWithoutBarrier(wgpu::TextureUsage lastUsage, wgpu::TextureUsage usage);
143143

144144
VkImage mHandle = VK_NULL_HANDLE;
145+
bool mOwnsHandle = false;
145146
ResourceMemoryAllocation mMemoryAllocation;
146147
VkDeviceMemory mExternalAllocation = VK_NULL_HANDLE;
147148

0 commit comments

Comments
 (0)