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