Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
GrVkBuffer Class Reference

#include <GrVkBuffer.h>

Inheritance diagram for GrVkBuffer:
GrGpuBuffer GrGpuResource GrBuffer GrIORef< GrGpuResource > SkNoncopyable

Public Member Functions

VkBuffer vkBuffer () const
 
void addMemoryBarrier (VkAccessFlags srcAccessMask, VkAccessFlags dstAccesMask, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, bool byRegion) const
 
const VkDescriptorSet * uniformDescriptorSet () const
 
- Public Member Functions inherited from GrGpuBuffer
GrAccessPattern accessPattern () const
 
size_t size () const final
 
void ref () const final
 
void unref () const final
 
void * map ()
 
void unmap ()
 
bool isMapped () const
 
bool isCpuBuffer () const final
 
bool clearToZero ()
 
bool updateData (const void *src, size_t offset, size_t size, bool preserve)
 
GrGpuBufferType intendedType () const
 
- Public Member Functions inherited from GrGpuResource
bool wasDestroyed () const
 
const GrDirectContextgetContext () const
 
GrDirectContextgetContext ()
 
size_t gpuMemorySize () const
 
UniqueID uniqueID () const
 
const skgpu::UniqueKeygetUniqueKey () const
 
std::string getLabel () const
 
void setLabel (std::string_view label)
 
CacheAccess cacheAccess ()
 
const CacheAccess cacheAccess () const
 
ProxyAccess proxyAccess ()
 
ResourcePriv resourcePriv ()
 
const ResourcePriv resourcePriv () const
 
virtual void dumpMemoryStatistics (SkTraceMemoryDump *traceMemoryDump) const
 
virtual const char * getResourceType () const =0
 
- Public Member Functions inherited from GrIORef< GrGpuResource >
bool unique () const
 
void ref () const
 
void unref () const
 
void refCommandBuffer () const
 
void unrefCommandBuffer () const
 
- Public Member Functions inherited from SkNoncopyable
 SkNoncopyable ()=default
 
 SkNoncopyable (SkNoncopyable &&)=default
 
SkNoncopyableoperator= (SkNoncopyable &&)=default
 
- Public Member Functions inherited from GrBuffer
 GrBuffer (const GrBuffer &)=delete
 
GrBufferoperator= (const GrBuffer &)=delete
 
virtual ~GrBuffer ()=default
 
virtual void ref () const =0
 
virtual void unref () const =0
 
virtual size_t size () const =0
 
virtual bool isCpuBuffer () const =0
 

Static Public Member Functions

static sk_sp< GrVkBufferMake (GrVkGpu *gpu, size_t size, GrGpuBufferType bufferType, GrAccessPattern accessPattern)
 
- Static Public Member Functions inherited from GrGpuBuffer
static void ComputeScratchKeyForDynamicBuffer (size_t size, GrGpuBufferType, skgpu::ScratchKey *)
 
- Static Public Member Functions inherited from GrGpuResource
static uint32_t CreateUniqueID ()
 

Additional Inherited Members

- Public Types inherited from GrIORef< GrGpuResource >
enum  LastRemovedRef
 
- Protected Types inherited from GrGpuBuffer
enum class  MapType { kRead , kWriteDiscard }
 
- Protected Member Functions inherited from GrGpuBuffer
 GrGpuBuffer (GrGpu *, size_t sizeInBytes, GrGpuBufferType, GrAccessPattern, std::string_view label)
 
- Protected Member Functions inherited from GrGpuResource
void registerWithCache (skgpu::Budgeted)
 
void registerWithCacheWrapped (GrWrapCacheable)
 
 GrGpuResource (GrGpu *, std::string_view label)
 
virtual ~GrGpuResource ()
 
GrGpugetGpu () const
 
virtual void onRelease ()
 
virtual void onAbandon ()
 
virtual void setMemoryBacking (SkTraceMemoryDump *, const SkString &) const
 
SkString getResourceName () const
 
void dumpMemoryStatisticsPriv (SkTraceMemoryDump *traceMemoryDump, const SkString &resourceName, const char *type, size_t size) const
 
- Protected Member Functions inherited from GrIORef< GrGpuResource >
 GrIORef ()
 
bool internalHasRef () const
 
bool internalHasNoCommandBufferUsages () const
 
void addInitialRef () const
 
- Protected Member Functions inherited from GrBuffer
 GrBuffer ()=default
 
- Protected Attributes inherited from GrGpuBuffer
void * fMapPtr
 

Detailed Description

Definition at line 17 of file GrVkBuffer.h.

Member Function Documentation

◆ addMemoryBarrier()

void GrVkBuffer::addMemoryBarrier ( VkAccessFlags  srcAccessMask,
VkAccessFlags  dstAccesMask,
VkPipelineStageFlags  srcStageMask,
VkPipelineStageFlags  dstStageMask,
bool  byRegion 
) const

Definition at line 270 of file GrVkBuffer.cpp.

274 {
275 VkBufferMemoryBarrier bufferMemoryBarrier = {
277 nullptr, // pNext
278 srcAccessMask, // srcAccessMask
279 dstAccesMask, // dstAccessMask
280 VK_QUEUE_FAMILY_IGNORED, // srcQueueFamilyIndex
281 VK_QUEUE_FAMILY_IGNORED, // dstQueueFamilyIndex
282 fBuffer, // buffer
283 0, // offset
284 this->size(), // size
285 };
286
287 // TODO: restrict to area of buffer we're interested in
288 this->getVkGpu()->addBufferMemoryBarrier(srcStageMask, dstStageMask, byRegion,
289 &bufferMemoryBarrier);
290}
size_t size() const final
Definition: GrGpuBuffer.h:34
void addBufferMemoryBarrier(const GrManagedResource *, VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, bool byRegion, VkBufferMemoryBarrier *barrier) const
Definition: GrVkGpu.cpp:2127
#define VK_QUEUE_FAMILY_IGNORED
Definition: vulkan_core.h:127
@ VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER
Definition: vulkan_core.h:246

◆ Make()

sk_sp< GrVkBuffer > GrVkBuffer::Make ( GrVkGpu gpu,
size_t  size,
GrGpuBufferType  bufferType,
GrAccessPattern  accessPattern 
)
static

Definition at line 69 of file GrVkBuffer.cpp.

72 {
73 VkBuffer buffer;
75
76 // The only time we don't require mappable buffers is when we have a static access pattern and
77 // we're on a device where gpu only memory has faster reads on the gpu than memory that is also
78 // mappable on the cpu. Protected memory always uses mappable buffers.
79 bool requiresMappable = gpu->protectedContext() ||
83
85 BufferUsage allocUsage;
86
87 // create the buffer object
88 VkBufferCreateInfo bufInfo;
89 memset(&bufInfo, 0, sizeof(VkBufferCreateInfo));
91 bufInfo.flags = 0;
92 bufInfo.size = size;
93 // To support SkMesh buffer updates we make Vertex and Index buffers capable of being transfer
94 // dsts.
95 switch (bufferType) {
98 allocUsage = requiresMappable ? BufferUsage::kCpuWritesGpuReads : BufferUsage::kGpuOnly;
99 break;
102 allocUsage = requiresMappable ? BufferUsage::kCpuWritesGpuReads : BufferUsage::kGpuOnly;
103 break;
106 allocUsage = requiresMappable ? BufferUsage::kCpuWritesGpuReads : BufferUsage::kGpuOnly;
107 break;
110 allocUsage = BufferUsage::kCpuWritesGpuReads;
111 break;
114 allocUsage = BufferUsage::kTransfersFromCpuToGpu;
115 break;
118 allocUsage = BufferUsage::kTransfersFromGpuToCpu;
119 break;
120 }
121 // We may not always get a mappable buffer for non dynamic access buffers. Thus we set the
122 // transfer dst usage bit in case we need to do a copy to write data.
123 // TODO: It doesn't really hurt setting this extra usage flag, but maybe we can narrow the scope
124 // of buffers we set it on more than just not dynamic.
125 if (!requiresMappable) {
127 }
128
130 bufInfo.queueFamilyIndexCount = 0;
131 bufInfo.pQueueFamilyIndices = nullptr;
132
133 VkResult err;
134 err = VK_CALL(gpu, CreateBuffer(gpu->device(), &bufInfo, nullptr, &buffer));
135 if (err) {
136 return nullptr;
137 }
138
139 bool shouldPersistentlyMapCpuToGpu = gpu->vkCaps().shouldPersistentlyMapCpuToGpuBuffers();
140 auto checkResult = [gpu, allocUsage, shouldPersistentlyMapCpuToGpu](VkResult result) {
141 GR_VK_LOG_IF_NOT_SUCCESS(gpu, result, "skgpu::VulkanMemory::AllocBufferMemory "
142 "(allocUsage:%d, shouldPersistentlyMapCpuToGpu:%d)",
143 (int)allocUsage, (int)shouldPersistentlyMapCpuToGpu);
144 return gpu->checkVkResult(result);
145 };
146 auto allocator = gpu->memoryAllocator();
148 buffer,
149 allocUsage,
150 shouldPersistentlyMapCpuToGpu,
151 checkResult,
152 &alloc)) {
153 VK_CALL(gpu, DestroyBuffer(gpu->device(), buffer, nullptr));
154 return nullptr;
155 }
156
157 // Bind buffer
158 GR_VK_CALL_RESULT(gpu, err, BindBufferMemory(gpu->device(),
159 buffer,
160 alloc.fMemory,
161 alloc.fOffset));
162 if (err) {
164 VK_CALL(gpu, DestroyBuffer(gpu->device(), buffer, nullptr));
165 return nullptr;
166 }
167
168 // If this is a uniform buffer we must setup a descriptor set
169 const GrVkDescriptorSet* uniformDescSet = nullptr;
170 if (bufferType == GrGpuBufferType::kUniform) {
171 uniformDescSet = make_uniform_desc_set(gpu, buffer, size);
172 if (!uniformDescSet) {
173 VK_CALL(gpu, DestroyBuffer(gpu->device(), buffer, nullptr));
175 return nullptr;
176 }
177 }
178
179 return sk_sp<GrVkBuffer>(new GrVkBuffer(
180 gpu, size, bufferType, accessPattern, buffer, alloc, uniformDescSet,
181 /*label=*/"MakeVkBuffer"));
182}
@ kDynamic_GrAccessPattern
Definition: GrTypesPriv.h:426
@ kStream_GrAccessPattern
Definition: GrTypesPriv.h:430
#define VK_CALL(GPU, X)
Definition: GrVkBuffer.cpp:19
static const GrVkDescriptorSet * make_uniform_desc_set(GrVkGpu *gpu, VkBuffer buffer, size_t size)
Definition: GrVkBuffer.cpp:39
#define GR_VK_LOG_IF_NOT_SUCCESS(GPU, RESULT, X,...)
Definition: GrVkUtil.h:28
#define GR_VK_CALL_RESULT(GPU, RESULT, X)
Definition: GrVkUtil.h:35
GrAccessPattern accessPattern() const
Definition: GrGpuBuffer.h:32
bool shouldPersistentlyMapCpuToGpuBuffers() const
Definition: GrVkCaps.h:198
bool gpuOnlyBuffersMorePerformant() const
Definition: GrVkCaps.h:193
const GrVkCaps & vkCaps() const
Definition: GrVkGpu.h:61
VkDevice device() const
Definition: GrVkGpu.h:71
bool protectedContext() const
Definition: GrVkGpu.h:81
bool checkVkResult(VkResult)
Definition: GrVkGpu.cpp:2659
skgpu::VulkanMemoryAllocator * memoryAllocator() const
Definition: GrVkGpu.h:68
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
void FreeBufferMemory(VulkanMemoryAllocator *, const VulkanAlloc &alloc)
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
VkDeviceMemory fMemory
Definition: VulkanTypes.h:39
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_TRANSFER_SRC_BIT
Definition: vulkan_core.h:2545
VkResult
Definition: vulkan_core.h:140
@ VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
Definition: vulkan_core.h:214

◆ uniformDescriptorSet()

const VkDescriptorSet * GrVkBuffer::uniformDescriptorSet ( ) const

Definition at line 359 of file GrVkBuffer.cpp.

359 {
360 SkASSERT(fUniformDescriptorSet);
361 return fUniformDescriptorSet->descriptorSet();
362}
#define SkASSERT(cond)
Definition: SkAssert.h:116
const VkDescriptorSet * descriptorSet() const

◆ vkBuffer()

VkBuffer GrVkBuffer::vkBuffer ( ) const
inline

Definition at line 24 of file GrVkBuffer.h.

24{ return fBuffer; }

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