Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Typedefs | Functions
skgpu::VulkanMemory Namespace Reference

Typedefs

using CheckResult = bool(VkResult)
 

Functions

bool AllocBufferMemory (VulkanMemoryAllocator *, VkBuffer buffer, skgpu::VulkanMemoryAllocator::BufferUsage, bool shouldPersistentlyMapCpuToGpu, const std::function< CheckResult > &, VulkanAlloc *alloc)
 
void FreeBufferMemory (VulkanMemoryAllocator *, const VulkanAlloc &alloc)
 
bool AllocImageMemory (VulkanMemoryAllocator *, VkImage image, skgpu::Protected isProtected, bool forceDedicatedMemory, bool useLazyAllocation, const std::function< CheckResult > &, VulkanAlloc *alloc)
 
void FreeImageMemory (VulkanMemoryAllocator *, const VulkanAlloc &alloc)
 
void * MapAlloc (VulkanMemoryAllocator *, const VulkanAlloc &, const std::function< CheckResult > &)
 
void UnmapAlloc (VulkanMemoryAllocator *, const VulkanAlloc &alloc)
 
void FlushMappedAlloc (VulkanMemoryAllocator *, const skgpu::VulkanAlloc &, VkDeviceSize offset, VkDeviceSize size, const std::function< CheckResult > &)
 
void InvalidateMappedAlloc (VulkanMemoryAllocator *, const VulkanAlloc &alloc, VkDeviceSize offset, VkDeviceSize size, const std::function< CheckResult > &)
 
void GetNonCoherentMappedMemoryRange (const VulkanAlloc &, VkDeviceSize offset, VkDeviceSize size, VkDeviceSize alignment, VkMappedMemoryRange *)
 

Typedef Documentation

◆ CheckResult

Definition at line 21 of file VulkanMemory.h.

Function Documentation

◆ AllocBufferMemory()

bool skgpu::VulkanMemory::AllocBufferMemory ( VulkanMemoryAllocator allocator,
VkBuffer  buffer,
skgpu::VulkanMemoryAllocator::BufferUsage  usage,
bool  shouldPersistentlyMapCpuToGpu,
const std::function< CheckResult > &  checkResult,
VulkanAlloc alloc 
)

Definition at line 16 of file VulkanMemory.cpp.

21 {
22 VulkanBackendMemory memory = 0;
23 uint32_t propFlags;
24 if (usage == BufferUsage::kTransfersFromCpuToGpu ||
25 (usage == BufferUsage::kCpuWritesGpuReads && shouldPersistentlyMapCpuToGpu)) {
26 // In general it is always fine (and often better) to keep buffers always mapped that we are
27 // writing to on the cpu.
28 propFlags = VulkanMemoryAllocator::kPersistentlyMapped_AllocationPropertyFlag;
29 } else {
30 propFlags = VulkanMemoryAllocator::kNone_AllocationPropertyFlag;
31 }
32
33 VkResult result = allocator->allocateBufferMemory(buffer, usage, propFlags, &memory);
34 if (!checkResult(result)) {
35 return false;
36 }
37 allocator->getAllocInfo(memory, alloc);
38 return true;
39}
virtual VkResult allocateBufferMemory(VkBuffer buffer, BufferUsage usage, uint32_t allocationPropertyFlags, skgpu::VulkanBackendMemory *memory)=0
virtual void getAllocInfo(const skgpu::VulkanBackendMemory &, skgpu::VulkanAlloc *) const =0
static const uint8_t buffer[]
GAsyncResult * result
intptr_t VulkanBackendMemory
Definition VulkanTypes.h:31
static void usage(char *argv0)
VkResult

◆ AllocImageMemory()

bool skgpu::VulkanMemory::AllocImageMemory ( VulkanMemoryAllocator allocator,
VkImage  image,
skgpu::Protected  isProtected,
bool  forceDedicatedMemory,
bool  useLazyAllocation,
const std::function< CheckResult > &  checkResult,
VulkanAlloc alloc 
)

Definition at line 46 of file VulkanMemory.cpp.

52 {
53 VulkanBackendMemory memory = 0;
54
55 uint32_t propFlags;
56 // If we ever find that our allocator is not aggressive enough in using dedicated image
57 // memory we can add a size check here to force the use of dedicate memory. However for now,
58 // we let the allocators decide. The allocator can query the GPU for each image to see if the
59 // GPU recommends or requires the use of dedicated memory.
60 if (forceDedicatedMemory) {
61 propFlags = VulkanMemoryAllocator::kDedicatedAllocation_AllocationPropertyFlag;
62 } else {
63 propFlags = VulkanMemoryAllocator::kNone_AllocationPropertyFlag;
64 }
65
66 if (isProtected == Protected::kYes) {
67 propFlags = propFlags | VulkanMemoryAllocator::kProtected_AllocationPropertyFlag;
68 }
69
70 if (useLazyAllocation) {
71 propFlags = propFlags | VulkanMemoryAllocator::kLazyAllocation_AllocationPropertyFlag;
72 }
73
74 VkResult result = allocator->allocateImageMemory(image, propFlags, &memory);
75 if (!checkResult(result)) {
76 return false;
77 }
78
79 allocator->getAllocInfo(memory, alloc);
80 return true;
81}
virtual VkResult allocateImageMemory(VkImage image, uint32_t allocationPropertyFlags, skgpu::VulkanBackendMemory *memory)=0
sk_sp< SkImage > image
Definition examples.cpp:29

◆ FlushMappedAlloc()

void skgpu::VulkanMemory::FlushMappedAlloc ( VulkanMemoryAllocator allocator,
const skgpu::VulkanAlloc alloc,
VkDeviceSize  offset,
VkDeviceSize  size,
const std::function< CheckResult > &  checkResult 
)

Definition at line 133 of file VulkanMemory.cpp.

137 {
138 if (alloc.fFlags & VulkanAlloc::kNoncoherent_Flag) {
139 SkASSERT(offset == 0);
140 SkASSERT(size <= alloc.fSize);
142 VkResult result = allocator->flushMemory(alloc.fBackendMemory, offset, size);
143 checkResult(result);
144 }
145}
#define SkASSERT(cond)
Definition SkAssert.h:116
virtual VkResult flushMemory(const skgpu::VulkanBackendMemory &memory, VkDeviceSize offset, VkDeviceSize size)
Point offset
VkDeviceSize fSize
Definition VulkanTypes.h:40
VulkanBackendMemory fBackendMemory
Definition VulkanTypes.h:43

◆ FreeBufferMemory()

void skgpu::VulkanMemory::FreeBufferMemory ( VulkanMemoryAllocator allocator,
const VulkanAlloc alloc 
)

Definition at line 41 of file VulkanMemory.cpp.

41 {
43 allocator->freeMemory(alloc.fBackendMemory);
44}
virtual void freeMemory(const skgpu::VulkanBackendMemory &)=0

◆ FreeImageMemory()

void skgpu::VulkanMemory::FreeImageMemory ( VulkanMemoryAllocator allocator,
const VulkanAlloc alloc 
)

Definition at line 83 of file VulkanMemory.cpp.

84 {
86 allocator->freeMemory(alloc.fBackendMemory);
87}

◆ GetNonCoherentMappedMemoryRange()

void skgpu::VulkanMemory::GetNonCoherentMappedMemoryRange ( const VulkanAlloc alloc,
VkDeviceSize  offset,
VkDeviceSize  size,
VkDeviceSize  alignment,
VkMappedMemoryRange range 
)

Definition at line 108 of file VulkanMemory.cpp.

112 {
113 SkASSERT(alloc.fFlags & VulkanAlloc::kNoncoherent_Flag);
114 offset = offset + alloc.fOffset;
115 VkDeviceSize offsetDiff = offset & (alignment -1);
116 offset = offset - offsetDiff;
117 size = (size + alignment - 1) & ~(alignment - 1);
118#ifdef SK_DEBUG
119 SkASSERT(offset >= alloc.fOffset);
120 SkASSERT(offset + size <= alloc.fOffset + alloc.fSize);
121 SkASSERT(0 == (offset & (alignment-1)));
122 SkASSERT(size > 0);
123 SkASSERT(0 == (size & (alignment-1)));
124#endif
125
126 memset(range, 0, sizeof(VkMappedMemoryRange));
128 range->memory = alloc.fMemory;
129 range->offset = offset;
130 range->size = size;
131}
VkDeviceSize offset
VkDeviceMemory memory
VkStructureType sType
VkDeviceMemory fMemory
Definition VulkanTypes.h:38
VkDeviceSize fOffset
Definition VulkanTypes.h:39
uint64_t VkDeviceSize
Definition vulkan_core.h:96
@ VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE

◆ InvalidateMappedAlloc()

void skgpu::VulkanMemory::InvalidateMappedAlloc ( VulkanMemoryAllocator allocator,
const VulkanAlloc alloc,
VkDeviceSize  offset,
VkDeviceSize  size,
const std::function< CheckResult > &  checkResult 
)

Definition at line 147 of file VulkanMemory.cpp.

151 {
152 if (alloc.fFlags & VulkanAlloc::kNoncoherent_Flag) {
153 SkASSERT(offset == 0);
154 SkASSERT(size <= alloc.fSize);
156 VkResult result = allocator->invalidateMemory(alloc.fBackendMemory, offset, size);
157 checkResult(result);
158 }
159}
virtual VkResult invalidateMemory(const skgpu::VulkanBackendMemory &memory, VkDeviceSize offset, VkDeviceSize size)

◆ MapAlloc()

void * skgpu::VulkanMemory::MapAlloc ( VulkanMemoryAllocator allocator,
const VulkanAlloc alloc,
const std::function< CheckResult > &  checkResult 
)

Definition at line 89 of file VulkanMemory.cpp.

91 {
92 SkASSERT(VulkanAlloc::kMappable_Flag & alloc.fFlags);
94 void* mapPtr;
95 VkResult result = allocator->mapMemory(alloc.fBackendMemory, &mapPtr);
96 if (!checkResult(result)) {
97 return nullptr;
98 }
99 return mapPtr;
100}
virtual void * mapMemory(const skgpu::VulkanBackendMemory &)

◆ UnmapAlloc()

void skgpu::VulkanMemory::UnmapAlloc ( VulkanMemoryAllocator allocator,
const VulkanAlloc alloc 
)

Definition at line 102 of file VulkanMemory.cpp.

103 {
105 allocator->unmapMemory(alloc.fBackendMemory);
106}
virtual void unmapMemory(const skgpu::VulkanBackendMemory &)=0