Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
ComputeTask.cpp
Go to the documentation of this file.
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
9
14
15namespace skgpu::graphite {
16
18 return sk_sp<ComputeTask>(new ComputeTask(std::move(dispatchGroups)));
19}
20
21ComputeTask::ComputeTask(DispatchGroupList dispatchGroups)
22 : fDispatchGroups(std::move(dispatchGroups)), fChildTasks(fDispatchGroups.size()) {
23 for (auto& group : fDispatchGroups) {
24 fChildTasks.push_back(group->snapChildTask());
25 }
26}
27
29
31 const RuntimeEffectDictionary* rtd) {
32 for (auto& child : fChildTasks) {
33 if (child) {
34 Status status = child->prepareResources(provider, rtd);
35 if (status == Status::kFail) {
36 return Status::kFail;
37 } else if (status == Status::kDiscard) {
38 child.reset();
39 }
40 }
41 }
42 for (const auto& group : fDispatchGroups) {
43 if (!group->prepareResources(provider)) {
44 return Status::kFail;
45 }
46 }
47 return Status::kSuccess;
48}
49
51 if (fDispatchGroups.empty()) {
52 return Status::kDiscard;
53 }
54 SkASSERT(fDispatchGroups.size() == fChildTasks.size());
55 const std::unique_ptr<DispatchGroup>* currentSpanPtr = &fDispatchGroups[0];
56 size_t currentSpanSize = 0u;
57 for (int i = 0; i < fDispatchGroups.size(); ++i) {
58 // If the next DispatchGroup has a dependent task, then encode the accumulated span as a
59 // compute pass now. CommandBuffer encodes each compute pass with a separate encoder, so
60 // the dependent task can use a non-compute encoder if needed.
61 Task* child = fChildTasks[i].get();
62 if (child) {
63 if (currentSpanSize > 0u) {
64 if (!commandBuffer->addComputePass({currentSpanPtr, currentSpanSize})) {
65 return Status::kFail;
66 }
67 currentSpanPtr = &fDispatchGroups[i];
68 currentSpanSize = 0u;
69 }
70
71 Status status = child->addCommands(ctx, commandBuffer, rtd);
72 if (status == Status::kFail) {
73 return Status::kFail;
74 } else if (status == Status::kDiscard) {
75 fChildTasks[i].reset();
76 }
77 }
78 currentSpanSize++;
79 }
80 return (currentSpanSize == 0u ||
81 commandBuffer->addComputePass({currentSpanPtr, currentSpanSize})) ? Status::kSuccess
82 : Status::kFail;
83}
84
85} // namespace skgpu::graphite
#define SkASSERT(cond)
Definition SkAssert.h:116
bool addComputePass(DispatchGroupSpan dispatchGroups)
Status addCommands(Context *, CommandBuffer *, ReplayTargetData) override
static sk_sp< ComputeTask > Make(DispatchGroupList dispatchGroups)
Status prepareResources(ResourceProvider *, const RuntimeEffectDictionary *) override
virtual Status addCommands(Context *, CommandBuffer *, ReplayTargetData)=0
bool empty() const
Definition SkTArray.h:194
int size() const
Definition SkTArray.h:416
Definition ref_ptr.h:256