| 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/SkTypes.h" |
| 13 | #include "include/gpu/GrDriverBugWorkarounds.h" |
| 14 | #include "include/gpu/GrTypes.h" |
| 15 | #include "include/private/GrTypesPriv.h" |
| 16 | |
| 17 | #include <vector> |
| 18 | |
| 19 | class SkExecutor; |
| 20 | |
| 21 | #if SK_SUPPORT_GPU |
| 22 | struct SK_API GrContextOptions { |
| 23 | enum class Enable { |
| 24 | /** Forces an option to be disabled. */ |
| 25 | kNo, |
| 26 | /** Forces an option to be enabled. */ |
| 27 | kYes, |
| 28 | /** |
| 29 | * Uses Skia's default behavior, which may use runtime properties (e.g. driver version). |
| 30 | */ |
| 31 | kDefault |
| 32 | }; |
| 33 | |
| 34 | enum class ShaderCacheStrategy { |
| 35 | kSkSL, |
| 36 | kBackendSource, |
| 37 | kBackendBinary, |
| 38 | }; |
| 39 | |
| 40 | /** |
| 41 | * Abstract class which stores Skia data in a cache that persists between sessions. Currently, |
| 42 | * Skia stores compiled shader binaries (only when glProgramBinary / glGetProgramBinary are |
| 43 | * supported) when provided a persistent cache, but this may extend to other data in the future. |
| 44 | */ |
| 45 | class SK_API PersistentCache { |
| 46 | public: |
| 47 | virtual ~PersistentCache() {} |
| 48 | |
| 49 | /** |
| 50 | * Returns the data for the key if it exists in the cache, otherwise returns null. |
| 51 | */ |
| 52 | virtual sk_sp<SkData> load(const SkData& key) = 0; |
| 53 | |
| 54 | virtual void store(const SkData& key, const SkData& data) = 0; |
| 55 | }; |
| 56 | |
| 57 | /** |
| 58 | * Abstract class to report errors when compiling shaders. If fShaderErrorHandler is present, |
| 59 | * it will be called to report any compilation failures. Otherwise, failures will be reported |
| 60 | * via SkDebugf and asserts. |
| 61 | */ |
| 62 | class SK_API ShaderErrorHandler { |
| 63 | public: |
| 64 | virtual ~ShaderErrorHandler() {} |
| 65 | virtual void compileError(const char* shader, const char* errors) = 0; |
| 66 | }; |
| 67 | |
| 68 | GrContextOptions() {} |
| 69 | |
| 70 | // Suppress prints for the GrContext. |
| 71 | bool fSuppressPrints = false; |
| 72 | |
| 73 | /** |
| 74 | * Controls whether we check for GL errors after functions that allocate resources (e.g. |
| 75 | * glTexImage2D), for shader compilation success, and program link success. Ignored on |
| 76 | * backends other than GL. |
| 77 | */ |
| 78 | Enable fSkipGLErrorChecks = Enable::kDefault; |
| 79 | |
| 80 | /** Overrides: These options override feature detection using backend API queries. These |
| 81 | overrides can only reduce the feature set or limits, never increase them beyond the |
| 82 | detected values. */ |
| 83 | |
| 84 | int fMaxTextureSizeOverride = SK_MaxS32; |
| 85 | |
| 86 | /** the threshold in bytes above which we will use a buffer mapping API to map vertex and index |
| 87 | buffers to CPU memory in order to update them. A value of -1 means the GrContext should |
| 88 | deduce the optimal value for this platform. */ |
| 89 | int fBufferMapThreshold = -1; |
| 90 | |
| 91 | /** |
| 92 | * Executor to handle threaded work within Ganesh. If this is nullptr, then all work will be |
| 93 | * done serially on the main thread. To have worker threads assist with various tasks, set this |
| 94 | * to a valid SkExecutor instance. Currently, used for software path rendering, but may be used |
| 95 | * for other tasks. |
| 96 | */ |
| 97 | SkExecutor* fExecutor = nullptr; |
| 98 | |
| 99 | /** Construct mipmaps manually, via repeated downsampling draw-calls. This is used when |
| 100 | the driver's implementation (glGenerateMipmap) contains bugs. This requires mipmap |
| 101 | level and LOD control (ie desktop or ES3). */ |
| 102 | bool fDoManualMipmapping = false; |
| 103 | |
| 104 | /** |
| 105 | * Disables the use of coverage counting shortcuts to render paths. Coverage counting can cause |
| 106 | * artifacts along shared edges if care isn't taken to ensure both contours wind in the same |
| 107 | * direction. |
| 108 | */ |
| 109 | // FIXME: Once this is removed from Chrome and Android, rename to fEnable"". |
| 110 | bool fDisableCoverageCountingPaths = true; |
| 111 | |
| 112 | /** |
| 113 | * Disables distance field rendering for paths. Distance field computation can be expensive, |
| 114 | * and yields no benefit if a path is not rendered multiple times with different transforms. |
| 115 | */ |
| 116 | bool fDisableDistanceFieldPaths = false; |
| 117 | |
| 118 | /** |
| 119 | * If true this allows path mask textures to be cached. This is only really useful if paths |
| 120 | * are commonly rendered at the same scale and fractional translation. |
| 121 | */ |
| 122 | bool fAllowPathMaskCaching = true; |
| 123 | |
| 124 | /** |
| 125 | * If true, the GPU will not be used to perform YUV -> RGB conversion when generating |
| 126 | * textures from codec-backed images. |
| 127 | */ |
| 128 | bool fDisableGpuYUVConversion = false; |
| 129 | |
| 130 | /** |
| 131 | * The maximum size of cache textures used for Skia's Glyph cache. |
| 132 | */ |
| 133 | size_t fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4; |
| 134 | |
| 135 | /** |
| 136 | * Below this threshold size in device space distance field fonts won't be used. Distance field |
| 137 | * fonts don't support hinting which is more important at smaller sizes. |
| 138 | */ |
| 139 | float fMinDistanceFieldFontSize = 18; |
| 140 | |
| 141 | /** |
| 142 | * Above this threshold size in device space glyphs are drawn as individual paths. |
| 143 | */ |
| 144 | #if defined(SK_BUILD_FOR_ANDROID) |
| 145 | float fGlyphsAsPathsFontSize = 384; |
| 146 | #elif defined(SK_BUILD_FOR_MAC) |
| 147 | float fGlyphsAsPathsFontSize = 256; |
| 148 | #else |
| 149 | float fGlyphsAsPathsFontSize = 324; |
| 150 | #endif |
| 151 | |
| 152 | /** |
| 153 | * Can the glyph atlas use multiple textures. If allowed, the each texture's size is bound by |
| 154 | * fGlypheCacheTextureMaximumBytes. |
| 155 | */ |
| 156 | Enable fAllowMultipleGlyphCacheTextures = Enable::kDefault; |
| 157 | |
| 158 | /** |
| 159 | * Bugs on certain drivers cause stencil buffers to leak. This flag causes Skia to avoid |
| 160 | * allocating stencil buffers and use alternate rasterization paths, avoiding the leak. |
| 161 | */ |
| 162 | bool fAvoidStencilBuffers = false; |
| 163 | |
| 164 | /** |
| 165 | * If true, texture fetches from mip-mapped textures will be biased to read larger MIP levels. |
| 166 | * This has the effect of sharpening those textures, at the cost of some aliasing, and possible |
| 167 | * performance impact. |
| 168 | */ |
| 169 | bool fSharpenMipmappedTextures = false; |
| 170 | |
| 171 | /** |
| 172 | * Enables driver workaround to use draws instead of HW clears, e.g. glClear on the GL backend. |
| 173 | */ |
| 174 | Enable fUseDrawInsteadOfClear = Enable::kDefault; |
| 175 | |
| 176 | /** |
| 177 | * Allow Ganesh to more aggressively reorder operations. |
| 178 | * Eventually this will just be what is done and will not be optional. |
| 179 | */ |
| 180 | Enable fReduceOpsTaskSplitting = Enable::kDefault; |
| 181 | |
| 182 | /** |
| 183 | * Some ES3 contexts report the ES2 external image extension, but not the ES3 version. |
| 184 | * If support for external images is critical, enabling this option will cause Ganesh to limit |
| 185 | * shaders to the ES2 shading language in that situation. |
| 186 | */ |
| 187 | bool fPreferExternalImagesOverES3 = false; |
| 188 | |
| 189 | /** |
| 190 | * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers. |
| 191 | * This does not affect code path choices that are made for perfomance reasons nor does it |
| 192 | * override other GrContextOption settings. |
| 193 | */ |
| 194 | bool fDisableDriverCorrectnessWorkarounds = false; |
| 195 | |
| 196 | /** |
| 197 | * Maximum number of GPU programs or pipelines to keep active in the runtime cache. |
| 198 | */ |
| 199 | int fRuntimeProgramCacheSize = 256; |
| 200 | |
| 201 | /** |
| 202 | * Cache in which to store compiled shader binaries between runs. |
| 203 | */ |
| 204 | PersistentCache* fPersistentCache = nullptr; |
| 205 | |
| 206 | /** |
| 207 | * This affects the usage of the PersistentCache. We can cache SkSL, backend source (GLSL), or |
| 208 | * backend binaries (GL program binaries). By default we cache binaries, but if the driver's |
| 209 | * binary loading/storing is believed to have bugs, this can be limited to caching GLSL. |
| 210 | * Caching GLSL strings still saves CPU work when a GL program is created. |
| 211 | */ |
| 212 | ShaderCacheStrategy fShaderCacheStrategy = ShaderCacheStrategy::kBackendBinary; |
| 213 | |
| 214 | /** |
| 215 | * If present, use this object to report shader compilation failures. If not, report failures |
| 216 | * via SkDebugf and assert. |
| 217 | */ |
| 218 | ShaderErrorHandler* fShaderErrorHandler = nullptr; |
| 219 | |
| 220 | /** |
| 221 | * Specifies the number of samples Ganesh should use when performing internal draws with MSAA or |
| 222 | * mixed samples (hardware capabilities permitting). |
| 223 | * |
| 224 | * If 0, Ganesh will disable internal code paths that use multisampling. |
| 225 | */ |
| 226 | int fInternalMultisampleCount = 4; |
| 227 | |
| 228 | /** |
| 229 | * In Skia's vulkan backend a single GrContext submit equates to the submission of a single |
| 230 | * primary command buffer to the VkQueue. This value specifies how many vulkan secondary command |
| 231 | * buffers we will cache for reuse on a given primary command buffer. A single submit may use |
| 232 | * more than this many secondary command buffers, but after the primary command buffer is |
| 233 | * finished on the GPU it will only hold on to this many secondary command buffers for reuse. |
| 234 | * |
| 235 | * A value of -1 means we will pick a limit value internally. |
| 236 | */ |
| 237 | int fMaxCachedVulkanSecondaryCommandBuffers = -1; |
| 238 | |
| 239 | #if GR_TEST_UTILS |
| 240 | /** |
| 241 | * Private options that are only meant for testing within Skia's tools. |
| 242 | */ |
| 243 | |
| 244 | /** |
| 245 | * If non-zero, overrides the maximum size of a tile for sw-backed images and bitmaps rendered |
| 246 | * by SkGpuDevice. |
| 247 | */ |
| 248 | int fMaxTileSizeOverride = 0; |
| 249 | |
| 250 | /** |
| 251 | * Prevents use of dual source blending, to test that all xfer modes work correctly without it. |
| 252 | */ |
| 253 | bool fSuppressDualSourceBlending = false; |
| 254 | |
| 255 | /** |
| 256 | * If true, the caps will never support geometry shaders. |
| 257 | */ |
| 258 | bool fSuppressGeometryShaders = false; |
| 259 | |
| 260 | /** |
| 261 | * If true, the caps will never support tessellation shaders. |
| 262 | */ |
| 263 | bool fSuppressTessellationShaders = false; |
| 264 | |
| 265 | /** |
| 266 | * Render everything in wireframe |
| 267 | */ |
| 268 | bool fWireframeMode = false; |
| 269 | |
| 270 | /** |
| 271 | * Enforces clearing of all textures when they're created. |
| 272 | */ |
| 273 | bool fClearAllTextures = false; |
| 274 | |
| 275 | /** |
| 276 | * Randomly generate a (false) GL_OUT_OF_MEMORY error |
| 277 | */ |
| 278 | bool fRandomGLOOM = false; |
| 279 | |
| 280 | /** |
| 281 | * Include or exclude specific GPU path renderers. |
| 282 | */ |
| 283 | GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kDefault; |
| 284 | #endif |
| 285 | |
| 286 | GrDriverBugWorkarounds fDriverBugWorkarounds; |
| 287 | }; |
| 288 | #else |
| 289 | struct GrContextOptions { |
| 290 | struct PersistentCache {}; |
| 291 | }; |
| 292 | #endif |
| 293 | |
| 294 | #endif |
| 295 | |