With my latest sessions on my VulkanApp lua experiment I'm finally starting to get back on rails with my vulkan 3D engine π, and in the last post, we ended with a nice first triangle display, yeepee!
In this session, we will introduce the support for the Vulkan Memory Allocator library in our project, as managing the device memory is going to be a serious pain otherwise.
D:/Projects/NervLand/sources/nvVulkan/vma\vk_mem_alloc.h:17132:5: warning: pointer is missing a nullability type specifier (_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness] VkBuffer* pBuffer, ^ D:/Projects/NervLand/sources/nvVulkan/vma\vk_mem_alloc.h:17132:5: note: insert '_Nullable' if the pointer may be null VkBuffer* pBuffer, ^ _Nullable D:/Projects/NervLand/sources/nvVulkan/vma\vk_mem_alloc.h:17132:5: note: insert '_Nonnull' if the pointer should never be null VkBuffer* pBuffer, ^
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Wnullability-completeness" #define VMA_IMPLEMENTATION #include <vk_mem_alloc.h> #pragma clang diagnostic pop
#ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wnullability-completeness" #endif #define VMA_IMPLEMENTATION #include <vk_mem_alloc.h> #ifdef __clang__ #pragma clang diagnostic pop #endif
auto* pdev = get_physical_device(); VmaAllocatorCreateInfo vmainfo{}; vmainfo.flags = 0; vmainfo.physicalDevice = pdev->getVk(); vmainfo.device = _device; vmainfo.instance = pdev->get_instance()->getVk(); vmainfo.vulkanApiVersion = VK_API_VERSION_1_3; logDEBUG("Creating VMA allocator..."); CHECK_VK_MSG(vmaCreateAllocator(&vmainfo, &_allocator), "Cannot create VMA allocator.");
2022-11-04 20:12:55.771051 [DEBUG] Creating VMA allocator... Assertion failed: m_VulkanFunctions.vkGetInstanceProcAddr && m_VulkanFunctions.vkGetDeviceProcAddr && "To use VMA_DYNAMIC_VULKAN_FUNCTIONS in new versions of VMA you now have to pass " "VmaVulkanFunctions::vkGetInstanceProcAddr and vkGetDeviceProcAddr as VmaAllocatorCreateInfo::pVulkanFunctions. " "Other members can be null.", file D:/Projects/NervLand/sources/nvVulkan/vma\vk_mem_alloc.h, line 14334
// Init the VmaAllocator: // cf. // https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/struct_vma_allocator_create_info.html auto* pdev = get_physical_device(); auto* eng = VulkanEngine::instance(); VmaAllocatorCreateInfo vmainfo{}; VmaVulkanFunctions vkfuncs{}; vkfuncs.vkGetInstanceProcAddr = eng->vkGetInstanceProcAddr; vkfuncs.vkGetDeviceProcAddr = inst->vkGetDeviceProcAddr; vmainfo.flags = 0; vmainfo.physicalDevice = pdev->getVk(); vmainfo.device = _device; vmainfo.instance = inst->getVk(); vmainfo.vulkanApiVersion = VK_API_VERSION_1_3; vmainfo.pVulkanFunctions = &vkfuncs; logTRACE("Creating VMA allocator..."); CHECK_VK_MSG(vmaCreateAllocator(&vmainfo, &_allocator), "Cannot create VMA allocator.");
#define VMA_STATIC_VULKAN_FUNCTIONS 0 #define VMA_DYNAMIC_VULKAN_FUNCTIONS 1 #include <vk_mem_alloc.h>
// Use the VMA allocator to create this resource: VmaAllocationCreateInfo allocInfo = {}; allocInfo.usage = VMA_MEMORY_USAGE_AUTO; auto* allocator = _device->get_vma_allocator(); CHECK_VK_MSG(vmaCreateImage(allocator, &image_create_info, &allocInfo, &_image, &_allocation, nullptr), "Cannot create image");
local depthImg = self.vkeng:create_image_2d(self.width, self.height, vk.Format.D32_SFLOAT, vk.ImageUsageFlagBits.DEPTH_STENCIL_ATTACHMENT_BIT) -- logDEBUG("Depth image idx: ", depthImg) -- self:allocate_image_memory(depthImg)
// Use the VMA allocator to create this resource: VmaAllocationCreateInfo allocInfo = {}; allocInfo.usage = VMA_MEMORY_USAGE_AUTO; auto* allocator = _device->get_vma_allocator(); CHECK_VK_MSG(vmaCreateBuffer(allocator, &buffer_create_info, &allocInfo, &_buffer, &_allocation, nullptr), "Cannot create buffer");