blob: 638a70f2a3981502b972dc6080d33eb52c41d2a6 [file] [log] [blame]
bsalomondc47ff72015-05-26 12:16:59 -07001/*
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"
Greg Danielf5d87582017-12-18 14:48:15 -05009#include "GrBackendSurface.h"
bsalomondc47ff72015-05-26 12:16:59 -070010#include "GrContextOptions.h"
Brian Salomonc67c31c2018-12-06 10:00:03 -050011#include "GrSurface.h"
12#include "GrSurfaceProxy.h"
Greg Daniel4065d452018-11-16 15:43:41 -050013#include "GrTypesPriv.h"
csmartdalton28341fa2016-08-17 10:00:21 -070014#include "GrWindowRectangles.h"
Brian Osman71a18892017-08-10 10:23:25 -040015#include "SkJSONWriter.h"
bsalomondc47ff72015-05-26 12:16:59 -070016
bsalomondc47ff72015-05-26 12:16:59 -070017GrCaps::GrCaps(const GrContextOptions& options) {
18 fMipMapSupport = false;
19 fNPOTTextureTileSupport = false;
brianosmana6359362016-03-21 06:55:37 -070020 fSRGBSupport = false;
brianosman35b784d2016-05-05 11:52:53 -070021 fSRGBWriteControl = false;
bsalomondc47ff72015-05-26 12:16:59 -070022 fDiscardRenderTargetSupport = false;
23 fReuseScratchTextures = true;
robertphillips1b8e1b52015-06-24 06:54:10 -070024 fReuseScratchBuffers = true;
bsalomondc47ff72015-05-26 12:16:59 -070025 fGpuTracingSupport = false;
bsalomondc47ff72015-05-26 12:16:59 -070026 fOversizedStencilSupport = false;
27 fTextureBarrierSupport = false;
Robert Phillips7f861922018-01-30 13:13:42 +000028 fSampleLocationsSupport = false;
csmartdalton2b5f2cb2016-06-10 14:06:32 -070029 fMultisampleDisableSupport = false;
Chris Dalton1d616352017-05-31 12:51:23 -060030 fInstanceAttribSupport = false;
egdanieleed519e2016-01-15 11:36:18 -080031 fUsesMixedSamples = false;
Chris Dalton27059d32018-01-23 14:06:50 -070032 fUsePrimitiveRestart = false;
csmartdalton485a1202016-07-13 10:16:32 -070033 fPreferClientSideDynamicBuffers = false;
Chris Dalton344e9032017-12-11 15:42:09 -070034 fPreferFullscreenClears = false;
bsalomon7dea7b72015-08-19 08:26:51 -070035 fMustClearUploadedBufferData = false;
Greg Danielb2acf0a2018-09-12 09:17:11 -040036 fSupportsAHardwareBufferImages = false;
jvanverth84741b32016-09-30 08:39:02 -070037 fFenceSyncSupport = false;
Brian Osman2c2bc112017-02-28 10:02:49 -050038 fCrossContextTextureSupport = false;
Brian Osman499bf1a2018-09-17 11:32:42 -040039 fHalfFloatVertexAttributeSupport = false;
Brian Salomonf7232642018-09-19 08:58:08 -040040 fDynamicStateArrayGeometryProcessorTextureSupport = false;
Michael Ludwiga21d1962019-01-11 15:26:22 -050041 fPerformPartialClearsAsDraws = false;
42 fPerformColorClearsAsDraws = false;
43 fPerformStencilClearsAsDraws = false;
bsalomondc47ff72015-05-26 12:16:59 -070044
bsalomondc47ff72015-05-26 12:16:59 -070045 fBlendEquationSupport = kBasic_BlendEquationSupport;
cdalton1dd05422015-06-12 09:01:18 -070046 fAdvBlendEqBlacklist = 0;
47
bsalomondc47ff72015-05-26 12:16:59 -070048 fMapBufferFlags = kNone_MapFlags;
49
bsalomon7dbd45d2016-03-23 10:40:53 -070050 fMaxVertexAttributes = 0;
egdanielff1d5472015-09-10 08:37:20 -070051 fMaxRenderTargetSize = 1;
Chris Dalton2612bae2018-02-22 13:41:37 -070052 fMaxPreferredRenderTargetSize = 1;
egdanielff1d5472015-09-10 08:37:20 -070053 fMaxTextureSize = 1;
cdaltonaf8bc7d2016-02-05 09:35:20 -080054 fMaxRasterSamples = 0;
csmartdalton9bc11872016-08-09 12:42:47 -070055 fMaxWindowRectangles = 0;
bsalomondc47ff72015-05-26 12:16:59 -070056
Chris Dalton584a79a2017-11-15 13:14:01 -070057 // An default count of 4 was chosen because of the common pattern in Blink of:
58 // isect RR
59 // diff RR
60 // isect convex_poly
61 // isect convex_poly
62 // when drawing rounded div borders.
63 fMaxClipAnalyticFPs = 4;
64
robertphillipscaef3452015-11-11 13:18:11 -080065 fSuppressPrints = options.fSuppressPrints;
Brian Osman195c05b2017-08-30 15:14:04 -040066#if GR_TEST_UTILS
Jim Van Verthfbdc0802017-05-02 16:15:53 -040067 fWireframeMode = options.fWireframeMode;
Brian Osman195c05b2017-08-30 15:14:04 -040068#else
69 fWireframeMode = false;
70#endif
cdalton397536c2016-03-25 12:15:03 -070071 fBufferMapThreshold = options.fBufferMapThreshold;
Chris Daltone4679fa2017-09-29 13:58:26 -060072 fBlacklistCoverageCounting = false;
Eric Karl5c779752017-05-08 12:02:07 -070073 fAvoidStencilBuffers = false;
Greg Daniel4374e962018-09-28 15:09:47 -040074 fAvoidWritePixelsFastPath = false;
robertphillips63926682015-08-20 09:39:02 -070075
76 fPreferVRAMUseOverFlushes = true;
Adrienne Walkerab7181d2018-05-14 14:02:03 -070077
Michael Ludwigf23a1522018-12-10 11:36:13 -050078 // Default to true, allow older versions of OpenGL to disable explicitly
79 fClampToBorderSupport = true;
80
Adrienne Walkerab7181d2018-05-14 14:02:03 -070081 fDriverBugWorkarounds = options.fDriverBugWorkarounds;
bsalomondc47ff72015-05-26 12:16:59 -070082}
83
bsalomon4ee6bd82015-05-27 13:23:23 -070084void GrCaps::applyOptionsOverrides(const GrContextOptions& options) {
csmartdalton28341fa2016-08-17 10:00:21 -070085 this->onApplyOptionsOverrides(options);
Brian Salomon01b476a2018-01-23 11:06:41 -050086 if (options.fDisableDriverCorrectnessWorkarounds) {
Brian Salomone7393ab2018-02-13 09:05:54 -050087 // We always blacklist coverage counting on Vulkan currently. TODO: Either stop doing that
88 // or disambiguate blacklisting from incomplete implementation.
89 // SkASSERT(!fBlacklistCoverageCounting);
Brian Salomon01b476a2018-01-23 11:06:41 -050090 SkASSERT(!fAvoidStencilBuffers);
91 SkASSERT(!fAdvBlendEqBlacklist);
Michael Ludwiga21d1962019-01-11 15:26:22 -050092 SkASSERT(!fPerformColorClearsAsDraws);
93 SkASSERT(!fPerformStencilClearsAsDraws);
94 // Don't check the partial-clear workaround, since that is a backend limitation, not a
95 // driver workaround (it just so happens the fallbacks are the same).
96 }
97 if (GrContextOptions::Enable::kNo == options.fUseDrawInsteadOfClear) {
98 fPerformColorClearsAsDraws = false;
99 fPerformStencilClearsAsDraws = false;
100 } else if (GrContextOptions::Enable::kYes == options.fUseDrawInsteadOfClear) {
101 fPerformColorClearsAsDraws = true;
102 fPerformStencilClearsAsDraws = true;
Brian Salomon01b476a2018-01-23 11:06:41 -0500103 }
104
bsalomon4ee6bd82015-05-27 13:23:23 -0700105 fMaxTextureSize = SkTMin(fMaxTextureSize, options.fMaxTextureSizeOverride);
Brian Osman195c05b2017-08-30 15:14:04 -0400106 fMaxTileSize = fMaxTextureSize;
107#if GR_TEST_UTILS
bsalomon8c07b7a2015-11-02 11:36:52 -0800108 // If the max tile override is zero, it means we should use the max texture size.
Brian Osman195c05b2017-08-30 15:14:04 -0400109 if (options.fMaxTileSizeOverride && options.fMaxTileSizeOverride < fMaxTextureSize) {
bsalomon8c07b7a2015-11-02 11:36:52 -0800110 fMaxTileSize = options.fMaxTileSizeOverride;
111 }
Chris Dalton040238b2017-12-18 14:22:34 -0700112 if (options.fSuppressGeometryShaders) {
113 fShaderCaps->fGeometryShaderSupport = false;
114 }
Brian Osman195c05b2017-08-30 15:14:04 -0400115#endif
csmartdalton28341fa2016-08-17 10:00:21 -0700116 if (fMaxWindowRectangles > GrWindowRectangles::kMaxWindows) {
csmartdalton7535f412016-08-23 06:51:00 -0700117 SkDebugf("WARNING: capping window rectangles at %i. HW advertises support for %i.\n",
118 GrWindowRectangles::kMaxWindows, fMaxWindowRectangles);
csmartdalton28341fa2016-08-17 10:00:21 -0700119 fMaxWindowRectangles = GrWindowRectangles::kMaxWindows;
120 }
Eric Karl5c779752017-05-08 12:02:07 -0700121 fAvoidStencilBuffers = options.fAvoidStencilBuffers;
Adrienne Walkerab7181d2018-05-14 14:02:03 -0700122
123 fDriverBugWorkarounds.applyOverrides(options.fDriverBugWorkarounds);
bsalomon4ee6bd82015-05-27 13:23:23 -0700124}
125
Kevin Lubickf4def342018-10-04 12:52:50 -0400126
127#ifdef SK_ENABLE_DUMP_GPU
128static const char* pixel_config_name(GrPixelConfig config) {
129 switch (config) {
130 case kUnknown_GrPixelConfig: return "Unknown";
131 case kAlpha_8_GrPixelConfig: return "Alpha8";
132 case kAlpha_8_as_Alpha_GrPixelConfig: return "Alpha8_asAlpha";
133 case kAlpha_8_as_Red_GrPixelConfig: return "Alpha8_asRed";
134 case kGray_8_GrPixelConfig: return "Gray8";
135 case kGray_8_as_Lum_GrPixelConfig: return "Gray8_asLum";
136 case kGray_8_as_Red_GrPixelConfig: return "Gray8_asRed";
137 case kRGB_565_GrPixelConfig: return "RGB565";
138 case kRGBA_4444_GrPixelConfig: return "RGBA444";
139 case kRGBA_8888_GrPixelConfig: return "RGBA8888";
140 case kRGB_888_GrPixelConfig: return "RGB888";
Jim Van Verth69e57852018-12-05 13:38:59 -0500141 case kRG_88_GrPixelConfig: return "RG88";
Kevin Lubickf4def342018-10-04 12:52:50 -0400142 case kBGRA_8888_GrPixelConfig: return "BGRA8888";
143 case kSRGBA_8888_GrPixelConfig: return "SRGBA8888";
144 case kSBGRA_8888_GrPixelConfig: return "SBGRA8888";
145 case kRGBA_1010102_GrPixelConfig: return "RGBA1010102";
146 case kRGBA_float_GrPixelConfig: return "RGBAFloat";
147 case kRG_float_GrPixelConfig: return "RGFloat";
148 case kAlpha_half_GrPixelConfig: return "AlphaHalf";
149 case kAlpha_half_as_Red_GrPixelConfig: return "AlphaHalf_asRed";
150 case kRGBA_half_GrPixelConfig: return "RGBAHalf";
Jim Van Verth1676cb92019-01-15 13:24:45 -0500151 case kRGB_ETC1_GrPixelConfig: return "RGBETC1";
Kevin Lubickf4def342018-10-04 12:52:50 -0400152 }
153 SK_ABORT("Invalid pixel config");
154 return "<invalid>";
155}
156
bsalomondc47ff72015-05-26 12:16:59 -0700157static SkString map_flags_to_string(uint32_t flags) {
158 SkString str;
159 if (GrCaps::kNone_MapFlags == flags) {
160 str = "none";
161 } else {
162 SkASSERT(GrCaps::kCanMap_MapFlag & flags);
163 SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag);
164 str = "can_map";
165
166 if (GrCaps::kSubset_MapFlag & flags) {
167 str.append(" partial");
168 } else {
169 str.append(" full");
170 }
171 SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag);
172 }
173 SkASSERT(0 == flags); // Make sure we handled all the flags.
174 return str;
175}
176
Brian Osman71a18892017-08-10 10:23:25 -0400177void GrCaps::dumpJSON(SkJSONWriter* writer) const {
178 writer->beginObject();
jvanverth84741b32016-09-30 08:39:02 -0700179
Brian Osman71a18892017-08-10 10:23:25 -0400180 writer->appendBool("MIP Map Support", fMipMapSupport);
181 writer->appendBool("NPOT Texture Tile Support", fNPOTTextureTileSupport);
182 writer->appendBool("sRGB Support", fSRGBSupport);
183 writer->appendBool("sRGB Write Control", fSRGBWriteControl);
Brian Osman71a18892017-08-10 10:23:25 -0400184 writer->appendBool("Discard Render Target Support", fDiscardRenderTargetSupport);
185 writer->appendBool("Reuse Scratch Textures", fReuseScratchTextures);
186 writer->appendBool("Reuse Scratch Buffers", fReuseScratchBuffers);
187 writer->appendBool("Gpu Tracing Support", fGpuTracingSupport);
188 writer->appendBool("Oversized Stencil Support", fOversizedStencilSupport);
189 writer->appendBool("Texture Barrier Support", fTextureBarrierSupport);
Robert Phillips7f861922018-01-30 13:13:42 +0000190 writer->appendBool("Sample Locations Support", fSampleLocationsSupport);
Brian Osman71a18892017-08-10 10:23:25 -0400191 writer->appendBool("Multisample disable support", fMultisampleDisableSupport);
192 writer->appendBool("Instance Attrib Support", fInstanceAttribSupport);
193 writer->appendBool("Uses Mixed Samples", fUsesMixedSamples);
Chris Dalton27059d32018-01-23 14:06:50 -0700194 writer->appendBool("Use primitive restart", fUsePrimitiveRestart);
Brian Osman71a18892017-08-10 10:23:25 -0400195 writer->appendBool("Prefer client-side dynamic buffers", fPreferClientSideDynamicBuffers);
Chris Dalton344e9032017-12-11 15:42:09 -0700196 writer->appendBool("Prefer fullscreen clears", fPreferFullscreenClears);
Brian Osman71a18892017-08-10 10:23:25 -0400197 writer->appendBool("Must clear buffer memory", fMustClearUploadedBufferData);
Greg Danielb2acf0a2018-09-12 09:17:11 -0400198 writer->appendBool("Supports importing AHardwareBuffers", fSupportsAHardwareBufferImages);
Brian Osman71a18892017-08-10 10:23:25 -0400199 writer->appendBool("Fence sync support", fFenceSyncSupport);
200 writer->appendBool("Cross context texture support", fCrossContextTextureSupport);
Brian Osman499bf1a2018-09-17 11:32:42 -0400201 writer->appendBool("Half float vertex attribute support", fHalfFloatVertexAttributeSupport);
Brian Salomonf7232642018-09-19 08:58:08 -0400202 writer->appendBool("Specify GeometryProcessor textures as a dynamic state array",
203 fDynamicStateArrayGeometryProcessorTextureSupport);
Michael Ludwiga21d1962019-01-11 15:26:22 -0500204 writer->appendBool("Use draws for partial clears", fPerformPartialClearsAsDraws);
205 writer->appendBool("Use draws for color clears", fPerformColorClearsAsDraws);
206 writer->appendBool("Use draws for stencil clip clears", fPerformStencilClearsAsDraws);
207 writer->appendBool("Clamp-to-border", fClampToBorderSupport);
Brian Osman71a18892017-08-10 10:23:25 -0400208
Chris Daltoncc604e52017-10-06 16:27:32 -0600209 writer->appendBool("Blacklist Coverage Counting Path Renderer [workaround]",
210 fBlacklistCoverageCounting);
Brian Osman71a18892017-08-10 10:23:25 -0400211 writer->appendBool("Prefer VRAM Use over flushes [workaround]", fPreferVRAMUseOverFlushes);
Robert Phillipsf2ec0242018-03-01 16:51:25 -0500212 writer->appendBool("Avoid stencil buffers [workaround]", fAvoidStencilBuffers);
robertphillips63926682015-08-20 09:39:02 -0700213
cdalton1dd05422015-06-12 09:01:18 -0700214 if (this->advancedBlendEquationSupport()) {
Brian Osman71a18892017-08-10 10:23:25 -0400215 writer->appendHexU32("Advanced Blend Equation Blacklist", fAdvBlendEqBlacklist);
cdalton1dd05422015-06-12 09:01:18 -0700216 }
bsalomondc47ff72015-05-26 12:16:59 -0700217
Brian Osman71a18892017-08-10 10:23:25 -0400218 writer->appendS32("Max Vertex Attributes", fMaxVertexAttributes);
219 writer->appendS32("Max Texture Size", fMaxTextureSize);
220 writer->appendS32("Max Render Target Size", fMaxRenderTargetSize);
Chris Dalton2612bae2018-02-22 13:41:37 -0700221 writer->appendS32("Max Preferred Render Target Size", fMaxPreferredRenderTargetSize);
Brian Osman71a18892017-08-10 10:23:25 -0400222 writer->appendS32("Max Raster Samples", fMaxRasterSamples);
223 writer->appendS32("Max Window Rectangles", fMaxWindowRectangles);
Chris Dalton584a79a2017-11-15 13:14:01 -0700224 writer->appendS32("Max Clip Analytic Fragment Processors", fMaxClipAnalyticFPs);
bsalomondc47ff72015-05-26 12:16:59 -0700225
226 static const char* kBlendEquationSupportNames[] = {
227 "Basic",
228 "Advanced",
229 "Advanced Coherent",
230 };
231 GR_STATIC_ASSERT(0 == kBasic_BlendEquationSupport);
232 GR_STATIC_ASSERT(1 == kAdvanced_BlendEquationSupport);
233 GR_STATIC_ASSERT(2 == kAdvancedCoherent_BlendEquationSupport);
234 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1);
235
Brian Osman71a18892017-08-10 10:23:25 -0400236 writer->appendString("Blend Equation Support",
237 kBlendEquationSupportNames[fBlendEquationSupport]);
238 writer->appendString("Map Buffer Support", map_flags_to_string(fMapBufferFlags).c_str());
bsalomondc47ff72015-05-26 12:16:59 -0700239
Brian Salomonbdecacf2018-02-02 20:32:49 -0500240 SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig));
Brian Osman0f450ac2017-08-09 20:45:52 +0000241 SkASSERT(!this->isConfigTexturable(kUnknown_GrPixelConfig));
Brian Osman175af0d2017-08-09 14:29:36 -0400242
Brian Osman71a18892017-08-10 10:23:25 -0400243 writer->beginArray("configs");
244
245 for (size_t i = 1; i < kGrPixelConfigCnt; ++i) {
Brian Osman0f450ac2017-08-09 20:45:52 +0000246 GrPixelConfig config = static_cast<GrPixelConfig>(i);
Brian Osman80488222017-08-10 13:29:30 -0400247 writer->beginObject(nullptr, false);
Brian Osman71a18892017-08-10 10:23:25 -0400248 writer->appendString("name", pixel_config_name(config));
Brian Salomonbdecacf2018-02-02 20:32:49 -0500249 writer->appendS32("max sample count", this->maxRenderTargetSampleCount(config));
Brian Osman71a18892017-08-10 10:23:25 -0400250 writer->appendBool("texturable", this->isConfigTexturable(config));
251 writer->endObject();
Brian Osman0f450ac2017-08-09 20:45:52 +0000252 }
Brian Osman175af0d2017-08-09 14:29:36 -0400253
Brian Osman71a18892017-08-10 10:23:25 -0400254 writer->endArray();
255
256 this->onDumpJSON(writer);
257
258 writer->appendName("shaderCaps");
259 this->shaderCaps()->dumpJSON(writer);
260
261 writer->endObject();
bsalomondc47ff72015-05-26 12:16:59 -0700262}
Kevin Lubickf4def342018-10-04 12:52:50 -0400263#else
264void GrCaps::dumpJSON(SkJSONWriter* writer) const { }
265#endif
Greg Danielf5d87582017-12-18 14:48:15 -0500266
Brian Salomonc67c31c2018-12-06 10:00:03 -0500267bool GrCaps::surfaceSupportsWritePixels(const GrSurface* surface) const {
268 return surface->readOnly() ? false : this->onSurfaceSupportsWritePixels(surface);
269}
270
271bool GrCaps::canCopySurface(const GrSurfaceProxy* dst, const GrSurfaceProxy* src,
272 const SkIRect& srcRect, const SkIPoint& dstPoint) const {
273 return dst->readOnly() ? false : this->onCanCopySurface(dst, src, srcRect, dstPoint);
274}
275
Brian Salomonbdecacf2018-02-02 20:32:49 -0500276bool GrCaps::validateSurfaceDesc(const GrSurfaceDesc& desc, GrMipMapped mipped) const {
277 if (!this->isConfigTexturable(desc.fConfig)) {
278 return false;
279 }
280
Brian Salomon57111332018-02-05 15:55:54 -0500281 if (GrMipMapped::kYes == mipped && !this->mipMapSupport()) {
282 return false;
Brian Salomonbdecacf2018-02-02 20:32:49 -0500283 }
284
285 if (desc.fWidth < 1 || desc.fHeight < 1) {
286 return false;
287 }
288
289 if (SkToBool(desc.fFlags & kRenderTarget_GrSurfaceFlag)) {
290 if (0 == this->getRenderTargetSampleCount(desc.fSampleCnt, desc.fConfig)) {
291 return false;
292 }
293 int maxRTSize = this->maxRenderTargetSize();
294 if (desc.fWidth > maxRTSize || desc.fHeight > maxRTSize) {
295 return false;
296 }
297 } else {
298 // We currently do not support multisampled textures
299 if (desc.fSampleCnt > 1) {
300 return false;
301 }
302 int maxSize = this->maxTextureSize();
303 if (desc.fWidth > maxSize || desc.fHeight > maxSize) {
304 return false;
305 }
306 }
307
308 return true;
309}
Timothy Liang036fdfe2018-06-28 15:50:36 -0400310
Greg Daniel4065d452018-11-16 15:43:41 -0500311GrBackendFormat GrCaps::getBackendFormatFromColorType(SkColorType ct) const {
312 return this->getBackendFormatFromGrColorType(SkColorTypeToGrColorType(ct), GrSRGBEncoded::kNo);
313}