| 1 |
/* |
| 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 |
|
| 11 |
#include "include/core/SkData.h" |
| 12 |
#include "include/core/SkString.h" |
| 13 |
#include "include/core/SkTypes.h" |
| 14 |
#include "include/gpu/ShaderErrorHandler.h" |
| 15 |
#include "include/gpu/ganesh/GrDriverBugWorkarounds.h" |
| 16 |
#include "include/gpu/ganesh/GrTypes.h" |
| 17 |
#include "include/private/gpu/ganesh/GrTypesPriv.h" |
| 18 |
|
| 19 |
#include <optional> |
| 20 |
#include <vector> |
| 21 |
|
| 22 |
class SkExecutor; |
| 23 |
|
| 24 |
struct SK_API GrContextOptions { |
| 25 |
enum class Enable { |
| 26 |
/** Forces an option to be disabled. */ |
| 27 |
kNo, |
| 28 |
/** Forces an option to be enabled. */ |
| 29 |
kYes, |
| 30 |
/** |
| 31 |
* Uses Skia's default behavior, which may use runtime properties (e.g. driver version). |
| 32 |
*/ |
| 33 |
kDefault |
| 34 |
}; |
| 35 |
|
| 36 |
enum class ShaderCacheStrategy { |
| 37 |
kSkSL, |
| 38 |
kBackendSource, |
| 39 |
kBackendBinary, |
| 40 |
}; |
| 41 |
|
| 42 |
/** |
| 43 |
* Abstract class which stores Skia data in a cache that persists between sessions. Currently, |
| 44 |
* Skia stores compiled shader binaries (only when glProgramBinary / glGetProgramBinary are |
| 45 |
* supported) when provided a persistent cache, but this may extend to other data in the future. |
| 46 |
*/ |
| 47 |
class SK_API PersistentCache { |
| 48 |
public: |
| 49 |
virtual ~PersistentCache() = default; |
| 50 |
|
| 51 |
/** |
| 52 |
* Returns the data for the key if it exists in the cache, otherwise returns null. |
| 53 |
*/ |
| 54 |
virtual sk_sp<SkData> load(const SkData& key) = 0; |
| 55 |
|
| 56 |
// Placeholder until all clients override the 3-parameter store(), then remove this, and |
| 57 |
// make that version pure virtual. |
| 58 |
virtual void store(const SkData& /*key*/, const SkData& /*data*/) { SkASSERT(false); } |
| 59 |
|
| 60 |
/** |
| 61 |
* Stores data in the cache, indexed by key. description provides a human-readable |
| 62 |
* version of the key. |
| 63 |
*/ |
| 64 |
virtual void store(const SkData& key, const SkData& data, const SkString& /*description*/) { |
| 65 |
this->store(key, data); |
| 66 |
} |
| 67 |
|
| 68 |
protected: |
| 69 |
PersistentCache() = default; |
| 70 |
PersistentCache(const PersistentCache&) = delete; |
| 71 |
PersistentCache& operator=(const PersistentCache&) = delete; |
| 72 |
}; |
| 73 |
|
| 74 |
using ShaderErrorHandler = skgpu::ShaderErrorHandler; |
| 75 |
|
| 76 |
GrContextOptions() {} |
| 77 |
|
| 78 |
/** |
| 79 |
* Optional callback that can be passed into the GrDirectContext which will be called when the |
| 80 |
* GrDirectContext is about to be destroyed. When this call is made, it will be safe for the |
| 81 |
* client to delete the GPU backend context that is backing the GrDirectContext. The |
| 82 |
* GrDirectContextDestroyedContext will be passed back to the client in the callback. |
| 83 |
*/ |
| 84 |
GrDirectContextDestroyedContext fContextDeleteContext = nullptr; |
| 85 |
GrDirectContextDestroyedProc fContextDeleteProc = nullptr; |
| 86 |
|
| 87 |
/** |
| 88 |
* Executor to handle threaded work within Ganesh. If this is nullptr, then all work will be |
| 89 |
* done serially on the main thread. To have worker threads assist with various tasks, set this |
| 90 |
* to a valid SkExecutor instance. Currently, used for software path rendering, but may be used |
| 91 |
* for other tasks. |
| 92 |
*/ |
| 93 |
SkExecutor* fExecutor = nullptr; |
| 94 |
|
| 95 |
/** |
| 96 |
* Cache in which to store compiled shader binaries between runs. |
| 97 |
*/ |
| 98 |
PersistentCache* fPersistentCache = nullptr; |
| 99 |
|
| 100 |
/** |
| 101 |
* If present, use this object to report shader compilation failures. If not, report failures |
| 102 |
* via SkDebugf and assert. |
| 103 |
*/ |
| 104 |
ShaderErrorHandler* fShaderErrorHandler = nullptr; |
| 105 |
|
| 106 |
/** Default minimum size to use when allocating buffers for uploading data to textures. The |
| 107 |
larger the value the more uploads can be packed into one buffer, but at the cost of |
| 108 |
more gpu memory allocated that may not be used. Uploads larger than the minimum will still |
| 109 |
work by allocating a dedicated buffer. */ |
| 110 |
size_t fMinimumStagingBufferSize = 64 * 1024; |
| 111 |
|
| 112 |
/** |
| 113 |
* The maximum size of cache textures used for Skia's Glyph cache. |
| 114 |
*/ |
| 115 |
size_t fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4; |
| 116 |
|
| 117 |
/** |
| 118 |
* Controls whether we check for GL errors after functions that allocate resources (e.g. |
| 119 |
* glTexImage2D), at the end of a GPU submission, or checking framebuffer completeness. The |
| 120 |
* results of shader compilation and program linking are always checked, regardless of this |
| 121 |
* option. Ignored on backends other than GL. |
| 122 |
*/ |
| 123 |
Enable fSkipGLErrorChecks = Enable::kDefault; |
| 124 |
|
| 125 |
/** |
| 126 |
* Can the glyph atlas use multiple textures. If allowed, the each texture's size is bound by |
| 127 |
* fGlypheCacheTextureMaximumBytes. |
| 128 |
*/ |
| 129 |
Enable fAllowMultipleGlyphCacheTextures = Enable::kDefault; |
| 130 |
|
| 131 |
/** |
| 132 |
* Enables driver workaround to use draws instead of HW clears, e.g. glClear on the GL backend. |
| 133 |
*/ |
| 134 |
Enable fUseDrawInsteadOfClear = Enable::kDefault; |
| 135 |
|
| 136 |
/** |
| 137 |
* Allow Ganesh to more aggressively reorder operations to reduce the number of render passes. |
| 138 |
* Offscreen draws will be done upfront instead of interrupting the main render pass when |
| 139 |
* possible. May increase VRAM usage, but still observes the resource cache limit. |
| 140 |
* Enabled by default. |
| 141 |
*/ |
| 142 |
Enable fReduceOpsTaskSplitting = Enable::kDefault; |
| 143 |
|
| 144 |
/** |
| 145 |
* This affects the usage of the PersistentCache. We can cache SkSL, backend source (GLSL), or |
| 146 |
* backend binaries (GL program binaries). By default we cache binaries, but if the driver's |
| 147 |
* binary loading/storing is believed to have bugs, this can be limited to caching GLSL. |
| 148 |
* Caching GLSL strings still saves CPU work when a GL program is created. |
| 149 |
*/ |
| 150 |
ShaderCacheStrategy fShaderCacheStrategy = ShaderCacheStrategy::kBackendBinary; |
| 151 |
|
| 152 |
/** Overrides: These options override feature detection using backend API queries. These |
| 153 |
overrides can only reduce the feature set or limits, never increase them beyond the |
| 154 |
detected values. */ |
| 155 |
|
| 156 |
int fMaxTextureSizeOverride = SK_MaxS32; |
| 157 |
|
| 158 |
/** the threshold in bytes above which we will use a buffer mapping API to map vertex and index |
| 159 |
buffers to CPU memory in order to update them. A value of -1 means the GrContext should |
| 160 |
deduce the optimal value for this platform. */ |
| 161 |
int fBufferMapThreshold = -1; |
| 162 |
|
| 163 |
/** |
| 164 |
* Maximum number of GPU programs or pipelines to keep active in the runtime cache. |
| 165 |
*/ |
| 166 |
int fRuntimeProgramCacheSize = 256; |
| 167 |
|
| 168 |
/** |
| 169 |
* Specifies the number of samples Ganesh should use when performing internal draws with MSAA |
| 170 |
* (hardware capabilities permitting). |
| 171 |
* |
| 172 |
* If 0, Ganesh will disable internal code paths that use multisampling. |
| 173 |
*/ |
| 174 |
int fInternalMultisampleCount = 4; |
| 175 |
|
| 176 |
/** |
| 177 |
* In Skia's vulkan backend a single GrContext submit equates to the submission of a single |
| 178 |
* primary command buffer to the VkQueue. This value specifies how many vulkan secondary command |
| 179 |
* buffers we will cache for reuse on a given primary command buffer. A single submit may use |
| 180 |
* more than this many secondary command buffers, but after the primary command buffer is |
| 181 |
* finished on the GPU it will only hold on to this many secondary command buffers for reuse. |
| 182 |
* |
| 183 |
* A value of -1 means we will pick a limit value internally. |
| 184 |
*/ |
| 185 |
int fMaxCachedVulkanSecondaryCommandBuffers = -1; |
| 186 |
|
| 187 |
/** |
| 188 |
* Below this threshold size in device space distance field fonts won't be used. Distance field |
| 189 |
* fonts don't support hinting which is more important at smaller sizes. |
| 190 |
*/ |
| 191 |
float fMinDistanceFieldFontSize = 18; |
| 192 |
|
| 193 |
/** |
| 194 |
* Above this threshold size in device space glyphs are drawn as individual paths. |
| 195 |
*/ |
| 196 |
#if defined(SK_BUILD_FOR_ANDROID) |
| 197 |
float fGlyphsAsPathsFontSize = 384; |
| 198 |
#elif defined(SK_BUILD_FOR_MAC) |
| 199 |
float fGlyphsAsPathsFontSize = 256; |
| 200 |
#else |
| 201 |
float fGlyphsAsPathsFontSize = 324; |
| 202 |
#endif |
| 203 |
|
| 204 |
GrDriverBugWorkarounds fDriverBugWorkarounds; |
| 205 |
|
| 206 |
/** Construct mipmaps manually, via repeated downsampling draw-calls. This is used when |
| 207 |
the driver's implementation (glGenerateMipmap) contains bugs. This requires mipmap |
| 208 |
level control (ie desktop or ES3). */ |
| 209 |
bool fDoManualMipmapping = false; |
| 210 |
|
| 211 |
/** |
| 212 |
* Disables the use of coverage counting shortcuts to render paths. Coverage counting can cause |
| 213 |
* artifacts along shared edges if care isn't taken to ensure both contours wind in the same |
| 214 |
* direction. |
| 215 |
*/ |
| 216 |
// FIXME: Once this is removed from Chrome and Android, rename to fEnable"". |
| 217 |
bool fDisableCoverageCountingPaths = true; |
| 218 |
|
| 219 |
/** |
| 220 |
* Disables distance field rendering for paths. Distance field computation can be expensive, |
| 221 |
* and yields no benefit if a path is not rendered multiple times with different transforms. |
| 222 |
*/ |
| 223 |
bool fDisableDistanceFieldPaths = false; |
| 224 |
|
| 225 |
/** |
| 226 |
* If true this allows path mask textures to be cached. This is only really useful if paths |
| 227 |
* are commonly rendered at the same scale and fractional translation. |
| 228 |
*/ |
| 229 |
bool fAllowPathMaskCaching = true; |
| 230 |
|
| 231 |
/** |
| 232 |
* If true, the GPU will not be used to perform YUV -> RGB conversion when generating |
| 233 |
* textures from codec-backed images. |
| 234 |
*/ |
| 235 |
bool fDisableGpuYUVConversion = false; |
| 236 |
|
| 237 |
/** |
| 238 |
* Bugs on certain drivers cause stencil buffers to leak. This flag causes Skia to avoid |
| 239 |
* allocating stencil buffers and use alternate rasterization paths, avoiding the leak. |
| 240 |
*/ |
| 241 |
bool fAvoidStencilBuffers = false; |
| 242 |
|
| 243 |
/** |
| 244 |
* If true, texture fetches from mip-mapped textures will be biased to read larger MIP levels. |
| 245 |
* This has the effect of sharpening those textures, at the cost of some aliasing, and possible |
| 246 |
* performance impact. |
| 247 |
*/ |
| 248 |
bool fSharpenMipmappedTextures = true; |
| 249 |
|
| 250 |
/** |
| 251 |
* Some ES3 contexts report the ES2 external image extension, but not the ES3 version. |
| 252 |
* If support for external images is critical, enabling this option will cause Ganesh to limit |
| 253 |
* shaders to the ES2 shading language in that situation. |
| 254 |
*/ |
| 255 |
bool fPreferExternalImagesOverES3 = false; |
| 256 |
|
| 257 |
/** |
| 258 |
* Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers. |
| 259 |
* This does not affect code path choices that are made for perfomance reasons nor does it |
| 260 |
* override other GrContextOption settings. |
| 261 |
*/ |
| 262 |
bool fDisableDriverCorrectnessWorkarounds = false; |
| 263 |
|
| 264 |
/** |
| 265 |
* If true, the caps will never support mipmaps. |
| 266 |
*/ |
| 267 |
bool fSuppressMipmapSupport = false; |
| 268 |
|
| 269 |
/** |
| 270 |
* If true, the TessellationPathRenderer will not be used for path rendering. |
| 271 |
* If false, will fallback to any driver workarounds, if set. |
| 272 |
*/ |
| 273 |
bool fDisableTessellationPathRenderer = false; |
| 274 |
|
| 275 |
/** |
| 276 |
* If true, and if supported, enables hardware tessellation in the caps. |
| 277 |
* DEPRECATED: This value is ignored; experimental hardware tessellation is always disabled. |
| 278 |
*/ |
| 279 |
bool fEnableExperimentalHardwareTessellation = false; |
| 280 |
|
| 281 |
/** |
| 282 |
* If true, then add 1 pixel padding to all glyph masks in the atlas to support bi-lerp |
| 283 |
* rendering of all glyphs. This must be set to true to use Slugs. |
| 284 |
*/ |
| 285 |
bool fSupportBilerpFromGlyphAtlas = false; |
| 286 |
|
| 287 |
/** |
| 288 |
* Uses a reduced variety of shaders. May perform less optimally in steady state but can reduce |
| 289 |
* jank due to shader compilations. |
| 290 |
*/ |
| 291 |
bool fReducedShaderVariations = false; |
| 292 |
|
| 293 |
/** |
| 294 |
* If true, then allow to enable MSAA on new Intel GPUs. |
| 295 |
*/ |
| 296 |
bool fAllowMSAAOnNewIntel = false; |
| 297 |
|
| 298 |
/** |
| 299 |
* Currently on ARM Android we disable the use of GL TexStorage because of memory regressions. |
| 300 |
* However, some clients may still want to use TexStorage. For example, TexStorage support is |
| 301 |
* required for creating protected textures. |
| 302 |
* |
| 303 |
* This flag has no impact on non GL backends. |
| 304 |
*/ |
| 305 |
bool fAlwaysUseTexStorageWhenAvailable = false; |
| 306 |
|
| 307 |
// Suppress prints for the GrContext. |
| 308 |
bool fSuppressPrints = false; |
| 309 |
|
| 310 |
#if defined(GPU_TEST_UTILS) |
| 311 |
/** |
| 312 |
* Private options that are only meant for testing within Skia's tools. |
| 313 |
*/ |
| 314 |
|
| 315 |
/** |
| 316 |
* Include or exclude specific GPU path renderers. |
| 317 |
*/ |
| 318 |
GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kDefault; |
| 319 |
|
| 320 |
/** |
| 321 |
* Specify the GPU resource cache limit. Equivalent to calling `setResourceCacheLimit` on the |
| 322 |
* context at construction time. |
| 323 |
* |
| 324 |
* A value of -1 means use the default limit value. |
| 325 |
*/ |
| 326 |
int fResourceCacheLimitOverride = -1; |
| 327 |
|
| 328 |
/** |
| 329 |
* Maximum width and height of internal texture atlases. |
| 330 |
*/ |
| 331 |
int fMaxTextureAtlasSize = 2048; |
| 332 |
|
| 333 |
/** |
| 334 |
* Testing-only mode to exercise allocation failures in the flush-time callback objects. |
| 335 |
* For now it only simulates allocation failure during the preFlush callback. |
| 336 |
*/ |
| 337 |
bool fFailFlushTimeCallbacks = false; |
| 338 |
|
| 339 |
/** |
| 340 |
* Prevents use of dual source blending, to test that all xfer modes work correctly without it. |
| 341 |
*/ |
| 342 |
bool fSuppressDualSourceBlending = false; |
| 343 |
|
| 344 |
/** |
| 345 |
* Prevents the use of non-coefficient-based blend equations, for testing dst reads, barriers, |
| 346 |
* and in-shader blending. |
| 347 |
*/ |
| 348 |
bool fSuppressAdvancedBlendEquations = false; |
| 349 |
|
| 350 |
/** |
| 351 |
* Prevents the use of framebuffer fetches, for testing dst reads and texture barriers. |
| 352 |
*/ |
| 353 |
bool fSuppressFramebufferFetch = false; |
| 354 |
|
| 355 |
/** |
| 356 |
* If true, then all paths are processed as if "setIsVolatile" had been called. |
| 357 |
*/ |
| 358 |
bool fAllPathsVolatile = false; |
| 359 |
|
| 360 |
/** |
| 361 |
* Render everything in wireframe |
| 362 |
*/ |
| 363 |
bool fWireframeMode = false; |
| 364 |
|
| 365 |
/** |
| 366 |
* Enforces clearing of all textures when they're created. |
| 367 |
*/ |
| 368 |
bool fClearAllTextures = false; |
| 369 |
|
| 370 |
/** |
| 371 |
* Randomly generate a (false) GL_OUT_OF_MEMORY error |
| 372 |
*/ |
| 373 |
bool fRandomGLOOM = false; |
| 374 |
|
| 375 |
/** |
| 376 |
* Force off support for write/transfer pixels row bytes in caps. |
| 377 |
*/ |
| 378 |
bool fDisallowWriteAndTransferPixelRowBytes = false; |
| 379 |
|
| 380 |
#endif |
| 381 |
|
| 382 |
}; |
| 383 |
|
| 384 |
#endif |