Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | List of all members
skgpu::graphite::ComputeStep Class Reference

#include <ComputeStep.h>

Inheritance diagram for skgpu::graphite::ComputeStep:
skgpu::graphite::VelloStep< S > skgpu::graphite::VelloFineStepBase< vello_cpp::ShaderStage::FineAreaR8, kAlpha_8_SkColorType > skgpu::graphite::VelloFineStepBase< vello_cpp::ShaderStage::FineArea, kRGBA_8888_SkColorType > skgpu::graphite::VelloFineStepBase< S, T > skgpu::graphite::VelloFineAreaAlpha8Step skgpu::graphite::VelloFineAreaStep skgpu::graphite::VelloFineMsaaStepBase< vello_cpp::ShaderStage::FineMsaa16R8, kAlpha_8_SkColorType, vello_cpp::build_mask_lut_16 > skgpu::graphite::VelloFineMsaaStepBase< vello_cpp::ShaderStage::FineMsaa16, kRGBA_8888_SkColorType, vello_cpp::build_mask_lut_16 > skgpu::graphite::VelloFineMsaaStepBase< vello_cpp::ShaderStage::FineMsaa8R8, kAlpha_8_SkColorType, vello_cpp::build_mask_lut_8 > skgpu::graphite::VelloFineMsaaStepBase< vello_cpp::ShaderStage::FineMsaa8, kRGBA_8888_SkColorType, vello_cpp::build_mask_lut_8 > skgpu::graphite::VelloFineMsaaStepBase< S, T, MaskLutBuilder > skgpu::graphite::VelloFineMsaa16Alpha8Step skgpu::graphite::VelloFineMsaa16Step skgpu::graphite::VelloFineMsaa8Alpha8Step skgpu::graphite::VelloFineMsaa8Step

Classes

struct  NativeShaderSource
 
struct  ResourceDesc
 
struct  WorkgroupBufferDesc
 

Public Types

enum class  DataFlow { kPrivate , kShared }
 
enum class  ResourceType {
  kUniformBuffer , kStorageBuffer , kReadOnlyStorageBuffer , kIndirectBuffer ,
  kWriteOnlyStorageTexture , kReadOnlyTexture , kSampledTexture
}
 
enum class  ResourcePolicy { kNone , kClear , kMapped }
 
enum class  NativeShaderFormat { kWGSL , kMSL }
 

Public Member Functions

virtual ~ComputeStep ()=default
 
virtual std::string computeSkSL () const
 
virtual NativeShaderSource nativeShaderSource (NativeShaderFormat) const
 
virtual size_t calculateBufferSize (int resourceIndex, const ResourceDesc &) const
 
virtual std::tuple< SkISize, SkColorTypecalculateTextureParameters (int resourceIndex, const ResourceDesc &) const
 
virtual SamplerDesc calculateSamplerParameters (int resourceIndex, const ResourceDesc &) const
 
virtual WorkgroupSize calculateGlobalDispatchSize () const
 
virtual void prepareStorageBuffer (int resourceIndex, const ResourceDesc &resource, void *buffer, size_t bufferSize) const
 
virtual void prepareUniformBuffer (int resourceIndex, const ResourceDesc &, UniformManager *) const
 
SkSpan< const ResourceDescresources () const
 
SkSpan< const WorkgroupBufferDescworkgroupBuffers () const
 
uint32_t uniqueID () const
 
const char * name () const
 
WorkgroupSize localDispatchSize () const
 
bool supportsNativeShader () const
 

Protected Types

enum class  Flags : uint8_t { kNone = 0b00000 , kSupportsNativeShader = 0b00010 }
 

Protected Member Functions

 ComputeStep (std::string_view name, WorkgroupSize localDispatchSize, SkSpan< const ResourceDesc > resources, SkSpan< const WorkgroupBufferDesc > workgroupBuffers={}, Flags baseFlags=Flags::kNone)
 

Detailed Description

A ComputeStep represents a compute pass within a wider draw operation. A ComputeStep implementation describes an invocation of a compute program and its data binding layout.

A ComputeStep can perform arbitrary operations on the GPU over various types of data, including geometry and image processing. The data processed by a ComputeStep can be inputs (textures or buffers) populated on the CPU, data forwarded to and from other ComputeStep invocations (via "slots"), transient storage buffers/textures that are only used within an individual dispatch, geometry attribute (vertex/index/instance) and indirect draw parameters of a subsequent raster pipeline stage, as well as texture outputs.

The data flow between sequential ComputeStep invocations within a DispatchGroup is achieved by operating over a shared "resource table". ComputeSteps can declare a resource with a slot number. Multiple ComputeSteps in a group that declare a resource with the same slot number will have access to the same backing resource object through that slot:

 _______________                _______________
|               |              |               |
|                ---[Slot 0]---                |
|               |              |               |
|                ---[Slot 1]---                |
| ComputeStep 1 |              | ComputeStep 2 |
|                ---[Slot 2]   |               |
|               |              |               |
|               |   [Slot 3]---                |
|               |              |               |
 ---------------                ---------------

In the example above, slots 0 and 1 are accessed by both ComputeSteps, while slots 2 and 3 are exclusively accessed by ComputeStep 1 and 2 respectively. Alternately, slots 2 and 3 could be declared as "private" resources which are visible to a single ComputeStep.

Similarly, raster stage geometry buffers that are specified as the output of a ComputeStep can be used to assign the draw buffers of a RenderStep.

It is the responsibility of the owning entity (e.g. a RendererProvider) to ensure that a chain of ComputeStep and RenderStep invocations have a compatible resource and data-flow layout.

Definition at line 67 of file ComputeStep.h.

Member Enumeration Documentation

◆ DataFlow

Enumerator
kPrivate 
kShared 

Definition at line 69 of file ComputeStep.h.

69 {
70 // A private binding is a resource that is only visible to a single ComputeStep invocation.
72
73 // Bindings with a slot number that can be used to forward data between a series of
74 // `ComputeStep`s. This DataFlow type is accompanied with a "slot number" that can be
75 // shared by multiple `ComputeStep`s in a group.
76 kShared,
77 };

◆ Flags

enum class skgpu::graphite::ComputeStep::Flags : uint8_t
strongprotected
Enumerator
kNone 
kSupportsNativeShader 

Definition at line 254 of file ComputeStep.h.

◆ NativeShaderFormat

Enumerator
kWGSL 
kMSL 

Definition at line 171 of file ComputeStep.h.

◆ ResourcePolicy

Enumerator
kNone 
kClear 
kMapped 

Definition at line 95 of file ComputeStep.h.

95 {
96 kNone,
97
98 // The memory of the resource will be initialized to 0
99 kClear,
100
101 // The ComputeStep will be asked to initialize the memory on the CPU via
102 // `ComputeStep::prepareStorageBuffer` or `ComputeStep::prepareUniformBuffer` prior to
103 // pipeline execution. This may incur a transfer cost on platforms that do not allow buffers
104 // to be mapped in shared memory.
105 //
106 // If multiple ComputeSteps in a DispatchGroup declare a mapped resource with the same
107 // shared slot number, only the first ComputeStep in the group will receive a call to
108 // prepare the buffer.
109 //
110 // This only has meaning for buffer resources. A resource with the `kUniformBuffer` resource
111 // type must specify the `kMapped` resource policy.
112 kMapped,
113 };

◆ ResourceType

Enumerator
kUniformBuffer 
kStorageBuffer 
kReadOnlyStorageBuffer 
kIndirectBuffer 
kWriteOnlyStorageTexture 
kReadOnlyTexture 
kSampledTexture 

Definition at line 79 of file ComputeStep.h.

79 {
83
84 // An indirect buffer is a storage buffer populated by this ComputeStep to determine the
85 // global dispatch size of a subsequent ComputeStep within the same DispatchGroup. The
86 // contents of the buffer must be laid out according to the `IndirectDispatchArgs` struct
87 // definition declared in ComputeTypes.h.
89
93 };

Constructor & Destructor Documentation

◆ ~ComputeStep()

virtual skgpu::graphite::ComputeStep::~ComputeStep ( )
virtualdefault

◆ ComputeStep()

skgpu::graphite::ComputeStep::ComputeStep ( std::string_view  name,
WorkgroupSize  localDispatchSize,
SkSpan< const ResourceDesc resources,
SkSpan< const WorkgroupBufferDesc workgroupBuffers = {},
Flags  baseFlags = Flags::kNone 
)
protected

Definition at line 28 of file ComputeStep.cpp.

33 : fUniqueID(next_id())
34 , fFlags(baseFlags)
35 , fName(name)
36 , fResources(resources.data(), resources.size())
37 , fWorkgroupBuffers(workgroupBuffers.data(), workgroupBuffers.size())
38 , fLocalDispatchSize(localDispatchSize) {
39#ifdef SK_DEBUG
40 std::unordered_set<int> slots;
41 for (const ResourceDesc& r : fResources) {
42 // Validate that slot assignments within a ComputeStep are unique.
43 if (r.fFlow == DataFlow::kShared) {
44 SkASSERT(r.fSlot > -1);
46 auto [_, inserted] = slots.insert(r.fSlot);
47 SkASSERT(inserted);
48 }
49 }
50#endif // SK_DEBUG
51}
#define SkASSERT(cond)
Definition SkAssert.h:116
WorkgroupSize localDispatchSize() const
SkSpan< const ResourceDesc > resources() const
SkSpan< const WorkgroupBufferDesc > workgroupBuffers() const
const char * name() const
constexpr int kMaxComputeDataFlowSlots
static uint32_t next_id()
Definition DrawAtlas.cpp:69

Member Function Documentation

◆ calculateBufferSize()

size_t skgpu::graphite::ComputeStep::calculateBufferSize ( int  resourceIndex,
const ResourceDesc  
) const
virtual

◆ calculateGlobalDispatchSize()

WorkgroupSize skgpu::graphite::ComputeStep::calculateGlobalDispatchSize ( ) const
virtual

Definition at line 89 of file ComputeStep.cpp.

89 {
90 SK_ABORT("ComputeSteps must override calculateGlobalDispatchSize() unless "
91 "the workgroup count is determined out-of-band");
92 return WorkgroupSize();
93}

◆ calculateSamplerParameters()

SamplerDesc skgpu::graphite::ComputeStep::calculateSamplerParameters ( int  resourceIndex,
const ResourceDesc  
) const
virtual

Definition at line 83 of file ComputeStep.cpp.

83 {
84 SK_ABORT("ComputeSteps that initialize a sampler must override calculateSamplerParameters()");
85 constexpr SkTileMode kTileModes[2] = {SkTileMode::kClamp, SkTileMode::kClamp};
86 return {{}, kTileModes};
87}
SkTileMode
Definition SkTileMode.h:13

◆ calculateTextureParameters()

std::tuple< SkISize, SkColorType > skgpu::graphite::ComputeStep::calculateTextureParameters ( int  resourceIndex,
const ResourceDesc  
) const
virtual

Reimplemented in skgpu::graphite::VelloFineStepBase< S, T >, skgpu::graphite::VelloFineStepBase< vello_cpp::ShaderStage::FineArea, kRGBA_8888_SkColorType >, and skgpu::graphite::VelloFineStepBase< vello_cpp::ShaderStage::FineAreaR8, kAlpha_8_SkColorType >.

Definition at line 77 of file ComputeStep.cpp.

78 {
79 SK_ABORT("ComputeSteps that initialize a texture must override calculateTextureParameters()");
81}
@ kUnknown_SkColorType
uninitialized
Definition SkColorType.h:20
static constexpr SkISize MakeEmpty()
Definition SkSize.h:22

◆ computeSkSL()

std::string skgpu::graphite::ComputeStep::computeSkSL ( ) const
virtual

Definition at line 62 of file ComputeStep.cpp.

62 {
63 SK_ABORT("ComputeSteps must override computeSkSL() unless they support native shader source");
64 return "";
65}

◆ localDispatchSize()

WorkgroupSize skgpu::graphite::ComputeStep::localDispatchSize ( ) const
inline

Definition at line 249 of file ComputeStep.h.

249{ return fLocalDispatchSize; }

◆ name()

const char * skgpu::graphite::ComputeStep::name ( ) const
inline

Definition at line 244 of file ComputeStep.h.

244{ return fName.c_str(); }

◆ nativeShaderSource()

ComputeStep::NativeShaderSource skgpu::graphite::ComputeStep::nativeShaderSource ( NativeShaderFormat  ) const
virtual

Reimplemented in skgpu::graphite::VelloStep< S >.

Definition at line 67 of file ComputeStep.cpp.

67 {
68 SK_ABORT("ComputeSteps that support native shader source must override nativeShaderSource()");
69 return {};
70}

◆ prepareStorageBuffer()

void skgpu::graphite::ComputeStep::prepareStorageBuffer ( int  resourceIndex,
const ResourceDesc resource,
void *  buffer,
size_t  bufferSize 
) const
virtual

◆ prepareUniformBuffer()

void skgpu::graphite::ComputeStep::prepareUniformBuffer ( int  resourceIndex,
const ResourceDesc ,
UniformManager  
) const
virtual

Definition at line 58 of file ComputeStep.cpp.

58 {
59 SK_ABORT("ComputeSteps that initialize a uniform buffer must override prepareUniformBuffer()");
60}

◆ resources()

SkSpan< const ResourceDesc > skgpu::graphite::ComputeStep::resources ( ) const
inline

Definition at line 236 of file ComputeStep.h.

236{ return SkSpan(fResources); }

◆ supportsNativeShader()

bool skgpu::graphite::ComputeStep::supportsNativeShader ( ) const
inline

Definition at line 251 of file ComputeStep.h.

251{ return SkToBool(fFlags & Flags::kSupportsNativeShader); }
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35

◆ uniqueID()

uint32_t skgpu::graphite::ComputeStep::uniqueID ( ) const
inline

Definition at line 241 of file ComputeStep.h.

241{ return fUniqueID; }

◆ workgroupBuffers()

SkSpan< const WorkgroupBufferDesc > skgpu::graphite::ComputeStep::workgroupBuffers ( ) const
inline

Definition at line 237 of file ComputeStep.h.

237{ return SkSpan(fWorkgroupBuffers); }

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