Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrMtlCaps.h
Go to the documentation of this file.
1/*
2 * Copyright 2017 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 GrMtlCaps_DEFINED
9#define GrMtlCaps_DEFINED
10
14
15#import <Metal/Metal.h>
16
19
20/**
21 * Stores some capabilities of a Mtl backend.
22 */
23class GrMtlCaps : public GrCaps {
24public:
25 GrMtlCaps(const GrContextOptions& contextOptions, id<MTLDevice> device);
26
27 bool isFormatSRGB(const GrBackendFormat&) const override;
28
29 bool isFormatTexturable(const GrBackendFormat&, GrTextureType) const override;
30 bool isFormatTexturable(MTLPixelFormat) const;
31
32 bool isFormatCopyable(const GrBackendFormat&) const override { return true; }
33
35 int sampleCount = 1) const override;
36 bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const override;
37 bool isFormatRenderable(MTLPixelFormat, int sampleCount) const;
38
39 int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat&) const override;
40 int getRenderTargetSampleCount(int requestedCount, MTLPixelFormat) const;
41
42 int maxRenderTargetSampleCount(const GrBackendFormat&) const override;
43 int maxRenderTargetSampleCount(MTLPixelFormat) const;
44
45 SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType,
46 const GrBackendFormat& surfaceFormat,
47 GrColorType srcColorType) const override;
48
50
51 DstCopyRestrictions getDstCopyRestrictions(const GrRenderTargetProxy* src,
52 GrColorType ct) const override;
53
54 /**
55 * Returns both a supported and most prefered stencil format to use in draws.
56 */
57 MTLPixelFormat preferredStencilFormat() const {
58 return fPreferredStencilFormat;
59 }
60
61 bool canCopyAsBlit(MTLPixelFormat dstFormat, int dstSampleCount,
62 MTLPixelFormat srcFormat, int srcSampleCount,
63 const SkIRect& srcRect, const SkIPoint& dstPoint,
64 bool areDstSrcSameObj) const;
65
66 bool canCopyAsResolve(MTLPixelFormat dstFormat, int dstSampleCount,
67 MTLPixelFormat srcFormat, int srcSampleCount,
68 bool srcIsRenderTarget, const SkISize srcDimensions,
69 const SkIRect& srcRect,
70 const SkIPoint& dstPoint,
71 bool areDstSrcSameObj) const;
72
74
76 int idx = static_cast<int>(colorType);
77 return fColorTypeToFormatTable[idx];
78 }
79
81
82 uint64_t computeFormatKey(const GrBackendFormat&) const override;
83
85 const GrProgramInfo&,
86 ProgramDescOverrideFlags) const override;
87 MTLPixelFormat getStencilPixelFormat(const GrProgramDesc& desc) const;
88
89 bool isMac() const { return fGPUFamily == GPUFamily::kMac; }
90 bool isApple() const { return fGPUFamily == GPUFamily::kApple; }
91
92 size_t getMinBufferAlignment() const { return this->isMac() ? 4 : 1; }
93
94 // if true, MTLStoreActionStoreAndMultiplesampleResolve is available
95 bool storeAndMultisampleResolveSupport() const { return fStoreAndMultisampleResolveSupport; }
96
98
99#if defined(GR_TEST_UTILS)
100 std::vector<GrTest::TestFormatColorTypeCombination> getTestingCombinations() const override;
101#endif
102 void onDumpJSON(SkJSONWriter*) const override;
103
104private:
105 void initGPUFamily(id<MTLDevice> device);
106
107 void initStencilFormat(id<MTLDevice> device);
108
109 void initGrCaps(id<MTLDevice> device);
110 void initShaderCaps();
111
112 void applyDriverCorrectnessWorkarounds(const GrContextOptions&, const id<MTLDevice>);
113
114 void initFormatTable();
115
116 bool onSurfaceSupportsWritePixels(const GrSurface*) const override;
117 bool onCanCopySurface(const GrSurfaceProxy* dst, const SkIRect& dstRect,
118 const GrSurfaceProxy* src, const SkIRect& srcRect) const override;
121
123 GrColorType) const override;
124
126
127 // ColorTypeInfo for a specific format
128 struct ColorTypeInfo {
130 enum {
131 kUploadData_Flag = 0x1,
132 // Does Ganesh itself support rendering to this colorType & format pair. Renderability
133 // still additionally depends on if the format itself is renderable.
134 kRenderable_Flag = 0x2,
135 };
136 uint32_t fFlags = 0;
137
138 skgpu::Swizzle fReadSwizzle;
139 skgpu::Swizzle fWriteSwizzle;
140 };
141
142 struct FormatInfo {
143 uint32_t colorTypeFlags(GrColorType colorType) const {
144 for (int i = 0; i < fColorTypeInfoCount; ++i) {
145 if (fColorTypeInfos[i].fColorType == colorType) {
146 return fColorTypeInfos[i].fFlags;
147 }
148 }
149 return 0;
150 }
151
152 enum {
153 kTexturable_Flag = 0x1,
154 kRenderable_Flag = 0x2, // Color attachment and blendable
155 kMSAA_Flag = 0x4,
156 kResolve_Flag = 0x8,
157 };
158 static const uint16_t kAllFlags = kTexturable_Flag | kRenderable_Flag |
159 kMSAA_Flag | kResolve_Flag;
160
161 uint16_t fFlags = 0;
162
163 std::unique_ptr<ColorTypeInfo[]> fColorTypeInfos;
164 int fColorTypeInfoCount = 0;
165 };
166#ifdef SK_BUILD_FOR_IOS
167 inline static constexpr size_t kNumMtlFormats = 18;
168#else
169 inline static constexpr size_t kNumMtlFormats = 19;
170#endif
171 static size_t GetFormatIndex(MTLPixelFormat);
172 FormatInfo fFormatTable[kNumMtlFormats];
173
174 const FormatInfo& getFormatInfo(const MTLPixelFormat pixelFormat) const {
175 size_t index = GetFormatIndex(pixelFormat);
176 return fFormatTable[index];
177 }
178
179 MTLPixelFormat fColorTypeToFormatTable[kGrColorTypeCnt];
180 void setColorType(GrColorType, std::initializer_list<MTLPixelFormat> formats);
181
182 enum class GPUFamily {
183 kMac,
184 kApple,
185 };
186 bool getGPUFamily(id<MTLDevice> device, GPUFamily* gpuFamily, int* group);
187 bool getGPUFamilyFromFeatureSet(id<MTLDevice> device, GrMtlCaps::GPUFamily* gpuFamily,
188 int* group);
189
190 GPUFamily fGPUFamily;
191 int fFamilyGroup;
192
193 SkTDArray<int> fSampleCounts;
194
195 MTLPixelFormat fPreferredStencilFormat;
196
197 bool fStoreAndMultisampleResolveSupport : 1;
198
199 using INHERITED = GrCaps;
200};
201
202#endif
static const int kGrColorTypeCnt
GrTextureType
GrColorType
SkColorType fColorType
uint16_t fFlags
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
SurfaceReadPixelsSupport
Definition GrCaps.h:296
ProgramDescOverrideFlags
Definition GrCaps.h:511
bool onCanCopySurface(const GrSurfaceProxy *dst, const SkIRect &dstRect, const GrSurfaceProxy *src, const SkIRect &srcRect) const override
Definition GrMtlCaps.mm:315
SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface *) const override
bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat &format, int sampleCount=1) const override
Definition GrMtlCaps.mm:476
int maxRenderTargetSampleCount(const GrBackendFormat &) const override
Definition GrMtlCaps.mm:498
bool storeAndMultisampleResolveSupport() const
Definition GrMtlCaps.h:95
bool isApple() const
Definition GrMtlCaps.h:90
DstCopyRestrictions getDstCopyRestrictions(const GrRenderTargetProxy *src, GrColorType ct) const override
bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat &) const override
bool isFormatSRGB(const GrBackendFormat &) const override
Definition GrMtlCaps.mm:462
MTLPixelFormat preferredStencilFormat() const
Definition GrMtlCaps.h:57
bool isMac() const
Definition GrMtlCaps.h:89
MTLPixelFormat getFormatFromColorType(GrColorType colorType) const
Definition GrMtlCaps.h:75
bool canCopyAsBlit(MTLPixelFormat dstFormat, int dstSampleCount, MTLPixelFormat srcFormat, int srcSampleCount, const SkIRect &srcRect, const SkIPoint &dstPoint, bool areDstSrcSameObj) const
Definition GrMtlCaps.mm:268
bool isFormatTexturable(const GrBackendFormat &, GrTextureType) const override
Definition GrMtlCaps.mm:466
SupportedRead onSupportedReadPixelsColorType(GrColorType, const GrBackendFormat &, GrColorType) const override
int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat &) const override
Definition GrMtlCaps.mm:512
bool canCopyAsResolve(MTLPixelFormat dstFormat, int dstSampleCount, MTLPixelFormat srcFormat, int srcSampleCount, bool srcIsRenderTarget, const SkISize srcDimensions, const SkIRect &srcRect, const SkIPoint &dstPoint, bool areDstSrcSameObj) const
Definition GrMtlCaps.mm:288
GrBackendFormat getBackendFormatFromCompressionType(SkTextureCompressionType) const override
skgpu::Swizzle onGetReadSwizzle(const GrBackendFormat &, GrColorType) const override
SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType, const GrBackendFormat &surfaceFormat, GrColorType srcColorType) const override
skgpu::Swizzle getWriteSwizzle(const GrBackendFormat &, GrColorType) const override
GrBackendFormat onGetDefaultBackendFormat(GrColorType) const override
uint64_t computeFormatKey(const GrBackendFormat &) const override
size_t getMinBufferAlignment() const
Definition GrMtlCaps.h:92
bool isFormatRenderable(const GrBackendFormat &format, int sampleCount) const override
Definition GrMtlCaps.mm:490
bool isFormatCopyable(const GrBackendFormat &) const override
Definition GrMtlCaps.h:32
bool onSurfaceSupportsWritePixels(const GrSurface *) const override
void onDumpJSON(SkJSONWriter *) const override
MTLPixelFormat getStencilPixelFormat(const GrProgramDesc &desc) const
bool renderTargetSupportsDiscardableMSAA(const GrMtlRenderTarget *) const
GrProgramDesc makeDesc(GrRenderTarget *, const GrProgramInfo &, ProgramDescOverrideFlags) const override
VkDevice device
Definition main.cc:53
uint32_t uint32_t * format