bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 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" |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 9 | |
| 10 | #include "GrBackendSurface.h" |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 11 | #include "GrContextOptions.h" |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 12 | #include "GrWindowRectangles.h" |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 13 | #include "SkJSONWriter.h" |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 14 | |
csmartdalton | 6aa0e11 | 2017-02-08 16:14:11 -0500 | [diff] [blame] | 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"; |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 19 | case kAlpha_8_as_Alpha_GrPixelConfig: return "Alpha8_asAlpha"; |
| 20 | case kAlpha_8_as_Red_GrPixelConfig: return "Alpha8_asRed"; |
csmartdalton | 6aa0e11 | 2017-02-08 16:14:11 -0500 | [diff] [blame] | 21 | case kGray_8_GrPixelConfig: return "Gray8"; |
Greg Daniel | 7af060a | 2017-12-05 16:27:11 -0500 | [diff] [blame] | 22 | case kGray_8_as_Lum_GrPixelConfig: return "Gray8_asLum"; |
| 23 | case kGray_8_as_Red_GrPixelConfig: return "Gray8_asRed"; |
csmartdalton | 6aa0e11 | 2017-02-08 16:14:11 -0500 | [diff] [blame] | 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"; |
csmartdalton | 6aa0e11 | 2017-02-08 16:14:11 -0500 | [diff] [blame] | 31 | case kRGBA_float_GrPixelConfig: return "RGBAFloat"; |
| 32 | case kRG_float_GrPixelConfig: return "RGFloat"; |
| 33 | case kAlpha_half_GrPixelConfig: return "AlphaHalf"; |
Greg Daniel | ef59d87 | 2017-11-17 16:47:21 -0500 | [diff] [blame] | 34 | case kAlpha_half_as_Red_GrPixelConfig: return "AlphaHalf_asRed"; |
csmartdalton | 6aa0e11 | 2017-02-08 16:14:11 -0500 | [diff] [blame] | 35 | case kRGBA_half_GrPixelConfig: return "RGBAHalf"; |
| 36 | } |
Ben Wagner | b4aab9a | 2017-08-16 10:53:04 -0400 | [diff] [blame] | 37 | SK_ABORT("Invalid pixel config"); |
csmartdalton | 6aa0e11 | 2017-02-08 16:14:11 -0500 | [diff] [blame] | 38 | return "<invalid>"; |
| 39 | } |
| 40 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 41 | GrCaps::GrCaps(const GrContextOptions& options) { |
| 42 | fMipMapSupport = false; |
| 43 | fNPOTTextureTileSupport = false; |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 44 | fSRGBSupport = false; |
brianosman | 35b784d | 2016-05-05 11:52:53 -0700 | [diff] [blame] | 45 | fSRGBWriteControl = false; |
Brian Osman | 57bc3ea | 2017-07-27 09:58:11 -0400 | [diff] [blame] | 46 | fSRGBDecodeDisableSupport = false; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 47 | fDiscardRenderTargetSupport = false; |
| 48 | fReuseScratchTextures = true; |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 49 | fReuseScratchBuffers = true; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 50 | fGpuTracingSupport = false; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 51 | fOversizedStencilSupport = false; |
| 52 | fTextureBarrierSupport = false; |
Robert Phillips | 7f86192 | 2018-01-30 13:13:42 +0000 | [diff] [blame] | 53 | fSampleLocationsSupport = false; |
csmartdalton | 2b5f2cb | 2016-06-10 14:06:32 -0700 | [diff] [blame] | 54 | fMultisampleDisableSupport = false; |
Chris Dalton | 1d61635 | 2017-05-31 12:51:23 -0600 | [diff] [blame] | 55 | fInstanceAttribSupport = false; |
egdaniel | eed519e | 2016-01-15 11:36:18 -0800 | [diff] [blame] | 56 | fUsesMixedSamples = false; |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame] | 57 | fUsePrimitiveRestart = false; |
csmartdalton | 485a120 | 2016-07-13 10:16:32 -0700 | [diff] [blame] | 58 | fPreferClientSideDynamicBuffers = false; |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 59 | fPreferFullscreenClears = false; |
bsalomon | 7dea7b7 | 2015-08-19 08:26:51 -0700 | [diff] [blame] | 60 | fMustClearUploadedBufferData = false; |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 61 | fSampleShadingSupport = false; |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 62 | fFenceSyncSupport = false; |
Brian Osman | 2c2bc11 | 2017-02-28 10:02:49 -0500 | [diff] [blame] | 63 | fCrossContextTextureSupport = false; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 64 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 65 | fBlendEquationSupport = kBasic_BlendEquationSupport; |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 66 | fAdvBlendEqBlacklist = 0; |
| 67 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 68 | fMapBufferFlags = kNone_MapFlags; |
| 69 | |
bsalomon | 7dbd45d | 2016-03-23 10:40:53 -0700 | [diff] [blame] | 70 | fMaxVertexAttributes = 0; |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 71 | fMaxRenderTargetSize = 1; |
| 72 | fMaxTextureSize = 1; |
cdalton | af8bc7d | 2016-02-05 09:35:20 -0800 | [diff] [blame] | 73 | fMaxRasterSamples = 0; |
csmartdalton | 9bc1187 | 2016-08-09 12:42:47 -0700 | [diff] [blame] | 74 | fMaxWindowRectangles = 0; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 75 | |
Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 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 | |
robertphillips | caef345 | 2015-11-11 13:18:11 -0800 | [diff] [blame] | 84 | fSuppressPrints = options.fSuppressPrints; |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 85 | #if GR_TEST_UTILS |
Jim Van Verth | fbdc080 | 2017-05-02 16:15:53 -0400 | [diff] [blame] | 86 | fWireframeMode = options.fWireframeMode; |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 87 | #else |
| 88 | fWireframeMode = false; |
| 89 | #endif |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 90 | fBufferMapThreshold = options.fBufferMapThreshold; |
Chris Dalton | e4679fa | 2017-09-29 13:58:26 -0600 | [diff] [blame] | 91 | fBlacklistCoverageCounting = false; |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 92 | fAvoidStencilBuffers = false; |
robertphillips | 6392668 | 2015-08-20 09:39:02 -0700 | [diff] [blame] | 93 | |
| 94 | fPreferVRAMUseOverFlushes = true; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 95 | } |
| 96 | |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 97 | void GrCaps::applyOptionsOverrides(const GrContextOptions& options) { |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 98 | this->onApplyOptionsOverrides(options); |
Brian Salomon | 01b476a | 2018-01-23 11:06:41 -0500 | [diff] [blame] | 99 | if (options.fDisableDriverCorrectnessWorkarounds) { |
| 100 | SkASSERT(!fBlacklistCoverageCounting); |
| 101 | SkASSERT(!fAvoidStencilBuffers); |
| 102 | SkASSERT(!fAdvBlendEqBlacklist); |
| 103 | } |
| 104 | |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 105 | fMaxTextureSize = SkTMin(fMaxTextureSize, options.fMaxTextureSizeOverride); |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 106 | fMaxTileSize = fMaxTextureSize; |
| 107 | #if GR_TEST_UTILS |
bsalomon | 8c07b7a | 2015-11-02 11:36:52 -0800 | [diff] [blame] | 108 | // If the max tile override is zero, it means we should use the max texture size. |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 109 | if (options.fMaxTileSizeOverride && options.fMaxTileSizeOverride < fMaxTextureSize) { |
bsalomon | 8c07b7a | 2015-11-02 11:36:52 -0800 | [diff] [blame] | 110 | fMaxTileSize = options.fMaxTileSizeOverride; |
| 111 | } |
Chris Dalton | 040238b | 2017-12-18 14:22:34 -0700 | [diff] [blame] | 112 | if (options.fSuppressGeometryShaders) { |
| 113 | fShaderCaps->fGeometryShaderSupport = false; |
| 114 | } |
Brian Osman | 195c05b | 2017-08-30 15:14:04 -0400 | [diff] [blame] | 115 | #endif |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 116 | if (fMaxWindowRectangles > GrWindowRectangles::kMaxWindows) { |
csmartdalton | 7535f41 | 2016-08-23 06:51:00 -0700 | [diff] [blame] | 117 | SkDebugf("WARNING: capping window rectangles at %i. HW advertises support for %i.\n", |
| 118 | GrWindowRectangles::kMaxWindows, fMaxWindowRectangles); |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 119 | fMaxWindowRectangles = GrWindowRectangles::kMaxWindows; |
| 120 | } |
Eric Karl | 5c77975 | 2017-05-08 12:02:07 -0700 | [diff] [blame] | 121 | fAvoidStencilBuffers = options.fAvoidStencilBuffers; |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 122 | } |
| 123 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 124 | static SkString map_flags_to_string(uint32_t flags) { |
| 125 | SkString str; |
| 126 | if (GrCaps::kNone_MapFlags == flags) { |
| 127 | str = "none"; |
| 128 | } else { |
| 129 | SkASSERT(GrCaps::kCanMap_MapFlag & flags); |
| 130 | SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag); |
| 131 | str = "can_map"; |
| 132 | |
| 133 | if (GrCaps::kSubset_MapFlag & flags) { |
| 134 | str.append(" partial"); |
| 135 | } else { |
| 136 | str.append(" full"); |
| 137 | } |
| 138 | SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag); |
| 139 | } |
| 140 | SkASSERT(0 == flags); // Make sure we handled all the flags. |
| 141 | return str; |
| 142 | } |
| 143 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 144 | void GrCaps::dumpJSON(SkJSONWriter* writer) const { |
| 145 | writer->beginObject(); |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 146 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 147 | writer->appendBool("MIP Map Support", fMipMapSupport); |
| 148 | writer->appendBool("NPOT Texture Tile Support", fNPOTTextureTileSupport); |
| 149 | writer->appendBool("sRGB Support", fSRGBSupport); |
| 150 | writer->appendBool("sRGB Write Control", fSRGBWriteControl); |
| 151 | writer->appendBool("sRGB Decode Disable", fSRGBDecodeDisableSupport); |
| 152 | writer->appendBool("Discard Render Target Support", fDiscardRenderTargetSupport); |
| 153 | writer->appendBool("Reuse Scratch Textures", fReuseScratchTextures); |
| 154 | writer->appendBool("Reuse Scratch Buffers", fReuseScratchBuffers); |
| 155 | writer->appendBool("Gpu Tracing Support", fGpuTracingSupport); |
| 156 | writer->appendBool("Oversized Stencil Support", fOversizedStencilSupport); |
| 157 | writer->appendBool("Texture Barrier Support", fTextureBarrierSupport); |
Robert Phillips | 7f86192 | 2018-01-30 13:13:42 +0000 | [diff] [blame] | 158 | writer->appendBool("Sample Locations Support", fSampleLocationsSupport); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 159 | writer->appendBool("Multisample disable support", fMultisampleDisableSupport); |
| 160 | writer->appendBool("Instance Attrib Support", fInstanceAttribSupport); |
| 161 | writer->appendBool("Uses Mixed Samples", fUsesMixedSamples); |
Chris Dalton | 27059d3 | 2018-01-23 14:06:50 -0700 | [diff] [blame] | 162 | writer->appendBool("Use primitive restart", fUsePrimitiveRestart); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 163 | writer->appendBool("Prefer client-side dynamic buffers", fPreferClientSideDynamicBuffers); |
Chris Dalton | 344e903 | 2017-12-11 15:42:09 -0700 | [diff] [blame] | 164 | writer->appendBool("Prefer fullscreen clears", fPreferFullscreenClears); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 165 | writer->appendBool("Must clear buffer memory", fMustClearUploadedBufferData); |
| 166 | writer->appendBool("Sample shading support", fSampleShadingSupport); |
| 167 | writer->appendBool("Fence sync support", fFenceSyncSupport); |
| 168 | writer->appendBool("Cross context texture support", fCrossContextTextureSupport); |
| 169 | |
Chris Dalton | cc604e5 | 2017-10-06 16:27:32 -0600 | [diff] [blame] | 170 | writer->appendBool("Blacklist Coverage Counting Path Renderer [workaround]", |
| 171 | fBlacklistCoverageCounting); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 172 | writer->appendBool("Prefer VRAM Use over flushes [workaround]", fPreferVRAMUseOverFlushes); |
robertphillips | 6392668 | 2015-08-20 09:39:02 -0700 | [diff] [blame] | 173 | |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 174 | if (this->advancedBlendEquationSupport()) { |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 175 | writer->appendHexU32("Advanced Blend Equation Blacklist", fAdvBlendEqBlacklist); |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 176 | } |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 177 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 178 | writer->appendS32("Max Vertex Attributes", fMaxVertexAttributes); |
| 179 | writer->appendS32("Max Texture Size", fMaxTextureSize); |
| 180 | writer->appendS32("Max Render Target Size", fMaxRenderTargetSize); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 181 | writer->appendS32("Max Raster Samples", fMaxRasterSamples); |
| 182 | writer->appendS32("Max Window Rectangles", fMaxWindowRectangles); |
Chris Dalton | 584a79a | 2017-11-15 13:14:01 -0700 | [diff] [blame] | 183 | writer->appendS32("Max Clip Analytic Fragment Processors", fMaxClipAnalyticFPs); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 184 | |
| 185 | static const char* kBlendEquationSupportNames[] = { |
| 186 | "Basic", |
| 187 | "Advanced", |
| 188 | "Advanced Coherent", |
| 189 | }; |
| 190 | GR_STATIC_ASSERT(0 == kBasic_BlendEquationSupport); |
| 191 | GR_STATIC_ASSERT(1 == kAdvanced_BlendEquationSupport); |
| 192 | GR_STATIC_ASSERT(2 == kAdvancedCoherent_BlendEquationSupport); |
| 193 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1); |
| 194 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 195 | writer->appendString("Blend Equation Support", |
| 196 | kBlendEquationSupportNames[fBlendEquationSupport]); |
| 197 | writer->appendString("Map Buffer Support", map_flags_to_string(fMapBufferFlags).c_str()); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 198 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 199 | SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig, false)); |
| 200 | SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig, true)); |
Brian Osman | 0f450ac | 2017-08-09 20:45:52 +0000 | [diff] [blame] | 201 | SkASSERT(!this->isConfigTexturable(kUnknown_GrPixelConfig)); |
Brian Osman | 175af0d | 2017-08-09 14:29:36 -0400 | [diff] [blame] | 202 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 203 | writer->beginArray("configs"); |
| 204 | |
| 205 | for (size_t i = 1; i < kGrPixelConfigCnt; ++i) { |
Brian Osman | 0f450ac | 2017-08-09 20:45:52 +0000 | [diff] [blame] | 206 | GrPixelConfig config = static_cast<GrPixelConfig>(i); |
Brian Osman | 8048822 | 2017-08-10 13:29:30 -0400 | [diff] [blame] | 207 | writer->beginObject(nullptr, false); |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 208 | writer->appendString("name", pixel_config_name(config)); |
| 209 | writer->appendBool("renderable", this->isConfigRenderable(config, false)); |
| 210 | writer->appendBool("renderableMSAA", this->isConfigRenderable(config, true)); |
| 211 | writer->appendBool("texturable", this->isConfigTexturable(config)); |
| 212 | writer->endObject(); |
Brian Osman | 0f450ac | 2017-08-09 20:45:52 +0000 | [diff] [blame] | 213 | } |
Brian Osman | 175af0d | 2017-08-09 14:29:36 -0400 | [diff] [blame] | 214 | |
Brian Osman | 71a1889 | 2017-08-10 10:23:25 -0400 | [diff] [blame] | 215 | writer->endArray(); |
| 216 | |
| 217 | this->onDumpJSON(writer); |
| 218 | |
| 219 | writer->appendName("shaderCaps"); |
| 220 | this->shaderCaps()->dumpJSON(writer); |
| 221 | |
| 222 | writer->endObject(); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 223 | } |
Greg Daniel | f5d8758 | 2017-12-18 14:48:15 -0500 | [diff] [blame] | 224 | |