From 60a58538aad90a09e87ce08b489b07ed55573e69 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Tue, 30 Jul 2024 15:22:59 -0700 Subject: [PATCH] [Impeller] Use linear sampling to sample from AHB textures in Vulkan. (flutter/engine#54233) Fixes https://github.com/flutter/flutter/issues/152579 This now matches Skia OpenGL behavior with SurfaceTexture. ![flutter_04](https://github.com/user-attachments/assets/ccae62a0-4b46-4776-b8ee-f7314722aa68) --- .../vulkan/android/ahb_texture_source_vk.cc | 12 ++++++------ .../renderer/backend/vulkan/sampler_vk.cc | 17 ++++------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/engine/src/flutter/impeller/renderer/backend/vulkan/android/ahb_texture_source_vk.cc b/engine/src/flutter/impeller/renderer/backend/vulkan/android/ahb_texture_source_vk.cc index c6d0197bac..fb4c37b894 100644 --- a/engine/src/flutter/impeller/renderer/backend/vulkan/android/ahb_texture_source_vk.cc +++ b/engine/src/flutter/impeller/renderer/backend/vulkan/android/ahb_texture_source_vk.cc @@ -146,6 +146,10 @@ static std::shared_ptr CreateYUVConversion( const auto& ahb_format = ahb_props.get(); + const bool supports_linear_filtering = + !!(ahb_format.formatFeatures & + vk::FormatFeatureFlagBits::eSampledImageYcbcrConversionLinearFilter); + auto& conversion_info = conversion_chain.get(); conversion_info.format = ahb_format.format; @@ -154,12 +158,8 @@ static std::shared_ptr CreateYUVConversion( conversion_info.components = ahb_format.samplerYcbcrConversionComponents; conversion_info.xChromaOffset = ahb_format.suggestedXChromaOffset; conversion_info.yChromaOffset = ahb_format.suggestedYChromaOffset; - // If the potential format features of the sampler Y′CBCR conversion do not - // support VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT, - // chromaFilter must not be VK_FILTER_LINEAR. - // - // Since we are not checking, let's just default to a safe value. - conversion_info.chromaFilter = vk::Filter::eNearest; + conversion_info.chromaFilter = + supports_linear_filtering ? vk::Filter::eLinear : vk::Filter::eNearest; conversion_info.forceExplicitReconstruction = false; if (conversion_info.format == vk::Format::eUndefined) { diff --git a/engine/src/flutter/impeller/renderer/backend/vulkan/sampler_vk.cc b/engine/src/flutter/impeller/renderer/backend/vulkan/sampler_vk.cc index 2d7bfe1c01..836f9bdd24 100644 --- a/engine/src/flutter/impeller/renderer/backend/vulkan/sampler_vk.cc +++ b/engine/src/flutter/impeller/renderer/backend/vulkan/sampler_vk.cc @@ -55,27 +55,18 @@ static vk::UniqueSampler CreateSampler( sampler_chain.get().conversion = yuv_conversion->GetConversion(); - // - // TL;DR: When using YUV conversion, our samplers are somewhat hobbled and - // not all options configurable in Impeller (especially the linear - // filtering which is by far the most used form of filtering) can be - // supported. Switch to safe defaults. - // // Spec: If sampler Y'CBCR conversion is enabled and the potential format // features of the sampler Y'CBCR conversion do not support or enable // separate reconstruction filters, minFilter and magFilter must be equal to // the sampler Y'CBCR conversion's chromaFilter. // - // Thing is, we don't enable separate reconstruction filters. By the time we - // are here, we also don't have access to the descriptor used to create this - // conversion. So we don't yet know what the chromaFilter is. But eNearest - // is a safe bet since the `AndroidHardwareBufferTextureSourceVK` defaults - // to that safe value. So just use that. + // We don't enable separate reconstruction filters. So, just do what the + // spec. says and use the conversions chromaFilter. // // See the validation VUID-VkSamplerCreateInfo-minFilter-01645 for more. // - sampler_info.magFilter = vk::Filter::eNearest; - sampler_info.minFilter = vk::Filter::eNearest; + sampler_info.minFilter = sampler_info.magFilter = + yuv_conversion->GetDescriptor().get().chromaFilter; // Spec: If sampler Y′CBCR conversion is enabled, addressModeU, // addressModeV, and addressModeW must be