Robert Phillips | d034db7 | 2021-09-29 14:29:32 -0400 | [diff] [blame] | 1 | /* |
| 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 Verth | 42f710f | 2022-04-11 11:48:46 -0400 | [diff] [blame] | 10 | #include "include/gpu/graphite/Context.h" |
| 11 | #include "include/gpu/graphite/GraphiteTypes.h" |
| 12 | #include "include/gpu/graphite/Recording.h" |
Greg Daniel | 5d67b17 | 2022-03-28 15:27:44 -0400 | [diff] [blame] | 13 | #include "src/core/SkTraceEvent.h" |
Brian Salomon | c759bbf | 2023-12-05 11:11:27 -0500 | [diff] [blame] | 14 | #include "src/gpu/graphite/Caps.h" |
| 15 | #include "src/gpu/graphite/ContextPriv.h" |
Greg Daniel | 5d67b17 | 2022-03-28 15:27:44 -0400 | [diff] [blame] | 16 | #include "tools/gpu/FlushFinishTracker.h" |
| 17 | |
Robert Phillips | 3062759 | 2021-10-11 11:28:21 -0400 | [diff] [blame] | 18 | namespace skiatest::graphite { |
Robert Phillips | d034db7 | 2021-09-29 14:29:32 -0400 | [diff] [blame] | 19 | |
| 20 | GraphiteTestContext::GraphiteTestContext() {} |
| 21 | |
| 22 | GraphiteTestContext::~GraphiteTestContext() {} |
| 23 | |
Jim Van Verth | 3871479 | 2022-04-07 16:08:04 -0400 | [diff] [blame] | 24 | void GraphiteTestContext::submitRecordingAndWaitOnSync(skgpu::graphite::Context* context, |
| 25 | skgpu::graphite::Recording* recording) { |
Greg Daniel | 5d67b17 | 2022-03-28 15:27:44 -0400 | [diff] [blame] | 26 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 27 | SkASSERT(context); |
| 28 | SkASSERT(recording); |
| 29 | |
| 30 | if (fFinishTrackers[fCurrentFlushIdx]) { |
Brian Salomon | c759bbf | 2023-12-05 11:11:27 -0500 | [diff] [blame] | 31 | fFinishTrackers[fCurrentFlushIdx]->waitTillFinished([this] { tick(); }); |
Greg Daniel | 5d67b17 | 2022-03-28 15:27:44 -0400 | [diff] [blame] | 32 | } |
| 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 Verth | 3871479 | 2022-04-07 16:08:04 -0400 | [diff] [blame] | 40 | skgpu::graphite::InsertRecordingInfo info; |
Greg Daniel | 5d67b17 | 2022-03-28 15:27:44 -0400 | [diff] [blame] | 41 | info.fRecording = recording; |
| 42 | info.fFinishedContext = fFinishTrackers[fCurrentFlushIdx].get(); |
Greg Daniel | 6b52f37 | 2022-03-30 16:55:09 -0400 | [diff] [blame] | 43 | info.fFinishedProc = sk_gpu_test::FlushFinishTracker::FlushFinishedResult; |
Greg Daniel | 5d67b17 | 2022-03-28 15:27:44 -0400 | [diff] [blame] | 44 | context->insertRecording(info); |
| 45 | |
Jim Van Verth | 3871479 | 2022-04-07 16:08:04 -0400 | [diff] [blame] | 46 | context->submit(skgpu::graphite::SyncToCpu::kNo); |
Greg Daniel | 5d67b17 | 2022-03-28 15:27:44 -0400 | [diff] [blame] | 47 | |
Herb Derby | b780fc2 | 2022-06-28 08:27:35 -0400 | [diff] [blame] | 48 | fCurrentFlushIdx = (fCurrentFlushIdx + 1) % std::size(fFinishTrackers); |
Greg Daniel | 5d67b17 | 2022-03-28 15:27:44 -0400 | [diff] [blame] | 49 | } |
| 50 | |
Brian Salomon | c759bbf | 2023-12-05 11:11:27 -0500 | [diff] [blame] | 51 | void 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 Phillips | 3062759 | 2021-10-11 11:28:21 -0400 | [diff] [blame] | 64 | } // namespace skiatest::graphite |