xref: /aosp_15_r20/external/skia/src/gpu/graphite/task/ComputeTask.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
1 /*
2  * Copyright 2022 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_ComputeTask_DEFINED
9 #define skgpu_graphite_task_ComputeTask_DEFINED
10 
11 #include "include/private/base/SkTArray.h"
12 #include "src/gpu/graphite/task/Task.h"
13 #include "src/gpu/graphite/task/TaskList.h"
14 
15 #include <memory>
16 
17 namespace skgpu::graphite {
18 
19 class DispatchGroup;
20 
21 /**
22  * ComputeTask handles preparing and recording DispatchGroups into a series of compute dispatches
23  * within a command buffer. It is guaranteed that dispatches within a DispatchGroup will be executed
24  * sequentially.
25  */
26 class ComputeTask final : public Task {
27 public:
28     using DispatchGroupList = skia_private::STArray<1, std::unique_ptr<DispatchGroup>>;
29 
30     static sk_sp<ComputeTask> Make(DispatchGroupList dispatchGroups);
31 
32     ~ComputeTask() override;
33 
34     Status prepareResources(ResourceProvider*,
35                             ScratchResourceManager*,
36                             const RuntimeEffectDictionary*) override;
37     Status addCommands(Context*, CommandBuffer*, ReplayTargetData) override;
38 
39 private:
40     explicit ComputeTask(DispatchGroupList dispatchGroups);
41 
42     DispatchGroupList fDispatchGroups;
43 
44     // Every element of this list is a task that must execute before the DispatchGroup stored at the
45     // same array index. Child tasks are allowed to be a nullptr to represent NOP (i.e. the
46     // corresponding DispatchGroup doesn't have any pre-tasks).
47     skia_private::TArray<sk_sp<Task>> fChildTasks;
48 };
49 
50 }  // namespace skgpu::graphite
51 
52 #endif  // skgpu_graphite_task_ComputeTask_DEFINED
53