venus: add support for external semaphores on Android
This is a hack. Signed-off-by: Chia-I Wu <olvaffe@gmail.com> Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11253>
This commit is contained in:
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user