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