vulkan: Use a static method to close semaphore handles

These functions don't need the device or external semaphore service
at all. Make them free functions so that a future change can allow
the handles to be closed after the device has destroyed its semaphore
service.

Bug: chromium:1359106
Change-Id: I246dd0a8f3f972c4547503d16bf8b00db14cdf58
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/104542
Reviewed-by: Loko Kung <lokokung@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Austin Eng 2022-10-04 15:14:04 +00:00 committed by Dawn LUCI CQ
parent 70c3a4d605
commit 327cc706c2
5 changed files with 11 additions and 9 deletions

View File

@ -928,7 +928,12 @@ MaybeError Texture::ExportExternalTexture(VkImageLayout desiredLayout,
return {}; return {};
} }
Texture::~Texture() {} Texture::~Texture() {
if (mExternalSemaphoreHandle != kNullExternalSemaphoreHandle) {
external_semaphore::Service::CloseHandle(mExternalSemaphoreHandle);
}
mExternalSemaphoreHandle = kNullExternalSemaphoreHandle;
}
void Texture::SetLabelHelper(const char* prefix) { void Texture::SetLabelHelper(const char* prefix) {
SetDebugName(ToBackend(GetDevice()), mHandle, prefix, GetLabel()); SetDebugName(ToBackend(GetDevice()), mHandle, prefix, GetLabel());
@ -956,11 +961,6 @@ void Texture::DestroyImpl() {
mHandle = VK_NULL_HANDLE; mHandle = VK_NULL_HANDLE;
mExternalAllocation = VK_NULL_HANDLE; mExternalAllocation = VK_NULL_HANDLE;
if (mExternalSemaphoreHandle != kNullExternalSemaphoreHandle) {
device->GetExternalSemaphoreService()->CloseHandle(mExternalSemaphoreHandle);
}
mExternalSemaphoreHandle = kNullExternalSemaphoreHandle;
} }
// For Vulkan, we currently run the base destruction code after the internal changes because // For Vulkan, we currently run the base destruction code after the internal changes because
// of the dependency on the texture state which the base code overwrites too early. // of the dependency on the texture state which the base code overwrites too early.
@ -1345,8 +1345,7 @@ void Texture::EnsureSubresourceContentInitialized(CommandRecordingContext* recor
void Texture::UpdateExternalSemaphoreHandle(ExternalSemaphoreHandle handle) { void Texture::UpdateExternalSemaphoreHandle(ExternalSemaphoreHandle handle) {
if (mExternalSemaphoreHandle != kNullExternalSemaphoreHandle) { if (mExternalSemaphoreHandle != kNullExternalSemaphoreHandle) {
Device* device = ToBackend(GetDevice()); external_semaphore::Service::CloseHandle(mExternalSemaphoreHandle);
device->GetExternalSemaphoreService()->CloseHandle(mExternalSemaphoreHandle);
} }
mExternalSemaphoreHandle = handle; mExternalSemaphoreHandle = handle;
} }

View File

@ -52,7 +52,7 @@ class Service {
ExternalSemaphoreHandle DuplicateHandle(ExternalSemaphoreHandle handle); ExternalSemaphoreHandle DuplicateHandle(ExternalSemaphoreHandle handle);
// Close an external handle. // Close an external handle.
void CloseHandle(ExternalSemaphoreHandle handle); static void CloseHandle(ExternalSemaphoreHandle handle);
private: private:
Device* mDevice = nullptr; Device* mDevice = nullptr;

View File

@ -142,6 +142,7 @@ ExternalSemaphoreHandle Service::DuplicateHandle(ExternalSemaphoreHandle handle)
return fd; return fd;
} }
// static
void Service::CloseHandle(ExternalSemaphoreHandle handle) { void Service::CloseHandle(ExternalSemaphoreHandle handle) {
int ret = close(handle); int ret = close(handle);
ASSERT(ret == 0); ASSERT(ret == 0);

View File

@ -51,6 +51,7 @@ ExternalSemaphoreHandle Service::DuplicateHandle(ExternalSemaphoreHandle handle)
return kNullExternalSemaphoreHandle; return kNullExternalSemaphoreHandle;
} }
// static
void Service::CloseHandle(ExternalSemaphoreHandle handle) {} void Service::CloseHandle(ExternalSemaphoreHandle handle) {}
} // namespace dawn::native::vulkan::external_semaphore } // namespace dawn::native::vulkan::external_semaphore

View File

@ -137,6 +137,7 @@ ExternalSemaphoreHandle Service::DuplicateHandle(ExternalSemaphoreHandle handle)
return out_handle; return out_handle;
} }
// static
void Service::CloseHandle(ExternalSemaphoreHandle handle) { void Service::CloseHandle(ExternalSemaphoreHandle handle) {
zx_status_t status = zx_handle_close(handle); zx_status_t status = zx_handle_close(handle);
ASSERT(status == ZX_OK); ASSERT(status == ZX_OK);