Add Vulkan Memory Allocator

This commit is contained in:
Benau 2022-07-11 12:58:03 +08:00
parent 0b4ebc35b9
commit 0f4a21ab6e
7 changed files with 19653 additions and 0 deletions

View File

@ -26,6 +26,7 @@ set(GE_SOURCES
src/ge_main.cpp
src/ge_texture.cpp
src/ge_dx9_texture.cpp
src/ge_vma.cpp
src/ge_vulkan_2d_renderer.cpp
src/ge_vulkan_camera_scene_node.cpp
src/ge_vulkan_command_loader.cpp

View File

@ -0,0 +1,19 @@
#ifndef HEADER_GE_VMA_HPP
#define HEADER_GE_VMA_HPP
#include "vulkan_wrapper.h"
// Remove clang warnings
#define VMA_NULLABLE
#define VMA_NOT_NULL
#if !defined(__APPLE__) || defined(DLOPEN_MOLTENVK)
#define VMA_STATIC_VULKAN_FUNCTIONS 0
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 1
#elif defined(IOS_STK)
// MoltenVK doesn't provide full 1.3 support, which will lead to linking errors
#define VMA_VULKAN_VERSION 1002000
#endif
#include "vk_mem_alloc.h"
#endif

View File

@ -6,6 +6,7 @@
#ifdef _IRR_COMPILE_WITH_VULKAN_
#include "vulkan_wrapper.h"
#include "ge_vma.hpp"
#include "SDL_video.h"
#include "../source/Irrlicht/CNullDriver.h"
@ -340,6 +341,7 @@ namespace GE
VkFormat findSupportedFormat(const std::vector<VkFormat>& candidates,
VkImageTiling tiling,
VkFormatFeatureFlags features);
VmaAllocator getVmaAllocator() const { return m_vk->allocator; }
private:
struct SwapChainSupportDetails
{
@ -381,6 +383,7 @@ namespace GE
VkDebugUtilsMessengerEXT debug;
VkSurfaceKHR surface;
VkDevice device;
VmaAllocator allocator;
VkSwapchainKHR swap_chain;
std::vector<VkImage> swap_chain_images;
std::vector<VkImageView> swap_chain_image_views;
@ -397,6 +400,7 @@ namespace GE
debug = VK_NULL_HANDLE;
surface = VK_NULL_HANDLE;
device = VK_NULL_HANDLE;
allocator = VK_NULL_HANDLE;
swap_chain = VK_NULL_HANDLE;
samplers = {{}};
render_pass = VK_NULL_HANDLE;
@ -419,6 +423,8 @@ namespace GE
vkDestroyImageView(device, image_view, NULL);
if (swap_chain != VK_NULL_HANDLE)
vkDestroySwapchainKHR(device, swap_chain, NULL);
if (allocator != VK_NULL_HANDLE)
vmaDestroyAllocator(allocator);
if (device != VK_NULL_HANDLE)
vkDestroyDevice(device, NULL);
if (surface != VK_NULL_HANDLE)

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,10 @@
#if !defined(__APPLE__) || defined(DLOPEN_MOLTENVK)
#include <glad/vulkan.h>
#define VK_API_VERSION_MAJOR(version) (((uint32_t)(version) >> 22) & 0x7FU)
#define VK_API_VERSION_MINOR(version) (((uint32_t)(version) >> 12) & 0x3FFU)
#define VK_API_VERSION_PATCH(version) ((uint32_t)(version) & 0xFFFU)
#ifdef DLOPEN_MOLTENVK
#define VK_NO_PROTOTYPES 1
#include <vk_mvk_moltenvk.h>

View File

@ -0,0 +1,2 @@
#define VMA_IMPLEMENTATION
#include "ge_vma.hpp"

View File

@ -581,6 +581,23 @@ GEVulkanDriver::GEVulkanDriver(const SIrrlichtCreationParameters& params,
}
#endif
VmaAllocatorCreateInfo allocator_create_info = {};
allocator_create_info.physicalDevice = m_physical_device;
allocator_create_info.device = m_vk->device;
allocator_create_info.instance = m_vk->instance;
#if !defined(__APPLE__) || defined(DLOPEN_MOLTENVK)
VmaVulkanFunctions vulkan_functions = {};
vulkan_functions.vkGetInstanceProcAddr = vkGetInstanceProcAddr;
vulkan_functions.vkGetDeviceProcAddr = vkGetDeviceProcAddr;
allocator_create_info.pVulkanFunctions = &vulkan_functions;
#endif
if (vmaCreateAllocator(&allocator_create_info, &m_vk->allocator) !=
VK_SUCCESS)
{
throw std::runtime_error("vmaCreateAllocator failed");
}
createSwapChain();
createSyncObjects();
createSamplers();