Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Friends | List of all members
skgpu::graphite::Resource Class Referenceabstract

#include <Resource.h>

Inheritance diagram for skgpu::graphite::Resource:
skgpu::graphite::Buffer skgpu::graphite::ComputePipeline skgpu::graphite::GraphicsPipeline skgpu::graphite::MtlBlitCommandEncoder skgpu::graphite::MtlComputeCommandEncoder skgpu::graphite::MtlRenderCommandEncoder skgpu::graphite::Sampler skgpu::graphite::TestResource skgpu::graphite::Texture skgpu::graphite::VulkanDescriptorSet skgpu::graphite::VulkanFramebuffer skgpu::graphite::VulkanRenderPass skgpu::graphite::VulkanSamplerYcbcrConversion

Classes

class  UniqueID
 

Public Member Functions

 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
 
virtual const char * getResourceType () const =0
 
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)
 

Protected Member Functions

 Resource (const SharedContext *, Ownership, skgpu::Budgeted, size_t gpuMemorySize, std::string_view label, bool commandBufferRefsAsUsageRefs=false)
 
virtual ~Resource ()
 
const SharedContextsharedContext () const
 
virtual void freeGpuData ()=0
 
virtual void invokeReleaseProc ()
 
virtual void onDumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump, const char *dumpName) const
 
void setDeleteASAP ()
 

Friends

class ProxyCache
 

Detailed Description

Base class for objects that can be kept in the ResourceCache.

Definition at line 37 of file Resource.h.

Constructor & Destructor Documentation

◆ Resource() [1/3]

skgpu::graphite::Resource::Resource ( const Resource )
delete

◆ Resource() [2/3]

skgpu::graphite::Resource::Resource ( Resource &&  )
delete

◆ Resource() [3/3]

skgpu::graphite::Resource::Resource ( const SharedContext sharedContext,
Ownership  ownership,
skgpu::Budgeted  budgeted,
size_t  gpuMemorySize,
std::string_view  label,
bool  commandBufferRefsAsUsageRefs = false 
)
protected

Definition at line 26 of file Resource.cpp.

32 : fSharedContext(sharedContext)
33 , fUsageRefCnt(1)
34 , fCommandBufferRefCnt(0)
35 , fCacheRefCnt(0)
36 , fCommandBufferRefsAsUsageRefs(commandBufferRefsAsUsageRefs)
37 , fOwnership(ownership)
38 , fGpuMemorySize(gpuMemorySize)
39 , fBudgeted(budgeted)
40 , fUniqueID(create_unique_id()) {
41 // If we don't own the resource that must mean its wrapped in a client object. Thus we should
42 // not be budgeted
43 SkASSERT(fOwnership == Ownership::kOwned || fBudgeted == skgpu::Budgeted::kNo);
44
45 this->setLabel(label);
46}
#define SkASSERT(cond)
Definition SkAssert.h:116
skgpu::Budgeted budgeted() const
Definition Resource.h:100
size_t gpuMemorySize() const
Definition Resource.h:104
const SharedContext * sharedContext() const
Definition Resource.h:187
void setLabel(std::string_view label)
Definition Resource.h:136
Ownership ownership() const
Definition Resource.h:98

◆ ~Resource()

skgpu::graphite::Resource::~Resource ( )
protectedvirtual

Definition at line 48 of file Resource.cpp.

48 {
49 // The cache should have released or destroyed this resource.
50 SkASSERT(this->wasDestroyed());
51}
bool wasDestroyed() const
Definition Resource.h:151

Member Function Documentation

◆ budgeted()

skgpu::Budgeted skgpu::graphite::Resource::budgeted ( ) const
inline

Definition at line 100 of file Resource.h.

100{ return fBudgeted; }

◆ dumpMemoryStatistics()

void skgpu::graphite::Resource::dumpMemoryStatistics ( SkTraceMemoryDump traceMemoryDump) const

Definition at line 98 of file Resource.cpp.

98 {
99 if (this->ownership() == Ownership::kWrapped && !traceMemoryDump->shouldDumpWrappedObjects()) {
100 return;
101 }
102
103 if (this->budgeted() == skgpu::Budgeted::kNo &&
104 !traceMemoryDump->shouldDumpUnbudgetedObjects()) {
105 return;
106 }
107
108 size_t size = this->gpuMemorySize();
109
110 // Avoid dumping objects without a size (e.g. Samplers, pipelines, etc).
111 // TODO: Would a client ever actually want to see all of this? Wouldn't be hard to add it as an
112 // option.
113 if (size == 0) {
114 return;
115 }
116
117 SkString resourceName("skia/gpu_resources/resource_");
118 resourceName.appendU32(this->uniqueID().asUInt());
119
120 traceMemoryDump->dumpNumericValue(resourceName.c_str(), "size", "bytes", size);
121 traceMemoryDump->dumpStringValue(resourceName.c_str(), "type", this->getResourceType());
122 traceMemoryDump->dumpStringValue(resourceName.c_str(), "label", this->getLabel().c_str());
123 if (this->isPurgeable()) {
124 traceMemoryDump->dumpNumericValue(resourceName.c_str(), "purgeable_size", "bytes", size);
125 }
126 if (traceMemoryDump->shouldDumpWrappedObjects()) {
127 traceMemoryDump->dumpWrappedState(resourceName.c_str(),
128 this->ownership() == Ownership::kWrapped);
129 }
130 if (traceMemoryDump->shouldDumpUnbudgetedObjects()) {
131 traceMemoryDump->dumpBudgetedState(resourceName.c_str(),
132 this->budgeted() == skgpu::Budgeted::kYes);
133 }
134
135 this->onDumpMemoryStatistics(traceMemoryDump, resourceName.c_str());
136
137 // TODO: implement this to report real gpu id backing the resource. Will be virtual implemented
138 // by backend specific resource subclasses.
139 //this->setMemoryBacking(traceMemoryDump, resourceName);
140}
virtual bool shouldDumpUnbudgetedObjects() const
virtual void dumpWrappedState(const char *, bool)
virtual void dumpStringValue(const char *, const char *, const char *)
virtual void dumpBudgetedState(const char *, bool)
virtual bool shouldDumpWrappedObjects() const
virtual void dumpNumericValue(const char *dumpName, const char *valueName, const char *units, uint64_t value)=0
virtual void onDumpMemoryStatistics(SkTraceMemoryDump *traceMemoryDump, const char *dumpName) const
Definition Resource.h:196
UniqueID uniqueID() const
Definition Resource.h:123
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

◆ freeGpuData()

virtual void skgpu::graphite::Resource::freeGpuData ( )
protectedpure virtual

◆ getLabel()

std::string skgpu::graphite::Resource::getLabel ( ) const
inline

Definition at line 132 of file Resource.h.

132{ return fLabel; }

◆ getResourceType()

virtual const char * skgpu::graphite::Resource::getResourceType ( ) const
pure virtual

◆ gpuMemorySize()

size_t skgpu::graphite::Resource::gpuMemorySize ( ) const
inline

Definition at line 104 of file Resource.h.

104{ return fGpuMemorySize; }

◆ invokeReleaseProc()

virtual void skgpu::graphite::Resource::invokeReleaseProc ( )
inlineprotectedvirtual

Reimplemented in skgpu::graphite::Texture.

Definition at line 193 of file Resource.h.

193{}

◆ key()

const GraphiteResourceKey & skgpu::graphite::Resource::key ( ) const
inline

Definition at line 153 of file Resource.h.

153{ return fKey; }

◆ onDumpMemoryStatistics()

virtual void skgpu::graphite::Resource::onDumpMemoryStatistics ( SkTraceMemoryDump traceMemoryDump,
const char *  dumpName 
) const
inlineprotectedvirtual

Reimplemented in skgpu::graphite::DawnBuffer, skgpu::graphite::DawnTexture, and skgpu::graphite::Texture.

Definition at line 196 of file Resource.h.

197 {}

◆ operator=() [1/2]

Resource & skgpu::graphite::Resource::operator= ( const Resource )
delete

◆ operator=() [2/2]

Resource & skgpu::graphite::Resource::operator= ( Resource &&  )
delete

◆ ownership()

Ownership skgpu::graphite::Resource::ownership ( ) const
inline

Definition at line 98 of file Resource.h.

98{ return fOwnership; }

◆ prepareForReturnToCache()

virtual void skgpu::graphite::Resource::prepareForReturnToCache ( const std::function< void()> &  takeRef)
inlinevirtual

If the resource has a non-shareable key then this gives the resource subclass an opportunity to prepare itself to re-enter the cache. The ResourceCache extends its privilege to take the first UsageRef to this function via takeRef. If takeRef is called this resource will not immediately enter the cache but will be re-reprocessed with the Usage Ref count again reaches zero.

Definition at line 170 of file Resource.h.

170{}

◆ ref()

void skgpu::graphite::Resource::ref ( ) const
inline

Definition at line 45 of file Resource.h.

45 {
46 // Only the cache should be able to add the first usage ref to a resource.
47 SkASSERT(this->hasUsageRef());
48 // No barrier required.
49 (void)fUsageRefCnt.fetch_add(+1, std::memory_order_relaxed);
50 }

◆ refCommandBuffer()

void skgpu::graphite::Resource::refCommandBuffer ( ) const
inline

Definition at line 70 of file Resource.h.

70 {
71 if (fCommandBufferRefsAsUsageRefs) {
72 return this->ref();
73 }
74 // No barrier required.
75 (void)fCommandBufferRefCnt.fetch_add(+1, std::memory_order_relaxed);
76 }

◆ setDeleteASAP()

void skgpu::graphite::Resource::setDeleteASAP ( )
inlineprotected

Definition at line 205 of file Resource.h.

205{ fDeleteASAP = DeleteASAP::kYes; }

◆ setKey()

void skgpu::graphite::Resource::setKey ( const GraphiteResourceKey key)
inline

Definition at line 155 of file Resource.h.

155 {
156 SkASSERT(key.shareable() == Shareable::kNo || this->budgeted() == skgpu::Budgeted::kYes);
157 fKey = key;
158 }
const GraphiteResourceKey & key() const
Definition Resource.h:153

◆ setLabel()

void skgpu::graphite::Resource::setLabel ( std::string_view  label)
inline

Definition at line 136 of file Resource.h.

136 {
137 fLabel = label;
138 // TODO: call into subclasses to allow them to set the label on actual GPU objects if they
139 // want to.
140 }

◆ sharedContext()

const SharedContext * skgpu::graphite::Resource::sharedContext ( ) const
inlineprotected

Definition at line 187 of file Resource.h.

187{ return fSharedContext; }

◆ uniqueID()

UniqueID skgpu::graphite::Resource::uniqueID ( ) const
inline

Definition at line 123 of file Resource.h.

123{ return fUniqueID; }

◆ unref()

void skgpu::graphite::Resource::unref ( ) const
inline

Definition at line 53 of file Resource.h.

53 {
54 bool shouldFree = false;
55 {
56 SkAutoMutexExclusive locked(fUnrefMutex);
57 SkASSERT(this->hasUsageRef());
58 // A release here acts in place of all releases we "should" have been doing in ref().
59 if (1 == fUsageRefCnt.fetch_add(-1, std::memory_order_acq_rel)) {
60 shouldFree = this->notifyARefIsZero(LastRemovedRef::kUsage);
61 }
62 }
63 if (shouldFree) {
64 Resource* mutableThis = const_cast<Resource*>(this);
65 mutableThis->internalDispose();
66 }
67 }
Resource(const Resource &)=delete

◆ unrefCommandBuffer()

void skgpu::graphite::Resource::unrefCommandBuffer ( ) const
inline

Definition at line 79 of file Resource.h.

79 {
80 if (fCommandBufferRefsAsUsageRefs) {
81 return this->unref();
82 }
83 bool shouldFree = false;
84 {
85 SkAutoMutexExclusive locked(fUnrefMutex);
86 SkASSERT(this->hasCommandBufferRef());
87 // A release here acts in place of all releases we "should" have been doing in ref().
88 if (1 == fCommandBufferRefCnt.fetch_add(-1, std::memory_order_acq_rel)) {
89 shouldFree = this->notifyARefIsZero(LastRemovedRef::kCommandBuffer);
90 }
91 }
92 if (shouldFree) {
93 Resource* mutableThis = const_cast<Resource*>(this);
94 mutableThis->internalDispose();
95 }
96 }

◆ wasDestroyed()

bool skgpu::graphite::Resource::wasDestroyed ( ) const
inline

Definition at line 151 of file Resource.h.

151{ return fSharedContext == nullptr; }

Friends And Related Symbol Documentation

◆ ProxyCache

friend class ProxyCache
friend

Definition at line 208 of file Resource.h.


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