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