mirror of
https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git
synced 2025-05-25 05:59:16 +00:00
Updated first chapter of the documentation "Quick start"
Rebuilt the docs. Closes #228
This commit is contained in:
parent
5c710e86a0
commit
4d65f7e113
11 changed files with 142 additions and 109 deletions
include
|
@ -17943,25 +17943,15 @@ To do it properly:
|
|||
|
||||
It may be a good idea to create dedicated CPP file just for this purpose.
|
||||
|
||||
Note on language: This library is written in C++, but has C-compatible interface.
|
||||
Thus you can include and use vk_mem_alloc.h in C or C++ code, but full
|
||||
implementation with `VMA_IMPLEMENTATION` macro must be compiled as C++, NOT as C.
|
||||
|
||||
Please note that this library includes header `<vulkan/vulkan.h>`, which in turn
|
||||
This library includes header `<vulkan/vulkan.h>`, which in turn
|
||||
includes `<windows.h>` on Windows. If you need some specific macros defined
|
||||
before including these headers (like `WIN32_LEAN_AND_MEAN` or
|
||||
`WINVER` for Windows, `VK_USE_PLATFORM_WIN32_KHR` for Vulkan), you must define
|
||||
them before every `#include` of this library.
|
||||
|
||||
You may need to configure the way you import Vulkan functions.
|
||||
|
||||
- By default, VMA assumes you you link statically with Vulkan API. If this is not the case,
|
||||
`#define VMA_STATIC_VULKAN_FUNCTIONS 0` before `#include` of the VMA implementation and use another way.
|
||||
- You can `#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1` and pass only pointers to `vkGetInstanceProcAddr` and
|
||||
`vkGetDeviceProcAddr` functions through VmaAllocatorCreateInfo::pVulkanFunctions.
|
||||
All the remaining Vulkan functions will be fetched automatically.
|
||||
- Finally, you can provide your own pointers to all Vulkan functions needed by VMA using structure member
|
||||
VmaAllocatorCreateInfo::pVulkanFunctions, if you fetched them in some custom way e.g. using some loader like [Volk](https://github.com/zeux/volk).
|
||||
\note This library is written in C++, but has C-compatible interface.
|
||||
Thus you can include and use vk_mem_alloc.h in C or C++ code, but full
|
||||
implementation with `VMA_IMPLEMENTATION` macro must be compiled as C++, NOT as C.
|
||||
|
||||
|
||||
\section quick_start_initialization Initialization
|
||||
|
@ -17972,23 +17962,44 @@ At program startup:
|
|||
-# Fill VmaAllocatorCreateInfo structure and create #VmaAllocator object by
|
||||
calling vmaCreateAllocator().
|
||||
|
||||
\code
|
||||
VmaAllocatorCreateInfo allocatorInfo = {};
|
||||
allocatorInfo.vulkanApiVersion = VK_API_VERSION_1_2;
|
||||
allocatorInfo.physicalDevice = physicalDevice;
|
||||
allocatorInfo.device = device;
|
||||
allocatorInfo.instance = instance;
|
||||
|
||||
VmaAllocator allocator;
|
||||
vmaCreateAllocator(&allocatorInfo, &allocator);
|
||||
\endcode
|
||||
|
||||
Only members `physicalDevice`, `device`, `instance` are required.
|
||||
However, you should inform the library which Vulkan version do you use by setting
|
||||
VmaAllocatorCreateInfo::vulkanApiVersion and which extensions did you enable
|
||||
by setting VmaAllocatorCreateInfo::flags (like #VMA_ALLOCATOR_CREATE_BUFFER_DEVICE_ADDRESS_BIT for VK_KHR_buffer_device_address).
|
||||
Otherwise, VMA would use only features of Vulkan 1.0 core with no extensions.
|
||||
|
||||
You may need to configure importing Vulkan functions. There are 3 ways to do this:
|
||||
|
||||
-# **If you link with Vulkan static library** (e.g. "vulkan-1.lib" on Windows):
|
||||
- You don't need to do anything.
|
||||
- VMA will use these, as macro `VMA_STATIC_VULKAN_FUNCTIONS` is defined to 1 by default.
|
||||
-# **If you want VMA to fetch pointers to Vulkan functions dynamically** using `vkGetInstanceProcAddr`,
|
||||
`vkGetDeviceProcAddr` (this is the option presented in the example below):
|
||||
- Define `VMA_STATIC_VULKAN_FUNCTIONS` to 0, `VMA_DYNAMIC_VULKAN_FUNCTIONS` to 1.
|
||||
- Provide pointers to these two functions via VmaVulkanFunctions::vkGetInstanceProcAddr,
|
||||
VmaVulkanFunctions::vkGetDeviceProcAddr.
|
||||
- The library will fetch pointers to all other functions it needs internally.
|
||||
-# **If you fetch pointers to all Vulkan functions in a custom way**, e.g. using some loader like
|
||||
[Volk](https://github.com/zeux/volk):
|
||||
- Define `VMA_STATIC_VULKAN_FUNCTIONS` and `VMA_DYNAMIC_VULKAN_FUNCTIONS` to 0.
|
||||
- Pass these pointers via structure #VmaVulkanFunctions.
|
||||
|
||||
\code
|
||||
VmaVulkanFunctions vulkanFunctions = {};
|
||||
vulkanFunctions.vkGetInstanceProcAddr = &vkGetInstanceProcAddr;
|
||||
vulkanFunctions.vkGetDeviceProcAddr = &vkGetDeviceProcAddr;
|
||||
|
||||
VmaAllocatorCreateInfo allocatorCreateInfo = {};
|
||||
allocatorCreateInfo.vulkanApiVersion = VK_API_VERSION_1_2;
|
||||
allocatorCreateInfo.physicalDevice = physicalDevice;
|
||||
allocatorCreateInfo.device = device;
|
||||
allocatorCreateInfo.instance = instance;
|
||||
allocatorCreateInfo.pVulkanFunctions = &vulkanFunctions;
|
||||
|
||||
VmaAllocator allocator;
|
||||
vmaCreateAllocator(&allocatorCreateInfo, &allocator);
|
||||
\endcode
|
||||
|
||||
|
||||
\section quick_start_resource_allocation Resource allocation
|
||||
|
||||
|
@ -17997,7 +18008,7 @@ When you want to create a buffer or image:
|
|||
-# Fill `VkBufferCreateInfo` / `VkImageCreateInfo` structure.
|
||||
-# Fill VmaAllocationCreateInfo structure.
|
||||
-# Call vmaCreateBuffer() / vmaCreateImage() to get `VkBuffer`/`VkImage` with memory
|
||||
already allocated and bound to it.
|
||||
already allocated and bound to it, plus #VmaAllocation objects that represents its underlying memory.
|
||||
|
||||
\code
|
||||
VkBufferCreateInfo bufferInfo = { VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue