1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113

gpu / vulkan / vma_wrapper.h [blame]

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GPU_VULKAN_VMA_WRAPPER_H_
#define GPU_VULKAN_VMA_WRAPPER_H_

#include <algorithm>

#include <vulkan/vulkan_core.h>

#include "base/component_export.h"
#include "ui/gfx/extension_set.h"

VK_DEFINE_HANDLE(VmaAllocator)
VK_DEFINE_HANDLE(VmaAllocation)

struct VmaAllocationCreateInfo;
struct VmaAllocationInfo;
struct VmaBudget;

namespace gpu {
namespace vma {

COMPONENT_EXPORT(VULKAN)
VkResult CreateAllocator(VkPhysicalDevice physical_device,
                         VkDevice device,
                         VkInstance instance,
                         const gfx::ExtensionSet& enabled_extensions,
                         const VkDeviceSize preferred_large_heap_block_size,
                         const VkDeviceSize* heap_size_limit,
                         const bool is_thread_safe,
                         VmaAllocator* allocator);

COMPONENT_EXPORT(VULKAN) void DestroyAllocator(VmaAllocator allocator);

COMPONENT_EXPORT(VULKAN)
VkResult AllocateMemoryForImage(VmaAllocator allocator,
                                VkImage image,
                                const VmaAllocationCreateInfo* create_info,
                                VmaAllocation* allocation,
                                VmaAllocationInfo* allocation_info);

COMPONENT_EXPORT(VULKAN)
VkResult AllocateMemoryForBuffer(VmaAllocator allocator,
                                 VkBuffer buffer,
                                 const VmaAllocationCreateInfo* create_info,
                                 VmaAllocation* allocation,
                                 VmaAllocationInfo* allocationInfo);

COMPONENT_EXPORT(VULKAN)
VkResult CreateBuffer(VmaAllocator allocator,
                      const VkBufferCreateInfo* buffer_create_info,
                      VkMemoryPropertyFlags required_flags,
                      VkMemoryPropertyFlags preferred_flags,
                      VkBuffer* buffer,
                      VmaAllocation* allocation);

COMPONENT_EXPORT(VULKAN)
void DestroyBuffer(VmaAllocator allocator,
                   VkBuffer buffer,
                   VmaAllocation allocation);

COMPONENT_EXPORT(VULKAN)
VkResult MapMemory(VmaAllocator allocator,
                   VmaAllocation allocation,
                   void** data);

COMPONENT_EXPORT(VULKAN)
void UnmapMemory(VmaAllocator allocator, VmaAllocation allocation);

COMPONENT_EXPORT(VULKAN)
void FreeMemory(VmaAllocator allocator, VmaAllocation allocation);

COMPONENT_EXPORT(VULKAN)
VkResult FlushAllocation(VmaAllocator allocator,
                         VmaAllocation allocation,
                         VkDeviceSize offset,
                         VkDeviceSize size);

COMPONENT_EXPORT(VULKAN)
VkResult InvalidateAllocation(VmaAllocator allocator,
                              VmaAllocation allocation,
                              VkDeviceSize offset,
                              VkDeviceSize size);

COMPONENT_EXPORT(VULKAN)
void GetAllocationInfo(VmaAllocator allocator,
                       VmaAllocation allocation,
                       VmaAllocationInfo* allocation_info);

COMPONENT_EXPORT(VULKAN)
void GetMemoryTypeProperties(VmaAllocator allocator,
                             uint32_t memory_type_index,
                             VkMemoryPropertyFlags* flags);

COMPONENT_EXPORT(VULKAN)
void GetPhysicalDeviceProperties(
    VmaAllocator allocator,
    const VkPhysicalDeviceProperties** physical_device_properties);

COMPONENT_EXPORT(VULKAN)
void GetBudget(VmaAllocator allocator, VmaBudget* budget);

// Allocated and used, respectively.
COMPONENT_EXPORT(VULKAN)
std::pair<uint64_t, uint64_t> GetTotalAllocatedAndUsedMemory(
    VmaAllocator allocator);

}  // namespace vma
}  // namespace gpu

#endif  // GPU_VULKAN_VMA_WRAPPER_H_