• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/SkSpan.h"
13 #include "include/private/base/SkAPI.h"
14 #include "include/private/base/SkMath.h"
15 
16 #include <optional>
17 
18 class SkData;
19 class SkRuntimeEffect;
20 namespace skgpu { class ShaderErrorHandler; }
21 
22 namespace skgpu::graphite {
23 
24 struct ContextOptionsPriv;
25 
26 struct SK_API ContextOptions {
ContextOptionsContextOptions27     ContextOptions() {}
28 
29     /**
30      * Disables correctness workarounds that are enabled for particular GPUs, OSes, or drivers.
31      * This does not affect code path choices that are made for perfomance reasons nor does it
32      * override other ContextOption settings.
33      */
34     bool fDisableDriverCorrectnessWorkarounds = false;
35 
36     /**
37      * If present, use this object to report shader compilation failures. If not, report failures
38      * via SkDebugf and assert.
39      */
40     skgpu::ShaderErrorHandler* fShaderErrorHandler = nullptr;
41 
42     /**
43      * Specifies the number of samples Graphite should use when performing internal draws with MSAA
44      * (hardware capabilities permitting).
45      *
46      * If <= 1, Graphite will disable internal code paths that use multisampling.
47      */
48     int fInternalMultisampleCount = 4;
49 
50     /**
51      * Will the client make sure to only ever be executing one thread that uses the Context and all
52      * derived classes (e.g. Recorders, Recordings, etc.) at a time. If so we can possibly make some
53      * objects (e.g. VulkanMemoryAllocator) not thread safe to improve single thread performance.
54      */
55     bool fClientWillExternallySynchronizeAllThreads = false;
56 
57     /**
58      * The maximum size of cache textures used for Skia's Glyph cache.
59      */
60     size_t fGlyphCacheTextureMaximumBytes = 2048 * 1024 * 4;
61 
62     /**
63      * Below this threshold size in device space distance field fonts won't be used. Distance field
64      * fonts don't support hinting which is more important at smaller sizes.
65      */
66     float fMinDistanceFieldFontSize = 18;
67 
68     /**
69      * Above this threshold size in device space glyphs are drawn as individual paths.
70      */
71 #if defined(SK_BUILD_FOR_ANDROID)
72     float fGlyphsAsPathsFontSize = 384;
73 #elif defined(SK_BUILD_FOR_MAC)
74     float fGlyphsAsPathsFontSize = 256;
75 #else
76     float fGlyphsAsPathsFontSize = 324;
77 #endif
78 
79     /**
80      * The maximum size of textures used for Skia's PathAtlas caches.
81      */
82     int fMaxPathAtlasTextureSize = 8192;  // oversized, PathAtlas will likely be smaller
83 
84     /**
85      * Can the glyph and path atlases use multiple textures. If allowed, each texture's size is
86      * bound by fGlyphCacheTextureMaximumBytes and fMaxPathAtlasTextureSize, respectively.
87      */
88     bool fAllowMultipleAtlasTextures = true;
89     bool fSupportBilerpFromGlyphAtlas = false;
90 
91     /**
92      * For the moment, if Recordings are replayed in the order they are recorded, then
93      * Graphite can make certain assumptions that allow for better performance. Otherwise
94      * we have to flush some caches at the start of each Recording to ensure that they can
95      * be played back properly.
96      */
97     bool fRequireOrderedRecordings = false;
98 
99     static constexpr size_t kDefaultContextBudget = 256 * (1 << 20);
100     /**
101      * What is the budget for GPU resources allocated and held by the Context.
102      */
103     size_t fGpuBudgetInBytes = kDefaultContextBudget;
104 
105     /**
106      * Whether labels will be set on backend resources.
107      */
108 #if defined(SK_DEBUG)
109     bool fSetBackendLabels = true;
110 #else
111     bool fSetBackendLabels = false;
112 #endif
113 
114     /**
115      * If Skia is creating a default VMA allocator for the Vulkan backend this value will be used
116      * for the preferredLargeHeapBlockSize. If the value is not set, then Skia will use an
117      * inernally defined default size.
118      *
119      * However, it is highly discouraged to have Skia make a default allocator (and support for
120      * doing so will be removed soon,  b/321962001). Instead clients should create their own
121      * allocator to pass into Skia where they can fine tune this value themeselves.
122      */
123     std::optional<uint64_t> fVulkanVMALargeHeapBlockSize;
124 
125     /** Client-provided context that is passed to client-provided PipelineCallback. */
126     using PipelineCallbackContext = void*;
127     /**  Client-provided callback that is called whenever Graphite encounters a new Pipeline. */
128     using PipelineCallback = void (*)(PipelineCallbackContext context, sk_sp<SkData> pipelineData);
129 
130     /**
131      *  These two members allow a client to register a callback that will be invoked
132      *  whenever Graphite encounters a new Pipeline. The callback will be passed an
133      *  sk_sp<SkData> that a client can take ownership of and serialize. The SkData
134      *  contains all the information Graphite requires to recreate the Pipeline at
135      *  a later date. The SkData is versioned however, so must be regenerated and
136      *  re-serialized when it becomes out of date.
137      */
138     PipelineCallbackContext fPipelineCallbackContext = nullptr;
139     PipelineCallback fPipelineCallback = nullptr;
140 
141     /**
142      * The runtime effects provided here will be registered as user-defined *known* runtime
143      * effects and will be given a stable key. Such runtime effects can then be used in
144      * serialized pipeline keys (c.f. PrecompileContext::precompile).
145      *
146      * Graphite will take a ref on the provided runtime effects and they will persist for as long
147      * as the Context exists. Rather than recreating new SkRuntimeEffects using the same SkSL,
148      * clients should use the existing SkRuntimeEffects provided here.
149      *
150      * Warning: Registering runtime effects here does obligate users to clear out their caches
151      * of serialized pipeline keys if the provided runtime effects ever change in a meaningful way.
152      * This includes adding, removing or reordering the effects provided here.
153      */
154     SkSpan<sk_sp<SkRuntimeEffect>> fUserDefinedKnownRuntimeEffects;
155 
156     /**
157      * Private options that are only meant for testing within Skia's tools.
158      */
159     ContextOptionsPriv* fOptionsPriv = nullptr;
160 };
161 
162 }  // namespace skgpu::graphite
163 
164 #endif  // skgpu_graphite_ContextOptions
165