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 
6 
7 #include "flutter/fml/hash_combine.h"
12 
13 namespace impeller {
14 
15 YUVConversionVK::YUVConversionVK(const vk::Device& device,
16  const YUVConversionDescriptorVK& chain)
17  : chain_(chain) {
18  auto conversion = device.createSamplerYcbcrConversionUnique(chain_.get());
19  if (conversion.result != vk::Result::eSuccess) {
20  VALIDATION_LOG << "Could not create YUV conversion: "
21  << vk::to_string(conversion.result);
22  return;
23  }
24  conversion_ = std::move(conversion.value);
25 }
26 
27 YUVConversionVK::~YUVConversionVK() = default;
28 
29 bool YUVConversionVK::IsValid() const {
30  return conversion_ && !!conversion_.get();
31 }
32 
33 vk::SamplerYcbcrConversion YUVConversionVK::GetConversion() const {
34  return conversion_ ? conversion_.get()
35  : static_cast<vk::SamplerYcbcrConversion>(VK_NULL_HANDLE);
36 }
37 
38 const YUVConversionDescriptorVK& YUVConversionVK::GetDescriptor() const {
39  return chain_;
40 }
41 
42 std::size_t YUVConversionDescriptorVKHash::operator()(
43  const YUVConversionDescriptorVK& desc) const {
44  // Hashers in Vulkan HPP hash the pNext member which isn't what we want for
45  // these to be stable.
46  const auto& conv = desc.get();
47 
48  std::size_t hash = fml::HashCombine(conv.format, //
49  conv.ycbcrModel, //
50  conv.ycbcrRange, //
51  conv.components.r, //
52  conv.components.g, //
53  conv.components.b, //
54  conv.components.a, //
55  conv.xChromaOffset, //
56  conv.yChromaOffset, //
57  conv.chromaFilter, //
58  conv.forceExplicitReconstruction //
59  );
60 #if FML_OS_ANDROID
61  const auto external_format = desc.get<vk::ExternalFormatANDROID>();
62  fml::HashCombineSeed(hash, external_format.externalFormat);
63 #endif // FML_OS_ANDROID
64 
65  return hash;
66 };
67 
68 bool YUVConversionDescriptorVKEqual::operator()(
69  const YUVConversionDescriptorVK& lhs_desc,
70  const YUVConversionDescriptorVK& rhs_desc) const {
71  // Default equality checks in Vulkan HPP checks pNext member members by
72  // pointer which isn't what we want.
73  {
74  const auto& lhs = lhs_desc.get();
75  const auto& rhs = rhs_desc.get();
76 
77  if (lhs.format != rhs.format || //
78  lhs.ycbcrModel != rhs.ycbcrModel || //
79  lhs.ycbcrRange != rhs.ycbcrRange || //
80  lhs.components.r != rhs.components.r || //
81  lhs.components.g != rhs.components.g || //
82  lhs.components.b != rhs.components.b || //
83  lhs.components.a != rhs.components.a || //
84  lhs.xChromaOffset != rhs.xChromaOffset || //
85  lhs.yChromaOffset != rhs.yChromaOffset || //
86  lhs.chromaFilter != rhs.chromaFilter || //
87  lhs.forceExplicitReconstruction != rhs.forceExplicitReconstruction //
88  ) {
89  return false;
90  }
91  }
92 #if FML_OS_ANDROID
93  {
94  const auto lhs = lhs_desc.get<vk::ExternalFormatANDROID>();
95  const auto rhs = rhs_desc.get<vk::ExternalFormatANDROID>();
96  return lhs.externalFormat == rhs.externalFormat;
97  }
98 #else // FML_OS_ANDROID
99  return true;
100 #endif // FML_OS_ANDROID
101 }
102 
103 ImmutableSamplerKeyVK::ImmutableSamplerKeyVK(const SamplerVK& sampler)
104  : sampler(sampler.GetDescriptor()) {
105  if (const auto& conversion = sampler.GetYUVConversion()) {
106  yuv_conversion = conversion->GetDescriptor();
107  }
108 }
109 
114 }
115 
116 std::size_t ImmutableSamplerKeyVK::GetHash() const {
117  return fml::HashCombine(SamplerDescriptor::ToKey(sampler),
119 }
120 
121 } // namespace impeller
GLenum external_format
YUVConversionVK(const YUVConversionVK &)=delete
vk::StructureChain< vk::SamplerYcbcrConversionCreateInfo > YUVConversionDescriptorVK
bool IsEqual(const ImmutableSamplerKeyVK &other) const override
YUVConversionDescriptorVK yuv_conversion
std::size_t GetHash() const override
static uint64_t ToKey(const SamplerDescriptor &d)
#define VALIDATION_LOG
Definition: validation.h:91