mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-12 15:13:34 +00:00
improving descriptor sets and pools management
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user