Flutter Engine
The Flutter Engine
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 ScratchResourceManager* scratchManager,
32 const RuntimeEffectDictionary* rtd) {
33 for (auto& child : fChildTasks) {
34 if (child) {
35 Status status = child->prepareResources(provider, scratchManager, rtd);
36 if (status == Status::kFail) {
37 return Status::kFail;
38 } else if (status == Status::kDiscard) {
39 child.reset();
40 }
41 }
42 }
43 for (const auto& group : fDispatchGroups) {
44 // TODO: Allow ComputeTasks to instantiate with scratch textures and return them.
45 if (!group->prepareResources(provider)) {
46 return Status::kFail;
47 }
48 }
49 return Status::kSuccess;
50}
51
53 CommandBuffer* commandBuffer,
54 ReplayTargetData rtd) {
55 if (fDispatchGroups.empty()) {
56 return Status::kDiscard;
57 }
58 SkASSERT(fDispatchGroups.size() == fChildTasks.size());
59 const std::unique_ptr<DispatchGroup>* currentSpanPtr = &fDispatchGroups[0];
60 size_t currentSpanSize = 0u;
61 for (int i = 0; i < fDispatchGroups.size(); ++i) {
62 // If the next DispatchGroup has a dependent task, then encode the accumulated span as a
63 // compute pass now. CommandBuffer encodes each compute pass with a separate encoder, so
64 // the dependent task can use a non-compute encoder if needed.
65 Task* child = fChildTasks[i].get();
66 if (child) {
67 if (currentSpanSize > 0u) {
68 if (!commandBuffer->addComputePass({currentSpanPtr, currentSpanSize})) {
69 return Status::kFail;
70 }
71 currentSpanPtr = &fDispatchGroups[i];
72 currentSpanSize = 0u;
73 }
74
75 Status status = child->addCommands(ctx, commandBuffer, rtd);
76 if (status == Status::kFail) {
77 return Status::kFail;
78 } else if (status == Status::kDiscard) {
79 fChildTasks[i].reset();
80 }
81 }
82 currentSpanSize++;
83 }
84 return (currentSpanSize == 0u ||
85 commandBuffer->addComputePass({currentSpanPtr, currentSpanSize})) ? Status::kSuccess
87}
88
89} // namespace skgpu::graphite
#define SkASSERT(cond)
Definition: SkAssert.h:116
bool addComputePass(DispatchGroupSpan dispatchGroups)
Status addCommands(Context *, CommandBuffer *, ReplayTargetData) override
Definition: ComputeTask.cpp:52
Status prepareResources(ResourceProvider *, ScratchResourceManager *, const RuntimeEffectDictionary *) override
Definition: ComputeTask.cpp:30
static sk_sp< ComputeTask > Make(DispatchGroupList dispatchGroups)
Definition: ComputeTask.cpp:17
virtual Status addCommands(Context *, CommandBuffer *, ReplayTargetData)=0
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Definition: ref_ptr.h:256