Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit af0528e

Browse files
authored
[Impeller] Use linear sampling to sample from AHB textures in Vulkan. (#54233)
Fixes flutter/flutter#152579 This now matches Skia OpenGL behavior with SurfaceTexture. ![flutter_04](https://github.com/user-attachments/assets/ccae62a0-4b46-4776-b8ee-f7314722aa68)
1 parent 0b42657 commit af0528e

File tree

2 files changed

+10
-19
lines changed

2 files changed

+10
-19
lines changed

impeller/renderer/backend/vulkan/android/ahb_texture_source_vk.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ static std::shared_ptr<YUVConversionVK> CreateYUVConversion(
146146
const auto& ahb_format =
147147
ahb_props.get<vk::AndroidHardwareBufferFormatPropertiesANDROID>();
148148

149+
const bool supports_linear_filtering =
150+
!!(ahb_format.formatFeatures &
151+
vk::FormatFeatureFlagBits::eSampledImageYcbcrConversionLinearFilter);
152+
149153
auto& conversion_info = conversion_chain.get();
150154

151155
conversion_info.format = ahb_format.format;
@@ -154,12 +158,8 @@ static std::shared_ptr<YUVConversionVK> CreateYUVConversion(
154158
conversion_info.components = ahb_format.samplerYcbcrConversionComponents;
155159
conversion_info.xChromaOffset = ahb_format.suggestedXChromaOffset;
156160
conversion_info.yChromaOffset = ahb_format.suggestedYChromaOffset;
157-
// If the potential format features of the sampler Y′CBCR conversion do not
158-
// support VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT,
159-
// chromaFilter must not be VK_FILTER_LINEAR.
160-
//
161-
// Since we are not checking, let's just default to a safe value.
162-
conversion_info.chromaFilter = vk::Filter::eNearest;
161+
conversion_info.chromaFilter =
162+
supports_linear_filtering ? vk::Filter::eLinear : vk::Filter::eNearest;
163163
conversion_info.forceExplicitReconstruction = false;
164164

165165
if (conversion_info.format == vk::Format::eUndefined) {

impeller/renderer/backend/vulkan/sampler_vk.cc

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,18 @@ static vk::UniqueSampler CreateSampler(
5555
sampler_chain.get<vk::SamplerYcbcrConversionInfo>().conversion =
5656
yuv_conversion->GetConversion();
5757

58-
//
59-
// TL;DR: When using YUV conversion, our samplers are somewhat hobbled and
60-
// not all options configurable in Impeller (especially the linear
61-
// filtering which is by far the most used form of filtering) can be
62-
// supported. Switch to safe defaults.
63-
//
6458
// Spec: If sampler Y'CBCR conversion is enabled and the potential format
6559
// features of the sampler Y'CBCR conversion do not support or enable
6660
// separate reconstruction filters, minFilter and magFilter must be equal to
6761
// the sampler Y'CBCR conversion's chromaFilter.
6862
//
69-
// Thing is, we don't enable separate reconstruction filters. By the time we
70-
// are here, we also don't have access to the descriptor used to create this
71-
// conversion. So we don't yet know what the chromaFilter is. But eNearest
72-
// is a safe bet since the `AndroidHardwareBufferTextureSourceVK` defaults
73-
// to that safe value. So just use that.
63+
// We don't enable separate reconstruction filters. So, just do what the
64+
// spec. says and use the conversions chromaFilter.
7465
//
7566
// See the validation VUID-VkSamplerCreateInfo-minFilter-01645 for more.
7667
//
77-
sampler_info.magFilter = vk::Filter::eNearest;
78-
sampler_info.minFilter = vk::Filter::eNearest;
68+
sampler_info.minFilter = sampler_info.magFilter =
69+
yuv_conversion->GetDescriptor().get().chromaFilter;
7970

8071
// Spec: If sampler Y′CBCR conversion is enabled, addressModeU,
8172
// addressModeV, and addressModeW must be

0 commit comments

Comments
 (0)