flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
164.96k stars 27.17k forks source link

[Impeller] Allow both linear and nearest sampling of AHB backed Vulkan textures. #152584

Open chinmaygarde opened 1 month ago

chinmaygarde commented 1 month ago

Today, AHB backed textures will prefer linear sampling (after checking for VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT) and fallback to nearest sampling. That is, sampling will ignore the min and mag filter specified in the impeller::SamplerDescriptor. This is because of stricter requirements when sampling from AHBs.

If VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT is not supported, there is no way linear sample without a render to an intermediate texture.

On the other hand, if VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT is supported, using nearest sampling is not possible today because we create only a single conversion.

It may be tempting to just check for VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_SEPARATE_RECONSTRUCTION_FILTER_BIT and use whatever is specified in the impeller::SamplerDescriptor. While this is extremely convenient, in practice, this bit is never set on most Android formats.

To work around this, a completely separate conversion must be created and cached in the conversions library. And, in the relatively uncommon case where linear sampling is not supported, a separate render to texture must be performed.

This describes an edge case since most uses require linear sampling and that seems to be well supported out of the box. But, if we get reports of users depending on specific kinds of sampling, we should look into using separate conversions and (in extreme cases to catch lack of support for direct linear sampling) render to texture.

chinmaygarde commented 1 month ago

Edge case but wanted to write down how this could be done if we need it.

chinmaygarde commented 1 month ago

xref https://github.com/flutter/engine/pull/54233