2015-05-22 21:01:46 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GrContextOptions_DEFINED
|
|
|
|
#define GrContextOptions_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkData.h"
|
2021-02-26 18:54:11 +00:00
|
|
|
#include "include/core/SkString.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "include/gpu/GrDriverBugWorkarounds.h"
|
|
|
|
#include "include/gpu/GrTypes.h"
|
2021-12-10 22:27:10 +00:00
|
|
|
#include "include/gpu/ShaderErrorHandler.h"
|
2022-04-12 13:59:38 +00:00
|
|
|
#include "include/private/gpu/ganesh/GrTypesPriv.h"
|
2015-05-22 21:01:46 +00:00
|
|
|
|
2017-11-01 19:45:43 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2017-08-23 14:12:00 +00:00
|
|
|
class SkExecutor;
|
|
|
|
|
2018-05-14 21:02:03 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
2019-02-15 14:39:52 +00:00
|
|
|
struct SK_API GrContextOptions {
|
2017-10-18 12:33:29 +00:00
|
|
|
enum class Enable {
|
|
|
|
/** Forces an option to be disabled. */
|
|
|
|
kNo,
|
|
|
|
/** Forces an option to be enabled. */
|
|
|
|
kYes,
|
|
|
|
/**
|
|
|
|
* Uses Skia's default behavior, which may use runtime properties (e.g. driver version).
|
|
|
|
*/
|
|
|
|
kDefault
|
|
|
|
};
|
|
|
|
|
2019-09-03 18:59:26 +00:00
|
|
|
enum class ShaderCacheStrategy {
|
|
|
|
kSkSL,
|
|
|
|
kBackendSource,
|
|
|
|
kBackendBinary,
|
|
|
|
};
|
|
|
|
|
2017-11-01 19:45:43 +00:00
|
|
|
/**
|
|
|
|
* Abstract class which stores Skia data in a cache that persists between sessions. Currently,
|
|
|
|
* Skia stores compiled shader binaries (only when glProgramBinary / glGetProgramBinary are
|
|
|
|
* supported) when provided a persistent cache, but this may extend to other data in the future.
|
|
|
|
*/
|
2019-02-15 14:39:52 +00:00
|
|
|
class SK_API PersistentCache {
|
2017-11-01 19:45:43 +00:00
|
|
|
public:
|
2021-01-26 19:29:06 +00:00
|
|
|
virtual ~PersistentCache() = default;
|
2017-11-01 19:45:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the data for the key if it exists in the cache, otherwise returns null.
|
|
|
|
*/
|
|
|
|
virtual sk_sp<SkData> load(const SkData& key) = 0;
|
|
|
|
|
2021-02-26 18:54:11 +00:00
|
|
|
// Placeholder until all clients override the 3-parameter store(), then remove this, and
|
|
|
|
// make that version pure virtual.
|
|
|
|
virtual void store(const SkData& /*key*/, const SkData& /*data*/) { SkASSERT(false); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores data in the cache, indexed by key. description provides a human-readable
|
|
|
|
* version of the key.
|
|
|
|
*/
|
|
|
|
virtual void store(const SkData& key, const SkData& data, const SkString& /*description*/) {
|
|
|
|
this->store(key, data);
|
|
|
|
}
|
2021-01-26 19:29:06 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
PersistentCache() = default;
|
|
|
|
PersistentCache(const PersistentCache&) = delete;
|
|
|
|
PersistentCache& operator=(const PersistentCache&) = delete;
|
2017-11-01 19:45:43 +00:00
|
|
|
};
|
|
|
|
|
2021-12-10 22:27:10 +00:00
|
|
|
using ShaderErrorHandler = skgpu::ShaderErrorHandler;
|
2019-05-03 17:13:35 +00:00
|
|
|
|
2016-09-27 13:34:10 +00:00
|
|
|
GrContextOptions() {}
|
2015-05-22 21:01:46 +00:00
|
|
|
|
|
|
|
// Suppress prints for the GrContext.
|
2016-09-15 20:50:26 +00:00
|
|
|
bool fSuppressPrints = false;
|
2015-05-27 20:23:23 +00:00
|
|
|
|
2020-02-25 17:13:29 +00:00
|
|
|
/**
|
|
|
|
* Controls whether we check for GL errors after functions that allocate resources (e.g.
|
|
|
|
* glTexImage2D), for shader compilation success, and program link success. Ignored on
|
|
|
|
* backends other than GL.
|
|
|
|
*/
|
|
|
|
Enable fSkipGLErrorChecks = Enable::kDefault;
|
|
|
|
|
2015-05-27 20:23:23 +00:00
|
|
|
/** Overrides: These options override feature detection using backend API queries. These
|
|
|
|
overrides can only reduce the feature set or limits, never increase them beyond the
|
|
|
|
detected values. */
|
|
|
|
|
2016-09-15 20:50:26 +00:00
|
|
|
int fMaxTextureSizeOverride = SK_MaxS32;
|
|
|
|
|
2015-06-01 21:17:47 +00:00
|
|
|
/** the threshold in bytes above which we will use a buffer mapping API to map vertex and index
|
|
|
|
buffers to CPU memory in order to update them. A value of -1 means the GrContext should
|
|
|
|
deduce the optimal value for this platform. */
|
2016-09-15 20:50:26 +00:00
|
|
|
int fBufferMapThreshold = -1;
|
2015-06-18 21:18:02 +00:00
|
|
|
|
2017-08-23 14:12:00 +00:00
|
|
|
/**
|
|
|
|
* Executor to handle threaded work within Ganesh. If this is nullptr, then all work will be
|
|
|
|
* done serially on the main thread. To have worker threads assist with various tasks, set this
|
|
|
|
* to a valid SkExecutor instance. Currently, used for software path rendering, but may be used
|
|
|
|
* for other tasks.
|
|
|
|
*/
|
|
|
|
SkExecutor* fExecutor = nullptr;
|
|
|
|
|
2016-06-09 20:11:08 +00:00
|
|
|
/** Construct mipmaps manually, via repeated downsampling draw-calls. This is used when
|
|
|
|
the driver's implementation (glGenerateMipmap) contains bugs. This requires mipmap
|
2020-09-08 15:48:08 +00:00
|
|
|
level control (ie desktop or ES3). */
|
2016-09-15 20:50:26 +00:00
|
|
|
bool fDoManualMipmapping = false;
|
2016-07-29 15:14:20 +00:00
|
|
|
|
2018-06-27 00:16:47 +00:00
|
|
|
/**
|
2019-03-30 06:31:23 +00:00
|
|
|
* Disables the use of coverage counting shortcuts to render paths. Coverage counting can cause
|
|
|
|
* artifacts along shared edges if care isn't taken to ensure both contours wind in the same
|
|
|
|
* direction.
|
2018-06-27 00:16:47 +00:00
|
|
|
*/
|
2019-03-18 16:22:30 +00:00
|
|
|
// FIXME: Once this is removed from Chrome and Android, rename to fEnable"".
|
|
|
|
bool fDisableCoverageCountingPaths = true;
|
2018-06-27 00:16:47 +00:00
|
|
|
|
2017-08-29 20:15:39 +00:00
|
|
|
/**
|
|
|
|
* Disables distance field rendering for paths. Distance field computation can be expensive,
|
|
|
|
* and yields no benefit if a path is not rendered multiple times with different transforms.
|
|
|
|
*/
|
|
|
|
bool fDisableDistanceFieldPaths = false;
|
|
|
|
|
2016-09-21 18:16:05 +00:00
|
|
|
/**
|
|
|
|
* If true this allows path mask textures to be cached. This is only really useful if paths
|
|
|
|
* are commonly rendered at the same scale and fractional translation.
|
|
|
|
*/
|
2017-09-27 19:31:29 +00:00
|
|
|
bool fAllowPathMaskCaching = true;
|
2016-09-21 18:16:05 +00:00
|
|
|
|
2017-02-14 19:15:48 +00:00
|
|
|
/**
|
|
|
|
* If true, the GPU will not be used to perform YUV -> RGB conversion when generating
|
|
|
|
* textures from codec-backed images.
|
|
|
|
*/
|
|
|
|
bool fDisableGpuYUVConversion = false;
|
2017-02-22 19:00:42 +00:00
|
|
|
|
|
|
|
/**
|
2017-08-30 19:14:04 +00:00
|
|
|
* The maximum size of cache textures used for Skia's Glyph cache.
|
2017-02-22 19:00:42 +00:00
|
|
|
*/
|
2018-06-07 00:46:38 +00:00
|
|
|
size_t fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4;
|
2017-02-22 19:00:42 +00:00
|
|
|
|
2017-11-07 21:23:34 +00:00
|
|
|
/**
|
|
|
|
* Below this threshold size in device space distance field fonts won't be used. Distance field
|
2020-06-12 13:37:31 +00:00
|
|
|
* fonts don't support hinting which is more important at smaller sizes.
|
2017-11-07 21:23:34 +00:00
|
|
|
*/
|
2020-06-12 13:37:31 +00:00
|
|
|
float fMinDistanceFieldFontSize = 18;
|
2017-11-07 21:23:34 +00:00
|
|
|
|
|
|
|
/**
|
2020-06-12 13:37:31 +00:00
|
|
|
* Above this threshold size in device space glyphs are drawn as individual paths.
|
2017-11-07 21:23:34 +00:00
|
|
|
*/
|
2020-06-12 13:37:31 +00:00
|
|
|
#if defined(SK_BUILD_FOR_ANDROID)
|
|
|
|
float fGlyphsAsPathsFontSize = 384;
|
|
|
|
#elif defined(SK_BUILD_FOR_MAC)
|
|
|
|
float fGlyphsAsPathsFontSize = 256;
|
|
|
|
#else
|
|
|
|
float fGlyphsAsPathsFontSize = 324;
|
|
|
|
#endif
|
2017-11-07 21:23:34 +00:00
|
|
|
|
2017-11-06 15:36:57 +00:00
|
|
|
/**
|
|
|
|
* Can the glyph atlas use multiple textures. If allowed, the each texture's size is bound by
|
|
|
|
* fGlypheCacheTextureMaximumBytes.
|
|
|
|
*/
|
|
|
|
Enable fAllowMultipleGlyphCacheTextures = Enable::kDefault;
|
|
|
|
|
2017-05-02 20:15:53 +00:00
|
|
|
/**
|
2017-08-30 19:14:04 +00:00
|
|
|
* Bugs on certain drivers cause stencil buffers to leak. This flag causes Skia to avoid
|
|
|
|
* allocating stencil buffers and use alternate rasterization paths, avoiding the leak.
|
2017-05-02 20:15:53 +00:00
|
|
|
*/
|
2017-08-30 19:14:04 +00:00
|
|
|
bool fAvoidStencilBuffers = false;
|
2017-05-02 20:15:53 +00:00
|
|
|
|
2017-10-18 12:33:29 +00:00
|
|
|
/**
|
2019-01-11 20:26:22 +00:00
|
|
|
* Enables driver workaround to use draws instead of HW clears, e.g. glClear on the GL backend.
|
2017-10-18 12:33:29 +00:00
|
|
|
*/
|
2019-01-11 20:26:22 +00:00
|
|
|
Enable fUseDrawInsteadOfClear = Enable::kDefault;
|
2017-10-18 12:33:29 +00:00
|
|
|
|
2018-02-07 22:08:21 +00:00
|
|
|
/**
|
2021-06-21 15:11:44 +00:00
|
|
|
* Allow Ganesh to more aggressively reorder operations to reduce the number of render passes.
|
|
|
|
* Offscreen draws will be done upfront instead of interrupting the main render pass when
|
|
|
|
* possible. May increase VRAM usage, but still observes the resource cache limit.
|
|
|
|
* Enabled by default.
|
2018-10-09 13:31:40 +00:00
|
|
|
*/
|
2019-08-22 21:15:39 +00:00
|
|
|
Enable fReduceOpsTaskSplitting = Enable::kDefault;
|
2018-10-09 13:31:40 +00:00
|
|
|
|
2018-05-08 17:00:42 +00:00
|
|
|
/**
|
|
|
|
* Some ES3 contexts report the ES2 external image extension, but not the ES3 version.
|
|
|
|
* If support for external images is critical, enabling this option will cause Ganesh to limit
|
|
|
|
* shaders to the ES2 shading language in that situation.
|
|
|
|
*/
|
|
|
|
bool fPreferExternalImagesOverES3 = false;
|
|
|
|
|
2018-01-23 16:06:41 +00:00
|
|
|
/**
|
|
|
|
* Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers.
|
|
|
|
* This does not affect code path choices that are made for perfomance reasons nor does it
|
|
|
|
* override other GrContextOption settings.
|
|
|
|
*/
|
|
|
|
bool fDisableDriverCorrectnessWorkarounds = false;
|
|
|
|
|
2019-09-06 14:16:02 +00:00
|
|
|
/**
|
|
|
|
* Maximum number of GPU programs or pipelines to keep active in the runtime cache.
|
|
|
|
*/
|
|
|
|
int fRuntimeProgramCacheSize = 256;
|
|
|
|
|
2017-11-01 19:45:43 +00:00
|
|
|
/**
|
|
|
|
* Cache in which to store compiled shader binaries between runs.
|
|
|
|
*/
|
|
|
|
PersistentCache* fPersistentCache = nullptr;
|
|
|
|
|
2019-02-15 15:05:06 +00:00
|
|
|
/**
|
2019-09-03 18:59:26 +00:00
|
|
|
* This affects the usage of the PersistentCache. We can cache SkSL, backend source (GLSL), or
|
|
|
|
* backend binaries (GL program binaries). By default we cache binaries, but if the driver's
|
|
|
|
* binary loading/storing is believed to have bugs, this can be limited to caching GLSL.
|
|
|
|
* Caching GLSL strings still saves CPU work when a GL program is created.
|
2019-02-15 15:05:06 +00:00
|
|
|
*/
|
2019-09-03 18:59:26 +00:00
|
|
|
ShaderCacheStrategy fShaderCacheStrategy = ShaderCacheStrategy::kBackendBinary;
|
2019-02-15 15:05:06 +00:00
|
|
|
|
2019-09-03 18:59:26 +00:00
|
|
|
/**
|
|
|
|
* If present, use this object to report shader compilation failures. If not, report failures
|
|
|
|
* via SkDebugf and assert.
|
|
|
|
*/
|
|
|
|
ShaderErrorHandler* fShaderErrorHandler = nullptr;
|
2019-05-01 18:13:41 +00:00
|
|
|
|
2019-06-17 20:16:49 +00:00
|
|
|
/**
|
2021-04-22 18:57:28 +00:00
|
|
|
* Specifies the number of samples Ganesh should use when performing internal draws with MSAA
|
|
|
|
* (hardware capabilities permitting).
|
2019-06-24 17:54:24 +00:00
|
|
|
*
|
|
|
|
* If 0, Ganesh will disable internal code paths that use multisampling.
|
2019-06-17 20:16:49 +00:00
|
|
|
*/
|
2019-06-24 17:54:24 +00:00
|
|
|
int fInternalMultisampleCount = 4;
|
2019-06-17 20:16:49 +00:00
|
|
|
|
2020-07-14 13:21:48 +00:00
|
|
|
/**
|
|
|
|
* In Skia's vulkan backend a single GrContext submit equates to the submission of a single
|
|
|
|
* primary command buffer to the VkQueue. This value specifies how many vulkan secondary command
|
|
|
|
* buffers we will cache for reuse on a given primary command buffer. A single submit may use
|
|
|
|
* more than this many secondary command buffers, but after the primary command buffer is
|
|
|
|
* finished on the GPU it will only hold on to this many secondary command buffers for reuse.
|
|
|
|
*
|
|
|
|
* A value of -1 means we will pick a limit value internally.
|
|
|
|
*/
|
|
|
|
int fMaxCachedVulkanSecondaryCommandBuffers = -1;
|
|
|
|
|
2020-10-19 14:07:48 +00:00
|
|
|
/**
|
|
|
|
* If true, the caps will never support mipmaps.
|
|
|
|
*/
|
|
|
|
bool fSuppressMipmapSupport = false;
|
|
|
|
|
2021-02-25 00:41:44 +00:00
|
|
|
/**
|
|
|
|
* If true, and if supported, enables hardware tessellation in the caps.
|
2022-04-27 01:02:09 +00:00
|
|
|
* DEPRECATED: This value is ignored; experimental hardware tessellation is always disabled.
|
2021-02-25 00:41:44 +00:00
|
|
|
*/
|
|
|
|
bool fEnableExperimentalHardwareTessellation = false;
|
|
|
|
|
2021-12-09 21:19:08 +00:00
|
|
|
/**
|
|
|
|
* If true, then add 1 pixel padding to all glyph masks in the atlas to support bi-lerp
|
|
|
|
* rendering of all glyphs. This must be set to true to use GrSlug.
|
|
|
|
*/
|
2022-02-17 19:58:33 +00:00
|
|
|
#if defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG) || \
|
2022-02-18 16:15:46 +00:00
|
|
|
defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_SERIALIZE) || \
|
|
|
|
defined(SK_EXPERIMENTAL_SIMULATE_DRAWGLYPHRUNLIST_WITH_SLUG_STRIKE_SERIALIZE)
|
2021-12-09 21:19:08 +00:00
|
|
|
bool fSupportBilerpFromGlyphAtlas = true;
|
|
|
|
#else
|
|
|
|
bool fSupportBilerpFromGlyphAtlas = false;
|
|
|
|
#endif
|
|
|
|
|
2021-04-09 15:57:59 +00:00
|
|
|
/**
|
|
|
|
* Uses a reduced variety of shaders. May perform less optimally in steady state but can reduce
|
|
|
|
* jank due to shader compilations.
|
|
|
|
*/
|
|
|
|
bool fReducedShaderVariations = false;
|
|
|
|
|
2022-01-20 13:23:51 +00:00
|
|
|
/**
|
|
|
|
* If true, then allow to enable MSAA on new Intel GPUs.
|
|
|
|
*/
|
|
|
|
bool fAllowMSAAOnNewIntel = false;
|
|
|
|
|
2021-06-04 18:45:05 +00:00
|
|
|
#if GR_TEST_UTILS
|
2017-02-22 19:00:42 +00:00
|
|
|
/**
|
2017-08-30 19:14:04 +00:00
|
|
|
* Private options that are only meant for testing within Skia's tools.
|
2017-02-22 19:00:42 +00:00
|
|
|
*/
|
|
|
|
|
2017-05-04 00:08:42 +00:00
|
|
|
/**
|
2017-08-30 19:14:04 +00:00
|
|
|
* Prevents use of dual source blending, to test that all xfer modes work correctly without it.
|
2017-05-04 00:08:42 +00:00
|
|
|
*/
|
2017-08-30 19:14:04 +00:00
|
|
|
bool fSuppressDualSourceBlending = false;
|
2017-05-08 19:02:07 +00:00
|
|
|
|
2021-06-24 23:19:00 +00:00
|
|
|
/**
|
|
|
|
* Prevents the use of non-coefficient-based blend equations, for testing dst reads, barriers,
|
|
|
|
* and in-shader blending.
|
|
|
|
*/
|
|
|
|
bool fSuppressAdvancedBlendEquations = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prevents the use of framebuffer fetches, for testing dst reads and texture barriers.
|
|
|
|
*/
|
|
|
|
bool fSuppressFramebufferFetch = false;
|
|
|
|
|
2020-09-23 17:55:27 +00:00
|
|
|
/**
|
|
|
|
* If true, then all paths are processed as if "setIsVolatile" had been called.
|
|
|
|
*/
|
|
|
|
bool fAllPathsVolatile = false;
|
|
|
|
|
2017-08-30 19:14:04 +00:00
|
|
|
/**
|
|
|
|
* Render everything in wireframe
|
|
|
|
*/
|
|
|
|
bool fWireframeMode = false;
|
|
|
|
|
2019-07-16 15:52:08 +00:00
|
|
|
/**
|
|
|
|
* Enforces clearing of all textures when they're created.
|
|
|
|
*/
|
|
|
|
bool fClearAllTextures = false;
|
|
|
|
|
2020-06-24 14:19:52 +00:00
|
|
|
/**
|
|
|
|
* Randomly generate a (false) GL_OUT_OF_MEMORY error
|
|
|
|
*/
|
|
|
|
bool fRandomGLOOM = false;
|
|
|
|
|
2021-01-31 18:16:39 +00:00
|
|
|
/**
|
2021-06-07 17:39:27 +00:00
|
|
|
* Force off support for write/transfer pixels row bytes in caps.
|
2021-01-31 18:16:39 +00:00
|
|
|
*/
|
2021-06-07 17:39:27 +00:00
|
|
|
bool fDisallowWriteAndTransferPixelRowBytes = false;
|
2021-01-31 18:16:39 +00:00
|
|
|
|
2017-08-30 19:14:04 +00:00
|
|
|
/**
|
|
|
|
* Include or exclude specific GPU path renderers.
|
|
|
|
*/
|
2019-12-28 21:51:11 +00:00
|
|
|
GpuPathRenderers fGpuPathRenderers = GpuPathRenderers::kDefault;
|
2021-04-14 15:52:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Specify the GPU resource cache limit. Equivalent to calling `setResourceCacheLimit` on the
|
|
|
|
* context at construction time.
|
|
|
|
*
|
|
|
|
* A value of -1 means use the default limit value.
|
|
|
|
*/
|
|
|
|
int fResourceCacheLimitOverride = -1;
|
2021-05-25 16:11:46 +00:00
|
|
|
|
2021-06-24 00:47:09 +00:00
|
|
|
/**
|
|
|
|
* Maximum width and height of internal texture atlases.
|
|
|
|
*/
|
|
|
|
int fMaxTextureAtlasSize = 2048;
|
2017-08-30 19:14:04 +00:00
|
|
|
#endif
|
2017-12-13 15:59:33 +00:00
|
|
|
|
2018-05-14 21:02:03 +00:00
|
|
|
GrDriverBugWorkarounds fDriverBugWorkarounds;
|
|
|
|
};
|
|
|
|
#else
|
|
|
|
struct GrContextOptions {
|
|
|
|
struct PersistentCache {};
|
2017-08-30 19:14:04 +00:00
|
|
|
};
|
2018-05-14 21:02:03 +00:00
|
|
|
#endif
|
2017-02-22 19:00:42 +00:00
|
|
|
|
2015-05-22 21:01:46 +00:00
|
|
|
#endif
|