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
|
||||
*.pdb
|
||||
*.exe
|
||||
*vgcore
|
||||
.gdb_history
|
||||
.vs/
|
||||
.xmake/
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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,6 +28,12 @@ int update(void* param)
|
||||
static int i = 0;
|
||||
mlx_t* mlx = (mlx_t*)param;
|
||||
|
||||
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");
|
||||
|
||||
@@ -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->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");
|
||||
|
||||
int color = 0;
|
||||
@@ -46,11 +53,7 @@ int update(void* param)
|
||||
color += (color < 255);
|
||||
}
|
||||
|
||||
if(++i == 5000)
|
||||
mlx_clear_window(mlx->mlx, mlx->win);
|
||||
if(i == 7000)
|
||||
mlx_set_font_scale(mlx->mlx, mlx->win, "default", 16.f);
|
||||
|
||||
i++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/images/texture.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
#include <array>
|
||||
#include <core/errors.h>
|
||||
#include <mlx_profile.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
|
||||
return;
|
||||
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)
|
||||
error::report(e_kind::fatal_error, "SDL error : unable to init all subsystems : %s", SDL_GetError());
|
||||
}
|
||||
@@ -80,8 +83,16 @@ namespace mlx::core
|
||||
void Application::destroyTexture(void* ptr)
|
||||
{
|
||||
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);
|
||||
if(!texture->isInit())
|
||||
core::error::report(e_kind::error, "trying to destroy a texture");
|
||||
else
|
||||
texture->destroy();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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,6 +228,9 @@ extern "C"
|
||||
mlx::core::error::report(e_kind::error, "TTF loader : not a truetype font file '%s'", filepath);
|
||||
return;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/core/render_core.h>
|
||||
#include <renderer/command/vk_cmd_buffer.h>
|
||||
#include <mutex>
|
||||
|
||||
#ifdef DEBUG
|
||||
#ifdef MLX_COMPILER_MSVC
|
||||
@@ -138,6 +137,7 @@ namespace mlx
|
||||
|
||||
vkDeviceWaitIdle(_device());
|
||||
|
||||
_pool_manager.destroyAllPools();
|
||||
_cmd_manager.destroy();
|
||||
_allocator.destroy();
|
||||
_device.destroy();
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <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_device.h"
|
||||
#include "vk_instance.h"
|
||||
@@ -45,6 +47,8 @@ namespace mlx
|
||||
const std::vector<const char*> validationLayers = { "VK_LAYER_KHRONOS_validation" };
|
||||
|
||||
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>
|
||||
{
|
||||
@@ -62,6 +66,7 @@ namespace mlx
|
||||
inline ValidationLayers& getLayers() noexcept { return _layers; }
|
||||
inline CmdBuffer& getSingleTimeCmdBuffer() noexcept { return _cmd_manager.getCmdBuffer(); }
|
||||
inline SingleTimeCmdManager& getSingleTimeCmdManager() noexcept { return _cmd_manager; }
|
||||
inline DescriptorPool& getDescriptorPool() { return _pool_manager.getAvailablePool(); }
|
||||
|
||||
private:
|
||||
Render_Core() = default;
|
||||
@@ -71,6 +76,7 @@ namespace mlx
|
||||
ValidationLayers _layers;
|
||||
SingleTimeCmdManager _cmd_manager;
|
||||
Queues _queues;
|
||||
DescriptorPoolManager _pool_manager;
|
||||
Device _device;
|
||||
Instance _instance;
|
||||
GPUallocator _allocator;
|
||||
|
||||
@@ -6,12 +6,13 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <iterator>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <SDL2/SDL.h>
|
||||
@@ -84,24 +85,19 @@ namespace mlx
|
||||
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");
|
||||
|
||||
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>;
|
||||
std::sort(devices_score.begin(), devices_score.end(), [](const device_pair& a, const device_pair& b)
|
||||
{
|
||||
return a.first > b.first;
|
||||
});
|
||||
|
||||
if(devices_score.front().first > 0)
|
||||
_physicalDevice = devices_score.front().second;
|
||||
|
||||
if(_physicalDevice == VK_NULL_HANDLE)
|
||||
if(devices_score.rbegin()->first > 0)
|
||||
_physicalDevice = devices_score.rbegin()->second;
|
||||
else
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to find a suitable GPU");
|
||||
|
||||
#ifdef DEBUG
|
||||
VkPhysicalDeviceProperties props;
|
||||
vkGetPhysicalDeviceProperties(_physicalDevice, &props);
|
||||
@@ -126,6 +122,9 @@ namespace mlx
|
||||
if(!indices.isComplete() || !extensionsSupported || formatCount == 0)
|
||||
return -1;
|
||||
|
||||
VkPhysicalDeviceFeatures features;
|
||||
vkGetPhysicalDeviceFeatures(device, &features);
|
||||
|
||||
int score = 0;
|
||||
#ifndef FORCE_INTEGRATED_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)
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
if(!features.geometryShader)
|
||||
return -1;
|
||||
|
||||
score += props.limits.maxImageDimension2D;
|
||||
score += props.limits.maxBoundDescriptorSets;
|
||||
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> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <renderer/descriptors/vk_descriptor_set.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
|
||||
namespace mlx
|
||||
@@ -21,17 +22,34 @@ namespace mlx
|
||||
poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||
poolInfo.poolSizeCount = n;
|
||||
poolInfo.pPoolSizes = size;
|
||||
poolInfo.maxSets = 8192;
|
||||
poolInfo.maxSets = MAX_SETS_PER_POOL;
|
||||
poolInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
|
||||
|
||||
VkResult res = vkCreateDescriptorPool(Render_Core::get().getDevice().get(), &poolInfo, nullptr, &_pool);
|
||||
if(res != VK_SUCCESS)
|
||||
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::freeDescriptor(const DescriptorSet& set)
|
||||
{
|
||||
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;
|
||||
#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> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
{
|
||||
public:
|
||||
DescriptorPool() = default;
|
||||
|
||||
void init(std::size_t n, VkDescriptorPoolSize* size);
|
||||
void freeDescriptor(const class DescriptorSet& set);
|
||||
void destroy() noexcept;
|
||||
|
||||
inline VkDescriptorPool& operator()() 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; }
|
||||
|
||||
~DescriptorPool() = default;
|
||||
|
||||
private:
|
||||
VkDescriptorPool _pool = VK_NULL_HANDLE;
|
||||
std::size_t _allocated_sets = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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();
|
||||
DescriptorSet set;
|
||||
set.init(_renderer, _pool, _layout);
|
||||
set.init(_renderer, &Render_Core::get().getDescriptorPool(), _layout);
|
||||
return set;
|
||||
}
|
||||
|
||||
@@ -115,8 +115,8 @@ namespace mlx
|
||||
void DescriptorSet::destroy() noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(_pool->isInit())
|
||||
vkFreeDescriptorSets(Render_Core::get().getDevice().get(), _pool->get(), _desc_set.size(), _desc_set.data());
|
||||
if(_pool != nullptr && Render_Core::get().isInit()) // checks if the render core is still init (it should always be init but just in case)
|
||||
_pool->freeDescriptor(*this);
|
||||
for(auto& set : _desc_set)
|
||||
{
|
||||
if(set != VK_NULL_HANDLE)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
{
|
||||
public:
|
||||
DescriptorSet() = default;
|
||||
|
||||
void init(class Renderer* renderer, class DescriptorPool* pool, class DescriptorSetLayout* layout);
|
||||
|
||||
void writeDescriptor(int binding, class UBO* ubo) const noexcept;
|
||||
@@ -35,8 +37,12 @@ namespace mlx
|
||||
VkDescriptorSet& operator()() noexcept;
|
||||
VkDescriptorSet& get() noexcept;
|
||||
|
||||
inline const std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT>& getAllFramesDescriptorSets() const { return _desc_set; }
|
||||
|
||||
void destroy() noexcept;
|
||||
|
||||
~DescriptorSet() = default;
|
||||
|
||||
private:
|
||||
std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT> _desc_set;
|
||||
class DescriptorPool* _pool = nullptr;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <volk.h>
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class DescriptorSetLayout
|
||||
{
|
||||
public:
|
||||
DescriptorSetLayout() = default;
|
||||
|
||||
void init(std::vector<std::pair<int, VkDescriptorType>> binds, VkShaderStageFlagBits stage);
|
||||
void destroy() noexcept;
|
||||
|
||||
@@ -31,6 +31,8 @@ namespace mlx
|
||||
inline VkDescriptorSetLayout& get() noexcept { return _layout; }
|
||||
inline const std::vector<std::pair<int, VkDescriptorType>>& getBindings() const noexcept { return _bindings; }
|
||||
|
||||
~DescriptorSetLayout() = default;
|
||||
|
||||
private:
|
||||
VkDescriptorSetLayout _layout = VK_NULL_HANDLE;
|
||||
std::vector<std::pair<int, VkDescriptorType>> _bindings;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <volk.h>
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
#include <vma.h>
|
||||
#include <renderer/core/cmd_resource.h>
|
||||
#include <renderer/command/vk_cmd_buffer.h>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
#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({
|
||||
{0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER}
|
||||
}, VK_SHADER_STAGE_VERTEX_BIT);
|
||||
@@ -60,8 +54,8 @@ namespace mlx
|
||||
{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER}
|
||||
}, VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
|
||||
_vert_set.init(this, &_desc_pool, &_vert_layout);
|
||||
_frag_set.init(this, &_desc_pool, &_frag_layout);
|
||||
_vert_set.init(this, &Render_Core::get().getDescriptorPool(), &_vert_layout);
|
||||
_frag_set.init(this, &Render_Core::get().getDescriptorPool(), &_frag_layout);
|
||||
|
||||
_vert_set.writeDescriptor(0, _uniform_buffer.get());
|
||||
|
||||
@@ -179,8 +173,9 @@ namespace mlx
|
||||
_uniform_buffer->destroy();
|
||||
_vert_layout.destroy();
|
||||
_frag_layout.destroy();
|
||||
_frag_set.destroy();
|
||||
_vert_set.destroy();
|
||||
_cmd.destroy();
|
||||
_desc_pool.destroy();
|
||||
_pass.destroy();
|
||||
if(_render_target == nullptr)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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::vector<FrameBuffer> _framebuffers;
|
||||
|
||||
DescriptorPool _desc_pool;
|
||||
|
||||
DescriptorSetLayout _vert_layout;
|
||||
DescriptorSetLayout _frag_layout;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user