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