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

#include <VulkanBuffer.h>

Inheritance diagram for skgpu::graphite::VulkanBuffer:
skgpu::graphite::Buffer skgpu::graphite::Resource

Public Member Functions

void freeGpuData () override
 
VkBuffer vkBuffer () const
 
VkBufferUsageFlags bufferUsageFlags () const
 
void setBufferAccess (VulkanCommandBuffer *buffer, VkAccessFlags dstAccessMask, VkPipelineStageFlags dstStageMask) const
 
- Public Member Functions inherited from skgpu::graphite::Buffer
size_t size () const
 
void * map ()
 
void asyncMap (GpuFinishedProc=nullptr, GpuFinishedContext=nullptr)
 
void unmap ()
 
bool isMapped () const
 
virtual bool isUnmappable () const
 
const char * getResourceType () const override
 
- Public Member Functions inherited from skgpu::graphite::Resource
 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)
 

Static Public Member Functions

static sk_sp< BufferMake (const VulkanSharedContext *, size_t, BufferType, AccessPattern)
 

Additional Inherited Members

- Protected Member Functions inherited from skgpu::graphite::Buffer
 Buffer (const SharedContext *sharedContext, size_t size, bool commandBufferRefsAsUsageRefs=false)
 
- Protected Member Functions inherited from skgpu::graphite::Resource
 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 ()
 
- Protected Attributes inherited from skgpu::graphite::Buffer
void * fMapPtr = nullptr
 

Detailed Description

Definition at line 19 of file VulkanBuffer.h.

Member Function Documentation

◆ bufferUsageFlags()

VkBufferUsageFlags skgpu::graphite::VulkanBuffer::bufferUsageFlags ( ) const
inline

Definition at line 24 of file VulkanBuffer.h.

24{ return fBufferUsageFlags; }

◆ freeGpuData()

void skgpu::graphite::VulkanBuffer::freeGpuData ( )
overridevirtual

Implements skgpu::graphite::Resource.

Definition at line 158 of file VulkanBuffer.cpp.

158 {
159 if (fMapPtr) {
160 this->internalUnmap(0, this->size());
161 fMapPtr = nullptr;
162 }
163
164 const VulkanSharedContext* sharedContext =
165 static_cast<const VulkanSharedContext*>(this->sharedContext());
166 SkASSERT(fBuffer);
167 SkASSERT(fAlloc.fMemory && fAlloc.fBackendMemory);
168 VULKAN_CALL(sharedContext->interface(),
169 DestroyBuffer(sharedContext->device(), fBuffer, nullptr));
170 fBuffer = VK_NULL_HANDLE;
171
172 skgpu::VulkanMemory::FreeBufferMemory(sharedContext->memoryAllocator(), fAlloc);
173 fAlloc.fMemory = VK_NULL_HANDLE;
174 fAlloc.fBackendMemory = 0;
175}
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define VULKAN_CALL(IFACE, X)
size_t size() const
Definition: Buffer.h:19
const SharedContext * sharedContext() const
Definition: Resource.h:189
void FreeBufferMemory(VulkanMemoryAllocator *, const VulkanAlloc &alloc)
VulkanBackendMemory fBackendMemory
Definition: VulkanTypes.h:44
VkDeviceMemory fMemory
Definition: VulkanTypes.h:39
#define VK_NULL_HANDLE
Definition: vulkan_core.h:46

◆ Make()

sk_sp< Buffer > skgpu::graphite::VulkanBuffer::Make ( const VulkanSharedContext sharedContext,
size_t  size,
BufferType  type,
AccessPattern  accessPattern 
)
static

Definition at line 17 of file VulkanBuffer.cpp.

20 {
21 if (size <= 0) {
22 return nullptr;
23 }
24 VkBuffer buffer;
26
27 // The only time we don't require mappable buffers is when we're on a device where gpu only
28 // memory has faster reads on the gpu than memory that is also mappable on the cpu. Protected
29 // memory always uses mappable buffers.
30 bool requiresMappable = sharedContext->isProtected() == Protected::kYes ||
31 accessPattern == AccessPattern::kHostVisible ||
32 !sharedContext->vulkanCaps().gpuOnlyBuffersMorePerformant();
33
35
36 // The default usage captures use cases besides transfer buffers. GPU-only buffers are preferred
37 // unless mappability is required.
38 BufferUsage allocUsage =
40
41 // Create the buffer object
42 VkBufferCreateInfo bufInfo;
43 memset(&bufInfo, 0, sizeof(VkBufferCreateInfo));
45 bufInfo.flags = 0;
46 bufInfo.size = size;
47
48 // To support SkMesh buffer updates we make Vertex and Index buffers capable of being transfer
49 // dsts. To support rtAdjust uniform buffer updates, we make host-visible uniform buffers also
50 // capable of being transfer dsts.
51 switch (type) {
54 break;
57 break;
60 break;
62 bufInfo.usage =
64 break;
67 break;
70 break;
74 break;
78 break;
82 break;
83 }
84
85 // We may not always get a mappable buffer for non-dynamic access buffers. Thus we set the
86 // transfer dst usage bit in case we need to do a copy to write data. It doesn't really hurt
87 // to set this extra usage flag, but we could narrow the scope of buffers we set it on more than
88 // just not dynamic.
89 if (!requiresMappable || accessPattern == AccessPattern::kGpuOnly) {
91 }
92
94 bufInfo.queueFamilyIndexCount = 0;
95 bufInfo.pQueueFamilyIndices = nullptr;
96
99 result,
100 CreateBuffer(sharedContext->device(),
101 &bufInfo,
102 nullptr, /*const VkAllocationCallbacks*/
103 &buffer));
104 if (result != VK_SUCCESS) {
105 return nullptr;
106 }
107
108 auto allocator = sharedContext->memoryAllocator();
109 bool shouldPersistentlyMapCpuToGpu =
110 sharedContext->vulkanCaps().shouldPersistentlyMapCpuToGpuBuffers();
111 //AllocBufferMemory
112 auto checkResult = [](VkResult result) {
113 return result == VK_SUCCESS;
114 };
116 buffer,
117 allocUsage,
118 shouldPersistentlyMapCpuToGpu,
119 checkResult,
120 &alloc)) {
121 VULKAN_CALL(sharedContext->interface(), DestroyBuffer(sharedContext->device(),
122 buffer,
123 /*const VkAllocationCallbacks*=*/nullptr));
124 return nullptr;
125 }
126
127 // Bind buffer
130 result,
131 BindBufferMemory(sharedContext->device(), buffer, alloc.fMemory, alloc.fOffset));
132 if (result != VK_SUCCESS) {
134 VULKAN_CALL(sharedContext->interface(), DestroyBuffer(sharedContext->device(),
135 buffer,
136 /*const VkAllocationCallbacks*=*/nullptr));
137 return nullptr;
138 }
139
140 return sk_sp<Buffer>(new VulkanBuffer(
141 sharedContext, size, type, accessPattern, std::move(buffer), alloc, bufInfo.usage));
142}
#define VULKAN_CALL_RESULT(SHARED_CONTEXT, RESULT, X)
GLenum type
GAsyncResult * result
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
bool AllocBufferMemory(VulkanMemoryAllocator *, VkBuffer buffer, skgpu::VulkanMemoryAllocator::BufferUsage, bool shouldPersistentlyMapCpuToGpu, const std::function< CheckResult > &, VulkanAlloc *alloc)
VulkanMemoryAllocator::BufferUsage BufferUsage
VkDeviceSize size
Definition: vulkan_core.h:3416
uint32_t queueFamilyIndexCount
Definition: vulkan_core.h:3419
const uint32_t * pQueueFamilyIndices
Definition: vulkan_core.h:3420
VkBufferCreateFlags flags
Definition: vulkan_core.h:3415
VkStructureType sType
Definition: vulkan_core.h:3413
VkBufferUsageFlags usage
Definition: vulkan_core.h:3417
VkSharingMode sharingMode
Definition: vulkan_core.h:3418
VkDeviceSize fOffset
Definition: VulkanTypes.h:40
@ VK_SHARING_MODE_EXCLUSIVE
Definition: vulkan_core.h:1813
@ VK_BUFFER_USAGE_TRANSFER_DST_BIT
Definition: vulkan_core.h:2546
@ VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT
Definition: vulkan_core.h:2553
@ VK_BUFFER_USAGE_INDEX_BUFFER_BIT
Definition: vulkan_core.h:2551
@ VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT
Definition: vulkan_core.h:2549
@ VK_BUFFER_USAGE_VERTEX_BUFFER_BIT
Definition: vulkan_core.h:2552
@ VK_BUFFER_USAGE_STORAGE_BUFFER_BIT
Definition: vulkan_core.h:2550
@ VK_BUFFER_USAGE_TRANSFER_SRC_BIT
Definition: vulkan_core.h:2545
VkResult
Definition: vulkan_core.h:140
@ VK_SUCCESS
Definition: vulkan_core.h:141
@ VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
Definition: vulkan_core.h:214

◆ setBufferAccess()

void skgpu::graphite::VulkanBuffer::setBufferAccess ( VulkanCommandBuffer buffer,
VkAccessFlags  dstAccessMask,
VkPipelineStageFlags  dstStageMask 
) const

Definition at line 254 of file VulkanBuffer.cpp.

256 {
257 // TODO: fill out other cases where we need a barrier
258 if (dstAccessMask == VK_ACCESS_HOST_READ_BIT ||
259 dstAccessMask == VK_ACCESS_TRANSFER_WRITE_BIT ||
260 dstAccessMask == VK_ACCESS_UNIFORM_READ_BIT) {
261 VkPipelineStageFlags srcStageMask =
262 VulkanBuffer::AccessMaskToPipelineSrcStageFlags(fCurrentAccessMask);
263
264 VkBufferMemoryBarrier bufferMemoryBarrier = {
266 nullptr, // pNext
267 fCurrentAccessMask, // srcAccessMask
268 dstAccessMask, // dstAccessMask
269 VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex
270 VK_QUEUE_FAMILY_IGNORED, // dstQueueFamilyIndex
271 fBuffer, // buffer
272 0, // offset
273 this->size(), // size
274 };
275 cmdBuffer->addBufferMemoryBarrier(srcStageMask, dstStageMask, &bufferMemoryBarrier);
276 }
277
278 fCurrentAccessMask = dstAccessMask;
279}
VkFlags VkPipelineStageFlags
Definition: vulkan_core.h:2470
@ VK_ACCESS_HOST_READ_BIT
Definition: vulkan_core.h:2213
@ VK_ACCESS_TRANSFER_WRITE_BIT
Definition: vulkan_core.h:2212
@ VK_ACCESS_UNIFORM_READ_BIT
Definition: vulkan_core.h:2203
#define VK_QUEUE_FAMILY_IGNORED
Definition: vulkan_core.h:127
@ VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER
Definition: vulkan_core.h:246

◆ vkBuffer()

VkBuffer skgpu::graphite::VulkanBuffer::vkBuffer ( ) const
inline

Definition at line 23 of file VulkanBuffer.h.

23{ return fBuffer; }

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