Debian Codegraph @

include/gpu/graphite/GraphiteTypes.h

raw
1 /*
2 * Copyright 2021 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_GraphiteTypes_DEFINED
9 #define skgpu_graphite_GraphiteTypes_DEFINED
10
11 #include "include/core/SkPoint.h"
12 #include "include/core/SkRect.h"
13 #include "include/core/SkTypes.h"
14 #include "include/gpu/GpuTypes.h"
15
16 #include <memory>
17
18 class SkSurface;
19
20 namespace skgpu {
21 class MutableTextureState;
22 }
23
24 namespace skgpu::graphite {
25
26 class BackendSemaphore;
27 class Recording;
28 class Task;
29
30 using GpuFinishedContext = void*;
31 using GpuFinishedProc = void (*)(GpuFinishedContext finishedContext, CallbackResult);
32
33 using GpuFinishedWithStatsProc = void (*)(GpuFinishedContext finishedContext,
34 CallbackResult,
35 const GpuStats&);
36
37 // NOTE: This can be converted to just an `enum class InsertStatus {}` once clients are migrated
38 // off of assuming `Context::insertRecording()` returns a boolean.
39 class InsertStatus {
40 public:
41 // Do not refer to V directly; use these constants as if InsertStatus were a class enum, e.g.
42 // InsertStatus::kSuccess.
43 enum V {
44 // Everything successfully added to underlying CommandBuffer
45 kSuccess,
46 // Recording or InsertRecordingInfo invalid, no CB changes
47 kInvalidRecording,
48 // Promise image instantiation failed, no CB changes
49 kPromiseImageInstantiationFailed,
50 // Internal failure, CB partially modified, state unrecoverable or unknown (e.g. dependent
51 // texture uploads for future Recordings may or may not get executed)
52 kAddCommandsFailed,
53 // Internal failure, shader pipeline compilation failed (driver issue, or disk corruption),
54 // state unrecoverable.
55 kAsyncShaderCompilesFailed,
56 // The inserted Recording is out of order from what the Context expects (when
57 // `[Context|Recorder]Options::fRequireOrderedRecordings` is true), which can either
58 // represent a client synchronization error or an internal failure when a prior dependent
59 // Recording failed for some reason, no CB changes but state likely unrecoverable.
60 kOutOfOrderRecording,
61 };
62
63 constexpr InsertStatus() : fValue(kSuccess) {}
64 /*implicit*/ constexpr InsertStatus(V v) : fValue(v) {}
65
66 operator InsertStatus::V() const {
67 return fValue;
68 }
69
70 // Assist migration from old bool return value of insertRecording; kSuccess is true,
71 // all other error statuses are false.
72 // NOTE: This is intentionally not explicit so that InsertStatus can be assigned correctly to
73 // a bool or returned as a bool, since these are not boolean contexts that automatically apply
74 // explicit bool operators (e.g. inside an if condition).
75 operator bool() const {
76 return fValue == kSuccess;
77 }
78
79 private:
80 V fValue;
81 };
82
83 /**
84 * The fFinishedProc is called when the Recording has been submitted and finished on the GPU, or
85 * when there is a failure that caused it not to be submitted. The callback will always be called
86 * and the caller can use the callback to know it is safe to free any resources associated with
87 * the Recording that they may be holding onto. If the Recording is successfully submitted to the
88 * GPU the callback will be called with CallbackResult::kSuccess once the GPU has finished. All
89 * other cases where some failure occurred it will be called with CallbackResult::kFailed.
90 *
91 * Alternatively, the client can provide fFinishedProcWithStats. This provides additional
92 * information about execution of the recording on the GPU. Only the stats requested using
93 * fStatsFlags will be valid and only if CallbackResult is kSuccess. If both fFinishedProc
94 * and fFinishedProcWithStats are provided the latter is preferred and the former won't be
95 * called.
96 *
97 * The fTargetSurface, if provided, is used as a target for any draws recorded onto a deferred
98 * canvas returned from Recorder::makeDeferredCanvas. This target surface must be provided iff
99 * the Recording contains any such draws. It must be Graphite-backed and its backing texture's
100 * TextureInfo must match the info provided to the Recorder when making the deferred canvas.
101 *
102 * fTargetTranslation is an additional translation applied to draws targeting fTargetSurface.
103 *
104 * fTargetClip is an additional clip applied to draws targeting fTargetSurface. It is defined in the
105 * local replay space, that is, with fTargetTranslation applied. An empty clip will not be applied.
106 *
107 * The client may pass in two arrays of initialized BackendSemaphores to be included in the
108 * command stream. At some time before issuing commands in the Recording, the fWaitSemaphores will
109 * be waited on by the gpu. We only guarantee these wait semaphores block transfer and fragment
110 * shader work. Similarly, at some time after issuing the Recording's commands, the
111 * fSignalSemaphores will be signaled by the gpu. Depending on the platform, the timing of the wait
112 * and signal operations will either be immediately before or after the given Recording's command
113 * stream, respectively, or before and after the entire CommandBuffer's command stream. The
114 * semaphores are not sent to the GPU until the next Context::submit call is made.
115 *
116 * The client will own and be responsible for deleting the underlying semaphore objects after the
117 * submission completes, however the BackendSemaphore objects themselves can be deleted as soon
118 * as this function returns.
119 */
120 struct InsertRecordingInfo {
121 Recording* fRecording = nullptr;
122
123 SkSurface* fTargetSurface = nullptr;
124 SkIVector fTargetTranslation = {0, 0};
125 SkIRect fTargetClip = {0, 0, 0, 0};
126 MutableTextureState* fTargetTextureState = nullptr;
127
128 size_t fNumWaitSemaphores = 0;
129 BackendSemaphore* fWaitSemaphores = nullptr;
130 size_t fNumSignalSemaphores = 0;
131 BackendSemaphore* fSignalSemaphores = nullptr;
132
133 GpuStatsFlags fGpuStatsFlags = GpuStatsFlags::kNone;
134 GpuFinishedContext fFinishedContext = nullptr;
135 GpuFinishedProc fFinishedProc = nullptr;
136 GpuFinishedWithStatsProc fFinishedWithStatsProc = nullptr;
137
138 // For unit testing purposes, this can be used to induce a known failure status from
139 // Context::insertRecording(). When this set to anything other than kSuccess, insertRecording()
140 // will operate as normal until the first condition that would normally return the simulated
141 // status is encountered. At that point, operations are treated as if that condition had failed.
142 // This leaves the Context in a state consistent with encountering the InsertStatus in a normal
143 // application.
144 //
145 // NOTE: If the simulated failure status is one of the later error codes but the inserted
146 // Recording would fail with an earlier error code normally, that error is still returned.
147 InsertStatus fSimulatedStatus = InsertStatus::kSuccess;
148 };
149
150 /**
151 * The fFinishedProc is called when the Recording has been submitted and finished on the GPU, or
152 * when there is a failure that caused it not to be submitted. The callback will always be called
153 * and the caller can use the callback to know it is safe to free any resources associated with
154 * the Recording that they may be holding onto. If the Recording is successfully submitted to the
155 * GPU the callback will be called with CallbackResult::kSuccess once the GPU has finished. All
156 * other cases where some failure occured it will be called with CallbackResult::kFailed.
157 */
158 struct InsertFinishInfo {
159 InsertFinishInfo() = default;
160 InsertFinishInfo(GpuFinishedContext context, GpuFinishedProc proc)
161 : fFinishedContext{context}, fFinishedProc{proc} {}
162 InsertFinishInfo(GpuFinishedContext context, GpuFinishedWithStatsProc proc)
163 : fFinishedContext{context}, fFinishedWithStatsProc{proc} {}
164 GpuFinishedContext fFinishedContext = nullptr;
165 GpuFinishedProc fFinishedProc = nullptr;
166 GpuFinishedWithStatsProc fFinishedWithStatsProc = nullptr;
167 GpuStatsFlags fGpuStatsFlags = GpuStatsFlags::kNone;
168 };
169
170 /**
171 * Actually submit work to the GPU and track its completion
172 */
173 enum class SyncToCpu : bool {
174 kYes = true,
175 kNo = false
176 };
177
178 enum class MarkFrameBoundary : bool {
179 kYes = true,
180 kNo = false
181 };
182
183 struct SubmitInfo {
184 SyncToCpu fSync = SyncToCpu::kNo;
185 MarkFrameBoundary fMarkBoundary = MarkFrameBoundary::kNo;
186 uint64_t fFrameID = 0;
187
188 constexpr SubmitInfo() = default;
189
190 constexpr SubmitInfo(SyncToCpu sync)
191 : fSync(sync)
192 , fMarkBoundary(MarkFrameBoundary::kNo)
193 , fFrameID(0) {}
194
195 constexpr SubmitInfo(SyncToCpu sync, uint64_t frameID)
196 : fSync(sync)
197 , fMarkBoundary(MarkFrameBoundary::kYes)
198 , fFrameID(frameID) {}
199 };
200
201 /*
202 * For Promise Images - should the Promise Image be fulfilled every time a Recording that references
203 * it is inserted into the Context.
204 */
205 enum class Volatile : bool {
206 kNo = false, // only fulfilled once
207 kYes = true // fulfilled on every insertion call
208 };
209
210 enum class DepthStencilFlags : int {
211 kNone = 0b000,
212 kDepth = 0b001,
213 kStencil = 0b010,
214 kDepthStencil = kDepth | kStencil,
215 };
216
217 enum class SampleCount : uint8_t {
218 k1 = 1,
219 k2 = 2,
220 k4 = 4,
221 k8 = 8,
222 k16 = 16
223 };
224
225 /**
226 * Convert an integer value to a strictly typed SampleCount value, rounding down to the lowest
227 * valid sample count if needed if `sampleCount` is not already equivalent.
228 */
229 constexpr SampleCount ToSampleCount(uint32_t sampleCount) {
230 return sampleCount >= 16 ? SampleCount::k16 :
231 sampleCount >= 8 ? SampleCount::k8 :
232 sampleCount >= 4 ? SampleCount::k4 :
233 sampleCount >= 2 ? SampleCount::k2 :
234 SampleCount::k1;
235 }
236
237 /*
238 * This enum allows mapping from a set of observed RenderSteps (e.g., from a GraphicsPipeline
239 * printout) to the correct 'drawTypes' parameter needed by the Precompilation API.
240 */
241 enum DrawTypeFlags : uint16_t {
242
243 kNone = 0,
244
245 // kBitmapText_Mask should be used for the BitmapTextRenderStep[mask] RenderStep
246 kBitmapText_Mask = 1 << 0,
247 // kBitmapText_LCD should be used for the BitmapTextRenderStep[LCD] RenderStep
248 kBitmapText_LCD = 1 << 1,
249 // kBitmapText_Color should be used for the BitmapTextRenderStep[color] RenderStep
250 kBitmapText_Color = 1 << 2,
251 // kSDFText should be used for the SDFTextRenderStep RenderStep
252 kSDFText = 1 << 3,
253 // kSDFText_LCD should be used for the SDFTextLCDRenderStep RenderStep
254 kSDFText_LCD = 1 << 4,
255
256 // kDrawVertices should be used to generate Pipelines that use the following RenderSteps:
257 // VerticesRenderStep[*] for:
258 // [Tris], [TrisTexCoords], [TrisColor], [TrisColorTexCoords],
259 // [Tristrips], [TristripsTexCoords], [TristripsColor], [TristripsColorTexCoords]
260 kDrawVertices = 1 << 5,
261
262 // kCircularArc renders filled circular arcs, with or without the center included, and
263 // stroked circular arcs with butt or round caps that don't include the center point.
264 // It corresponds to the CircularArcRenderStep.
265 kCircularArc = 1 << 6,
266
267 // kSimpleShape should be used to generate Pipelines that use the following RenderSteps:
268 // AnalyticRRectRenderStep
269 // PerEdgeAAQuadRenderStep
270 // CoverBoundsRenderStep[NonAAFill]
271 kAnalyticRRect = 1 << 7,
272 kPerEdgeAAQuad = 1 << 8,
273 kNonAAFillRect = 1 << 9,
274
275 kSimpleShape = kAnalyticRRect | kPerEdgeAAQuad | kNonAAFillRect,
276
277 // kNonSimpleShape should be used to generate Pipelines that use the following RenderSteps:
278 // CoverageMaskRenderStep
279 // CoverBoundsRenderStep[*] for [InverseCover], [RegularCover]
280 // TessellateStrokeRenderStep
281 // TessellateWedgesRenderStep[*] for [Convex], [EvenOdd], [Winding]
282 // TessellateCurvesRenderStep[*] for [EvenOdd], [Winding]
283 // MiddleOutFanRenderStep[*] for [EvenOdd], [Winding]
284 kNonSimpleShape = 1 << 10,
285
286 // This draw type covers all the methods Skia uses to draw drop shadows. It can be used to
287 // generate Pipelines which, as part of their labels, have:
288 // the AnalyticBlurRenderStep
289 // VerticesRenderStep[TrisColor] with a GaussianColorFilter
290 // For this draw type the PaintOptions parameter to Precompile() will be ignored.
291 kDropShadows = 1 << 11,
292
293 // kAnalyticClip should be combined with the primary drawType for Pipelines that contain
294 // either of the following sub-strings:
295 // AnalyticClip
296 // AnalyticAndAtlasClip
297 kAnalyticClip = 1 << 12,
298
299 kLast = kAnalyticClip,
300 };
301
302 } // namespace skgpu::graphite
303
304 #endif // skgpu_graphite_GraphiteTypes_DEFINED