From 0b4d8aa108f2fd14f1ee4de1affacab166d7a357 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Wed, 11 Oct 2017 15:34:27 -0400 Subject: Add benchmark for comparing multitexturing to non-multitexturing image draws. Allows benchmarks to override GrContextOptions. Removes the ability to use the same GrContext for all benchmarks in a config. Change-Id: I5ab9f6e81055451ac912a66537843d1a49f3b479 Reviewed-on: https://skia-review.googlesource.com/34080 Reviewed-by: Brian Osman Commit-Queue: Brian Salomon --- bench/nanobench.cpp | 75 ++++++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 44 deletions(-) (limited to 'bench/nanobench.cpp') diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp index 5a976e6640..203ed67073 100644 --- a/bench/nanobench.cpp +++ b/bench/nanobench.cpp @@ -65,9 +65,10 @@ extern bool gSkForceRasterPipelineBlitter; #include "GrContextFactory.h" #include "gl/GrGLUtil.h" #include "SkGr.h" + using sk_gpu_test::ContextInfo; using sk_gpu_test::GrContextFactory; using sk_gpu_test::TestContext; - std::unique_ptr gGrFactory; + GrContextOptions grContextOpts; #endif struct GrContextOptions; @@ -124,7 +125,6 @@ DEFINE_bool(lite, false, "Use SkLiteRecorder in recording benchmarks?"); DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?"); DEFINE_bool(loopSKP, true, "Loop SKPs like we do for micro benches?"); DEFINE_int32(flushEvery, 10, "Flush --outResultsFile every Nth run."); -DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each test."); DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?"); DEFINE_bool(gpuStatsDump, false, "Dump GPU states after each benchmark to json"); DEFINE_bool(keepAlive, false, "Print a message every so often so that we don't time out"); @@ -174,44 +174,45 @@ bool Target::capturePixels(SkBitmap* bmp) { #if SK_SUPPORT_GPU struct GPUTarget : public Target { - explicit GPUTarget(const Config& c) : Target(c), context(nullptr) { } - TestContext* context; + explicit GPUTarget(const Config& c) : Target(c) {} + ContextInfo contextInfo; + std::unique_ptr factory; void setup() override { - this->context->makeCurrent(); + this->contextInfo.testContext()->makeCurrent(); // Make sure we're done with whatever came before. - this->context->finish(); + this->contextInfo.testContext()->finish(); } void endTiming() override { - if (this->context) { - this->context->waitOnSyncOrSwap(); + if (this->contextInfo.testContext()) { + this->contextInfo.testContext()->waitOnSyncOrSwap(); } } - void fence() override { - this->context->finish(); - } + void fence() override { this->contextInfo.testContext()->finish(); } bool needsFrameTiming(int* maxFrameLag) const override { - if (!this->context->getMaxGpuFrameLag(maxFrameLag)) { + if (!this->contextInfo.testContext()->getMaxGpuFrameLag(maxFrameLag)) { // Frame lag is unknown. *maxFrameLag = FLAGS_gpuFrameLag; } return true; } bool init(SkImageInfo info, Benchmark* bench) override { + GrContextOptions options = grContextOpts; + bench->modifyGrContextOptions(&options); + this->factory.reset(new GrContextFactory(options)); uint32_t flags = this->config.useDFText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0; SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); - this->surface = SkSurface::MakeRenderTarget(gGrFactory->get(this->config.ctxType, - this->config.ctxOverrides), - SkBudgeted::kNo, info, - this->config.samples, &props); - this->context = gGrFactory->getContextInfo(this->config.ctxType, - this->config.ctxOverrides).testContext(); + this->surface = SkSurface::MakeRenderTarget( + this->factory->get(this->config.ctxType, this->config.ctxOverrides), + SkBudgeted::kNo, info, this->config.samples, &props); + this->contextInfo = + this->factory->getContextInfo(this->config.ctxType, this->config.ctxOverrides); if (!this->surface.get()) { return false; } - if (!this->context->fenceSyncSupport()) { + if (!this->contextInfo.testContext()->fenceSyncSupport()) { SkDebugf("WARNING: GL context for config \"%s\" does not support fence sync. " "Timings might not be accurate.\n", this->config.name.c_str()); } @@ -219,9 +220,9 @@ struct GPUTarget : public Target { } void fillOptions(ResultsWriter* log) override { const GrGLubyte* version; - if (this->context->backend() == kOpenGL_GrBackend) { - const GrGLInterface* gl = - reinterpret_cast(this->context->backendContext()); + if (this->contextInfo.backend() == kOpenGL_GrBackend) { + const GrGLInterface* gl = reinterpret_cast( + this->contextInfo.testContext()->backendContext()); GR_GL_CALL_RET(gl, version, GetString(GR_GL_VERSION)); log->configOption("GL_VERSION", (const char*)(version)); @@ -235,6 +236,11 @@ struct GPUTarget : public Target { log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); } } + + void dumpStats() override { + this->contextInfo.grContext()->printCacheStats(); + this->contextInfo.grContext()->printGpuStats(); + } }; #endif @@ -394,7 +400,6 @@ static int setup_gpu_bench(Target* target, Benchmark* bench, int maxGpuFrameLag) } else { loops = detect_forever_loops(loops); } - // Pretty much the same deal as the calibration: do some warmup to make // sure we're timing steady-state pipelined frames. for (int i = 0; i < maxGpuFrameLag; i++) { @@ -427,7 +432,8 @@ static void create_config(const SkCommandLineConfig* config, SkTArray* c const auto colorType = gpuConfig->getColorType(); auto colorSpace = gpuConfig->getColorSpace(); - if (const GrContext* ctx = gGrFactory->get(ctxType, ctxOverrides)) { + GrContextFactory factory(grContextOpts); + if (const GrContext* ctx = factory.get(ctxType, ctxOverrides)) { GrPixelConfig grPixConfig = SkImageInfo2GrPixelConfig(colorType, colorSpace, *ctx->caps()); int supportedSampleCount = ctx->caps()->getSampleCount(sampleCount, grPixConfig); @@ -578,14 +584,6 @@ static bool valid_brd_bench(sk_sp encoded, SkColorType colorType, uint32 static void cleanup_run(Target* target) { delete target; -#if SK_SUPPORT_GPU - if (FLAGS_abandonGpuContext) { - gGrFactory->abandonContexts(); - } - if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) { - gGrFactory->destroyContexts(); - } -#endif } static void collect_files(const SkCommandLineFlags::StringArray& paths, const char* ext, @@ -1141,10 +1139,8 @@ int main(int argc, char** argv) { SkTaskGroup::Enabler enabled(FLAGS_threads); #if SK_SUPPORT_GPU - GrContextOptions grContextOpts; grContextOpts.fGpuPathRenderers = CollectGpuPathRenderersFromFlags(); grContextOpts.fExecutor = GpuExecutorForTools(); - gGrFactory.reset(new GrContextFactory(grContextOpts)); #endif if (FLAGS_veryVerbose) { @@ -1401,10 +1397,7 @@ int main(int argc, char** argv) { #if SK_SUPPORT_GPU if (FLAGS_gpuStats && Benchmark::kGPU_Backend == configs[i].backend) { - GrContext* context = gGrFactory->get(configs[i].ctxType, - configs[i].ctxOverrides); - context->printCacheStats(); - context->printGpuStats(); + target->dumpStats(); } #endif @@ -1425,11 +1418,5 @@ int main(int argc, char** argv) { log->config("meta"); log->metric("max_rss_mb", sk_tools::getMaxResidentSetSizeMB()); -#if SK_SUPPORT_GPU - // Make sure we clean up the global GrContextFactory here, otherwise we might race with the - // SkEventTracer destructor - gGrFactory.reset(nullptr); -#endif - return 0; } -- cgit v1.2.3