Flutter Engine
The Flutter Engine
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
skgpu::graphite::QueueManager Class Referenceabstract

#include <QueueManager.h>

Inheritance diagram for skgpu::graphite::QueueManager:
skgpu::graphite::DawnQueueManager skgpu::graphite::MtlQueueManager skgpu::graphite::VulkanQueueManager

Public Member Functions

virtual ~QueueManager ()
 
bool addRecording (const InsertRecordingInfo &, Context *)
 
bool addTask (Task *, Context *)
 
bool addFinishInfo (const InsertFinishInfo &, ResourceProvider *, SkSpan< const sk_sp< Buffer > > buffersToAsyncMap={})
 
bool submitToGpu ()
 
bool hasUnfinishedGpuWork ()
 
void checkForFinishedWork (SyncToCpu)
 
void returnCommandBuffer (std::unique_ptr< CommandBuffer >)
 
virtual void tick () const
 
void addUploadBufferManagerRefs (UploadBufferManager *)
 

Protected Types

using OutstandingSubmission = std::unique_ptr< GpuWorkSubmission >
 

Protected Member Functions

 QueueManager (const SharedContext *sharedContext)
 

Protected Attributes

const SharedContextfSharedContext
 
std::unique_ptr< CommandBufferfCurrentCommandBuffer
 

Private Member Functions

virtual std::unique_ptr< CommandBuffergetNewCommandBuffer (ResourceProvider *)=0
 
virtual OutstandingSubmission onSubmitToGpu ()=0
 

Detailed Description

Definition at line 32 of file QueueManager.h.

Member Typedef Documentation

◆ OutstandingSubmission

Definition at line 65 of file QueueManager.h.

Constructor & Destructor Documentation

◆ ~QueueManager()

skgpu::graphite::QueueManager::~QueueManager ( )
virtual

Definition at line 37 of file QueueManager.cpp.

37 {
40 } else if (!fOutstandingSubmissions.empty()) {
41 SKGPU_LOG_F("When ContextOptions::fNeverYieldToWebGPU is specified all GPU work must be "
42 "finished before destroying Context.");
43 }
44}
#define SKGPU_LOG_F(fmt,...)
Definition: Log.h:36
bool empty() const
Definition: SkDeque.h:38
bool allowCpuSync() const
Definition: Caps.h:232
const SharedContext * fSharedContext
Definition: QueueManager.h:67
void checkForFinishedWork(SyncToCpu)
const Caps * caps() const
Definition: SharedContext.h:39

◆ QueueManager()

skgpu::graphite::QueueManager::QueueManager ( const SharedContext sharedContext)
protected

Definition at line 32 of file QueueManager.cpp.

33 : fSharedContext(sharedContext)
34 , fOutstandingSubmissions(sizeof(OutstandingSubmission), kDefaultOutstandingAllocCnt) {
35}
std::unique_ptr< GpuWorkSubmission > OutstandingSubmission
Definition: QueueManager.h:65
static constexpr int kDefaultOutstandingAllocCnt

Member Function Documentation

◆ addFinishInfo()

bool skgpu::graphite::QueueManager::addFinishInfo ( const InsertFinishInfo info,
ResourceProvider resourceProvider,
SkSpan< const sk_sp< Buffer > >  buffersToAsyncMap = {} 
)

Definition at line 191 of file QueueManager.cpp.

193 {
195 if (info.fFinishedProc) {
196 callback = RefCntedCallback::Make(info.fFinishedProc, info.fFinishedContext);
197 }
198
199 if (!this->setupCommandBuffer(resourceProvider)) {
200 if (callback) {
201 callback->setFailureResult();
202 }
203 SKGPU_LOG_E("CommandBuffer creation failed");
204 return false;
205 }
206
207 if (callback) {
208 fCurrentCommandBuffer->addFinishedProc(std::move(callback));
209 }
210 fCurrentCommandBuffer->addBuffersToAsyncMapOnSubmit(buffersToAsyncMap);
211
212 return true;
213}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define SKGPU_LOG_E(fmt,...)
Definition: Log.h:38
static sk_sp< RefCntedCallback > Make(Callback proc, Context ctx)
std::unique_ptr< CommandBuffer > fCurrentCommandBuffer
Definition: QueueManager.h:68
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback

◆ addRecording()

bool skgpu::graphite::QueueManager::addRecording ( const InsertRecordingInfo info,
Context context 
)

Definition at line 66 of file QueueManager.cpp.

66 {
67 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
68
70 if (info.fFinishedProc) {
71 callback = RefCntedCallback::Make(info.fFinishedProc, info.fFinishedContext);
72 }
73
74 SkASSERT(info.fRecording);
75 if (!info.fRecording) {
76 if (callback) {
77 callback->setFailureResult();
78 }
79 SKGPU_LOG_E("No valid Recording passed into addRecording call");
80 return false;
81 }
82
84 uint32_t* recordingID = fLastAddedRecordingIDs.find(info.fRecording->priv().recorderID());
85 if (recordingID &&
86 info.fRecording->priv().uniqueID() != *recordingID+1) {
87 if (callback) {
88 callback->setFailureResult();
89 }
90 SKGPU_LOG_E("Recordings are expected to be replayed in order");
91 return false;
92 }
93
94 // Note the new Recording ID.
95 fLastAddedRecordingIDs.set(info.fRecording->priv().recorderID(),
96 info.fRecording->priv().uniqueID());
97 }
98
99 if (info.fTargetSurface &&
100 !static_cast<const SkSurface_Base*>(info.fTargetSurface)->isGraphiteBacked()) {
101 if (callback) {
102 callback->setFailureResult();
103 }
104 info.fRecording->priv().setFailureResultForFinishedProcs();
105 SKGPU_LOG_E("Target surface passed into addRecording call is not graphite-backed");
106 return false;
107 }
108
109 auto resourceProvider = context->priv().resourceProvider();
110 if (!this->setupCommandBuffer(resourceProvider)) {
111 if (callback) {
112 callback->setFailureResult();
113 }
114 info.fRecording->priv().setFailureResultForFinishedProcs();
115 SKGPU_LOG_E("CommandBuffer creation failed");
116 return false;
117 }
118
119 if (info.fRecording->priv().hasNonVolatileLazyProxies()) {
120 if (!info.fRecording->priv().instantiateNonVolatileLazyProxies(resourceProvider)) {
121 if (callback) {
122 callback->setFailureResult();
123 }
124 info.fRecording->priv().setFailureResultForFinishedProcs();
125 SKGPU_LOG_E("Non-volatile PromiseImage instantiation has failed");
126 return false;
127 }
128 }
129
130 if (info.fRecording->priv().hasVolatileLazyProxies()) {
131 if (!info.fRecording->priv().instantiateVolatileLazyProxies(resourceProvider)) {
132 if (callback) {
133 callback->setFailureResult();
134 }
135 info.fRecording->priv().setFailureResultForFinishedProcs();
136 info.fRecording->priv().deinstantiateVolatileLazyProxies();
137 SKGPU_LOG_E("Volatile PromiseImage instantiation has failed");
138 return false;
139 }
140 }
141
142 fCurrentCommandBuffer->addWaitSemaphores(info.fNumWaitSemaphores, info.fWaitSemaphores);
143 if (!info.fRecording->priv().addCommands(context,
145 static_cast<Surface*>(info.fTargetSurface),
146 info.fTargetTranslation)) {
147 if (callback) {
148 callback->setFailureResult();
149 }
150 info.fRecording->priv().setFailureResultForFinishedProcs();
151 info.fRecording->priv().deinstantiateVolatileLazyProxies();
152 SKGPU_LOG_E("Adding Recording commands to the CommandBuffer has failed");
153 return false;
154 }
155 fCurrentCommandBuffer->addSignalSemaphores(info.fNumSignalSemaphores, info.fSignalSemaphores);
156 if (info.fTargetTextureState) {
157 fCurrentCommandBuffer->prepareSurfaceForStateUpdate(info.fTargetSurface,
158 info.fTargetTextureState);
159 }
160
161 if (callback) {
162 fCurrentCommandBuffer->addFinishedProc(std::move(callback));
163 }
164
165 info.fRecording->priv().deinstantiateVolatileLazyProxies();
166
167 return true;
168}
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define TRACE_FUNC
Definition: SkTraceEvent.h:30
bool isGraphiteBacked() const
bool requireOrderedRecordings() const
Definition: Caps.h:287
V * find(const K &key) const
Definition: SkTHash.h:494
V * set(K key, V val)
Definition: SkTHash.h:487
#define TRACE_EVENT0(category_group, name)
Definition: trace_event.h:131

◆ addTask()

bool skgpu::graphite::QueueManager::addTask ( Task task,
Context context 
)

Definition at line 170 of file QueueManager.cpp.

171 {
172 SkASSERT(task);
173 if (!task) {
174 SKGPU_LOG_E("No valid Task passed into addTask call");
175 return false;
176 }
177
178 if (!this->setupCommandBuffer(context->priv().resourceProvider())) {
179 SKGPU_LOG_E("CommandBuffer creation failed");
180 return false;
181 }
182
183 if (task->addCommands(context, fCurrentCommandBuffer.get(), {}) == Task::Status::kFail) {
184 SKGPU_LOG_E("Adding Task commands to the CommandBuffer has failed");
185 return false;
186 }
187
188 return true;
189}

◆ addUploadBufferManagerRefs()

void skgpu::graphite::QueueManager::addUploadBufferManagerRefs ( UploadBufferManager uploadManager)

Definition at line 276 of file QueueManager.cpp.

276 {
278 uploadManager->transferToCommandBuffer(fCurrentCommandBuffer.get());
279}

◆ checkForFinishedWork()

void skgpu::graphite::QueueManager::checkForFinishedWork ( SyncToCpu  sync)

Definition at line 243 of file QueueManager.cpp.

243 {
244 TRACE_EVENT1("skia.gpu", TRACE_FUNC, "sync", sync == SyncToCpu::kYes);
245
246 if (sync == SyncToCpu::kYes) {
248 // wait for the last submission to finish
249 OutstandingSubmission* back = (OutstandingSubmission*)fOutstandingSubmissions.back();
250 if (back) {
251 (*back)->waitUntilFinished(fSharedContext);
252 }
253 }
254
255 // Iterate over all the outstanding submissions to see if any have finished. The work
256 // submissions are in order from oldest to newest, so we start at the front to check if they
257 // have finished. If so we pop it off and move onto the next.
258 // Repeat till we find a submission that has not finished yet (and all others afterwards are
259 // also guaranteed to not have finished).
260 OutstandingSubmission* front = (OutstandingSubmission*)fOutstandingSubmissions.front();
261 while (front && (*front)->isFinished(fSharedContext)) {
262 // Make sure we remove before deleting as deletion might try to kick off another submit
263 // (though hopefully *not* in Graphite).
264 fOutstandingSubmissions.pop_front();
265 // Since we used placement new we are responsible for calling the destructor manually.
266 front->~OutstandingSubmission();
267 front = (OutstandingSubmission*)fOutstandingSubmissions.front();
268 }
269 SkASSERT(sync == SyncToCpu::kNo || fOutstandingSubmissions.empty());
270}
const void * front() const
Definition: SkDeque.h:42
void pop_front()
Definition: SkDeque.cpp:153
const void * back() const
Definition: SkDeque.h:43
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val)
Definition: trace_event.h:141

◆ getNewCommandBuffer()

virtual std::unique_ptr< CommandBuffer > skgpu::graphite::QueueManager::getNewCommandBuffer ( ResourceProvider )
privatepure virtual

◆ hasUnfinishedGpuWork()

bool skgpu::graphite::QueueManager::hasUnfinishedGpuWork ( )

Definition at line 241 of file QueueManager.cpp.

241{ return !fOutstandingSubmissions.empty(); }

◆ onSubmitToGpu()

virtual OutstandingSubmission skgpu::graphite::QueueManager::onSubmitToGpu ( )
privatepure virtual

◆ returnCommandBuffer()

void skgpu::graphite::QueueManager::returnCommandBuffer ( std::unique_ptr< CommandBuffer commandBuffer)

Definition at line 272 of file QueueManager.cpp.

272 {
273 fAvailableCommandBuffers.push_back(std::move(commandBuffer));
274}

◆ submitToGpu()

bool skgpu::graphite::QueueManager::submitToGpu ( )

Definition at line 215 of file QueueManager.cpp.

215 {
216 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
217
219 // We warn because this probably representative of a bad client state, where they don't
220 // need to submit but didn't notice, but technically the submit itself is fine (no-op), so
221 // we return true.
222 SKGPU_LOG_D("Submit called with no active command buffer!");
223 return true;
224 }
225
226#ifdef SK_DEBUG
227 if (!fCurrentCommandBuffer->hasWork()) {
228 SKGPU_LOG_D("Submitting empty command buffer!");
229 }
230#endif
231
232 auto submission = this->onSubmitToGpu();
233 if (!submission) {
234 return false;
235 }
236
237 new (fOutstandingSubmissions.push_back()) OutstandingSubmission(std::move(submission));
238 return true;
239}
#define SKGPU_LOG_D(fmt,...)
Definition: Log.h:42
void * push_back()
Definition: SkDeque.cpp:112
virtual OutstandingSubmission onSubmitToGpu()=0

◆ tick()

virtual void skgpu::graphite::QueueManager::tick ( ) const
inlinevirtual

Reimplemented in skgpu::graphite::DawnQueueManager.

Definition at line 58 of file QueueManager.h.

58{}

Member Data Documentation

◆ fCurrentCommandBuffer

std::unique_ptr<CommandBuffer> skgpu::graphite::QueueManager::fCurrentCommandBuffer
protected

Definition at line 68 of file QueueManager.h.

◆ fSharedContext

const SharedContext* skgpu::graphite::QueueManager::fSharedContext
protected

Definition at line 67 of file QueueManager.h.


The documentation for this class was generated from the following files: