blob: 6a94db2e1ffb59beab477a6249ea7c11bae3ffc4 [file] [log] [blame]
bsalomon682c2692015-05-22 14:01:46 -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#ifndef GrContextOptions_DEFINED
9#define GrContextOptions_DEFINED
10
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkData.h"
12#include "include/core/SkTypes.h"
13#include "include/gpu/GrDriverBugWorkarounds.h"
14#include "include/gpu/GrTypes.h"
15#include "include/private/GrTypesPriv.h"
bsalomon682c2692015-05-22 14:01:46 -070016
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -040017#include <vector>
18
Brian Osman51279982017-08-23 10:12:00 -040019class SkExecutor;
20
Adrienne Walkerab7181d2018-05-14 14:02:03 -070021#if SK_SUPPORT_GPU
Brian Salomonf5cdd9b2019-02-15 09:39:52 -050022struct SK_API GrContextOptions {
Brian Salomon43f8bf02017-10-18 08:33:29 -040023 enum class Enable {
24 /** Forces an option to be disabled. */
25 kNo,
26 /** Forces an option to be enabled. */
27 kYes,
28 /**
29 * Uses Skia's default behavior, which may use runtime properties (e.g. driver version).
30 */
31 kDefault
32 };
33
Brian Osmana66081d2019-09-03 14:59:26 -040034 enum class ShaderCacheStrategy {
35 kSkSL,
36 kBackendSource,
37 kBackendBinary,
38 };
39
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -040040 /**
41 * Abstract class which stores Skia data in a cache that persists between sessions. Currently,
42 * Skia stores compiled shader binaries (only when glProgramBinary / glGetProgramBinary are
43 * supported) when provided a persistent cache, but this may extend to other data in the future.
44 */
Brian Salomonf5cdd9b2019-02-15 09:39:52 -050045 class SK_API PersistentCache {
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -040046 public:
47 virtual ~PersistentCache() {}
48
49 /**
50 * Returns the data for the key if it exists in the cache, otherwise returns null.
51 */
52 virtual sk_sp<SkData> load(const SkData& key) = 0;
53
54 virtual void store(const SkData& key, const SkData& data) = 0;
55 };
56
Brian Osman5e7fbfd2019-05-03 13:13:35 -040057 /**
58 * Abstract class to report errors when compiling shaders. If fShaderErrorHandler is present,
59 * it will be called to report any compilation failures. Otherwise, failures will be reported
60 * via SkDebugf and asserts.
61 */
62 class SK_API ShaderErrorHandler {
63 public:
64 virtual ~ShaderErrorHandler() {}
65 virtual void compileError(const char* shader, const char* errors) = 0;
66 };
67
Mike Kleinfc6c37b2016-09-27 09:34:10 -040068 GrContextOptions() {}
bsalomon682c2692015-05-22 14:01:46 -070069
bsalomon682c2692015-05-22 14:01:46 -070070 // Suppress prints for the GrContext.
bsalomon6b2552f2016-09-15 13:50:26 -070071 bool fSuppressPrints = false;
bsalomon4ee6bd82015-05-27 13:23:23 -070072
73 /** Overrides: These options override feature detection using backend API queries. These
74 overrides can only reduce the feature set or limits, never increase them beyond the
75 detected values. */
76
bsalomon6b2552f2016-09-15 13:50:26 -070077 int fMaxTextureSizeOverride = SK_MaxS32;
78
joshualitte5b74c62015-06-01 14:17:47 -070079 /** the threshold in bytes above which we will use a buffer mapping API to map vertex and index
80 buffers to CPU memory in order to update them. A value of -1 means the GrContext should
81 deduce the optimal value for this platform. */
bsalomon6b2552f2016-09-15 13:50:26 -070082 int fBufferMapThreshold = -1;
joshualitt83bc2292015-06-18 14:18:02 -070083
Brian Osman51279982017-08-23 10:12:00 -040084 /**
85 * Executor to handle threaded work within Ganesh. If this is nullptr, then all work will be
86 * done serially on the main thread. To have worker threads assist with various tasks, set this
87 * to a valid SkExecutor instance. Currently, used for software path rendering, but may be used
88 * for other tasks.
89 */
90 SkExecutor* fExecutor = nullptr;
91
brianosman9a3fbf72016-06-09 13:11:08 -070092 /** Construct mipmaps manually, via repeated downsampling draw-calls. This is used when
93 the driver's implementation (glGenerateMipmap) contains bugs. This requires mipmap
94 level and LOD control (ie desktop or ES3). */
bsalomon6b2552f2016-09-15 13:50:26 -070095 bool fDoManualMipmapping = false;
csmartdaltone0d36292016-07-29 08:14:20 -070096
bsalomon39ef7fb2016-09-21 11:16:05 -070097 /**
Chris Daltona8fbeba2019-03-30 00:31:23 -060098 * Disables the use of coverage counting shortcuts to render paths. Coverage counting can cause
99 * artifacts along shared edges if care isn't taken to ensure both contours wind in the same
100 * direction.
Chris Daltonef125092018-06-26 18:16:47 -0600101 */
Chris Daltonf7748182019-03-18 16:22:30 +0000102 // FIXME: Once this is removed from Chrome and Android, rename to fEnable"".
103 bool fDisableCoverageCountingPaths = true;
Chris Daltonef125092018-06-26 18:16:47 -0600104
105 /**
Brian Osmanb350ae22017-08-29 16:15:39 -0400106 * Disables distance field rendering for paths. Distance field computation can be expensive,
107 * and yields no benefit if a path is not rendered multiple times with different transforms.
108 */
109 bool fDisableDistanceFieldPaths = false;
110
111 /**
bsalomon39ef7fb2016-09-21 11:16:05 -0700112 * If true this allows path mask textures to be cached. This is only really useful if paths
113 * are commonly rendered at the same scale and fractional translation.
114 */
Brian Osman36dcd7f2017-09-27 15:31:29 -0400115 bool fAllowPathMaskCaching = true;
bsalomon39ef7fb2016-09-21 11:16:05 -0700116
117 /**
Brian Osman46da1cc2017-02-14 14:15:48 -0500118 * If true, the GPU will not be used to perform YUV -> RGB conversion when generating
119 * textures from codec-backed images.
120 */
121 bool fDisableGpuYUVConversion = false;
csmartdalton008b9d82017-02-22 12:00:42 -0700122
123 /**
Brian Osman195c05b2017-08-30 15:14:04 -0400124 * The maximum size of cache textures used for Skia's Glyph cache.
125 */
Khushalfa8ff092018-06-06 17:46:38 -0700126 size_t fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4;
Brian Osman195c05b2017-08-30 15:14:04 -0400127
128 /**
Brian Salomonaf597482017-11-07 16:23:34 -0500129 * Below this threshold size in device space distance field fonts won't be used. Distance field
130 * fonts don't support hinting which is more important at smaller sizes. A negative value means
131 * use the default threshold.
132 */
133 float fMinDistanceFieldFontSize = -1.f;
134
135 /**
136 * Above this threshold size in device space glyphs are drawn as individual paths. A negative
137 * value means use the default threshold.
138 */
139 float fGlyphsAsPathsFontSize = -1.f;
140
141 /**
Brian Salomon9f545bc2017-11-06 10:36:57 -0500142 * Can the glyph atlas use multiple textures. If allowed, the each texture's size is bound by
143 * fGlypheCacheTextureMaximumBytes.
144 */
145 Enable fAllowMultipleGlyphCacheTextures = Enable::kDefault;
146
147 /**
Brian Osman195c05b2017-08-30 15:14:04 -0400148 * Bugs on certain drivers cause stencil buffers to leak. This flag causes Skia to avoid
149 * allocating stencil buffers and use alternate rasterization paths, avoiding the leak.
150 */
151 bool fAvoidStencilBuffers = false;
152
Brian Salomon43f8bf02017-10-18 08:33:29 -0400153 /**
Brian Osman8a83ca42018-02-12 14:32:17 -0500154 * If true, texture fetches from mip-mapped textures will be biased to read larger MIP levels.
155 * This has the effect of sharpening those textures, at the cost of some aliasing, and possible
156 * performance impact.
157 */
158 bool fSharpenMipmappedTextures = false;
159
160 /**
Michael Ludwiga21d1962019-01-11 15:26:22 -0500161 * Enables driver workaround to use draws instead of HW clears, e.g. glClear on the GL backend.
Brian Salomon43f8bf02017-10-18 08:33:29 -0400162 */
Michael Ludwiga21d1962019-01-11 15:26:22 -0500163 Enable fUseDrawInsteadOfClear = Enable::kDefault;
Brian Salomon43f8bf02017-10-18 08:33:29 -0400164
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400165 /**
Robert Phillipsd425dee2019-04-26 11:12:24 -0400166 * Allow Ganesh to more aggressively reorder operations.
Robert Phillips46acf9d2018-10-09 09:31:40 -0400167 * Eventually this will just be what is done and will not be optional.
168 */
Greg Daniel93138742019-08-22 17:15:39 -0400169 Enable fReduceOpsTaskSplitting = Enable::kDefault;
Robert Phillips46acf9d2018-10-09 09:31:40 -0400170
171 /**
Brian Osman06d37462018-05-08 13:00:42 -0400172 * Some ES3 contexts report the ES2 external image extension, but not the ES3 version.
173 * If support for external images is critical, enabling this option will cause Ganesh to limit
174 * shaders to the ES2 shading language in that situation.
175 */
176 bool fPreferExternalImagesOverES3 = false;
177
178 /**
Brian Salomon01b476a2018-01-23 11:06:41 -0500179 * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers.
180 * This does not affect code path choices that are made for perfomance reasons nor does it
181 * override other GrContextOption settings.
182 */
183 bool fDisableDriverCorrectnessWorkarounds = false;
184
185 /**
Brian Osman172bb442019-09-06 10:16:02 -0400186 * Maximum number of GPU programs or pipelines to keep active in the runtime cache.
187 */
188 int fRuntimeProgramCacheSize = 256;
189
190 /**
Ethan Nicholasd1b2eec2017-11-01 15:45:43 -0400191 * Cache in which to store compiled shader binaries between runs.
192 */
193 PersistentCache* fPersistentCache = nullptr;
194
Brian Salomon28bafb02019-02-15 10:05:06 -0500195 /**
Brian Osmana66081d2019-09-03 14:59:26 -0400196 * This affects the usage of the PersistentCache. We can cache SkSL, backend source (GLSL), or
197 * backend binaries (GL program binaries). By default we cache binaries, but if the driver's
198 * binary loading/storing is believed to have bugs, this can be limited to caching GLSL.
199 * Caching GLSL strings still saves CPU work when a GL program is created.
Brian Salomon28bafb02019-02-15 10:05:06 -0500200 */
Brian Osmana66081d2019-09-03 14:59:26 -0400201 ShaderCacheStrategy fShaderCacheStrategy = ShaderCacheStrategy::kBackendBinary;
Brian Salomon28bafb02019-02-15 10:05:06 -0500202
Brian Osmana66081d2019-09-03 14:59:26 -0400203 // Legacy flag until clients are updated to use fShaderCacheStrategy
204 bool fDisallowGLSLBinaryCaching = false;
205
206 /**
207 * If present, use this object to report shader compilation failures. If not, report failures
208 * via SkDebugf and assert.
209 */
210 ShaderErrorHandler* fShaderErrorHandler = nullptr;
Brian Osman8518f2e2019-05-01 14:13:41 -0400211
Chris Dalton1e6c5b82019-06-17 14:16:49 -0600212 /**
213 * Specifies the number of samples Ganesh should use when performing internal draws with MSAA or
214 * mixed samples (hardware capabilities permitting).
Chris Daltona1638a52019-06-24 11:54:24 -0600215 *
216 * If 0, Ganesh will disable internal code paths that use multisampling.
Chris Dalton1e6c5b82019-06-17 14:16:49 -0600217 */
Chris Daltona1638a52019-06-24 11:54:24 -0600218 int fInternalMultisampleCount = 4;
Chris Dalton1e6c5b82019-06-17 14:16:49 -0600219
Brian Osman195c05b2017-08-30 15:14:04 -0400220#if GR_TEST_UTILS
221 /**
222 * Private options that are only meant for testing within Skia's tools.
223 */
224
225 /**
226 * If non-zero, overrides the maximum size of a tile for sw-backed images and bitmaps rendered
227 * by SkGpuDevice.
228 */
229 int fMaxTileSizeOverride = 0;
230
231 /**
232 * Prevents use of dual source blending, to test that all xfer modes work correctly without it.
233 */
234 bool fSuppressDualSourceBlending = false;
235
236 /**
Chris Dalton040238b2017-12-18 14:22:34 -0700237 * If true, the caps will never support geometry shaders.
238 */
239 bool fSuppressGeometryShaders = false;
240
241 /**
Jim Van Verthfbdc0802017-05-02 16:15:53 -0400242 * Render everything in wireframe
243 */
244 bool fWireframeMode = false;
245
246 /**
Brian Salomona3e29962019-07-16 11:52:08 -0400247 * Enforces clearing of all textures when they're created.
248 */
249 bool fClearAllTextures = false;
250
251 /**
Brian Osman195c05b2017-08-30 15:14:04 -0400252 * Include or exclude specific GPU path renderers.
csmartdalton008b9d82017-02-22 12:00:42 -0700253 */
Chris Daltona8fbeba2019-03-30 00:31:23 -0600254 GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kAll;
Brian Osman195c05b2017-08-30 15:14:04 -0400255#endif
Brian Salomonb5086962017-12-13 10:59:33 -0500256
257#if SK_SUPPORT_ATLAS_TEXT
258 /**
259 * Controls whether distance field glyph vertices always have 3 components even when the view
260 * matrix does not have perspective.
261 */
262 Enable fDistanceFieldGlyphVerticesAlwaysHaveW = Enable::kDefault;
263#endif
Adrienne Walkerab7181d2018-05-14 14:02:03 -0700264
265 GrDriverBugWorkarounds fDriverBugWorkarounds;
bsalomon682c2692015-05-22 14:01:46 -0700266};
Adrienne Walkerab7181d2018-05-14 14:02:03 -0700267#else
268struct GrContextOptions {
269 struct PersistentCache {};
270};
271#endif
bsalomon682c2692015-05-22 14:01:46 -0700272
bsalomon682c2692015-05-22 14:01:46 -0700273#endif