[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)
This commit is contained in:
Chinmay Garde
2024-07-30 15:22:59 -07:00
committed by GitHub
parent 2016939425
commit 60a58538aa
2 changed files with 10 additions and 19 deletions

View File

@@ -146,6 +146,10 @@ static std::shared_ptr<YUVConversionVK> CreateYUVConversion(
const auto& ahb_format =
ahb_props.get<vk::AndroidHardwareBufferFormatPropertiesANDROID>();
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<YUVConversionVK> 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) {

View File

@@ -55,27 +55,18 @@ static vk::UniqueSampler CreateSampler(
sampler_chain.get<vk::SamplerYcbcrConversionInfo>().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