blob: 7003cc5bfec0971c131d50e1568142794603b2b2 [file] [log] [blame]
bsalomondc47ff72015-05-26 12:16:59 -07001
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
12GrShaderCaps::GrShaderCaps() {
13 fShaderDerivativeSupport = false;
14 fGeometryShaderSupport = false;
15 fPathRenderingSupport = false;
16 fDstReadInShaderSupport = false;
17 fDualSourceBlendingSupport = false;
bsalomondc47ff72015-05-26 12:16:59 -070018 fShaderPrecisionVaries = false;
19}
20
21static 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
33static 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
45SkString GrShaderCaps::dump() const {
46 SkString r;
47 static const char* gNY[] = { "NO", "YES" };
cdalton7e806f32015-11-11 15:16:07 -080048 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]);
bsalomondc47ff72015-05-26 12:16:59 -070053
cdalton7e806f32015-11-11 15:16:07 -080054 r.appendf("Shader Float Precisions (varies: %s):\n", gNY[fShaderPrecisionVaries]);
bsalomondc47ff72015-05-26 12:16:59 -070055
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
cdalton6fd158e2015-05-27 15:08:33 -070074void GrShaderCaps::applyOptionsOverrides(const GrContextOptions& options) {
75 fDualSourceBlendingSupport = fDualSourceBlendingSupport && !options.fSuppressDualSourceBlending;
egdanielb7e7d572015-11-04 04:23:53 -080076 this->onApplyOptionsOverrides(options);
bsalomon4ee6bd82015-05-27 13:23:23 -070077}
78
bsalomondc47ff72015-05-26 12:16:59 -070079///////////////////////////////////////////////////////////////////////////////
80
81GrCaps::GrCaps(const GrContextOptions& options) {
82 fMipMapSupport = false;
83 fNPOTTextureTileSupport = false;
84 fTwoSidedStencilSupport = false;
85 fStencilWrapOpsSupport = false;
86 fDiscardRenderTargetSupport = false;
87 fReuseScratchTextures = true;
robertphillips1b8e1b52015-06-24 06:54:10 -070088 fReuseScratchBuffers = true;
bsalomondc47ff72015-05-26 12:16:59 -070089 fGpuTracingSupport = false;
90 fCompressedTexSubImageSupport = false;
91 fOversizedStencilSupport = false;
92 fTextureBarrierSupport = false;
cdalton63f6c1f2015-11-06 07:09:43 -080093 fMixedSamplesSupport = false;
joshualitt58001552015-06-26 12:46:36 -070094 fSupportsInstancedDraws = false;
egdaniel51c8d402015-08-06 10:54:13 -070095 fFullClearIsFree = false;
bsalomon7dea7b72015-08-19 08:26:51 -070096 fMustClearUploadedBufferData = false;
bsalomondc47ff72015-05-26 12:16:59 -070097
98 fUseDrawInsteadOfClear = false;
99
100 fBlendEquationSupport = kBasic_BlendEquationSupport;
cdalton1dd05422015-06-12 09:01:18 -0700101 fAdvBlendEqBlacklist = 0;
102
bsalomondc47ff72015-05-26 12:16:59 -0700103 fMapBufferFlags = kNone_MapFlags;
104
egdanielff1d5472015-09-10 08:37:20 -0700105 fMaxRenderTargetSize = 1;
106 fMaxTextureSize = 1;
bsalomondc47ff72015-05-26 12:16:59 -0700107 fMaxSampleCount = 0;
108
109 memset(fConfigRenderSupport, 0, sizeof(fConfigRenderSupport));
110 memset(fConfigTextureSupport, 0, sizeof(fConfigTextureSupport));
111
robertphillipscaef3452015-11-11 13:18:11 -0800112 fSuppressPrints = options.fSuppressPrints;
113 fImmediateFlush = options.fImmediateMode;
bsalomondc47ff72015-05-26 12:16:59 -0700114 fDrawPathMasksToCompressedTextureSupport = options.fDrawPathToCompressedTexture;
joshualitt7224c862015-05-29 06:46:47 -0700115 fGeometryBufferMapThreshold = options.fGeometryBufferMapThreshold;
joshualitt83bc2292015-06-18 14:18:02 -0700116 fUseDrawInsteadOfPartialRenderTargetWrite = options.fUseDrawInsteadOfPartialRenderTargetWrite;
robertphillips63926682015-08-20 09:39:02 -0700117
118 fPreferVRAMUseOverFlushes = true;
bsalomondc47ff72015-05-26 12:16:59 -0700119}
120
bsalomon4ee6bd82015-05-27 13:23:23 -0700121void GrCaps::applyOptionsOverrides(const GrContextOptions& options) {
122 fMaxTextureSize = SkTMin(fMaxTextureSize, options.fMaxTextureSizeOverride);
bsalomon8c07b7a2015-11-02 11:36:52 -0800123 // If the max tile override is zero, it means we should use the max texture size.
124 if (!options.fMaxTileSizeOverride || options.fMaxTileSizeOverride > fMaxTextureSize) {
125 fMaxTileSize = fMaxTextureSize;
126 } else {
127 fMaxTileSize = options.fMaxTileSizeOverride;
128 }
egdanielb7e7d572015-11-04 04:23:53 -0800129 this->onApplyOptionsOverrides(options);
bsalomon4ee6bd82015-05-27 13:23:23 -0700130}
131
bsalomondc47ff72015-05-26 12:16:59 -0700132static SkString map_flags_to_string(uint32_t flags) {
133 SkString str;
134 if (GrCaps::kNone_MapFlags == flags) {
135 str = "none";
136 } else {
137 SkASSERT(GrCaps::kCanMap_MapFlag & flags);
138 SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag);
139 str = "can_map";
140
141 if (GrCaps::kSubset_MapFlag & flags) {
142 str.append(" partial");
143 } else {
144 str.append(" full");
145 }
146 SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag);
147 }
148 SkASSERT(0 == flags); // Make sure we handled all the flags.
149 return str;
150}
151
152SkString GrCaps::dump() const {
153 SkString r;
154 static const char* gNY[] = {"NO", "YES"};
155 r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]);
156 r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]);
157 r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]);
158 r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]);
159 r.appendf("Discard Render Target Support : %s\n", gNY[fDiscardRenderTargetSupport]);
160 r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]);
robertphillips1b8e1b52015-06-24 06:54:10 -0700161 r.appendf("Reuse Scratch Buffers : %s\n", gNY[fReuseScratchBuffers]);
bsalomondc47ff72015-05-26 12:16:59 -0700162 r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]);
163 r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]);
164 r.appendf("Oversized Stencil Support : %s\n", gNY[fOversizedStencilSupport]);
165 r.appendf("Texture Barrier Support : %s\n", gNY[fTextureBarrierSupport]);
cdalton63f6c1f2015-11-06 07:09:43 -0800166 r.appendf("Mixed Samples Support : %s\n", gNY[fMixedSamplesSupport]);
joshualitt58001552015-06-26 12:46:36 -0700167 r.appendf("Supports instanced draws : %s\n", gNY[fSupportsInstancedDraws]);
egdaniel51c8d402015-08-06 10:54:13 -0700168 r.appendf("Full screen clear is free : %s\n", gNY[fFullClearIsFree]);
bsalomon7dea7b72015-08-19 08:26:51 -0700169 r.appendf("Must clear buffer memory : %s\n", gNY[fMustClearUploadedBufferData]);
bsalomondc47ff72015-05-26 12:16:59 -0700170 r.appendf("Draw Instead of Clear [workaround] : %s\n", gNY[fUseDrawInsteadOfClear]);
joshualitt83bc2292015-06-18 14:18:02 -0700171 r.appendf("Draw Instead of TexSubImage [workaround] : %s\n",
172 gNY[fUseDrawInsteadOfPartialRenderTargetWrite]);
robertphillips63926682015-08-20 09:39:02 -0700173 r.appendf("Prefer VRAM Use over flushes [workaround] : %s\n", gNY[fPreferVRAMUseOverFlushes]);
174
cdalton1dd05422015-06-12 09:01:18 -0700175 if (this->advancedBlendEquationSupport()) {
176 r.appendf("Advanced Blend Equation Blacklist : 0x%x\n", fAdvBlendEqBlacklist);
177 }
bsalomondc47ff72015-05-26 12:16:59 -0700178
179 r.appendf("Max Texture Size : %d\n", fMaxTextureSize);
bsalomondc47ff72015-05-26 12:16:59 -0700180 r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize);
181 r.appendf("Max Sample Count : %d\n", fMaxSampleCount);
182
183 static const char* kBlendEquationSupportNames[] = {
184 "Basic",
185 "Advanced",
186 "Advanced Coherent",
187 };
188 GR_STATIC_ASSERT(0 == kBasic_BlendEquationSupport);
189 GR_STATIC_ASSERT(1 == kAdvanced_BlendEquationSupport);
190 GR_STATIC_ASSERT(2 == kAdvancedCoherent_BlendEquationSupport);
191 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1);
192
193 r.appendf("Blend Equation Support : %s\n",
194 kBlendEquationSupportNames[fBlendEquationSupport]);
195 r.appendf("Map Buffer Support : %s\n",
196 map_flags_to_string(fMapBufferFlags).c_str());
197
198 static const char* kConfigNames[] = {
199 "Unknown", // kUnknown_GrPixelConfig
200 "Alpha8", // kAlpha_8_GrPixelConfig,
201 "Index8", // kIndex_8_GrPixelConfig,
202 "RGB565", // kRGB_565_GrPixelConfig,
203 "RGBA444", // kRGBA_4444_GrPixelConfig,
204 "RGBA8888", // kRGBA_8888_GrPixelConfig,
205 "BGRA8888", // kBGRA_8888_GrPixelConfig,
206 "SRGBA8888",// kSRGBA_8888_GrPixelConfig,
207 "ETC1", // kETC1_GrPixelConfig,
208 "LATC", // kLATC_GrPixelConfig,
209 "R11EAC", // kR11_EAC_GrPixelConfig,
210 "ASTC12x12",// kASTC_12x12_GrPixelConfig,
211 "RGBAFloat",// kRGBA_float_GrPixelConfig
212 "AlphaHalf",// kAlpha_half_GrPixelConfig
213 "RGBAHalf", // kRGBA_half_GrPixelConfig
214 };
215 GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
216 GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
217 GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
218 GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
219 GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
220 GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
221 GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
222 GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig);
223 GR_STATIC_ASSERT(8 == kETC1_GrPixelConfig);
224 GR_STATIC_ASSERT(9 == kLATC_GrPixelConfig);
225 GR_STATIC_ASSERT(10 == kR11_EAC_GrPixelConfig);
226 GR_STATIC_ASSERT(11 == kASTC_12x12_GrPixelConfig);
227 GR_STATIC_ASSERT(12 == kRGBA_float_GrPixelConfig);
228 GR_STATIC_ASSERT(13 == kAlpha_half_GrPixelConfig);
229 GR_STATIC_ASSERT(14 == kRGBA_half_GrPixelConfig);
230 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
231
232 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][0]);
233 SkASSERT(!fConfigRenderSupport[kUnknown_GrPixelConfig][1]);
234
235 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
236 r.appendf("%s is renderable: %s, with MSAA: %s\n",
237 kConfigNames[i],
238 gNY[fConfigRenderSupport[i][0]],
239 gNY[fConfigRenderSupport[i][1]]);
240 }
241
242 SkASSERT(!fConfigTextureSupport[kUnknown_GrPixelConfig]);
243
244 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
245 r.appendf("%s is uploadable to a texture: %s\n",
246 kConfigNames[i],
247 gNY[fConfigTextureSupport[i]]);
248 }
249
250 return r;
251}