122 {
123 VmaAllocationCreateInfo info;
124 info.flags = 0;
125 info.usage = VMA_MEMORY_USAGE_UNKNOWN;
126 info.memoryTypeBits = 0;
127 info.pool = VK_NULL_HANDLE;
128 info.pUserData = nullptr;
129
130 switch (usage) {
131 case BufferUsage::kGpuOnly:
132 info.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
133 info.preferredFlags = 0;
134 break;
135 case BufferUsage::kCpuWritesGpuReads:
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151 info.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
152 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
153 info.preferredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
154 break;
155 case BufferUsage::kTransfersFromCpuToGpu:
156 info.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
157 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
158 info.preferredFlags = 0;
159 break;
160 case BufferUsage::kTransfersFromGpuToCpu:
161 info.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
162 info.preferredFlags = VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
163 break;
164 }
165
166 if (must_use_coherent_host_visible_memory_ &&
167 (info.requiredFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)) {
168 info.requiredFlags |= VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
169 }
170 if (kDedicatedAllocation_AllocationPropertyFlag & allocationPropertyFlags) {
171 info.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
172 }
173 if ((kLazyAllocation_AllocationPropertyFlag & allocationPropertyFlags) &&
174 BufferUsage::kGpuOnly == usage) {
175 info.preferredFlags |= VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT;
176 }
177
178 if (kPersistentlyMapped_AllocationPropertyFlag & allocationPropertyFlags) {
179 SkASSERT(BufferUsage::kGpuOnly != usage);
180 info.flags |= VMA_ALLOCATION_CREATE_MAPPED_BIT;
181 }
182
183 VmaAllocation allocation;
184 VkResult result = vmaAllocateMemoryForBuffer(allocator_, buffer, &info,
185 &allocation, nullptr);
186 if (VK_SUCCESS == result) {
187 *backendMemory = reinterpret_cast<skgpu::VulkanBackendMemory>(allocation);
188 }
189
190 return result;
191}