csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 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 | |
Kevin Lubick | f541ddf | 2021-10-13 16:02:56 -0400 | [diff] [blame] | 8 | #include "bench/BigPath.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkGraphics.h" |
| 11 | #include "include/core/SkPicture.h" |
| 12 | #include "include/core/SkPictureRecorder.h" |
| 13 | #include "include/core/SkStream.h" |
| 14 | #include "include/core/SkSurface.h" |
| 15 | #include "include/core/SkSurfaceProps.h" |
Kevin Lubick | ee6dbb4 | 2023-11-03 09:19:25 -0400 | [diff] [blame] | 16 | #include "include/docs/SkMultiPictureDocument.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "include/effects/SkPerlinNoiseShader.h" |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 18 | #include "include/gpu/GrDirectContext.h" |
Kevin Lubick | 5c93acf | 2023-05-09 12:11:43 -0400 | [diff] [blame] | 19 | #include "include/gpu/ganesh/SkSurfaceGanesh.h" |
Kevin Lubick | 0bff57e | 2023-06-09 14:29:17 -0400 | [diff] [blame] | 20 | #include "include/private/chromium/GrDeferredDisplayList.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/core/SkOSFile.h" |
| 22 | #include "src/core/SkTaskGroup.h" |
Greg Daniel | 719239c | 2022-04-07 11:20:24 -0400 | [diff] [blame] | 23 | #include "src/gpu/ganesh/GrCaps.h" |
| 24 | #include "src/gpu/ganesh/GrDirectContextPriv.h" |
| 25 | #include "src/gpu/ganesh/SkGr.h" |
Kevin Lubick | a201943 | 2023-06-12 15:42:51 -0400 | [diff] [blame] | 26 | #include "src/gpu/ganesh/image/GrImageUtils.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 27 | #include "src/utils/SkOSPath.h" |
| 28 | #include "tools/DDLPromiseImageHelper.h" |
| 29 | #include "tools/DDLTileHelper.h" |
Kevin Lubick | 9b02837 | 2023-10-05 15:04:54 -0400 | [diff] [blame] | 30 | #include "tools/EncodeUtils.h" |
Nathaniel Nifong | 1b458e8 | 2019-07-26 11:32:46 -0400 | [diff] [blame] | 31 | #include "tools/SkSharingProc.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 32 | #include "tools/flags/CommandLineFlags.h" |
| 33 | #include "tools/flags/CommonFlags.h" |
| 34 | #include "tools/flags/CommonFlagsConfig.h" |
Kevin Lubick | ee6dbb4 | 2023-11-03 09:19:25 -0400 | [diff] [blame] | 35 | #include "tools/fonts/FontToolUtils.h" |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 36 | #include "tools/gpu/FlushFinishTracker.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 37 | #include "tools/gpu/GpuTimer.h" |
| 38 | #include "tools/gpu/GrContextFactory.h" |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 39 | |
Robert Phillips | 2af13c1 | 2021-09-01 16:47:01 +0000 | [diff] [blame] | 40 | #if defined(SK_ENABLE_SVG) |
Florin Malita | b341810 | 2020-10-15 18:10:29 -0400 | [diff] [blame] | 41 | #include "modules/svg/include/SkSVGDOM.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 42 | #include "src/xml/SkDOM.h" |
Chris Dalton | a4f5ce0 | 2018-06-26 10:13:06 -0600 | [diff] [blame] | 43 | #endif |
| 44 | |
Hal Canary | 8a00144 | 2018-09-19 11:31:27 -0400 | [diff] [blame] | 45 | #include <stdlib.h> |
| 46 | #include <algorithm> |
| 47 | #include <array> |
| 48 | #include <chrono> |
Herb Derby | 1db274d | 2021-02-02 12:34:33 -0500 | [diff] [blame] | 49 | #include <cinttypes> |
Hal Canary | 8a00144 | 2018-09-19 11:31:27 -0400 | [diff] [blame] | 50 | #include <cmath> |
| 51 | #include <vector> |
Chris Dalton | a4f5ce0 | 2018-06-26 10:13:06 -0600 | [diff] [blame] | 52 | |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 53 | /** |
Chris Dalton | a4f5ce0 | 2018-06-26 10:13:06 -0600 | [diff] [blame] | 54 | * This is a minimalist program whose sole purpose is to open a .skp or .svg file, benchmark it on a |
| 55 | * single config, and exit. It is intended to be used through skpbench.py rather than invoked |
| 56 | * directly. Limiting the entire process to a single config/skp pair helps to keep the results |
| 57 | * repeatable. |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 58 | * |
| 59 | * No tiling, looping, or other fanciness is used; it just draws the skp whole into a size-matched |
| 60 | * render target and syncs the GPU after each draw. |
| 61 | * |
Nathaniel Nifong | fa40851 | 2019-07-26 09:44:46 -0400 | [diff] [blame] | 62 | * Well, maybe a little fanciness, MSKP's can be loaded and played. The animation is played as many |
| 63 | * times as necessary to reach the target sample duration and FPS is reported. |
| 64 | * |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 65 | * Currently, only GPU configs are supported. |
| 66 | */ |
| 67 | |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 68 | static DEFINE_bool(ddl, false, "record the skp into DDLs before rendering"); |
Adlai Holler | e5c379d | 2020-05-18 10:21:53 -0400 | [diff] [blame] | 69 | static DEFINE_int(ddlNumRecordingThreads, 0, "number of DDL recording threads (0=num_cores)"); |
Mike Klein | 5b3f343 | 2019-03-21 11:42:21 -0500 | [diff] [blame] | 70 | static DEFINE_int(ddlTilingWidthHeight, 0, "number of tiles along one edge when in DDL mode"); |
Robert Phillips | 24a8e9e | 2020-03-06 20:26:28 +0000 | [diff] [blame] | 71 | |
| 72 | static DEFINE_bool(comparableDDL, false, "render in a way that is comparable to 'comparableSKP'"); |
| 73 | static DEFINE_bool(comparableSKP, false, "report in a way that is comparable to 'comparableDDL'"); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 74 | |
Mike Klein | 5b3f343 | 2019-03-21 11:42:21 -0500 | [diff] [blame] | 75 | static DEFINE_int(duration, 5000, "number of milliseconds to run the benchmark"); |
| 76 | static DEFINE_int(sampleMs, 50, "minimum duration of a sample"); |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 77 | static DEFINE_bool(gpuClock, false, "time on the gpu clock (gpu work only)"); |
| 78 | static DEFINE_bool(fps, false, "use fps instead of ms"); |
| 79 | static DEFINE_string(src, "", |
| 80 | "path to a single .skp or .svg file, or 'warmup' for a builtin warmup run"); |
| 81 | static DEFINE_string(png, "", "if set, save a .png proof to disk at this file location"); |
Mike Klein | 5b3f343 | 2019-03-21 11:42:21 -0500 | [diff] [blame] | 82 | static DEFINE_int(verbosity, 4, "level of verbosity (0=none to 5=debug)"); |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 83 | static DEFINE_bool(suppressHeader, false, "don't print a header row before the results"); |
Chris Dalton | 84c8787 | 2020-01-16 14:45:57 -0700 | [diff] [blame] | 84 | static DEFINE_double(scale, 1, "Scale the size of the canvas and the zoom level by this factor."); |
Herb Derby | 1db274d | 2021-02-02 12:34:33 -0500 | [diff] [blame] | 85 | static DEFINE_bool(dumpSamples, false, "print the individual samples to stdout"); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 86 | |
John Stiles | 00ee8f5 | 2020-05-05 15:57:46 -0400 | [diff] [blame] | 87 | static const char header[] = |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 88 | " accum median max min stddev samples sample_ms clock metric config bench"; |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 89 | |
John Stiles | 00ee8f5 | 2020-05-05 15:57:46 -0400 | [diff] [blame] | 90 | static const char resultFormat[] = |
| 91 | "%8.4g %8.4g %8.4g %8.4g %6.3g%% %7zu %9i %-5s %-6s %-9s %s"; |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 92 | |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 93 | static constexpr int kNumFlushesToPrimeCache = 3; |
| 94 | |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 95 | struct Sample { |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 96 | using duration = std::chrono::nanoseconds; |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 97 | |
| 98 | Sample() : fFrames(0), fDuration(0) {} |
| 99 | double seconds() const { return std::chrono::duration<double>(fDuration).count(); } |
| 100 | double ms() const { return std::chrono::duration<double, std::milli>(fDuration).count(); } |
| 101 | double value() const { return FLAGS_fps ? fFrames / this->seconds() : this->ms() / fFrames; } |
| 102 | static const char* metric() { return FLAGS_fps ? "fps" : "ms"; } |
| 103 | |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 104 | int fFrames; |
| 105 | duration fDuration; |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
csmartdalton | e038489 | 2016-09-28 14:53:07 -0700 | [diff] [blame] | 108 | class GpuSync { |
| 109 | public: |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 110 | GpuSync() {} |
| 111 | ~GpuSync() {} |
csmartdalton | e038489 | 2016-09-28 14:53:07 -0700 | [diff] [blame] | 112 | |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 113 | void waitIfNeeded(); |
| 114 | |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 115 | sk_gpu_test::FlushFinishTracker* newFlushTracker(GrDirectContext* context); |
csmartdalton | e038489 | 2016-09-28 14:53:07 -0700 | [diff] [blame] | 116 | |
| 117 | private: |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 118 | enum { kMaxFrameLag = 3 }; |
| 119 | sk_sp<sk_gpu_test::FlushFinishTracker> fFinishTrackers[kMaxFrameLag - 1]; |
| 120 | int fCurrentFlushIdx = 0; |
csmartdalton | e038489 | 2016-09-28 14:53:07 -0700 | [diff] [blame] | 121 | }; |
| 122 | |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 123 | enum class ExitErr { |
| 124 | kOk = 0, |
| 125 | kUsage = 64, |
| 126 | kData = 65, |
| 127 | kUnavailable = 69, |
| 128 | kIO = 74, |
| 129 | kSoftware = 70 |
| 130 | }; |
| 131 | |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 132 | static void flush_with_sync(GrDirectContext*, GpuSync&); |
| 133 | static void draw_skp_and_flush_with_sync(GrDirectContext*, SkSurface*, const SkPicture*, GpuSync&); |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 134 | static sk_sp<SkPicture> create_warmup_skp(); |
Chris Dalton | a4f5ce0 | 2018-06-26 10:13:06 -0600 | [diff] [blame] | 135 | static sk_sp<SkPicture> create_skp_from_svg(SkStream*, const char* filename); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 136 | static bool mkdir_p(const SkString& name); |
Mike Klein | 88544fb | 2019-03-20 10:50:33 -0500 | [diff] [blame] | 137 | static SkString join(const CommandLineFlags::StringArray&); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 138 | static void exitf(ExitErr, const char* format, ...); |
| 139 | |
Nathaniel Nifong | fa40851 | 2019-07-26 09:44:46 -0400 | [diff] [blame] | 140 | // An interface used by both static SKPs and animated SKPs |
| 141 | class SkpProducer { |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 142 | public: |
| 143 | virtual ~SkpProducer() {} |
| 144 | // Draw an SkPicture to the provided surface, flush the surface, and sync the GPU. |
| 145 | // You may use the static draw_skp_and_flush_with_sync declared above. |
| 146 | // returned int tells how many draw/flush/sync were done. |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 147 | virtual int drawAndFlushAndSync(GrDirectContext*, SkSurface* surface, GpuSync& gpuSync) = 0; |
Nathaniel Nifong | fa40851 | 2019-07-26 09:44:46 -0400 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | class StaticSkp : public SkpProducer { |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 151 | public: |
| 152 | StaticSkp(sk_sp<SkPicture> skp) : fSkp(skp) {} |
Nathaniel Nifong | fa40851 | 2019-07-26 09:44:46 -0400 | [diff] [blame] | 153 | |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 154 | int drawAndFlushAndSync(GrDirectContext* context, |
| 155 | SkSurface* surface, |
| 156 | GpuSync& gpuSync) override { |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 157 | draw_skp_and_flush_with_sync(context, surface, fSkp.get(), gpuSync); |
Nathaniel Nifong | fa40851 | 2019-07-26 09:44:46 -0400 | [diff] [blame] | 158 | return 1; |
| 159 | } |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 160 | |
| 161 | private: |
| 162 | sk_sp<SkPicture> fSkp; |
Nathaniel Nifong | fa40851 | 2019-07-26 09:44:46 -0400 | [diff] [blame] | 163 | }; |
| 164 | |
| 165 | // A class for playing/benchmarking a multi frame SKP file. |
| 166 | // the recorded frames are looped over repeatedly. |
| 167 | // This type of benchmark may have a much higher std dev in frame times. |
| 168 | class MultiFrameSkp : public SkpProducer { |
| 169 | public: |
| 170 | MultiFrameSkp(const std::vector<SkDocumentPage>& frames) : fFrames(frames){} |
| 171 | |
| 172 | static std::unique_ptr<MultiFrameSkp> MakeFromFile(const SkString& path) { |
| 173 | // Load the multi frame skp at the given filename. |
| 174 | std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path.c_str()); |
| 175 | if (!stream) { return nullptr; } |
| 176 | |
| 177 | // Attempt to deserialize with an image sharing serial proc. |
| 178 | auto deserialContext = std::make_unique<SkSharingDeserialContext>(); |
| 179 | SkDeserialProcs procs; |
| 180 | procs.fImageProc = SkSharingDeserialContext::deserializeImage; |
| 181 | procs.fImageCtx = deserialContext.get(); |
| 182 | |
| 183 | // The outer format of multi-frame skps is the multi-picture document, which is a |
| 184 | // skp file containing subpictures separated by annotations. |
Kevin Lubick | 68de6e3 | 2023-10-13 11:19:03 -0400 | [diff] [blame] | 185 | int page_count = SkMultiPictureDocument::ReadPageCount(stream.get()); |
Nathaniel Nifong | fa40851 | 2019-07-26 09:44:46 -0400 | [diff] [blame] | 186 | if (!page_count) { |
| 187 | return nullptr; |
| 188 | } |
| 189 | std::vector<SkDocumentPage> frames(page_count); // can't call reserve, why? |
Kevin Lubick | 68de6e3 | 2023-10-13 11:19:03 -0400 | [diff] [blame] | 190 | if (!SkMultiPictureDocument::Read(stream.get(), frames.data(), page_count, &procs)) { |
Nathaniel Nifong | fa40851 | 2019-07-26 09:44:46 -0400 | [diff] [blame] | 191 | return nullptr; |
| 192 | } |
| 193 | |
| 194 | return std::make_unique<MultiFrameSkp>(frames); |
| 195 | } |
| 196 | |
| 197 | // Draw the whole animation once. |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 198 | int drawAndFlushAndSync(GrDirectContext* context, |
| 199 | SkSurface* surface, |
| 200 | GpuSync& gpuSync) override { |
Nathaniel Nifong | fa40851 | 2019-07-26 09:44:46 -0400 | [diff] [blame] | 201 | for (int i=0; i<this->count(); i++){ |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 202 | draw_skp_and_flush_with_sync(context, surface, this->frame(i).get(), gpuSync); |
Nathaniel Nifong | fa40851 | 2019-07-26 09:44:46 -0400 | [diff] [blame] | 203 | } |
| 204 | return this->count(); |
| 205 | } |
| 206 | // Return the requested frame. |
| 207 | sk_sp<SkPicture> frame(int n) const { return fFrames[n].fPicture; } |
| 208 | // Return the number of frames in the recording. |
| 209 | int count() const { return fFrames.size(); } |
| 210 | private: |
| 211 | std::vector<SkDocumentPage> fFrames; |
| 212 | }; |
| 213 | |
Robert Phillips | 0d8722c | 2021-03-29 13:29:40 -0400 | [diff] [blame] | 214 | static void ddl_sample(GrDirectContext* dContext, DDLTileHelper* tiles, GpuSync& gpuSync, |
Adlai Holler | e5c379d | 2020-05-18 10:21:53 -0400 | [diff] [blame] | 215 | Sample* sample, SkTaskGroup* recordingTaskGroup, SkTaskGroup* gpuTaskGroup, |
Robert Phillips | 0d8722c | 2021-03-29 13:29:40 -0400 | [diff] [blame] | 216 | std::chrono::high_resolution_clock::time_point* startStopTime, |
| 217 | SkPicture* picture) { |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 218 | using clock = std::chrono::high_resolution_clock; |
| 219 | |
| 220 | clock::time_point start = *startStopTime; |
| 221 | |
Robert Phillips | 24a8e9e | 2020-03-06 20:26:28 +0000 | [diff] [blame] | 222 | if (FLAGS_comparableDDL) { |
| 223 | SkASSERT(!FLAGS_comparableSKP); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 224 | |
Robert Phillips | 24a8e9e | 2020-03-06 20:26:28 +0000 | [diff] [blame] | 225 | // In this mode we simply alternate between creating a DDL and drawing it - all on one |
| 226 | // thread. The interleaving is so that we don't starve the GPU. |
| 227 | // One unfortunate side effect of this is that we can't delete the DDLs until after |
| 228 | // the GPU work is flushed. |
Robert Phillips | 0d8722c | 2021-03-29 13:29:40 -0400 | [diff] [blame] | 229 | tiles->interleaveDDLCreationAndDraw(dContext, picture); |
Robert Phillips | 24a8e9e | 2020-03-06 20:26:28 +0000 | [diff] [blame] | 230 | } else if (FLAGS_comparableSKP) { |
| 231 | // In this mode simply draw the re-inflated per-tile SKPs directly to the GPU w/o going |
| 232 | // through a DDL. |
Robert Phillips | 0d8722c | 2021-03-29 13:29:40 -0400 | [diff] [blame] | 233 | tiles->drawAllTilesDirectly(dContext, picture); |
Robert Phillips | 24a8e9e | 2020-03-06 20:26:28 +0000 | [diff] [blame] | 234 | } else { |
Robert Phillips | 0d8722c | 2021-03-29 13:29:40 -0400 | [diff] [blame] | 235 | tiles->kickOffThreadedWork(recordingTaskGroup, gpuTaskGroup, dContext, picture); |
Adlai Holler | e5c379d | 2020-05-18 10:21:53 -0400 | [diff] [blame] | 236 | recordingTaskGroup->wait(); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 237 | } |
Adlai Holler | e5c379d | 2020-05-18 10:21:53 -0400 | [diff] [blame] | 238 | |
| 239 | if (gpuTaskGroup) { |
| 240 | gpuTaskGroup->add([&]{ |
Robert Phillips | 0d8722c | 2021-03-29 13:29:40 -0400 | [diff] [blame] | 241 | flush_with_sync(dContext, gpuSync); |
Adlai Holler | e5c379d | 2020-05-18 10:21:53 -0400 | [diff] [blame] | 242 | }); |
| 243 | gpuTaskGroup->wait(); |
| 244 | } else { |
Robert Phillips | 0d8722c | 2021-03-29 13:29:40 -0400 | [diff] [blame] | 245 | flush_with_sync(dContext, gpuSync); |
Adlai Holler | e5c379d | 2020-05-18 10:21:53 -0400 | [diff] [blame] | 246 | } |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 247 | |
| 248 | *startStopTime = clock::now(); |
| 249 | |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 250 | if (sample) { |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 251 | sample->fDuration += *startStopTime - start; |
| 252 | sample->fFrames++; |
| 253 | } |
| 254 | } |
| 255 | |
Kevin Lubick | 0377199 | 2023-05-24 11:09:36 -0400 | [diff] [blame] | 256 | static void run_ddl_benchmark(sk_gpu_test::TestContext* testContext, |
| 257 | GrDirectContext* dContext, |
| 258 | sk_sp<SkSurface> dstSurface, |
| 259 | SkPicture* inputPicture, |
Adlai Holler | e5c379d | 2020-05-18 10:21:53 -0400 | [diff] [blame] | 260 | std::vector<Sample>* samples) { |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 261 | using clock = std::chrono::high_resolution_clock; |
| 262 | const Sample::duration sampleDuration = std::chrono::milliseconds(FLAGS_sampleMs); |
| 263 | const clock::duration benchDuration = std::chrono::milliseconds(FLAGS_duration); |
| 264 | |
Kevin Lubick | 0bff57e | 2023-06-09 14:29:17 -0400 | [diff] [blame] | 265 | GrSurfaceCharacterization dstCharacterization; |
Robert Phillips | 11c6767 | 2020-04-23 15:10:03 -0400 | [diff] [blame] | 266 | SkAssertResult(dstSurface->characterize(&dstCharacterization)); |
Robert Phillips | 19f466d | 2020-02-26 10:27:07 -0500 | [diff] [blame] | 267 | |
Robert Phillips | 11c6767 | 2020-04-23 15:10:03 -0400 | [diff] [blame] | 268 | SkIRect viewport = dstSurface->imageInfo().bounds(); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 269 | |
Kevin Lubick | a201943 | 2023-06-12 15:42:51 -0400 | [diff] [blame] | 270 | auto supportedYUVADataTypes = skgpu::ganesh::SupportedTextureFormats(*dContext); |
Brian Salomon | 59c60b0 | 2020-09-01 15:01:15 -0400 | [diff] [blame] | 271 | DDLPromiseImageHelper promiseImageHelper(supportedYUVADataTypes); |
Robert Phillips | 0d8722c | 2021-03-29 13:29:40 -0400 | [diff] [blame] | 272 | sk_sp<SkPicture> newSKP = promiseImageHelper.recreateSKP(dContext, inputPicture); |
| 273 | if (!newSKP) { |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 274 | exitf(ExitErr::kUnavailable, "DDL: conversion of skp failed"); |
| 275 | } |
| 276 | |
Robert Phillips | 0d8722c | 2021-03-29 13:29:40 -0400 | [diff] [blame] | 277 | promiseImageHelper.uploadAllToGPU(nullptr, dContext); |
Robert Phillips | 923181b | 2020-02-14 12:36:37 -0500 | [diff] [blame] | 278 | |
Robert Phillips | 0d8722c | 2021-03-29 13:29:40 -0400 | [diff] [blame] | 279 | DDLTileHelper tiles(dContext, dstCharacterization, viewport, |
Robert Phillips | 96f6d9a | 2021-02-26 10:41:06 -0500 | [diff] [blame] | 280 | FLAGS_ddlTilingWidthHeight, FLAGS_ddlTilingWidthHeight, |
Robert Phillips | 0c08849 | 2020-11-10 08:30:50 -0500 | [diff] [blame] | 281 | /* addRandomPaddingToDst */ false); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 282 | |
Robert Phillips | 0d8722c | 2021-03-29 13:29:40 -0400 | [diff] [blame] | 283 | tiles.createBackendTextures(nullptr, dContext); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 284 | |
Adlai Holler | e5c379d | 2020-05-18 10:21:53 -0400 | [diff] [blame] | 285 | // In comparable modes, there is no GPU thread. The following pointers are all null. |
| 286 | // Otherwise, we transfer testContext onto the GPU thread until after the bench. |
| 287 | std::unique_ptr<SkExecutor> gpuThread; |
| 288 | std::unique_ptr<SkTaskGroup> gpuTaskGroup; |
| 289 | std::unique_ptr<SkExecutor> recordingThreadPool; |
| 290 | std::unique_ptr<SkTaskGroup> recordingTaskGroup; |
| 291 | if (!FLAGS_comparableDDL && !FLAGS_comparableSKP) { |
| 292 | gpuThread = SkExecutor::MakeFIFOThreadPool(1, false); |
| 293 | gpuTaskGroup = std::make_unique<SkTaskGroup>(*gpuThread); |
| 294 | recordingThreadPool = SkExecutor::MakeFIFOThreadPool(FLAGS_ddlNumRecordingThreads, false); |
| 295 | recordingTaskGroup = std::make_unique<SkTaskGroup>(*recordingThreadPool); |
| 296 | testContext->makeNotCurrent(); |
| 297 | gpuTaskGroup->add([=]{ testContext->makeCurrent(); }); |
| 298 | } |
Robert Phillips | f7dcdb0 | 2018-06-21 11:18:25 -0400 | [diff] [blame] | 299 | |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 300 | clock::time_point startStopTime = clock::now(); |
| 301 | |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 302 | GpuSync gpuSync; |
Robert Phillips | 0d8722c | 2021-03-29 13:29:40 -0400 | [diff] [blame] | 303 | ddl_sample(dContext, &tiles, gpuSync, nullptr, recordingTaskGroup.get(), |
| 304 | gpuTaskGroup.get(), &startStopTime, newSKP.get()); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 305 | |
| 306 | clock::duration cumulativeDuration = std::chrono::milliseconds(0); |
| 307 | |
| 308 | do { |
| 309 | samples->emplace_back(); |
| 310 | Sample& sample = samples->back(); |
| 311 | |
| 312 | do { |
Robert Phillips | 24a8e9e | 2020-03-06 20:26:28 +0000 | [diff] [blame] | 313 | tiles.resetAllTiles(); |
Robert Phillips | 0d8722c | 2021-03-29 13:29:40 -0400 | [diff] [blame] | 314 | ddl_sample(dContext, &tiles, gpuSync, &sample, recordingTaskGroup.get(), |
| 315 | gpuTaskGroup.get(), &startStopTime, newSKP.get()); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 316 | } while (sample.fDuration < sampleDuration); |
| 317 | |
| 318 | cumulativeDuration += sample.fDuration; |
| 319 | } while (cumulativeDuration < benchDuration || 0 == samples->size() % 2); |
| 320 | |
Adlai Holler | e5c379d | 2020-05-18 10:21:53 -0400 | [diff] [blame] | 321 | // Move the context back to this thread now that we're done benching. |
| 322 | if (gpuTaskGroup) { |
| 323 | gpuTaskGroup->add([=]{ |
| 324 | testContext->makeNotCurrent(); |
| 325 | }); |
| 326 | gpuTaskGroup->wait(); |
| 327 | testContext->makeCurrent(); |
| 328 | } |
| 329 | |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 330 | if (!FLAGS_png.isEmpty()) { |
| 331 | // The user wants to see the final result |
Kevin Lubick | 0bff57e | 2023-06-09 14:29:17 -0400 | [diff] [blame] | 332 | skgpu::ganesh::DrawDDL(dstSurface, tiles.composeDDL()); |
Kevin Lubick | 99bcee2 | 2023-09-06 10:09:08 -0400 | [diff] [blame] | 333 | dContext->flushAndSubmit(dstSurface.get(), GrSyncCpu::kNo); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 334 | } |
Greg Daniel | d78a9b4 | 2019-12-16 15:37:19 -0500 | [diff] [blame] | 335 | |
Robert Phillips | 24a8e9e | 2020-03-06 20:26:28 +0000 | [diff] [blame] | 336 | tiles.resetAllTiles(); |
| 337 | |
Greg Daniel | d78a9b4 | 2019-12-16 15:37:19 -0500 | [diff] [blame] | 338 | // Make sure the gpu has finished all its work before we exit this function and delete the |
| 339 | // fence. |
Robert Phillips | 0d8722c | 2021-03-29 13:29:40 -0400 | [diff] [blame] | 340 | dContext->flush(); |
Kevin Lubick | 99bcee2 | 2023-09-06 10:09:08 -0400 | [diff] [blame] | 341 | dContext->submit(GrSyncCpu::kYes); |
Robert Phillips | 8472a3d | 2020-04-16 16:27:45 -0400 | [diff] [blame] | 342 | |
Robert Phillips | 0d8722c | 2021-03-29 13:29:40 -0400 | [diff] [blame] | 343 | promiseImageHelper.deleteAllFromGPU(nullptr, dContext); |
Robert Phillips | 8472a3d | 2020-04-16 16:27:45 -0400 | [diff] [blame] | 344 | |
Robert Phillips | 0d8722c | 2021-03-29 13:29:40 -0400 | [diff] [blame] | 345 | tiles.deleteBackendTextures(nullptr, dContext); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 346 | } |
| 347 | |
Kevin Lubick | 0377199 | 2023-05-24 11:09:36 -0400 | [diff] [blame] | 348 | static void run_benchmark(GrDirectContext* context, |
| 349 | sk_sp<SkSurface> surface, |
| 350 | SkpProducer* skpp, |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 351 | std::vector<Sample>* samples) { |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 352 | using clock = std::chrono::high_resolution_clock; |
| 353 | const Sample::duration sampleDuration = std::chrono::milliseconds(FLAGS_sampleMs); |
csmartdalton | 037adf3 | 2016-09-28 13:56:01 -0700 | [diff] [blame] | 354 | const clock::duration benchDuration = std::chrono::milliseconds(FLAGS_duration); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 355 | |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 356 | GpuSync gpuSync; |
Nathaniel Nifong | fa40851 | 2019-07-26 09:44:46 -0400 | [diff] [blame] | 357 | int i = 0; |
| 358 | do { |
Kevin Lubick | 0377199 | 2023-05-24 11:09:36 -0400 | [diff] [blame] | 359 | i += skpp->drawAndFlushAndSync(context, surface.get(), gpuSync); |
Nathaniel Nifong | fa40851 | 2019-07-26 09:44:46 -0400 | [diff] [blame] | 360 | } while(i < kNumFlushesToPrimeCache); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 361 | |
csmartdalton | 037adf3 | 2016-09-28 13:56:01 -0700 | [diff] [blame] | 362 | clock::time_point now = clock::now(); |
| 363 | const clock::time_point endTime = now + benchDuration; |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 364 | |
csmartdalton | 037adf3 | 2016-09-28 13:56:01 -0700 | [diff] [blame] | 365 | do { |
| 366 | clock::time_point sampleStart = now; |
| 367 | samples->emplace_back(); |
| 368 | Sample& sample = samples->back(); |
| 369 | |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 370 | do { |
Kevin Lubick | 0377199 | 2023-05-24 11:09:36 -0400 | [diff] [blame] | 371 | sample.fFrames += skpp->drawAndFlushAndSync(context, surface.get(), gpuSync); |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 372 | now = clock::now(); |
| 373 | sample.fDuration = now - sampleStart; |
csmartdalton | 037adf3 | 2016-09-28 13:56:01 -0700 | [diff] [blame] | 374 | } while (sample.fDuration < sampleDuration); |
| 375 | } while (now < endTime || 0 == samples->size() % 2); |
Greg Daniel | d78a9b4 | 2019-12-16 15:37:19 -0500 | [diff] [blame] | 376 | |
| 377 | // Make sure the gpu has finished all its work before we exit this function and delete the |
| 378 | // fence. |
Kevin Lubick | 99bcee2 | 2023-09-06 10:09:08 -0400 | [diff] [blame] | 379 | context->flush(surface.get()); |
| 380 | context->submit(GrSyncCpu::kYes); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Kevin Lubick | 0377199 | 2023-05-24 11:09:36 -0400 | [diff] [blame] | 383 | static void run_gpu_time_benchmark(sk_gpu_test::GpuTimer* gpuTimer, |
| 384 | GrDirectContext* context, |
| 385 | sk_sp<SkSurface> surface, |
| 386 | const SkPicture* skp, |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 387 | std::vector<Sample>* samples) { |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 388 | using sk_gpu_test::PlatformTimerQuery; |
| 389 | using clock = std::chrono::steady_clock; |
| 390 | const clock::duration sampleDuration = std::chrono::milliseconds(FLAGS_sampleMs); |
| 391 | const clock::duration benchDuration = std::chrono::milliseconds(FLAGS_duration); |
| 392 | |
| 393 | if (!gpuTimer->disjointSupport()) { |
| 394 | fprintf(stderr, "WARNING: GPU timer cannot detect disjoint operations; " |
| 395 | "results may be unreliable\n"); |
| 396 | } |
| 397 | |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 398 | GpuSync gpuSync; |
Kevin Lubick | 0377199 | 2023-05-24 11:09:36 -0400 | [diff] [blame] | 399 | draw_skp_and_flush_with_sync(context, surface.get(), skp, gpuSync); |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 400 | |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 401 | PlatformTimerQuery previousTime = 0; |
| 402 | for (int i = 1; i < kNumFlushesToPrimeCache; ++i) { |
| 403 | gpuTimer->queueStart(); |
Kevin Lubick | 0377199 | 2023-05-24 11:09:36 -0400 | [diff] [blame] | 404 | draw_skp_and_flush_with_sync(context, surface.get(), skp, gpuSync); |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 405 | previousTime = gpuTimer->queueStop(); |
Chris Dalton | a2b5b64 | 2018-06-24 13:08:57 -0600 | [diff] [blame] | 406 | } |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 407 | |
| 408 | clock::time_point now = clock::now(); |
| 409 | const clock::time_point endTime = now + benchDuration; |
| 410 | |
| 411 | do { |
| 412 | const clock::time_point sampleEndTime = now + sampleDuration; |
| 413 | samples->emplace_back(); |
| 414 | Sample& sample = samples->back(); |
| 415 | |
| 416 | do { |
| 417 | gpuTimer->queueStart(); |
Kevin Lubick | 0377199 | 2023-05-24 11:09:36 -0400 | [diff] [blame] | 418 | draw_skp_and_flush_with_sync(context, surface.get(), skp, gpuSync); |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 419 | PlatformTimerQuery time = gpuTimer->queueStop(); |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 420 | |
| 421 | switch (gpuTimer->checkQueryStatus(previousTime)) { |
| 422 | using QueryStatus = sk_gpu_test::GpuTimer::QueryStatus; |
| 423 | case QueryStatus::kInvalid: |
| 424 | exitf(ExitErr::kUnavailable, "GPU timer failed"); |
John Stiles | 30212b7 | 2020-06-11 17:55:07 -0400 | [diff] [blame] | 425 | break; |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 426 | case QueryStatus::kPending: |
| 427 | exitf(ExitErr::kUnavailable, "timer query still not ready after fence sync"); |
John Stiles | 30212b7 | 2020-06-11 17:55:07 -0400 | [diff] [blame] | 428 | break; |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 429 | case QueryStatus::kDisjoint: |
| 430 | if (FLAGS_verbosity >= 4) { |
| 431 | fprintf(stderr, "discarding timer query due to disjoint operations.\n"); |
| 432 | } |
| 433 | break; |
| 434 | case QueryStatus::kAccurate: |
| 435 | sample.fDuration += gpuTimer->getTimeElapsed(previousTime); |
| 436 | ++sample.fFrames; |
| 437 | break; |
| 438 | } |
| 439 | gpuTimer->deleteQuery(previousTime); |
| 440 | previousTime = time; |
| 441 | now = clock::now(); |
| 442 | } while (now < sampleEndTime || 0 == sample.fFrames); |
| 443 | } while (now < endTime || 0 == samples->size() % 2); |
| 444 | |
| 445 | gpuTimer->deleteQuery(previousTime); |
Greg Daniel | d78a9b4 | 2019-12-16 15:37:19 -0500 | [diff] [blame] | 446 | |
| 447 | // Make sure the gpu has finished all its work before we exit this function and delete the |
| 448 | // fence. |
Kevin Lubick | 99bcee2 | 2023-09-06 10:09:08 -0400 | [diff] [blame] | 449 | context->flush(surface.get()); |
| 450 | context->submit(GrSyncCpu::kYes); |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 451 | } |
| 452 | |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 453 | void print_result(const std::vector<Sample>& samples, const char* config, const char* bench) { |
| 454 | if (0 == (samples.size() % 2)) { |
| 455 | exitf(ExitErr::kSoftware, "attempted to gather stats on even number of samples"); |
| 456 | } |
| 457 | |
Herb Derby | 1db274d | 2021-02-02 12:34:33 -0500 | [diff] [blame] | 458 | if (FLAGS_dumpSamples) { |
| 459 | printf("Samples: "); |
| 460 | for (const Sample& sample : samples) { |
| 461 | printf("%" PRId64 " ", static_cast<int64_t>(sample.fDuration.count())); |
| 462 | } |
| 463 | printf("%s\n", bench); |
| 464 | } |
| 465 | |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 466 | Sample accum = Sample(); |
| 467 | std::vector<double> values; |
| 468 | values.reserve(samples.size()); |
| 469 | for (const Sample& sample : samples) { |
| 470 | accum.fFrames += sample.fFrames; |
| 471 | accum.fDuration += sample.fDuration; |
| 472 | values.push_back(sample.value()); |
| 473 | } |
| 474 | std::sort(values.begin(), values.end()); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 475 | |
csmartdalton | 6904b19 | 2016-09-29 06:23:23 -0700 | [diff] [blame] | 476 | const double accumValue = accum.value(); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 477 | double variance = 0; |
csmartdalton | 037adf3 | 2016-09-28 13:56:01 -0700 | [diff] [blame] | 478 | for (double value : values) { |
| 479 | const double delta = value - accumValue; |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 480 | variance += delta * delta; |
| 481 | } |
csmartdalton | 037adf3 | 2016-09-28 13:56:01 -0700 | [diff] [blame] | 482 | variance /= values.size(); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 483 | // Technically, this is the relative standard deviation. |
csmartdalton | 037adf3 | 2016-09-28 13:56:01 -0700 | [diff] [blame] | 484 | const double stddev = 100/*%*/ * sqrt(variance) / accumValue; |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 485 | |
csmartdalton | 6904b19 | 2016-09-29 06:23:23 -0700 | [diff] [blame] | 486 | printf(resultFormat, accumValue, values[values.size() / 2], values.back(), values.front(), |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 487 | stddev, values.size(), FLAGS_sampleMs, FLAGS_gpuClock ? "gpu" : "cpu", Sample::metric(), |
| 488 | config, bench); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 489 | printf("\n"); |
| 490 | fflush(stdout); |
| 491 | } |
| 492 | |
| 493 | int main(int argc, char** argv) { |
Mike Klein | 88544fb | 2019-03-20 10:50:33 -0500 | [diff] [blame] | 494 | CommandLineFlags::SetUsage( |
| 495 | "Use skpbench.py instead. " |
| 496 | "You usually don't want to use this program directly."); |
| 497 | CommandLineFlags::Parse(argc, argv); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 498 | |
| 499 | if (!FLAGS_suppressHeader) { |
| 500 | printf("%s\n", header); |
| 501 | } |
csmartdalton | 037adf3 | 2016-09-28 13:56:01 -0700 | [diff] [blame] | 502 | if (FLAGS_duration <= 0) { |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 503 | exit(0); // This can be used to print the header and quit. |
| 504 | } |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 505 | |
| 506 | // Parse the config. |
| 507 | const SkCommandLineConfigGpu* config = nullptr; // Initialize for spurious warning. |
| 508 | SkCommandLineConfigArray configs; |
| 509 | ParseConfigs(FLAGS_config, &configs); |
Herb Derby | ffacce5 | 2022-11-09 10:51:34 -0500 | [diff] [blame] | 510 | if (configs.size() != 1 || !(config = configs[0]->asConfigGpu())) { |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 511 | exitf(ExitErr::kUsage, "invalid config '%s': must specify one (and only one) GPU config", |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 512 | join(FLAGS_config).c_str()); |
| 513 | } |
| 514 | |
| 515 | // Parse the skp. |
Herb Derby | 6a0a4c4 | 2022-09-30 16:43:14 -0400 | [diff] [blame] | 516 | if (FLAGS_src.size() != 1) { |
Chris Dalton | a4f5ce0 | 2018-06-26 10:13:06 -0600 | [diff] [blame] | 517 | exitf(ExitErr::kUsage, |
| 518 | "invalid input '%s': must specify a single .skp or .svg file, or 'warmup'", |
| 519 | join(FLAGS_src).c_str()); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 520 | } |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 521 | |
| 522 | SkGraphics::Init(); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 523 | |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 524 | sk_sp<SkPicture> skp; |
Nathaniel Nifong | fa40851 | 2019-07-26 09:44:46 -0400 | [diff] [blame] | 525 | std::unique_ptr<MultiFrameSkp> mskp; // populated if the file is multi frame. |
Chris Dalton | a4f5ce0 | 2018-06-26 10:13:06 -0600 | [diff] [blame] | 526 | SkString srcname; |
| 527 | if (0 == strcmp(FLAGS_src[0], "warmup")) { |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 528 | skp = create_warmup_skp(); |
Chris Dalton | a4f5ce0 | 2018-06-26 10:13:06 -0600 | [diff] [blame] | 529 | srcname = "warmup"; |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 530 | } else { |
Chris Dalton | a4f5ce0 | 2018-06-26 10:13:06 -0600 | [diff] [blame] | 531 | SkString srcfile(FLAGS_src[0]); |
| 532 | std::unique_ptr<SkStream> srcstream(SkStream::MakeFromFile(srcfile.c_str())); |
| 533 | if (!srcstream) { |
| 534 | exitf(ExitErr::kIO, "failed to open file %s", srcfile.c_str()); |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 535 | } |
Chris Dalton | a4f5ce0 | 2018-06-26 10:13:06 -0600 | [diff] [blame] | 536 | if (srcfile.endsWith(".svg")) { |
| 537 | skp = create_skp_from_svg(srcstream.get(), srcfile.c_str()); |
Nathaniel Nifong | fa40851 | 2019-07-26 09:44:46 -0400 | [diff] [blame] | 538 | } else if (srcfile.endsWith(".mskp")) { |
| 539 | mskp = MultiFrameSkp::MakeFromFile(srcfile); |
| 540 | // populate skp with it's first frame, for width height determination. |
| 541 | skp = mskp->frame(0); |
Chris Dalton | a4f5ce0 | 2018-06-26 10:13:06 -0600 | [diff] [blame] | 542 | } else { |
| 543 | skp = SkPicture::MakeFromStream(srcstream.get()); |
| 544 | } |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 545 | if (!skp) { |
Chris Dalton | a4f5ce0 | 2018-06-26 10:13:06 -0600 | [diff] [blame] | 546 | exitf(ExitErr::kData, "failed to parse file %s", srcfile.c_str()); |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 547 | } |
Chris Dalton | a4f5ce0 | 2018-06-26 10:13:06 -0600 | [diff] [blame] | 548 | srcname = SkOSPath::Basename(srcfile.c_str()); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 549 | } |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 550 | int width = std::min(SkScalarCeilToInt(skp->cullRect().width()), 2048), |
| 551 | height = std::min(SkScalarCeilToInt(skp->cullRect().height()), 2048); |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 552 | if (FLAGS_verbosity >= 3 && |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 553 | (width != skp->cullRect().width() || height != skp->cullRect().height())) { |
csmartdalton | d7a9db6 | 2016-09-22 05:10:02 -0700 | [diff] [blame] | 554 | fprintf(stderr, "%s is too large (%ix%i), cropping to %ix%i.\n", |
Chris Dalton | a4f5ce0 | 2018-06-26 10:13:06 -0600 | [diff] [blame] | 555 | srcname.c_str(), SkScalarCeilToInt(skp->cullRect().width()), |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 556 | SkScalarCeilToInt(skp->cullRect().height()), width, height); |
| 557 | } |
Chris Dalton | 84c8787 | 2020-01-16 14:45:57 -0700 | [diff] [blame] | 558 | if (FLAGS_scale != 1) { |
| 559 | width *= FLAGS_scale; |
| 560 | height *= FLAGS_scale; |
| 561 | if (FLAGS_verbosity >= 3) { |
| 562 | fprintf(stderr, "Scale factor of %.2f: scaling to %ix%i.\n", |
| 563 | FLAGS_scale, width, height); |
| 564 | } |
| 565 | } |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 566 | |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 567 | if (config->getSurfType() != SkCommandLineConfigGpu::SurfType::kDefault) { |
| 568 | exitf(ExitErr::kUnavailable, "This tool only supports the default surface type. (%s)", |
| 569 | config->getTag().c_str()); |
| 570 | } |
| 571 | |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 572 | // Create a context. |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 573 | GrContextOptions ctxOptions; |
Kevin Lubick | 8f4e560 | 2021-10-14 09:50:00 -0400 | [diff] [blame] | 574 | CommonFlags::SetCtxOptions(&ctxOptions); |
csmartdalton | 008b9d8 | 2017-02-22 12:00:42 -0700 | [diff] [blame] | 575 | sk_gpu_test::GrContextFactory factory(ctxOptions); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 576 | sk_gpu_test::ContextInfo ctxInfo = |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 577 | factory.getContextInfo(config->getContextType(), config->getContextOverrides()); |
Robert Phillips | 7b4e43c | 2020-07-01 16:59:17 -0400 | [diff] [blame] | 578 | auto ctx = ctxInfo.directContext(); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 579 | if (!ctx) { |
| 580 | exitf(ExitErr::kUnavailable, "failed to create context for config %s", |
| 581 | config->getTag().c_str()); |
| 582 | } |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 583 | if (ctx->maxRenderTargetSize() < std::max(width, height)) { |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 584 | exitf(ExitErr::kUnavailable, "render target size %ix%i not supported by platform (max: %i)", |
Brian Salomon | c7fe0f7 | 2018-05-11 10:14:21 -0400 | [diff] [blame] | 585 | width, height, ctx->maxRenderTargetSize()); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 586 | } |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 587 | GrBackendFormat format = ctx->defaultBackendFormat(config->getColorType(), GrRenderable::kYes); |
| 588 | if (!format.isValid()) { |
| 589 | exitf(ExitErr::kUnavailable, "failed to get GrBackendFormat from SkColorType: %d", |
Greg Daniel | 0a7aa14 | 2018-02-21 13:02:32 -0500 | [diff] [blame] | 590 | config->getColorType()); |
| 591 | } |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 592 | int supportedSampleCount = ctx->priv().caps()->getRenderTargetSampleCount( |
Greg Daniel | 6fa62e2 | 2019-08-07 15:52:37 -0400 | [diff] [blame] | 593 | config->getSamples(), format); |
Greg Daniel | 81e7bf8 | 2017-07-19 14:47:42 -0400 | [diff] [blame] | 594 | if (supportedSampleCount != config->getSamples()) { |
| 595 | exitf(ExitErr::kUnavailable, "sample count %i not supported by platform", |
| 596 | config->getSamples()); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 597 | } |
| 598 | sk_gpu_test::TestContext* testCtx = ctxInfo.testContext(); |
| 599 | if (!testCtx) { |
| 600 | exitf(ExitErr::kSoftware, "testContext is null"); |
| 601 | } |
| 602 | if (!testCtx->fenceSyncSupport()) { |
| 603 | exitf(ExitErr::kUnavailable, "GPU does not support fence sync"); |
| 604 | } |
| 605 | |
| 606 | // Create a render target. |
Brian Osman | fcb5023 | 2021-08-12 10:51:48 -0400 | [diff] [blame] | 607 | SkImageInfo info = SkImageInfo::Make( |
| 608 | width, height, config->getColorType(), config->getAlphaType(), config->refColorSpace()); |
Chris Dalton | 180b4a1 | 2021-03-16 20:49:15 -0600 | [diff] [blame] | 609 | SkSurfaceProps props(config->getSurfaceFlags(), kRGB_H_SkPixelGeometry); |
Kevin Lubick | 5c93acf | 2023-05-09 12:11:43 -0400 | [diff] [blame] | 610 | sk_sp<SkSurface> surface = |
| 611 | SkSurfaces::RenderTarget(ctx, skgpu::Budgeted::kNo, info, config->getSamples(), &props); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 612 | if (!surface) { |
| 613 | exitf(ExitErr::kUnavailable, "failed to create %ix%i render target for config %s", |
| 614 | width, height, config->getTag().c_str()); |
| 615 | } |
| 616 | |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 617 | // Run the benchmark. |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 618 | std::vector<Sample> samples; |
csmartdalton | 037adf3 | 2016-09-28 13:56:01 -0700 | [diff] [blame] | 619 | if (FLAGS_sampleMs > 0) { |
| 620 | // +1 because we might take one more sample in order to have an odd number. |
| 621 | samples.reserve(1 + (FLAGS_duration + FLAGS_sampleMs - 1) / FLAGS_sampleMs); |
| 622 | } else { |
| 623 | samples.reserve(2 * FLAGS_duration); |
| 624 | } |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 625 | SkCanvas* canvas = surface->getCanvas(); |
| 626 | canvas->translate(-skp->cullRect().x(), -skp->cullRect().y()); |
Chris Dalton | 84c8787 | 2020-01-16 14:45:57 -0700 | [diff] [blame] | 627 | if (FLAGS_scale != 1) { |
| 628 | canvas->scale(FLAGS_scale, FLAGS_scale); |
| 629 | } |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 630 | if (!FLAGS_gpuClock) { |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 631 | if (FLAGS_ddl) { |
Adlai Holler | e5c379d | 2020-05-18 10:21:53 -0400 | [diff] [blame] | 632 | run_ddl_benchmark(testCtx, ctx, surface, skp.get(), &samples); |
Nathaniel Nifong | fa40851 | 2019-07-26 09:44:46 -0400 | [diff] [blame] | 633 | } else if (!mskp) { |
| 634 | auto s = std::make_unique<StaticSkp>(skp); |
Kevin Lubick | 0377199 | 2023-05-24 11:09:36 -0400 | [diff] [blame] | 635 | run_benchmark(ctx, surface, s.get(), &samples); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 636 | } else { |
Kevin Lubick | 0377199 | 2023-05-24 11:09:36 -0400 | [diff] [blame] | 637 | run_benchmark(ctx, surface, mskp.get(), &samples); |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 638 | } |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 639 | } else { |
Robert Phillips | 9660108 | 2018-05-29 16:13:26 -0400 | [diff] [blame] | 640 | if (FLAGS_ddl) { |
| 641 | exitf(ExitErr::kUnavailable, "DDL: GPU-only timing not supported"); |
| 642 | } |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 643 | if (!testCtx->gpuTimingSupport()) { |
| 644 | exitf(ExitErr::kUnavailable, "GPU does not support timing"); |
| 645 | } |
Kevin Lubick | 0377199 | 2023-05-24 11:09:36 -0400 | [diff] [blame] | 646 | run_gpu_time_benchmark(testCtx->gpuTimer(), ctx, surface, skp.get(), &samples); |
csmartdalton | c6618dd | 2016-10-05 08:42:03 -0700 | [diff] [blame] | 647 | } |
Chris Dalton | a4f5ce0 | 2018-06-26 10:13:06 -0600 | [diff] [blame] | 648 | print_result(samples, config->getTag().c_str(), srcname.c_str()); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 649 | |
| 650 | // Save a proof (if one was requested). |
| 651 | if (!FLAGS_png.isEmpty()) { |
| 652 | SkBitmap bmp; |
Mike Reed | 12e946b | 2017-04-17 10:53:29 -0400 | [diff] [blame] | 653 | bmp.allocPixels(info); |
| 654 | if (!surface->getCanvas()->readPixels(bmp, 0, 0)) { |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 655 | exitf(ExitErr::kUnavailable, "failed to read canvas pixels for png"); |
| 656 | } |
Brian Osman | e581aaa | 2018-08-09 09:46:53 -0400 | [diff] [blame] | 657 | if (!mkdir_p(SkOSPath::Dirname(FLAGS_png[0]))) { |
| 658 | exitf(ExitErr::kIO, "failed to create directory for png \"%s\"", FLAGS_png[0]); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 659 | } |
Kevin Lubick | f48d2b0 | 2023-04-11 18:37:34 -0400 | [diff] [blame] | 660 | if (!ToolUtils::EncodeImageToPngFile(FLAGS_png[0], bmp)) { |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 661 | exitf(ExitErr::kIO, "failed to save png to \"%s\"", FLAGS_png[0]); |
| 662 | } |
| 663 | } |
| 664 | |
Greg Daniel | d78a9b4 | 2019-12-16 15:37:19 -0500 | [diff] [blame] | 665 | return(0); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 668 | static void flush_with_sync(GrDirectContext* context, GpuSync& gpuSync) { |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 669 | gpuSync.waitIfNeeded(); |
| 670 | |
| 671 | GrFlushInfo flushInfo; |
| 672 | flushInfo.fFinishedProc = sk_gpu_test::FlushFinishTracker::FlushFinished; |
| 673 | flushInfo.fFinishedContext = gpuSync.newFlushTracker(context); |
| 674 | |
| 675 | context->flush(flushInfo); |
Greg Daniel | 0a2464f | 2020-05-14 15:45:44 -0400 | [diff] [blame] | 676 | context->submit(); |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 677 | } |
| 678 | |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 679 | static void draw_skp_and_flush_with_sync(GrDirectContext* context, SkSurface* surface, |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 680 | const SkPicture* skp, GpuSync& gpuSync) { |
Robert Phillips | 9882dae | 2019-03-04 11:00:10 -0500 | [diff] [blame] | 681 | auto canvas = surface->getCanvas(); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 682 | canvas->drawPicture(skp); |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 683 | |
| 684 | flush_with_sync(context, gpuSync); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 685 | } |
| 686 | |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 687 | static sk_sp<SkPicture> create_warmup_skp() { |
| 688 | static constexpr SkRect bounds{0, 0, 500, 500}; |
| 689 | SkPictureRecorder recorder; |
| 690 | SkCanvas* recording = recorder.beginRecording(bounds); |
| 691 | |
| 692 | recording->clear(SK_ColorWHITE); |
| 693 | |
| 694 | SkPaint stroke; |
| 695 | stroke.setStyle(SkPaint::kStroke_Style); |
| 696 | stroke.setStrokeWidth(2); |
| 697 | |
| 698 | // Use a big path to (theoretically) warmup the CPU. |
Kevin Lubick | f541ddf | 2021-10-13 16:02:56 -0400 | [diff] [blame] | 699 | SkPath bigPath = BenchUtils::make_big_path(); |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 700 | recording->drawPath(bigPath, stroke); |
| 701 | |
| 702 | // Use a perlin shader to warmup the GPU. |
| 703 | SkPaint perlin; |
Kevin Lubick | 8fdbbca | 2023-06-07 16:14:51 -0400 | [diff] [blame] | 704 | perlin.setShader(SkShaders::MakeTurbulence(0.1f, 0.1f, 1, 0, nullptr)); |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 705 | recording->drawRect(bounds, perlin); |
| 706 | |
| 707 | return recorder.finishRecordingAsPicture(); |
| 708 | } |
| 709 | |
Chris Dalton | a4f5ce0 | 2018-06-26 10:13:06 -0600 | [diff] [blame] | 710 | static sk_sp<SkPicture> create_skp_from_svg(SkStream* stream, const char* filename) { |
Robert Phillips | 2af13c1 | 2021-09-01 16:47:01 +0000 | [diff] [blame] | 711 | #if defined(SK_ENABLE_SVG) |
Kevin Lubick | ee6dbb4 | 2023-11-03 09:19:25 -0400 | [diff] [blame] | 712 | sk_sp<SkSVGDOM> svg = |
| 713 | SkSVGDOM::Builder().setFontManager(ToolUtils::TestFontMgr()).make(*stream); |
Chris Dalton | a4f5ce0 | 2018-06-26 10:13:06 -0600 | [diff] [blame] | 714 | if (!svg) { |
| 715 | exitf(ExitErr::kData, "failed to build svg dom from file %s", filename); |
| 716 | } |
| 717 | |
| 718 | static constexpr SkRect bounds{0, 0, 1200, 1200}; |
| 719 | SkPictureRecorder recorder; |
| 720 | SkCanvas* recording = recorder.beginRecording(bounds); |
| 721 | |
| 722 | svg->setContainerSize(SkSize::Make(recording->getBaseLayerSize())); |
| 723 | svg->render(recording); |
| 724 | |
| 725 | return recorder.finishRecordingAsPicture(); |
| 726 | #endif |
Robert Phillips | 2af13c1 | 2021-09-01 16:47:01 +0000 | [diff] [blame] | 727 | exitf(ExitErr::kData, "SK_ENABLE_SVG is disabled; cannot open svg file %s", filename); |
Florin Malita | 5d3ff43 | 2018-07-31 16:38:43 -0400 | [diff] [blame] | 728 | return nullptr; |
Chris Dalton | a4f5ce0 | 2018-06-26 10:13:06 -0600 | [diff] [blame] | 729 | } |
| 730 | |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 731 | bool mkdir_p(const SkString& dirname) { |
Chris Dalton | 1d460d0 | 2019-04-01 12:40:06 -0600 | [diff] [blame] | 732 | if (dirname.isEmpty() || dirname == SkString("/")) { |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 733 | return true; |
| 734 | } |
| 735 | return mkdir_p(SkOSPath::Dirname(dirname.c_str())) && sk_mkdir(dirname.c_str()); |
| 736 | } |
| 737 | |
Mike Klein | 88544fb | 2019-03-20 10:50:33 -0500 | [diff] [blame] | 738 | static SkString join(const CommandLineFlags::StringArray& stringArray) { |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 739 | SkString joined; |
Herb Derby | 6a0a4c4 | 2022-09-30 16:43:14 -0400 | [diff] [blame] | 740 | for (int i = 0; i < stringArray.size(); ++i) { |
csmartdalton | 5772eaa | 2016-10-11 18:28:54 -0700 | [diff] [blame] | 741 | joined.appendf(i ? " %s" : "%s", stringArray[i]); |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 742 | } |
| 743 | return joined; |
| 744 | } |
| 745 | |
John Stiles | 87aa7a9 | 2022-02-04 18:17:59 -0500 | [diff] [blame] | 746 | static void exitf(ExitErr err, const char* format, ...) SK_PRINTF_LIKE(2, 3); |
| 747 | |
csmartdalton | 4b5179b | 2016-09-19 11:03:58 -0700 | [diff] [blame] | 748 | static void exitf(ExitErr err, const char* format, ...) { |
| 749 | fprintf(stderr, ExitErr::kSoftware == err ? "INTERNAL ERROR: " : "ERROR: "); |
| 750 | va_list args; |
| 751 | va_start(args, format); |
| 752 | vfprintf(stderr, format, args); |
| 753 | va_end(args); |
| 754 | fprintf(stderr, ExitErr::kSoftware == err ? "; this should never happen.\n": ".\n"); |
| 755 | exit((int)err); |
| 756 | } |
csmartdalton | e038489 | 2016-09-28 14:53:07 -0700 | [diff] [blame] | 757 | |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 758 | void GpuSync::waitIfNeeded() { |
| 759 | if (fFinishTrackers[fCurrentFlushIdx]) { |
| 760 | fFinishTrackers[fCurrentFlushIdx]->waitTillFinished(); |
| 761 | } |
csmartdalton | e038489 | 2016-09-28 14:53:07 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Robert Phillips | 00f78de | 2020-07-01 16:09:43 -0400 | [diff] [blame] | 764 | sk_gpu_test::FlushFinishTracker* GpuSync::newFlushTracker(GrDirectContext* context) { |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 765 | fFinishTrackers[fCurrentFlushIdx].reset(new sk_gpu_test::FlushFinishTracker(context)); |
csmartdalton | e038489 | 2016-09-28 14:53:07 -0700 | [diff] [blame] | 766 | |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 767 | sk_gpu_test::FlushFinishTracker* tracker = fFinishTrackers[fCurrentFlushIdx].get(); |
| 768 | // We add an additional ref to the current flush tracker here. This ref is owned by the finish |
| 769 | // callback on the flush call. The finish callback will unref the tracker when called. |
| 770 | tracker->ref(); |
csmartdalton | e038489 | 2016-09-28 14:53:07 -0700 | [diff] [blame] | 771 | |
Herb Derby | b780fc2 | 2022-06-28 08:27:35 -0400 | [diff] [blame] | 772 | fCurrentFlushIdx = (fCurrentFlushIdx + 1) % std::size(fFinishTrackers); |
Greg Daniel | 02497d4 | 2020-02-21 15:46:27 -0500 | [diff] [blame] | 773 | return tracker; |
csmartdalton | e038489 | 2016-09-28 14:53:07 -0700 | [diff] [blame] | 774 | } |