bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2015 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
| 8 | |
| 9 | #include "GrCaps.h" |
| 10 | #include "GrContextOptions.h" |
| 11 | |
| 12 | GrShaderCaps::GrShaderCaps() { |
| 13 | fShaderDerivativeSupport = false; |
| 14 | fGeometryShaderSupport = false; |
| 15 | fPathRenderingSupport = false; |
| 16 | fDstReadInShaderSupport = false; |
| 17 | fDualSourceBlendingSupport = false; |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 18 | fIntegerSupport = false; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 19 | fShaderPrecisionVaries = false; |
| 20 | } |
| 21 | |
| 22 | static const char* shader_type_to_string(GrShaderType type) { |
| 23 | switch (type) { |
| 24 | case kVertex_GrShaderType: |
| 25 | return "vertex"; |
| 26 | case kGeometry_GrShaderType: |
| 27 | return "geometry"; |
| 28 | case kFragment_GrShaderType: |
| 29 | return "fragment"; |
| 30 | } |
| 31 | return ""; |
| 32 | } |
| 33 | |
| 34 | static const char* precision_to_string(GrSLPrecision p) { |
| 35 | switch (p) { |
| 36 | case kLow_GrSLPrecision: |
| 37 | return "low"; |
| 38 | case kMedium_GrSLPrecision: |
| 39 | return "medium"; |
| 40 | case kHigh_GrSLPrecision: |
| 41 | return "high"; |
| 42 | } |
| 43 | return ""; |
| 44 | } |
| 45 | |
| 46 | SkString GrShaderCaps::dump() const { |
| 47 | SkString r; |
| 48 | static const char* gNY[] = { "NO", "YES" }; |
cdalton | 7e806f3 | 2015-11-11 15:16:07 -0800 | [diff] [blame] | 49 | r.appendf("Shader Derivative Support : %s\n", gNY[fShaderDerivativeSupport]); |
| 50 | r.appendf("Geometry Shader Support : %s\n", gNY[fGeometryShaderSupport]); |
| 51 | r.appendf("Path Rendering Support : %s\n", gNY[fPathRenderingSupport]); |
| 52 | r.appendf("Dst Read In Shader Support : %s\n", gNY[fDstReadInShaderSupport]); |
| 53 | r.appendf("Dual Source Blending Support : %s\n", gNY[fDualSourceBlendingSupport]); |
cdalton | 793dc26 | 2016-02-08 10:11:47 -0800 | [diff] [blame] | 54 | r.appendf("Integer Support : %s\n", gNY[fIntegerSupport]); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 55 | |
cdalton | 7e806f3 | 2015-11-11 15:16:07 -0800 | [diff] [blame] | 56 | r.appendf("Shader Float Precisions (varies: %s):\n", gNY[fShaderPrecisionVaries]); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 57 | |
| 58 | for (int s = 0; s < kGrShaderTypeCount; ++s) { |
| 59 | GrShaderType shaderType = static_cast<GrShaderType>(s); |
| 60 | r.appendf("\t%s:\n", shader_type_to_string(shaderType)); |
| 61 | for (int p = 0; p < kGrSLPrecisionCount; ++p) { |
| 62 | if (fFloatPrecisions[s][p].supported()) { |
| 63 | GrSLPrecision precision = static_cast<GrSLPrecision>(p); |
| 64 | r.appendf("\t\t%s: log_low: %d log_high: %d bits: %d\n", |
| 65 | precision_to_string(precision), |
| 66 | fFloatPrecisions[s][p].fLogRangeLow, |
| 67 | fFloatPrecisions[s][p].fLogRangeHigh, |
| 68 | fFloatPrecisions[s][p].fBits); |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | return r; |
| 74 | } |
| 75 | |
cdalton | 6fd158e | 2015-05-27 15:08:33 -0700 | [diff] [blame] | 76 | void GrShaderCaps::applyOptionsOverrides(const GrContextOptions& options) { |
| 77 | fDualSourceBlendingSupport = fDualSourceBlendingSupport && !options.fSuppressDualSourceBlending; |
egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 78 | this->onApplyOptionsOverrides(options); |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 79 | } |
| 80 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 81 | /////////////////////////////////////////////////////////////////////////////// |
| 82 | |
| 83 | GrCaps::GrCaps(const GrContextOptions& options) { |
| 84 | fMipMapSupport = false; |
| 85 | fNPOTTextureTileSupport = false; |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 86 | fSRGBSupport = false; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 87 | fTwoSidedStencilSupport = false; |
| 88 | fStencilWrapOpsSupport = false; |
| 89 | fDiscardRenderTargetSupport = false; |
| 90 | fReuseScratchTextures = true; |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 91 | fReuseScratchBuffers = true; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 92 | fGpuTracingSupport = false; |
| 93 | fCompressedTexSubImageSupport = false; |
| 94 | fOversizedStencilSupport = false; |
| 95 | fTextureBarrierSupport = false; |
cdalton | eb79eea | 2016-02-26 10:39:34 -0800 | [diff] [blame] | 96 | fSampleLocationsSupport = false; |
egdaniel | eed519e | 2016-01-15 11:36:18 -0800 | [diff] [blame] | 97 | fUsesMixedSamples = false; |
joshualitt | 5800155 | 2015-06-26 12:46:36 -0700 | [diff] [blame] | 98 | fSupportsInstancedDraws = false; |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 99 | fFullClearIsFree = false; |
bsalomon | 7dea7b7 | 2015-08-19 08:26:51 -0700 | [diff] [blame] | 100 | fMustClearUploadedBufferData = false; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 101 | |
| 102 | fUseDrawInsteadOfClear = false; |
| 103 | |
| 104 | fBlendEquationSupport = kBasic_BlendEquationSupport; |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 105 | fAdvBlendEqBlacklist = 0; |
| 106 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 107 | fMapBufferFlags = kNone_MapFlags; |
| 108 | |
bsalomon | 7dbd45d | 2016-03-23 10:40:53 -0700 | [diff] [blame] | 109 | fMaxVertexAttributes = 0; |
egdaniel | ff1d547 | 2015-09-10 08:37:20 -0700 | [diff] [blame] | 110 | fMaxRenderTargetSize = 1; |
| 111 | fMaxTextureSize = 1; |
egdaniel | eed519e | 2016-01-15 11:36:18 -0800 | [diff] [blame] | 112 | fMaxColorSampleCount = 0; |
| 113 | fMaxStencilSampleCount = 0; |
cdalton | af8bc7d | 2016-02-05 09:35:20 -0800 | [diff] [blame] | 114 | fMaxRasterSamples = 0; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 115 | |
robertphillips | caef345 | 2015-11-11 13:18:11 -0800 | [diff] [blame] | 116 | fSuppressPrints = options.fSuppressPrints; |
| 117 | fImmediateFlush = options.fImmediateMode; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 118 | fDrawPathMasksToCompressedTextureSupport = options.fDrawPathToCompressedTexture; |
robertphillips | f8c3ba4 | 2016-03-25 04:55:58 -0700 | [diff] [blame^] | 119 | fGeometryBufferMapThreshold = options.fGeometryBufferMapThreshold; |
joshualitt | 83bc229 | 2015-06-18 14:18:02 -0700 | [diff] [blame] | 120 | fUseDrawInsteadOfPartialRenderTargetWrite = options.fUseDrawInsteadOfPartialRenderTargetWrite; |
bsalomon | babafcc | 2016-02-16 11:36:47 -0800 | [diff] [blame] | 121 | fUseDrawInsteadOfAllRenderTargetWrites = false; |
robertphillips | 6392668 | 2015-08-20 09:39:02 -0700 | [diff] [blame] | 122 | |
| 123 | fPreferVRAMUseOverFlushes = true; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 124 | } |
| 125 | |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 126 | void GrCaps::applyOptionsOverrides(const GrContextOptions& options) { |
| 127 | fMaxTextureSize = SkTMin(fMaxTextureSize, options.fMaxTextureSizeOverride); |
bsalomon | 8c07b7a | 2015-11-02 11:36:52 -0800 | [diff] [blame] | 128 | // If the max tile override is zero, it means we should use the max texture size. |
| 129 | if (!options.fMaxTileSizeOverride || options.fMaxTileSizeOverride > fMaxTextureSize) { |
| 130 | fMaxTileSize = fMaxTextureSize; |
| 131 | } else { |
| 132 | fMaxTileSize = options.fMaxTileSizeOverride; |
| 133 | } |
egdaniel | b7e7d57 | 2015-11-04 04:23:53 -0800 | [diff] [blame] | 134 | this->onApplyOptionsOverrides(options); |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 135 | } |
| 136 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 137 | static SkString map_flags_to_string(uint32_t flags) { |
| 138 | SkString str; |
| 139 | if (GrCaps::kNone_MapFlags == flags) { |
| 140 | str = "none"; |
| 141 | } else { |
| 142 | SkASSERT(GrCaps::kCanMap_MapFlag & flags); |
| 143 | SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag); |
| 144 | str = "can_map"; |
| 145 | |
| 146 | if (GrCaps::kSubset_MapFlag & flags) { |
| 147 | str.append(" partial"); |
| 148 | } else { |
| 149 | str.append(" full"); |
| 150 | } |
| 151 | SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag); |
| 152 | } |
| 153 | SkASSERT(0 == flags); // Make sure we handled all the flags. |
| 154 | return str; |
| 155 | } |
| 156 | |
| 157 | SkString GrCaps::dump() const { |
| 158 | SkString r; |
| 159 | static const char* gNY[] = {"NO", "YES"}; |
| 160 | r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]); |
| 161 | r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]); |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 162 | r.appendf("sRGB Support : %s\n", gNY[fSRGBSupport]); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 163 | r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]); |
| 164 | r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]); |
| 165 | r.appendf("Discard Render Target Support : %s\n", gNY[fDiscardRenderTargetSupport]); |
| 166 | r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame] | 167 | r.appendf("Reuse Scratch Buffers : %s\n", gNY[fReuseScratchBuffers]); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 168 | r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]); |
| 169 | r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]); |
| 170 | r.appendf("Oversized Stencil Support : %s\n", gNY[fOversizedStencilSupport]); |
| 171 | r.appendf("Texture Barrier Support : %s\n", gNY[fTextureBarrierSupport]); |
cdalton | eb79eea | 2016-02-26 10:39:34 -0800 | [diff] [blame] | 172 | r.appendf("Sample Locations Support : %s\n", gNY[fSampleLocationsSupport]); |
egdaniel | eed519e | 2016-01-15 11:36:18 -0800 | [diff] [blame] | 173 | r.appendf("Uses Mixed Samples : %s\n", gNY[fUsesMixedSamples]); |
joshualitt | 5800155 | 2015-06-26 12:46:36 -0700 | [diff] [blame] | 174 | r.appendf("Supports instanced draws : %s\n", gNY[fSupportsInstancedDraws]); |
egdaniel | 51c8d40 | 2015-08-06 10:54:13 -0700 | [diff] [blame] | 175 | r.appendf("Full screen clear is free : %s\n", gNY[fFullClearIsFree]); |
bsalomon | 7dea7b7 | 2015-08-19 08:26:51 -0700 | [diff] [blame] | 176 | r.appendf("Must clear buffer memory : %s\n", gNY[fMustClearUploadedBufferData]); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 177 | r.appendf("Draw Instead of Clear [workaround] : %s\n", gNY[fUseDrawInsteadOfClear]); |
joshualitt | 83bc229 | 2015-06-18 14:18:02 -0700 | [diff] [blame] | 178 | r.appendf("Draw Instead of TexSubImage [workaround] : %s\n", |
| 179 | gNY[fUseDrawInsteadOfPartialRenderTargetWrite]); |
robertphillips | 6392668 | 2015-08-20 09:39:02 -0700 | [diff] [blame] | 180 | r.appendf("Prefer VRAM Use over flushes [workaround] : %s\n", gNY[fPreferVRAMUseOverFlushes]); |
| 181 | |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 182 | if (this->advancedBlendEquationSupport()) { |
| 183 | r.appendf("Advanced Blend Equation Blacklist : 0x%x\n", fAdvBlendEqBlacklist); |
| 184 | } |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 185 | |
bsalomon | 7dbd45d | 2016-03-23 10:40:53 -0700 | [diff] [blame] | 186 | r.appendf("Max Vertex Attributes : %d\n", fMaxVertexAttributes); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 187 | r.appendf("Max Texture Size : %d\n", fMaxTextureSize); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 188 | r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize); |
egdaniel | eed519e | 2016-01-15 11:36:18 -0800 | [diff] [blame] | 189 | r.appendf("Max Color Sample Count : %d\n", fMaxColorSampleCount); |
| 190 | r.appendf("Max Stencil Sample Count : %d\n", fMaxStencilSampleCount); |
cdalton | af8bc7d | 2016-02-05 09:35:20 -0800 | [diff] [blame] | 191 | r.appendf("Max Raster Samples : %d\n", fMaxRasterSamples); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 192 | |
| 193 | static const char* kBlendEquationSupportNames[] = { |
| 194 | "Basic", |
| 195 | "Advanced", |
| 196 | "Advanced Coherent", |
| 197 | }; |
| 198 | GR_STATIC_ASSERT(0 == kBasic_BlendEquationSupport); |
| 199 | GR_STATIC_ASSERT(1 == kAdvanced_BlendEquationSupport); |
| 200 | GR_STATIC_ASSERT(2 == kAdvancedCoherent_BlendEquationSupport); |
| 201 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1); |
| 202 | |
| 203 | r.appendf("Blend Equation Support : %s\n", |
| 204 | kBlendEquationSupportNames[fBlendEquationSupport]); |
| 205 | r.appendf("Map Buffer Support : %s\n", |
| 206 | map_flags_to_string(fMapBufferFlags).c_str()); |
| 207 | |
| 208 | static const char* kConfigNames[] = { |
| 209 | "Unknown", // kUnknown_GrPixelConfig |
| 210 | "Alpha8", // kAlpha_8_GrPixelConfig, |
| 211 | "Index8", // kIndex_8_GrPixelConfig, |
| 212 | "RGB565", // kRGB_565_GrPixelConfig, |
| 213 | "RGBA444", // kRGBA_4444_GrPixelConfig, |
| 214 | "RGBA8888", // kRGBA_8888_GrPixelConfig, |
| 215 | "BGRA8888", // kBGRA_8888_GrPixelConfig, |
| 216 | "SRGBA8888",// kSRGBA_8888_GrPixelConfig, |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 217 | "SBGRA8888",// kSBGRA_8888_GrPixelConfig, |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 218 | "ETC1", // kETC1_GrPixelConfig, |
| 219 | "LATC", // kLATC_GrPixelConfig, |
| 220 | "R11EAC", // kR11_EAC_GrPixelConfig, |
| 221 | "ASTC12x12",// kASTC_12x12_GrPixelConfig, |
| 222 | "RGBAFloat",// kRGBA_float_GrPixelConfig |
| 223 | "AlphaHalf",// kAlpha_half_GrPixelConfig |
| 224 | "RGBAHalf", // kRGBA_half_GrPixelConfig |
| 225 | }; |
| 226 | GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig); |
| 227 | GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig); |
| 228 | GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig); |
| 229 | GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig); |
| 230 | GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig); |
| 231 | GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig); |
| 232 | GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig); |
| 233 | GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig); |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 234 | GR_STATIC_ASSERT(8 == kSBGRA_8888_GrPixelConfig); |
| 235 | GR_STATIC_ASSERT(9 == kETC1_GrPixelConfig); |
| 236 | GR_STATIC_ASSERT(10 == kLATC_GrPixelConfig); |
| 237 | GR_STATIC_ASSERT(11 == kR11_EAC_GrPixelConfig); |
| 238 | GR_STATIC_ASSERT(12 == kASTC_12x12_GrPixelConfig); |
| 239 | GR_STATIC_ASSERT(13 == kRGBA_float_GrPixelConfig); |
| 240 | GR_STATIC_ASSERT(14 == kAlpha_half_GrPixelConfig); |
| 241 | GR_STATIC_ASSERT(15 == kRGBA_half_GrPixelConfig); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 242 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt); |
| 243 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 244 | SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig, false)); |
| 245 | SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig, true)); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 246 | |
| 247 | for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 248 | GrPixelConfig config = static_cast<GrPixelConfig>(i); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 249 | r.appendf("%s is renderable: %s, with MSAA: %s\n", |
| 250 | kConfigNames[i], |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 251 | gNY[this->isConfigRenderable(config, false)], |
| 252 | gNY[this->isConfigRenderable(config, true)]); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 253 | } |
| 254 | |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 255 | SkASSERT(!this->isConfigTexturable(kUnknown_GrPixelConfig)); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 256 | |
| 257 | for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 258 | GrPixelConfig config = static_cast<GrPixelConfig>(i); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 259 | r.appendf("%s is uploadable to a texture: %s\n", |
| 260 | kConfigNames[i], |
bsalomon | 41e4384e | 2016-01-08 09:12:44 -0800 | [diff] [blame] | 261 | gNY[this->isConfigTexturable(config)]); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | return r; |
| 265 | } |