Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Protected Member Functions | Private 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::VulkanYcbcrConversion

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, bool commandBufferRefsAsUsageRefs=false)
 
virtual ~Resource ()
 
const SharedContextsharedContext () const
 
virtual void onDumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump, const char *dumpName) const
 
void setDeleteASAP ()
 

Private Member Functions

virtual void freeGpuData ()=0
 
virtual void invokeReleaseProc ()
 
virtual void setBackendLabel (char const *label)
 

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,
bool  commandBufferRefsAsUsageRefs = false 
)
protected

Definition at line 26 of file Resource.cpp.

31 : fSharedContext(sharedContext)
32 , fUsageRefCnt(1)
33 , fCommandBufferRefCnt(0)
34 , fCacheRefCnt(0)
35 , fCommandBufferRefsAsUsageRefs(commandBufferRefsAsUsageRefs)
36 , fOwnership(ownership)
37 , fGpuMemorySize(gpuMemorySize)
38 , fBudgeted(budgeted)
39 , fUniqueID(create_unique_id()) {
40 // If we don't own the resource that must mean its wrapped in a client object. Thus we should
41 // not be budgeted
42 SkASSERT(fOwnership == Ownership::kOwned || fBudgeted == skgpu::Budgeted::kNo);
43}
#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:189
Ownership ownership() const
Definition: Resource.h:98

◆ ~Resource()

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

Definition at line 45 of file Resource.cpp.

45 {
46 // The cache should have released or destroyed this resource.
47 SkASSERT(this->wasDestroyed());
48}
bool wasDestroyed() const
Definition: Resource.h:154

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 95 of file Resource.cpp.

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

Reimplemented in skgpu::graphite::Texture.

Definition at line 211 of file Resource.h.

211{}

◆ key()

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

Definition at line 156 of file Resource.h.

156{ return fKey; }

◆ onDumpMemoryStatistics()

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

Reimplemented in skgpu::graphite::Texture.

Definition at line 192 of file Resource.h.

193 {}

◆ 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 173 of file Resource.h.

173{}

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

◆ setBackendLabel()

virtual void skgpu::graphite::Resource::setBackendLabel ( char const *  label)
inlineprivatevirtual

Definition at line 229 of file Resource.h.

229{}

◆ setDeleteASAP()

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

Definition at line 202 of file Resource.h.

202{ fDeleteASAP = DeleteASAP::kYes; }

◆ setKey()

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

Definition at line 158 of file Resource.h.

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

◆ setLabel()

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

Definition at line 136 of file Resource.h.

136 {
137 fLabel = label;
138
139 if (!fLabel.empty()) {
140 const std::string fullLabel = "Skia_" + fLabel;
141 this->setBackendLabel(fullLabel.c_str());
142 }
143 }
virtual void setBackendLabel(char const *label)
Definition: Resource.h:229

◆ sharedContext()

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

Definition at line 189 of file Resource.h.

189{ 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 }
void unref() const
Definition: Resource.h:53

◆ wasDestroyed()

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

Definition at line 154 of file Resource.h.

154{ return fSharedContext == nullptr; }

Friends And Related Function Documentation

◆ ProxyCache

friend class ProxyCache
friend

Definition at line 205 of file Resource.h.


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