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; |
| 18 | fMixedSamplesSupport = false; |
| 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" }; |
| 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]); |
| 54 | r.appendf("Mixed Samples Support : %s\n", gNY[fMixedSamplesSupport]); |
| 55 | |
| 56 | r.appendf("Shader Float Precisions (varies: %s):\n", gNY[fShaderPrecisionVaries]); |
| 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; |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 78 | } |
| 79 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 80 | /////////////////////////////////////////////////////////////////////////////// |
| 81 | |
| 82 | GrCaps::GrCaps(const GrContextOptions& options) { |
| 83 | fMipMapSupport = false; |
| 84 | fNPOTTextureTileSupport = false; |
| 85 | fTwoSidedStencilSupport = false; |
| 86 | fStencilWrapOpsSupport = false; |
| 87 | fDiscardRenderTargetSupport = false; |
| 88 | fReuseScratchTextures = true; |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame^] | 89 | fReuseScratchBuffers = true; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 90 | fGpuTracingSupport = false; |
| 91 | fCompressedTexSubImageSupport = false; |
| 92 | fOversizedStencilSupport = false; |
| 93 | fTextureBarrierSupport = false; |
| 94 | |
| 95 | fUseDrawInsteadOfClear = false; |
| 96 | |
| 97 | fBlendEquationSupport = kBasic_BlendEquationSupport; |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 98 | fAdvBlendEqBlacklist = 0; |
| 99 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 100 | fMapBufferFlags = kNone_MapFlags; |
| 101 | |
| 102 | fMaxRenderTargetSize = 0; |
| 103 | fMaxTextureSize = 0; |
bsalomon | c59a1df | 2015-06-01 07:13:42 -0700 | [diff] [blame] | 104 | fMinTextureSize = 0; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 105 | fMaxSampleCount = 0; |
| 106 | |
| 107 | memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport)); |
| 108 | memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport)); |
| 109 | |
| 110 | fSupressPrints = options.fSuppressPrints; |
| 111 | fDrawPathMasksToCompressedTextureSupport = options.fDrawPathToCompressedTexture; |
joshualitt | 7224c86 | 2015-05-29 06:46:47 -0700 | [diff] [blame] | 112 | fGeometryBufferMapThreshold = options.fGeometryBufferMapThreshold; |
joshualitt | 83bc229 | 2015-06-18 14:18:02 -0700 | [diff] [blame] | 113 | fUseDrawInsteadOfPartialRenderTargetWrite = options.fUseDrawInsteadOfPartialRenderTargetWrite; |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 114 | } |
| 115 | |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 116 | void GrCaps::applyOptionsOverrides(const GrContextOptions& options) { |
| 117 | fMaxTextureSize = SkTMin(fMaxTextureSize, options.fMaxTextureSizeOverride); |
bsalomon | c59a1df | 2015-06-01 07:13:42 -0700 | [diff] [blame] | 118 | fMinTextureSize = SkTMax(fMinTextureSize, options.fMinTextureSizeOverride); |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 119 | } |
| 120 | |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 121 | static SkString map_flags_to_string(uint32_t flags) { |
| 122 | SkString str; |
| 123 | if (GrCaps::kNone_MapFlags == flags) { |
| 124 | str = "none"; |
| 125 | } else { |
| 126 | SkASSERT(GrCaps::kCanMap_MapFlag & flags); |
| 127 | SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag); |
| 128 | str = "can_map"; |
| 129 | |
| 130 | if (GrCaps::kSubset_MapFlag & flags) { |
| 131 | str.append(" partial"); |
| 132 | } else { |
| 133 | str.append(" full"); |
| 134 | } |
| 135 | SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag); |
| 136 | } |
| 137 | SkASSERT(0 == flags); // Make sure we handled all the flags. |
| 138 | return str; |
| 139 | } |
| 140 | |
| 141 | SkString GrCaps::dump() const { |
| 142 | SkString r; |
| 143 | static const char* gNY[] = {"NO", "YES"}; |
| 144 | r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]); |
| 145 | r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]); |
| 146 | r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]); |
| 147 | r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]); |
| 148 | r.appendf("Discard Render Target Support : %s\n", gNY[fDiscardRenderTargetSupport]); |
| 149 | r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]); |
robertphillips | 1b8e1b5 | 2015-06-24 06:54:10 -0700 | [diff] [blame^] | 150 | r.appendf("Reuse Scratch Buffers : %s\n", gNY[fReuseScratchBuffers]); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 151 | r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]); |
| 152 | r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]); |
| 153 | r.appendf("Oversized Stencil Support : %s\n", gNY[fOversizedStencilSupport]); |
| 154 | r.appendf("Texture Barrier Support : %s\n", gNY[fTextureBarrierSupport]); |
| 155 | r.appendf("Draw Instead of Clear [workaround] : %s\n", gNY[fUseDrawInsteadOfClear]); |
joshualitt | 83bc229 | 2015-06-18 14:18:02 -0700 | [diff] [blame] | 156 | r.appendf("Draw Instead of TexSubImage [workaround] : %s\n", |
| 157 | gNY[fUseDrawInsteadOfPartialRenderTargetWrite]); |
cdalton | 1dd0542 | 2015-06-12 09:01:18 -0700 | [diff] [blame] | 158 | if (this->advancedBlendEquationSupport()) { |
| 159 | r.appendf("Advanced Blend Equation Blacklist : 0x%x\n", fAdvBlendEqBlacklist); |
| 160 | } |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 161 | |
| 162 | r.appendf("Max Texture Size : %d\n", fMaxTextureSize); |
bsalomon | c59a1df | 2015-06-01 07:13:42 -0700 | [diff] [blame] | 163 | r.appendf("Min Texture Size : %d\n", fMinTextureSize); |
bsalomon | dc47ff7 | 2015-05-26 12:16:59 -0700 | [diff] [blame] | 164 | r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize); |
| 165 | r.appendf("Max Sample Count : %d\n", fMaxSampleCount); |
| 166 | |
| 167 | static const char* kBlendEquationSupportNames[] = { |
| 168 | "Basic", |
| 169 | "Advanced", |
| 170 | "Advanced Coherent", |
| 171 | }; |
| 172 | GR_STATIC_ASSERT(0 == kBasic_BlendEquationSupport); |
| 173 | GR_STATIC_ASSERT(1 == kAdvanced_BlendEquationSupport); |
| 174 | GR_STATIC_ASSERT(2 == kAdvancedCoherent_BlendEquationSupport); |
| 175 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1); |
| 176 | |
| 177 | r.appendf("Blend Equation Support : %s\n", |
| 178 | kBlendEquationSupportNames[fBlendEquationSupport]); |
| 179 | r.appendf("Map Buffer Support : %s\n", |
| 180 | map_flags_to_string(fMapBufferFlags).c_str()); |
| 181 | |
| 182 | static const char* kConfigNames[] = { |
| 183 | "Unknown", // kUnknown_GrPixelConfig |
| 184 | "Alpha8", // kAlpha_8_GrPixelConfig, |
| 185 | "Index8", // kIndex_8_GrPixelConfig, |
| 186 | "RGB565", // kRGB_565_GrPixelConfig, |
| 187 | "RGBA444", // kRGBA_4444_GrPixelConfig, |
| 188 | "RGBA8888", // kRGBA_8888_GrPixelConfig, |
| 189 | "BGRA8888", // kBGRA_8888_GrPixelConfig, |
| 190 | "SRGBA8888",// kSRGBA_8888_GrPixelConfig, |
| 191 | "ETC1", // kETC1_GrPixelConfig, |
| 192 | "LATC", // kLATC_GrPixelConfig, |
| 193 | "R11EAC", // kR11_EAC_GrPixelConfig, |
| 194 | "ASTC12x12",// kASTC_12x12_GrPixelConfig, |
| 195 | "RGBAFloat",// kRGBA_float_GrPixelConfig |
| 196 | "AlphaHalf",// kAlpha_half_GrPixelConfig |
| 197 | "RGBAHalf", // kRGBA_half_GrPixelConfig |
| 198 | }; |
| 199 | GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig); |
| 200 | GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig); |
| 201 | GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig); |
| 202 | GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig); |
| 203 | GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig); |
| 204 | GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig); |
| 205 | GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig); |
| 206 | GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig); |
| 207 | GR_STATIC_ASSERT(8 == kETC1_GrPixelConfig); |
| 208 | GR_STATIC_ASSERT(9 == kLATC_GrPixelConfig); |
| 209 | GR_STATIC_ASSERT(10 == kR11_EAC_GrPixelConfig); |
| 210 | GR_STATIC_ASSERT(11 == kASTC_12x12_GrPixelConfig); |
| 211 | GR_STATIC_ASSERT(12 == kRGBA_float_GrPixelConfig); |
| 212 | GR_STATIC_ASSERT(13 == kAlpha_half_GrPixelConfig); |
| 213 | GR_STATIC_ASSERT(14 == kRGBA_half_GrPixelConfig); |
| 214 | GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt); |
| 215 | |
| 216 | SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]); |
| 217 | SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]); |
| 218 | |
| 219 | for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
| 220 | r.appendf("%s is renderable: %s, with MSAA: %s\n", |
| 221 | kConfigNames[i], |
| 222 | gNY[fConfigRenderSupport[i][0]], |
| 223 | gNY[fConfigRenderSupport[i][1]]); |
| 224 | } |
| 225 | |
| 226 | SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]); |
| 227 | |
| 228 | for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) { |
| 229 | r.appendf("%s is uploadable to a texture: %s\n", |
| 230 | kConfigNames[i], |
| 231 | gNY[fConfigTextureSupport[i]]); |
| 232 | } |
| 233 | |
| 234 | return r; |
| 235 | } |