v3dv/android: Use u_gralloc code
Use generic u_gralloc logic instead of custom. Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com> Reviewed-by: Alejandro Piñeiro <apinheiro@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25028>
This commit is contained in:
parent
083e7d3a92
commit
83b90c4400
5 changed files with 30 additions and 140 deletions
|
|
@ -101,7 +101,7 @@ if with_platform_wayland
|
|||
endif
|
||||
|
||||
if with_platform_android
|
||||
v3dv_deps += dep_android
|
||||
v3dv_deps += [dep_android, idep_u_gralloc]
|
||||
v3dv_flags += '-DVK_USE_PLATFORM_ANDROID_KHR'
|
||||
libv3dv_files += files('v3dv_android.c')
|
||||
endif
|
||||
|
|
|
|||
|
|
@ -112,119 +112,6 @@ v3dv_hal_close(struct hw_device_t *dev)
|
|||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
get_format_bpp(int native)
|
||||
{
|
||||
int bpp;
|
||||
|
||||
switch (native) {
|
||||
case HAL_PIXEL_FORMAT_RGBA_FP16:
|
||||
bpp = 8;
|
||||
break;
|
||||
case HAL_PIXEL_FORMAT_RGBA_8888:
|
||||
case HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED:
|
||||
case HAL_PIXEL_FORMAT_RGBX_8888:
|
||||
case HAL_PIXEL_FORMAT_BGRA_8888:
|
||||
case HAL_PIXEL_FORMAT_RGBA_1010102:
|
||||
bpp = 4;
|
||||
break;
|
||||
case HAL_PIXEL_FORMAT_RGB_565:
|
||||
bpp = 2;
|
||||
break;
|
||||
default:
|
||||
bpp = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return bpp;
|
||||
}
|
||||
|
||||
/* get buffer info from VkNativeBufferANDROID */
|
||||
static VkResult
|
||||
v3dv_gralloc_info_other(struct v3dv_device *device,
|
||||
const VkNativeBufferANDROID *native_buffer,
|
||||
int *out_stride,
|
||||
uint64_t *out_modifier)
|
||||
{
|
||||
*out_stride = native_buffer->stride /*in pixels*/ *
|
||||
get_format_bpp(native_buffer->format);
|
||||
*out_modifier = DRM_FORMAT_MOD_LINEAR;
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
static const char cros_gralloc_module_name[] = "CrOS Gralloc";
|
||||
|
||||
#define CROS_GRALLOC_DRM_GET_BUFFER_INFO 4
|
||||
|
||||
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
|
||||
v3dv_gralloc_info_cros(struct v3dv_device *device,
|
||||
const VkNativeBufferANDROID *native_buffer,
|
||||
int *out_stride,
|
||||
uint64_t *out_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,
|
||||
native_buffer->handle, &info);
|
||||
if (ret)
|
||||
return VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
||||
|
||||
*out_stride = info.stride[0];
|
||||
*out_modifier = info.modifier;
|
||||
|
||||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkResult
|
||||
v3dv_gralloc_info(struct v3dv_device *device,
|
||||
const VkNativeBufferANDROID *native_buffer,
|
||||
int *out_dmabuf,
|
||||
int *out_stride,
|
||||
int *out_size,
|
||||
uint64_t *out_modifier)
|
||||
{
|
||||
if (device->gralloc_type == V3DV_GRALLOC_UNKNOWN) {
|
||||
/* get gralloc module for gralloc buffer info query */
|
||||
int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
|
||||
(const hw_module_t **) &device->gralloc);
|
||||
|
||||
device->gralloc_type = V3DV_GRALLOC_OTHER;
|
||||
|
||||
if (err == 0) {
|
||||
const gralloc_module_t *gralloc = device->gralloc;
|
||||
mesa_logi("opened gralloc module name: %s", gralloc->common.name);
|
||||
|
||||
if (strcmp(gralloc->common.name, cros_gralloc_module_name) == 0 &&
|
||||
gralloc->perform) {
|
||||
device->gralloc_type = V3DV_GRALLOC_CROS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*out_dmabuf = native_buffer->handle->data[0];
|
||||
*out_size = lseek(*out_dmabuf, 0, SEEK_END);
|
||||
|
||||
if (device->gralloc_type == V3DV_GRALLOC_CROS) {
|
||||
return v3dv_gralloc_info_cros(device, native_buffer, out_stride,
|
||||
out_modifier);
|
||||
} else {
|
||||
return v3dv_gralloc_info_other(device, native_buffer, out_stride,
|
||||
out_modifier);
|
||||
}
|
||||
}
|
||||
|
||||
VkResult
|
||||
v3dv_import_native_buffer_fd(VkDevice device_h,
|
||||
int native_buffer_fd,
|
||||
|
|
|
|||
|
|
@ -1968,6 +1968,11 @@ v3dv_CreateDevice(VkPhysicalDevice physicalDevice,
|
|||
return vk_error(NULL, result);
|
||||
}
|
||||
|
||||
#ifdef ANDROID
|
||||
device->gralloc = u_gralloc_create(U_GRALLOC_TYPE_AUTO);
|
||||
assert(device->gralloc);
|
||||
#endif
|
||||
|
||||
device->instance = instance;
|
||||
device->pdevice = physical_device;
|
||||
|
||||
|
|
@ -2034,6 +2039,9 @@ fail:
|
|||
v3dv_event_free_resources(device);
|
||||
v3dv_query_free_resources(device);
|
||||
vk_device_finish(&device->vk);
|
||||
#ifdef ANDROID
|
||||
u_gralloc_destroy(&device->gralloc);
|
||||
#endif
|
||||
vk_free(&device->vk.alloc, device);
|
||||
|
||||
return result;
|
||||
|
|
@ -2072,6 +2080,9 @@ v3dv_DestroyDevice(VkDevice _device,
|
|||
mtx_destroy(&device->query_mutex);
|
||||
|
||||
vk_device_finish(&device->vk);
|
||||
#ifdef ANDROID
|
||||
u_gralloc_destroy(&device->gralloc);
|
||||
#endif
|
||||
vk_free2(&device->vk.alloc, pAllocator, device);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -361,18 +361,19 @@ v3dv_image_init(struct v3dv_device *device,
|
|||
const VkNativeBufferANDROID *native_buffer =
|
||||
vk_find_struct_const(pCreateInfo->pNext, NATIVE_BUFFER_ANDROID);
|
||||
|
||||
int native_buf_fd = -1;
|
||||
int native_buf_stride = 0;
|
||||
int native_buf_size = 0;
|
||||
struct u_gralloc_buffer_basic_info buffer_info;
|
||||
|
||||
if (native_buffer != NULL) {
|
||||
VkResult result = v3dv_gralloc_info(device, native_buffer, &native_buf_fd,
|
||||
&native_buf_stride, &native_buf_size,
|
||||
&modifier);
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
struct u_gralloc_buffer_handle u_gralloc_handle = {
|
||||
.handle = native_buffer->handle,
|
||||
.hal_format = native_buffer->format,
|
||||
.pixel_stride = native_buffer->stride,
|
||||
};
|
||||
|
||||
if (modifier != DRM_FORMAT_MOD_BROADCOM_UIF)
|
||||
if (u_gralloc_get_buffer_basic_info(device->gralloc, &u_gralloc_handle, &buffer_info))
|
||||
return VK_ERROR_INVALID_EXTERNAL_HANDLE;
|
||||
|
||||
if (buffer_info.modifier != DRM_FORMAT_MOD_BROADCOM_UIF)
|
||||
tiling = VK_IMAGE_TILING_LINEAR;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -427,13 +428,13 @@ v3dv_image_init(struct v3dv_device *device,
|
|||
#ifdef ANDROID
|
||||
if (native_buffer != NULL) {
|
||||
assert(image->plane_count == 1);
|
||||
image->planes[0].slices[0].stride = native_buf_stride;
|
||||
image->planes[0].slices[0].stride = buffer_info.strides[0];
|
||||
image->non_disjoint_size =
|
||||
image->planes[0].slices[0].size =
|
||||
image->planes[0].size = native_buf_size;
|
||||
image->planes[0].size = lseek(buffer_info.fds[0], 0, SEEK_END);
|
||||
|
||||
VkResult result = v3dv_import_native_buffer_fd(v3dv_device_to_handle(device),
|
||||
native_buf_fd, pAllocator,
|
||||
buffer_info.fds[0], pAllocator,
|
||||
v3dv_image_to_handle(image));
|
||||
if (result != VK_SUCCESS)
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -64,6 +64,10 @@
|
|||
#define VG(x) ((void)0)
|
||||
#endif
|
||||
|
||||
#ifdef ANDROID
|
||||
#include "util/u_gralloc/u_gralloc.h"
|
||||
#endif
|
||||
|
||||
#include "v3dv_limits.h"
|
||||
|
||||
#include "common/v3d_device_info.h"
|
||||
|
|
@ -588,12 +592,7 @@ struct v3dv_device {
|
|||
struct util_dynarray device_address_bo_list; /* Array of struct v3dv_bo * */
|
||||
|
||||
#ifdef ANDROID
|
||||
const void *gralloc;
|
||||
enum {
|
||||
V3DV_GRALLOC_UNKNOWN,
|
||||
V3DV_GRALLOC_CROS,
|
||||
V3DV_GRALLOC_OTHER,
|
||||
} gralloc_type;
|
||||
struct u_gralloc *gralloc;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
@ -2587,14 +2586,6 @@ u64_compare(const void *key1, const void *key2)
|
|||
#endif
|
||||
|
||||
#ifdef ANDROID
|
||||
VkResult
|
||||
v3dv_gralloc_info(struct v3dv_device *device,
|
||||
const VkNativeBufferANDROID *gralloc_info,
|
||||
int *out_dmabuf,
|
||||
int *out_stride,
|
||||
int *out_size,
|
||||
uint64_t *out_modifier);
|
||||
|
||||
VkResult
|
||||
v3dv_import_native_buffer_fd(VkDevice device_h,
|
||||
int dma_buf,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue