mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-12 07:03:34 +00:00
adding debug messages to renderer, working on VMA implementation
This commit is contained in:
103
src/renderer/core/memory.cpp
git.filemode.normal_file
103
src/renderer/core/memory.cpp
git.filemode.normal_file
@@ -0,0 +1,103 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* memory.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kbz_8 <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/20 22:02:37 by kbz_8 #+# #+# */
|
||||
/* Updated: 2023/11/08 22:31:27 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#define VMA_STATIC_VULKAN_FUNCTIONS 0
|
||||
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0
|
||||
#define VMA_VULKAN_VERSION 1002000
|
||||
#include <renderer/core/memory.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void GPUallocator::init() noexcept
|
||||
{
|
||||
VmaVulkanFunctions vma_vulkan_func{};
|
||||
vma_vulkan_func.vkAllocateMemory = vkAllocateMemory;
|
||||
vma_vulkan_func.vkBindBufferMemory = vkBindBufferMemory;
|
||||
vma_vulkan_func.vkBindImageMemory = vkBindImageMemory;
|
||||
vma_vulkan_func.vkCreateBuffer = vkCreateBuffer;
|
||||
vma_vulkan_func.vkCreateImage = vkCreateImage;
|
||||
vma_vulkan_func.vkDestroyBuffer = vkDestroyBuffer;
|
||||
vma_vulkan_func.vkDestroyImage = vkDestroyImage;
|
||||
vma_vulkan_func.vkFlushMappedMemoryRanges = vkFlushMappedMemoryRanges;
|
||||
vma_vulkan_func.vkFreeMemory = vkFreeMemory;
|
||||
vma_vulkan_func.vkGetBufferMemoryRequirements = vkGetBufferMemoryRequirements;
|
||||
vma_vulkan_func.vkGetImageMemoryRequirements = vkGetImageMemoryRequirements;
|
||||
vma_vulkan_func.vkGetPhysicalDeviceMemoryProperties = vkGetPhysicalDeviceMemoryProperties;
|
||||
vma_vulkan_func.vkGetPhysicalDeviceProperties = vkGetPhysicalDeviceProperties;
|
||||
vma_vulkan_func.vkInvalidateMappedMemoryRanges = vkInvalidateMappedMemoryRanges;
|
||||
vma_vulkan_func.vkMapMemory = vkMapMemory;
|
||||
vma_vulkan_func.vkUnmapMemory = vkUnmapMemory;
|
||||
vma_vulkan_func.vkCmdCopyBuffer = vkCmdCopyBuffer;
|
||||
|
||||
VmaAllocatorCreateInfo allocatorCreateInfo{};
|
||||
allocatorCreateInfo.vulkanApiVersion = VK_API_VERSION_1_2;
|
||||
allocatorCreateInfo.physicalDevice = Render_Core::get().getDevice().getPhysicalDevice();
|
||||
allocatorCreateInfo.device = Render_Core::get().getDevice().get();
|
||||
allocatorCreateInfo.instance = Render_Core::get().getInstance().get();
|
||||
allocatorCreateInfo.pVulkanFunctions = &vma_vulkan_func;
|
||||
|
||||
if(vmaCreateAllocator(&allocatorCreateInfo, &_allocator) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create allocator");
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Vulkan : created new allocator");
|
||||
#endif
|
||||
}
|
||||
|
||||
VmaAllocation GPUallocator::createBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer) noexcept
|
||||
{
|
||||
VmaAllocation allocation;
|
||||
if(vmaCreateBuffer(_allocator, binfo, vinfo, &buffer, &allocation, nullptr) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate a buffer");
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Graphics Allocator : created new buffer");
|
||||
#endif
|
||||
return allocation;
|
||||
}
|
||||
|
||||
void GPUallocator::destroyBuffer(VmaAllocation allocation, VkBuffer buffer) noexcept
|
||||
{
|
||||
vmaDestroyBuffer(_allocator, buffer, allocation);
|
||||
}
|
||||
|
||||
VmaAllocation GPUallocator::createImage(const VkImageCreateInfo* iminfo, const VmaAllocationCreateInfo* vinfo, VkImage& image) noexcept
|
||||
{
|
||||
VmaAllocation allocation;
|
||||
if(vmaCreateImage(_allocator, iminfo, vinfo, &image, &allocation, nullptr) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate an image");
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Graphics Allocator : created new image");
|
||||
#endif
|
||||
return allocation;
|
||||
}
|
||||
|
||||
void GPUallocator::destroyImage(VmaAllocation allocation, VkImage image) noexcept
|
||||
{
|
||||
vmaDestroyImage(_allocator, image, allocation);
|
||||
}
|
||||
|
||||
void GPUallocator::mapMemory(VmaAllocation allocation, void** data) noexcept
|
||||
{
|
||||
if(vmaMapMemory(_allocator, allocation, data) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Graphics allocator : unable to map GPU memory to CPU memory");
|
||||
}
|
||||
|
||||
void GPUallocator::unmapMemory(VmaAllocation allocation) noexcept
|
||||
{
|
||||
vmaUnmapMemory(_allocator, allocation);
|
||||
}
|
||||
|
||||
void GPUallocator::destroy() noexcept
|
||||
{
|
||||
vmaDestroyAllocator(_allocator);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user