Flutter Engine
The Flutter Engine
Classes | Public Member Functions | List of all members
skgpu::graphite::DawnResourceProvider Class Referencefinal

#include <DawnResourceProvider.h>

Inheritance diagram for skgpu::graphite::DawnResourceProvider:
skgpu::graphite::ResourceProvider

Public Member Functions

 DawnResourceProvider (SharedContext *sharedContext, SingleOwner *, uint32_t recorderID, size_t resourceBudget)
 
 ~DawnResourceProvider () override
 
sk_sp< DawnTexturefindOrCreateDiscardableMSAALoadTexture (SkISize dimensions, const TextureInfo &msaaInfo)
 
wgpu::RenderPipeline findOrCreateBlitWithDrawPipeline (const RenderPassDesc &renderPassDesc)
 
sk_sp< DawnBufferfindOrCreateDawnBuffer (size_t size, BufferType type, AccessPattern, std::string_view label)
 
const wgpu::BindGroupLayout & getOrCreateUniformBuffersBindGroupLayout ()
 
const wgpu::BindGroupLayout & getOrCreateSingleTextureSamplerBindGroupLayout ()
 
const wgpu::BindGroup & findOrCreateUniformBuffersBindGroup (const std::array< std::pair< const DawnBuffer *, uint32_t >, 4 > &boundBuffersAndSizes)
 
const wgpu::BindGroup & findOrCreateSingleTextureSamplerBindGroup (const DawnSampler *sampler, const DawnTexture *texture)
 
const sk_sp< DawnBuffer > & getOrCreateIntrinsicConstantBuffer ()
 
- Public Member Functions inherited from skgpu::graphite::ResourceProvider
virtual ~ResourceProvider ()
 
sk_sp< GraphicsPipelinefindOrCreateGraphicsPipeline (const RuntimeEffectDictionary *, const GraphicsPipelineDesc &, const RenderPassDesc &)
 
sk_sp< ComputePipelinefindOrCreateComputePipeline (const ComputePipelineDesc &)
 
sk_sp< TexturefindOrCreateScratchTexture (SkISize, const TextureInfo &, std::string_view label, skgpu::Budgeted)
 
sk_sp< TexturecreateWrappedTexture (const BackendTexture &, std::string_view label)
 
sk_sp< TexturefindOrCreateDepthStencilAttachment (SkISize dimensions, const TextureInfo &)
 
sk_sp< TexturefindOrCreateDiscardableMSAAAttachment (SkISize dimensions, const TextureInfo &)
 
sk_sp< BufferfindOrCreateBuffer (size_t size, BufferType type, AccessPattern, std::string_view label)
 
sk_sp< SamplerfindOrCreateCompatibleSampler (const SamplerDesc &)
 
BackendTexture createBackendTexture (SkISize dimensions, const TextureInfo &)
 
void deleteBackendTexture (const BackendTexture &)
 
ProxyCacheproxyCache ()
 
size_t getResourceCacheLimit () const
 
size_t getResourceCacheCurrentBudgetedBytes () const
 
void dumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump) const
 
void freeGpuResources ()
 
void purgeResourcesNotUsedSince (StdSteadyClock::time_point purgeTime)
 

Additional Inherited Members

- Protected Member Functions inherited from skgpu::graphite::ResourceProvider
 ResourceProvider (SharedContext *sharedContext, SingleOwner *singleOwner, uint32_t recorderID, size_t resourceBudget)
 
- Protected Attributes inherited from skgpu::graphite::ResourceProvider
SharedContextfSharedContext
 
sk_sp< ResourceCachefResourceCache
 

Detailed Description

Definition at line 24 of file DawnResourceProvider.h.

Constructor & Destructor Documentation

◆ DawnResourceProvider()

skgpu::graphite::DawnResourceProvider::DawnResourceProvider ( SharedContext sharedContext,
SingleOwner singleOwner,
uint32_t  recorderID,
size_t  resourceBudget 
)

Definition at line 152 of file DawnResourceProvider.cpp.

156 : ResourceProvider(sharedContext, singleOwner, recorderID, resourceBudget)
157 , fUniformBufferBindGroupCache(kMaxNumberOfCachedBufferBindGroups)
158 , fSingleTextureSamplerBindGroups(kMaxNumberOfCachedTextureBindGroups) {}
ResourceProvider(SharedContext *sharedContext, SingleOwner *singleOwner, uint32_t recorderID, size_t resourceBudget)

◆ ~DawnResourceProvider()

skgpu::graphite::DawnResourceProvider::~DawnResourceProvider ( )
overridedefault

Member Function Documentation

◆ findOrCreateBlitWithDrawPipeline()

wgpu::RenderPipeline skgpu::graphite::DawnResourceProvider::findOrCreateBlitWithDrawPipeline ( const RenderPassDesc renderPassDesc)

Definition at line 162 of file DawnResourceProvider.cpp.

163 {
164 uint64_t renderPassKey =
165 this->dawnSharedContext()->dawnCaps()->getRenderPassDescKeyForPipeline(renderPassDesc);
166 wgpu::RenderPipeline pipeline = fBlitWithDrawPipelines[renderPassKey];
167 if (!pipeline) {
168 static constexpr char kVertexShaderText[] = R"(
169 var<private> fullscreenTriPositions : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
170 vec2(-1.0, -1.0), vec2(-1.0, 3.0), vec2(3.0, -1.0));
171
172 @vertex
173 fn main(@builtin(vertex_index) vertexIndex : u32) -> @builtin(position) vec4<f32> {
174 return vec4(fullscreenTriPositions[vertexIndex], 1.0, 1.0);
175 }
176 )";
177
178 static constexpr char kFragmentShaderText[] = R"(
179 @group(0) @binding(0) var colorMap: texture_2d<f32>;
180
181 @fragment
182 fn main(@builtin(position) fragPosition : vec4<f32>) -> @location(0) vec4<f32> {
183 var coords : vec2<i32> = vec2<i32>(i32(fragPosition.x), i32(fragPosition.y));
184 return textureLoad(colorMap, coords, 0);
185 }
186 )";
187
188 auto vsModule = create_shader_module(dawnSharedContext()->device(), kVertexShaderText);
189 auto fsModule = create_shader_module(dawnSharedContext()->device(), kFragmentShaderText);
190
191 pipeline = create_blit_render_pipeline(
192 dawnSharedContext(),
193 /*label=*/"BlitWithDraw",
194 std::move(vsModule),
195 std::move(fsModule),
196 /*renderPassColorFormat=*/
197 renderPassDesc.fColorAttachment.fTextureInfo.dawnTextureSpec().getViewFormat(),
198 /*renderPassDepthStencilFormat=*/
199 renderPassDesc.fDepthStencilAttachment.fTextureInfo.isValid()
200 ? renderPassDesc.fDepthStencilAttachment.fTextureInfo.dawnTextureSpec()
201 .getViewFormat()
202 : wgpu::TextureFormat::Undefined,
203 /*numSamples=*/renderPassDesc.fColorAttachment.fTextureInfo.numSamples());
204
205 if (pipeline) {
206 fBlitWithDrawPipelines.set(renderPassKey, pipeline);
207 }
208 }
209
210 return pipeline;
211}
uint64_t getRenderPassDescKeyForPipeline(const RenderPassDesc &renderPassDesc) const
Definition: DawnCaps.cpp:870
const DawnCaps * dawnCaps() const
V * set(K key, V val)
Definition: SkTHash.h:487
VkDevice device
Definition: main.cc:53

◆ findOrCreateDawnBuffer()

sk_sp< DawnBuffer > skgpu::graphite::DawnResourceProvider::findOrCreateDawnBuffer ( size_t  size,
BufferType  type,
AccessPattern  accessPattern,
std::string_view  label 
)

Definition at line 332 of file DawnResourceProvider.cpp.

335 {
336 sk_sp<Buffer> buffer = this->findOrCreateBuffer(size, type, accessPattern, std::move(label));
337 DawnBuffer* ptr = static_cast<DawnBuffer*>(buffer.release());
338 return sk_sp<DawnBuffer>(ptr);
339}
GLenum type
sk_sp< Buffer > findOrCreateBuffer(size_t size, BufferType type, AccessPattern, std::string_view label)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
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

◆ findOrCreateDiscardableMSAALoadTexture()

sk_sp< DawnTexture > skgpu::graphite::DawnResourceProvider::findOrCreateDiscardableMSAALoadTexture ( SkISize  dimensions,
const TextureInfo msaaInfo 
)

Definition at line 236 of file DawnResourceProvider.cpp.

237 {
238 SkASSERT(msaaInfo.isValid());
239
240 // Derive the load texture's info from MSAA texture's info.
241 DawnTextureInfo dawnMsaaLoadTextureInfo;
242 msaaInfo.getDawnTextureInfo(&dawnMsaaLoadTextureInfo);
243 dawnMsaaLoadTextureInfo.fSampleCount = 1;
244 dawnMsaaLoadTextureInfo.fUsage |= wgpu::TextureUsage::TextureBinding;
245
246#if !defined(__EMSCRIPTEN__)
247 // MSAA texture can be transient attachment (memoryless) but the load texture cannot be.
248 // This is because the load texture will need to have its content retained between two passes
249 // loading:
250 // - first pass: the resolve texture is blitted to the load texture.
251 // - 2nd pass: the actual render pass is started and the load texture is blitted to the MSAA
252 // texture.
253 dawnMsaaLoadTextureInfo.fUsage &= (~wgpu::TextureUsage::TransientAttachment);
254#endif
255
256 auto texture = this->findOrCreateDiscardableMSAAAttachment(dimensions, dawnMsaaLoadTextureInfo);
257
258 return sk_sp<DawnTexture>(static_cast<DawnTexture*>(texture.release()));
259}
#define SkASSERT(cond)
Definition: SkAssert.h:116
sk_sp< Texture > findOrCreateDiscardableMSAAAttachment(SkISize dimensions, const TextureInfo &)
FlTexture * texture

◆ findOrCreateSingleTextureSamplerBindGroup()

const wgpu::BindGroup & skgpu::graphite::DawnResourceProvider::findOrCreateSingleTextureSamplerBindGroup ( const DawnSampler sampler,
const DawnTexture texture 
)

Definition at line 499 of file DawnResourceProvider.cpp.

500 {
501 auto key = make_texture_bind_group_key(sampler, texture);
502 auto* existingBindGroup = fSingleTextureSamplerBindGroups.find(key);
503 if (existingBindGroup) {
504 // cache hit.
505 return *existingBindGroup;
506 }
507
508 std::array<wgpu::BindGroupEntry, 2> entries;
509
510 entries[0].binding = 0;
511 entries[0].sampler = sampler->dawnSampler();
512 entries[1].binding = 1;
513 entries[1].textureView = texture->sampleTextureView();
514
515 wgpu::BindGroupDescriptor desc;
517 desc.entryCount = entries.size();
518 desc.entries = entries.data();
519
520 const auto& device = this->dawnSharedContext()->device();
521 auto bindGroup = device.CreateBindGroup(&desc);
522
523 return *fSingleTextureSamplerBindGroups.insert(key, bindGroup);
524}
V * find(const K &key)
Definition: SkLRUCache.h:49
V * insert(const K &key, V value)
Definition: SkLRUCache.h:62
const wgpu::BindGroupLayout & getOrCreateSingleTextureSamplerBindGroupLayout()
const wgpu::Device & device() const

◆ findOrCreateUniformBuffersBindGroup()

const wgpu::BindGroup & skgpu::graphite::DawnResourceProvider::findOrCreateUniformBuffersBindGroup ( const std::array< std::pair< const DawnBuffer *, uint32_t >, 4 > &  boundBuffersAndSizes)

Definition at line 454 of file DawnResourceProvider.cpp.

455 {
456 auto key = make_ubo_bind_group_key(boundBuffersAndSizes);
457 auto* existingBindGroup = fUniformBufferBindGroupCache.find(key);
458 if (existingBindGroup) {
459 // cache hit.
460 return *existingBindGroup;
461 }
462
463 // Translate to wgpu::BindGroupDescriptor
464 std::array<wgpu::BindGroupEntry, 4> entries;
465
466 constexpr uint32_t kBindingIndices[] = {
471 };
472
473 for (uint32_t i = 0; i < boundBuffersAndSizes.size(); ++i) {
474 const DawnBuffer* boundBuffer = boundBuffersAndSizes[i].first;
475 const uint32_t bindingSize = boundBuffersAndSizes[i].second;
476
477 entries[i].binding = kBindingIndices[i];
478 entries[i].offset = 0;
479 if (boundBuffer) {
480 entries[i].buffer = boundBuffer->dawnBuffer();
481 entries[i].size = SkAlignTo(bindingSize, kBufferBindingSizeAlignment);
482 } else {
483 entries[i].buffer = this->getOrCreateNullBuffer();
484 entries[i].size = wgpu::kWholeSize;
485 }
486 }
487
488 wgpu::BindGroupDescriptor desc;
490 desc.entryCount = entries.size();
491 desc.entries = entries.data();
492
493 const auto& device = this->dawnSharedContext()->device();
494 auto bindGroup = device.CreateBindGroup(&desc);
495
496 return *fUniformBufferBindGroupCache.insert(key, bindGroup);
497}
static constexpr size_t SkAlignTo(size_t x, size_t alignment)
Definition: SkAlign.h:33
static constexpr unsigned int kRenderStepUniformBufferIndex
static constexpr unsigned int kPaintUniformBufferIndex
static constexpr unsigned int kGradientBufferIndex
static constexpr unsigned int kIntrinsicUniformBufferIndex
const wgpu::BindGroupLayout & getOrCreateUniformBuffersBindGroupLayout()

◆ getOrCreateIntrinsicConstantBuffer()

const sk_sp< DawnBuffer > & skgpu::graphite::DawnResourceProvider::getOrCreateIntrinsicConstantBuffer ( )

Definition at line 442 of file DawnResourceProvider.cpp.

442 {
443 if (!fIntrinsicConstantBuffer) {
444 fIntrinsicConstantBuffer = findOrCreateDawnBuffer(sizeof(float[4]),
447 "IntrinsicConstantBuffer");
448 SkASSERT(fIntrinsicConstantBuffer);
449 }
450
451 return fIntrinsicConstantBuffer;
452}
sk_sp< DawnBuffer > findOrCreateDawnBuffer(size_t size, BufferType type, AccessPattern, std::string_view label)

◆ getOrCreateSingleTextureSamplerBindGroupLayout()

const wgpu::BindGroupLayout & skgpu::graphite::DawnResourceProvider::getOrCreateSingleTextureSamplerBindGroupLayout ( )

Definition at line 394 of file DawnResourceProvider.cpp.

394 {
395 if (fSingleTextureSamplerBindGroupLayout) {
396 return fSingleTextureSamplerBindGroupLayout;
397 }
398
399 std::array<wgpu::BindGroupLayoutEntry, 2> entries;
400
401 entries[0].binding = 0;
402 entries[0].visibility = wgpu::ShaderStage::Fragment;
403 entries[0].sampler.type = wgpu::SamplerBindingType::Filtering;
404
405 entries[1].binding = 1;
406 entries[1].visibility = wgpu::ShaderStage::Fragment;
407 entries[1].texture.sampleType = wgpu::TextureSampleType::Float;
408 entries[1].texture.viewDimension = wgpu::TextureViewDimension::e2D;
409 entries[1].texture.multisampled = false;
410
411 wgpu::BindGroupLayoutDescriptor groupLayoutDesc;
413 groupLayoutDesc.label = "Single texture + sampler bind group layout";
414 }
415
416 groupLayoutDesc.entryCount = entries.size();
417 groupLayoutDesc.entries = entries.data();
418 fSingleTextureSamplerBindGroupLayout =
419 this->dawnSharedContext()->device().CreateBindGroupLayout(&groupLayoutDesc);
420
421 return fSingleTextureSamplerBindGroupLayout;
422}
bool setBackendLabels() const
Definition: Caps.h:297
const Caps * caps() const
Definition: SharedContext.h:39

◆ getOrCreateUniformBuffersBindGroupLayout()

const wgpu::BindGroupLayout & skgpu::graphite::DawnResourceProvider::getOrCreateUniformBuffersBindGroupLayout ( )

Definition at line 341 of file DawnResourceProvider.cpp.

341 {
342 if (fUniformBuffersBindGroupLayout) {
343 return fUniformBuffersBindGroupLayout;
344 }
345
346 std::array<wgpu::BindGroupLayoutEntry, 4> entries;
348 entries[0].visibility = wgpu::ShaderStage::Vertex | wgpu::ShaderStage::Fragment;
349 entries[0].buffer.type = wgpu::BufferBindingType::Uniform;
350 entries[0].buffer.hasDynamicOffset = true;
351 entries[0].buffer.minBindingSize = 0;
352
354 entries[1].visibility = wgpu::ShaderStage::Vertex | wgpu::ShaderStage::Fragment;
355 entries[1].buffer.type = fSharedContext->caps()->storageBufferPreferred()
356 ? wgpu::BufferBindingType::ReadOnlyStorage
358 entries[1].buffer.hasDynamicOffset = true;
359 entries[1].buffer.minBindingSize = 0;
360
362 entries[2].visibility = wgpu::ShaderStage::Fragment;
363 entries[2].buffer.type = fSharedContext->caps()->storageBufferPreferred()
364 ? wgpu::BufferBindingType::ReadOnlyStorage
366 entries[2].buffer.hasDynamicOffset = true;
367 entries[2].buffer.minBindingSize = 0;
368
369 // Gradient buffer will only be used when storage buffers are preferred, else large
370 // gradients use a texture fallback, set binding type as a uniform when not in use to
371 // satisfy any binding type restricions for non-supported ssbo devices.
373 entries[3].visibility = wgpu::ShaderStage::Fragment;
374 entries[3].buffer.type = fSharedContext->caps()->storageBufferPreferred()
375 ? wgpu::BufferBindingType::ReadOnlyStorage
377 entries[3].buffer.hasDynamicOffset = true;
378 entries[3].buffer.minBindingSize = 0;
379
380 wgpu::BindGroupLayoutDescriptor groupLayoutDesc;
382 groupLayoutDesc.label = "Uniform buffers bind group layout";
383 }
384
385 groupLayoutDesc.entryCount = entries.size();
386 groupLayoutDesc.entries = entries.data();
387 fUniformBuffersBindGroupLayout =
388 this->dawnSharedContext()->device().CreateBindGroupLayout(&groupLayoutDesc);
389
390 return fUniformBuffersBindGroupLayout;
391}
GrTriangulator::Vertex Vertex
SkMeshSpecification::Uniform Uniform
Definition: SkMesh.cpp:66
bool storageBufferPreferred() const
Definition: Caps.h:239

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