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