| Flutter Impeller |

yuv_conversion_vk.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/renderer/backend/vulkan/yuv_conversion_vk.h"
6
7 #include "flutter/fml/hash_combine.h"
8 #include "impeller/base/validation.h"
9 #include "impeller/renderer/backend/vulkan/device_holder_vk.h"
10 #include "impeller/renderer/backend/vulkan/sampler_vk.h"
11
12 namespace impeller {
13
14 YUVConversionVK::YUVConversionVK(const vk::Device& device,
15 const YUVConversionDescriptorVK& chain)
16 : chain_(chain) {
17 auto conversion = device.createSamplerYcbcrConversionUnique(chain_.get());
18 if (conversion.result != vk::Result::eSuccess) {
19 VALIDATION_LOG << "Could not create YUV conversion: "
20 << vk::to_string(conversion.result);
21 return;
22 }
23 conversion_ = std::move(conversion.value);
24 }
25
26 YUVConversionVK::~YUVConversionVK() = default;
27
28 bool YUVConversionVK::IsValid() const {
29 return conversion_ && !!conversion_.get();
30 }
31
32 vk::SamplerYcbcrConversion YUVConversionVK::GetConversion() const {
33 return conversion_ ? conversion_.get()
34 : static_cast<vk::SamplerYcbcrConversion>(VK_NULL_HANDLE);
35 }
36
37 const YUVConversionDescriptorVK& YUVConversionVK::GetDescriptor() const {
38 return chain_;
39 }
40
41 std::size_t YUVConversionDescriptorVKHash::operator()(
42 const YUVConversionDescriptorVK& desc) const {
43 // Hashers in Vulkan HPP hash the pNext member which isn't what we want for
44 // these to be stable.
45 const auto& conv = desc.get();
46
47 std::size_t hash = fml::HashCombine(conv.format, //
48 conv.ycbcrModel, //
49 conv.ycbcrRange, //
50 conv.components.r, //
51 conv.components.g, //
52 conv.components.b, //
53 conv.components.a, //
54 conv.xChromaOffset, //
55 conv.yChromaOffset, //
56 conv.chromaFilter, //
57 conv.forceExplicitReconstruction //
58 );
59 #if FML_OS_ANDROID
60 const auto external_format = desc.get<vk::ExternalFormatANDROID>();
61 fml::HashCombineSeed(hash, external_format.externalFormat);
62 #endif // FML_OS_ANDROID
63
64 return hash;
65 };
66
67 bool YUVConversionDescriptorVKEqual::operator()(
68 const YUVConversionDescriptorVK& lhs_desc,
69 const YUVConversionDescriptorVK& rhs_desc) const {
70 // Default equality checks in Vulkan HPP checks pNext member members by
71 // pointer which isn't what we want.
72 {
73 const auto& lhs = lhs_desc.get();
74 const auto& rhs = rhs_desc.get();
75
76 if (lhs.format != rhs.format || //
77 lhs.ycbcrModel != rhs.ycbcrModel || //
78 lhs.ycbcrRange != rhs.ycbcrRange || //
79 lhs.components.r != rhs.components.r || //
80 lhs.components.g != rhs.components.g || //
81 lhs.components.b != rhs.components.b || //
82 lhs.components.a != rhs.components.a || //
83 lhs.xChromaOffset != rhs.xChromaOffset || //
84 lhs.yChromaOffset != rhs.yChromaOffset || //
85 lhs.chromaFilter != rhs.chromaFilter || //
86 lhs.forceExplicitReconstruction != rhs.forceExplicitReconstruction //
87 ) {
88 return false;
89 }
90 }
91 #if FML_OS_ANDROID
92 {
93 const auto lhs = lhs_desc.get<vk::ExternalFormatANDROID>();
94 const auto rhs = rhs_desc.get<vk::ExternalFormatANDROID>();
95 return lhs.externalFormat == rhs.externalFormat;
96 }
97 #else // FML_OS_ANDROID
98 return true;
99 #endif // FML_OS_ANDROID
100 }
101
102 ImmutableSamplerKeyVK::ImmutableSamplerKeyVK(const SamplerVK& sampler)
103 : sampler(sampler.GetDescriptor()) {
104 if (const auto& conversion = sampler.GetYUVConversion()) {
105 yuv_conversion = conversion->GetDescriptor();
106 }
107 }
108
109 bool ImmutableSamplerKeyVK::IsEqual(const ImmutableSamplerKeyVK& other) const {
110 return sampler.IsEqual(other.sampler) &&
111 YUVConversionDescriptorVKEqual{}(yuv_conversion, other.yuv_conversion);
112 }
113
114 std::size_t ImmutableSamplerKeyVK::GetHash() const {
115 return fml::HashCombine(sampler.GetHash(),
116 YUVConversionDescriptorVKHash{}(yuv_conversion));
117 }
118
119 } // namespace impeller
impeller::ImmutableSamplerKeyVK
Definition: yuv_conversion_vk.h:94
impeller::ImmutableSamplerKeyVK::ImmutableSamplerKeyVK
ImmutableSamplerKeyVK(const SamplerVK &sampler)
Definition: yuv_conversion_vk.cc:102
validation.h
impeller::SamplerDescriptor::GetHash
std::size_t GetHash() const override
Definition: sampler_descriptor.h:34
impeller::YUVConversionVK::IsValid
bool IsValid() const
Definition: yuv_conversion_vk.cc:28
impeller::SamplerVK
Definition: sampler_vk.h:19
impeller::YUVConversionVK::GetConversion
vk::SamplerYcbcrConversion GetConversion() const
Definition: yuv_conversion_vk.cc:32
impeller::YUVConversionDescriptorVKHash
Definition: yuv_conversion_vk.h:85
device_holder_vk.h
impeller::YUVConversionVK::YUVConversionVK
YUVConversionVK(const YUVConversionVK &)=delete
impeller::ImmutableSamplerKeyVK::IsEqual
bool IsEqual(const ImmutableSamplerKeyVK &other) const override
Definition: yuv_conversion_vk.cc:109
impeller::YUVConversionVK::GetDescriptor
const YUVConversionDescriptorVK & GetDescriptor() const
Get the descriptor used to create this conversion.
Definition: yuv_conversion_vk.cc:37
impeller::YUVConversionVK::~YUVConversionVK
~YUVConversionVK()
impeller::ImmutableSamplerKeyVK::GetHash
std::size_t GetHash() const override
Definition: yuv_conversion_vk.cc:114
impeller::ImmutableSamplerKeyVK::yuv_conversion
YUVConversionDescriptorVK yuv_conversion
Definition: yuv_conversion_vk.h:96
impeller::YUVConversionDescriptorVKEqual
Definition: yuv_conversion_vk.h:89
impeller::YUVConversionDescriptorVKHash::operator()
std::size_t operator()(const YUVConversionDescriptorVK &object) const
Definition: yuv_conversion_vk.cc:41
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:73
yuv_conversion_vk.h
sampler_vk.h
impeller::YUVConversionDescriptorVKEqual::operator()
bool operator()(const YUVConversionDescriptorVK &lhs, const YUVConversionDescriptorVK &rhs) const
Definition: yuv_conversion_vk.cc:67
impeller::ImmutableSamplerKeyVK::sampler
SamplerDescriptor sampler
Definition: yuv_conversion_vk.h:95
impeller::YUVConversionDescriptorVK
vk::StructureChain< vk::SamplerYcbcrConversionCreateInfo > YUVConversionDescriptorVK
Definition: yuv_conversion_vk.h:30
impeller
Definition: aiks_blur_unittests.cc:20
impeller::SamplerDescriptor::IsEqual
bool IsEqual(const SamplerDescriptor &o) const override
Definition: sampler_descriptor.h:41