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 | |
Robert Phillips | 3062759 | 2021-10-11 11:28:21 -0400 | [diff] [blame] | 8 | #ifndef skiatest_graphite_GraphiteTestContext_DEFINED |
| 9 | #define skiatest_graphite_GraphiteTestContext_DEFINED |
Robert Phillips | d034db7 | 2021-09-29 14:29:32 -0400 | [diff] [blame] | 10 | |
Robert Phillips | d034db7 | 2021-09-29 14:29:32 -0400 | [diff] [blame] | 11 | #include "include/core/SkRefCnt.h" |
Jim Van Verth | 42f710f | 2022-04-11 11:48:46 -0400 | [diff] [blame] | 12 | #include "include/gpu/graphite/GraphiteTypes.h" |
Robert Phillips | d034db7 | 2021-09-29 14:29:32 -0400 | [diff] [blame] | 13 | |
John Stiles | 946718b | 2023-09-18 12:52:29 -0400 | [diff] [blame] | 14 | namespace skgpu { |
| 15 | enum class BackendApi : unsigned; |
| 16 | enum class ContextType; |
| 17 | } |
Jim Van Verth | 3871479 | 2022-04-07 16:08:04 -0400 | [diff] [blame] | 18 | namespace skgpu::graphite { |
Greg Daniel | 5d67b17 | 2022-03-28 15:27:44 -0400 | [diff] [blame] | 19 | class Context; |
Robert Phillips | c983b97 | 2023-06-20 12:59:31 -0400 | [diff] [blame] | 20 | struct ContextOptions; |
Greg Daniel | 5d67b17 | 2022-03-28 15:27:44 -0400 | [diff] [blame] | 21 | class Recording; |
| 22 | } |
| 23 | |
| 24 | namespace sk_gpu_test { class FlushFinishTracker; } |
Robert Phillips | d034db7 | 2021-09-29 14:29:32 -0400 | [diff] [blame] | 25 | |
Robert Phillips | 3062759 | 2021-10-11 11:28:21 -0400 | [diff] [blame] | 26 | namespace skiatest::graphite { |
Robert Phillips | d034db7 | 2021-09-29 14:29:32 -0400 | [diff] [blame] | 27 | |
Brian Salomon | 23e1cb2 | 2023-12-05 19:46:43 -0500 | [diff] [blame] | 28 | struct TestOptions; |
| 29 | |
Robert Phillips | d034db7 | 2021-09-29 14:29:32 -0400 | [diff] [blame] | 30 | /** |
| 31 | * An offscreen 3D context. This class is intended for Skia's internal testing needs and not |
| 32 | * for general use. |
| 33 | */ |
| 34 | class GraphiteTestContext { |
| 35 | public: |
| 36 | GraphiteTestContext(const GraphiteTestContext&) = delete; |
| 37 | GraphiteTestContext& operator=(const GraphiteTestContext&) = delete; |
| 38 | |
| 39 | virtual ~GraphiteTestContext(); |
| 40 | |
Greg Daniel | a8ca811 | 2022-10-10 18:25:22 -0400 | [diff] [blame] | 41 | virtual skgpu::BackendApi backend() = 0; |
Robert Phillips | d034db7 | 2021-09-29 14:29:32 -0400 | [diff] [blame] | 42 | |
John Stiles | 946718b | 2023-09-18 12:52:29 -0400 | [diff] [blame] | 43 | virtual skgpu::ContextType contextType() = 0; |
| 44 | |
Brian Salomon | 23e1cb2 | 2023-12-05 19:46:43 -0500 | [diff] [blame] | 45 | virtual std::unique_ptr<skgpu::graphite::Context> makeContext(const TestOptions&) = 0; |
Robert Phillips | d034db7 | 2021-09-29 14:29:32 -0400 | [diff] [blame] | 46 | |
Greg Daniel | 5d67b17 | 2022-03-28 15:27:44 -0400 | [diff] [blame] | 47 | bool getMaxGpuFrameLag(int *maxFrameLag) const { |
| 48 | *maxFrameLag = kMaxFrameLag; |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * This will insert a Recording and submit work to the GPU. Additionally, we will add a finished |
| 54 | * callback to our insert recording call. We allow ourselves to have kMaxFrameLag number of |
| 55 | * unfinished flushes active on the GPU at a time. If we have 2 outstanding flushes then we will |
| 56 | * wait on the CPU until one has finished. |
| 57 | */ |
Jim Van Verth | 3871479 | 2022-04-07 16:08:04 -0400 | [diff] [blame] | 58 | void submitRecordingAndWaitOnSync(skgpu::graphite::Context*, skgpu::graphite::Recording*); |
Greg Daniel | 5d67b17 | 2022-03-28 15:27:44 -0400 | [diff] [blame] | 59 | |
Brian Salomon | f8daeeb | 2023-11-17 16:06:37 -0500 | [diff] [blame] | 60 | /** |
| 61 | * Allow the GPU API to make or detect forward progress on submitted work. For most APIs this is |
| 62 | * a no-op as the API can do this on another thread. |
| 63 | */ |
| 64 | virtual void tick() {} |
| 65 | |
Brian Salomon | c759bbf | 2023-12-05 11:11:27 -0500 | [diff] [blame] | 66 | /** |
| 67 | * If the context supports CPU/GPU sync'ing this calls submit with skgpu::SyncToCpu::kYes. |
| 68 | * Otherwise it calls it with kNo in a busy loop. |
| 69 | */ |
| 70 | void syncedSubmit(skgpu::graphite::Context*); |
| 71 | |
Robert Phillips | d034db7 | 2021-09-29 14:29:32 -0400 | [diff] [blame] | 72 | protected: |
Greg Daniel | 5d67b17 | 2022-03-28 15:27:44 -0400 | [diff] [blame] | 73 | static constexpr int kMaxFrameLag = 3; |
| 74 | |
| 75 | sk_sp<sk_gpu_test::FlushFinishTracker> fFinishTrackers[kMaxFrameLag - 1]; |
| 76 | int fCurrentFlushIdx = 0; |
| 77 | |
Robert Phillips | d034db7 | 2021-09-29 14:29:32 -0400 | [diff] [blame] | 78 | GraphiteTestContext(); |
| 79 | }; |
| 80 | |
| 81 | |
Robert Phillips | 3062759 | 2021-10-11 11:28:21 -0400 | [diff] [blame] | 82 | } // namespace skiatest::graphite |
Robert Phillips | d034db7 | 2021-09-29 14:29:32 -0400 | [diff] [blame] | 83 | |
Robert Phillips | 3062759 | 2021-10-11 11:28:21 -0400 | [diff] [blame] | 84 | #endif // skiatest_graphite_GraphiteTestContext_DEFINED |