xref: /aosp_15_r20/external/skia/include/gpu/graphite/ContextOptions.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2022 Google LLC
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 skgpu_graphite_ContextOptions_DEFINED
9 #define skgpu_graphite_ContextOptions_DEFINED
10 
11 #include "include/private/base/SkAPI.h"
12 #include "include/private/base/SkMath.h"
13 
14 #include <optional>
15 
16 namespace skgpu { class ShaderErrorHandler; }
17 
18 namespace skgpu::graphite {
19 
20 struct ContextOptionsPriv;
21 
22 struct SK_API ContextOptions {
ContextOptionsContextOptions23     ContextOptions() {}
24 
25     /**
26      * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers.
27      * This does not affect code path choices that are made for perfomance reasons nor does it
28      * override other ContextOption settings.
29      */
30     bool fDisableDriverCorrectnessWorkarounds = false;
31 
32     /**
33      * If present, use this object to report shader compilation failures. If not, report failures
34      * via SkDebugf and assert.
35      */
36     skgpu::ShaderErrorHandler* fShaderErrorHandler = nullptr;
37 
38     /**
39      * Specifies the number of samples Graphite should use when performing internal draws with MSAA
40      * (hardware capabilities permitting).
41      *
42      * If <= 1, Graphite will disable internal code paths that use multisampling.
43      */
44     int fInternalMultisampleCount = 4;
45 
46     /**
47      * Will the client make sure to only ever be executing one thread that uses the Context and all
48      * derived classes (e.g. Recorders, Recordings, etc.) at a time. If so we can possibly make some
49      * objects (e.g. VulkanMemoryAllocator) not thread safe to improve single thread performance.
50      */
51     bool fClientWillExternallySynchronizeAllThreads = false;
52 
53     /**
54      * The maximum size of cache textures used for Skia's Glyph cache.
55      */
56     size_t fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4;
57 
58     /**
59      * Below this threshold size in device space distance field fonts won't be used. Distance field
60      * fonts don't support hinting which is more important at smaller sizes.
61      */
62     float fMinDistanceFieldFontSize = 18;
63 
64     /**
65      * Above this threshold size in device space glyphs are drawn as individual paths.
66      */
67 #if defined(SK_BUILD_FOR_ANDROID)
68     float fGlyphsAsPathsFontSize = 384;
69 #elif defined(SK_BUILD_FOR_MAC)
70     float fGlyphsAsPathsFontSize = 256;
71 #else
72     float fGlyphsAsPathsFontSize = 324;
73 #endif
74 
75     /**
76      * The maximum size of textures used for Skia's PathAtlas caches.
77      */
78     int fMaxPathAtlasTextureSize = 8192;  // oversized, PathAtlas will likely be smaller
79 
80     /**
81      * Can the glyph and path atlases use multiple textures. If allowed, each texture's size is
82      * bound by fGlyphCacheTextureMaximumBytes and fMaxPathAtlasTextureSize, respectively.
83      */
84     bool fAllowMultipleAtlasTextures = true;
85     bool fSupportBilerpFromGlyphAtlas = false;
86 
87     /**
88      * Disable caching of glyph uploads at the start of each Recording. These can add additional
89      * overhead and are only necessary if Recordings are replayed or played out of order.
90      *
91      * Deprecated, now only used to set requireOrderedRecordings Caps.
92      */
93     bool fDisableCachedGlyphUploads = false;
94 
95     static constexpr size_t kDefaultContextBudget = 256 * (1 << 20);
96     /**
97      * What is the budget for GPU resources allocated and held by the Context.
98      */
99     size_t fGpuBudgetInBytes = kDefaultContextBudget;
100 
101     /**
102      * Whether labels will be set on backend resources.
103      */
104 #if defined(SK_DEBUG)
105     bool fSetBackendLabels = true;
106 #else
107     bool fSetBackendLabels = false;
108 #endif
109 
110     /**
111      * If Skia is creating a default VMA allocator for the Vulkan backend this value will be used
112      * for the preferredLargeHeapBlockSize. If the value is not set, then Skia will use an
113      * inernally defined default size.
114      *
115      * However, it is highly discouraged to have Skia make a default allocator (and support for
116      * doing so will be removed soon,  b/321962001). Instead clients should create their own
117      * allocator to pass into Skia where they can fine tune this value themeselves.
118      */
119     std::optional<uint64_t> fVulkanVMALargeHeapBlockSize;
120 
121     /**
122      * Private options that are only meant for testing within Skia's tools.
123      */
124     ContextOptionsPriv* fOptionsPriv = nullptr;
125 };
126 
127 }  // namespace skgpu::graphite
128 
129 #endif  // skgpu_graphite_ContextOptions
130