fixing rendering issues

This commit is contained in:
Kbz-8
2023-11-14 07:07:43 +01:00
parent d29cd56044
commit ad60a17da9
25 changed files with 171 additions and 117 deletions

View File

@@ -6,7 +6,7 @@
/* By: kbz_8 <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/20 22:02:37 by kbz_8 #+# #+# */
/* Updated: 2023/11/10 23:29:56 by maldavid ### ########.fr */
/* Updated: 2023/11/14 06:25:19 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -28,6 +28,7 @@
#endif
#include <renderer/core/render_core.h>
#include <fstream>
namespace mlx
{
@@ -65,44 +66,52 @@ namespace mlx
allocatorCreateInfo.pVulkanFunctions = &vma_vulkan_func;
if(vmaCreateAllocator(&allocatorCreateInfo, &_allocator) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create allocator");
core::error::report(e_kind::fatal_error, "Vulkan : failed to create graphics memory 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, VmaAllocationInfo& allocinfo) noexcept
VmaAllocation GPUallocator::createBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer, const char* name) 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");
if(name != nullptr)
vmaSetAllocationName(_allocator, allocation, name);
#ifdef DEBUG
core::error::report(e_kind::message, "Graphics Allocator : created new buffer");
#endif
vmaGetAllocationInfo(_allocator, allocation, &allocinfo);
return allocation;
}
void GPUallocator::destroyBuffer(VmaAllocation allocation, VkBuffer buffer) noexcept
{
vmaDestroyBuffer(_allocator, buffer, allocation);
#ifdef DEBUG
core::error::report(e_kind::message, "Graphics Allocator : destroyed buffer");
#endif
}
VmaAllocation GPUallocator::createImage(const VkImageCreateInfo* iminfo, const VmaAllocationCreateInfo* vinfo, VkImage& image, VmaAllocationInfo& allocinfo) noexcept
VmaAllocation GPUallocator::createImage(const VkImageCreateInfo* iminfo, const VmaAllocationCreateInfo* vinfo, VkImage& image, const char* name) 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");
if(name != nullptr)
vmaSetAllocationName(_allocator, allocation, name);
#ifdef DEBUG
core::error::report(e_kind::message, "Graphics Allocator : created new image");
#endif
vmaGetAllocationInfo(_allocator, allocation, &allocinfo);
return allocation;
}
void GPUallocator::destroyImage(VmaAllocation allocation, VkImage image) noexcept
{
vmaDestroyImage(_allocator, image, allocation);
#ifdef DEBUG
core::error::report(e_kind::message, "Graphics Allocator : destroyed image");
#endif
}
void GPUallocator::mapMemory(VmaAllocation allocation, void** data) noexcept
@@ -115,6 +124,25 @@ namespace mlx
{
vmaUnmapMemory(_allocator, allocation);
}
void GPUallocator::dumpMemoryToJson()
{
static uint32_t id = 0;
std::string name("memory_dump");
name.append(std::to_string(id) + ".json");
std::ofstream file(name);
if(!file.is_open())
{
core::error::report(e_kind::error, "Graphics allocator : unable to dump memory to a json file");
return;
}
char* str = nullptr;
vmaBuildStatsString(_allocator, &str, true);
file << str;
vmaFreeStatsString(_allocator, str);
file.close();
id++;
}
void GPUallocator::flush(VmaAllocation allocation, VkDeviceSize size, VkDeviceSize offset) noexcept
{

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/20 02:13:03 by maldavid #+# #+# */
/* Updated: 2023/11/10 08:14:06 by maldavid ### ########.fr */
/* Updated: 2023/11/14 03:12:59 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -27,15 +27,17 @@ namespace mlx
void init() noexcept;
void destroy() noexcept;
VmaAllocation createBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer, VmaAllocationInfo& allocinfo) noexcept;
VmaAllocation createBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer, const char* name = nullptr) noexcept;
void destroyBuffer(VmaAllocation allocation, VkBuffer buffer) noexcept;
VmaAllocation createImage(const VkImageCreateInfo* iminfo, const VmaAllocationCreateInfo* vinfo, VkImage& image, VmaAllocationInfo& allocinfo) noexcept;
VmaAllocation createImage(const VkImageCreateInfo* iminfo, const VmaAllocationCreateInfo* vinfo, VkImage& image, const char* name = nullptr) noexcept;
void destroyImage(VmaAllocation allocation, VkImage image) noexcept;
void mapMemory(VmaAllocation allocation, void** data) noexcept;
void unmapMemory(VmaAllocation allocation) noexcept;
void dumpMemoryToJson();
void flush(VmaAllocation allocation, VkDeviceSize size, VkDeviceSize offset) noexcept;
~GPUallocator() = default;

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:16:32 by maldavid #+# #+# */
/* Updated: 2023/10/21 00:04:39 by kbz_8 ### ########.fr */
/* Updated: 2023/11/14 05:00:44 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -40,7 +40,7 @@ namespace mlx
const std::vector<const char*> validationLayers = { "VK_LAYER_KHRONOS_validation" };
constexpr const int MAX_FRAMES_IN_FLIGHT = 2;
constexpr const int MAX_FRAMES_IN_FLIGHT = 3;
class Render_Core : public Singleton<Render_Core>
{

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 19:14:29 by maldavid #+# #+# */
/* Updated: 2023/11/11 02:14:58 by maldavid ### ########.fr */
/* Updated: 2023/11/11 10:38:01 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -101,9 +101,9 @@ namespace mlx
if(_physicalDevice == VK_NULL_HANDLE)
core::error::report(e_kind::fatal_error, "Vulkan : failed to find a suitable GPU");
VkPhysicalDeviceProperties props;
vkGetPhysicalDeviceProperties(_physicalDevice, &props);
#ifdef DEBUG
VkPhysicalDeviceProperties props;
vkGetPhysicalDeviceProperties(_physicalDevice, &props);
core::error::report(e_kind::message, "Vulkan : picked a physical device, %s", props.deviceName);
#endif
}