Debian Codegraph @

src/gpu/graphite/task/Task.h

raw
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 #ifndef skgpu_graphite_task_Task_DEFINED
9 #define skgpu_graphite_task_Task_DEFINED
10
11 #include "include/core/SkPoint.h"
12 #include "include/core/SkRect.h"
13 #include "include/core/SkRefCnt.h"
14 #include "src/gpu/Token.h"
15 #include "src/gpu/graphite/DebugUtils.h"
16 #include "src/gpu/graphite/Log.h"
17 #include "src/gpu/graphite/RuntimeEffectDictionary.h"
18
19 #include <functional>
20
21 namespace skgpu::graphite {
22
23 class CommandBuffer;
24 class Context;
25 class GraphicsPipeline;
26 class ResourceProvider;
27 class ScratchResourceManager;
28 class Texture;
29 class TextureProxy;
30
31 class Task : public SkRefCnt {
32 public:
33 // Holds a render target and translation to use in the task's work, if necessary.
34 struct ReplayTargetData {
35 const Texture* fTarget;
36 SkIVector fTranslation;
37 SkIRect fClip;
38 };
39
40 enum class Status {
41 // The task step (prepareResources or addCommands) succeeded, proceed to the next task.
42 // If the Recording is replayed, this task should be executed again.
43 kSuccess,
44 // The task step succeeded, but it was a one-time-only operation and should be removed from
45 // the task list. If this is returned from prepareResources(), the task is removed before
46 // addCommands() will ever be called. If this is returned from addCommands(), it will not
47 // be part of any replayed Recording, but any added commands from the first call will be
48 // executed once.
49 //
50 // NOTE: If a task step needs to be conditionally processed but repeatable, it should
51 // internally skip work and still return kSuccess instead of kDiscard.
52 kDiscard,
53 // The step failed and cannot be recovered so the Recording is invalidated.
54 kFail
55 };
56
57 // Instantiate and prepare any Resources that must happen while the Task is still on the
58 // Recorder.
59 virtual Status prepareResources(ResourceProvider*,
60 ScratchResourceManager*,
61 sk_sp<const RuntimeEffectDictionary>) = 0;
62
63 // Returns true on success; false on failure.
64 virtual Status addCommands(Context*, CommandBuffer*, ReplayTargetData) = 0;
65
66 // Visit all pipelines or proxies until `visitor` returns false to end early. By default assume
67 // the task uses none. Because these are functions are virtual, they cannot be templated.
68 //
69 // WARNING: These visit functions will visit all tasks and their children, including revisiting
70 // anything that was added multiple times. Ideally the task graph should be visited after
71 // prepareResources() has been called because that will clean out cycles and re-references.
72 virtual bool visitPipelines(const std::function<bool(const GraphicsPipeline*)>& visitor) {
73 return true;
74 }
75
76 virtual bool visitProxies(const std::function<bool(const TextureProxy*)>& visitor,
77 bool readsOnly) {
78 return true;
79 }
80
81 #if defined(SK_DUMP_TASKS)
82 virtual void dump(int index, const char* prefix = "") const {
83 const char* taskName = this->getTaskName();
84 if (index >= 0) {
85 SkDebugf("%s%d: %s\n", prefix, index, taskName);
86 } else {
87 SkDebugf("%s%s\n", prefix, taskName);
88 }
89 }
90
91 skgpu::Token fFlushToken = skgpu::Token::InvalidToken();
92
93 virtual const char* getTaskName() const { return "Base Task (unknown type)"; }
94 #endif
95 };
96
97 } // namespace skgpu::graphite
98
99 #endif // skgpu_graphite_task_Task_DEFINED