1 /*
2 * Copyright 2015 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 #include "GrCaps.h"
9
10 #include "GrBackendSurface.h"
11 #include "GrContextOptions.h"
12 #include "GrWindowRectangles.h"
13 #include "SkJSONWriter.h"
14
pixel_config_name(GrPixelConfig config)15 static const char* pixel_config_name(GrPixelConfig config) {
16 switch (config) {
17 case kUnknown_GrPixelConfig: return "Unknown";
18 case kAlpha_8_GrPixelConfig: return "Alpha8";
19 case kAlpha_8_as_Alpha_GrPixelConfig: return "Alpha8_asAlpha";
20 case kAlpha_8_as_Red_GrPixelConfig: return "Alpha8_asRed";
21 case kGray_8_GrPixelConfig: return "Gray8";
22 case kGray_8_as_Lum_GrPixelConfig: return "Gray8_asLum";
23 case kGray_8_as_Red_GrPixelConfig: return "Gray8_asRed";
24 case kRGB_565_GrPixelConfig: return "RGB565";
25 case kRGBA_4444_GrPixelConfig: return "RGBA444";
26 case kRGBA_8888_GrPixelConfig: return "RGBA8888";
27 case kBGRA_8888_GrPixelConfig: return "BGRA8888";
28 case kSRGBA_8888_GrPixelConfig: return "SRGBA8888";
29 case kSBGRA_8888_GrPixelConfig: return "SBGRA8888";
30 case kRGBA_8888_sint_GrPixelConfig: return "RGBA8888_sint";
31 case kRGBA_float_GrPixelConfig: return "RGBAFloat";
32 case kRG_float_GrPixelConfig: return "RGFloat";
33 case kAlpha_half_GrPixelConfig: return "AlphaHalf";
34 case kAlpha_half_as_Red_GrPixelConfig: return "AlphaHalf_asRed";
35 case kRGBA_half_GrPixelConfig: return "RGBAHalf";
36 }
37 SK_ABORT("Invalid pixel config");
38 return "<invalid>";
39 }
40
GrCaps(const GrContextOptions & options)41 GrCaps::GrCaps(const GrContextOptions& options) {
42 fMipMapSupport = false;
43 fNPOTTextureTileSupport = false;
44 fSRGBSupport = false;
45 fSRGBWriteControl = false;
46 fSRGBDecodeDisableSupport = false;
47 fDiscardRenderTargetSupport = false;
48 fReuseScratchTextures = true;
49 fReuseScratchBuffers = true;
50 fGpuTracingSupport = false;
51 fOversizedStencilSupport = false;
52 fTextureBarrierSupport = false;
53 fSampleLocationsSupport = false;
54 fMultisampleDisableSupport = false;
55 fInstanceAttribSupport = false;
56 fUsesMixedSamples = false;
57 fUsePrimitiveRestart = false;
58 fPreferClientSideDynamicBuffers = false;
59 fPreferFullscreenClears = false;
60 fMustClearUploadedBufferData = false;
61 fSampleShadingSupport = false;
62 fFenceSyncSupport = false;
63 fCrossContextTextureSupport = false;
64
65 fBlendEquationSupport = kBasic_BlendEquationSupport;
66 fAdvBlendEqBlacklist = 0;
67
68 fMapBufferFlags = kNone_MapFlags;
69
70 fMaxVertexAttributes = 0;
71 fMaxRenderTargetSize = 1;
72 fMaxTextureSize = 1;
73 fMaxRasterSamples = 0;
74 fMaxWindowRectangles = 0;
75
76 // An default count of 4 was chosen because of the common pattern in Blink of:
77 // isect RR
78 // diff RR
79 // isect convex_poly
80 // isect convex_poly
81 // when drawing rounded div borders.
82 fMaxClipAnalyticFPs = 4;
83
84 fSuppressPrints = options.fSuppressPrints;
85 #if GR_TEST_UTILS
86 fWireframeMode = options.fWireframeMode;
87 #else
88 fWireframeMode = false;
89 #endif
90 fBufferMapThreshold = options.fBufferMapThreshold;
91 fBlacklistCoverageCounting = false;
92 fAvoidStencilBuffers = false;
93
94 fPreferVRAMUseOverFlushes = true;
95 }
96
applyOptionsOverrides(const GrContextOptions & options)97 void GrCaps::applyOptionsOverrides(const GrContextOptions& options) {
98 this->onApplyOptionsOverrides(options);
99 if (options.fDisableDriverCorrectnessWorkarounds) {
100 // We always blacklist coverage counting on Vulkan currently. TODO: Either stop doing that
101 // or disambiguate blacklisting from incomplete implementation.
102 // SkASSERT(!fBlacklistCoverageCounting);
103 SkASSERT(!fAvoidStencilBuffers);
104 SkASSERT(!fAdvBlendEqBlacklist);
105 }
106
107 fMaxTextureSize = SkTMin(fMaxTextureSize, options.fMaxTextureSizeOverride);
108 fMaxTileSize = fMaxTextureSize;
109 #if GR_TEST_UTILS
110 // If the max tile override is zero, it means we should use the max texture size.
111 if (options.fMaxTileSizeOverride && options.fMaxTileSizeOverride < fMaxTextureSize) {
112 fMaxTileSize = options.fMaxTileSizeOverride;
113 }
114 if (options.fSuppressGeometryShaders) {
115 fShaderCaps->fGeometryShaderSupport = false;
116 }
117 #endif
118 if (fMaxWindowRectangles > GrWindowRectangles::kMaxWindows) {
119 SkDebugf("WARNING: capping window rectangles at %i. HW advertises support for %i.\n",
120 GrWindowRectangles::kMaxWindows, fMaxWindowRectangles);
121 fMaxWindowRectangles = GrWindowRectangles::kMaxWindows;
122 }
123 fAvoidStencilBuffers = options.fAvoidStencilBuffers;
124 }
125
map_flags_to_string(uint32_t flags)126 static SkString map_flags_to_string(uint32_t flags) {
127 SkString str;
128 if (GrCaps::kNone_MapFlags == flags) {
129 str = "none";
130 } else {
131 SkASSERT(GrCaps::kCanMap_MapFlag & flags);
132 SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag);
133 str = "can_map";
134
135 if (GrCaps::kSubset_MapFlag & flags) {
136 str.append(" partial");
137 } else {
138 str.append(" full");
139 }
140 SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag);
141 }
142 SkASSERT(0 == flags); // Make sure we handled all the flags.
143 return str;
144 }
145
dumpJSON(SkJSONWriter * writer) const146 void GrCaps::dumpJSON(SkJSONWriter* writer) const {
147 writer->beginObject();
148
149 writer->appendBool("MIP Map Support", fMipMapSupport);
150 writer->appendBool("NPOT Texture Tile Support", fNPOTTextureTileSupport);
151 writer->appendBool("sRGB Support", fSRGBSupport);
152 writer->appendBool("sRGB Write Control", fSRGBWriteControl);
153 writer->appendBool("sRGB Decode Disable", fSRGBDecodeDisableSupport);
154 writer->appendBool("Discard Render Target Support", fDiscardRenderTargetSupport);
155 writer->appendBool("Reuse Scratch Textures", fReuseScratchTextures);
156 writer->appendBool("Reuse Scratch Buffers", fReuseScratchBuffers);
157 writer->appendBool("Gpu Tracing Support", fGpuTracingSupport);
158 writer->appendBool("Oversized Stencil Support", fOversizedStencilSupport);
159 writer->appendBool("Texture Barrier Support", fTextureBarrierSupport);
160 writer->appendBool("Sample Locations Support", fSampleLocationsSupport);
161 writer->appendBool("Multisample disable support", fMultisampleDisableSupport);
162 writer->appendBool("Instance Attrib Support", fInstanceAttribSupport);
163 writer->appendBool("Uses Mixed Samples", fUsesMixedSamples);
164 writer->appendBool("Use primitive restart", fUsePrimitiveRestart);
165 writer->appendBool("Prefer client-side dynamic buffers", fPreferClientSideDynamicBuffers);
166 writer->appendBool("Prefer fullscreen clears", fPreferFullscreenClears);
167 writer->appendBool("Must clear buffer memory", fMustClearUploadedBufferData);
168 writer->appendBool("Sample shading support", fSampleShadingSupport);
169 writer->appendBool("Fence sync support", fFenceSyncSupport);
170 writer->appendBool("Cross context texture support", fCrossContextTextureSupport);
171
172 writer->appendBool("Blacklist Coverage Counting Path Renderer [workaround]",
173 fBlacklistCoverageCounting);
174 writer->appendBool("Prefer VRAM Use over flushes [workaround]", fPreferVRAMUseOverFlushes);
175
176 if (this->advancedBlendEquationSupport()) {
177 writer->appendHexU32("Advanced Blend Equation Blacklist", fAdvBlendEqBlacklist);
178 }
179
180 writer->appendS32("Max Vertex Attributes", fMaxVertexAttributes);
181 writer->appendS32("Max Texture Size", fMaxTextureSize);
182 writer->appendS32("Max Render Target Size", fMaxRenderTargetSize);
183 writer->appendS32("Max Raster Samples", fMaxRasterSamples);
184 writer->appendS32("Max Window Rectangles", fMaxWindowRectangles);
185 writer->appendS32("Max Clip Analytic Fragment Processors", fMaxClipAnalyticFPs);
186
187 static const char* kBlendEquationSupportNames[] = {
188 "Basic",
189 "Advanced",
190 "Advanced Coherent",
191 };
192 GR_STATIC_ASSERT(0 == kBasic_BlendEquationSupport);
193 GR_STATIC_ASSERT(1 == kAdvanced_BlendEquationSupport);
194 GR_STATIC_ASSERT(2 == kAdvancedCoherent_BlendEquationSupport);
195 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1);
196
197 writer->appendString("Blend Equation Support",
198 kBlendEquationSupportNames[fBlendEquationSupport]);
199 writer->appendString("Map Buffer Support", map_flags_to_string(fMapBufferFlags).c_str());
200
201 SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig, false));
202 SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig, true));
203 SkASSERT(!this->isConfigTexturable(kUnknown_GrPixelConfig));
204
205 writer->beginArray("configs");
206
207 for (size_t i = 1; i < kGrPixelConfigCnt; ++i) {
208 GrPixelConfig config = static_cast<GrPixelConfig>(i);
209 writer->beginObject(nullptr, false);
210 writer->appendString("name", pixel_config_name(config));
211 writer->appendBool("renderable", this->isConfigRenderable(config, false));
212 writer->appendBool("renderableMSAA", this->isConfigRenderable(config, true));
213 writer->appendBool("texturable", this->isConfigTexturable(config));
214 writer->endObject();
215 }
216
217 writer->endArray();
218
219 this->onDumpJSON(writer);
220
221 writer->appendName("shaderCaps");
222 this->shaderCaps()->dumpJSON(writer);
223
224 writer->endObject();
225 }
226
227