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/GrDriverBugWorkarounds.h" 15 #include "include/gpu/GrTypes.h" 16 #include "include/gpu/ShaderErrorHandler.h" 17 #include "include/private/GrTypesPriv.h" 18 19 #include <vector> 20 21 class SkExecutor; 22 23 #if SK_SUPPORT_GPU 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. storeGrContextOptions58 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 */ storeGrContextOptions64 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 GrContextOptionsGrContextOptions76 GrContextOptions() {} 77 78 // Suppress prints for the GrContext. 79 bool fSuppressPrints = false; 80 81 /** 82 * Controls whether we check for GL errors after functions that allocate resources (e.g. 83 * glTexImage2D), for shader compilation success, and program link success. Ignored on 84 * backends other than GL. 85 */ 86 Enable fSkipGLErrorChecks = Enable::kDefault; 87 88 /** Overrides: These options override feature detection using backend API queries. These 89 overrides can only reduce the feature set or limits, never increase them beyond the 90 detected values. */ 91 92 int fMaxTextureSizeOverride = SK_MaxS32; 93 94 /** the threshold in bytes above which we will use a buffer mapping API to map vertex and index 95 buffers to CPU memory in order to update them. A value of -1 means the GrContext should 96 deduce the optimal value for this platform. */ 97 int fBufferMapThreshold = -1; 98 99 /** 100 * Executor to handle threaded work within Ganesh. If this is nullptr, then all work will be 101 * done serially on the main thread. To have worker threads assist with various tasks, set this 102 * to a valid SkExecutor instance. Currently, used for software path rendering, but may be used 103 * for other tasks. 104 */ 105 SkExecutor* fExecutor = nullptr; 106 107 /** Construct mipmaps manually, via repeated downsampling draw-calls. This is used when 108 the driver's implementation (glGenerateMipmap) contains bugs. This requires mipmap 109 level control (ie desktop or ES3). */ 110 bool fDoManualMipmapping = false; 111 112 /** 113 * Disables the use of coverage counting shortcuts to render paths. Coverage counting can cause 114 * artifacts along shared edges if care isn't taken to ensure both contours wind in the same 115 * direction. 116 */ 117 // FIXME: Once this is removed from Chrome and Android, rename to fEnable"". 118 bool fDisableCoverageCountingPaths = true; 119 120 /** 121 * Disables distance field rendering for paths. Distance field computation can be expensive, 122 * and yields no benefit if a path is not rendered multiple times with different transforms. 123 */ 124 bool fDisableDistanceFieldPaths = false; 125 126 /** 127 * If true this allows path mask textures to be cached. This is only really useful if paths 128 * are commonly rendered at the same scale and fractional translation. 129 */ 130 bool fAllowPathMaskCaching = true; 131 132 /** 133 * If true, the GPU will not be used to perform YUV -> RGB conversion when generating 134 * textures from codec-backed images. 135 */ 136 bool fDisableGpuYUVConversion = false; 137 138 /** 139 * The maximum size of cache textures used for Skia's Glyph cache. 140 */ 141 size_t fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4; 142 143 /** 144 * Below this threshold size in device space distance field fonts won't be used. Distance field 145 * fonts don't support hinting which is more important at smaller sizes. 146 */ 147 float fMinDistanceFieldFontSize = 18; 148 149 /** 150 * Above this threshold size in device space glyphs are drawn as individual paths. 151 */ 152 #if defined(SK_BUILD_FOR_ANDROID) 153 float fGlyphsAsPathsFontSize = 384; 154 #elif defined(SK_BUILD_FOR_MAC) 155 float fGlyphsAsPathsFontSize = 256; 156 #else 157 float fGlyphsAsPathsFontSize = 324; 158 #endif 159 160 /** 161 * Can the glyph atlas use multiple textures. If allowed, the each texture's size is bound by 162 * fGlypheCacheTextureMaximumBytes. 163 */ 164 Enable fAllowMultipleGlyphCacheTextures = Enable::kDefault; 165 166 /** 167 * Bugs on certain drivers cause stencil buffers to leak. This flag causes Skia to avoid 168 * allocating stencil buffers and use alternate rasterization paths, avoiding the leak. 169 */ 170 bool fAvoidStencilBuffers = false; 171 172 /** 173 * If true, texture fetches from mip-mapped textures will be biased to read larger MIP levels. 174 * This has the effect of sharpening those textures, at the cost of some aliasing, and possible 175 * performance impact. 176 */ 177 bool fSharpenMipmappedTextures = false; 178 179 /** 180 * Enables driver workaround to use draws instead of HW clears, e.g. glClear on the GL backend. 181 */ 182 Enable fUseDrawInsteadOfClear = Enable::kDefault; 183 184 /** 185 * Allow Ganesh to more aggressively reorder operations to reduce the number of render passes. 186 * Offscreen draws will be done upfront instead of interrupting the main render pass when 187 * possible. May increase VRAM usage, but still observes the resource cache limit. 188 * Enabled by default. 189 */ 190 Enable fReduceOpsTaskSplitting = Enable::kDefault; 191 192 /** 193 * Some ES3 contexts report the ES2 external image extension, but not the ES3 version. 194 * If support for external images is critical, enabling this option will cause Ganesh to limit 195 * shaders to the ES2 shading language in that situation. 196 */ 197 bool fPreferExternalImagesOverES3 = false; 198 199 /** 200 * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers. 201 * This does not affect code path choices that are made for perfomance reasons nor does it 202 * override other GrContextOption settings. 203 */ 204 bool fDisableDriverCorrectnessWorkarounds = false; 205 206 /** 207 * Maximum number of GPU programs or pipelines to keep active in the runtime cache. 208 */ 209 int fRuntimeProgramCacheSize = 256; 210 211 /** 212 * Cache in which to store compiled shader binaries between runs. 213 */ 214 PersistentCache* fPersistentCache = nullptr; 215 216 /** 217 * This affects the usage of the PersistentCache. We can cache SkSL, backend source (GLSL), or 218 * backend binaries (GL program binaries). By default we cache binaries, but if the driver's 219 * binary loading/storing is believed to have bugs, this can be limited to caching GLSL. 220 * Caching GLSL strings still saves CPU work when a GL program is created. 221 */ 222 ShaderCacheStrategy fShaderCacheStrategy = ShaderCacheStrategy::kBackendBinary; 223 224 /** 225 * If present, use this object to report shader compilation failures. If not, report failures 226 * via SkDebugf and assert. 227 */ 228 ShaderErrorHandler* fShaderErrorHandler = nullptr; 229 230 /** 231 * Specifies the number of samples Ganesh should use when performing internal draws with MSAA 232 * (hardware capabilities permitting). 233 * 234 * If 0, Ganesh will disable internal code paths that use multisampling. 235 */ 236 int fInternalMultisampleCount = 4; 237 238 /** 239 * In Skia's vulkan backend a single GrContext submit equates to the submission of a single 240 * primary command buffer to the VkQueue. This value specifies how many vulkan secondary command 241 * buffers we will cache for reuse on a given primary command buffer. A single submit may use 242 * more than this many secondary command buffers, but after the primary command buffer is 243 * finished on the GPU it will only hold on to this many secondary command buffers for reuse. 244 * 245 * A value of -1 means we will pick a limit value internally. 246 */ 247 int fMaxCachedVulkanSecondaryCommandBuffers = -1; 248 249 /** 250 * If true, the caps will never support mipmaps. 251 */ 252 bool fSuppressMipmapSupport = false; 253 254 /** 255 * If true, and if supported, enables hardware tessellation in the caps. 256 */ 257 bool fEnableExperimentalHardwareTessellation = false; 258 259 /** 260 * If true, then add 1 pixel padding to all glyph masks in the atlas to support bi-lerp 261 * rendering of all glyphs. This must be set to true to use GrSlug. 262 */ 263 #if defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG) 264 bool fSupportBilerpFromGlyphAtlas = true; 265 #else 266 bool fSupportBilerpFromGlyphAtlas = false; 267 #endif 268 269 /** 270 * Uses a reduced variety of shaders. May perform less optimally in steady state but can reduce 271 * jank due to shader compilations. 272 */ 273 bool fReducedShaderVariations = false; 274 275 /** 276 * If true, then allow to enable MSAA on new Intel GPUs. 277 */ 278 bool fAllowMSAAOnNewIntel = false; 279 280 #if GR_TEST_UTILS 281 /** 282 * Private options that are only meant for testing within Skia's tools. 283 */ 284 285 /** 286 * Prevents use of dual source blending, to test that all xfer modes work correctly without it. 287 */ 288 bool fSuppressDualSourceBlending = false; 289 290 /** 291 * Prevents the use of non-coefficient-based blend equations, for testing dst reads, barriers, 292 * and in-shader blending. 293 */ 294 bool fSuppressAdvancedBlendEquations = false; 295 296 /** 297 * Prevents the use of framebuffer fetches, for testing dst reads and texture barriers. 298 */ 299 bool fSuppressFramebufferFetch = false; 300 301 /** 302 * If greater than zero and less than the actual hardware limit, overrides the maximum number of 303 * tessellation segments supported by the caps. 304 */ 305 int fMaxTessellationSegmentsOverride = 0; 306 307 /** 308 * If true, then all paths are processed as if "setIsVolatile" had been called. 309 */ 310 bool fAllPathsVolatile = false; 311 312 /** 313 * Render everything in wireframe 314 */ 315 bool fWireframeMode = false; 316 317 /** 318 * Enforces clearing of all textures when they're created. 319 */ 320 bool fClearAllTextures = false; 321 322 /** 323 * Randomly generate a (false) GL_OUT_OF_MEMORY error 324 */ 325 bool fRandomGLOOM = false; 326 327 /** 328 * Force off support for write/transfer pixels row bytes in caps. 329 */ 330 bool fDisallowWriteAndTransferPixelRowBytes = false; 331 332 /** 333 * Include or exclude specific GPU path renderers. 334 */ 335 GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kDefault; 336 337 /** 338 * Specify the GPU resource cache limit. Equivalent to calling `setResourceCacheLimit` on the 339 * context at construction time. 340 * 341 * A value of -1 means use the default limit value. 342 */ 343 int fResourceCacheLimitOverride = -1; 344 345 /** 346 * If true, then always try to use hardware tessellation, regardless of how small a path may be. 347 */ 348 bool fAlwaysPreferHardwareTessellation = false; 349 350 /** 351 * Maximum width and height of internal texture atlases. 352 */ 353 int fMaxTextureAtlasSize = 2048; 354 #endif 355 356 GrDriverBugWorkarounds fDriverBugWorkarounds; 357 }; 358 #else 359 struct GrContextOptions { 360 struct PersistentCache {}; 361 }; 362 #endif 363 364 #endif 365