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 * Allow Ganesh to more aggressively reorder operations to reduce the number of render passes. 200 * Offscreen draws will be done upfront instead of interrupting the main render pass when 201 * possible. May increase VRAM usage, but still observes the resource cache limit. 202 * Enabled by default. 203 */ 204 Enable fReduceOpsTaskSplitting = Enable::kDefault; 205 206 /** 207 * Some ES3 contexts report the ES2 external image extension, but not the ES3 version. 208 * If support for external images is critical, enabling this option will cause Ganesh to limit 209 * shaders to the ES2 shading language in that situation. 210 */ 211 bool fPreferExternalImagesOverES3 = false; 212 213 /** 214 * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers. 215 * This does not affect code path choices that are made for perfomance reasons nor does it 216 * override other GrContextOption settings. 217 */ 218 bool fDisableDriverCorrectnessWorkarounds = false; 219 220 /** 221 * Maximum number of GPU programs or pipelines to keep active in the runtime cache. 222 */ 223 int fRuntimeProgramCacheSize = 256; 224 225 /** 226 * Cache in which to store compiled shader binaries between runs. 227 */ 228 PersistentCache* fPersistentCache = nullptr; 229 230 /** 231 * This affects the usage of the PersistentCache. We can cache SkSL, backend source (GLSL), or 232 * backend binaries (GL program binaries). By default we cache binaries, but if the driver's 233 * binary loading/storing is believed to have bugs, this can be limited to caching GLSL. 234 * Caching GLSL strings still saves CPU work when a GL program is created. 235 */ 236 ShaderCacheStrategy fShaderCacheStrategy = ShaderCacheStrategy::kBackendBinary; 237 238 /** 239 * If present, use this object to report shader compilation failures. If not, report failures 240 * via SkDebugf and assert. 241 */ 242 ShaderErrorHandler* fShaderErrorHandler = nullptr; 243 244 /** 245 * Specifies the number of samples Ganesh should use when performing internal draws with MSAA 246 * (hardware capabilities permitting). 247 * 248 * If 0, Ganesh will disable internal code paths that use multisampling. 249 */ 250 int fInternalMultisampleCount = 4; 251 252 /** 253 * In Skia's vulkan backend a single GrContext submit equates to the submission of a single 254 * primary command buffer to the VkQueue. This value specifies how many vulkan secondary command 255 * buffers we will cache for reuse on a given primary command buffer. A single submit may use 256 * more than this many secondary command buffers, but after the primary command buffer is 257 * finished on the GPU it will only hold on to this many secondary command buffers for reuse. 258 * 259 * A value of -1 means we will pick a limit value internally. 260 */ 261 int fMaxCachedVulkanSecondaryCommandBuffers = -1; 262 263 /** 264 * If true, the caps will never support mipmaps. 265 */ 266 bool fSuppressMipmapSupport = false; 267 268 /** 269 * If true, and if supported, enables hardware tessellation in the caps. 270 */ 271 bool fEnableExperimentalHardwareTessellation = false; 272 273 /** 274 * Uses a reduced variety of shaders. May perform less optimally in steady state but can reduce 275 * jank due to shader compilations. 276 */ 277 bool fReducedShaderVariations = false; 278 279 // Advanced Filter: Record process name, so that we can get it in other places easily. 280 std::string fProcessName; 281 282 #if GR_TEST_UTILS 283 /** 284 * Private options that are only meant for testing within Skia's tools. 285 */ 286 287 /** 288 * Prevents use of dual source blending, to test that all xfer modes work correctly without it. 289 */ 290 bool fSuppressDualSourceBlending = false; 291 292 /** 293 * Prevents the use of non-coefficient-based blend equations, for testing dst reads, barriers, 294 * and in-shader blending. 295 */ 296 bool fSuppressAdvancedBlendEquations = false; 297 298 /** 299 * Prevents the use of framebuffer fetches, for testing dst reads and texture barriers. 300 */ 301 bool fSuppressFramebufferFetch = false; 302 303 /** 304 * If greater than zero and less than the actual hardware limit, overrides the maximum number of 305 * tessellation segments supported by the caps. 306 */ 307 int fMaxTessellationSegmentsOverride = 0; 308 309 /** 310 * If true, then all paths are processed as if "setIsVolatile" had been called. 311 */ 312 bool fAllPathsVolatile = false; 313 314 /** 315 * Render everything in wireframe 316 */ 317 bool fWireframeMode = false; 318 319 /** 320 * Enforces clearing of all textures when they're created. 321 */ 322 bool fClearAllTextures = false; 323 324 /** 325 * Randomly generate a (false) GL_OUT_OF_MEMORY error 326 */ 327 bool fRandomGLOOM = false; 328 329 /** 330 * Force off support for write/transfer pixels row bytes in caps. 331 */ 332 bool fDisallowWriteAndTransferPixelRowBytes = false; 333 334 /** 335 * Include or exclude specific GPU path renderers. 336 */ 337 GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kDefault; 338 339 /** 340 * Specify the GPU resource cache limit. Equivalent to calling `setResourceCacheLimit` on the 341 * context at construction time. 342 * 343 * A value of -1 means use the default limit value. 344 */ 345 int fResourceCacheLimitOverride = -1; 346 347 /** 348 * If true, then always try to use hardware tessellation, regardless of how small a path may be. 349 */ 350 bool fAlwaysPreferHardwareTessellation = false; 351 352 /** 353 * Maximum width and height of internal texture atlases. 354 */ 355 int fMaxTextureAtlasSize = 2048; 356 #endif 357 358 GrDriverBugWorkarounds fDriverBugWorkarounds; 359 }; 360 #else 361 struct GrContextOptions { 362 struct PersistentCache {}; 363 }; 364 #endif 365 366 #endif 367