Debian Codegraph @

src/gpu/ganesh/vk/GrVkSamplerYcbcrConversion.h

raw
1 /*
2 * Copyright 2018 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef GrVkSamplerYcbcrConverison_DEFINED
9 #define GrVkSamplerYcbcrConverison_DEFINED
10
11 #include "include/private/base/SkDebug.h"
12 #include "include/private/base/SkMacros.h"
13 #include "include/private/gpu/vk/SkiaVulkan.h"
14 #include "src/core/SkChecksum.h"
15 #include "src/gpu/ganesh/GrManagedResource.h"
16 #include "src/gpu/ganesh/vk/GrVkManagedResource.h"
17
18 #include <cinttypes>
19 #include <cstdint>
20 #include <optional>
21
22 class GrVkGpu;
23 namespace skgpu {
24 struct VulkanYcbcrConversionInfo;
25 }
26
27 class GrVkSamplerYcbcrConversion : public GrVkManagedResource {
28 public:
29 static GrVkSamplerYcbcrConversion* Create(GrVkGpu* gpu,
30 const skgpu::VulkanYcbcrConversionInfo&);
31
32 VkSamplerYcbcrConversion ycbcrConversion() const { return fYcbcrConversion; }
33
34 // If the format does not support
35 // VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_SEPARATE_RECONSTRUCTION_FILTER_BIT,
36 // sampler's minFilter and magFilter must match the conversion's chromaFilter, which can be
37 // found in fRequiredFilter. If not set, minFilter and magFilter can be independently set.
38 std::optional<VkFilter> requiredFilter() const { return fRequiredFilter; }
39
40 SK_BEGIN_REQUIRE_DENSE
41 struct Key {
42 Key() = default;
43 Key(VkFormat vkFormat, uint64_t externalFormat, uint32_t conversionKey) {
44 fVkFormat = vkFormat;
45 fExternalFormat = externalFormat;
46 fConversionKey = conversionKey;
47 }
48
49 VkFormat fVkFormat = VK_FORMAT_UNDEFINED;
50 uint32_t fConversionKey = 0;
51 uint64_t fExternalFormat = 0;
52
53 bool operator==(const Key& that) const {
54 return this->fVkFormat == that.fVkFormat &&
55 this->fExternalFormat == that.fExternalFormat &&
56 this->fConversionKey == that.fConversionKey;
57 }
58 };
59 SK_END_REQUIRE_DENSE
60
61 // Helpers for hashing GrVkSamplerYcbcrConversion
62 static Key GenerateKey(const skgpu::VulkanYcbcrConversionInfo& ycbcrInfo);
63
64 static const Key& GetKey(const GrVkSamplerYcbcrConversion& ycbcrConversion) {
65 return ycbcrConversion.fKey;
66 }
67 static uint32_t Hash(const Key& key) {
68 return SkChecksum::Hash32(&key, sizeof(Key));
69 }
70
71 #ifdef SK_TRACE_MANAGED_RESOURCES
72 void dumpInfo() const override {
73 SkDebugf("GrVkSamplerYcbcrConversion: %" PRIdPTR " (%d refs)\n", (intptr_t)fYcbcrConversion,
74 this->getRefCnt());
75 }
76 #endif
77
78 private:
79 GrVkSamplerYcbcrConversion(const GrVkGpu* gpu,
80 VkSamplerYcbcrConversion ycbcrConversion,
81 std::optional<VkFilter> requiredFilter,
82 Key key)
83 : INHERITED(gpu)
84 , fYcbcrConversion(ycbcrConversion)
85 , fRequiredFilter(requiredFilter)
86 , fKey(key) {}
87
88 void freeGPUData() const override;
89
90 VkSamplerYcbcrConversion fYcbcrConversion;
91 std::optional<VkFilter> fRequiredFilter;
92 Key fKey;
93
94 using INHERITED = GrVkManagedResource;
95 };
96
97 #endif
98