Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 04283f3

Browse files
egdanielSkia Commit-Bot
authored andcommitted
Reland "Implement submit API to GrContext."
This reverts commit 9ee15d7. Reason for revert: relanding with fixes Original change's description: > Revert "Implement submit API to GrContext." > > This reverts commit 40f288c. > > Reason for revert: canvaskit breaking for some reason??? > > Original change's description: > > Implement submit API to GrContext. > > > > Change-Id: Ib813d42abb5f63e2ecdbf245d416658143853288 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/289033 > > Commit-Queue: Greg Daniel <[email protected]> > > Reviewed-by: Brian Salomon <[email protected]> > > [email protected],[email protected],[email protected],[email protected] > > Change-Id: Iee6c8342cccc601edf64ea011f1303e5d72559a9 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290917 > Reviewed-by: Greg Daniel <[email protected]> > Commit-Queue: Greg Daniel <[email protected]> [email protected],[email protected],[email protected],[email protected] # Not skipping CQ checks because this is a reland. Change-Id: I5203676f88893cbbaba685301b8a713b40396b48 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290960 Reviewed-by: Greg Daniel <[email protected]> Commit-Queue: Greg Daniel <[email protected]>
1 parent c5eb5c7 commit 04283f3

File tree

14 files changed

+168
-86
lines changed

14 files changed

+168
-86
lines changed

RELEASE_NOTES.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ Milestone 85
99

1010
* <insert new release notes here>
1111

12+
* GrContext submit is now required to be called in order to send GPU work to the
13+
actual GPU. The flush calls simply produces 3D API specific objects that are ready
14+
to be submitted (e.g. command buffers). For the GL backend, the flush will still
15+
send commands to the driver. However, clients should still assume the must call
16+
submit which is where any glFlush that is need for sync objects will be called. There,
17+
are flushAndSubmit() functions of GrContext, SkSurface, and SkImage that will act
18+
like the previous flush() functions. This will flush the work and immediately call
19+
submit.
20+
https://review.skia.org/289033
21+
1222
* Remove deprecated version of flush calls on GrContext and SkSurface.
1323
https://review.skia.org/2290540
1424

include/core/SkSurface.h

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,8 @@ class SK_API SkSurface : public SkRefCnt {
916916
Skia will correctly order its own draws and pixel operations. This must to be used to ensure
917917
correct ordering when the surface backing store is accessed outside Skia (e.g. direct use of
918918
the 3D API or a windowing system). GrContext has additional flush and submit methods that
919-
apply to all surfaces and images created from a GrContext.
919+
apply to all surfaces and images created from a GrContext. This is equivalent to calling
920+
SkSurface::flush with a default GrFlushInfo followed by GrContext::submit.
920921
*/
921922
void flushAndSubmit();
922923

@@ -925,7 +926,16 @@ class SK_API SkSurface : public SkRefCnt {
925926
kPresent, //!< back-end surface will be used for presenting to screen
926927
};
927928

928-
/** Issues pending SkSurface commands to the GPU-backed API and resolves any SkSurface MSAA.
929+
/** Issues pending SkSurface commands to the GPU-backed API objects and resolves any SkSurface
930+
MSAA. A call to GrContext::submit is always required to ensure work is actually sent to the
931+
gpu. Some specific API details:
932+
GL: Commands are actually sent to the driver, but glFlush is never called. Thus some
933+
sync objects from the flush will not be valid until a submission occurs.
934+
935+
Vulkan/Metal/D3D/Dawn: Commands are recorded to the backend APIs corresponding command
936+
buffer or encoder objects. However, these objects are not sent to the gpu until a
937+
submission occurs.
938+
929939
The work that is submitted to the GPU will be dependent on the BackendSurfaceAccess that is
930940
passed in.
931941
@@ -941,13 +951,19 @@ class SK_API SkSurface : public SkRefCnt {
941951
The GrFlushInfo describes additional options to flush. Please see documentation at
942952
GrFlushInfo for more info.
943953
944-
If the return is GrSemaphoresSubmitted::kYes, only initialized GrBackendSemaphores will
945-
have been submitted and can be waited on (it is possible Skia failed to create a subset of
946-
the semaphores). If this call returns GrSemaphoresSubmitted::kNo, the GPU backend will not
947-
have submitted any semaphores to be signaled on the GPU. Thus the client should not have
948-
the GPU wait on any of the semaphores passed in with the GrFlushInfo. Regardless of whether
949-
semaphores were submitted to the GPU or not, the client is still responsible for deleting
950-
any initialized semaphores.
954+
If the return is GrSemaphoresSubmitted::kYes, only initialized GrBackendSemaphores will be
955+
submitted to the gpu during the next submit call (it is possible Skia failed to create a
956+
subset of the semaphores). The client should not wait on these semaphores until after submit
957+
has been called, but must keep them alive until then. If a submit flag was passed in with
958+
the flush these valid semaphores can we waited on immediately. If this call returns
959+
GrSemaphoresSubmitted::kNo, the GPU backend will not submit any semaphores to be signaled on
960+
the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in
961+
with the GrFlushInfo. Regardless of whether semaphores were submitted to the GPU or not, the
962+
client is still responsible for deleting any initialized semaphores.
963+
Regardleess of semaphore submission the context will still be flushed. It should be
964+
emphasized that a return value of GrSemaphoresSubmitted::kNo does not mean the flush did not
965+
happen. It simply means there were no semaphores submitted to the GPU. A caller should only
966+
take this as a failure if they passed in semaphores to be submitted.
951967
952968
Pending surface commands are flushed regardless of the return result.
953969

include/gpu/GrContext.h

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ class SK_API GrContext : public GrRecordingContext {
296296
///////////////////////////////////////////////////////////////////////////
297297
// Misc.
298298

299-
300299
/**
301300
* Inserts a list of GPU semaphores that the current GPU-backed API must wait on before
302301
* executing any more commands on the GPU. Skia will take ownership of the underlying semaphores
@@ -307,20 +306,35 @@ class SK_API GrContext : public GrRecordingContext {
307306
bool wait(int numSemaphores, const GrBackendSemaphore* waitSemaphores);
308307

309308
/**
310-
* Call to ensure all drawing to the context has been issued to the underlying 3D API.
309+
* Call to ensure all drawing to the context has been flushed and submitted to the underlying 3D
310+
* API. This is equivalent to calling GrContext::flush with a default GrFlushInfo followed by
311+
* GrContext::submit.
311312
*/
312-
void flushAndSubmit() { this->flush(GrFlushInfo(), GrPrepareForExternalIORequests()); }
313+
void flushAndSubmit() {
314+
this->flush(GrFlushInfo(), GrPrepareForExternalIORequests());
315+
this->submit();
316+
}
313317

314318
/**
315-
* Call to ensure all drawing to the context has been issued to the underlying 3D API.
319+
* Call to ensure all drawing to the context has been flushed to underlying 3D API specific
320+
* objects. A call to GrContext::submit is always required to ensure work is actually sent to
321+
* the gpu. Some specific API details:
322+
* GL: Commands are actually sent to the driver, but glFlush is never called. Thus some
323+
* sync objects from the flush will not be valid until a submission occurs.
324+
*
325+
* Vulkan/Metal/D3D/Dawn: Commands are recorded to the backend APIs corresponding command
326+
* buffer or encoder objects. However, these objects are not sent to the gpu until a
327+
* submission occurs.
316328
*
317-
* If the return is GrSemaphoresSubmitted::kYes, only initialized GrBackendSemaphores will have
318-
* been submitted and can be waited on (it is possible Skia failed to create a subset of the
319-
* semaphores). If this call returns GrSemaphoresSubmitted::kNo, the GPU backend will not have
320-
* submitted any semaphores to be signaled on the GPU. Thus the client should not have the GPU
321-
* wait on any of the semaphores passed in with the GrFlushInfo. Regardless of whether
322-
* semaphores were submitted to the GPU or not, the client is still responsible for deleting any
323-
* initialized semaphores.
329+
* If the return is GrSemaphoresSubmitted::kYes, only initialized GrBackendSemaphores will be
330+
* submitted to the gpu during the next submit call (it is possible Skia failed to create a
331+
* subset of the semaphores). The client should not wait on these semaphores until after submit
332+
* has been called, but must keep them alive until then. If a submit flag was passed in with the
333+
* flush these valid semaphores can we waited on immediately. If this call returns
334+
* GrSemaphoresSubmitted::kNo, the GPU backend will not submit any semaphores to be signaled on
335+
* the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in with
336+
* the GrFlushInfo. Regardless of whether semaphores were submitted to the GPU or not, the
337+
* client is still responsible for deleting any initialized semaphores.
324338
* Regardleess of semaphore submission the context will still be flushed. It should be
325339
* emphasized that a return value of GrSemaphoresSubmitted::kNo does not mean the flush did not
326340
* happen. It simply means there were no semaphores submitted to the GPU. A caller should only
@@ -331,26 +345,54 @@ class SK_API GrContext : public GrRecordingContext {
331345
}
332346

333347
/**
334-
* Call to ensure all drawing to the context has been issued to the underlying 3D API.
348+
* Call to ensure all drawing to the context has been flushed to underlying 3D API specific
349+
* objects. A call to GrContext::submit is always required to ensure work is actually sent to
350+
* the gpu. Some specific API details:
351+
* GL: Commands are actually sent to the driver, but glFlush is never called. Thus some
352+
* sync objects from the flush will not be valid until submit is called.
335353
*
336-
* If this call returns GrSemaphoresSubmitted::kNo, the GPU backend will not have created or
337-
* added any semaphores to signal on the GPU. Thus the client should not have the GPU wait on
338-
* any of the semaphores passed in with the GrFlushInfo. However, any pending commands to the
339-
* context will still be flushed. It should be emphasized that a return value of
340-
* GrSemaphoresSubmitted::kNo does not mean the flush did not happen. It simply means there were
341-
* no semaphores submitted to the GPU. A caller should only take this as a failure if they
342-
* passed in semaphores to be submitted.
354+
* Vulkan/Metal/D3D/Dawn: Commands are recorded to the backend APIs corresponding command
355+
* buffer or encoder objects. However, these objects are not sent to the gpu until
356+
* submit is called.
357+
*
358+
* Note: The default values for GrFlushInfo will submit the work the gpu.
359+
*
360+
* If the return is GrSemaphoresSubmitted::kYes, only initialized GrBackendSemaphores will be
361+
* submitted to the gpu during the next submit call (it is possible Skia failed to create a
362+
* subset of the semaphores). The client should not wait on these semaphores until after submit
363+
* has been called, but must keep them alive until then. If this call returns
364+
* GrSemaphoresSubmitted::kNo, the GPU backend will not submit any semaphores to be signaled on
365+
* the GPU. Thus the client should not have the GPU wait on any of the semaphores passed in with
366+
* the GrFlushInfo. The client is always responsible for deleting any initialized semaphores.
367+
* Regardleess of semaphore submission the context will still be flushed. It should be
368+
* emphasized that a return value of GrSemaphoresSubmitted::kNo does not mean the flush did not
369+
* happen. It simply means there were no semaphores submitted to the GPU. A caller should only
370+
* take this as a failure if they passed in semaphores to be submitted.
343371
*
344372
* If the GrPrepareForExternalIORequests contains valid gpu backed SkSurfaces or SkImages, Skia
345373
* will put the underlying backend objects into a state that is ready for external uses. See
346-
* declaration of GrPreopareForExternalIORequests for more details.
374+
* declaration of GrPreopareForExternalIORequests for more details. Note that the backend
375+
* objects will not be moved to this state until submit has been called. If subsequent flushes
376+
* are called between this and submit, those objects are no longer guaranteed to be in a state
377+
* that is ready for external use.
347378
*/
348379
GrSemaphoresSubmitted flush(const GrFlushInfo&, const GrPrepareForExternalIORequests&);
349380

350381
/**
351-
* Placeholder no-op submit call.
382+
* Submit outstanding work to the gpu from all previously un-submitted flushes. The return
383+
* value of the submit will indicate whether or not the submission to the GPU was successful.
384+
*
385+
* If the call returns true, all previously passed in semaphores in flush calls will have been
386+
* submitted to the GPU and they can safely be waited on. The caller should wait on those
387+
* semaphores or perform some other global synchronization before deleting the semaphores.
388+
*
389+
* If it returns false, then those same semaphores will not have been submitted and we will not
390+
* try to submit them again. The caller is free to delete the semaphores at any time.
391+
*
392+
* If the syncCpu flag is true this function will return once the gpu has finished with all
393+
* submitted work.
352394
*/
353-
bool submit(bool syncToCpu = false);
395+
bool submit(bool syncCpu = false);
354396

355397
/**
356398
* Checks whether any asynchronous work is complete and if so calls related callbacks.

include/gpu/GrTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ static const uint32_t kAll_GrBackendState = 0xffffffff;
227227

228228
enum GrFlushFlags {
229229
kNone_GrFlushFlags = 0,
230-
// flush will wait till all submitted GPU work is finished before returning.
230+
// Deprecated: Use syncCpu call on submit instead.
231231
kSyncCpu_GrFlushFlag = 0x1,
232232
};
233233

src/gpu/GrContext.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,21 +319,26 @@ GrSemaphoresSubmitted GrContext::flush(const GrFlushInfo& info,
319319
return GrSemaphoresSubmitted::kNo;
320320
}
321321

322-
bool submitted = false;
323-
if (this->drawingManager()->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess,
324-
info, externalRequests)) {
325-
bool forceSync = SkToBool(info.fFlags & kSyncCpu_GrFlushFlag);
326-
submitted = this->drawingManager()->submitToGpu(forceSync);
327-
}
322+
bool flushed = this->drawingManager()->flush(
323+
nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, info, externalRequests);
328324

329-
if (!submitted || (!this->priv().caps()->semaphoreSupport() && info.fNumSemaphores)) {
325+
if (!flushed || (!this->priv().caps()->semaphoreSupport() && info.fNumSemaphores)) {
330326
return GrSemaphoresSubmitted::kNo;
331327
}
332328
return GrSemaphoresSubmitted::kYes;
333329
}
334330

335-
bool GrContext::submit(bool syncToCpu) {
336-
return true;
331+
bool GrContext::submit(bool syncCpu) {
332+
ASSERT_SINGLE_OWNER
333+
if (this->abandoned()) {
334+
return false;
335+
}
336+
337+
if (!fGpu) {
338+
return false;
339+
}
340+
341+
return fGpu->submitToGpu(syncCpu);
337342
}
338343

339344
////////////////////////////////////////////////////////////////////////////////

src/gpu/GrDrawingManager.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -570,12 +570,7 @@ GrSemaphoresSubmitted GrDrawingManager::flushSurfaces(GrSurfaceProxy* proxies[],
570570

571571
SkDEBUGCODE(this->validate());
572572

573-
bool submitted = false;
574-
if (didFlush) {
575-
submitted = this->submitToGpu(SkToBool(info.fFlags & kSyncCpu_GrFlushFlag));
576-
}
577-
578-
if (!submitted || (!direct->priv().caps()->semaphoreSupport() && info.fNumSemaphores)) {
573+
if (!didFlush || (!direct->priv().caps()->semaphoreSupport() && info.fNumSemaphores)) {
579574
return GrSemaphoresSubmitted::kNo;
580575
}
581576
return GrSemaphoresSubmitted::kYes;

src/gpu/GrRenderTargetContext.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,7 @@ void GrRenderTargetContext::asyncReadPixels(const SkIRect& rect, SkColorType col
19011901
flushInfo.fFinishedContext = finishContext;
19021902
flushInfo.fFinishedProc = finishCallback;
19031903
this->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo);
1904+
directContext->submit();
19041905
}
19051906

19061907
void GrRenderTargetContext::asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpace,
@@ -2153,6 +2154,7 @@ void GrRenderTargetContext::asyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvC
21532154
flushInfo.fFinishedContext = finishContext;
21542155
flushInfo.fFinishedProc = finishCallback;
21552156
this->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo);
2157+
direct->submit();
21562158
}
21572159

21582160
GrSemaphoresSubmitted GrRenderTargetContext::flush(SkSurface::BackendSurfaceAccess access,

src/gpu/GrSurfaceContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ bool GrSurfaceContext::readPixels(const GrImageInfo& origDstInfo, void* dst, siz
275275
}
276276

277277
direct->priv().flushSurface(srcProxy);
278-
278+
direct->submit();
279279
if (!direct->priv().getGpu()->readPixels(srcSurface, pt.fX, pt.fY, dstInfo.width(),
280280
dstInfo.height(), this->colorInfo().colorType(),
281281
supportedRead.fColorType, readDst, readRB)) {

src/gpu/SkGpuDevice.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ void SkGpuDevice::drawDrawable(SkDrawable* drawable, const SkMatrix* matrix, SkC
10611061

10621062
void SkGpuDevice::flush() {
10631063
this->flush(SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo());
1064+
this->context()->submit();
10641065
}
10651066

10661067
GrSemaphoresSubmitted SkGpuDevice::flush(SkSurface::BackendSurfaceAccess access,

src/image/SkImage.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,10 @@ GrSemaphoresSubmitted SkImage::flush(GrContext* context, const GrFlushInfo& flus
160160
return as_IB(this)->onFlush(context, flushInfo);
161161
}
162162

163-
void SkImage::flushAndSubmit(GrContext* context) { this->flush(context, {}); }
163+
void SkImage::flushAndSubmit(GrContext* context) {
164+
this->flush(context, {});
165+
context->submit();
166+
}
164167

165168
#else
166169

0 commit comments

Comments
 (0)