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" |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 11 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 12 | GrCaps::GrCaps(const GrContextOptions& options) { |
| 13 | fMipMapSupport = false; |
| 14 | fNPOTTextureTileSupport = false; |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 15 | fSRGBSupport = false; |
brianosman | 35b784d | 2016-05-05 11:52:53 -0700 | [diff] [blame] | 16 | fSRGBWriteControl = false; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 17 | fTwoSidedStencilSupport = false; |
| 18 | fStencilWrapOpsSupport = false; |
| 19 | fDiscardRenderTargetSupport = false; |
| 20 | fReuseScratchTextures = true; |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 21 | fReuseScratchBuffers = true; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 22 | fGpuTracingSupport = false; |
| 23 | fCompressedTexSubImageSupport = false; |
| 24 | fOversizedStencilSupport = false; |
| 25 | fTextureBarrierSupport = false; |
cdalton | eb79eea | 2016-02-26 10:39:34 -0800 | [diff] [blame] | 26 | fSampleLocationsSupport = false; |
csmartdalton | 2b5f2cb | 2016-06-10 14:06:32 -0700 | [diff] [blame] | 27 | fMultisampleDisableSupport = false; |
egdaniel | eed519e | 2016-01-15 11:36:18 -0800 | [diff] [blame] | 28 | fUsesMixedSamples = false; |
csmartdalton | 485a120 | 2016-07-13 10:16:32 -0700 | [diff] [blame] | 29 | fPreferClientSideDynamicBuffers = false; |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 30 | fFullClearIsFree = false; |
bsalomon | 7dea7b7 | 2015-08-19 08:26:51 -0700 | [diff] [blame] | 31 | fMustClearUploadedBufferData = false; |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 32 | fSampleShadingSupport = false; |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 33 | fFenceSyncSupport = false; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 34 | |
| 35 | fUseDrawInsteadOfClear = false; |
| 36 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 37 | fInstancedSupport = InstancedSupport::kNone; |
| 38 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 39 | fBlendEquationSupport = kBasic_BlendEquationSupport; |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 40 | fAdvBlendEqBlacklist = 0; |
| 41 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 42 | fMapBufferFlags = kNone_MapFlags; |
| 43 | |
bsalomon | 7dbd45d | 2016-03-23 10:40:53 -0700 | [diff] [blame] | 44 | fMaxVertexAttributes = 0; |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 45 | fMaxRenderTargetSize = 1; |
| 46 | fMaxTextureSize = 1; |
egdaniel | eed519e | 2016-01-15 11:36:18 -0800 | [diff] [blame] | 47 | fMaxColorSampleCount = 0; |
| 48 | fMaxStencilSampleCount = 0; |
cdalton | af8bc7d | 2016-02-05 09:35:20 -0800 | [diff] [blame] | 49 | fMaxRasterSamples = 0; |
csmartdalton | 9bc1187 | 2016-08-09 12:42:47 -0700 | [diff] [blame] | 50 | fMaxWindowRectangles = 0; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 51 | |
robertphillips | caef345 | 2015-11-11 13:18:11 -0800 | [diff] [blame] | 52 | fSuppressPrints = options.fSuppressPrints; |
| 53 | fImmediateFlush = options.fImmediateMode; |
cdalton | 397536c | 2016-03-25 12:15:03 -0700 | [diff] [blame] | 54 | fBufferMapThreshold = options.fBufferMapThreshold; |
joshualitt | 83bc229 | 2015-06-18 14:18:02 -0700 | [diff] [blame] | 55 | fUseDrawInsteadOfPartialRenderTargetWrite = options.fUseDrawInsteadOfPartialRenderTargetWrite; |
bsalomon | babafcc | 2016-02-16 11:36:47 -0800 | [diff] [blame] | 56 | fUseDrawInsteadOfAllRenderTargetWrites = false; |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 57 | fAvoidInstancedDrawsToFPTargets = false; |
robertphillips | 6392668 | 2015-08-20 09:39:02 -0700 | [diff] [blame] | 58 | |
| 59 | fPreferVRAMUseOverFlushes = true; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 60 | } |
| 61 | |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 62 | void GrCaps::applyOptionsOverrides(const GrContextOptions& options) { |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 63 | this->onApplyOptionsOverrides(options); |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 64 | fMaxTextureSize = SkTMin(fMaxTextureSize, options.fMaxTextureSizeOverride); |
bsalomon | 8c07b7a | 2015-11-02 11:36:52 -0800 | [diff] [blame] | 65 | // If the max tile override is zero, it means we should use the max texture size. |
| 66 | if (!options.fMaxTileSizeOverride || options.fMaxTileSizeOverride > fMaxTextureSize) { |
| 67 | fMaxTileSize = fMaxTextureSize; |
| 68 | } else { |
| 69 | fMaxTileSize = options.fMaxTileSizeOverride; |
| 70 | } |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 71 | if (fMaxWindowRectangles > GrWindowRectangles::kMaxWindows) { |
csmartdalton | 7535f41 | 2016-08-23 06:51:00 -0700 | [diff] [blame] | 72 | SkDebugf("WARNING: capping window rectangles at %i. HW advertises support for %i.\n", |
| 73 | GrWindowRectangles::kMaxWindows, fMaxWindowRectangles); |
csmartdalton | 28341fa | 2016-08-17 10:00:21 -0700 | [diff] [blame] | 74 | fMaxWindowRectangles = GrWindowRectangles::kMaxWindows; |
| 75 | } |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 76 | } |
| 77 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 78 | static SkString map_flags_to_string(uint32_t flags) { |
| 79 | SkString str; |
| 80 | if (GrCaps::kNone_MapFlags == flags) { |
| 81 | str = "none"; |
| 82 | } else { |
| 83 | SkASSERT(GrCaps::kCanMap_MapFlag & flags); |
| 84 | SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag); |
| 85 | str = "can_map"; |
| 86 | |
| 87 | if (GrCaps::kSubset_MapFlag & flags) { |
| 88 | str.append(" partial"); |
| 89 | } else { |
| 90 | str.append(" full"); |
| 91 | } |
| 92 | SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag); |
| 93 | } |
| 94 | SkASSERT(0 == flags); // Make sure we handled all the flags. |
| 95 | return str; |
| 96 | } |
| 97 | |
| 98 | SkString GrCaps::dump() const { |
| 99 | SkString r; |
| 100 | static const char* gNY[] = {"NO", "YES"}; |
| 101 | r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]); |
| 102 | r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]); |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 103 | r.appendf("sRGB Support : %s\n", gNY[fSRGBSupport]); |
brianosman | 35b784d | 2016-05-05 11:52:53 -0700 | [diff] [blame] | 104 | r.appendf("sRGB Write Control : %s\n", gNY[fSRGBWriteControl]); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 105 | r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]); |
| 106 | r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]); |
| 107 | r.appendf("Discard Render Target Support : %s\n", gNY[fDiscardRenderTargetSupport]); |
| 108 | r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 109 | r.appendf("Reuse Scratch Buffers : %s\n", gNY[fReuseScratchBuffers]); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 110 | r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]); |
| 111 | r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]); |
| 112 | r.appendf("Oversized Stencil Support : %s\n", gNY[fOversizedStencilSupport]); |
| 113 | r.appendf("Texture Barrier Support : %s\n", gNY[fTextureBarrierSupport]); |
cdalton | eb79eea | 2016-02-26 10:39:34 -0800 | [diff] [blame] | 114 | r.appendf("Sample Locations Support : %s\n", gNY[fSampleLocationsSupport]); |
csmartdalton | 2b5f2cb | 2016-06-10 14:06:32 -0700 | [diff] [blame] | 115 | r.appendf("Multisample disable support : %s\n", gNY[fMultisampleDisableSupport]); |
egdaniel | eed519e | 2016-01-15 11:36:18 -0800 | [diff] [blame] | 116 | r.appendf("Uses Mixed Samples : %s\n", gNY[fUsesMixedSamples]); |
csmartdalton | 485a120 | 2016-07-13 10:16:32 -0700 | [diff] [blame] | 117 | r.appendf("Prefer client-side dynamic buffers : %s\n", gNY[fPreferClientSideDynamicBuffers]); |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 118 | r.appendf("Full screen clear is free : %s\n", gNY[fFullClearIsFree]); |
bsalomon | 7dea7b7 | 2015-08-19 08:26:51 -0700 | [diff] [blame] | 119 | r.appendf("Must clear buffer memory : %s\n", gNY[fMustClearUploadedBufferData]); |
jvanverth | 84741b3 | 2016-09-30 08:39:02 -0700 | [diff] [blame] | 120 | r.appendf("Sample shading support : %s\n", gNY[fSampleShadingSupport]); |
| 121 | r.appendf("Fence sync support : %s\n", gNY[fFenceSyncSupport]); |
| 122 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 123 | r.appendf("Draw Instead of Clear [workaround] : %s\n", gNY[fUseDrawInsteadOfClear]); |
joshualitt | 83bc229 | 2015-06-18 14:18:02 -0700 | [diff] [blame] | 124 | r.appendf("Draw Instead of TexSubImage [workaround] : %s\n", |
| 125 | gNY[fUseDrawInsteadOfPartialRenderTargetWrite]); |
robertphillips | 6392668 | 2015-08-20 09:39:02 -0700 | [diff] [blame] | 126 | r.appendf("Prefer VRAM Use over flushes [workaround] : %s\n", gNY[fPreferVRAMUseOverFlushes]); |
| 127 | |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 128 | if (this->advancedBlendEquationSupport()) { |
| 129 | r.appendf("Advanced Blend Equation Blacklist : 0x%x\n", fAdvBlendEqBlacklist); |
| 130 | } |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 131 | |
bsalomon | 7dbd45d | 2016-03-23 10:40:53 -0700 | [diff] [blame] | 132 | r.appendf("Max Vertex Attributes : %d\n", fMaxVertexAttributes); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 133 | r.appendf("Max Texture Size : %d\n", fMaxTextureSize); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 134 | r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize); |
egdaniel | eed519e | 2016-01-15 11:36:18 -0800 | [diff] [blame] | 135 | r.appendf("Max Color Sample Count : %d\n", fMaxColorSampleCount); |
| 136 | r.appendf("Max Stencil Sample Count : %d\n", fMaxStencilSampleCount); |
cdalton | af8bc7d | 2016-02-05 09:35:20 -0800 | [diff] [blame] | 137 | r.appendf("Max Raster Samples : %d\n", fMaxRasterSamples); |
csmartdalton | 9bc1187 | 2016-08-09 12:42:47 -0700 | [diff] [blame] | 138 | r.appendf("Max Window Rectangles : %d\n", fMaxWindowRectangles); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 139 | |
csmartdalton | e0d3629 | 2016-07-29 08:14:20 -0700 | [diff] [blame] | 140 | static const char* kInstancedSupportNames[] = { |
| 141 | "None", |
| 142 | "Basic", |
| 143 | "Multisampled", |
| 144 | "Mixed Sampled", |
| 145 | }; |
| 146 | GR_STATIC_ASSERT(0 == (int)InstancedSupport::kNone); |
| 147 | GR_STATIC_ASSERT(1 == (int)InstancedSupport::kBasic); |
| 148 | GR_STATIC_ASSERT(2 == (int)InstancedSupport::kMultisampled); |
| 149 | GR_STATIC_ASSERT(3 == (int)InstancedSupport::kMixedSampled); |
| 150 | GR_STATIC_ASSERT(4 == SK_ARRAY_COUNT(kInstancedSupportNames)); |
| 151 | |
| 152 | r.appendf("Instanced Support : %s\n", |
| 153 | kInstancedSupportNames[(int)fInstancedSupport]); |
| 154 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 155 | static const char* kBlendEquationSupportNames[] = { |
| 156 | "Basic", |
| 157 | "Advanced", |
| 158 | "Advanced Coherent", |
| 159 | }; |
| 160 | GR_STATIC_ASSERT(0 == kBasic_BlendEquationSupport); |
| 161 | GR_STATIC_ASSERT(1 == kAdvanced_BlendEquationSupport); |
| 162 | GR_STATIC_ASSERT(2 == kAdvancedCoherent_BlendEquationSupport); |
| 163 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1); |
| 164 | |
| 165 | r.appendf("Blend Equation Support : %s\n", |
| 166 | kBlendEquationSupportNames[fBlendEquationSupport]); |
| 167 | r.appendf("Map Buffer Support : %s\n", |
| 168 | map_flags_to_string(fMapBufferFlags).c_str()); |
| 169 | |
| 170 | static const char* kConfigNames[] = { |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 171 | "Unknown", // kUnknown_GrPixelConfig |
| 172 | "Alpha8", // kAlpha_8_GrPixelConfig, |
Brian Osman | 986563b | 2017-01-10 14:20:02 -0500 | [diff] [blame] | 173 | "Gray8", // kGray_8_GrPixelConfig, |
Brian Salomon | bf7b620 | 2016-11-11 16:08:03 -0500 | [diff] [blame] | 174 | "RGB565", // kRGB_565_GrPixelConfig, |
| 175 | "RGBA444", // kRGBA_4444_GrPixelConfig, |
| 176 | "RGBA8888", // kRGBA_8888_GrPixelConfig, |
| 177 | "BGRA8888", // kBGRA_8888_GrPixelConfig, |
| 178 | "SRGBA8888", // kSRGBA_8888_GrPixelConfig, |
| 179 | "SBGRA8888", // kSBGRA_8888_GrPixelConfig, |
| 180 | "RGBA8888_sint", // kRGBA_8888_sint_GrPixelConfig, |
| 181 | "ETC1", // kETC1_GrPixelConfig, |
| 182 | "LATC", // kLATC_GrPixelConfig, |
| 183 | "R11EAC", // kR11_EAC_GrPixelConfig, |
| 184 | "ASTC12x12", // kASTC_12x12_GrPixelConfig, |
| 185 | "RGBAFloat", // kRGBA_float_GrPixelConfig |
| 186 | "AlphaHalf", // kAlpha_half_GrPixelConfig |
| 187 | "RGBAHalf", // kRGBA_half_GrPixelConfig |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 188 | }; |
| 189 | GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig); |
| 190 | GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig); |
Brian Osman | 986563b | 2017-01-10 14:20:02 -0500 | [diff] [blame] | 191 | GR_STATIC_ASSERT(2 == kGray_8_GrPixelConfig); |
Brian Osman | d0be1ef | 2017-01-11 16:57:15 -0500 | [diff] [blame] | 192 | GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig); |
| 193 | GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig); |
| 194 | GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig); |
| 195 | GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig); |
| 196 | GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig); |
| 197 | GR_STATIC_ASSERT(8 == kSBGRA_8888_GrPixelConfig); |
| 198 | GR_STATIC_ASSERT(9 == kRGBA_8888_sint_GrPixelConfig); |
| 199 | GR_STATIC_ASSERT(10 == kETC1_GrPixelConfig); |
| 200 | GR_STATIC_ASSERT(11 == kLATC_GrPixelConfig); |
| 201 | GR_STATIC_ASSERT(12 == kR11_EAC_GrPixelConfig); |
| 202 | GR_STATIC_ASSERT(13 == kASTC_12x12_GrPixelConfig); |
| 203 | GR_STATIC_ASSERT(14 == kRGBA_float_GrPixelConfig); |
| 204 | GR_STATIC_ASSERT(15 == kAlpha_half_GrPixelConfig); |
| 205 | GR_STATIC_ASSERT(16 == kRGBA_half_GrPixelConfig); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 206 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt); |
| 207 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 208 | SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig, false)); |
| 209 | SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig, true)); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 210 | |
| 211 | for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 212 | GrPixelConfig config = static_cast<GrPixelConfig>(i); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 213 | r.appendf("%s is renderable: %s, with MSAA: %s\n", |
| 214 | kConfigNames[i], |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 215 | gNY[this->isConfigRenderable(config, false)], |
| 216 | gNY[this->isConfigRenderable(config, true)]); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 217 | } |
| 218 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 219 | SkASSERT(!this->isConfigTexturable(kUnknown_GrPixelConfig)); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 220 | |
| 221 | for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 222 | GrPixelConfig config = static_cast<GrPixelConfig>(i); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 223 | r.appendf("%s is uploadable to a texture: %s\n", |
| 224 | kConfigNames[i], |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 225 | gNY[this->isConfigTexturable(config)]); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | return r; |
| 229 | } |