blob: c544d6ef772fa979ba2bb01e402c54ba7e217c82 [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;
cdalton793dc262016-02-08 10:11:47 -080018 fIntegerSupport = false;
bsalomondc47ff72015-05-26 12:16:59 -070019 fShaderPrecisionVaries = false;
20}
21
22static 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
34static 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
46SkString GrShaderCaps::dump() const {
47 SkString r;
48 static const char* gNY[] = { "NO", "YES" };
cdalton7e806f32015-11-11 15:16:07 -080049 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]);
cdalton793dc262016-02-08 10:11:47 -080054 r.appendf("Integer Support : %s\n", gNY[fIntegerSupport]);
bsalomondc47ff72015-05-26 12:16:59 -070055
cdalton7e806f32015-11-11 15:16:07 -080056 r.appendf("Shader Float Precisions (varies: %s):\n", gNY[fShaderPrecisionVaries]);
bsalomondc47ff72015-05-26 12:16:59 -070057
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
cdalton6fd158e2015-05-27 15:08:33 -070076void GrShaderCaps::applyOptionsOverrides(const GrContextOptions& options) {
77 fDualSourceBlendingSupport = fDualSourceBlendingSupport && !options.fSuppressDualSourceBlending;
egdanielb7e7d572015-11-04 04:23:53 -080078 this->onApplyOptionsOverrides(options);
bsalomon4ee6bd82015-05-27 13:23:23 -070079}
80
bsalomondc47ff72015-05-26 12:16:59 -070081///////////////////////////////////////////////////////////////////////////////
82
83GrCaps::GrCaps(const GrContextOptions& options) {
84 fMipMapSupport = false;
85 fNPOTTextureTileSupport = false;
86 fTwoSidedStencilSupport = false;
87 fStencilWrapOpsSupport = false;
88 fDiscardRenderTargetSupport = false;
89 fReuseScratchTextures = true;
robertphillips1b8e1b52015-06-24 06:54:10 -070090 fReuseScratchBuffers = true;
bsalomondc47ff72015-05-26 12:16:59 -070091 fGpuTracingSupport = false;
92 fCompressedTexSubImageSupport = false;
93 fOversizedStencilSupport = false;
94 fTextureBarrierSupport = false;
cdaltoneb79eea2016-02-26 10:39:34 -080095 fSampleLocationsSupport = false;
egdanieleed519e2016-01-15 11:36:18 -080096 fUsesMixedSamples = false;
joshualitt58001552015-06-26 12:46:36 -070097 fSupportsInstancedDraws = false;
egdaniel51c8d402015-08-06 10:54:13 -070098 fFullClearIsFree = false;
bsalomon7dea7b72015-08-19 08:26:51 -070099 fMustClearUploadedBufferData = false;
bsalomondc47ff72015-05-26 12:16:59 -0700100
101 fUseDrawInsteadOfClear = false;
102
103 fBlendEquationSupport = kBasic_BlendEquationSupport;
cdalton1dd05422015-06-12 09:01:18 -0700104 fAdvBlendEqBlacklist = 0;
105
bsalomondc47ff72015-05-26 12:16:59 -0700106 fMapBufferFlags = kNone_MapFlags;
107
egdanielff1d5472015-09-10 08:37:20 -0700108 fMaxRenderTargetSize = 1;
109 fMaxTextureSize = 1;
egdanieleed519e2016-01-15 11:36:18 -0800110 fMaxColorSampleCount = 0;
111 fMaxStencilSampleCount = 0;
cdaltonaf8bc7d2016-02-05 09:35:20 -0800112 fMaxRasterSamples = 0;
bsalomondc47ff72015-05-26 12:16:59 -0700113
robertphillipscaef3452015-11-11 13:18:11 -0800114 fSuppressPrints = options.fSuppressPrints;
115 fImmediateFlush = options.fImmediateMode;
bsalomondc47ff72015-05-26 12:16:59 -0700116 fDrawPathMasksToCompressedTextureSupport = options.fDrawPathToCompressedTexture;
joshualitt7224c862015-05-29 06:46:47 -0700117 fGeometryBufferMapThreshold = options.fGeometryBufferMapThreshold;
joshualitt83bc2292015-06-18 14:18:02 -0700118 fUseDrawInsteadOfPartialRenderTargetWrite = options.fUseDrawInsteadOfPartialRenderTargetWrite;
bsalomonbabafcc2016-02-16 11:36:47 -0800119 fUseDrawInsteadOfAllRenderTargetWrites = false;
robertphillips63926682015-08-20 09:39:02 -0700120
121 fPreferVRAMUseOverFlushes = true;
bsalomondc47ff72015-05-26 12:16:59 -0700122}
123
bsalomon4ee6bd82015-05-27 13:23:23 -0700124void GrCaps::applyOptionsOverrides(const GrContextOptions& options) {
125 fMaxTextureSize = SkTMin(fMaxTextureSize, options.fMaxTextureSizeOverride);
bsalomon8c07b7a2015-11-02 11:36:52 -0800126 // If the max tile override is zero, it means we should use the max texture size.
127 if (!options.fMaxTileSizeOverride || options.fMaxTileSizeOverride > fMaxTextureSize) {
128 fMaxTileSize = fMaxTextureSize;
129 } else {
130 fMaxTileSize = options.fMaxTileSizeOverride;
131 }
egdanielb7e7d572015-11-04 04:23:53 -0800132 this->onApplyOptionsOverrides(options);
bsalomon4ee6bd82015-05-27 13:23:23 -0700133}
134
bsalomondc47ff72015-05-26 12:16:59 -0700135static SkString map_flags_to_string(uint32_t flags) {
136 SkString str;
137 if (GrCaps::kNone_MapFlags == flags) {
138 str = "none";
139 } else {
140 SkASSERT(GrCaps::kCanMap_MapFlag & flags);
141 SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag);
142 str = "can_map";
143
144 if (GrCaps::kSubset_MapFlag & flags) {
145 str.append(" partial");
146 } else {
147 str.append(" full");
148 }
149 SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag);
150 }
151 SkASSERT(0 == flags); // Make sure we handled all the flags.
152 return str;
153}
154
155SkString GrCaps::dump() const {
156 SkString r;
157 static const char* gNY[] = {"NO", "YES"};
158 r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]);
159 r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]);
160 r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]);
161 r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]);
162 r.appendf("Discard Render Target Support : %s\n", gNY[fDiscardRenderTargetSupport]);
163 r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]);
robertphillips1b8e1b52015-06-24 06:54:10 -0700164 r.appendf("Reuse Scratch Buffers : %s\n", gNY[fReuseScratchBuffers]);
bsalomondc47ff72015-05-26 12:16:59 -0700165 r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]);
166 r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]);
167 r.appendf("Oversized Stencil Support : %s\n", gNY[fOversizedStencilSupport]);
168 r.appendf("Texture Barrier Support : %s\n", gNY[fTextureBarrierSupport]);
cdaltoneb79eea2016-02-26 10:39:34 -0800169 r.appendf("Sample Locations Support : %s\n", gNY[fSampleLocationsSupport]);
egdanieleed519e2016-01-15 11:36:18 -0800170 r.appendf("Uses Mixed Samples : %s\n", gNY[fUsesMixedSamples]);
joshualitt58001552015-06-26 12:46:36 -0700171 r.appendf("Supports instanced draws : %s\n", gNY[fSupportsInstancedDraws]);
egdaniel51c8d402015-08-06 10:54:13 -0700172 r.appendf("Full screen clear is free : %s\n", gNY[fFullClearIsFree]);
bsalomon7dea7b72015-08-19 08:26:51 -0700173 r.appendf("Must clear buffer memory : %s\n", gNY[fMustClearUploadedBufferData]);
bsalomondc47ff72015-05-26 12:16:59 -0700174 r.appendf("Draw Instead of Clear [workaround] : %s\n", gNY[fUseDrawInsteadOfClear]);
joshualitt83bc2292015-06-18 14:18:02 -0700175 r.appendf("Draw Instead of TexSubImage [workaround] : %s\n",
176 gNY[fUseDrawInsteadOfPartialRenderTargetWrite]);
robertphillips63926682015-08-20 09:39:02 -0700177 r.appendf("Prefer VRAM Use over flushes [workaround] : %s\n", gNY[fPreferVRAMUseOverFlushes]);
178
cdalton1dd05422015-06-12 09:01:18 -0700179 if (this->advancedBlendEquationSupport()) {
180 r.appendf("Advanced Blend Equation Blacklist : 0x%x\n", fAdvBlendEqBlacklist);
181 }
bsalomondc47ff72015-05-26 12:16:59 -0700182
183 r.appendf("Max Texture Size : %d\n", fMaxTextureSize);
bsalomondc47ff72015-05-26 12:16:59 -0700184 r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize);
egdanieleed519e2016-01-15 11:36:18 -0800185 r.appendf("Max Color Sample Count : %d\n", fMaxColorSampleCount);
186 r.appendf("Max Stencil Sample Count : %d\n", fMaxStencilSampleCount);
cdaltonaf8bc7d2016-02-05 09:35:20 -0800187 r.appendf("Max Raster Samples : %d\n", fMaxRasterSamples);
bsalomondc47ff72015-05-26 12:16:59 -0700188
189 static const char* kBlendEquationSupportNames[] = {
190 "Basic",
191 "Advanced",
192 "Advanced Coherent",
193 };
194 GR_STATIC_ASSERT(0 == kBasic_BlendEquationSupport);
195 GR_STATIC_ASSERT(1 == kAdvanced_BlendEquationSupport);
196 GR_STATIC_ASSERT(2 == kAdvancedCoherent_BlendEquationSupport);
197 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1);
198
199 r.appendf("Blend Equation Support : %s\n",
200 kBlendEquationSupportNames[fBlendEquationSupport]);
201 r.appendf("Map Buffer Support : %s\n",
202 map_flags_to_string(fMapBufferFlags).c_str());
203
204 static const char* kConfigNames[] = {
205 "Unknown", // kUnknown_GrPixelConfig
206 "Alpha8", // kAlpha_8_GrPixelConfig,
207 "Index8", // kIndex_8_GrPixelConfig,
208 "RGB565", // kRGB_565_GrPixelConfig,
209 "RGBA444", // kRGBA_4444_GrPixelConfig,
210 "RGBA8888", // kRGBA_8888_GrPixelConfig,
211 "BGRA8888", // kBGRA_8888_GrPixelConfig,
212 "SRGBA8888",// kSRGBA_8888_GrPixelConfig,
213 "ETC1", // kETC1_GrPixelConfig,
214 "LATC", // kLATC_GrPixelConfig,
215 "R11EAC", // kR11_EAC_GrPixelConfig,
216 "ASTC12x12",// kASTC_12x12_GrPixelConfig,
217 "RGBAFloat",// kRGBA_float_GrPixelConfig
218 "AlphaHalf",// kAlpha_half_GrPixelConfig
219 "RGBAHalf", // kRGBA_half_GrPixelConfig
220 };
221 GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
222 GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
223 GR_STATIC_ASSERT(2 == kIndex_8_GrPixelConfig);
224 GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
225 GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
226 GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
227 GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
228 GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig);
brianosmanc571c002016-03-17 13:01:26 -0700229 GR_STATIC_ASSERT(8 == kETC1_GrPixelConfig);
230 GR_STATIC_ASSERT(9 == kLATC_GrPixelConfig);
231 GR_STATIC_ASSERT(10 == kR11_EAC_GrPixelConfig);
232 GR_STATIC_ASSERT(11 == kASTC_12x12_GrPixelConfig);
233 GR_STATIC_ASSERT(12 == kRGBA_float_GrPixelConfig);
234 GR_STATIC_ASSERT(13 == kAlpha_half_GrPixelConfig);
235 GR_STATIC_ASSERT(14 == kRGBA_half_GrPixelConfig);
bsalomondc47ff72015-05-26 12:16:59 -0700236 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
237
bsalomon41e4384e2016-01-08 09:12:44 -0800238 SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig, false));
239 SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig, true));
bsalomondc47ff72015-05-26 12:16:59 -0700240
241 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
bsalomon41e4384e2016-01-08 09:12:44 -0800242 GrPixelConfig config = static_cast<GrPixelConfig>(i);
bsalomondc47ff72015-05-26 12:16:59 -0700243 r.appendf("%s is renderable: %s, with MSAA: %s\n",
244 kConfigNames[i],
bsalomon41e4384e2016-01-08 09:12:44 -0800245 gNY[this->isConfigRenderable(config, false)],
246 gNY[this->isConfigRenderable(config, true)]);
bsalomondc47ff72015-05-26 12:16:59 -0700247 }
248
bsalomon41e4384e2016-01-08 09:12:44 -0800249 SkASSERT(!this->isConfigTexturable(kUnknown_GrPixelConfig));
bsalomondc47ff72015-05-26 12:16:59 -0700250
251 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
bsalomon41e4384e2016-01-08 09:12:44 -0800252 GrPixelConfig config = static_cast<GrPixelConfig>(i);
bsalomondc47ff72015-05-26 12:16:59 -0700253 r.appendf("%s is uploadable to a texture: %s\n",
254 kConfigNames[i],
bsalomon41e4384e2016-01-08 09:12:44 -0800255 gNY[this->isConfigTexturable(config)]);
bsalomondc47ff72015-05-26 12:16:59 -0700256 }
257
258 return r;
259}