Debian Codegraph @

include/gpu/graphite/ContextOptions.h

raw
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/core/SkRefCnt.h"
12 #include "include/core/SkSize.h"
13 #include "include/core/SkSpan.h"
14 #include "include/gpu/graphite/GraphiteTypes.h"
15 #include "include/private/base/SkAPI.h"
16 #include "include/private/base/SkMath.h"
17
18 #include <optional>
19 #include <string>
20
21 class SkData;
22 class SkExecutor;
23 class SkRuntimeEffect;
24 namespace skgpu { class ShaderErrorHandler; }
25
26 namespace skgpu::graphite {
27
28 struct ContextOptionsPriv;
29 class PersistentPipelineStorage;
30
31 struct SK_API ContextOptions {
32 ContextOptions() {}
33
34 /**
35 * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers.
36 * This does not affect code path choices that are made for perfomance reasons nor does it
37 * override other ContextOption settings.
38 */
39 bool fDisableDriverCorrectnessWorkarounds = false;
40
41 /**
42 * If present, use this object to report shader compilation failures. If not, report failures
43 * via SkDebugf and assert.
44 */
45 skgpu::ShaderErrorHandler* fShaderErrorHandler = nullptr;
46
47 /**
48 * Specifies the number of samples Graphite should use when performing internal draws with MSAA
49 * (hardware capabilities permitting). This represents the maximum that will be used; if a
50 * a specific format supports only lower values, those may be used instead.
51 *
52 * If <= 1, Graphite will disable internal code paths that use multisampling.
53 */
54 SampleCount fInternalMultisampleCount = SampleCount::k4;
55
56 /**
57 * If set, this specifies the max width/height of MSAA textures that Graphite should use for
58 * internal draws. Graphite might have to break the drawing region into multiple tiles to
59 * satisfy the size constraint.
60 * Note: this option will be ignored if the backend doesn't support it, or if a more optimal HW
61 * feature is available.
62 */
63 std::optional<SkISize> fInternalMSAATileSize = std::nullopt;
64
65 /**
66 * If set, paths that are smaller than this size (in device space) will avoid MSAA techniques,
67 * even if MSAA is otherwise enabled via `fInternalMultisampleCount`. This should be smaller
68 * than `fGlyphsAsPathsFontSize` or large glyphs will not correctly avoid higher memory
69 * overhead.
70 */
71 float fMinimumPathSizeForMSAA = 0;
72
73 /**
74 * The maximum size of cache textures used for Skia's Glyph cache.
75 */
76 size_t fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4;
77
78 /**
79 * Below this threshold size in device space distance field fonts won't be used. Distance field
80 * fonts don't support hinting which is more important at smaller sizes.
81 */
82 float fMinDistanceFieldFontSize = 18;
83
84 /**
85 * Above this threshold size in device space glyphs are drawn as individual paths.
86 */
87 #if defined(SK_BUILD_FOR_ANDROID)
88 float fGlyphsAsPathsFontSize = 384;
89 #elif defined(SK_BUILD_FOR_MAC)
90 float fGlyphsAsPathsFontSize = 256;
91 #else
92 float fGlyphsAsPathsFontSize = 324;
93 #endif
94
95 /**
96 * The maximum size of textures used for Skia's PathAtlas caches.
97 */
98 int fMaxPathAtlasTextureSize = 8192; // oversized, PathAtlas will likely be smaller
99
100 /**
101 * Can the glyph and path atlases use multiple textures. If allowed, each texture's size is
102 * bound by fGlyphCacheTextureMaximumBytes and fMaxPathAtlasTextureSize, respectively.
103 */
104 bool fAllowMultipleAtlasTextures = true;
105 bool fSupportBilerpFromGlyphAtlas = false;
106
107 /**
108 * For the moment, if Recordings from the same Recorder are replayed in the order they are
109 * recorded, then Graphite can make certain assumptions that allow for better performance.
110 * Otherwise we have to flush some caches at the start of each Recording to ensure that they can
111 * be played back properly.
112 *
113 * This is the default ordering requirement for a Recorder. It can be overridden by
114 * setting the same field on the RecorderOptions passed to makeRecorder.
115 *
116 * Regardless of this value or a per-Recorder's setting, Recordings from separate Recorders can
117 * always be inserted in any order but it is the application's responsible to ensure that any
118 * implicit dependencies between the Recorders are respected (e.g. rendering to an SkSurface
119 * in one Recorder and sampling from that SkSurface's SkImage view on another Recorder).
120 */
121 bool fRequireOrderedRecordings = false;
122
123 static constexpr size_t kDefaultContextBudget = 256 * (1 << 20);
124 /**
125 * What is the budget for GPU resources allocated and held by the Context.
126 */
127 size_t fGpuBudgetInBytes = kDefaultContextBudget;
128
129 /**
130 * Whether labels will be set on backend resources.
131 */
132 #if defined(SK_DEBUG)
133 bool fSetBackendLabels = true;
134 #else
135 bool fSetBackendLabels = false;
136 #endif
137
138 /**
139 * Client-provided context that is passed to the client-provided PipelineCachingCallback
140 * and the (deprecated) PipelineCallback.
141 */
142 using PipelineCallbackContext = void*;
143
144 PipelineCallbackContext fPipelineCallbackContext = nullptr;
145
146 enum class PipelineCacheOp {
147 kAddingPipeline,
148 kPipelineFound,
149 };
150
151 using PipelineCachingCallback = void (*)(PipelineCallbackContext context,
152 PipelineCacheOp op,
153 const std::string& label,
154 uint32_t uniqueKeyHash,
155 bool fromPrecompile,
156 sk_sp<SkData> pipelineData);
157
158 /**
159 * This member variable allows a client to register a callback that will be invoked
160 * whenever Graphite either adds a Pipeline to its cache (kAddingPipeline op) or finds an
161 * existing Pipeline in its cache (kPipelineFound op). Together this allows clients
162 * to determine the frequency of a given Pipeline's use and which precompiled Pipelines
163 * are unused. The callback is also passed:
164 * a human-readable label that describes the Pipeline
165 * a 32-bit hash code that can be used rather than rehashing the provided data
166 * a Boolean indicating if the Pipeline had been generated via Precompilation
167 * Additionally, for kAddingPipeline ops:
168 * an SkData version of the Pipeline that a client can take ownership of and serialize.
169 * Not all Pipelines can be serialized, however, and nullptr will be passed in such cases.
170 *
171 * When provided, the SkData contains all the information Graphite requires to recreate
172 * the Pipeline at a later date, but it is versioned so recreation can fail if it's
173 * incompatible with a newer version of Skia.
174 */
175 PipelineCachingCallback fPipelineCachingCallback = nullptr;
176
177 /**
178 * Deprecated version of the Pipeline callback. This callback is only invoked for
179 * PipelineCacheOp::kAddingPipeline ops and when the key is serializable. It is ignored
180 * if fPipelineCachingCallback is set.
181 */
182 using PipelineCallback = void (*)(PipelineCallbackContext context, sk_sp<SkData> pipelineData);
183
184 PipelineCallback fPipelineCallback = nullptr;
185
186 /**
187 * The runtime effects provided here will be registered as user-defined *known* runtime
188 * effects and will be given a stable key. Such runtime effects can then be used in
189 * serialized pipeline keys (c.f. PrecompileContext::precompile).
190 *
191 * Graphite will take a ref on the provided runtime effects and they will persist for as long
192 * as the Context exists. Rather than recreating new SkRuntimeEffects using the same SkSL,
193 * clients should use the existing SkRuntimeEffects provided here.
194 *
195 * Warning: Registering runtime effects here does obligate users to clear out their caches
196 * of serialized pipeline keys if the provided runtime effects ever change in a meaningful way.
197 * This includes adding, removing or reordering the effects provided here.
198 */
199 SkSpan<sk_sp<SkRuntimeEffect>> fUserDefinedKnownRuntimeEffects;
200
201 /**
202 * Executor to handle threaded work within Graphite. If this is nullptr, then all work will be
203 * done serially on the main thread. To have worker threads assist with various tasks, set this
204 * to a valid SkExecutor instance. Currently, used for Pipeline compilation, but may be used
205 * for other tasks. It is up to the client to ensure the SkExecutor remains valid throughout
206 * the lifetime of the Context.
207 */
208 SkExecutor* fExecutor = nullptr;
209
210 /**
211 * Allows Graphite to store Pipeline data across Context lifetimes. It is up to the
212 * client to ensure the PersistentPipelineStorage object remains valid throughout the lifetime
213 * of the Context(s).
214 */
215 PersistentPipelineStorage* fPersistentPipelineStorage = nullptr;
216
217 /**
218 * An experimental flag in development. Behavior and performance is subject to change.
219 *
220 * Enables the use of startCapture and endCapture functions. Calling these APIs will capture all
221 * draw calls and surface creation from Recorders spawned from the Context.
222 */
223 bool fEnableCapture = false;
224
225 /**
226 * Private options that are only meant for testing within Skia's tools.
227 */
228 ContextOptionsPriv* fOptionsPriv = nullptr;
229 };
230
231 } // namespace skgpu::graphite
232
233 #endif // skgpu_graphite_ContextOptions