Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
VulkanCaps.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google LLC
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 skgpu_graphite_VulkanCaps_DEFINED
9#define skgpu_graphite_VulkanCaps_DEFINED
10
15
16namespace skgpu::graphite {
17struct ContextOptions;
18struct VulkanTextureInfo;
19
20class VulkanCaps final : public Caps {
21public:
24 VkPhysicalDevice,
25 uint32_t physicalDeviceVersion,
28 Protected);
29 ~VulkanCaps() override;
30
32 Mipmapped mipmapped,
34 Renderable) const override;
35
37 Mipmapped mipmapped) const override;
38
40 Mipmapped mipmapped,
41 Protected) const override;
42
43 TextureInfo getDefaultMSAATextureInfo(const TextureInfo& singleSampledInfo,
44 Discardable discardable) const override;
45
47 uint32_t sampleCount,
48 Protected) const override;
49
51
53 const RenderPassDesc&) const override;
54 UniqueKey makeComputePipelineKey(const ComputePipelineDesc&) const override { return {}; }
55
56 GraphiteResourceKey makeSamplerKey(const SamplerDesc&) const override;
57
58 uint32_t channelMask(const TextureInfo&) const override;
59
60 bool isRenderable(const TextureInfo&) const override;
61 bool isStorage(const TextureInfo&) const override;
62
63 void buildKeyForTexture(SkISize dimensions,
64 const TextureInfo&,
67 GraphiteResourceKey*) const override;
68
70 return fShouldAlwaysUseDedicatedImageMemory;
71 }
72
73 // Returns whether a pure GPU accessible buffer is more performant to read than a buffer that is
74 // also host visible. If so then in some cases we may prefer the cost of doing a copy to the
75 // buffer. This typically would only be the case for buffers that are written once and read
76 // many times on the gpu.
77 bool gpuOnlyBuffersMorePerformant() const { return fGpuOnlyBuffersMorePerformant; }
78
79 // For our CPU write and GPU read buffers (vertex, uniform, etc.), we should keep these buffers
80 // persistently mapped. In general, the answer will be yes. The main case where we don't do this
81 // is when using special memory that is DEVICE_LOCAL and HOST_VISIBLE on discrete GPUs.
83 return fShouldPersistentlyMapCpuToGpuBuffers;
84 }
85
86 bool supportsYcbcrConversion() const { return fSupportsYcbcrConversion; }
87
88 bool supportsDeviceFaultInfo() const { return fSupportsDeviceFaultInfo; }
89
90 uint32_t maxVertexAttributes() const {
91 return fMaxVertexAttributes;
92 }
93 uint64_t maxUniformBufferRange() const { return fMaxUniformBufferRange; }
94
96 return fPhysicalDeviceMemoryProperties2;
97 }
98
99 bool isTransferSrc(const VulkanTextureInfo&) const;
100 bool isTransferDst(const VulkanTextureInfo&) const;
101
102private:
103 enum VkVendor {
104 kAMD_VkVendor = 4098,
105 kARM_VkVendor = 5045,
106 kImagination_VkVendor = 4112,
107 kIntel_VkVendor = 32902,
108 kNvidia_VkVendor = 4318,
109 kQualcomm_VkVendor = 20803,
110 };
111
112 void init(const ContextOptions&,
114 VkPhysicalDevice,
115 uint32_t physicalDeviceVersion,
118 Protected);
119
120 void applyDriverCorrectnessWorkarounds(const VkPhysicalDeviceProperties&);
121
122 void initFormatTable(const skgpu::VulkanInterface*,
123 VkPhysicalDevice,
125
126 void initDepthStencilFormatTable(const skgpu::VulkanInterface*,
127 VkPhysicalDevice,
129
130 const ColorTypeInfo* getColorTypeInfo(SkColorType, const TextureInfo&) const override;
131
132 bool onIsTexturable(const TextureInfo&) const override;
133
134 bool supportsWritePixels(const TextureInfo&) const override;
135 bool supportsReadPixels(const TextureInfo&) const override;
136
137 std::pair<SkColorType, bool /*isRGBFormat*/> supportedWritePixelsColorType(
138 SkColorType dstColorType,
139 const TextureInfo& dstTextureInfo,
140 SkColorType srcColorType) const override;
141 std::pair<SkColorType, bool /*isRGBFormat*/> supportedReadPixelsColorType(
142 SkColorType srcColorType,
143 const TextureInfo& srcTextureInfo,
144 SkColorType dstColorType) const override;
145
146 // Struct that determines and stores which sample count quantities a VkFormat supports.
147 struct SupportedSampleCounts {
148 void initSampleCounts(const skgpu::VulkanInterface*,
149 VkPhysicalDevice,
151 VkFormat,
153
154 bool isSampleCountSupported(int requestedCount) const;
155
156 SkTDArray<int> fSampleCounts;
157 };
158
159 // Struct that determines and stores useful information about VkFormats.
160 struct FormatInfo {
161 uint32_t colorTypeFlags(SkColorType colorType) const {
162 for (int i = 0; i < fColorTypeInfoCount; ++i) {
163 if (fColorTypeInfos[i].fColorType == colorType) {
164 return fColorTypeInfos[i].fFlags;
165 }
166 }
167 return 0;
168 }
169
170 void init(const skgpu::VulkanInterface*,
171 VkPhysicalDevice,
173 VkFormat);
174
175 bool isTexturable(VkImageTiling) const;
176 bool isRenderable(VkImageTiling, uint32_t sampleCount) const;
177 bool isStorage(VkImageTiling) const;
178 bool isTransferSrc(VkImageTiling) const;
179 bool isTransferDst(VkImageTiling) const;
180
181 std::unique_ptr<ColorTypeInfo[]> fColorTypeInfos;
182 int fColorTypeInfoCount = 0;
183
184 VkFormatProperties fFormatProperties;
185 SupportedSampleCounts fSupportedSampleCounts;
186
187 // Indicates that a format is only supported if we are wrapping a texture with it.
188 SkDEBUGCODE(bool fIsWrappedOnly = false;)
189 };
190
191 // Map SkColorType to VkFormat.
192 VkFormat fColorTypeToFormatTable[kSkColorTypeCnt];
193 void setColorType(SkColorType, std::initializer_list<VkFormat> formats);
194 VkFormat getFormatFromColorType(SkColorType) const;
195
196 // Map VkFormat to FormatInfo.
197 static const size_t kNumVkFormats = 22;
198 FormatInfo fFormatTable[kNumVkFormats];
199
200 FormatInfo& getFormatInfo(VkFormat);
201 const FormatInfo& getFormatInfo(VkFormat) const;
202
203 // A more lightweight equivalent to FormatInfo for depth/stencil VkFormats.
204 struct DepthStencilFormatInfo {
205 void init(const skgpu::VulkanInterface*,
206 VkPhysicalDevice,
208 VkFormat);
209 bool isDepthStencilSupported(VkFormatFeatureFlags) const;
210
211 VkFormatProperties fFormatProperties;
212 SupportedSampleCounts fSupportedSampleCounts;
213 };
214
215 // Map DepthStencilFlags to VkFormat.
216 static const size_t kNumDepthStencilFlags = 4;
217 VkFormat fDepthStencilFlagsToFormatTable[kNumDepthStencilFlags];
218 VkFormat getFormatFromDepthStencilFlags(const SkEnumBitMask<DepthStencilFlags>& flags) const;
219
220 // Map depth/stencil VkFormats to DepthStencilFormatInfo.
221 static const size_t kNumDepthStencilVkFormats = 3;
222 DepthStencilFormatInfo fDepthStencilFormatTable[kNumDepthStencilVkFormats];
223
224 DepthStencilFormatInfo& getDepthStencilFormatInfo(VkFormat);
225 const DepthStencilFormatInfo& getDepthStencilFormatInfo(VkFormat) const;
226
227 uint32_t fMaxVertexAttributes;
228 uint64_t fMaxUniformBufferRange;
229 VkPhysicalDeviceMemoryProperties2 fPhysicalDeviceMemoryProperties2;
230
231 // Various bools to define whether certain Vulkan features are supported.
232 bool fSupportsMemorylessAttachments = false;
233 bool fSupportsYcbcrConversion = false;
234 bool fShouldAlwaysUseDedicatedImageMemory = false;
235 bool fGpuOnlyBuffersMorePerformant = false;
236 bool fShouldPersistentlyMapCpuToGpuBuffers = true;
237 bool fSupportsDeviceFaultInfo = false;
238};
239
240} // namespace skgpu::graphite
241
242#endif // skgpu_graphite_VulkanCaps_DEFINED
SkColorType fColorType
SkColorType
Definition SkColorType.h:19
static constexpr int kSkColorTypeCnt
Definition SkColorType.h:68
#define SkDEBUGCODE(...)
Definition SkDebug.h:23
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
bool gpuOnlyBuffersMorePerformant() const
Definition VulkanCaps.h:77
TextureInfo getDefaultDepthStencilTextureInfo(SkEnumBitMask< DepthStencilFlags >, uint32_t sampleCount, Protected) const override
const ColorTypeInfo * getColorTypeInfo(SkColorType, const TextureInfo &) const override
std::pair< SkColorType, bool > supportedWritePixelsColorType(SkColorType dstColorType, const TextureInfo &dstTextureInfo, SkColorType srcColorType) const override
bool shouldAlwaysUseDedicatedImageMemory() const
Definition VulkanCaps.h:69
void buildKeyForTexture(SkISize dimensions, const TextureInfo &, ResourceType, Shareable, GraphiteResourceKey *) const override
TextureInfo getTextureInfoForSampledCopy(const TextureInfo &textureInfo, Mipmapped mipmapped) const override
UniqueKey makeGraphicsPipelineKey(const GraphicsPipelineDesc &, const RenderPassDesc &) const override
GraphiteResourceKey makeSamplerKey(const SamplerDesc &) const override
bool supportsYcbcrConversion() const
Definition VulkanCaps.h:86
bool isStorage(const TextureInfo &) const override
bool supportsWritePixels(const TextureInfo &) const override
bool isRenderable(const TextureInfo &) const override
TextureInfo getDefaultSampledTextureInfo(SkColorType, Mipmapped mipmapped, Protected, Renderable) const override
bool isTransferSrc(const VulkanTextureInfo &) const
bool supportsReadPixels(const TextureInfo &) const override
bool isTransferDst(const VulkanTextureInfo &) const
UniqueKey makeComputePipelineKey(const ComputePipelineDesc &) const override
Definition VulkanCaps.h:54
const VkPhysicalDeviceMemoryProperties2 & physicalDeviceMemoryProperties2() const
Definition VulkanCaps.h:95
uint64_t maxUniformBufferRange() const
Definition VulkanCaps.h:93
TextureInfo getDefaultCompressedTextureInfo(SkTextureCompressionType, Mipmapped mipmapped, Protected) const override
TextureInfo getDefaultMSAATextureInfo(const TextureInfo &singleSampledInfo, Discardable discardable) const override
bool supportsDeviceFaultInfo() const
Definition VulkanCaps.h:88
uint32_t maxVertexAttributes() const
Definition VulkanCaps.h:90
bool onIsTexturable(const TextureInfo &) const override
uint32_t channelMask(const TextureInfo &) const override
bool shouldPersistentlyMapCpuToGpuBuffers() const
Definition VulkanCaps.h:82
std::pair< SkColorType, bool > supportedReadPixelsColorType(SkColorType srcColorType, const TextureInfo &srcTextureInfo, SkColorType dstColorType) const override
TextureInfo getDefaultStorageTextureInfo(SkColorType) const override
FlutterSemanticsFlag flags
uint32_t ResourceType
Renderable
Definition GpuTypes.h:69
Mipmapped
Definition GpuTypes.h:53
Protected
Definition GpuTypes.h:61
init(device_serial, adb_binary)
Definition _adb_path.py:12
VkFlags VkImageUsageFlags
VkImageTiling
VkFlags VkFormatFeatureFlags
VkFormat