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 #ifdef SKIA_OHOS 122 /** 123 * At the end of the frame, cleaning up each small-sized texture can help avoid frequent memory 124 * overruns and the issue of excessive time consumption during cleanup at the end of animations. 125 * However, enabling this feature will cause small textures to be redrawn every frame. If the te 126 * xture rendering on the current device is time-consuming, it is not recommended to enable this 127 * feature, as it may lead to performance issues. 128 */ 129 //OH ISSUE :cache small Texture on UnUni devices 130 bool clearSmallTexture = true; 131 #endif 132 133 /** Construct mipmaps manually, via repeated downsampling draw-calls. This is used when 134 the driver's implementation (glGenerateMipmap) contains bugs. This requires mipmap 135 level control (ie desktop or ES3). */ 136 bool fDoManualMipmapping = false; 137 138 /** 139 * Disables the use of coverage counting shortcuts to render paths. Coverage counting can cause 140 * artifacts along shared edges if care isn't taken to ensure both contours wind in the same 141 * direction. 142 */ 143 // FIXME: Once this is removed from Chrome and Android, rename to fEnable"". 144 bool fDisableCoverageCountingPaths = true; 145 146 /** 147 * Disables distance field rendering for paths. Distance field computation can be expensive, 148 * and yields no benefit if a path is not rendered multiple times with different transforms. 149 */ 150 bool fDisableDistanceFieldPaths = false; 151 152 /** 153 * If true this allows path mask textures to be cached. This is only really useful if paths 154 * are commonly rendered at the same scale and fractional translation. 155 */ 156 bool fAllowPathMaskCaching = true; 157 158 /** 159 * If true, the GPU will not be used to perform YUV -> RGB conversion when generating 160 * textures from codec-backed images. 161 */ 162 bool fDisableGpuYUVConversion = false; 163 164 /** 165 * The maximum size of cache textures used for Skia's Glyph cache. 166 */ 167 size_t fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4; 168 169 /** 170 * Below this threshold size in device space distance field fonts won't be used. Distance field 171 * fonts don't support hinting which is more important at smaller sizes. 172 */ 173 float fMinDistanceFieldFontSize = 18; 174 175 /** 176 * Above this threshold size in device space glyphs are drawn as individual paths. 177 */ 178 #if defined(SK_BUILD_FOR_ANDROID) 179 float fGlyphsAsPathsFontSize = 384; 180 #elif defined(SK_BUILD_FOR_MAC) 181 float fGlyphsAsPathsFontSize = 256; 182 #else 183 float fGlyphsAsPathsFontSize = 324; 184 #endif 185 186 /** 187 * Can the glyph atlas use multiple textures. If allowed, the each texture's size is bound by 188 * fGlypheCacheTextureMaximumBytes. 189 */ 190 Enable fAllowMultipleGlyphCacheTextures = Enable::kDefault; 191 192 /** 193 * Bugs on certain drivers cause stencil buffers to leak. This flag causes Skia to avoid 194 * allocating stencil buffers and use alternate rasterization paths, avoiding the leak. 195 */ 196 bool fAvoidStencilBuffers = false; 197 198 /** 199 * If true, texture fetches from mip-mapped textures will be biased to read larger MIP levels. 200 * This has the effect of sharpening those textures, at the cost of some aliasing, and possible 201 * performance impact. 202 */ 203 bool fSharpenMipmappedTextures = false; 204 205 /** 206 * Enables driver workaround to use draws instead of HW clears, e.g. glClear on the GL backend. 207 */ 208 Enable fUseDrawInsteadOfClear = Enable::kDefault; 209 210 /** 211 * Allow Ganesh to more aggressively reorder operations to reduce the number of render passes. 212 * Offscreen draws will be done upfront instead of interrupting the main render pass when 213 * possible. May increase VRAM usage, but still observes the resource cache limit. 214 * Enabled by default. 215 */ 216 Enable fReduceOpsTaskSplitting = Enable::kDefault; 217 218 /** 219 * Some ES3 contexts report the ES2 external image extension, but not the ES3 version. 220 * If support for external images is critical, enabling this option will cause Ganesh to limit 221 * shaders to the ES2 shading language in that situation. 222 */ 223 bool fPreferExternalImagesOverES3 = false; 224 225 /** 226 * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers. 227 * This does not affect code path choices that are made for perfomance reasons nor does it 228 * override other GrContextOption settings. 229 */ 230 bool fDisableDriverCorrectnessWorkarounds = false; 231 232 /** 233 * Maximum number of GPU programs or pipelines to keep active in the runtime cache. 234 */ 235 int fRuntimeProgramCacheSize = 512; 236 237 /** 238 * Cache in which to store compiled shader binaries between runs. 239 */ 240 PersistentCache* fPersistentCache = nullptr; 241 242 /** 243 * This affects the usage of the PersistentCache. We can cache SkSL, backend source (GLSL), or 244 * backend binaries (GL program binaries). By default we cache binaries, but if the driver's 245 * binary loading/storing is believed to have bugs, this can be limited to caching GLSL. 246 * Caching GLSL strings still saves CPU work when a GL program is created. 247 */ 248 ShaderCacheStrategy fShaderCacheStrategy = ShaderCacheStrategy::kBackendBinary; 249 250 /** 251 * If present, use this object to report shader compilation failures. If not, report failures 252 * via SkDebugf and assert. 253 */ 254 ShaderErrorHandler* fShaderErrorHandler = nullptr; 255 256 /** 257 * Specifies the number of samples Ganesh should use when performing internal draws with MSAA 258 * (hardware capabilities permitting). 259 * 260 * If 0, Ganesh will disable internal code paths that use multisampling. 261 */ 262 int fInternalMultisampleCount = 4; 263 264 /** 265 * In Skia's vulkan backend a single GrContext submit equates to the submission of a single 266 * primary command buffer to the VkQueue. This value specifies how many vulkan secondary command 267 * buffers we will cache for reuse on a given primary command buffer. A single submit may use 268 * more than this many secondary command buffers, but after the primary command buffer is 269 * finished on the GPU it will only hold on to this many secondary command buffers for reuse. 270 * 271 * A value of -1 means we will pick a limit value internally. 272 */ 273 int fMaxCachedVulkanSecondaryCommandBuffers = -1; 274 275 /** 276 * If true, the caps will never support mipmaps. 277 */ 278 bool fSuppressMipmapSupport = false; 279 280 /** 281 * If true, and if supported, enables hardware tessellation in the caps. 282 */ 283 bool fEnableExperimentalHardwareTessellation = false; 284 285 /** 286 * Uses a reduced variety of shaders. May perform less optimally in steady state but can reduce 287 * jank due to shader compilations. 288 */ 289 bool fReducedShaderVariations = false; 290 291 // Advanced Filter: Record process name, so that we can get it in other places easily. 292 std::string fProcessName; 293 294 #if GR_TEST_UTILS 295 /** 296 * Private options that are only meant for testing within Skia's tools. 297 */ 298 299 /** 300 * Prevents use of dual source blending, to test that all xfer modes work correctly without it. 301 */ 302 bool fSuppressDualSourceBlending = false; 303 304 /** 305 * Prevents the use of non-coefficient-based blend equations, for testing dst reads, barriers, 306 * and in-shader blending. 307 */ 308 bool fSuppressAdvancedBlendEquations = false; 309 310 /** 311 * Prevents the use of framebuffer fetches, for testing dst reads and texture barriers. 312 */ 313 bool fSuppressFramebufferFetch = false; 314 315 /** 316 * If greater than zero and less than the actual hardware limit, overrides the maximum number of 317 * tessellation segments supported by the caps. 318 */ 319 int fMaxTessellationSegmentsOverride = 0; 320 321 /** 322 * If true, then all paths are processed as if "setIsVolatile" had been called. 323 */ 324 bool fAllPathsVolatile = false; 325 326 /** 327 * Render everything in wireframe 328 */ 329 bool fWireframeMode = false; 330 331 /** 332 * Enforces clearing of all textures when they're created. 333 */ 334 bool fClearAllTextures = false; 335 336 /** 337 * Randomly generate a (false) GL_OUT_OF_MEMORY error 338 */ 339 bool fRandomGLOOM = false; 340 341 /** 342 * Force off support for write/transfer pixels row bytes in caps. 343 */ 344 bool fDisallowWriteAndTransferPixelRowBytes = false; 345 346 /** 347 * Include or exclude specific GPU path renderers. 348 */ 349 GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kDefault; 350 351 /** 352 * Specify the GPU resource cache limit. Equivalent to calling `setResourceCacheLimit` on the 353 * context at construction time. 354 * 355 * A value of -1 means use the default limit value. 356 */ 357 int fResourceCacheLimitOverride = -1; 358 359 /** 360 * If true, then always try to use hardware tessellation, regardless of how small a path may be. 361 */ 362 bool fAlwaysPreferHardwareTessellation = false; 363 364 /** 365 * Maximum width and height of internal texture atlases. 366 */ 367 int fMaxTextureAtlasSize = 2048; 368 #endif 369 370 GrDriverBugWorkarounds fDriverBugWorkarounds; 371 }; 372 #else 373 struct GrContextOptions { 374 struct PersistentCache {}; 375 }; 376 #endif 377 378 #endif 379