From: Rob Clark Date: Fri, 25 Jun 2021 19:45:03 +0000 (-0700) Subject: turnip: Add CrOS Gralloc support X-Git-Tag: upstream/21.2.3~1245 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e74366b18a3ed3e2c5a649c287abd3739b957011;p=platform%2Fupstream%2Fmesa.git turnip: Add CrOS Gralloc support Signed-off-by: Rob Clark Part-of: --- diff --git a/src/freedreno/vulkan/tu_android.c b/src/freedreno/vulkan/tu_android.c index 1eb6709..e59c9e6 100644 --- a/src/freedreno/vulkan/tu_android.c +++ b/src/freedreno/vulkan/tu_android.c @@ -60,7 +60,7 @@ PUBLIC struct hwvulkan_module_t HAL_MODULE_INFO_SYM = { .module_api_version = HWVULKAN_MODULE_API_VERSION_0_1, .hal_api_version = HARDWARE_MAKE_API_VERSION(1, 0), .id = HWVULKAN_HARDWARE_MODULE_ID, - .name = "AMD Vulkan HAL", + .name = "Turnip Vulkan HAL", .author = "Google", .methods = &(hw_module_methods_t){ @@ -116,11 +116,11 @@ tu_hal_close(struct hw_device_t *dev) } /* get dma-buf and modifier from gralloc info */ -VkResult -tu_gralloc_info(struct tu_device *device, - const VkNativeBufferANDROID *gralloc_info, - int *dma_buf, - uint64_t *modifier) +static VkResult +tu_gralloc_info_other(struct tu_device *device, + const VkNativeBufferANDROID *gralloc_info, + int *dma_buf, + uint64_t *modifier) { const uint32_t *handle_fds = (uint32_t *)gralloc_info->handle->data; @@ -172,8 +172,87 @@ tu_gralloc_info(struct tu_device *device, *modifier = ubwc ? DRM_FORMAT_MOD_QCOM_COMPRESSED : DRM_FORMAT_MOD_LINEAR; return VK_SUCCESS; +} + +static const char cros_gralloc_module_name[] = "CrOS Gralloc"; + +#define CROS_GRALLOC_DRM_GET_BUFFER_INFO 4 +#define CROS_GRALLOC_DRM_GET_USAGE 5 +#define CROS_GRALLOC_DRM_GET_USAGE_FRONT_RENDERING_BIT 0x1 + +struct cros_gralloc0_buffer_info { + uint32_t drm_fourcc; + int num_fds; + int fds[4]; + uint64_t modifier; + int offset[4]; + int stride[4]; +}; + +static VkResult +tu_gralloc_info_cros(struct tu_device *device, + const VkNativeBufferANDROID *gralloc_info, + int *dma_buf, + uint64_t *modifier) + +{ + const gralloc_module_t *gralloc = device->gralloc; + struct cros_gralloc0_buffer_info info; + int ret; + + ret = gralloc->perform(gralloc, CROS_GRALLOC_DRM_GET_BUFFER_INFO, + gralloc_info->handle, &info); + if (ret) + return VK_ERROR_INVALID_EXTERNAL_HANDLE; + + *dma_buf = info.fds[0]; + *modifier = info.modifier; + + return VK_SUCCESS; +} + +VkResult +tu_gralloc_info(struct tu_device *device, + const VkNativeBufferANDROID *gralloc_info, + int *dma_buf, + uint64_t *modifier) + +{ + if (!device->gralloc) { + /* get gralloc module for gralloc buffer info query */ + int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, + (const hw_module_t **)&device->gralloc); + + if (ret) { + /* This is *slightly* awkward, but if we are asked to import + * a gralloc handle, and there is no gralloc, it is some sort + * of invalid handle. + */ + return vk_startup_errorf(device->instance, + VK_ERROR_INVALID_EXTERNAL_HANDLE, + "Could not open gralloc\n"); + } + + const gralloc_module_t *gralloc = device->gralloc; + mesa_logi("opened gralloc module name: %s", gralloc->common.name); + /* TODO not sure qcom gralloc module name, but we should check + * for it here and move the special gmsm handling out of + * tu_gralloc_info_other() + */ + if (!strcmp(gralloc->common.name, cros_gralloc_module_name) && gralloc->perform) { + device->gralloc_type = TU_GRALLOC_CROS; + } else { + device->gralloc_type = TU_GRALLOC_OTHER; + } + } + + if (device->gralloc_type == TU_GRALLOC_CROS) { + return tu_gralloc_info_cros(device, gralloc_info, dma_buf, modifier); + } else { + return tu_gralloc_info_other(device, gralloc_info, dma_buf, modifier); + } } /** diff --git a/src/freedreno/vulkan/tu_private.h b/src/freedreno/vulkan/tu_private.h index 90fd45b..c0324be 100644 --- a/src/freedreno/vulkan/tu_private.h +++ b/src/freedreno/vulkan/tu_private.h @@ -407,6 +407,15 @@ struct tu_device * new submit is executed. */ pthread_cond_t timeline_cond; pthread_mutex_t submit_mutex; + +#ifdef ANDROID + const void *gralloc; + enum { + TU_GRALLOC_UNKNOWN, + TU_GRALLOC_CROS, + TU_GRALLOC_OTHER, + } gralloc_type; +#endif }; VkResult _tu_device_set_lost(struct tu_device *device,