xref: /aosp_15_r20/external/skia/include/gpu/graphite/GraphiteTypes.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 /**
38  * The fFinishedProc is called when the Recording has been submitted and finished on the GPU, or
39  * when there is a failure that caused it not to be submitted. The callback will always be called
40  * and the caller can use the callback to know it is safe to free any resources associated with
41  * the Recording that they may be holding onto. If the Recording is successfully submitted to the
42  * GPU the callback will be called with CallbackResult::kSuccess once the GPU has finished. All
43  * other cases where some failure occurred it will be called with CallbackResult::kFailed.
44  *
45  * Alternatively, the client can provide fFinishedProcWithStats. This provides additional
46  * information about execution of the recording on the GPU. Only the stats requested using
47  * fStatsFlags will be valid and only if CallbackResult is kSuccess. If both fFinishedProc
48  * and fFinishedProcWithStats are provided the latter is preferred and the former won't be
49  * called.
50  *
51  * The fTargetSurface, if provided, is used as a target for any draws recorded onto a deferred
52  * canvas returned from Recorder::makeDeferredCanvas. This target surface must be provided iff
53  * the Recording contains any such draws. It must be Graphite-backed and its backing texture's
54  * TextureInfo must match the info provided to the Recorder when making the deferred canvas.
55  *
56  * fTargetTranslation is an additional translation applied to draws targeting fTargetSurface.
57  *
58  * fTargetClip is an additional clip applied to draws targeting fTargetSurface. It is defined in the
59  * local replay space, that is, with fTargetTranslation applied. An empty clip will not be applied.
60  *
61  * The client may pass in two arrays of initialized BackendSemaphores to be included in the
62  * command stream. At some time before issuing commands in the Recording, the fWaitSemaphores will
63  * be waited on by the gpu. We only guarantee these wait semaphores block transfer and fragment
64  * shader work. Similarly, at some time after issuing the Recording's commands, the
65  * fSignalSemaphores will be signaled by the gpu. Depending on the platform, the timing of the wait
66  * and signal operations will either be immediately before or after the given Recording's command
67  * stream, respectively, or before and after the entire CommandBuffer's command stream. The
68  * semaphores are not sent to the GPU until the next Context::submit call is made.
69  *
70  * The client will own and be responsible for deleting the underlying semaphore objects after the
71  * submission completes, however the BackendSemaphore objects themselves can be deleted as soon
72  * as this function returns.
73  */
74 struct InsertRecordingInfo {
75     Recording* fRecording = nullptr;
76 
77     SkSurface* fTargetSurface = nullptr;
78     SkIVector fTargetTranslation = {0, 0};
79     SkIRect fTargetClip = {0, 0, 0, 0};
80     MutableTextureState* fTargetTextureState = nullptr;
81 
82     size_t fNumWaitSemaphores = 0;
83     BackendSemaphore* fWaitSemaphores = nullptr;
84     size_t fNumSignalSemaphores = 0;
85     BackendSemaphore* fSignalSemaphores = nullptr;
86 
87     GpuStatsFlags fGpuStatsFlags = GpuStatsFlags::kNone;
88     GpuFinishedContext fFinishedContext = nullptr;
89     GpuFinishedProc fFinishedProc = nullptr;
90     GpuFinishedWithStatsProc fFinishedWithStatsProc = nullptr;
91 };
92 
93 /**
94  * The fFinishedProc is called when the Recording has been submitted and finished on the GPU, or
95  * when there is a failure that caused it not to be submitted. The callback will always be called
96  * and the caller can use the callback to know it is safe to free any resources associated with
97  * the Recording that they may be holding onto. If the Recording is successfully submitted to the
98  * GPU the callback will be called with CallbackResult::kSuccess once the GPU has finished. All
99  * other cases where some failure occured it will be called with CallbackResult::kFailed.
100  */
101 struct InsertFinishInfo {
102     InsertFinishInfo() = default;
InsertFinishInfoInsertFinishInfo103     InsertFinishInfo(GpuFinishedContext context, GpuFinishedProc proc)
104             : fFinishedContext{context}, fFinishedProc{proc} {}
InsertFinishInfoInsertFinishInfo105     InsertFinishInfo(GpuFinishedContext context, GpuFinishedWithStatsProc proc)
106             : fFinishedContext{context}, fFinishedWithStatsProc{proc} {}
107     GpuFinishedContext fFinishedContext = nullptr;
108     GpuFinishedProc fFinishedProc = nullptr;
109     GpuFinishedWithStatsProc fFinishedWithStatsProc = nullptr;
110     GpuStatsFlags fGpuStatsFlags = GpuStatsFlags::kNone;
111 };
112 
113 /**
114  * Actually submit work to the GPU and track its completion
115  */
116 enum class SyncToCpu : bool {
117     kYes = true,
118     kNo = false
119 };
120 
121 /*
122  * For Promise Images - should the Promise Image be fulfilled every time a Recording that references
123  * it is inserted into the Context.
124  */
125 enum class Volatile : bool {
126     kNo = false,              // only fulfilled once
127     kYes = true               // fulfilled on every insertion call
128 };
129 
130 enum class DepthStencilFlags : int {
131     kNone         = 0b000,
132     kDepth        = 0b001,
133     kStencil      = 0b010,
134     kDepthStencil = kDepth | kStencil,
135 };
136 
137 /*
138  * This enum allows mapping from a set of observed RenderSteps (e.g., from a GraphicsPipeline
139  * printout) to the correct 'drawTypes' parameter needed by the Precompilation API.
140  */
141 enum DrawTypeFlags : uint16_t {
142 
143     kNone             = 0b000000000,
144 
145     // kBitmapText_Mask should be used for the BitmapTextRenderStep[mask] RenderStep
146     kBitmapText_Mask  = 0b00000001,
147     // kBitmapText_LCD should be used for the BitmapTextRenderStep[LCD] RenderStep
148     kBitmapText_LCD   = 0b00000010,
149     // kBitmapText_Color should be used for the BitmapTextRenderStep[color] RenderStep
150     kBitmapText_Color = 0b00000100,
151     // kSDFText should be used for the SDFTextRenderStep RenderStep
152     kSDFText          = 0b00001000,
153     // kSDFText_LCD should be used for the SDFTextLCDRenderStep RenderStep
154     kSDFText_LCD      = 0b00010000,
155 
156     // kDrawVertices should be used to generate Pipelines that use the following RenderSteps:
157     //    VerticesRenderStep[*] for:
158     //        [tris], [tris-texCoords], [tris-color], [tris-color-texCoords],
159     //        [tristrips], [tristrips-texCoords], [tristrips-color], [tristrips-color-texCoords]
160     kDrawVertices     = 0b00100000,
161 
162     // kSimpleShape should be used to generate Pipelines that use the following RenderSteps:
163     //    AnalyticBlurRenderStep
164     //    AnalyticRRectRenderStep
165     //    PerEdgeAAQuadRenderStep
166     //    CoverBoundsRenderStep[non-aa-fill]
167     kSimpleShape      = 0b01000000,
168 
169     // kNonSimpleShape should be used to generate Pipelines that use the following RenderSteps:
170     //    CoverageMaskRenderStep
171     //    CoverBoundsRenderStep[*] for [inverse-cover], [regular-cover]
172     //    TessellateStrokeRenderStep
173     //    TessellateWedgesRenderStep[*] for [convex], [evenodd], [winding]
174     //    TessellateCurvesRenderStep[*] for [even-odd], [winding]
175     //    MiddleOutFanRenderStep[*] for [even-odd], [winding]
176     kNonSimpleShape   = 0b10000000,
177 
178     kLast = kNonSimpleShape,
179 };
180 static constexpr int kDrawTypeFlagsCnt = static_cast<int>(DrawTypeFlags::kLast) + 1;
181 
182 } // namespace skgpu::graphite
183 
184 #endif // skgpu_graphite_GraphiteTypes_DEFINED
185