Flutter Engine
The Flutter Engine
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 21 of file VulkanMemory.cpp.

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

◆ 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 51 of file VulkanMemory.cpp.

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

◆ FlushMappedAlloc()

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

Definition at line 138 of file VulkanMemory.cpp.

142 {
143 if (alloc.fFlags & VulkanAlloc::kNoncoherent_Flag) {
144 SkASSERT(offset == 0);
145 SkASSERT(size <= alloc.fSize);
147 VkResult result = allocator->flushMemory(alloc.fBackendMemory, offset, size);
148 checkResult(result);
149 }
150}
#define SkASSERT(cond)
Definition: SkAssert.h:116
virtual VkResult flushMemory(const skgpu::VulkanBackendMemory &memory, VkDeviceSize offset, VkDeviceSize size)
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
SeparatedVector2 offset
VkDeviceSize fSize
Definition: VulkanTypes.h:41
VulkanBackendMemory fBackendMemory
Definition: VulkanTypes.h:44

◆ FreeBufferMemory()

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

Definition at line 46 of file VulkanMemory.cpp.

46 {
48 allocator->freeMemory(alloc.fBackendMemory);
49}
virtual void freeMemory(const skgpu::VulkanBackendMemory &)=0

◆ FreeImageMemory()

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

Definition at line 88 of file VulkanMemory.cpp.

89 {
91 allocator->freeMemory(alloc.fBackendMemory);
92}

◆ GetNonCoherentMappedMemoryRange()

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

Definition at line 113 of file VulkanMemory.cpp.

117 {
118 SkASSERT(alloc.fFlags & VulkanAlloc::kNoncoherent_Flag);
119 offset = offset + alloc.fOffset;
120 VkDeviceSize offsetDiff = offset & (alignment -1);
121 offset = offset - offsetDiff;
122 size = (size + alignment - 1) & ~(alignment - 1);
123#ifdef SK_DEBUG
124 SkASSERT(offset >= alloc.fOffset);
125 SkASSERT(offset + size <= alloc.fOffset + alloc.fSize);
126 SkASSERT(0 == (offset & (alignment-1)));
127 SkASSERT(size > 0);
128 SkASSERT(0 == (size & (alignment-1)));
129#endif
130
131 std::memset(range, 0, sizeof(VkMappedMemoryRange));
133 range->memory = alloc.fMemory;
134 range->offset = offset;
135 range->size = size;
136}
VkDeviceSize offset
Definition: vulkan_core.h:3298
VkDeviceMemory memory
Definition: vulkan_core.h:3297
VkDeviceSize size
Definition: vulkan_core.h:3299
VkStructureType sType
Definition: vulkan_core.h:3295
VkDeviceMemory fMemory
Definition: VulkanTypes.h:39
VkDeviceSize fOffset
Definition: VulkanTypes.h:40
uint64_t VkDeviceSize
Definition: vulkan_core.h:96
@ VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE
Definition: vulkan_core.h:208

◆ InvalidateMappedAlloc()

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

Definition at line 152 of file VulkanMemory.cpp.

156 {
157 if (alloc.fFlags & VulkanAlloc::kNoncoherent_Flag) {
158 SkASSERT(offset == 0);
159 SkASSERT(size <= alloc.fSize);
162 checkResult(result);
163 }
164}
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 94 of file VulkanMemory.cpp.

96 {
97 SkASSERT(VulkanAlloc::kMappable_Flag & alloc.fFlags);
99 void* mapPtr;
100 VkResult result = allocator->mapMemory(alloc.fBackendMemory, &mapPtr);
101 if (!checkResult(result)) {
102 return nullptr;
103 }
104 return mapPtr;
105}
virtual void * mapMemory(const skgpu::VulkanBackendMemory &)

◆ UnmapAlloc()

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

Definition at line 107 of file VulkanMemory.cpp.

108 {
110 allocator->unmapMemory(alloc.fBackendMemory);
111}
virtual void unmapMemory(const skgpu::VulkanBackendMemory &)=0