Flutter Engine
The Flutter Engine
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
30 // If this has no value then loading the resolve texture via a LoadOp is not supported.
31 std::optional<wgpu::LoadOp> resolveTextureLoadOp() const {
32 return fSupportedResolveTextureLoadOp;
33 }
34
36 Mipmapped mipmapped,
38 Renderable) const override;
40 Mipmapped mipmapped) const override;
42 Mipmapped mipmapped,
43 Protected) const override;
44 TextureInfo getDefaultMSAATextureInfo(const TextureInfo& singleSampledInfo,
45 Discardable discardable) const override;
47 uint32_t sampleCount,
48 Protected) const override;
51 const SkISize colorAttachmentDimensions) const override;
53 const RenderPassDesc&) const override;
55 uint32_t channelMask(const TextureInfo&) const override;
56 bool isRenderable(const TextureInfo&) const override;
57 bool isStorage(const TextureInfo&) const override;
58 void buildKeyForTexture(SkISize dimensions,
59 const TextureInfo&,
62 GraphiteResourceKey*) const override;
63 uint64_t getRenderPassDescKeyForPipeline(const RenderPassDesc& renderPassDesc) const;
64
65 static constexpr size_t kFormatCnt = 18;
66
67private:
68 const ColorTypeInfo* getColorTypeInfo(SkColorType, const TextureInfo&) const override;
69 bool onIsTexturable(const TextureInfo&) const override;
70 bool supportsWritePixels(const TextureInfo& textureInfo) const override;
71 bool supportsReadPixels(const TextureInfo& textureInfo) const override;
72 std::pair<SkColorType, bool /*isRGBFormat*/> supportedWritePixelsColorType(
73 SkColorType dstColorType,
74 const TextureInfo& dstTextureInfo,
75 SkColorType srcColorType) const override;
76 std::pair<SkColorType, bool /*isRGBFormat*/> supportedReadPixelsColorType(
77 SkColorType srcColorType,
78 const TextureInfo& srcTextureInfo,
79 SkColorType dstColorType) const override;
80
81 void initCaps(const DawnBackendContext& backendContext, const ContextOptions& options);
82 void initShaderCaps(const wgpu::Device& device);
83 void initFormatTable(const wgpu::Device& device);
84
85 wgpu::TextureFormat getFormatFromColorType(SkColorType colorType) const {
86 int idx = static_cast<int>(colorType);
87 return fColorTypeToFormatTable[idx];
88 }
89
90 uint32_t maxRenderTargetSampleCount(wgpu::TextureFormat format) const;
91 bool isTexturable(wgpu::TextureFormat format) const;
92 bool isRenderable(wgpu::TextureFormat format, uint32_t numSamples) const;
93
94 struct FormatInfo {
95 uint32_t colorTypeFlags(SkColorType colorType) const {
96 for (int i = 0; i < fColorTypeInfoCount; ++i) {
97 if (fColorTypeInfos[i].fColorType == colorType) {
98 return fColorTypeInfos[i].fFlags;
99 }
100 }
101 return 0;
102 }
103
104 enum {
105 kTexturable_Flag = 0x01,
106 kRenderable_Flag = 0x02, // Color attachment and blendable
107 kMSAA_Flag = 0x04,
108 kResolve_Flag = 0x08,
109 kStorage_Flag = 0x10,
110 };
111 static const uint16_t kAllFlags =
112 kTexturable_Flag | kRenderable_Flag | kMSAA_Flag | kResolve_Flag | kStorage_Flag;
113
114 uint16_t fFlags = 0;
115
116 std::unique_ptr<ColorTypeInfo[]> fColorTypeInfos;
117 int fColorTypeInfoCount = 0;
118 };
119 // Size here must match size of kFormats in DawnCaps.cpp
120 std::array<FormatInfo, kFormatCnt> fFormatTable;
121
122 static size_t GetFormatIndex(wgpu::TextureFormat format);
123 const FormatInfo& getFormatInfo(wgpu::TextureFormat format) const {
124 size_t index = GetFormatIndex(format);
125 return fFormatTable[index];
126 }
127
128 wgpu::TextureFormat fColorTypeToFormatTable[kSkColorTypeCnt];
129 void setColorType(SkColorType, std::initializer_list<wgpu::TextureFormat> formats);
130
131 // When supported, this value will hold the TransientAttachment usage symbol that is only
132 // defined in Dawn native builds and not EMSCRIPTEN but this avoids having to #define guard it.
133 wgpu::TextureUsage fSupportedTransientAttachmentUsage = wgpu::TextureUsage::None;
134 // When supported this holds the ExpandResolveTexture load op, otherwise holds no value.
135 std::optional<wgpu::LoadOp> fSupportedResolveTextureLoadOp;
136
137 bool fUseAsyncPipelineCreation = true;
138 bool fAllowScopedErrorChecks = true;
139};
140
141} // namespace skgpu::graphite
142
143#endif // skgpu_graphite_DawnCaps_DEFINED
const char * options
SkColorType fColorType
uint16_t fFlags
Definition: ShapeLayer.cpp:106
SkColorType
Definition: SkColorType.h:19
static constexpr int kSkColorTypeCnt
Definition: SkColorType.h:68
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
SkTextureCompressionType
static constexpr size_t kFormatCnt
Definition: DawnCaps.h:65
void buildKeyForTexture(SkISize dimensions, const TextureInfo &, ResourceType, Shareable, GraphiteResourceKey *) const override
Definition: DawnCaps.cpp:941
TextureInfo getDefaultStorageTextureInfo(SkColorType) const override
Definition: DawnCaps.cpp:303
bool allowScopedErrorChecks() const
Definition: DawnCaps.h:28
bool isStorage(const TextureInfo &) const override
Definition: DawnCaps.cpp:160
bool useAsyncPipelineCreation() const
Definition: DawnCaps.h:27
bool isRenderable(const TextureInfo &) const override
Definition: DawnCaps.cpp:154
TextureInfo getDefaultSampledTextureInfo(SkColorType, Mipmapped mipmapped, Protected, Renderable) const override
Definition: DawnCaps.cpp:187
SkISize getDepthAttachmentDimensions(const TextureInfo &, const SkISize colorAttachmentDimensions) const override
Definition: DawnCaps.cpp:328
TextureInfo getDefaultDepthStencilTextureInfo(SkEnumBitMask< DepthStencilFlags >, uint32_t sampleCount, Protected) const override
Definition: DawnCaps.cpp:285
uint32_t channelMask(const TextureInfo &) const override
Definition: DawnCaps.cpp:87
UniqueKey makeComputePipelineKey(const ComputePipelineDesc &) const override
Definition: DawnCaps.cpp:924
DawnCaps(const DawnBackendContext &, const ContextOptions &)
Definition: DawnCaps.cpp:77
UniqueKey makeGraphicsPipelineKey(const GraphicsPipelineDesc &, const RenderPassDesc &) const override
Definition: DawnCaps.cpp:902
TextureInfo getTextureInfoForSampledCopy(const TextureInfo &textureInfo, Mipmapped mipmapped) const override
Definition: DawnCaps.cpp:213
uint64_t getRenderPassDescKeyForPipeline(const RenderPassDesc &renderPassDesc) const
Definition: DawnCaps.cpp:870
TextureInfo getDefaultCompressedTextureInfo(SkTextureCompressionType, Mipmapped mipmapped, Protected) const override
Definition: DawnCaps.cpp:241
std::optional< wgpu::LoadOp > resolveTextureLoadOp() const
Definition: DawnCaps.h:31
TextureInfo getDefaultMSAATextureInfo(const TextureInfo &singleSampledInfo, Discardable discardable) const override
Definition: DawnCaps.cpp:263
VkDevice device
Definition: main.cc:53
uint32_t uint32_t * format
TextureUsage
Definition: formats.h:300
uint32_t ResourceType
Renderable
Definition: GpuTypes.h:69
Mipmapped
Definition: GpuTypes.h:53
Protected
Definition: GpuTypes.h:61
Definition: SkSize.h:16