Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Member Functions | List of all members
skgpu::graphite::DawnComputePipeline Class Referencefinal

#include <DawnComputePipeline.h>

Inheritance diagram for skgpu::graphite::DawnComputePipeline:
skgpu::graphite::ComputePipeline skgpu::graphite::Resource

Public Member Functions

 ~DawnComputePipeline () override=default
 
const wgpu::ComputePipeline & dawnComputePipeline () const
 
const wgpu::BindGroupLayout & dawnGroupLayout () const
 
- Public Member Functions inherited from skgpu::graphite::ComputePipeline
 ~ComputePipeline () override=default
 
const char * getResourceType () const override
 
- Public Member Functions inherited from skgpu::graphite::Resource
 Resource (const Resource &)=delete
 
 Resource (Resource &&)=delete
 
Resourceoperator= (const Resource &)=delete
 
Resourceoperator= (Resource &&)=delete
 
void ref () const
 
void unref () const
 
void refCommandBuffer () const
 
void unrefCommandBuffer () const
 
Ownership ownership () const
 
skgpu::Budgeted budgeted () const
 
size_t gpuMemorySize () const
 
UniqueID uniqueID () const
 
std::string getLabel () const
 
void setLabel (std::string_view label)
 
bool wasDestroyed () const
 
const GraphiteResourceKeykey () const
 
void setKey (const GraphiteResourceKey &key)
 
void dumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump) const
 
virtual void prepareForReturnToCache (const std::function< void()> &takeRef)
 

Static Public Member Functions

static sk_sp< DawnComputePipelineMake (const DawnSharedContext *, const ComputePipelineDesc &)
 

Private Member Functions

void freeGpuData () override
 

Additional Inherited Members

- Protected Member Functions inherited from skgpu::graphite::ComputePipeline
 ComputePipeline (const SharedContext *)
 
- Protected Member Functions inherited from skgpu::graphite::Resource
 Resource (const SharedContext *, Ownership, skgpu::Budgeted, size_t gpuMemorySize, std::string_view label, bool commandBufferRefsAsUsageRefs=false)
 
virtual ~Resource ()
 
const SharedContextsharedContext () const
 
virtual void invokeReleaseProc ()
 
virtual void onDumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump, const char *dumpName) const
 
void setDeleteASAP ()
 

Detailed Description

Definition at line 22 of file DawnComputePipeline.h.

Constructor & Destructor Documentation

◆ ~DawnComputePipeline()

skgpu::graphite::DawnComputePipeline::~DawnComputePipeline ( )
overridedefault

Member Function Documentation

◆ dawnComputePipeline()

const wgpu::ComputePipeline & skgpu::graphite::DawnComputePipeline::dawnComputePipeline ( ) const
inline

Definition at line 27 of file DawnComputePipeline.h.

27{ return fPipeline; }

◆ dawnGroupLayout()

const wgpu::BindGroupLayout & skgpu::graphite::DawnComputePipeline::dawnGroupLayout ( ) const
inline

Definition at line 28 of file DawnComputePipeline.h.

28{ return fGroupLayout; }

◆ freeGpuData()

void skgpu::graphite::DawnComputePipeline::freeGpuData ( )
overrideprivatevirtual

Implements skgpu::graphite::Resource.

Definition at line 201 of file DawnComputePipeline.cpp.

201{ fPipeline = nullptr; }

◆ Make()

sk_sp< DawnComputePipeline > skgpu::graphite::DawnComputePipeline::Make ( const DawnSharedContext sharedContext,
const ComputePipelineDesc pipelineDesc 
)
static

Definition at line 77 of file DawnComputePipeline.cpp.

78 {
79 auto [shaderModule, entryPointName] = compile_shader_module(sharedContext, pipelineDesc);
80 if (!shaderModule) {
81 return nullptr;
82 }
83
84 const ComputeStep* step = pipelineDesc.computeStep();
85
86 // ComputeStep resources are listed in the order that they must be declared in the shader. This
87 // order is then used for the index assignment using an "indexed by order" policy that has
88 // backend-specific semantics. The semantics on Dawn is to assign the index number in increasing
89 // order.
90 //
91 // All resources get assigned to a single bind group at index 0.
93 std::vector<wgpu::BindGroupLayoutEntry> bindGroupLayoutEntries;
94 auto resources = step->resources();
95
96 // Sampled textures count as 2 resources (1 texture and 1 sampler). All other types count as 1.
97 size_t resourceCount = 0;
98 for (const ComputeStep::ResourceDesc& r : resources) {
99 resourceCount++;
100 if (r.fType == ComputeStep::ResourceType::kSampledTexture) {
101 resourceCount++;
102 }
103 }
104
105 bindGroupLayoutEntries.reserve(resourceCount);
106 int declarationIndex = 0;
107 for (const ComputeStep::ResourceDesc& r : resources) {
108 bindGroupLayoutEntries.emplace_back();
109 uint32_t bindingIndex = bindGroupLayoutEntries.size() - 1;
110
111 wgpu::BindGroupLayoutEntry& entry = bindGroupLayoutEntries.back();
112 entry.binding = bindingIndex;
113 entry.visibility = wgpu::ShaderStage::Compute;
114 switch (r.fType) {
115 case ComputeStep::ResourceType::kUniformBuffer:
116 entry.buffer.type = wgpu::BufferBindingType::Uniform;
117 break;
118 case ComputeStep::ResourceType::kStorageBuffer:
119 case ComputeStep::ResourceType::kIndirectBuffer:
120 entry.buffer.type = wgpu::BufferBindingType::Storage;
121 break;
122 case ComputeStep::ResourceType::kReadOnlyStorageBuffer:
123 entry.buffer.type = wgpu::BufferBindingType::ReadOnlyStorage;
124 break;
125 case ComputeStep::ResourceType::kReadOnlyTexture:
126 entry.texture.sampleType = wgpu::TextureSampleType::Float;
127 entry.texture.viewDimension = wgpu::TextureViewDimension::e2D;
128 break;
129 case ComputeStep::ResourceType::kWriteOnlyStorageTexture: {
130 entry.storageTexture.access = wgpu::StorageTextureAccess::WriteOnly;
131 entry.storageTexture.viewDimension = wgpu::TextureViewDimension::e2D;
132
133 auto [_, colorType] = step->calculateTextureParameters(declarationIndex, r);
135 entry.storageTexture.format = textureInfo.dawnTextureSpec().getViewFormat();
136 break;
137 }
138 case ComputeStep::ResourceType::kSampledTexture: {
139 entry.sampler.type = wgpu::SamplerBindingType::Filtering;
140
141 // Add an additional entry for the texture.
142 bindGroupLayoutEntries.emplace_back();
143 wgpu::BindGroupLayoutEntry& texEntry = bindGroupLayoutEntries.back();
144 texEntry.binding = bindingIndex + 1;
145 texEntry.visibility = wgpu::ShaderStage::Compute;
146 texEntry.texture.sampleType = wgpu::TextureSampleType::Float;
147 texEntry.texture.viewDimension = wgpu::TextureViewDimension::e2D;
148 break;
149 }
150 }
151 declarationIndex++;
152 }
153
154 const wgpu::Device& device = sharedContext->device();
155
156 // All resources of a ComputeStep currently get assigned to a single bind group at index 0.
157 wgpu::BindGroupLayoutDescriptor bindGroupLayoutDesc;
158 bindGroupLayoutDesc.entryCount = bindGroupLayoutEntries.size();
159 bindGroupLayoutDesc.entries = bindGroupLayoutEntries.data();
160 wgpu::BindGroupLayout bindGroupLayout = device.CreateBindGroupLayout(&bindGroupLayoutDesc);
161 if (!bindGroupLayout) {
162 return nullptr;
163 }
164
165 wgpu::PipelineLayoutDescriptor pipelineLayoutDesc;
166 pipelineLayoutDesc.label = step->name();
167 pipelineLayoutDesc.bindGroupLayoutCount = 1;
168 pipelineLayoutDesc.bindGroupLayouts = &bindGroupLayout;
169 wgpu::PipelineLayout layout = device.CreatePipelineLayout(&pipelineLayoutDesc);
170 if (!layout) {
171 return nullptr;
172 }
173
174 wgpu::ComputePipelineDescriptor descriptor;
175 descriptor.label = step->name();
176 descriptor.compute.module = std::move(shaderModule);
177 descriptor.compute.entryPoint = entryPointName.c_str();
178 descriptor.layout = std::move(layout);
179
180 std::optional<DawnErrorChecker> errorChecker;
181 if (sharedContext->dawnCaps()->allowScopedErrorChecks()) {
182 errorChecker.emplace(sharedContext);
183 }
184 wgpu::ComputePipeline pipeline = device.CreateComputePipeline(&descriptor);
185 SkASSERT(pipeline);
186 if (errorChecker.has_value() && errorChecker->popErrorScopes() != DawnErrorType::kNoError) {
187 return nullptr;
188 }
189
190 return sk_sp<DawnComputePipeline>(new DawnComputePipeline(
191 sharedContext, std::move(pipeline), std::move(bindGroupLayout)));
192}
static int step(int x, SkScalar min, SkScalar max)
Definition BlurTest.cpp:215
#define SkASSERT(cond)
Definition SkAssert.h:116
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
const ResourceBindingRequirements & resourceBindingRequirements() const
Definition Caps.h:143
virtual TextureInfo getDefaultStorageTextureInfo(SkColorType) const =0
const SharedContext * sharedContext() const
Definition Resource.h:187
const Caps * caps() const
VkDevice device
Definition main.cc:53

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