Skip to content

Commit

Permalink
Bypass YUV conversions if the Vulkan format is not-undefined.
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde committed Mar 4, 2024
1 parent 28ea031 commit dd87020
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,13 @@ static vk::UniqueImageView CreateVKImageView(
: 1u;
view_info.subresourceRange.layerCount = ahb_desc.layers;

view_chain.get<vk::SamplerYcbcrConversionInfo>().conversion = yuv_conversion;
// We need a custom YUV conversion only if we don't recognize the format.
if (view_info.format == vk::Format::eUndefined) {
view_chain.get<vk::SamplerYcbcrConversionInfo>().conversion =
yuv_conversion;
} else {
view_chain.unlink<vk::SamplerYcbcrConversionInfo>();
}

auto image_view = device.createImageViewUnique(view_info);
if (image_view.result != vk::Result::eSuccess) {
Expand Down Expand Up @@ -350,6 +356,7 @@ AndroidHardwareBufferTextureSourceVK::AndroidHardwareBufferTextureSourceVK(
return;
}

needs_yuv_conversion_ = ahb_format.format == vk::Format::eUndefined;
device_memory_ = std::move(device_memory);
image_ = std::move(image);
yuv_conversion_ = std::move(yuv_conversion);
Expand Down Expand Up @@ -397,7 +404,7 @@ bool AndroidHardwareBufferTextureSourceVK::IsSwapchainImage() const {
// |TextureSourceVK|
std::shared_ptr<YUVConversionVK>
AndroidHardwareBufferTextureSourceVK::GetYUVConversion() const {
return yuv_conversion_;
return needs_yuv_conversion_ ? yuv_conversion_ : nullptr;
}

} // namespace impeller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class AndroidHardwareBufferTextureSourceVK final : public TextureSourceVK {
vk::UniqueImage image_;
vk::UniqueImageView image_view_;
std::shared_ptr<YUVConversionVK> yuv_conversion_;
bool needs_yuv_conversion_ = false;
bool is_valid_ = false;

AndroidHardwareBufferTextureSourceVK(
Expand Down

0 comments on commit dd87020

Please sign in to comment.