blob: 92c22b5fd2c08ab4a637e4d907042e61fd236a3a [file] [log] [blame]
bsalomondc47ff72015-05-26 12:16:59 -07001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "GrCaps.h"
9#include "GrContextOptions.h"
csmartdalton28341fa2016-08-17 10:00:21 -070010#include "GrWindowRectangles.h"
bsalomondc47ff72015-05-26 12:16:59 -070011
bsalomondc47ff72015-05-26 12:16:59 -070012GrCaps::GrCaps(const GrContextOptions& options) {
13 fMipMapSupport = false;
14 fNPOTTextureTileSupport = false;
brianosmana6359362016-03-21 06:55:37 -070015 fSRGBSupport = false;
brianosman35b784d2016-05-05 11:52:53 -070016 fSRGBWriteControl = false;
bsalomondc47ff72015-05-26 12:16:59 -070017 fTwoSidedStencilSupport = false;
18 fStencilWrapOpsSupport = false;
19 fDiscardRenderTargetSupport = false;
20 fReuseScratchTextures = true;
robertphillips1b8e1b52015-06-24 06:54:10 -070021 fReuseScratchBuffers = true;
bsalomondc47ff72015-05-26 12:16:59 -070022 fGpuTracingSupport = false;
23 fCompressedTexSubImageSupport = false;
24 fOversizedStencilSupport = false;
25 fTextureBarrierSupport = false;
cdaltoneb79eea2016-02-26 10:39:34 -080026 fSampleLocationsSupport = false;
csmartdalton2b5f2cb2016-06-10 14:06:32 -070027 fMultisampleDisableSupport = false;
egdanieleed519e2016-01-15 11:36:18 -080028 fUsesMixedSamples = false;
csmartdalton485a1202016-07-13 10:16:32 -070029 fPreferClientSideDynamicBuffers = false;
egdaniel51c8d402015-08-06 10:54:13 -070030 fFullClearIsFree = false;
bsalomon7dea7b72015-08-19 08:26:51 -070031 fMustClearUploadedBufferData = false;
ethannicholas28ef4452016-03-25 09:26:03 -070032 fSampleShadingSupport = false;
jvanverth84741b32016-09-30 08:39:02 -070033 fFenceSyncSupport = false;
bsalomondc47ff72015-05-26 12:16:59 -070034
35 fUseDrawInsteadOfClear = false;
36
csmartdaltone0d36292016-07-29 08:14:20 -070037 fInstancedSupport = InstancedSupport::kNone;
38
bsalomondc47ff72015-05-26 12:16:59 -070039 fBlendEquationSupport = kBasic_BlendEquationSupport;
cdalton1dd05422015-06-12 09:01:18 -070040 fAdvBlendEqBlacklist = 0;
41
bsalomondc47ff72015-05-26 12:16:59 -070042 fMapBufferFlags = kNone_MapFlags;
43
bsalomon7dbd45d2016-03-23 10:40:53 -070044 fMaxVertexAttributes = 0;
egdanielff1d5472015-09-10 08:37:20 -070045 fMaxRenderTargetSize = 1;
46 fMaxTextureSize = 1;
egdanieleed519e2016-01-15 11:36:18 -080047 fMaxColorSampleCount = 0;
48 fMaxStencilSampleCount = 0;
cdaltonaf8bc7d2016-02-05 09:35:20 -080049 fMaxRasterSamples = 0;
csmartdalton9bc11872016-08-09 12:42:47 -070050 fMaxWindowRectangles = 0;
bsalomondc47ff72015-05-26 12:16:59 -070051
robertphillipscaef3452015-11-11 13:18:11 -080052 fSuppressPrints = options.fSuppressPrints;
53 fImmediateFlush = options.fImmediateMode;
cdalton397536c2016-03-25 12:15:03 -070054 fBufferMapThreshold = options.fBufferMapThreshold;
joshualitt83bc2292015-06-18 14:18:02 -070055 fUseDrawInsteadOfPartialRenderTargetWrite = options.fUseDrawInsteadOfPartialRenderTargetWrite;
bsalomonbabafcc2016-02-16 11:36:47 -080056 fUseDrawInsteadOfAllRenderTargetWrites = false;
csmartdaltone0d36292016-07-29 08:14:20 -070057 fAvoidInstancedDrawsToFPTargets = false;
robertphillips63926682015-08-20 09:39:02 -070058
59 fPreferVRAMUseOverFlushes = true;
bsalomondc47ff72015-05-26 12:16:59 -070060}
61
bsalomon4ee6bd82015-05-27 13:23:23 -070062void GrCaps::applyOptionsOverrides(const GrContextOptions& options) {
csmartdalton28341fa2016-08-17 10:00:21 -070063 this->onApplyOptionsOverrides(options);
bsalomon4ee6bd82015-05-27 13:23:23 -070064 fMaxTextureSize = SkTMin(fMaxTextureSize, options.fMaxTextureSizeOverride);
bsalomon8c07b7a2015-11-02 11:36:52 -080065 // If the max tile override is zero, it means we should use the max texture size.
66 if (!options.fMaxTileSizeOverride || options.fMaxTileSizeOverride > fMaxTextureSize) {
67 fMaxTileSize = fMaxTextureSize;
68 } else {
69 fMaxTileSize = options.fMaxTileSizeOverride;
70 }
csmartdalton28341fa2016-08-17 10:00:21 -070071 if (fMaxWindowRectangles > GrWindowRectangles::kMaxWindows) {
csmartdalton7535f412016-08-23 06:51:00 -070072 SkDebugf("WARNING: capping window rectangles at %i. HW advertises support for %i.\n",
73 GrWindowRectangles::kMaxWindows, fMaxWindowRectangles);
csmartdalton28341fa2016-08-17 10:00:21 -070074 fMaxWindowRectangles = GrWindowRectangles::kMaxWindows;
75 }
bsalomon4ee6bd82015-05-27 13:23:23 -070076}
77
bsalomondc47ff72015-05-26 12:16:59 -070078static SkString map_flags_to_string(uint32_t flags) {
79 SkString str;
80 if (GrCaps::kNone_MapFlags == flags) {
81 str = "none";
82 } else {
83 SkASSERT(GrCaps::kCanMap_MapFlag & flags);
84 SkDEBUGCODE(flags &= ~GrCaps::kCanMap_MapFlag);
85 str = "can_map";
86
87 if (GrCaps::kSubset_MapFlag & flags) {
88 str.append(" partial");
89 } else {
90 str.append(" full");
91 }
92 SkDEBUGCODE(flags &= ~GrCaps::kSubset_MapFlag);
93 }
94 SkASSERT(0 == flags); // Make sure we handled all the flags.
95 return str;
96}
97
98SkString GrCaps::dump() const {
99 SkString r;
100 static const char* gNY[] = {"NO", "YES"};
101 r.appendf("MIP Map Support : %s\n", gNY[fMipMapSupport]);
102 r.appendf("NPOT Texture Tile Support : %s\n", gNY[fNPOTTextureTileSupport]);
brianosmana6359362016-03-21 06:55:37 -0700103 r.appendf("sRGB Support : %s\n", gNY[fSRGBSupport]);
brianosman35b784d2016-05-05 11:52:53 -0700104 r.appendf("sRGB Write Control : %s\n", gNY[fSRGBWriteControl]);
bsalomondc47ff72015-05-26 12:16:59 -0700105 r.appendf("Two Sided Stencil Support : %s\n", gNY[fTwoSidedStencilSupport]);
106 r.appendf("Stencil Wrap Ops Support : %s\n", gNY[fStencilWrapOpsSupport]);
107 r.appendf("Discard Render Target Support : %s\n", gNY[fDiscardRenderTargetSupport]);
108 r.appendf("Reuse Scratch Textures : %s\n", gNY[fReuseScratchTextures]);
robertphillips1b8e1b52015-06-24 06:54:10 -0700109 r.appendf("Reuse Scratch Buffers : %s\n", gNY[fReuseScratchBuffers]);
bsalomondc47ff72015-05-26 12:16:59 -0700110 r.appendf("Gpu Tracing Support : %s\n", gNY[fGpuTracingSupport]);
111 r.appendf("Compressed Update Support : %s\n", gNY[fCompressedTexSubImageSupport]);
112 r.appendf("Oversized Stencil Support : %s\n", gNY[fOversizedStencilSupport]);
113 r.appendf("Texture Barrier Support : %s\n", gNY[fTextureBarrierSupport]);
cdaltoneb79eea2016-02-26 10:39:34 -0800114 r.appendf("Sample Locations Support : %s\n", gNY[fSampleLocationsSupport]);
csmartdalton2b5f2cb2016-06-10 14:06:32 -0700115 r.appendf("Multisample disable support : %s\n", gNY[fMultisampleDisableSupport]);
egdanieleed519e2016-01-15 11:36:18 -0800116 r.appendf("Uses Mixed Samples : %s\n", gNY[fUsesMixedSamples]);
csmartdalton485a1202016-07-13 10:16:32 -0700117 r.appendf("Prefer client-side dynamic buffers : %s\n", gNY[fPreferClientSideDynamicBuffers]);
egdaniel51c8d402015-08-06 10:54:13 -0700118 r.appendf("Full screen clear is free : %s\n", gNY[fFullClearIsFree]);
bsalomon7dea7b72015-08-19 08:26:51 -0700119 r.appendf("Must clear buffer memory : %s\n", gNY[fMustClearUploadedBufferData]);
jvanverth84741b32016-09-30 08:39:02 -0700120 r.appendf("Sample shading support : %s\n", gNY[fSampleShadingSupport]);
121 r.appendf("Fence sync support : %s\n", gNY[fFenceSyncSupport]);
122
bsalomondc47ff72015-05-26 12:16:59 -0700123 r.appendf("Draw Instead of Clear [workaround] : %s\n", gNY[fUseDrawInsteadOfClear]);
joshualitt83bc2292015-06-18 14:18:02 -0700124 r.appendf("Draw Instead of TexSubImage [workaround] : %s\n",
125 gNY[fUseDrawInsteadOfPartialRenderTargetWrite]);
robertphillips63926682015-08-20 09:39:02 -0700126 r.appendf("Prefer VRAM Use over flushes [workaround] : %s\n", gNY[fPreferVRAMUseOverFlushes]);
127
cdalton1dd05422015-06-12 09:01:18 -0700128 if (this->advancedBlendEquationSupport()) {
129 r.appendf("Advanced Blend Equation Blacklist : 0x%x\n", fAdvBlendEqBlacklist);
130 }
bsalomondc47ff72015-05-26 12:16:59 -0700131
bsalomon7dbd45d2016-03-23 10:40:53 -0700132 r.appendf("Max Vertex Attributes : %d\n", fMaxVertexAttributes);
bsalomondc47ff72015-05-26 12:16:59 -0700133 r.appendf("Max Texture Size : %d\n", fMaxTextureSize);
bsalomondc47ff72015-05-26 12:16:59 -0700134 r.appendf("Max Render Target Size : %d\n", fMaxRenderTargetSize);
egdanieleed519e2016-01-15 11:36:18 -0800135 r.appendf("Max Color Sample Count : %d\n", fMaxColorSampleCount);
136 r.appendf("Max Stencil Sample Count : %d\n", fMaxStencilSampleCount);
cdaltonaf8bc7d2016-02-05 09:35:20 -0800137 r.appendf("Max Raster Samples : %d\n", fMaxRasterSamples);
csmartdalton9bc11872016-08-09 12:42:47 -0700138 r.appendf("Max Window Rectangles : %d\n", fMaxWindowRectangles);
bsalomondc47ff72015-05-26 12:16:59 -0700139
csmartdaltone0d36292016-07-29 08:14:20 -0700140 static const char* kInstancedSupportNames[] = {
141 "None",
142 "Basic",
143 "Multisampled",
144 "Mixed Sampled",
145 };
146 GR_STATIC_ASSERT(0 == (int)InstancedSupport::kNone);
147 GR_STATIC_ASSERT(1 == (int)InstancedSupport::kBasic);
148 GR_STATIC_ASSERT(2 == (int)InstancedSupport::kMultisampled);
149 GR_STATIC_ASSERT(3 == (int)InstancedSupport::kMixedSampled);
150 GR_STATIC_ASSERT(4 == SK_ARRAY_COUNT(kInstancedSupportNames));
151
152 r.appendf("Instanced Support : %s\n",
153 kInstancedSupportNames[(int)fInstancedSupport]);
154
bsalomondc47ff72015-05-26 12:16:59 -0700155 static const char* kBlendEquationSupportNames[] = {
156 "Basic",
157 "Advanced",
158 "Advanced Coherent",
159 };
160 GR_STATIC_ASSERT(0 == kBasic_BlendEquationSupport);
161 GR_STATIC_ASSERT(1 == kAdvanced_BlendEquationSupport);
162 GR_STATIC_ASSERT(2 == kAdvancedCoherent_BlendEquationSupport);
163 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kBlendEquationSupportNames) == kLast_BlendEquationSupport + 1);
164
165 r.appendf("Blend Equation Support : %s\n",
166 kBlendEquationSupportNames[fBlendEquationSupport]);
167 r.appendf("Map Buffer Support : %s\n",
168 map_flags_to_string(fMapBufferFlags).c_str());
169
170 static const char* kConfigNames[] = {
Brian Salomonbf7b6202016-11-11 16:08:03 -0500171 "Unknown", // kUnknown_GrPixelConfig
172 "Alpha8", // kAlpha_8_GrPixelConfig,
Brian Osman986563b2017-01-10 14:20:02 -0500173 "Gray8", // kGray_8_GrPixelConfig,
Brian Salomonbf7b6202016-11-11 16:08:03 -0500174 "RGB565", // kRGB_565_GrPixelConfig,
175 "RGBA444", // kRGBA_4444_GrPixelConfig,
176 "RGBA8888", // kRGBA_8888_GrPixelConfig,
177 "BGRA8888", // kBGRA_8888_GrPixelConfig,
178 "SRGBA8888", // kSRGBA_8888_GrPixelConfig,
179 "SBGRA8888", // kSBGRA_8888_GrPixelConfig,
180 "RGBA8888_sint", // kRGBA_8888_sint_GrPixelConfig,
181 "ETC1", // kETC1_GrPixelConfig,
182 "LATC", // kLATC_GrPixelConfig,
183 "R11EAC", // kR11_EAC_GrPixelConfig,
184 "ASTC12x12", // kASTC_12x12_GrPixelConfig,
185 "RGBAFloat", // kRGBA_float_GrPixelConfig
186 "AlphaHalf", // kAlpha_half_GrPixelConfig
187 "RGBAHalf", // kRGBA_half_GrPixelConfig
bsalomondc47ff72015-05-26 12:16:59 -0700188 };
189 GR_STATIC_ASSERT(0 == kUnknown_GrPixelConfig);
190 GR_STATIC_ASSERT(1 == kAlpha_8_GrPixelConfig);
Brian Osman986563b2017-01-10 14:20:02 -0500191 GR_STATIC_ASSERT(2 == kGray_8_GrPixelConfig);
Brian Osmand0be1ef2017-01-11 16:57:15 -0500192 GR_STATIC_ASSERT(3 == kRGB_565_GrPixelConfig);
193 GR_STATIC_ASSERT(4 == kRGBA_4444_GrPixelConfig);
194 GR_STATIC_ASSERT(5 == kRGBA_8888_GrPixelConfig);
195 GR_STATIC_ASSERT(6 == kBGRA_8888_GrPixelConfig);
196 GR_STATIC_ASSERT(7 == kSRGBA_8888_GrPixelConfig);
197 GR_STATIC_ASSERT(8 == kSBGRA_8888_GrPixelConfig);
198 GR_STATIC_ASSERT(9 == kRGBA_8888_sint_GrPixelConfig);
199 GR_STATIC_ASSERT(10 == kETC1_GrPixelConfig);
200 GR_STATIC_ASSERT(11 == kLATC_GrPixelConfig);
201 GR_STATIC_ASSERT(12 == kR11_EAC_GrPixelConfig);
202 GR_STATIC_ASSERT(13 == kASTC_12x12_GrPixelConfig);
203 GR_STATIC_ASSERT(14 == kRGBA_float_GrPixelConfig);
204 GR_STATIC_ASSERT(15 == kAlpha_half_GrPixelConfig);
205 GR_STATIC_ASSERT(16 == kRGBA_half_GrPixelConfig);
bsalomondc47ff72015-05-26 12:16:59 -0700206 GR_STATIC_ASSERT(SK_ARRAY_COUNT(kConfigNames) == kGrPixelConfigCnt);
207
bsalomon41e4384e2016-01-08 09:12:44 -0800208 SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig, false));
209 SkASSERT(!this->isConfigRenderable(kUnknown_GrPixelConfig, true));
bsalomondc47ff72015-05-26 12:16:59 -0700210
211 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
bsalomon41e4384e2016-01-08 09:12:44 -0800212 GrPixelConfig config = static_cast<GrPixelConfig>(i);
bsalomondc47ff72015-05-26 12:16:59 -0700213 r.appendf("%s is renderable: %s, with MSAA: %s\n",
214 kConfigNames[i],
bsalomon41e4384e2016-01-08 09:12:44 -0800215 gNY[this->isConfigRenderable(config, false)],
216 gNY[this->isConfigRenderable(config, true)]);
bsalomondc47ff72015-05-26 12:16:59 -0700217 }
218
bsalomon41e4384e2016-01-08 09:12:44 -0800219 SkASSERT(!this->isConfigTexturable(kUnknown_GrPixelConfig));
bsalomondc47ff72015-05-26 12:16:59 -0700220
221 for (size_t i = 1; i < SK_ARRAY_COUNT(kConfigNames); ++i) {
bsalomon41e4384e2016-01-08 09:12:44 -0800222 GrPixelConfig config = static_cast<GrPixelConfig>(i);
bsalomondc47ff72015-05-26 12:16:59 -0700223 r.appendf("%s is uploadable to a texture: %s\n",
224 kConfigNames[i],
bsalomon41e4384e2016-01-08 09:12:44 -0800225 gNY[this->isConfigTexturable(config)]);
bsalomondc47ff72015-05-26 12:16:59 -0700226 }
227
228 return r;
229}