turnip: rework android gralloc path so it doesn't call tu_image_create
Signed-off-by: Jonathan Marek <jonathan@marek.ca> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7406>
This commit is contained in:
parent
b2a21febe0
commit
990343b70d
|
@ -115,33 +115,21 @@ tu_hal_close(struct hw_device_t *dev)
|
|||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the VkImage using the gralloc handle in *gralloc_info.
|
||||
*
|
||||
* We support two different grallocs here, gbm_gralloc, and the qcom gralloc
|
||||
* used on Android phones.
|
||||
*/
|
||||
/* get dma-buf and modifier from gralloc info */
|
||||
VkResult
|
||||
tu_image_from_gralloc(VkDevice device_h,
|
||||
const VkImageCreateInfo *base_info,
|
||||
const VkNativeBufferANDROID *gralloc_info,
|
||||
const VkAllocationCallbacks *alloc,
|
||||
VkImage *out_image_h)
|
||||
tu_gralloc_info(struct tu_device *device,
|
||||
const VkNativeBufferANDROID *gralloc_info,
|
||||
int *dma_buf,
|
||||
uint64_t *modifier)
|
||||
|
||||
{
|
||||
TU_FROM_HANDLE(tu_device, device, device_h);
|
||||
VkImage image_h = VK_NULL_HANDLE;
|
||||
struct tu_image *image = NULL;
|
||||
VkResult result;
|
||||
bool ubwc = false;
|
||||
|
||||
const uint32_t *handle_fds = (uint32_t *)gralloc_info->handle->data;
|
||||
const uint32_t *handle_data = &handle_fds[gralloc_info->handle->numFds];
|
||||
int dma_buf;
|
||||
bool ubwc = false;
|
||||
|
||||
if (gralloc_info->handle->numFds == 1) {
|
||||
/* gbm_gralloc. TODO: modifiers support */
|
||||
dma_buf = handle_fds[0];
|
||||
*dma_buf = handle_fds[0];
|
||||
} else if (gralloc_info->handle->numFds == 2) {
|
||||
/* Qualcomm gralloc, find it at:
|
||||
*
|
||||
|
@ -174,7 +162,7 @@ tu_image_from_gralloc(VkDevice device_h,
|
|||
* of CPU-side metadata. I haven't found any need for the metadata buffer
|
||||
* yet. See qdMetaData.h for what's in the metadata fd.
|
||||
*/
|
||||
dma_buf = handle_fds[0];
|
||||
*dma_buf = handle_fds[0];
|
||||
} else {
|
||||
return vk_errorf(device->instance, VK_ERROR_INVALID_EXTERNAL_HANDLE,
|
||||
"VkNativeBufferANDROID::handle::numFds is %d, "
|
||||
|
@ -182,13 +170,27 @@ tu_image_from_gralloc(VkDevice device_h,
|
|||
gralloc_info->handle->numFds);
|
||||
}
|
||||
|
||||
result = tu_image_create(device_h, base_info, alloc, &image_h,
|
||||
ubwc ?
|
||||
DRM_FORMAT_MOD_QCOM_COMPRESSED :
|
||||
DRM_FORMAT_MOD_LINEAR,
|
||||
NULL);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
*modifier = ubwc ? DRM_FORMAT_MOD_QCOM_COMPRESSED : DRM_FORMAT_MOD_LINEAR;
|
||||
return VK_SUCCESS;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the VkImage using the gralloc handle in *gralloc_info.
|
||||
*
|
||||
* We support two different grallocs here, gbm_gralloc, and the qcom gralloc
|
||||
* used on Android phones.
|
||||
*/
|
||||
VkResult
|
||||
tu_import_memory_from_gralloc_handle(VkDevice device_h,
|
||||
int dma_buf,
|
||||
const VkAllocationCallbacks *alloc,
|
||||
VkImage image_h)
|
||||
|
||||
{
|
||||
struct tu_image *image = NULL;
|
||||
VkResult result;
|
||||
|
||||
image = tu_image_from_handle(image_h);
|
||||
|
||||
|
@ -223,8 +225,6 @@ tu_image_from_gralloc(VkDevice device_h,
|
|||
tu_BindImageMemory(device_h, image_h, memory_h, 0);
|
||||
|
||||
image->owned_memory = memory_h;
|
||||
/* Don't clobber the out-parameter until success is certain. */
|
||||
*out_image_h = image_h;
|
||||
|
||||
return VK_SUCCESS;
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ tu6_plane_index(VkFormat format, VkImageAspectFlags aspect_mask)
|
|||
}
|
||||
}
|
||||
|
||||
VkResult
|
||||
static VkResult
|
||||
tu_image_create(VkDevice _device,
|
||||
const VkImageCreateInfo *pCreateInfo,
|
||||
const VkAllocationCallbacks *alloc,
|
||||
|
@ -698,15 +698,6 @@ tu_CreateImage(VkDevice device,
|
|||
const VkAllocationCallbacks *pAllocator,
|
||||
VkImage *pImage)
|
||||
{
|
||||
#ifdef ANDROID
|
||||
const VkNativeBufferANDROID *gralloc_info =
|
||||
vk_find_struct_const(pCreateInfo->pNext, NATIVE_BUFFER_ANDROID);
|
||||
|
||||
if (gralloc_info)
|
||||
return tu_image_from_gralloc(device, pCreateInfo, gralloc_info,
|
||||
pAllocator, pImage);
|
||||
#endif
|
||||
|
||||
uint64_t modifier = DRM_FORMAT_MOD_INVALID;
|
||||
const VkSubresourceLayout *plane_layouts = NULL;
|
||||
|
||||
|
@ -739,7 +730,26 @@ tu_CreateImage(VkDevice device,
|
|||
modifier = DRM_FORMAT_MOD_LINEAR;
|
||||
}
|
||||
|
||||
return tu_image_create(device, pCreateInfo, pAllocator, pImage, modifier, plane_layouts);
|
||||
#ifdef ANDROID
|
||||
const VkNativeBufferANDROID *gralloc_info =
|
||||
vk_find_struct_const(pCreateInfo->pNext, NATIVE_BUFFER_ANDROID);
|
||||
int dma_buf;
|
||||
if (gralloc_info) {
|
||||
VkResult result = tu_gralloc_info(device, gralloc_info, &dma_buf, &modifier);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
VkResult result = tu_image_create(device, pCreateInfo, pAllocator, pImage, modifier, plane_layouts);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
||||
#ifdef ANDROID
|
||||
if (gralloc_info)
|
||||
return tu_import_memory_from_gralloc_handle(device, dma_buf, pAllocator, *pImage);
|
||||
#endif
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -1369,19 +1369,16 @@ tu_cs_image_stencil_ref(struct tu_cs *cs, const struct tu_image_view *iview, uin
|
|||
((iview->x & ~A6XX_##x##_COLOR_FORMAT__MASK) | A6XX_##x##_COLOR_FORMAT(FMT6_8_UINT))
|
||||
|
||||
VkResult
|
||||
tu_image_create(VkDevice _device,
|
||||
const VkImageCreateInfo *pCreateInfo,
|
||||
const VkAllocationCallbacks *alloc,
|
||||
VkImage *pImage,
|
||||
uint64_t modifier,
|
||||
const VkSubresourceLayout *plane_layouts);
|
||||
tu_gralloc_info(struct tu_device *device,
|
||||
const VkNativeBufferANDROID *gralloc_info,
|
||||
int *dma_buf,
|
||||
uint64_t *modifier);
|
||||
|
||||
VkResult
|
||||
tu_image_from_gralloc(VkDevice device_h,
|
||||
const VkImageCreateInfo *base_info,
|
||||
const VkNativeBufferANDROID *gralloc_info,
|
||||
const VkAllocationCallbacks *alloc,
|
||||
VkImage *out_image_h);
|
||||
tu_import_memory_from_gralloc_handle(VkDevice device_h,
|
||||
int dma_buf,
|
||||
const VkAllocationCallbacks *alloc,
|
||||
VkImage image_h);
|
||||
|
||||
void
|
||||
tu_image_view_init(struct tu_image_view *iview,
|
||||
|
|
Loading…
Reference in New Issue