mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 14:43:34 +00:00
improving descriptor sets and pools management (#41)
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -12,6 +12,7 @@
|
|||||||
*.ilk
|
*.ilk
|
||||||
*.pdb
|
*.pdb
|
||||||
*.exe
|
*.exe
|
||||||
|
*vgcore
|
||||||
.gdb_history
|
.gdb_history
|
||||||
.vs/
|
.vs/
|
||||||
.xmake/
|
.xmake/
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */
|
/* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/18 15:23:35 by maldavid ### ########.fr */
|
/* Updated: 2024/01/19 05:34:23 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -28,7 +28,13 @@ int update(void* param)
|
|||||||
static int i = 0;
|
static int i = 0;
|
||||||
mlx_t* mlx = (mlx_t*)param;
|
mlx_t* mlx = (mlx_t*)param;
|
||||||
|
|
||||||
mlx_set_font_scale(mlx->mlx, mlx->win, "default", 6.f);
|
if(i == 200)
|
||||||
|
mlx_clear_window(mlx->mlx, mlx->win);
|
||||||
|
|
||||||
|
if(i >= 250)
|
||||||
|
mlx_set_font_scale(mlx->mlx, mlx->win, "default", 16.f);
|
||||||
|
else
|
||||||
|
mlx_set_font_scale(mlx->mlx, mlx->win, "default", 6.f);
|
||||||
mlx_string_put(mlx->mlx, mlx->win, 160, 120, 0xFFFF2066, "this text should be hidden");
|
mlx_string_put(mlx->mlx, mlx->win, 160, 120, 0xFFFF2066, "this text should be hidden");
|
||||||
|
|
||||||
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->logo_png, 100, 100);
|
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->logo_png, 100, 100);
|
||||||
@@ -36,6 +42,7 @@ int update(void* param)
|
|||||||
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->logo_bmp, 220, 40);
|
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->logo_bmp, 220, 40);
|
||||||
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->img, 150, 60);
|
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->img, 150, 60);
|
||||||
|
|
||||||
|
mlx_set_font(mlx->mlx, mlx->win, "default");
|
||||||
mlx_string_put(mlx->mlx, mlx->win, 20, 50, 0xFFFFFFFF, "that's a text");
|
mlx_string_put(mlx->mlx, mlx->win, 20, 50, 0xFFFFFFFF, "that's a text");
|
||||||
|
|
||||||
int color = 0;
|
int color = 0;
|
||||||
@@ -46,11 +53,7 @@ int update(void* param)
|
|||||||
color += (color < 255);
|
color += (color < 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(++i == 5000)
|
i++;
|
||||||
mlx_clear_window(mlx->mlx, mlx->win);
|
|
||||||
if(i == 7000)
|
|
||||||
mlx_set_font_scale(mlx->mlx, mlx->win, "default", 16.f);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
|
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/18 15:19:58 by maldavid ### ########.fr */
|
/* Updated: 2024/01/20 08:21:37 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <renderer/images/texture.h>
|
#include <renderer/images/texture.h>
|
||||||
#include <renderer/core/render_core.h>
|
#include <renderer/core/render_core.h>
|
||||||
#include <array>
|
|
||||||
#include <core/errors.h>
|
#include <core/errors.h>
|
||||||
#include <mlx_profile.h>
|
#include <mlx_profile.h>
|
||||||
#include <core/memory.h>
|
#include <core/memory.h>
|
||||||
@@ -31,6 +30,10 @@ namespace mlx::core
|
|||||||
if(__drop_sdl_responsability) // is case the mlx is running in a sandbox like MacroUnitTester where SDL is already init
|
if(__drop_sdl_responsability) // is case the mlx is running in a sandbox like MacroUnitTester where SDL is already init
|
||||||
return;
|
return;
|
||||||
SDL_SetMemoryFunctions(MemManager::malloc, MemManager::calloc, MemManager::realloc, MemManager::free);
|
SDL_SetMemoryFunctions(MemManager::malloc, MemManager::calloc, MemManager::realloc, MemManager::free);
|
||||||
|
|
||||||
|
/* Remove this comment if you want to prioritise Wayland over X11/XWayland, at your own risks */
|
||||||
|
//SDL_SetHint(SDL_HINT_VIDEODRIVER, "wayland,x11");
|
||||||
|
|
||||||
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0)
|
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0)
|
||||||
error::report(e_kind::fatal_error, "SDL error : unable to init all subsystems : %s", SDL_GetError());
|
error::report(e_kind::fatal_error, "SDL error : unable to init all subsystems : %s", SDL_GetError());
|
||||||
}
|
}
|
||||||
@@ -80,9 +83,17 @@ namespace mlx::core
|
|||||||
void Application::destroyTexture(void* ptr)
|
void Application::destroyTexture(void* ptr)
|
||||||
{
|
{
|
||||||
MLX_PROFILE_FUNCTION();
|
MLX_PROFILE_FUNCTION();
|
||||||
vkDeviceWaitIdle(Render_Core::get().getDevice().get()); // TODO : synchronize with another method than stopping all the GPU process
|
vkDeviceWaitIdle(Render_Core::get().getDevice().get()); // TODO : synchronize with another method than waiting for GPU to be idle
|
||||||
|
if(ptr == nullptr)
|
||||||
|
{
|
||||||
|
core::error::report(e_kind::error, "wrong texture (NULL)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
Texture* texture = static_cast<Texture*>(ptr);
|
Texture* texture = static_cast<Texture*>(ptr);
|
||||||
texture->destroy();
|
if(!texture->isInit())
|
||||||
|
core::error::report(e_kind::error, "trying to destroy a texture");
|
||||||
|
else
|
||||||
|
texture->destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::~Application()
|
Application::~Application()
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
|
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/18 15:02:06 by maldavid ### ########.fr */
|
/* Updated: 2024/01/19 05:35:38 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -228,7 +228,10 @@ extern "C"
|
|||||||
mlx::core::error::report(e_kind::error, "TTF loader : not a truetype font file '%s'", filepath);
|
mlx::core::error::report(e_kind::error, "TTF loader : not a truetype font file '%s'", filepath);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
static_cast<mlx::core::Application*>(mlx)->loadFont(win, file, 16.f);
|
if(std::strcmp(filepath, "default") == 0)
|
||||||
|
static_cast<mlx::core::Application*>(mlx)->loadFont(win, file, 6.f);
|
||||||
|
else
|
||||||
|
static_cast<mlx::core::Application*>(mlx)->loadFont(win, file, 16.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mlx_set_font_scale(void* mlx, void* win, char* filepath, float scale)
|
void mlx_set_font_scale(void* mlx, void* win, char* filepath, float scale)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/12/17 23:33:34 by maldavid #+# #+# */
|
/* Created: 2022/12/17 23:33:34 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/07 01:29:31 by maldavid ### ########.fr */
|
/* Updated: 2024/01/20 08:20:07 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -15,7 +15,6 @@
|
|||||||
#include <mlx_profile.h>
|
#include <mlx_profile.h>
|
||||||
#include <renderer/core/render_core.h>
|
#include <renderer/core/render_core.h>
|
||||||
#include <renderer/command/vk_cmd_buffer.h>
|
#include <renderer/command/vk_cmd_buffer.h>
|
||||||
#include <mutex>
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#ifdef MLX_COMPILER_MSVC
|
#ifdef MLX_COMPILER_MSVC
|
||||||
@@ -138,6 +137,7 @@ namespace mlx
|
|||||||
|
|
||||||
vkDeviceWaitIdle(_device());
|
vkDeviceWaitIdle(_device());
|
||||||
|
|
||||||
|
_pool_manager.destroyAllPools();
|
||||||
_cmd_manager.destroy();
|
_cmd_manager.destroy();
|
||||||
_allocator.destroy();
|
_allocator.destroy();
|
||||||
_device.destroy();
|
_device.destroy();
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/08 19:16:32 by maldavid #+# #+# */
|
/* Created: 2022/10/08 19:16:32 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/11 05:14:03 by maldavid ### ########.fr */
|
/* Updated: 2024/01/20 08:17:58 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -18,6 +18,8 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include <renderer/command/single_time_cmd_manager.h>
|
#include <renderer/command/single_time_cmd_manager.h>
|
||||||
|
#include <renderer/descriptors/descriptor_pool_manager.h>
|
||||||
|
#include <renderer/descriptors/vk_descriptor_pool.h>
|
||||||
#include "vk_queues.h"
|
#include "vk_queues.h"
|
||||||
#include "vk_device.h"
|
#include "vk_device.h"
|
||||||
#include "vk_instance.h"
|
#include "vk_instance.h"
|
||||||
@@ -45,6 +47,8 @@ namespace mlx
|
|||||||
const std::vector<const char*> validationLayers = { "VK_LAYER_KHRONOS_validation" };
|
const std::vector<const char*> validationLayers = { "VK_LAYER_KHRONOS_validation" };
|
||||||
|
|
||||||
constexpr const int MAX_FRAMES_IN_FLIGHT = 3;
|
constexpr const int MAX_FRAMES_IN_FLIGHT = 3;
|
||||||
|
constexpr const int MAX_SETS_PER_POOL = 512;
|
||||||
|
constexpr const int NUMBER_OF_UNIFORM_BUFFERS = 1; // change this if for wathever reason more than one uniform buffer is needed
|
||||||
|
|
||||||
class Render_Core : public Singleton<Render_Core>
|
class Render_Core : public Singleton<Render_Core>
|
||||||
{
|
{
|
||||||
@@ -62,6 +66,7 @@ namespace mlx
|
|||||||
inline ValidationLayers& getLayers() noexcept { return _layers; }
|
inline ValidationLayers& getLayers() noexcept { return _layers; }
|
||||||
inline CmdBuffer& getSingleTimeCmdBuffer() noexcept { return _cmd_manager.getCmdBuffer(); }
|
inline CmdBuffer& getSingleTimeCmdBuffer() noexcept { return _cmd_manager.getCmdBuffer(); }
|
||||||
inline SingleTimeCmdManager& getSingleTimeCmdManager() noexcept { return _cmd_manager; }
|
inline SingleTimeCmdManager& getSingleTimeCmdManager() noexcept { return _cmd_manager; }
|
||||||
|
inline DescriptorPool& getDescriptorPool() { return _pool_manager.getAvailablePool(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Render_Core() = default;
|
Render_Core() = default;
|
||||||
@@ -71,6 +76,7 @@ namespace mlx
|
|||||||
ValidationLayers _layers;
|
ValidationLayers _layers;
|
||||||
SingleTimeCmdManager _cmd_manager;
|
SingleTimeCmdManager _cmd_manager;
|
||||||
Queues _queues;
|
Queues _queues;
|
||||||
|
DescriptorPoolManager _pool_manager;
|
||||||
Device _device;
|
Device _device;
|
||||||
Instance _instance;
|
Instance _instance;
|
||||||
GPUallocator _allocator;
|
GPUallocator _allocator;
|
||||||
|
|||||||
@@ -6,12 +6,13 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/08 19:14:29 by maldavid #+# #+# */
|
/* Created: 2022/10/08 19:14:29 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/10 21:54:17 by maldavid ### ########.fr */
|
/* Updated: 2024/01/20 05:34:15 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "render_core.h"
|
#include "render_core.h"
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
@@ -84,24 +85,19 @@ namespace mlx
|
|||||||
if(SDL_Vulkan_CreateSurface(window, Render_Core::get().getInstance().get(), &surface) != SDL_TRUE)
|
if(SDL_Vulkan_CreateSurface(window, Render_Core::get().getInstance().get(), &surface) != SDL_TRUE)
|
||||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a surface to pick physical device");
|
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a surface to pick physical device");
|
||||||
|
|
||||||
std::vector<std::pair<int, VkPhysicalDevice>> devices_score;
|
std::multimap<int, VkPhysicalDevice> devices_score;
|
||||||
|
|
||||||
std::transform(devices.cbegin(), devices.cend(), std::back_inserter(devices_score), [&](VkPhysicalDevice device)
|
for(const auto& device : devices)
|
||||||
{
|
{
|
||||||
return std::make_pair(deviceScore(device, surface), device);
|
int score = deviceScore(device, surface);
|
||||||
});
|
devices_score.insert(std::make_pair(score, device));
|
||||||
|
}
|
||||||
|
|
||||||
using device_pair = std::pair<int, VkPhysicalDevice>;
|
if(devices_score.rbegin()->first > 0)
|
||||||
std::sort(devices_score.begin(), devices_score.end(), [](const device_pair& a, const device_pair& b)
|
_physicalDevice = devices_score.rbegin()->second;
|
||||||
{
|
else
|
||||||
return a.first > b.first;
|
|
||||||
});
|
|
||||||
|
|
||||||
if(devices_score.front().first > 0)
|
|
||||||
_physicalDevice = devices_score.front().second;
|
|
||||||
|
|
||||||
if(_physicalDevice == VK_NULL_HANDLE)
|
|
||||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to find a suitable GPU");
|
core::error::report(e_kind::fatal_error, "Vulkan : failed to find a suitable GPU");
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
VkPhysicalDeviceProperties props;
|
VkPhysicalDeviceProperties props;
|
||||||
vkGetPhysicalDeviceProperties(_physicalDevice, &props);
|
vkGetPhysicalDeviceProperties(_physicalDevice, &props);
|
||||||
@@ -126,6 +122,9 @@ namespace mlx
|
|||||||
if(!indices.isComplete() || !extensionsSupported || formatCount == 0)
|
if(!indices.isComplete() || !extensionsSupported || formatCount == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
VkPhysicalDeviceFeatures features;
|
||||||
|
vkGetPhysicalDeviceFeatures(device, &features);
|
||||||
|
|
||||||
int score = 0;
|
int score = 0;
|
||||||
#ifndef FORCE_INTEGRATED_GPU
|
#ifndef FORCE_INTEGRATED_GPU
|
||||||
if(props.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
|
if(props.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
|
||||||
@@ -134,6 +133,10 @@ namespace mlx
|
|||||||
if(props.deviceType != VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU)
|
if(props.deviceType != VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU)
|
||||||
return -1;
|
return -1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if(!features.geometryShader)
|
||||||
|
return -1;
|
||||||
|
|
||||||
score += props.limits.maxImageDimension2D;
|
score += props.limits.maxImageDimension2D;
|
||||||
score += props.limits.maxBoundDescriptorSets;
|
score += props.limits.maxBoundDescriptorSets;
|
||||||
return score;
|
return score;
|
||||||
|
|||||||
39
src/renderer/descriptors/descriptor_pool_manager.cpp
git.filemode.normal_file
39
src/renderer/descriptors/descriptor_pool_manager.cpp
git.filemode.normal_file
@@ -0,0 +1,39 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* descriptor_pool_manager.cpp :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/01/20 06:51:47 by maldavid #+# #+# */
|
||||||
|
/* Updated: 2024/01/20 08:18:27 by maldavid ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include <renderer/core/render_core.h>
|
||||||
|
#include <renderer/descriptors/descriptor_pool_manager.h>
|
||||||
|
|
||||||
|
namespace mlx
|
||||||
|
{
|
||||||
|
DescriptorPool& DescriptorPoolManager::getAvailablePool()
|
||||||
|
{
|
||||||
|
for(auto& pool : _pools)
|
||||||
|
{
|
||||||
|
if(pool.getNumberOfSetsAllocated() < MAX_SETS_PER_POOL)
|
||||||
|
return pool;
|
||||||
|
}
|
||||||
|
VkDescriptorPoolSize pool_sizes[] = {
|
||||||
|
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, (MAX_FRAMES_IN_FLIGHT * NUMBER_OF_UNIFORM_BUFFERS) },
|
||||||
|
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, MAX_SETS_PER_POOL - (MAX_FRAMES_IN_FLIGHT * NUMBER_OF_UNIFORM_BUFFERS) }
|
||||||
|
};
|
||||||
|
_pools.emplace_front().init((sizeof(pool_sizes) / sizeof(VkDescriptorPoolSize)), pool_sizes);
|
||||||
|
return _pools.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DescriptorPoolManager::destroyAllPools()
|
||||||
|
{
|
||||||
|
for(auto& pool : _pools)
|
||||||
|
pool.destroy();
|
||||||
|
_pools.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
36
src/renderer/descriptors/descriptor_pool_manager.h
git.filemode.normal_file
36
src/renderer/descriptors/descriptor_pool_manager.h
git.filemode.normal_file
@@ -0,0 +1,36 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* descriptor_pool_manager.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2024/01/20 06:26:26 by maldavid #+# #+# */
|
||||||
|
/* Updated: 2024/01/20 08:23:04 by maldavid ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef __MLX_DESCRIPTOR_POOL_MANAGER__
|
||||||
|
#define __MLX_DESCRIPTOR_POOL_MANAGER__
|
||||||
|
|
||||||
|
#include <renderer/descriptors/vk_descriptor_pool.h>
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
namespace mlx
|
||||||
|
{
|
||||||
|
class DescriptorPoolManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DescriptorPoolManager() = default;
|
||||||
|
|
||||||
|
DescriptorPool& getAvailablePool(); // assumes the pool is for only one set allocation, may cause some issues if this is for more than one
|
||||||
|
void destroyAllPools();
|
||||||
|
|
||||||
|
~DescriptorPoolManager() = default;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::list<DescriptorPool> _pools;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -6,11 +6,12 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/23 18:34:23 by maldavid #+# #+# */
|
/* Created: 2023/01/23 18:34:23 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/18 10:19:55 by maldavid ### ########.fr */
|
/* Updated: 2024/01/20 07:40:40 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "vk_descriptor_pool.h"
|
#include "vk_descriptor_pool.h"
|
||||||
|
#include <renderer/descriptors/vk_descriptor_set.h>
|
||||||
#include <renderer/core/render_core.h>
|
#include <renderer/core/render_core.h>
|
||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
@@ -21,17 +22,34 @@ namespace mlx
|
|||||||
poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||||
poolInfo.poolSizeCount = n;
|
poolInfo.poolSizeCount = n;
|
||||||
poolInfo.pPoolSizes = size;
|
poolInfo.pPoolSizes = size;
|
||||||
poolInfo.maxSets = 8192;
|
poolInfo.maxSets = MAX_SETS_PER_POOL;
|
||||||
poolInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
|
poolInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
|
||||||
|
|
||||||
VkResult res = vkCreateDescriptorPool(Render_Core::get().getDevice().get(), &poolInfo, nullptr, &_pool);
|
VkResult res = vkCreateDescriptorPool(Render_Core::get().getDevice().get(), &poolInfo, nullptr, &_pool);
|
||||||
if(res != VK_SUCCESS)
|
if(res != VK_SUCCESS)
|
||||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create descriptor pool, %s", RCore::verbaliseResultVk(res));
|
core::error::report(e_kind::fatal_error, "Vulkan : failed to create descriptor pool, %s", RCore::verbaliseResultVk(res));
|
||||||
|
_allocated_sets++;
|
||||||
|
#ifdef DEBUG
|
||||||
|
core::error::report(e_kind::message, "Vulkan : created new descriptor pool");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void DescriptorPool::destroy() noexcept
|
void DescriptorPool::freeDescriptor(const DescriptorSet& set)
|
||||||
{
|
{
|
||||||
vkDestroyDescriptorPool(Render_Core::get().getDevice().get(), _pool, nullptr);
|
if(!isInit())
|
||||||
|
return;
|
||||||
|
const auto& sets = set.getAllFramesDescriptorSets();
|
||||||
|
vkFreeDescriptorSets(Render_Core::get().getDevice().get(), _pool, sets.size(), sets.data());
|
||||||
|
_allocated_sets--; // if this goes in underflow I quit
|
||||||
|
}
|
||||||
|
|
||||||
|
void DescriptorPool::destroy() noexcept
|
||||||
|
{
|
||||||
|
if(_pool != VK_NULL_HANDLE)
|
||||||
|
vkDestroyDescriptorPool(Render_Core::get().getDevice().get(), _pool, nullptr);
|
||||||
_pool = VK_NULL_HANDLE;
|
_pool = VK_NULL_HANDLE;
|
||||||
|
#ifdef DEBUG
|
||||||
|
core::error::report(e_kind::message, "Vulkan : destroyed a descriptor pool");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/23 18:32:43 by maldavid #+# #+# */
|
/* Created: 2023/01/23 18:32:43 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/18 10:22:20 by maldavid ### ########.fr */
|
/* Updated: 2024/01/20 07:38:32 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -22,16 +22,23 @@ namespace mlx
|
|||||||
class DescriptorPool
|
class DescriptorPool
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
DescriptorPool() = default;
|
||||||
|
|
||||||
void init(std::size_t n, VkDescriptorPoolSize* size);
|
void init(std::size_t n, VkDescriptorPoolSize* size);
|
||||||
|
void freeDescriptor(const class DescriptorSet& set);
|
||||||
void destroy() noexcept;
|
void destroy() noexcept;
|
||||||
|
|
||||||
inline VkDescriptorPool& operator()() noexcept { return _pool; }
|
inline VkDescriptorPool& operator()() noexcept { return _pool; }
|
||||||
inline VkDescriptorPool& get() noexcept { return _pool; }
|
inline VkDescriptorPool& get() noexcept { return _pool; }
|
||||||
|
inline std::size_t getNumberOfSetsAllocated() const noexcept { return _allocated_sets; }
|
||||||
|
|
||||||
inline bool isInit() const noexcept { return _pool != VK_NULL_HANDLE; }
|
inline bool isInit() const noexcept { return _pool != VK_NULL_HANDLE; }
|
||||||
|
|
||||||
|
~DescriptorPool() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VkDescriptorPool _pool = VK_NULL_HANDLE;
|
VkDescriptorPool _pool = VK_NULL_HANDLE;
|
||||||
|
std::size_t _allocated_sets = 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/23 18:40:44 by maldavid #+# #+# */
|
/* Created: 2023/01/23 18:40:44 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/18 10:22:10 by maldavid ### ########.fr */
|
/* Updated: 2024/01/20 08:18:07 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ namespace mlx
|
|||||||
{
|
{
|
||||||
MLX_PROFILE_FUNCTION();
|
MLX_PROFILE_FUNCTION();
|
||||||
DescriptorSet set;
|
DescriptorSet set;
|
||||||
set.init(_renderer, _pool, _layout);
|
set.init(_renderer, &Render_Core::get().getDescriptorPool(), _layout);
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,8 +115,8 @@ namespace mlx
|
|||||||
void DescriptorSet::destroy() noexcept
|
void DescriptorSet::destroy() noexcept
|
||||||
{
|
{
|
||||||
MLX_PROFILE_FUNCTION();
|
MLX_PROFILE_FUNCTION();
|
||||||
if(_pool->isInit())
|
if(_pool != nullptr && Render_Core::get().isInit()) // checks if the render core is still init (it should always be init but just in case)
|
||||||
vkFreeDescriptorSets(Render_Core::get().getDevice().get(), _pool->get(), _desc_set.size(), _desc_set.data());
|
_pool->freeDescriptor(*this);
|
||||||
for(auto& set : _desc_set)
|
for(auto& set : _desc_set)
|
||||||
{
|
{
|
||||||
if(set != VK_NULL_HANDLE)
|
if(set != VK_NULL_HANDLE)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/23 18:39:36 by maldavid #+# #+# */
|
/* Created: 2023/01/23 18:39:36 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/18 10:13:25 by maldavid ### ########.fr */
|
/* Updated: 2024/01/20 07:17:39 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -23,6 +23,8 @@ namespace mlx
|
|||||||
class DescriptorSet
|
class DescriptorSet
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
DescriptorSet() = default;
|
||||||
|
|
||||||
void init(class Renderer* renderer, class DescriptorPool* pool, class DescriptorSetLayout* layout);
|
void init(class Renderer* renderer, class DescriptorPool* pool, class DescriptorSetLayout* layout);
|
||||||
|
|
||||||
void writeDescriptor(int binding, class UBO* ubo) const noexcept;
|
void writeDescriptor(int binding, class UBO* ubo) const noexcept;
|
||||||
@@ -35,8 +37,12 @@ namespace mlx
|
|||||||
VkDescriptorSet& operator()() noexcept;
|
VkDescriptorSet& operator()() noexcept;
|
||||||
VkDescriptorSet& get() noexcept;
|
VkDescriptorSet& get() noexcept;
|
||||||
|
|
||||||
|
inline const std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT>& getAllFramesDescriptorSets() const { return _desc_set; }
|
||||||
|
|
||||||
void destroy() noexcept;
|
void destroy() noexcept;
|
||||||
|
|
||||||
|
~DescriptorSet() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT> _desc_set;
|
std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT> _desc_set;
|
||||||
class DescriptorPool* _pool = nullptr;
|
class DescriptorPool* _pool = nullptr;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/23 18:36:22 by maldavid #+# #+# */
|
/* Created: 2023/01/23 18:36:22 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/03 15:27:55 by maldavid ### ########.fr */
|
/* Updated: 2024/01/20 06:25:54 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -15,15 +15,15 @@
|
|||||||
|
|
||||||
#include <mlx_profile.h>
|
#include <mlx_profile.h>
|
||||||
#include <volk.h>
|
#include <volk.h>
|
||||||
#include <cstddef>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
|
||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
class DescriptorSetLayout
|
class DescriptorSetLayout
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
DescriptorSetLayout() = default;
|
||||||
|
|
||||||
void init(std::vector<std::pair<int, VkDescriptorType>> binds, VkShaderStageFlagBits stage);
|
void init(std::vector<std::pair<int, VkDescriptorType>> binds, VkShaderStageFlagBits stage);
|
||||||
void destroy() noexcept;
|
void destroy() noexcept;
|
||||||
|
|
||||||
@@ -31,6 +31,8 @@ namespace mlx
|
|||||||
inline VkDescriptorSetLayout& get() noexcept { return _layout; }
|
inline VkDescriptorSetLayout& get() noexcept { return _layout; }
|
||||||
inline const std::vector<std::pair<int, VkDescriptorType>>& getBindings() const noexcept { return _bindings; }
|
inline const std::vector<std::pair<int, VkDescriptorType>>& getBindings() const noexcept { return _bindings; }
|
||||||
|
|
||||||
|
~DescriptorSetLayout() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VkDescriptorSetLayout _layout = VK_NULL_HANDLE;
|
VkDescriptorSetLayout _layout = VK_NULL_HANDLE;
|
||||||
std::vector<std::pair<int, VkDescriptorType>> _bindings;
|
std::vector<std::pair<int, VkDescriptorType>> _bindings;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/25 11:54:21 by maldavid #+# #+# */
|
/* Created: 2023/01/25 11:54:21 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/07 01:20:31 by maldavid ### ########.fr */
|
/* Updated: 2024/01/19 06:10:15 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -15,8 +15,6 @@
|
|||||||
|
|
||||||
#include <mlx_profile.h>
|
#include <mlx_profile.h>
|
||||||
#include <volk.h>
|
#include <volk.h>
|
||||||
#include <cstddef>
|
|
||||||
#include <vector>
|
|
||||||
#include <vma.h>
|
#include <vma.h>
|
||||||
#include <renderer/core/cmd_resource.h>
|
#include <renderer/core/cmd_resource.h>
|
||||||
#include <renderer/command/vk_cmd_buffer.h>
|
#include <renderer/command/vk_cmd_buffer.h>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/12/18 17:25:16 by maldavid #+# #+# */
|
/* Created: 2022/12/18 17:25:16 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/16 08:02:57 by maldavid ### ########.fr */
|
/* Updated: 2024/01/20 08:19:46 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -47,12 +47,6 @@ namespace mlx
|
|||||||
_uniform_buffer->create(this, sizeof(glm::mat4), nullptr);
|
_uniform_buffer->create(this, sizeof(glm::mat4), nullptr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
VkDescriptorPoolSize pool_sizes[] = {
|
|
||||||
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 4096 },
|
|
||||||
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 4096 }
|
|
||||||
};
|
|
||||||
_desc_pool.init(2, pool_sizes);
|
|
||||||
|
|
||||||
_vert_layout.init({
|
_vert_layout.init({
|
||||||
{0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER}
|
{0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER}
|
||||||
}, VK_SHADER_STAGE_VERTEX_BIT);
|
}, VK_SHADER_STAGE_VERTEX_BIT);
|
||||||
@@ -60,8 +54,8 @@ namespace mlx
|
|||||||
{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER}
|
{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER}
|
||||||
}, VK_SHADER_STAGE_FRAGMENT_BIT);
|
}, VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||||
|
|
||||||
_vert_set.init(this, &_desc_pool, &_vert_layout);
|
_vert_set.init(this, &Render_Core::get().getDescriptorPool(), &_vert_layout);
|
||||||
_frag_set.init(this, &_desc_pool, &_frag_layout);
|
_frag_set.init(this, &Render_Core::get().getDescriptorPool(), &_frag_layout);
|
||||||
|
|
||||||
_vert_set.writeDescriptor(0, _uniform_buffer.get());
|
_vert_set.writeDescriptor(0, _uniform_buffer.get());
|
||||||
|
|
||||||
@@ -179,8 +173,9 @@ namespace mlx
|
|||||||
_uniform_buffer->destroy();
|
_uniform_buffer->destroy();
|
||||||
_vert_layout.destroy();
|
_vert_layout.destroy();
|
||||||
_frag_layout.destroy();
|
_frag_layout.destroy();
|
||||||
|
_frag_set.destroy();
|
||||||
|
_vert_set.destroy();
|
||||||
_cmd.destroy();
|
_cmd.destroy();
|
||||||
_desc_pool.destroy();
|
|
||||||
_pass.destroy();
|
_pass.destroy();
|
||||||
if(_render_target == nullptr)
|
if(_render_target == nullptr)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/12/18 17:14:45 by maldavid #+# #+# */
|
/* Created: 2022/12/18 17:14:45 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/16 08:01:25 by maldavid ### ########.fr */
|
/* Updated: 2024/01/20 08:18:53 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -125,8 +125,6 @@ namespace mlx
|
|||||||
std::array<Semaphore, MAX_FRAMES_IN_FLIGHT> _semaphores;
|
std::array<Semaphore, MAX_FRAMES_IN_FLIGHT> _semaphores;
|
||||||
std::vector<FrameBuffer> _framebuffers;
|
std::vector<FrameBuffer> _framebuffers;
|
||||||
|
|
||||||
DescriptorPool _desc_pool;
|
|
||||||
|
|
||||||
DescriptorSetLayout _vert_layout;
|
DescriptorSetLayout _vert_layout;
|
||||||
DescriptorSetLayout _frag_layout;
|
DescriptorSetLayout _frag_layout;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user