fixing compilation issues, adding profile

This commit is contained in:
2023-11-10 09:19:47 +01:00
parent 9c54cb6c68
commit 22c9e14947
13 changed files with 109 additions and 29 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@
*.a
*.so
*.out
.cache/

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
/* Updated: 2023/08/28 10:19:53 by maldavid ### ########.fr */
/* Updated: 2023/11/10 09:06:44 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -16,6 +16,7 @@
#include <array>
#include <core/errors.h>
#include <utils/endian.h>
#include <core/profile.h>
namespace mlx::core
{

60
src/core/profile.h git.filemode.normal_file
View File

@@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* profile.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/10 08:49:17 by maldavid #+# #+# */
/* Updated: 2023/11/10 09:05:56 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_PROFILE__
#define __MLX_PROFILE__
// Try to identify the compiler
#if defined(__BORLANDC__)
#define MLX_COMPILER_BORDLAND
#elif defined(__clang__)
#define MLX_COMPILER_CLANG
#ifdef __MINGW32__
#define MLX_COMPILER_MINGW
#ifdef __MINGW64_VERSION_MAJOR
#define MLX_COMPILER_MINGW_W64
#endif
#endif
#elif defined(__GNUC__) || defined(__MINGW32__)
#define MLX_COMPILER_GCC
#ifdef __MINGW32__
#define MLX_COMPILER_MINGW
#ifdef __MINGW64_VERSION_MAJOR
#define MLX_COMPILER_MINGW_W64
#endif
#endif
#elif defined(__INTEL_COMPILER) || defined(__ICL)
#define MLX_COMPILER_INTEL
#elif defined(_MSC_VER)
#define MLX_COMPILER_MSVC
#else
#define MLX_COMPILER_UNKNOWN
#warning "This compiler is not fully supported"
#endif
// Checking common assumptions
#include <climits>
#include <cstdint>
static_assert(CHAR_BIT == 8, "CHAR_BIT is expected to be 8");
static_assert(sizeof(int8_t) == 1, "int8_t is not of the correct size" );
static_assert(sizeof(int16_t) == 2, "int16_t is not of the correct size");
static_assert(sizeof(int32_t) == 4, "int32_t is not of the correct size");
static_assert(sizeof(int64_t) == 8, "int64_t is not of the correct size");
static_assert(sizeof(uint8_t) == 1, "uint8_t is not of the correct size" );
static_assert(sizeof(uint16_t) == 2, "uint16_t is not of the correct size");
static_assert(sizeof(uint32_t) == 4, "uint32_t is not of the correct size");
static_assert(sizeof(uint64_t) == 8, "uint64_t is not of the correct size");
#endif

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/08 18:55:57 by maldavid #+# #+# */
/* Updated: 2023/11/09 20:02:14 by maldavid ### ########.fr */
/* Updated: 2023/11/10 08:14:42 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -140,5 +140,6 @@ namespace mlx
void Buffer::flush(VkDeviceSize size, VkDeviceSize offset)
{
Render_Core::get().getAllocator().flush(_allocation, size, offset);
}
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/25 15:05:05 by maldavid #+# #+# */
/* Updated: 2023/04/22 19:51:54 by maldavid ### ########.fr */
/* Updated: 2023/11/10 07:53:26 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,7 +23,7 @@ namespace mlx
{
public:
inline void create(uint32_t size, const uint16_t* data) { Buffer::create(Buffer::kind::constant, size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, data); }
inline void bind(Renderer& renderer) noexcept { vkCmdBindIndexBuffer(renderer.getActiveCmdBuffer().get(), _buffer, _offset, VK_INDEX_TYPE_UINT16); }
inline void bind(Renderer& renderer) noexcept { vkCmdBindIndexBuffer(renderer.getActiveCmdBuffer().get(), _buffer, getOffset(), VK_INDEX_TYPE_UINT16); }
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:45:52 by maldavid #+# #+# */
/* Updated: 2023/04/22 19:51:56 by maldavid ### ########.fr */
/* Updated: 2023/11/10 07:54:48 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -50,11 +50,6 @@ namespace mlx
return _buffers[_renderer->getActiveImageIndex()].getOffset();
}
VkDeviceMemory UBO::getDeviceMemory() noexcept
{
return _buffers[_renderer->getActiveImageIndex()].getDeviceMemory();
}
VkBuffer& UBO::operator()() noexcept
{
return _buffers[_renderer->getActiveImageIndex()].get();

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:45:29 by maldavid #+# #+# */
/* Updated: 2023/04/22 19:51:59 by maldavid ### ########.fr */
/* Updated: 2023/11/10 07:54:29 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -37,7 +37,6 @@ namespace mlx
inline unsigned int getSize(int i) noexcept { return _buffers[i].getSize(); }
inline unsigned int getOffset(int i) noexcept { return _buffers[i].getOffset(); }
inline VkDeviceMemory getDeviceMemory(int i) noexcept { return _buffers[i].getDeviceMemory(); }
inline VkBuffer& operator()(int i) noexcept { return _buffers[i].get(); }
inline VkBuffer& get(int i) noexcept { return _buffers[i].get(); }

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:28:08 by maldavid #+# #+# */
/* Updated: 2022/12/19 15:38:45 by maldavid ### ########.fr */
/* Updated: 2023/11/10 08:33:52 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,8 +17,8 @@ namespace mlx
{
void VBO::setData(uint32_t size, const void* data)
{
if(size > _size)
core::error::report(e_kind::error, "Vulkan : trying to store to much data in a vertex buffer (%d bytes in %d bytes)", size, _size);
if(size > getSize())
core::error::report(e_kind::error, "Vulkan : trying to store to much data in a vertex buffer (%d bytes in %d bytes)", size, getSize());
if(data == nullptr)
core::error::report(e_kind::warning, "Vulkan : mapping null data in a vertex buffer");

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 18:27:38 by maldavid #+# #+# */
/* Updated: 2023/04/22 19:52:05 by maldavid ### ########.fr */
/* Updated: 2023/11/10 07:54:15 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -25,14 +25,14 @@ namespace mlx
void setData(uint32_t size, const void* data);
inline void bind(Renderer& renderer) noexcept { vkCmdBindVertexBuffers(renderer.getActiveCmdBuffer().get(), 0, 1, &_buffer, &_offset); }
inline void bind(Renderer& renderer) noexcept { vkCmdBindVertexBuffers(renderer.getActiveCmdBuffer().get(), 0, 1, &_buffer, &_alloc_infos.offset); }
};
class C_VBO : public Buffer
{
public:
inline void create(uint32_t size, const void* data) { Buffer::create(Buffer::kind::constant, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, data); }
inline void bind(Renderer& renderer) noexcept { vkCmdBindVertexBuffers(renderer.getActiveCmdBuffer().get(), 0, 1, &_buffer, &_offset); }
inline void bind(Renderer& renderer) noexcept { vkCmdBindVertexBuffers(renderer.getActiveCmdBuffer().get(), 0, 1, &_buffer, &_alloc_infos.offset); }
};
}

View File

@@ -6,14 +6,27 @@
/* 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 */
/* Updated: 2023/11/10 09:07:33 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <core/profile.h>
#include <cstdio>
#define VMA_STATIC_VULKAN_FUNCTIONS 0
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0
#define VMA_VULKAN_VERSION 1002000
#include <renderer/core/memory.h>
#define VMA_IMPLEMENTATION
#ifdef MLX_COMPILER_CLANG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnullability-completeness"
#include <renderer/core/memory.h>
#pragma clang diagnostic pop
#else
#include <renderer/core/memory.h>
#endif
#include <renderer/core/render_core.h>
namespace mlx
@@ -53,7 +66,7 @@ namespace mlx
#endif
}
VmaAllocation GPUallocator::createBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer) noexcept
VmaAllocation GPUallocator::createBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer, VmaAllocationInfo& allocinfo) noexcept
{
VmaAllocation allocation;
if(vmaCreateBuffer(_allocator, binfo, vinfo, &buffer, &allocation, nullptr) != VK_SUCCESS)
@@ -61,6 +74,7 @@ namespace mlx
#ifdef DEBUG
core::error::report(e_kind::message, "Graphics Allocator : created new buffer");
#endif
vmaGetAllocationInfo(_allocator, allocation, &allocinfo);
return allocation;
}
@@ -69,7 +83,7 @@ namespace mlx
vmaDestroyBuffer(_allocator, buffer, allocation);
}
VmaAllocation GPUallocator::createImage(const VkImageCreateInfo* iminfo, const VmaAllocationCreateInfo* vinfo, VkImage& image) noexcept
VmaAllocation GPUallocator::createImage(const VkImageCreateInfo* iminfo, const VmaAllocationCreateInfo* vinfo, VkImage& image, VmaAllocationInfo& allocinfo) noexcept
{
VmaAllocation allocation;
if(vmaCreateImage(_allocator, iminfo, vinfo, &image, &allocation, nullptr) != VK_SUCCESS)
@@ -77,6 +91,7 @@ namespace mlx
#ifdef DEBUG
core::error::report(e_kind::message, "Graphics Allocator : created new image");
#endif
vmaGetAllocationInfo(_allocator, allocation, &allocinfo);
return allocation;
}
@@ -95,6 +110,11 @@ namespace mlx
{
vmaUnmapMemory(_allocator, allocation);
}
void GPUallocator::flush(VmaAllocation allocation, VkDeviceSize size, VkDeviceSize offset) noexcept
{
vmaFlushAllocation(_allocator, allocation, offset, size);
}
void GPUallocator::destroy() 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/09 19:58:06 by maldavid ### ########.fr */
/* Updated: 2023/11/10 08:14:06 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -26,16 +26,18 @@ namespace mlx
void init() noexcept;
void destroy() noexcept;
VmaAllocation createBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer, VmaAllocationInfo& allocinfo) noexcept;
void destroyBuffer(VmaAllocation allocation, VkBuffer buffer) noexcept;
VmaAllocation createImage(const VkImageCreateInfo* iminfo, const VmaAllocationCreateInfo* vinfo, VkImage& image, VmaAllocationInfo& allocinfo) noexcept;
void destroyImage(VmaAllocation allocation, VkImage image) noexcept;
void mapMemory(VmaAllocation allocation, void** data) noexcept;
void unmapMemory(VmaAllocation allocation) noexcept;
void flush(VmaAllocation allocation, VkDeviceSize size, VkDeviceSize offset) noexcept;
~GPUallocator() = default;
private:

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/25 11:59:07 by maldavid #+# #+# */
/* Updated: 2023/11/09 19:35:26 by maldavid ### ########.fr */
/* Updated: 2023/11/10 08:24:11 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -43,7 +43,7 @@ namespace mlx
VmaAllocationCreateInfo alloc_info{};
alloc_info.usage = VMA_MEMORY_USAGE_GPU_ONLY;
_allocation = Render_Core::get().getAllocator().createImage(&imageInfo, &alloc_info, _image);
_allocation = Render_Core::get().getAllocator().createImage(&imageInfo, &alloc_info, _image, _alloc_infos);
_pool.init();
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/25 11:54:21 by maldavid #+# #+# */
/* Updated: 2023/11/09 19:29:54 by maldavid ### ########.fr */
/* Updated: 2023/11/10 08:23:59 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -50,6 +50,7 @@ namespace mlx
CmdBuffer _transfer_cmd;
CmdPool _pool;
VmaAllocation _allocation;
VmaAllocationInfo _alloc_infos;
VkImage _image = VK_NULL_HANDLE;
VkImageView _image_view = VK_NULL_HANDLE;
VkSampler _sampler = VK_NULL_HANDLE;