anv,radv,v3dv: Move AcquireImageANDROID to common code
All three implementations are identical. Reviewed-by: Eric Engestrom <eric@engestrom.ch> Reviewed-by: Iago Toral Quiroga <itoral@igalia.com> Tested-by: Tapani Pälli <tapani.palli@intel.com> Tested-by: Roman Stratiienko <r.stratiienko@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14372>
This commit is contained in:

committed by
Marge Bot

parent
9caf110d4f
commit
dfb1e1777c
@@ -792,85 +792,6 @@ VkResult anv_GetSwapchainGrallocUsageANDROID(
|
||||
return setup_gralloc0_usage(device, format, imageUsage, grallocUsage);
|
||||
}
|
||||
|
||||
VkResult
|
||||
anv_AcquireImageANDROID(
|
||||
VkDevice device_h,
|
||||
VkImage image_h,
|
||||
int nativeFenceFd,
|
||||
VkSemaphore semaphore_h,
|
||||
VkFence fence_h)
|
||||
{
|
||||
ANV_FROM_HANDLE(anv_device, device, device_h);
|
||||
VkResult result = VK_SUCCESS;
|
||||
|
||||
/* From https://source.android.com/devices/graphics/implement-vulkan :
|
||||
*
|
||||
* "The driver takes ownership of the fence file descriptor and closes
|
||||
* the fence file descriptor when no longer needed. The driver must do
|
||||
* so even if neither a semaphore or fence object is provided, or even
|
||||
* if vkAcquireImageANDROID fails and returns an error."
|
||||
*
|
||||
* The Vulkan spec for VkImportFence/SemaphoreFdKHR(), however, requires
|
||||
* the file descriptor to be left alone on failure.
|
||||
*/
|
||||
int semaphore_fd = -1, fence_fd = -1;
|
||||
if (nativeFenceFd >= 0) {
|
||||
if (semaphore_h != VK_NULL_HANDLE && fence_h != VK_NULL_HANDLE) {
|
||||
/* We have both so we have to import the sync file twice. One of
|
||||
* them needs to be a dup.
|
||||
*/
|
||||
semaphore_fd = nativeFenceFd;
|
||||
fence_fd = dup(nativeFenceFd);
|
||||
if (fence_fd < 0) {
|
||||
VkResult err = (errno == EMFILE) ? VK_ERROR_TOO_MANY_OBJECTS :
|
||||
VK_ERROR_OUT_OF_HOST_MEMORY;
|
||||
close(nativeFenceFd);
|
||||
return vk_error(device, err);
|
||||
}
|
||||
} else if (semaphore_h != VK_NULL_HANDLE) {
|
||||
semaphore_fd = nativeFenceFd;
|
||||
} else if (fence_h != VK_NULL_HANDLE) {
|
||||
fence_fd = nativeFenceFd;
|
||||
} else {
|
||||
/* Nothing to import into so we have to close the file */
|
||||
close(nativeFenceFd);
|
||||
}
|
||||
}
|
||||
|
||||
if (semaphore_h != VK_NULL_HANDLE) {
|
||||
const VkImportSemaphoreFdInfoKHR info = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR,
|
||||
.semaphore = semaphore_h,
|
||||
.flags = VK_SEMAPHORE_IMPORT_TEMPORARY_BIT,
|
||||
.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT,
|
||||
.fd = semaphore_fd,
|
||||
};
|
||||
result = vk_common_ImportSemaphoreFdKHR(device_h, &info);
|
||||
if (result == VK_SUCCESS)
|
||||
semaphore_fd = -1; /* ANV took ownership */
|
||||
}
|
||||
|
||||
if (result == VK_SUCCESS && fence_h != VK_NULL_HANDLE) {
|
||||
const VkImportFenceFdInfoKHR info = {
|
||||
.sType = VK_STRUCTURE_TYPE_IMPORT_FENCE_FD_INFO_KHR,
|
||||
.fence = fence_h,
|
||||
.flags = VK_FENCE_IMPORT_TEMPORARY_BIT,
|
||||
.handleType = VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT,
|
||||
.fd = fence_fd,
|
||||
};
|
||||
result = vk_common_ImportFenceFdKHR(device_h, &info);
|
||||
if (result == VK_SUCCESS)
|
||||
fence_fd = -1; /* ANV took ownership */
|
||||
}
|
||||
|
||||
if (semaphore_fd >= 0)
|
||||
close(semaphore_fd);
|
||||
if (fence_fd >= 0)
|
||||
close(fence_fd);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
VkResult
|
||||
anv_QueueSignalReleaseImageANDROID(
|
||||
VkQueue queue,
|
||||
|
Reference in New Issue
Block a user