blob: 2e75423102c54eaaf6a60c05f7af5d23e785a0db [file] [log] [blame]
Robert Phillipsd034db72021-09-29 14:29:32 -04001/*
2 * Copyright 2021 Google LLC
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
8#include "tools/graphite/GraphiteTestContext.h"
9
Jim Van Verth42f710f2022-04-11 11:48:46 -040010#include "include/gpu/graphite/Context.h"
11#include "include/gpu/graphite/GraphiteTypes.h"
12#include "include/gpu/graphite/Recording.h"
Greg Daniel5d67b172022-03-28 15:27:44 -040013#include "src/core/SkTraceEvent.h"
Brian Salomonc759bbf2023-12-05 11:11:27 -050014#include "src/gpu/graphite/Caps.h"
15#include "src/gpu/graphite/ContextPriv.h"
Greg Daniel5d67b172022-03-28 15:27:44 -040016#include "tools/gpu/FlushFinishTracker.h"
17
Robert Phillips30627592021-10-11 11:28:21 -040018namespace skiatest::graphite {
Robert Phillipsd034db72021-09-29 14:29:32 -040019
20GraphiteTestContext::GraphiteTestContext() {}
21
22GraphiteTestContext::~GraphiteTestContext() {}
23
Jim Van Verth38714792022-04-07 16:08:04 -040024void GraphiteTestContext::submitRecordingAndWaitOnSync(skgpu::graphite::Context* context,
25 skgpu::graphite::Recording* recording) {
Greg Daniel5d67b172022-03-28 15:27:44 -040026 TRACE_EVENT0("skia.gpu", TRACE_FUNC);
27 SkASSERT(context);
28 SkASSERT(recording);
29
30 if (fFinishTrackers[fCurrentFlushIdx]) {
Brian Salomonc759bbf2023-12-05 11:11:27 -050031 fFinishTrackers[fCurrentFlushIdx]->waitTillFinished([this] { tick(); });
Greg Daniel5d67b172022-03-28 15:27:44 -040032 }
33
34 fFinishTrackers[fCurrentFlushIdx].reset(new sk_gpu_test::FlushFinishTracker(context));
35
36 // We add an additional ref to the current flush tracker here. This ref is owned by the finish
37 // callback on the flush call. The finish callback will unref the tracker when called.
38 fFinishTrackers[fCurrentFlushIdx]->ref();
39
Jim Van Verth38714792022-04-07 16:08:04 -040040 skgpu::graphite::InsertRecordingInfo info;
Greg Daniel5d67b172022-03-28 15:27:44 -040041 info.fRecording = recording;
42 info.fFinishedContext = fFinishTrackers[fCurrentFlushIdx].get();
Greg Daniel6b52f372022-03-30 16:55:09 -040043 info.fFinishedProc = sk_gpu_test::FlushFinishTracker::FlushFinishedResult;
Greg Daniel5d67b172022-03-28 15:27:44 -040044 context->insertRecording(info);
45
Jim Van Verth38714792022-04-07 16:08:04 -040046 context->submit(skgpu::graphite::SyncToCpu::kNo);
Greg Daniel5d67b172022-03-28 15:27:44 -040047
Herb Derbyb780fc22022-06-28 08:27:35 -040048 fCurrentFlushIdx = (fCurrentFlushIdx + 1) % std::size(fFinishTrackers);
Greg Daniel5d67b172022-03-28 15:27:44 -040049}
50
Brian Salomonc759bbf2023-12-05 11:11:27 -050051void GraphiteTestContext::syncedSubmit(skgpu::graphite::Context* context) {
52 skgpu::graphite::SyncToCpu sync = context->priv().caps()->allowCpuSync()
53 ? skgpu::graphite::SyncToCpu::kYes
54 : skgpu::graphite::SyncToCpu::kNo;
55 context->submit(sync);
56 if (sync == skgpu::graphite::SyncToCpu::kNo) {
57 while (context->hasUnfinishedGpuWork()) {
58 this->tick();
59 context->checkAsyncWorkCompletion();
60 }
61 }
62}
63
Robert Phillips30627592021-10-11 11:28:21 -040064} // namespace skiatest::graphite