Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Static Public Member Functions | List of all members
skgpu::graphite::ComputeTask Class Referencefinal

#include <ComputeTask.h>

Inheritance diagram for skgpu::graphite::ComputeTask:
skgpu::graphite::Task SkRefCnt SkRefCntBase

Public Types

using DispatchGroupList = skia_private::STArray< 1, std::unique_ptr< DispatchGroup > >
 
- Public Types inherited from skgpu::graphite::Task
enum class  Status { kSuccess , kDiscard , kFail }
 

Public Member Functions

 ~ComputeTask () override
 
Status prepareResources (ResourceProvider *, ScratchResourceManager *, const RuntimeEffectDictionary *) override
 
Status addCommands (Context *, CommandBuffer *, ReplayTargetData) override
 
virtual Status prepareResources (ResourceProvider *, ScratchResourceManager *, const RuntimeEffectDictionary *)=0
 
virtual Status addCommands (Context *, CommandBuffer *, ReplayTargetData)=0
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Static Public Member Functions

static sk_sp< ComputeTaskMake (DispatchGroupList dispatchGroups)
 

Detailed Description

ComputeTask handles preparing and recording DispatchGroups into a series of compute dispatches within a command buffer. It is guaranteed that dispatches within a DispatchGroup will be executed sequentially.

Definition at line 26 of file ComputeTask.h.

Member Typedef Documentation

◆ DispatchGroupList

Definition at line 28 of file ComputeTask.h.

Constructor & Destructor Documentation

◆ ~ComputeTask()

skgpu::graphite::ComputeTask::~ComputeTask ( )
overridedefault

Member Function Documentation

◆ addCommands()

Task::Status skgpu::graphite::ComputeTask::addCommands ( Context ctx,
CommandBuffer commandBuffer,
ReplayTargetData  rtd 
)
overridevirtual

Implements skgpu::graphite::Task.

Definition at line 52 of file ComputeTask.cpp.

54 {
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}
#define SkASSERT(cond)
Definition: SkAssert.h:116
bool empty() const
Definition: SkTArray.h:199
int size() const
Definition: SkTArray.h:421
Definition: DM.cpp:1161

◆ Make()

sk_sp< ComputeTask > skgpu::graphite::ComputeTask::Make ( DispatchGroupList  dispatchGroups)
static

Definition at line 17 of file ComputeTask.cpp.

17 {
18 return sk_sp<ComputeTask>(new ComputeTask(std::move(dispatchGroups)));
19}

◆ prepareResources()

Task::Status skgpu::graphite::ComputeTask::prepareResources ( ResourceProvider provider,
ScratchResourceManager scratchManager,
const RuntimeEffectDictionary rtd 
)
overridevirtual

Implements skgpu::graphite::Task.

Definition at line 30 of file ComputeTask.cpp.

32 {
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}

The documentation for this class was generated from the following files: