Commit 5e4ff4ef authored by Chia-I Wu's avatar Chia-I Wu Committed by Marge Bot
Browse files

venus: add support for external semaphores on Android



This is a hack.
Signed-off-by: Chia-I Wu's avatarChia-I Wu <olvaffe@gmail.com>
Reviewed-by: Yiwei Zhang's avatarYiwei Zhang <zzyiwei@chromium.org>
Part-of: <mesa/mesa!11253>
parent e2ac01aa
......@@ -1445,6 +1445,13 @@ vn_physical_device_init_external_semaphore_handles(
*/
physical_dev->external_binary_semaphore_handles = 0;
physical_dev->external_timeline_semaphore_handles = 0;
#ifdef ANDROID
if (physical_dev->instance->experimental.globalFencing) {
physical_dev->external_binary_semaphore_handles =
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
}
#endif
}
static void
......@@ -1478,6 +1485,7 @@ vn_physical_device_get_native_extensions(
#ifdef ANDROID
if (instance->experimental.globalFencing) {
exts->KHR_external_fence_fd = true;
exts->KHR_external_semaphore_fd = true;
}
#endif
......
......@@ -972,7 +972,27 @@ vn_ImportSemaphoreFdKHR(
VkDevice device, const VkImportSemaphoreFdInfoKHR *pImportSemaphoreFdInfo)
{
struct vn_device *dev = vn_device_from_handle(device);
return vn_error(dev->instance, VK_ERROR_UNKNOWN);
struct vn_semaphore *sem =
vn_semaphore_from_handle(pImportSemaphoreFdInfo->semaphore);
ASSERTED const bool sync_file =
pImportSemaphoreFdInfo->handleType ==
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
const int fd = pImportSemaphoreFdInfo->fd;
assert(dev->instance->experimental.globalFencing);
assert(sync_file);
if (fd >= 0) {
const int ret = sync_wait(fd, -1);
if (ret)
return vn_error(dev->instance, VK_ERROR_INVALID_EXTERNAL_HANDLE);
close(fd);
}
/* abuse VN_SYNC_TYPE_WSI_SIGNALED */
vn_semaphore_signal_wsi(dev, sem);
return VK_SUCCESS;
}
VkResult
......@@ -981,7 +1001,29 @@ vn_GetSemaphoreFdKHR(VkDevice device,
int *pFd)
{
struct vn_device *dev = vn_device_from_handle(device);
return vn_error(dev->instance, VK_ERROR_UNKNOWN);
struct vn_semaphore *sem = vn_semaphore_from_handle(pGetFdInfo->semaphore);
const bool sync_file =
pGetFdInfo->handleType == VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
struct vn_sync_payload *payload = sem->payload;
assert(dev->instance->experimental.globalFencing);
assert(sync_file);
int fd = -1;
if (payload->type == VN_SYNC_TYPE_DEVICE_ONLY) {
VkResult result = vn_create_sync_file(dev, &fd);
if (result != VK_SUCCESS)
return vn_error(dev->instance, result);
}
if (sync_file) {
vn_sync_payload_release(dev, &sem->temporary);
sem->payload = &sem->permanent;
/* XXX implies wait operation on the host semaphore */
}
*pFd = fd;
return VK_SUCCESS;
}
/* event commands */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment