SpiecsEngine
 
Loading...
Searching...
No Matches
DescriptorSetManager.cpp
Go to the documentation of this file.
1/**
2* @file DescriptorSetManager.cpp
3* @brief The DescriptorSetManager Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
9#include "Render/Vulkan/VulkanRenderBackend.h"
10#include "../../../assets/Shaders/src/Header/ShaderCommon.h"
11
12namespace Spices {
13
15 std::mutex DescriptorSetManager::m_Mutex;
16
17 std::shared_ptr<VulkanDescriptorSet> DescriptorSetManager::Registry(const String2& name, uint32_t set)
18 {
20
21 std::unique_lock<std::mutex> lock(m_Mutex);
22
23 if (m_DescriptorSets.find(name) != m_DescriptorSets.end())
24 {
25 if (m_DescriptorSets[name].find(set) != m_DescriptorSets[name].end())
26 {
27 return m_DescriptorSets[name][set];
28 }
29 }
30
31 m_DescriptorSets[name][set] = std::make_shared<VulkanDescriptorSet>(VulkanRenderBackend::GetState(), VulkanRenderBackend::GetDescriptorPool());
32
33 return m_DescriptorSets[name][set];
34 }
35
36 std::shared_ptr<VulkanDescriptorSet> DescriptorSetManager::Registry(const std::string& name, uint32_t set)
37 {
39
40 return Registry({ name , name }, set);
41 }
42
44 {
46
47 std::unique_lock<std::mutex> lock(m_Mutex);
48
49 if (m_DescriptorSets.find(name) != m_DescriptorSets.end())
50 {
51 if (m_DescriptorSets[name].find(SpicesShader::BINDLESS_TEXTURE_SET) == m_DescriptorSets[name].end())
52 {
53 m_DescriptorSets.erase(name);
54 }
55 else
56 {
57 const auto descriptorSet = m_DescriptorSets[name][SpicesShader::BINDLESS_TEXTURE_SET];
58 m_DescriptorSets.erase(name);
59 m_DescriptorSets[name][SpicesShader::BINDLESS_TEXTURE_SET] = descriptorSet;
60 }
61 }
62 }
63
64 void DescriptorSetManager::UnLoad(const std::string& name)
65 {
67
68 UnLoad({ name , name });
69 }
70
72 {
74
75 std::unique_lock<std::mutex> lock(m_Mutex);
76
77 if (m_DescriptorSets.find(name) != m_DescriptorSets.end())
78 {
79 m_DescriptorSets.erase(name);
80 }
81 }
82
83 void DescriptorSetManager::UnLoadForce(const std::string& name)
84 {
86
87 UnLoadForce({ name , name });
88 }
89
91 {
93
94 std::unique_lock<std::mutex> lock(m_Mutex);
95
96 m_DescriptorSets.clear();
97 }
98
99 DescriptorSetInfo& DescriptorSetManager::GetByName(const String2& name)
100 {
102
103 std::unique_lock<std::mutex> lock(m_Mutex);
104
105 return m_DescriptorSets[name];
106 }
107
108 DescriptorSetInfo& DescriptorSetManager::GetByName(const std::string& name)
109 {
111
112 const auto str = String2(name, name);
113 return GetByName(str);
114 }
115}
#define SPICES_PROFILE_ZONE
static void UnLoadAll()
Forcing UnLoad all VulkanDescriptorSet.
static void UnLoadForce(const String2 &name)
Forcing UnLoad a VulkanDescriptorSet.
static std::shared_ptr< VulkanDescriptorSet > Registry(const String2 &name, uint32_t set)
Registry a VulkanDescriptorSet, create one if find none.
static void UnLoad(const String2 &name)
UnLoad a VulkanDescriptorSet.
static void UnLoad(const std::string &name)
UnLoad a VulkanDescriptorSet.
static std::shared_ptr< VulkanDescriptorSet > Registry(const std::string &name, uint32_t set)
Registry a VulkanDescriptorSet, create one if find none.
static std::mutex m_Mutex
Mutex of this DescriptorSetManager.
static DescriptorManagerContainer m_DescriptorSets
The container of all descriptor sets, identified with owner's name and set number.
static void UnLoadForce(const std::string &name)
Forcing UnLoad a VulkanDescriptorSet.
This Class manages all descriptor sets this project.
This Class is a wrapper of VkDescriptorSet.
String2(const std::string &str0, const std::string &str1)
Constructor Function.
Definition Math.h:76
double string
Definition Math.h:63