Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 &, skgpu::Budgeted)
 
virtual sk_sp< TexturecreateWrappedTexture (const BackendTexture &)=0
 
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, std::string_view label)=0
 
virtual sk_sp< SamplercreateSampler (const SamplerDesc &)=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 245 of file ResourceProvider.cpp.

245 {
246 if (!dimensions_are_valid(fSharedContext->caps()->maxTextureSize(), dimensions)) {
247 return {};
248 }
249 return this->onCreateBackendTexture(dimensions, info);
250}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
int maxTextureSize() const
Definition Caps.h:134
virtual BackendTexture onCreateBackendTexture(SkISize dimensions, const TextureInfo &)=0
const Caps * caps() const

◆ createBuffer()

virtual sk_sp< Buffer > skgpu::graphite::ResourceProvider::createBuffer ( size_t  size,
BufferType  type,
AccessPattern  ,
std::string_view  label 
)
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()

virtual sk_sp< Texture > skgpu::graphite::ResourceProvider::createWrappedTexture ( const BackendTexture )
pure virtual

◆ deleteBackendTexture()

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

Definition at line 277 of file ResourceProvider.cpp.

277 {
279}
virtual void onDeleteBackendTexture(const BackendTexture &)=0
FlTexture * texture

◆ dumpMemoryStatistics()

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

Definition at line 88 of file ResourceProvider.h.

88 {
89 fResourceCache->dumpMemoryStatistics(traceMemoryDump);
90 }

◆ findOrCreateBuffer()

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

Definition at line 184 of file ResourceProvider.cpp.

187 {
189
190 GraphiteResourceKey key;
191 {
192 // For the key we need ((sizeof(size_t) + (sizeof(uint32_t) - 1)) / (sizeof(uint32_t))
193 // uint32_t's for the size and one uint32_t for the rest.
194 static_assert(sizeof(uint32_t) == 4);
195 static const int kSizeKeyNum32DataCnt = (sizeof(size_t) + 3) / 4;
196 static const int kKeyNum32DataCnt = kSizeKeyNum32DataCnt + 1;
197
198 SkASSERT(static_cast<uint32_t>(type) < (1u << 4));
199 SkASSERT(static_cast<uint32_t>(accessPattern) < (1u << 1));
200
201 GraphiteResourceKey::Builder builder(&key, kType, kKeyNum32DataCnt, Shareable::kNo);
202 builder[0] = (static_cast<uint32_t>(type) << 0) |
203 (static_cast<uint32_t>(accessPattern) << 4);
204 size_t szKey = size;
205 for (int i = 0; i < kSizeKeyNum32DataCnt; ++i) {
206 builder[i + 1] = (uint32_t) szKey;
207
208 // If size_t is 4 bytes, we cannot do a shift of 32 or else we get a warning/error that
209 // shift amount is >= width of the type.
210 if constexpr(kSizeKeyNum32DataCnt > 1) {
211 szKey = szKey >> 32;
212 }
213 }
214 }
215
217 if (Resource* resource = fResourceCache->findAndRefResource(key, budgeted)) {
218 resource->setLabel(std::move(label));
219 return sk_sp<Buffer>(static_cast<Buffer*>(resource));
220 }
221 auto buffer = this->createBuffer(size, type, accessPattern, std::move(label));
222 if (!buffer) {
223 return nullptr;
224 }
225
226 buffer->setKey(key);
227 fResourceCache->insertResource(buffer.get());
228 return buffer;
229}
#define SkASSERT(cond)
Definition SkAssert.h:116
virtual sk_sp< Buffer > createBuffer(size_t size, BufferType type, AccessPattern, std::string_view label)=0
static const uint8_t buffer[]
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 desc)

Definition at line 167 of file ResourceProvider.cpp.

167 {
168 GraphiteResourceKey key = fSharedContext->caps()->makeSamplerKey(desc);
169
170 if (Resource* resource = fResourceCache->findAndRefResource(key, skgpu::Budgeted::kYes)) {
171 return sk_sp<Sampler>(static_cast<Sampler*>(resource));
172 }
173
174 sk_sp<Sampler> sampler = this->createSampler(desc);
175 if (!sampler) {
176 return nullptr;
177 }
178
179 sampler->setKey(key);
180 fResourceCache->insertResource(sampler.get());
181 return sampler;
182}
T * get() const
Definition SkRefCnt.h:303
virtual GraphiteResourceKey makeSamplerKey(const SamplerDesc &samplerDesc) const
Definition Caps.cpp:72
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 112 of file ResourceProvider.cpp.

113 {
114 SkASSERT(info.isValid());
115
117
118 GraphiteResourceKey key;
119 // We always make depth and stencil attachments shareable. Between any render pass the values
120 // are reset. Thus it is safe to be used by multiple different render passes without worry of
121 // stomping on each other's data.
123
124 return this->findOrCreateTextureWithKey(dimensions, info, key, skgpu::Budgeted::kYes);
125}
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 127 of file ResourceProvider.cpp.

128 {
129 SkASSERT(info.isValid());
130
132
133 GraphiteResourceKey key;
134 // We always make discardable msaa attachments shareable. Between any render pass we discard
135 // the values of the MSAA texture. Thus it is safe to be used by multiple different render
136 // passes without worry of stomping on each other's data. It is the callings code's
137 // responsibility to populate the discardable MSAA texture with data at the start of the
138 // render pass.
140
141 return this->findOrCreateTextureWithKey(dimensions, info, key, skgpu::Budgeted::kYes);
142}

◆ 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)
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)

◆ findOrCreateScratchTexture()

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

Definition at line 98 of file ResourceProvider.cpp.

100 {
101 SkASSERT(info.isValid());
102
104
105 GraphiteResourceKey key;
106 // Scratch textures are not shareable
107 fSharedContext->caps()->buildKeyForTexture(dimensions, info, kType, Shareable::kNo, &key);
108
109 return this->findOrCreateTextureWithKey(dimensions, info, key, budgeted);
110}

◆ freeGpuResources()

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

Definition at line 281 of file ResourceProvider.cpp.

281 {
282 // TODO: Are there Resources that are ref'd by the ResourceProvider or its subclasses that need
283 // be released? If we ever find that we're holding things directly on the ResourceProviders we
284 // call down into the subclasses to allow them to release things.
285
286 fResourceCache->purgeResources();
287}

◆ getResourceCacheCurrentBudgetedBytes()

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

Definition at line 84 of file ResourceProvider.h.

84 {
85 return fResourceCache->currentBudgetedBytes();
86 }

◆ getResourceCacheLimit()

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

Definition at line 83 of file ResourceProvider.h.

83{ return fResourceCache->getMaxBudget(); }

◆ onCreateBackendTexture()

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

◆ onDeleteBackendTexture()

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

◆ proxyCache()

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

Definition at line 81 of file ResourceProvider.h.

81{ return fResourceCache->proxyCache(); }

◆ purgeResourcesNotUsedSince()

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

Definition at line 289 of file ResourceProvider.cpp.

289 {
290 fResourceCache->purgeResourcesNotUsedSince(purgeTime);
291}

Member Data Documentation

◆ fResourceCache

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

Definition at line 117 of file ResourceProvider.h.

◆ fSharedContext

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

Definition at line 114 of file ResourceProvider.h.


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