SpiecsEngine
 
Loading...
Searching...
No Matches
BindLessTextureManager.cpp
Go to the documentation of this file.
1/**
2* @file BindLessTextureManager.cpp
3* @brief The BindLessTextureManager 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
17
18 uint32_t BindLessTextureManager::Registry(const std::string& name)
19 {
21
22 std::unique_lock<std::mutex> lock(m_Mutex);
23
24 /**
25 * @brief Return ID if texture already registry.
26 */
27 if (m_TextureIDMap.find(name) != m_TextureIDMap.end())
28 {
29 return m_TextureIDMap[name];
30 }
31
32 /**
33 * @brief Find a empty slot to store texture.
34 */
35 else
36 {
37 for (uint32_t i = 0; i < SpicesShader::BINDLESS_TEXTURE_MAXNUM; i++)
38 {
39 if (m_TextureInfoMap.find(i) == m_TextureInfoMap.end())
40 {
41 m_TextureInfoMap[i] = "";
42 m_TextureIDMap[name] = i;
43 return i;
44 }
45 }
46
47 SPICES_CORE_ERROR("Up to Maxium Bindless Texture Number : 65536")
48
49 return 0;
50 }
51 }
52
53 void BindLessTextureManager::UnRegistry(const std::string& name)
54 {
56
57 std::unique_lock<std::mutex> lock(m_Mutex);
58
59 if (m_TextureIDMap.find(name) != m_TextureIDMap.end())
60 {
61 m_TextureInfoMap.erase(m_TextureIDMap[name]);
62 m_TextureIDMap.erase(name);
63 }
64 }
65}
#define SPICES_PROFILE_ZONE
static void UnRegistry(const std::string &name)
UnRegistry a texture from bind less texture descriptor set array index.
static uint32_t Registry(const std::string &name)
Registry a texture to bind less texture descriptor set array index.
static std::unordered_map< uint32_t, std::string > m_TextureInfoMap
Hashmap of array index and "".
static std::mutex m_Mutex
Mutex of this BindLessTextureManager.
static std::unordered_map< std::string, uint32_t > m_TextureIDMap
Hashmap of texture path and array index.
This Class Helps registry a texture to bind less texture descriptor set.