| 126 | } |
| 127 | |
| 128 | VkResult VkTestMemoryAllocator::allocateBufferMemory(VkBuffer buffer, |
| 129 | BufferUsage usage, |
| 130 | uint32_t allocationPropertyFlags, |
| 131 | skgpu::VulkanBackendMemory* backendMemory) { |
| 132 | TRACE_EVENT0("skia.gpu", TRACE_FUNC); |
| 133 | VmaAllocationCreateInfo info; |
| 134 | info.flags = 0; |
| 135 | info.usage = VMA_MEMORY_USAGE_UNKNOWN; |
| 136 | info.memoryTypeBits = 0; |
| 137 | info.pool = VK_NULL_HANDLE; |
| 138 | info.pUserData = nullptr; |
| 139 | |
| 140 | switch (usage) { |
| 141 | case BufferUsage::kGpuOnly: |
| 142 | info.requiredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
| 143 | info.preferredFlags = 0; |
| 144 | break; |
| 145 | case BufferUsage::kCpuWritesGpuReads: |
| 146 | // When doing cpu writes and gpu reads the general rule of thumb is to use coherent |
| 147 | // memory. Though this depends on the fact that we are not doing any cpu reads and the |
| 148 | // cpu writes are sequential. For sparse writes we'd want cpu cached memory, however we |
| 149 | // don't do these types of writes in Skia. |
| 150 | // |
| 151 | // TODO: In the future there may be times where specific types of memory could benefit |
| 152 | // from a coherent and cached memory. Typically these allow for the gpu to read cpu |
| 153 | // writes from the cache without needing to flush the writes throughout the cache. The |
| 154 | // reverse is not true and GPU writes tend to invalidate the cache regardless. Also |
| 155 | // these gpu cache read access are typically lower bandwidth than non-cached memory. |
| 156 | // For now Skia doesn't really have a need or want of this type of memory. But if we |
| 157 | // ever do we could pass in an AllocationPropertyFlag that requests the cached property. |
| 158 | info.requiredFlags = |
| 159 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; |
| 160 | info.preferredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; |
| 161 | break; |
| 162 | case BufferUsage::kTransfersFromCpuToGpu: |
| 163 | info.requiredFlags = |
| 164 | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; |
| 165 | info.preferredFlags = 0; |
| 166 | break; |
| 167 | case BufferUsage::kTransfersFromGpuToCpu: |
| 168 | info.requiredFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
| 169 | info.preferredFlags = VK_MEMORY_PROPERTY_HOST_CACHED_BIT; |
| 170 | break; |
| 171 | } |
| 172 | |
| 173 | if (kDedicatedAllocation_AllocationPropertyFlag & allocationPropertyFlags) { |
| 174 | info.flags |= VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT; |
| 175 | } |
| 176 | if ((kLazyAllocation_AllocationPropertyFlag & allocationPropertyFlags) && |
| 177 | BufferUsage::kGpuOnly == usage) { |
| 178 | info.preferredFlags |= VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT; |
| 179 | } |
| 180 | |
| 181 | if (kPersistentlyMapped_AllocationPropertyFlag & allocationPropertyFlags) { |
| 182 | SkASSERT(BufferUsage::kGpuOnly != usage); |
| 183 | info.flags |= VMA_ALLOCATION_CREATE_MAPPED_BIT; |
| 184 | } |
| 185 |
nothing calls this directly
no test coverage detected