Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GrD3DCaps.h
Go to the documentation of this file.
1
2/*
3 * Copyright 2020 Google LLC
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#ifndef GrD3DCaps_DEFINED
10#define GrD3DCaps_DEFINED
11
13
17
19
20/**
21 * Stores some capabilities of a D3D backend.
22 */
23class GrD3DCaps : public GrCaps {
24public:
25 /**
26 * Creates a GrD3DCaps that is set such that nothing is supported. The init function should
27 * be called to fill out the caps.
28 */
29 GrD3DCaps(const GrContextOptions& contextOptions, IDXGIAdapter1*, ID3D12Device*);
30
31 bool isFormatSRGB(const GrBackendFormat&) const override;
32
33 bool isFormatTexturable(const GrBackendFormat&, GrTextureType) const override;
34 bool isFormatTexturable(DXGI_FORMAT) const;
35
36 bool isFormatCopyable(const GrBackendFormat&) const override { return true; }
37
39 int sampleCount = 1) const override;
40 bool isFormatRenderable(const GrBackendFormat& format, int sampleCount) const override;
41 bool isFormatRenderable(DXGI_FORMAT, int sampleCount) const;
42
43 bool isFormatUnorderedAccessible(DXGI_FORMAT) const;
44
45 int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat&) const override;
46 int getRenderTargetSampleCount(int requestedCount, DXGI_FORMAT) const;
47
48 int maxRenderTargetSampleCount(const GrBackendFormat&) const override;
49 int maxRenderTargetSampleCount(DXGI_FORMAT) const;
50
51 GrColorType getFormatColorType(DXGI_FORMAT) const;
52
53 SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType,
54 const GrBackendFormat& surfaceFormat,
55 GrColorType srcColorType) const override;
56
58
59 /**
60 * Returns both a supported and most preferred stencil format to use in draws.
61 */
62 DXGI_FORMAT preferredStencilFormat() const {
63 return fPreferredStencilFormat;
64 }
65 static int GetStencilFormatTotalBitCount(DXGI_FORMAT format) {
66 switch (format) {
67 case DXGI_FORMAT_D24_UNORM_S8_UINT:
68 return 32;
69 case DXGI_FORMAT_D32_FLOAT_S8X24_UINT:
70 // DXGI_FORMAT_D32_FLOAT_S8X24_UINT has 24 unused bits at the end so total bits is 64.
71 return 64;
72 default:
73 SkASSERT(false);
74 return 0;
75 }
76 }
77
78 /**
79 * Helpers used by canCopySurface. In all cases if the SampleCnt parameter is zero that means
80 * the surface is not a render target, otherwise it is the number of samples in the render
81 * target.
82 */
83 bool canCopyTexture(DXGI_FORMAT dstFormat, int dstSampleCnt,
84 DXGI_FORMAT srcFormat, int srcSamplecnt) const;
85
86 bool canCopyAsResolve(DXGI_FORMAT dstFormat, int dstSampleCnt,
87 DXGI_FORMAT srcFormat, int srcSamplecnt) const;
88
90
92 int idx = static_cast<int>(colorType);
93 return fColorTypeToFormatTable[idx];
94 }
95
97
98 uint64_t computeFormatKey(const GrBackendFormat&) const override;
99
102 const GrBackendFormat&) const override;
103
105 const GrProgramInfo&,
106 ProgramDescOverrideFlags) const override;
107
108 bool resolveSubresourceRegionSupport() const { return fResolveSubresourceRegionSupport; }
109 bool standardSwizzleLayoutSupport() const { return fStandardSwizzleLayoutSupport; }
110
111#if defined(GR_TEST_UTILS)
112 std::vector<GrTest::TestFormatColorTypeCombination> getTestingCombinations() const override;
113#endif
114
115private:
116 enum D3DVendor {
117 kAMD_D3DVendor = 0x1002,
118 kARM_D3DVendor = 0x13B5,
119 kImagination_D3DVendor = 0x1010,
120 kIntel_D3DVendor = 0x8086,
121 kNVIDIA_D3DVendor = 0x10DE,
122 kQualcomm_D3DVendor = 0x5143,
123 };
124
125 void init(const GrContextOptions& contextOptions, IDXGIAdapter1*, ID3D12Device*);
126
127 void initGrCaps(const D3D12_FEATURE_DATA_D3D12_OPTIONS&,
128 ID3D12Device*);
129 void initShaderCaps(int vendorID, const D3D12_FEATURE_DATA_D3D12_OPTIONS& optionsDesc);
130
131 void initFormatTable(const DXGI_ADAPTER_DESC&, ID3D12Device*);
132 void initStencilFormat(ID3D12Device*);
133
134 void applyDriverCorrectnessWorkarounds(int vendorID);
135
136 bool onSurfaceSupportsWritePixels(const GrSurface*) const override;
137 bool onCanCopySurface(const GrSurfaceProxy* dst, const SkIRect& dstRect,
138 const GrSurfaceProxy* src, const SkIRect& srcRect) const override;
140
142
144 GrColorType) const override;
145
147
148 // ColorTypeInfo for a specific format
149 struct ColorTypeInfo {
151 enum {
152 kUploadData_Flag = 0x1,
153 // Does Ganesh itself support rendering to this colorType & format pair. Renderability
154 // still additionally depends on if the format itself is renderable.
155 kRenderable_Flag = 0x2,
156 // Indicates that this colorType is supported only if we are wrapping a texture with
157 // the given format and colorType. We do not allow creation with this pair.
158 kWrappedOnly_Flag = 0x4,
159 };
160 uint32_t fFlags = 0;
161
162 skgpu::Swizzle fReadSwizzle;
163 skgpu::Swizzle fWriteSwizzle;
164 };
165
166 struct FormatInfo {
167 uint32_t colorTypeFlags(GrColorType colorType) const {
168 for (int i = 0; i < fColorTypeInfoCount; ++i) {
169 if (fColorTypeInfos[i].fColorType == colorType) {
170 return fColorTypeInfos[i].fFlags;
171 }
172 }
173 return 0;
174 }
175
176 void init(const DXGI_ADAPTER_DESC&, ID3D12Device*, DXGI_FORMAT);
177 static void InitFormatFlags(const D3D12_FEATURE_DATA_FORMAT_SUPPORT&, uint16_t* flags);
178 void initSampleCounts(const DXGI_ADAPTER_DESC& adapterDesc, ID3D12Device*, DXGI_FORMAT);
179
180 enum {
181 kTexturable_Flag = 0x1, // Can be sampled in a shader
182 kRenderable_Flag = 0x2, // Rendertarget and blendable
183 kMSAA_Flag = 0x4,
184 kResolve_Flag = 0x8,
185 kUnorderedAccess_Flag = 0x10,
186 };
187
188 uint16_t fFlags = 0;
189
190 SkTDArray<int> fColorSampleCounts;
191
192 // This GrColorType represents how the actually GPU format lays out its memory. This is used
193 // for uploading data to backend textures to make sure we've arranged the memory in the
194 // correct order.
195 GrColorType fFormatColorType = GrColorType::kUnknown;
196
197 std::unique_ptr<ColorTypeInfo[]> fColorTypeInfos;
198 int fColorTypeInfoCount = 0;
199 };
200 static const size_t kNumDxgiFormats = 15;
201 FormatInfo fFormatTable[kNumDxgiFormats];
202
203 FormatInfo& getFormatInfo(DXGI_FORMAT);
204 const FormatInfo& getFormatInfo(DXGI_FORMAT) const;
205
206 DXGI_FORMAT fColorTypeToFormatTable[kGrColorTypeCnt];
207 void setColorType(GrColorType, std::initializer_list<DXGI_FORMAT> formats);
208
209 int fMaxPerStageShaderResourceViews;
210 int fMaxPerStageUnorderedAccessViews;
211
212 DXGI_FORMAT fPreferredStencilFormat;
213
214 bool fResolveSubresourceRegionSupport : 1;
215 bool fStandardSwizzleLayoutSupport : 1;
216
217 using INHERITED = GrCaps;
218};
219
220#endif
static const int kGrColorTypeCnt
GrTextureType
GrColorType
SkColorType fColorType
uint16_t fFlags
#define SkASSERT(cond)
Definition SkAssert.h:116
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
SurfaceReadPixelsSupport
Definition GrCaps.h:296
ProgramDescOverrideFlags
Definition GrCaps.h:511
GrProgramDesc makeDesc(GrRenderTarget *, const GrProgramInfo &, ProgramDescOverrideFlags) const override
skgpu::Swizzle onGetReadSwizzle(const GrBackendFormat &, GrColorType) const override
GrColorType getFormatColorType(DXGI_FORMAT) const
DXGI_FORMAT getFormatFromColorType(GrColorType colorType) const
Definition GrD3DCaps.h:91
bool isFormatSRGB(const GrBackendFormat &) const override
bool canCopyTexture(DXGI_FORMAT dstFormat, int dstSampleCnt, DXGI_FORMAT srcFormat, int srcSamplecnt) const
Definition GrD3DCaps.cpp:72
int maxRenderTargetSampleCount(const GrBackendFormat &) const override
uint64_t computeFormatKey(const GrBackendFormat &) const override
bool standardSwizzleLayoutSupport() const
Definition GrD3DCaps.h:109
bool isFormatRenderable(const GrBackendFormat &format, int sampleCount) const override
bool onCanCopySurface(const GrSurfaceProxy *dst, const SkIRect &dstRect, const GrSurfaceProxy *src, const SkIRect &srcRect) const override
bool isFormatAsColorTypeRenderable(GrColorType ct, const GrBackendFormat &format, int sampleCount=1) const override
void addExtraSamplerKey(skgpu::KeyBuilder *, GrSamplerState, const GrBackendFormat &) const override
SupportedRead onSupportedReadPixelsColorType(GrColorType, const GrBackendFormat &, GrColorType) const override
SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType, const GrBackendFormat &surfaceFormat, GrColorType srcColorType) const override
bool onAreColorTypeAndFormatCompatible(GrColorType, const GrBackendFormat &) const override
DXGI_FORMAT preferredStencilFormat() const
Definition GrD3DCaps.h:62
GrBackendFormat onGetDefaultBackendFormat(GrColorType) const override
bool canCopyAsResolve(DXGI_FORMAT dstFormat, int dstSampleCnt, DXGI_FORMAT srcFormat, int srcSamplecnt) const
Definition GrD3DCaps.cpp:83
bool isFormatTexturable(const GrBackendFormat &, GrTextureType) const override
bool onSurfaceSupportsWritePixels(const GrSurface *) const override
GrBackendFormat getBackendFormatFromCompressionType(SkTextureCompressionType) const override
bool isFormatCopyable(const GrBackendFormat &) const override
Definition GrD3DCaps.h:36
static int GetStencilFormatTotalBitCount(DXGI_FORMAT format)
Definition GrD3DCaps.h:65
SurfaceReadPixelsSupport surfaceSupportsReadPixels(const GrSurface *) const override
int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat &) const override
bool resolveSubresourceRegionSupport() const
Definition GrD3DCaps.h:108
bool isFormatUnorderedAccessible(DXGI_FORMAT) const
skgpu::Swizzle getWriteSwizzle(const GrBackendFormat &, GrColorType) const override
FlutterSemanticsFlag flags
uint32_t uint32_t * format
init(device_serial, adb_binary)
Definition _adb_path.py:12