Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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"
11
12namespace impeller {
13
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
26YUVConversionVK::~YUVConversionVK() = default;
27
28bool YUVConversionVK::IsValid() const {
29 return conversion_ && !!conversion_.get();
30}
31
32vk::SamplerYcbcrConversion YUVConversionVK::GetConversion() const {
33 return conversion_ ? conversion_.get()
34 : static_cast<vk::SamplerYcbcrConversion>(VK_NULL_HANDLE);
35}
36
37const YUVConversionDescriptorVK& YUVConversionVK::GetDescriptor() const {
38 return chain_;
39}
40
41std::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
67bool 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
102ImmutableSamplerKeyVK::ImmutableSamplerKeyVK(const SamplerVK& sampler)
103 : sampler(sampler.GetDescriptor()) {
104 if (const auto& conversion = sampler.GetYUVConversion()) {
105 yuv_conversion = conversion->GetDescriptor();
106 }
107}
108
113
118
119} // namespace impeller
static uint32_t hash(const SkShaderBase::GradientInfo &v)
const SamplerDescriptor & GetDescriptor() const
Definition sampler.cc:13
YUVConversionVK(const YUVConversionVK &)=delete
VkDevice device
Definition main.cc:53
constexpr std::size_t HashCombine()
constexpr void HashCombineSeed(std::size_t &seed, Type arg)
vk::StructureChain< vk::SamplerYcbcrConversionCreateInfo > YUVConversionDescriptorVK
bool IsEqual(const ImmutableSamplerKeyVK &other) const override
YUVConversionDescriptorVK yuv_conversion
std::size_t GetHash() const override
bool IsEqual(const SamplerDescriptor &o) const override
std::size_t GetHash() const override
#define VALIDATION_LOG
Definition validation.h:73
#define VK_NULL_HANDLE
Definition vulkan_core.h:46