}
VkFormat
-vn_android_ahb_format_to_vk_format(uint32_t format)
+vn_android_drm_format_to_vk_format(uint32_t format)
{
switch (format) {
- case AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM:
- case AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM:
+ case DRM_FORMAT_ABGR8888:
+ case DRM_FORMAT_XBGR8888:
return VK_FORMAT_R8G8B8A8_UNORM;
- case AHARDWAREBUFFER_FORMAT_R8G8B8_UNORM:
+ case DRM_FORMAT_BGR888:
return VK_FORMAT_R8G8B8_UNORM;
- case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
+ case DRM_FORMAT_RGB565:
return VK_FORMAT_R5G6B5_UNORM_PACK16;
- case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT:
+ case DRM_FORMAT_ABGR16161616F:
return VK_FORMAT_R16G16B16A16_SFLOAT;
- case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM:
+ case DRM_FORMAT_ABGR2101010:
return VK_FORMAT_A2B10G10R10_UNORM_PACK32;
- case AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420:
- /* XXX Add a gralloc query for the resolved drm format and then map to a
- * compatiable VkFormat.
- */
- case AHARDWAREBUFFER_FORMAT_IMPLEMENTATION_DEFINED:
+ case DRM_FORMAT_YVU420:
+ case DRM_FORMAT_NV12:
return VK_FORMAT_G8_B8R8_2PLANE_420_UNORM;
default:
return VK_FORMAT_UNDEFINED;
}
struct cros_gralloc0_buffer_info {
- uint32_t drm_fourcc; /* ignored */
+ uint32_t drm_fourcc;
int num_fds; /* ignored */
int fds[4]; /* ignored */
uint64_t modifier;
};
struct vn_android_gralloc_buffer_properties {
+ uint32_t drm_fourcc;
uint64_t modifier;
uint32_t offset[4];
uint32_t stride[4];
if (info.modifier == DRM_FORMAT_MOD_INVALID)
return false;
+ out_props->drm_fourcc = info.drm_fourcc;
for (uint32_t i = 0; i < 4; i++) {
out_props->stride[i] = info.stride[i];
out_props->offset[i] = info.offset[i];
return VK_ERROR_INVALID_EXTERNAL_HANDLE;
}
+ /* Handle the special AHARDWAREBUFFER_FORMAT_BLOB for VkBuffer case. */
+ if (desc.format == AHARDWAREBUFFER_FORMAT_BLOB) {
+ out_props->format = VK_FORMAT_UNDEFINED;
+ return VK_SUCCESS;
+ }
+
+ if (!vn_android_get_gralloc_buffer_properties(
+ AHardwareBuffer_getNativeHandle(ahb), &buf_props))
+ return VK_ERROR_INVALID_EXTERNAL_HANDLE;
+
/* We implement AHB extension support with EXT_image_drm_format_modifier.
* It requires us to have a compatible VkFormat but not DRM formats. So if
* the ahb is not intended for backing a VkBuffer, error out early if the
* format is VK_FORMAT_UNDEFINED.
*/
- format = vn_android_ahb_format_to_vk_format(desc.format);
+ format = vn_android_drm_format_to_vk_format(buf_props.drm_fourcc);
if (format == VK_FORMAT_UNDEFINED) {
- if (desc.format != AHARDWAREBUFFER_FORMAT_BLOB) {
- vn_log(dev->instance, "Unknown AHB format(0x%X)", desc.format);
- return VK_ERROR_INVALID_EXTERNAL_HANDLE;
- }
-
- out_props->format = format;
- out_props->externalFormat = desc.format;
- return VK_SUCCESS;
- }
-
- if (!vn_android_get_gralloc_buffer_properties(
- AHardwareBuffer_getNativeHandle(ahb), &buf_props))
+ vn_log(dev->instance, "Unknown drm_fourcc(%u) from AHB format(0x%X)",
+ buf_props.drm_fourcc, desc.format);
return VK_ERROR_INVALID_EXTERNAL_HANDLE;
+ }
VkResult result = vn_android_get_modifier_properties(
dev, format, buf_props.modifier, &dev->base.base.alloc, &mod_props);
.sType = out_props->sType,
.pNext = out_props->pNext,
.format = format,
- .externalFormat = desc.format,
+ .externalFormat = buf_props.drm_fourcc,
.formatFeatures = format_features,
.samplerYcbcrConversionComponents = {
.r = VK_COMPONENT_SWIZZLE_IDENTITY,
local_info = *create_info;
local_info.format =
- vn_android_ahb_format_to_vk_format(ext_info->externalFormat);
+ vn_android_drm_format_to_vk_format(ext_info->externalFormat);
create_info = &local_info;
}
if (ext_info && ext_info->externalFormat) {
assert(pCreateInfo->format == VK_FORMAT_UNDEFINED);
- VkFormat format =
- vn_android_ahb_format_to_vk_format(ext_info->externalFormat);
- if (format == VK_FORMAT_UNDEFINED)
- return vn_error(dev->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
-
local_info = *pCreateInfo;
- local_info.format = format;
+ local_info.format =
+ vn_android_drm_format_to_vk_format(ext_info->externalFormat);
local_info.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
local_info.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
local_info.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
local_info.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
pCreateInfo = &local_info;
+
+ assert(pCreateInfo->format != VK_FORMAT_UNDEFINED);
}
struct vn_sampler_ycbcr_conversion *conv =