Merge "Make sure to close vulkan fd's in error cases" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d2a3454d8b
@@ -425,27 +425,38 @@ Frame VulkanManager::dequeueNextBuffer(VulkanSurface* surface) {
|
|||||||
semaphoreInfo.flags = 0;
|
semaphoreInfo.flags = 0;
|
||||||
VkSemaphore semaphore;
|
VkSemaphore semaphore;
|
||||||
VkResult err = mCreateSemaphore(mDevice, &semaphoreInfo, nullptr, &semaphore);
|
VkResult err = mCreateSemaphore(mDevice, &semaphoreInfo, nullptr, &semaphore);
|
||||||
LOG_ALWAYS_FATAL_IF(VK_SUCCESS != err, "Failed to create import semaphore, err: %d",
|
if (err != VK_SUCCESS) {
|
||||||
err);
|
ALOGE("Failed to create import semaphore, err: %d", err);
|
||||||
|
close(fence_clone);
|
||||||
|
sync_wait(bufferInfo->dequeue_fence, -1 /* forever */);
|
||||||
|
} else {
|
||||||
|
VkImportSemaphoreFdInfoKHR importInfo;
|
||||||
|
importInfo.sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR;
|
||||||
|
importInfo.pNext = nullptr;
|
||||||
|
importInfo.semaphore = semaphore;
|
||||||
|
importInfo.flags = VK_SEMAPHORE_IMPORT_TEMPORARY_BIT;
|
||||||
|
importInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
|
||||||
|
importInfo.fd = fence_clone;
|
||||||
|
|
||||||
VkImportSemaphoreFdInfoKHR importInfo;
|
err = mImportSemaphoreFdKHR(mDevice, &importInfo);
|
||||||
importInfo.sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR;
|
if (err != VK_SUCCESS) {
|
||||||
importInfo.pNext = nullptr;
|
ALOGE("Failed to import semaphore, err: %d", err);
|
||||||
importInfo.semaphore = semaphore;
|
mDestroySemaphore(mDevice, semaphore, nullptr);
|
||||||
importInfo.flags = VK_SEMAPHORE_IMPORT_TEMPORARY_BIT;
|
close(fence_clone);
|
||||||
importInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
|
sync_wait(bufferInfo->dequeue_fence, -1 /* forever */);
|
||||||
importInfo.fd = fence_clone;
|
} else {
|
||||||
|
GrBackendSemaphore backendSemaphore;
|
||||||
err = mImportSemaphoreFdKHR(mDevice, &importInfo);
|
backendSemaphore.initVulkan(semaphore);
|
||||||
LOG_ALWAYS_FATAL_IF(VK_SUCCESS != err, "Failed to import semaphore, err: %d", err);
|
// Skia will take ownership of the VkSemaphore and delete it once the wait
|
||||||
|
// has finished. The VkSemaphore also owns the imported fd, so it will
|
||||||
GrBackendSemaphore backendSemaphore;
|
// close the fd when it is deleted.
|
||||||
backendSemaphore.initVulkan(semaphore);
|
bufferInfo->skSurface->wait(1, &backendSemaphore);
|
||||||
bufferInfo->skSurface->wait(1, &backendSemaphore);
|
// The following flush blocks the GPU immediately instead of waiting for
|
||||||
// The following flush blocks the GPU immediately instead of waiting for other
|
// other drawing ops. It seems dequeue_fence is not respected otherwise.
|
||||||
// drawing ops. It seems dequeue_fence is not respected otherwise.
|
// TODO: remove the flush after finding why backendSemaphore is not working.
|
||||||
// TODO: remove the flush after finding why backendSemaphore is not working.
|
bufferInfo->skSurface->flushAndSubmit();
|
||||||
bufferInfo->skSurface->flushAndSubmit();
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -621,6 +632,7 @@ status_t VulkanManager::fenceWait(int fence, GrDirectContext* grContext) {
|
|||||||
VkSemaphore semaphore;
|
VkSemaphore semaphore;
|
||||||
VkResult err = mCreateSemaphore(mDevice, &semaphoreInfo, nullptr, &semaphore);
|
VkResult err = mCreateSemaphore(mDevice, &semaphoreInfo, nullptr, &semaphore);
|
||||||
if (VK_SUCCESS != err) {
|
if (VK_SUCCESS != err) {
|
||||||
|
close(fenceFd);
|
||||||
ALOGE("Failed to create import semaphore, err: %d", err);
|
ALOGE("Failed to create import semaphore, err: %d", err);
|
||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
@@ -635,6 +647,7 @@ status_t VulkanManager::fenceWait(int fence, GrDirectContext* grContext) {
|
|||||||
err = mImportSemaphoreFdKHR(mDevice, &importInfo);
|
err = mImportSemaphoreFdKHR(mDevice, &importInfo);
|
||||||
if (VK_SUCCESS != err) {
|
if (VK_SUCCESS != err) {
|
||||||
mDestroySemaphore(mDevice, semaphore, nullptr);
|
mDestroySemaphore(mDevice, semaphore, nullptr);
|
||||||
|
close(fenceFd);
|
||||||
ALOGE("Failed to import semaphore, err: %d", err);
|
ALOGE("Failed to import semaphore, err: %d", err);
|
||||||
return UNKNOWN_ERROR;
|
return UNKNOWN_ERROR;
|
||||||
}
|
}
|
||||||
@@ -642,7 +655,8 @@ status_t VulkanManager::fenceWait(int fence, GrDirectContext* grContext) {
|
|||||||
GrBackendSemaphore beSemaphore;
|
GrBackendSemaphore beSemaphore;
|
||||||
beSemaphore.initVulkan(semaphore);
|
beSemaphore.initVulkan(semaphore);
|
||||||
|
|
||||||
// Skia takes ownership of the semaphore and will delete it once the wait has finished.
|
// Skia will take ownership of the VkSemaphore and delete it once the wait has finished. The
|
||||||
|
// VkSemaphore also owns the imported fd, so it will close the fd when it is deleted.
|
||||||
grContext->wait(1, &beSemaphore);
|
grContext->wait(1, &beSemaphore);
|
||||||
grContext->flushAndSubmit();
|
grContext->flushAndSubmit();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user