| From cc62fbed6d83fa10dc2f30f758d8f34bd4f72593 Mon Sep 17 00:00:00 2001 |
| From: Yiwei Zhang <zzyiwei@chromium.org> |
| Date: Thu, 2 Sep 2021 07:17:37 +0000 |
| Subject: [PATCH] venus: suggest the proper sampler ycbcr model conversion |
| based on format |
| |
| Cc: 21.2.3 mesa-stable |
| |
| Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org> |
| Reviewed-by: Chia-I Wu <olvaffe@gmail.com> |
| Reviewed-by: Ryan Neph <ryanneph@google.com> |
| Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12694> |
| --- |
| src/virtio/vulkan/vn_android.c | 29 ++++++++++++++++++++++++++++- |
| 1 file changed, 28 insertions(+), 1 deletion(-) |
| |
| diff --git a/src/virtio/vulkan/vn_android.c b/src/virtio/vulkan/vn_android.c |
| index 52901e75bd0..72c483833ce 100644 |
| --- a/src/virtio/vulkan/vn_android.c |
| +++ b/src/virtio/vulkan/vn_android.c |
| @@ -151,6 +151,20 @@ vn_android_drm_format_to_vk_format(uint32_t format) |
| } |
| } |
| |
| +static bool |
| +vn_android_drm_format_is_yuv(uint32_t format) |
| +{ |
| + assert(vn_android_drm_format_to_vk_format(format) != VK_FORMAT_UNDEFINED); |
| + |
| + switch (format) { |
| + case DRM_FORMAT_YVU420: |
| + case DRM_FORMAT_NV12: |
| + return true; |
| + default: |
| + return false; |
| + } |
| +} |
| + |
| uint64_t |
| vn_android_get_ahb_usage(const VkImageUsageFlags usage, |
| const VkImageCreateFlags flags) |
| @@ -743,6 +757,19 @@ vn_android_get_ahb_format_properties( |
| const VkFormatFeatureFlags format_features = |
| mod_props.drmFormatModifierTilingFeatures | |
| VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT; |
| + |
| + /* 11.2.7. Android Hardware Buffer External Memory |
| + * |
| + * Implementations may not always be able to determine the color model, |
| + * numerical range, or chroma offsets of the image contents, so the values |
| + * in VkAndroidHardwareBufferFormatPropertiesANDROID are only suggestions. |
| + * Applications should treat these values as sensible defaults to use in the |
| + * absence of more reliable information obtained through some other means. |
| + */ |
| + const VkSamplerYcbcrModelConversion model = |
| + vn_android_drm_format_is_yuv(buf_props.drm_fourcc) |
| + ? VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_601 |
| + : VK_SAMPLER_YCBCR_MODEL_CONVERSION_RGB_IDENTITY; |
| *out_props = (VkAndroidHardwareBufferFormatPropertiesANDROID) { |
| .sType = out_props->sType, |
| .pNext = out_props->pNext, |
| @@ -755,7 +782,7 @@ vn_android_get_ahb_format_properties( |
| .b = VK_COMPONENT_SWIZZLE_IDENTITY, |
| .a = VK_COMPONENT_SWIZZLE_IDENTITY, |
| }, |
| - .suggestedYcbcrModel = VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_601, |
| + .suggestedYcbcrModel = model, |
| .suggestedYcbcrRange = VK_SAMPLER_YCBCR_RANGE_ITU_FULL, |
| .suggestedXChromaOffset = VK_CHROMA_LOCATION_MIDPOINT, |
| .suggestedYChromaOffset = VK_CHROMA_LOCATION_MIDPOINT, |
| -- |
| 2.33.0.153.gba50c8fa24-goog |
| |