Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
DawnCaps.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_DawnCaps_DEFINED
9#define skgpu_graphite_DawnCaps_DEFINED
10
12
13#include <array>
14
15#include "webgpu/webgpu_cpp.h" // NO_G3_REWRITE
16
17namespace skgpu::graphite {
18struct ContextOptions;
19
20struct DawnBackendContext;
21
22class DawnCaps final : public Caps {
23public:
25 ~DawnCaps() override;
26
27 bool useAsyncPipelineCreation() const { return fUseAsyncPipelineCreation; }
28 bool allowScopedErrorChecks() const { return fAllowScopedErrorChecks; }
29
31 Mipmapped mipmapped,
33 Renderable) const override;
35 Mipmapped mipmapped) const override;
37 Mipmapped mipmapped,
38 Protected) const override;
39 TextureInfo getDefaultMSAATextureInfo(const TextureInfo& singleSampledInfo,
40 Discardable discardable) const override;
42 uint32_t sampleCount,
43 Protected) const override;
46 const SkISize colorAttachmentDimensions) const override;
48 const RenderPassDesc&) const override;
50 uint32_t channelMask(const TextureInfo&) const override;
51 bool isRenderable(const TextureInfo&) const override;
52 bool isStorage(const TextureInfo&) const override;
53 void buildKeyForTexture(SkISize dimensions,
54 const TextureInfo&,
57 GraphiteResourceKey*) const override;
58 uint64_t getRenderPassDescKey(const RenderPassDesc& renderPassDesc) const;
59
60 static constexpr size_t kFormatCnt = 16;
61
62private:
63 const ColorTypeInfo* getColorTypeInfo(SkColorType, const TextureInfo&) const override;
64 bool onIsTexturable(const TextureInfo&) const override;
65 bool supportsWritePixels(const TextureInfo& textureInfo) const override;
66 bool supportsReadPixels(const TextureInfo& textureInfo) const override;
67 std::pair<SkColorType, bool /*isRGBFormat*/> supportedWritePixelsColorType(
68 SkColorType dstColorType,
69 const TextureInfo& dstTextureInfo,
70 SkColorType srcColorType) const override;
71 std::pair<SkColorType, bool /*isRGBFormat*/> supportedReadPixelsColorType(
72 SkColorType srcColorType,
73 const TextureInfo& srcTextureInfo,
74 SkColorType dstColorType) const override;
75
76 void initCaps(const DawnBackendContext& backendContext, const ContextOptions& options);
77 void initShaderCaps(const wgpu::Device& device);
78 void initFormatTable(const wgpu::Device& device);
79
80 wgpu::TextureFormat getFormatFromColorType(SkColorType colorType) const {
81 int idx = static_cast<int>(colorType);
82 return fColorTypeToFormatTable[idx];
83 }
84
85 uint32_t maxRenderTargetSampleCount(wgpu::TextureFormat format) const;
86 bool isTexturable(wgpu::TextureFormat format) const;
87 bool isRenderable(wgpu::TextureFormat format, uint32_t numSamples) const;
88
89 struct FormatInfo {
90 uint32_t colorTypeFlags(SkColorType colorType) const {
91 for (int i = 0; i < fColorTypeInfoCount; ++i) {
92 if (fColorTypeInfos[i].fColorType == colorType) {
93 return fColorTypeInfos[i].fFlags;
94 }
95 }
96 return 0;
97 }
98
99 enum {
100 kTexturable_Flag = 0x01,
101 kRenderable_Flag = 0x02, // Color attachment and blendable
102 kMSAA_Flag = 0x04,
103 kResolve_Flag = 0x08,
104 kStorage_Flag = 0x10,
105 };
106 static const uint16_t kAllFlags =
107 kTexturable_Flag | kRenderable_Flag | kMSAA_Flag | kResolve_Flag | kStorage_Flag;
108
109 uint16_t fFlags = 0;
110
111 std::unique_ptr<ColorTypeInfo[]> fColorTypeInfos;
112 int fColorTypeInfoCount = 0;
113 };
114 // Size here must match size of kFormats in DawnCaps.cpp
115 std::array<FormatInfo, kFormatCnt> fFormatTable;
116
117 static size_t GetFormatIndex(wgpu::TextureFormat format);
118 const FormatInfo& getFormatInfo(wgpu::TextureFormat format) const {
119 size_t index = GetFormatIndex(format);
120 return fFormatTable[index];
121 }
122
123 wgpu::TextureFormat fColorTypeToFormatTable[kSkColorTypeCnt];
124 void setColorType(SkColorType, std::initializer_list<wgpu::TextureFormat> formats);
125
126#if !defined(__EMSCRIPTEN__)
127 bool fTransientAttachmentSupport = false;
128#endif
129
130 bool fUseAsyncPipelineCreation = true;
131 bool fAllowScopedErrorChecks = true;
132};
133
134} // namespace skgpu::graphite
135
136#endif // skgpu_graphite_DawnCaps_DEFINED
const char * options
SkColorType fColorType
uint16_t fFlags
SkColorType
Definition SkColorType.h:19
static constexpr int kSkColorTypeCnt
Definition SkColorType.h:68
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static constexpr size_t kFormatCnt
Definition DawnCaps.h:60
uint64_t getRenderPassDescKey(const RenderPassDesc &renderPassDesc) const
Definition DawnCaps.cpp:836
void buildKeyForTexture(SkISize dimensions, const TextureInfo &, ResourceType, Shareable, GraphiteResourceKey *) const override
Definition DawnCaps.cpp:888
TextureInfo getDefaultStorageTextureInfo(SkColorType) const override
Definition DawnCaps.cpp:301
bool onIsTexturable(const TextureInfo &) const override
Definition DawnCaps.cpp:86
std::pair< SkColorType, bool > supportedWritePixelsColorType(SkColorType dstColorType, const TextureInfo &dstTextureInfo, SkColorType srcColorType) const override
Definition DawnCaps.cpp:373
bool allowScopedErrorChecks() const
Definition DawnCaps.h:28
bool isStorage(const TextureInfo &) const override
Definition DawnCaps.cpp:155
bool useAsyncPipelineCreation() const
Definition DawnCaps.h:27
std::pair< SkColorType, bool > supportedReadPixelsColorType(SkColorType srcColorType, const TextureInfo &srcTextureInfo, SkColorType dstColorType) const override
Definition DawnCaps.cpp:380
const ColorTypeInfo * getColorTypeInfo(SkColorType, const TextureInfo &) const override
Definition DawnCaps.cpp:344
bool isRenderable(const TextureInfo &) const override
Definition DawnCaps.cpp:149
bool supportsWritePixels(const TextureInfo &textureInfo) const override
Definition DawnCaps.cpp:363
TextureInfo getDefaultSampledTextureInfo(SkColorType, Mipmapped mipmapped, Protected, Renderable) const override
Definition DawnCaps.cpp:182
SkISize getDepthAttachmentDimensions(const TextureInfo &, const SkISize colorAttachmentDimensions) const override
Definition DawnCaps.cpp:326
TextureInfo getDefaultDepthStencilTextureInfo(SkEnumBitMask< DepthStencilFlags >, uint32_t sampleCount, Protected) const override
Definition DawnCaps.cpp:281
uint32_t channelMask(const TextureInfo &) const override
Definition DawnCaps.cpp:82
UniqueKey makeComputePipelineKey(const ComputePipelineDesc &) const override
Definition DawnCaps.cpp:871
UniqueKey makeGraphicsPipelineKey(const GraphicsPipelineDesc &, const RenderPassDesc &) const override
Definition DawnCaps.cpp:849
TextureInfo getTextureInfoForSampledCopy(const TextureInfo &textureInfo, Mipmapped mipmapped) const override
Definition DawnCaps.cpp:208
TextureInfo getDefaultCompressedTextureInfo(SkTextureCompressionType, Mipmapped mipmapped, Protected) const override
Definition DawnCaps.cpp:236
bool supportsReadPixels(const TextureInfo &textureInfo) const override
Definition DawnCaps.cpp:368
TextureInfo getDefaultMSAATextureInfo(const TextureInfo &singleSampledInfo, Discardable discardable) const override
Definition DawnCaps.cpp:258
VkDevice device
Definition main.cc:53
uint32_t uint32_t * format
uint32_t ResourceType
Renderable
Definition GpuTypes.h:69
Mipmapped
Definition GpuTypes.h:53
Protected
Definition GpuTypes.h:61