Add Vulkan Memory Allocator
This commit is contained in:
parent
0b4ebc35b9
commit
0f4a21ab6e
@ -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
|
||||
|
19
lib/graphics_engine/include/ge_vma.hpp
Normal file
19
lib/graphics_engine/include/ge_vma.hpp
Normal 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
|
@ -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)
|
||||
|
19604
lib/graphics_engine/include/vk_mem_alloc.h
Normal file
19604
lib/graphics_engine/include/vk_mem_alloc.h
Normal file
File diff suppressed because it is too large
Load Diff
@ -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>
|
||||
|
2
lib/graphics_engine/src/ge_vma.cpp
Normal file
2
lib/graphics_engine/src/ge_vma.cpp
Normal file
@ -0,0 +1,2 @@
|
||||
#define VMA_IMPLEMENTATION
|
||||
#include "ge_vma.hpp"
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user