Flutter Engine
The Flutter Engine
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
skgpu::graphite::ResourceProvider Class Referenceabstract

#include <ResourceProvider.h>

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

Public Member Functions

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)
 

Protected Member Functions

 ResourceProvider (SharedContext *sharedContext, SingleOwner *singleOwner, uint32_t recorderID, size_t resourceBudget)
 

Protected Attributes

SharedContextfSharedContext
 
sk_sp< ResourceCachefResourceCache
 

Private Member Functions

virtual sk_sp< GraphicsPipelinecreateGraphicsPipeline (const RuntimeEffectDictionary *, const GraphicsPipelineDesc &, const RenderPassDesc &)=0
 
virtual sk_sp< ComputePipelinecreateComputePipeline (const ComputePipelineDesc &)=0
 
virtual sk_sp< TexturecreateTexture (SkISize, const TextureInfo &, skgpu::Budgeted)=0
 
virtual sk_sp< BuffercreateBuffer (size_t size, BufferType type, AccessPattern)=0
 
virtual sk_sp< SamplercreateSampler (const SamplerDesc &)=0
 
virtual sk_sp< TextureonCreateWrappedTexture (const BackendTexture &)=0
 
virtual BackendTexture onCreateBackendTexture (SkISize dimensions, const TextureInfo &)=0
 
virtual void onDeleteBackendTexture (const BackendTexture &)=0
 

Detailed Description

Definition at line 50 of file ResourceProvider.h.

Constructor & Destructor Documentation

◆ ~ResourceProvider()

skgpu::graphite::ResourceProvider::~ResourceProvider ( )
virtual

Definition at line 50 of file ResourceProvider.cpp.

50 {
51 fResourceCache->shutdown();
52}
sk_sp< ResourceCache > fResourceCache

◆ ResourceProvider()

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

Definition at line 43 of file ResourceProvider.cpp.

47 : fSharedContext(sharedContext)
48 , fResourceCache(ResourceCache::Make(singleOwner, recorderID, resourceBudget)) {}
static sk_sp< ResourceCache > Make(SingleOwner *, uint32_t recorderID, size_t maxBytes)

Member Function Documentation

◆ createBackendTexture()

BackendTexture skgpu::graphite::ResourceProvider::createBackendTexture ( SkISize  dimensions,
const TextureInfo info 
)

Definition at line 271 of file ResourceProvider.cpp.

271 {
272 if (!dimensions_are_valid(fSharedContext->caps()->maxTextureSize(), dimensions)) {
273 return {};
274 }
275 return this->onCreateBackendTexture(dimensions, info);
276}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
int maxTextureSize() const
Definition: Caps.h:141
virtual BackendTexture onCreateBackendTexture(SkISize dimensions, const TextureInfo &)=0
const Caps * caps() const
Definition: SharedContext.h:39

◆ createBuffer()

virtual sk_sp< Buffer > skgpu::graphite::ResourceProvider::createBuffer ( size_t  size,
BufferType  type,
AccessPattern   
)
privatepure virtual

◆ createComputePipeline()

virtual sk_sp< ComputePipeline > skgpu::graphite::ResourceProvider::createComputePipeline ( const ComputePipelineDesc )
privatepure virtual

◆ createGraphicsPipeline()

virtual sk_sp< GraphicsPipeline > skgpu::graphite::ResourceProvider::createGraphicsPipeline ( const RuntimeEffectDictionary ,
const GraphicsPipelineDesc ,
const RenderPassDesc  
)
privatepure virtual

◆ createSampler()

virtual sk_sp< Sampler > skgpu::graphite::ResourceProvider::createSampler ( const SamplerDesc )
privatepure virtual

◆ createTexture()

virtual sk_sp< Texture > skgpu::graphite::ResourceProvider::createTexture ( SkISize  ,
const TextureInfo ,
skgpu::Budgeted   
)
privatepure virtual

◆ createWrappedTexture()

sk_sp< Texture > skgpu::graphite::ResourceProvider::createWrappedTexture ( const BackendTexture backendTexture,
std::string_view  label 
)

Definition at line 183 of file ResourceProvider.cpp.

184 {
185 sk_sp<Texture> texture = this->onCreateWrappedTexture(backendTexture);
186 if (texture) {
187 texture->setLabel(std::move(label));
188 }
189 return texture;
190}
virtual sk_sp< Texture > onCreateWrappedTexture(const BackendTexture &)=0
FlTexture * texture

◆ deleteBackendTexture()

void skgpu::graphite::ResourceProvider::deleteBackendTexture ( const BackendTexture texture)

Definition at line 303 of file ResourceProvider.cpp.

303 {
305}
virtual void onDeleteBackendTexture(const BackendTexture &)=0

◆ dumpMemoryStatistics()

void skgpu::graphite::ResourceProvider::dumpMemoryStatistics ( SkTraceMemoryDump traceMemoryDump) const
inline

Definition at line 92 of file ResourceProvider.h.

92 {
93 fResourceCache->dumpMemoryStatistics(traceMemoryDump);
94 }

◆ findOrCreateBuffer()

sk_sp< Buffer > skgpu::graphite::ResourceProvider::findOrCreateBuffer ( size_t  size,
BufferType  type,
AccessPattern  accessPattern,
std::string_view  label 
)

Definition at line 209 of file ResourceProvider.cpp.

212 {
214
215 GraphiteResourceKey key;
216 {
217 // For the key we need ((sizeof(size_t) + (sizeof(uint32_t) - 1)) / (sizeof(uint32_t))
218 // uint32_t's for the size and one uint32_t for the rest.
219 static_assert(sizeof(uint32_t) == 4);
220 static const int kSizeKeyNum32DataCnt = (sizeof(size_t) + 3) / 4;
221 static const int kKeyNum32DataCnt = kSizeKeyNum32DataCnt + 1;
222
223 SkASSERT(static_cast<uint32_t>(type) < (1u << 4));
224 SkASSERT(static_cast<uint32_t>(accessPattern) < (1u << 1));
225
226 GraphiteResourceKey::Builder builder(&key, kType, kKeyNum32DataCnt, Shareable::kNo);
227 builder[0] = (static_cast<uint32_t>(type) << 0) |
228 (static_cast<uint32_t>(accessPattern) << 4);
229 size_t szKey = size;
230 for (int i = 0; i < kSizeKeyNum32DataCnt; ++i) {
231 builder[i + 1] = (uint32_t) szKey;
232
233 // If size_t is 4 bytes, we cannot do a shift of 32 or else we get a warning/error that
234 // shift amount is >= width of the type.
235 if constexpr(kSizeKeyNum32DataCnt > 1) {
236 szKey = szKey >> 32;
237 }
238 }
239 }
240
242 if (Resource* resource = fResourceCache->findAndRefResource(key, budgeted)) {
243 resource->setLabel(std::move(label));
244 return sk_sp<Buffer>(static_cast<Buffer*>(resource));
245 }
246 auto buffer = this->createBuffer(size, type, accessPattern);
247 if (!buffer) {
248 return nullptr;
249 }
250
251 buffer->setKey(key);
252 buffer->setLabel(std::move(label));
253 fResourceCache->insertResource(buffer.get());
254 return buffer;
255}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkString resource(SkPDFResourceType type, int index)
GLenum type
virtual sk_sp< Buffer > createBuffer(size_t size, BufferType type, AccessPattern)=0
DlVertices::Builder Builder
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
uint32_t ResourceType
Budgeted
Definition: GpuTypes.h:35

◆ findOrCreateCompatibleSampler()

sk_sp< Sampler > skgpu::graphite::ResourceProvider::findOrCreateCompatibleSampler ( const SamplerDesc samplerDesc)

Definition at line 192 of file ResourceProvider.cpp.

192 {
193 GraphiteResourceKey key = fSharedContext->caps()->makeSamplerKey(samplerDesc);
194
195 if (Resource* resource = fResourceCache->findAndRefResource(key, skgpu::Budgeted::kYes)) {
196 return sk_sp<Sampler>(static_cast<Sampler*>(resource));
197 }
198
199 sk_sp<Sampler> sampler = this->createSampler(samplerDesc);
200 if (!sampler) {
201 return nullptr;
202 }
203
204 sampler->setKey(key);
205 fResourceCache->insertResource(sampler.get());
206 return sampler;
207}
T * get() const
Definition: SkRefCnt.h:303
virtual GraphiteResourceKey makeSamplerKey(const SamplerDesc &samplerDesc) const
Definition: Caps.cpp:73
virtual sk_sp< Sampler > createSampler(const SamplerDesc &)=0
std::function< ProfileSample(void)> Sampler
Sampler is run during SamplingProfiler::SampleRepeatedly. Each platform should implement its version ...

◆ findOrCreateComputePipeline()

sk_sp< ComputePipeline > skgpu::graphite::ResourceProvider::findOrCreateComputePipeline ( const ComputePipelineDesc pipelineDesc)

Definition at line 82 of file ResourceProvider.cpp.

83 {
84 auto globalCache = fSharedContext->globalCache();
85 UniqueKey pipelineKey = fSharedContext->caps()->makeComputePipelineKey(pipelineDesc);
86 sk_sp<ComputePipeline> pipeline = globalCache->findComputePipeline(pipelineKey);
87 if (!pipeline) {
88 pipeline = this->createComputePipeline(pipelineDesc);
89 if (pipeline) {
90 pipeline = globalCache->addComputePipeline(pipelineKey, std::move(pipeline));
91 }
92 }
93 return pipeline;
94}
virtual UniqueKey makeComputePipelineKey(const ComputePipelineDesc &) const =0
virtual sk_sp< ComputePipeline > createComputePipeline(const ComputePipelineDesc &)=0

◆ findOrCreateDepthStencilAttachment()

sk_sp< Texture > skgpu::graphite::ResourceProvider::findOrCreateDepthStencilAttachment ( SkISize  dimensions,
const TextureInfo info 
)

Definition at line 117 of file ResourceProvider.cpp.

118 {
119 SkASSERT(info.isValid());
120
122
123 GraphiteResourceKey key;
124 // We always make depth and stencil attachments shareable. Between any render pass the values
125 // are reset. Thus it is safe to be used by multiple different render passes without worry of
126 // stomping on each other's data.
128
129 return this->findOrCreateTextureWithKey(dimensions,
130 info,
131 key,
132 "DepthStencilAttachment",
134}
virtual void buildKeyForTexture(SkISize dimensions, const TextureInfo &, ResourceType, Shareable, GraphiteResourceKey *) const =0

◆ findOrCreateDiscardableMSAAAttachment()

sk_sp< Texture > skgpu::graphite::ResourceProvider::findOrCreateDiscardableMSAAAttachment ( SkISize  dimensions,
const TextureInfo info 
)

Definition at line 136 of file ResourceProvider.cpp.

137 {
138 SkASSERT(info.isValid());
139
141
142 GraphiteResourceKey key;
143 // We always make discardable msaa attachments shareable. Between any render pass we discard
144 // the values of the MSAA texture. Thus it is safe to be used by multiple different render
145 // passes without worry of stomping on each other's data. It is the callings code's
146 // responsibility to populate the discardable MSAA texture with data at the start of the
147 // render pass.
149
150 return this->findOrCreateTextureWithKey(dimensions,
151 info,
152 key,
153 "DiscardableMSAAAttachment",
155}

◆ findOrCreateGraphicsPipeline()

sk_sp< GraphicsPipeline > skgpu::graphite::ResourceProvider::findOrCreateGraphicsPipeline ( const RuntimeEffectDictionary runtimeDict,
const GraphicsPipelineDesc pipelineDesc,
const RenderPassDesc renderPassDesc 
)

Definition at line 54 of file ResourceProvider.cpp.

57 {
58 auto globalCache = fSharedContext->globalCache();
59 UniqueKey pipelineKey = fSharedContext->caps()->makeGraphicsPipelineKey(pipelineDesc,
60 renderPassDesc);
61 sk_sp<GraphicsPipeline> pipeline = globalCache->findGraphicsPipeline(pipelineKey);
62 if (!pipeline) {
63 // Haven't encountered this pipeline, so create a new one. Since pipelines are shared
64 // across Recorders, we could theoretically create equivalent pipelines on different
65 // threads. If this happens, GlobalCache returns the first-through-gate pipeline and we
66 // discard the redundant pipeline. While this is wasted effort in the rare event of a race,
67 // it allows pipeline creation to be performed without locking the global cache.
68 // NOTE: The parameters to TRACE_EVENT are only evaluated inside an if-block when the
69 // category is enabled.
70 TRACE_EVENT1("skia.shaders", "createGraphicsPipeline", "desc",
71 TRACE_STR_COPY(to_str(fSharedContext, pipelineDesc, renderPassDesc).c_str()));
72 pipeline = this->createGraphicsPipeline(runtimeDict, pipelineDesc, renderPassDesc);
73 if (pipeline) {
74 // TODO: Should we store a null pipeline if we failed to create one so that subsequent
75 // usage immediately sees that the pipeline cannot be created, vs. retrying every time?
76 pipeline = globalCache->addGraphicsPipeline(pipelineKey, std::move(pipeline));
77 }
78 }
79 return pipeline;
80}
#define TRACE_STR_COPY(str)
Definition: SkTraceEvent.h:63
virtual UniqueKey makeGraphicsPipelineKey(const GraphicsPipelineDesc &, const RenderPassDesc &) const =0
virtual sk_sp< GraphicsPipeline > createGraphicsPipeline(const RuntimeEffectDictionary *, const GraphicsPipelineDesc &, const RenderPassDesc &)=0
static std::string to_str(const SharedContext *ctx, const GraphicsPipelineDesc &gpDesc, const RenderPassDesc &rpDesc)
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val)
Definition: trace_event.h:141

◆ findOrCreateScratchTexture()

sk_sp< Texture > skgpu::graphite::ResourceProvider::findOrCreateScratchTexture ( SkISize  dimensions,
const TextureInfo info,
std::string_view  label,
skgpu::Budgeted  budgeted 
)

Definition at line 98 of file ResourceProvider.cpp.

101 {
102 SkASSERT(info.isValid());
103
105
106 GraphiteResourceKey key;
107 // Scratch textures are not shareable
108 fSharedContext->caps()->buildKeyForTexture(dimensions, info, kType, Shareable::kNo, &key);
109
110 return this->findOrCreateTextureWithKey(dimensions,
111 info,
112 key,
113 std::move(label),
114 budgeted);
115}

◆ freeGpuResources()

void skgpu::graphite::ResourceProvider::freeGpuResources ( )

Definition at line 307 of file ResourceProvider.cpp.

307 {
308 // TODO: Are there Resources that are ref'd by the ResourceProvider or its subclasses that need
309 // be released? If we ever find that we're holding things directly on the ResourceProviders we
310 // call down into the subclasses to allow them to release things.
311
312 fResourceCache->purgeResources();
313}

◆ getResourceCacheCurrentBudgetedBytes()

size_t skgpu::graphite::ResourceProvider::getResourceCacheCurrentBudgetedBytes ( ) const
inline

Definition at line 88 of file ResourceProvider.h.

88 {
89 return fResourceCache->currentBudgetedBytes();
90 }

◆ getResourceCacheLimit()

size_t skgpu::graphite::ResourceProvider::getResourceCacheLimit ( ) const
inline

Definition at line 87 of file ResourceProvider.h.

87{ return fResourceCache->getMaxBudget(); }

◆ onCreateBackendTexture()

virtual BackendTexture skgpu::graphite::ResourceProvider::onCreateBackendTexture ( SkISize  dimensions,
const TextureInfo  
)
privatepure virtual

◆ onCreateWrappedTexture()

virtual sk_sp< Texture > skgpu::graphite::ResourceProvider::onCreateWrappedTexture ( const BackendTexture )
privatepure virtual

◆ onDeleteBackendTexture()

virtual void skgpu::graphite::ResourceProvider::onDeleteBackendTexture ( const BackendTexture )
privatepure virtual

◆ proxyCache()

ProxyCache * skgpu::graphite::ResourceProvider::proxyCache ( )
inline

Definition at line 85 of file ResourceProvider.h.

85{ return fResourceCache->proxyCache(); }

◆ purgeResourcesNotUsedSince()

void skgpu::graphite::ResourceProvider::purgeResourcesNotUsedSince ( StdSteadyClock::time_point  purgeTime)

Definition at line 315 of file ResourceProvider.cpp.

315 {
316 fResourceCache->purgeResourcesNotUsedSince(purgeTime);
317}

Member Data Documentation

◆ fResourceCache

sk_sp<ResourceCache> skgpu::graphite::ResourceProvider::fResourceCache
protected

Definition at line 121 of file ResourceProvider.h.

◆ fSharedContext

SharedContext* skgpu::graphite::ResourceProvider::fSharedContext
protected

Definition at line 118 of file ResourceProvider.h.


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