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

Commit 762cb4e

Browse files
rphilliSkia Commit-Bot
authored andcommitted
Add option to DDL test harness to better match OOP-R behavior
Change-Id: I043613c127dbfa1ebb7dcf5eab7b996afb676b61 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/296449 Reviewed-by: Adlai Holler <[email protected]> Commit-Queue: Robert Phillips <[email protected]>
1 parent f4ec452 commit 762cb4e

File tree

5 files changed

+129
-13
lines changed

5 files changed

+129
-13
lines changed

dm/DM.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,8 @@ static Sink* create_sink(const GrContextOptions& grCtxOptions, const SkCommandLi
950950
return new GPUPrecompileTestingSink(gpuConfig, grCtxOptions);
951951
} else if (gpuConfig->getUseDDLSink()) {
952952
return new GPUDDLSink(gpuConfig, grCtxOptions);
953+
} else if (gpuConfig->getOOPRish()) {
954+
return new GPUOOPRSink(gpuConfig, grCtxOptions);
953955
} else {
954956
return new GPUSink(gpuConfig, grCtxOptions);
955957
}

dm/DMSrcSink.cpp

Lines changed: 99 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ GMSrc::GMSrc(skiagm::GMFactory factory) : fFactory(factory) {}
9393
Result GMSrc::draw(SkCanvas* canvas) const {
9494
std::unique_ptr<skiagm::GM> gm(fFactory());
9595
SkString msg;
96+
9697
skiagm::DrawResult drawResult = gm->draw(canvas, &msg);
9798
switch (drawResult) {
9899
case skiagm::DrawResult::kOk : return Result(Result::Status::Ok, msg);
@@ -1293,7 +1294,9 @@ SkISize MSKPSrc::size(int i) const {
12931294
return i >= 0 && i < fPages.count() ? fPages[i].fSize.toCeil() : SkISize{0, 0};
12941295
}
12951296

1296-
Result MSKPSrc::draw(SkCanvas* c) const { return this->draw(0, c); }
1297+
Result MSKPSrc::draw(SkCanvas* c) const {
1298+
return this->draw(0, c);
1299+
}
12971300
Result MSKPSrc::draw(int i, SkCanvas* canvas) const {
12981301
if (this->pageCount() == 0) {
12991302
return Result::Fatal("Unable to parse MultiPictureDocument file: %s", fPath.c_str());
@@ -1475,9 +1478,9 @@ Result GPUSink::onDraw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log,
14751478
}
14761479
surface->flushAndSubmit();
14771480
if (FLAGS_gpuStats) {
1478-
canvas->getGrContext()->priv().dumpCacheStats(log);
1479-
canvas->getGrContext()->priv().dumpGpuStats(log);
1480-
canvas->getGrContext()->priv().dumpContextStats(log);
1481+
context->priv().dumpCacheStats(log);
1482+
context->priv().dumpGpuStats(log);
1483+
context->priv().dumpContextStats(log);
14811484
}
14821485

14831486
this->readBack(surface.get(), dst);
@@ -1623,10 +1626,95 @@ Result GPUPrecompileTestingSink::draw(const Src& src, SkBitmap* dst, SkWStream*
16231626
}
16241627

16251628
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1626-
GPUDDLSink::GPUDDLSink(const SkCommandLineConfigGpu* config, const GrContextOptions& grCtxOptions)
1627-
: INHERITED(config, grCtxOptions)
1628-
, fRecordingThreadPool(SkExecutor::MakeLIFOThreadPool(1)) // TODO: this should be at least 2
1629-
, fGPUThread(SkExecutor::MakeFIFOThreadPool(1, false)) {
1629+
GPUOOPRSink::GPUOOPRSink(const SkCommandLineConfigGpu* config, const GrContextOptions& ctxOptions)
1630+
: INHERITED(config, ctxOptions) {
1631+
}
1632+
1633+
Result GPUOOPRSink::ooprDraw(const Src& src,
1634+
sk_sp<SkSurface> dstSurface,
1635+
GrContext* context) const {
1636+
SkSurfaceCharacterization dstCharacterization;
1637+
SkAssertResult(dstSurface->characterize(&dstCharacterization));
1638+
1639+
SkDeferredDisplayListRecorder recorder(dstCharacterization);
1640+
1641+
Result result = src.draw(recorder.getCanvas());
1642+
if (!result.isOk()) {
1643+
return result;
1644+
}
1645+
1646+
std::unique_ptr<SkDeferredDisplayList> ddl = recorder.detach();
1647+
1648+
SkDeferredDisplayList::ProgramIterator iter(context, ddl.get());
1649+
for (; !iter.done(); iter.next()) {
1650+
iter.compile();
1651+
}
1652+
1653+
dstSurface->draw(ddl.get());
1654+
1655+
// TODO: remove this flush once DDLs are reffed by the drawing manager
1656+
context->flushAndSubmit();
1657+
1658+
ddl.reset();
1659+
1660+
return Result::Ok();
1661+
}
1662+
1663+
Result GPUOOPRSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log) const {
1664+
GrContextOptions contextOptions = this->baseContextOptions();
1665+
src.modifyGrContextOptions(&contextOptions);
1666+
contextOptions.fPersistentCache = nullptr;
1667+
contextOptions.fExecutor = nullptr;
1668+
1669+
GrContextFactory factory(contextOptions);
1670+
1671+
ContextInfo ctxInfo = factory.getContextInfo(this->contextType(), this->contextOverrides());
1672+
GrContext* context = ctxInfo.grContext();
1673+
if (!context) {
1674+
return Result::Fatal("Could not create context.");
1675+
}
1676+
1677+
SkASSERT(context->priv().getGpu());
1678+
1679+
GrBackendTexture backendTexture;
1680+
GrBackendRenderTarget backendRT;
1681+
sk_sp<SkSurface> surface = this->createDstSurface(context, src.size(),
1682+
&backendTexture, &backendRT);
1683+
if (!surface) {
1684+
return Result::Fatal("Could not create a surface.");
1685+
}
1686+
1687+
Result result = this->ooprDraw(src, surface, context);
1688+
if (!result.isOk()) {
1689+
return result;
1690+
}
1691+
1692+
if (FLAGS_gpuStats) {
1693+
context->priv().dumpCacheStats(log);
1694+
context->priv().dumpGpuStats(log);
1695+
context->priv().dumpContextStats(log);
1696+
}
1697+
1698+
if (!this->readBack(surface.get(), dst)) {
1699+
return Result::Fatal("Could not readback from surface.");
1700+
}
1701+
1702+
surface.reset();
1703+
if (backendTexture.isValid()) {
1704+
context->deleteBackendTexture(backendTexture);
1705+
}
1706+
if (backendRT.isValid()) {
1707+
context->priv().getGpu()->deleteTestingOnlyBackendRenderTarget(backendRT);
1708+
}
1709+
1710+
return Result::Ok();
1711+
}
1712+
1713+
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1714+
GPUDDLSink::GPUDDLSink(const SkCommandLineConfigGpu* config, const GrContextOptions& ctxOptions)
1715+
: INHERITED(config, ctxOptions)
1716+
, fRecordingExecutor(SkExecutor::MakeLIFOThreadPool(1))
1717+
, fGPUExecutor(SkExecutor::MakeFIFOThreadPool(1, false)) {
16301718
}
16311719

16321720
Result GPUDDLSink::ddlDraw(const Src& src,
@@ -1735,7 +1823,7 @@ Result GPUDDLSink::ddlDraw(const Src& src,
17351823
return Result::Ok();
17361824
}
17371825

1738-
Result GPUDDLSink::draw(const Src& src, SkBitmap* dst, SkWStream* stream, SkString* log) const {
1826+
Result GPUDDLSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log) const {
17391827
GrContextOptions contextOptions = this->baseContextOptions();
17401828
src.modifyGrContextOptions(&contextOptions);
17411829
contextOptions.fPersistentCache = nullptr;
@@ -1767,8 +1855,8 @@ Result GPUDDLSink::draw(const Src& src, SkBitmap* dst, SkWStream* stream, SkStri
17671855
SkASSERT(otherCtx->priv().getGpu());
17681856
#endif
17691857

1770-
SkTaskGroup recordingTaskGroup(*fRecordingThreadPool);
1771-
SkTaskGroup gpuTaskGroup(*fGPUThread);
1858+
SkTaskGroup recordingTaskGroup(*fRecordingExecutor);
1859+
SkTaskGroup gpuTaskGroup(*fGPUExecutor);
17721860

17731861
// Make sure 'mainCtx' is current
17741862
mainTestCtx->makeCurrent();

dm/DMSrcSink.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,21 @@ class GPUPrecompileTestingSink : public GPUSink {
451451
typedef GPUSink INHERITED;
452452
};
453453

454+
// This sink attempts to emulate Chrome's OOP-R behavior. It:
455+
// doesn't use promise images
456+
// uses only a single thread for both DDL creation & drawing
457+
class GPUOOPRSink : public GPUSink {
458+
public:
459+
GPUOOPRSink(const SkCommandLineConfigGpu*, const GrContextOptions&);
460+
461+
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
462+
463+
private:
464+
Result ooprDraw(const Src&, sk_sp<SkSurface> dstSurface, GrContext*) const;
465+
466+
typedef GPUSink INHERITED;
467+
};
468+
454469
// This sink attempts to better simulate the Chrome DDL use-case. It:
455470
// creates the DDLs on separate recording threads
456471
// performs all the GPU work on a separate GPU thread
@@ -473,8 +488,8 @@ class GPUDDLSink : public GPUSink {
473488
sk_gpu_test::TestContext* gpuTestCtx,
474489
GrContext* gpuThreadCtx) const;
475490

476-
std::unique_ptr<SkExecutor> fRecordingThreadPool;
477-
std::unique_ptr<SkExecutor> fGPUThread;
491+
std::unique_ptr<SkExecutor> fRecordingExecutor;
492+
std::unique_ptr<SkExecutor> fGPUExecutor;
478493

479494
typedef GPUSink INHERITED;
480495
};

tools/flags/CommonFlagsConfig.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ static const struct {
7272
{ "gltestprecompile", "gpu", "api=gl,testPrecompile=true" },
7373
{ "glestestprecompile", "gpu", "api=gles,testPrecompile=true" },
7474
{ "glddl", "gpu", "api=gl,useDDLSink=true" },
75+
{ "glooprddl", "gpu", "api=gl,OOPRish=true" },
7576
{ "angle_d3d11_es2", "gpu", "api=angle_d3d11_es2" },
7677
{ "angle_d3d11_es3", "gpu", "api=angle_d3d11_es3" },
7778
{ "angle_d3d9_es2", "gpu", "api=angle_d3d9_es2" },
@@ -103,13 +104,15 @@ static const struct {
103104
{ "vkbert", "gpu", "api=vulkan,surf=bert" },
104105
{ "vktestpersistentcache", "gpu", "api=vulkan,testPersistentCache=1" },
105106
{ "vkddl", "gpu", "api=vulkan,useDDLSink=true" },
107+
{ "vkooprddl", "gpu", "api=vulkan,OOPRish=true" },
106108
#endif
107109
#ifdef SK_METAL
108110
{ "mtl", "gpu", "api=metal" },
109111
{ "mtl1010102", "gpu", "api=metal,color=1010102" },
110112
{ "mtlmsaa4", "gpu", "api=metal,samples=4" },
111113
{ "mtlmsaa8", "gpu", "api=metal,samples=8" },
112114
{ "mtlddl", "gpu", "api=metal,useDDLSink=true" },
115+
{ "mtlooprddl", "gpu", "api=metal,OOPRish=true" },
113116
#endif
114117
#ifdef SK_DIRECT3D
115118
{ "d3d", "gpu", "api=direct3d" },
@@ -459,6 +462,7 @@ SkCommandLineConfigGpu::SkCommandLineConfigGpu(const SkString& tag,
459462
int testPersistentCache,
460463
bool testPrecompile,
461464
bool useDDLSink,
465+
bool OOPRish,
462466
SurfType surfType)
463467
: SkCommandLineConfig(tag, SkString("gpu"), viaParts)
464468
, fContextType(contextType)
@@ -472,6 +476,7 @@ SkCommandLineConfigGpu::SkCommandLineConfigGpu(const SkString& tag,
472476
, fTestPersistentCache(testPersistentCache)
473477
, fTestPrecompile(testPrecompile)
474478
, fUseDDLSink(useDDLSink)
479+
, fOOPRish(OOPRish)
475480
, fSurfType(surfType) {
476481
if (!useStencilBuffers) {
477482
fContextOverrides |= ContextOverrides::kAvoidStencilBuffers;
@@ -493,6 +498,7 @@ SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString&
493498
int testPersistentCache = 0;
494499
bool testPrecompile = false;
495500
bool useDDLs = false;
501+
bool ooprish = false;
496502
SkCommandLineConfigGpu::SurfType surfType = SkCommandLineConfigGpu::SurfType::kDefault;
497503

498504
bool parseSucceeded = false;
@@ -511,6 +517,7 @@ SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString&
511517
extendedOptions.get_option_int("testPersistentCache", &testPersistentCache) &&
512518
extendedOptions.get_option_bool("testPrecompile", &testPrecompile) &&
513519
extendedOptions.get_option_bool("useDDLSink", &useDDLs) &&
520+
extendedOptions.get_option_bool("OOPRish", &ooprish) &&
514521
extendedOptions.get_option_gpu_surf_type("surf", &surfType);
515522

516523
// testing threading and the persistent cache are mutually exclusive.
@@ -531,6 +538,7 @@ SkCommandLineConfigGpu* parse_command_line_config_gpu(const SkString&
531538
testPersistentCache,
532539
testPrecompile,
533540
useDDLs,
541+
ooprish,
534542
surfType);
535543
}
536544

tools/flags/CommonFlagsConfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class SkCommandLineConfigGpu : public SkCommandLineConfig {
6464
int testPersistentCache,
6565
bool testPrecompile,
6666
bool useDDLSink,
67+
bool OOPRish,
6768
SurfType);
6869

6970
const SkCommandLineConfigGpu* asConfigGpu() const override { return this; }
@@ -78,6 +79,7 @@ class SkCommandLineConfigGpu : public SkCommandLineConfig {
7879
int getTestPersistentCache() const { return fTestPersistentCache; }
7980
bool getTestPrecompile() const { return fTestPrecompile; }
8081
bool getUseDDLSink() const { return fUseDDLSink; }
82+
bool getOOPRish() const { return fOOPRish; }
8183
SurfType getSurfType() const { return fSurfType; }
8284

8385
private:
@@ -92,6 +94,7 @@ class SkCommandLineConfigGpu : public SkCommandLineConfig {
9294
int fTestPersistentCache;
9395
bool fTestPrecompile;
9496
bool fUseDDLSink;
97+
bool fOOPRish;
9598
SurfType fSurfType;
9699
};
97100

0 commit comments

Comments
 (0)