Nameless Engine
Loading...
Searching...
No Matches
ShaderCpuWriteResourceBindingManager.h
1#pragma once
2
3// Standard.
4#include <set>
5#include <memory>
6#include <mutex>
7#include <array>
8#include <unordered_map>
9#include <unordered_set>
10
11// Custom.
12#include "shader/general/resource/binding/cpuwrite/ShaderCpuWriteResourceBinding.h"
13#include "shader/general/resource/binding/cpuwrite/ShaderCpuWriteResourceBindingUniquePtr.h"
14#include "render/general/resource/frame/FrameResourceManager.h"
15
16namespace ne {
17 class Renderer;
18 class Pipeline;
19
22 // Only renderer should be allowed to create this manager.
23 friend class Renderer;
24
25 // Unique pointers will notify the manager before destruction.
27
28 public:
30 struct Resources {
37 std::unordered_map<ShaderCpuWriteResourceBinding*, std::unique_ptr<ShaderCpuWriteResourceBinding>>
39
41 std::array<
42 std::unordered_set<ShaderCpuWriteResourceBinding*>,
45 };
46
48
51
54
72 std::variant<ShaderCpuWriteResourceBindingUniquePtr, Error> createShaderCpuWriteResource(
73 const std::string& sShaderResourceName,
74 const std::string& sResourceAdditionalInfo,
75 size_t iResourceDataSizeInBytes,
76 const std::unordered_set<Pipeline*>& pipelinesToUse,
77 const std::function<void*()>& onStartedUpdatingResource,
78 const std::function<void()>& onFinishedUpdatingResource);
79
87 void updateResources(size_t iCurrentFrameResourceIndex);
88
96
102 std::pair<std::recursive_mutex, Resources>* getResources();
103
104 private:
111
119 std::variant<ShaderCpuWriteResourceBindingUniquePtr, Error>
120 handleResourceCreation(std::variant<std::unique_ptr<ShaderCpuWriteResourceBinding>, Error> result);
121
128 void destroyResource(ShaderCpuWriteResourceBinding* pResourceToDestroy);
129
131 Renderer* pRenderer = nullptr;
132
134 std::pair<std::recursive_mutex, Resources> mtxShaderCpuWriteResources;
135 };
136} // namespace ne
Definition: Error.h:27
static constexpr unsigned int getFrameResourceCount()
Definition: FrameResourceManager.h:74
Definition: Renderer.h:43
Definition: ShaderCpuWriteResourceBindingManager.h:21
void updateResources(size_t iCurrentFrameResourceIndex)
Definition: ShaderCpuWriteResourceBindingManager.cpp:54
void destroyResource(ShaderCpuWriteResourceBinding *pResourceToDestroy)
Definition: ShaderCpuWriteResourceBindingManager.cpp:99
void markResourceAsNeedsUpdate(ShaderCpuWriteResourceBinding *pResourceToDestroy)
Definition: ShaderCpuWriteResourceBindingManager.cpp:75
Renderer * pRenderer
Definition: ShaderCpuWriteResourceBindingManager.h:131
std::pair< std::recursive_mutex, Resources > mtxShaderCpuWriteResources
Definition: ShaderCpuWriteResourceBindingManager.h:134
~ShaderCpuWriteResourceBindingManager()
Definition: ShaderCpuWriteResourceBindingManager.cpp:128
std::variant< ShaderCpuWriteResourceBindingUniquePtr, Error > createShaderCpuWriteResource(const std::string &sShaderResourceName, const std::string &sResourceAdditionalInfo, size_t iResourceDataSizeInBytes, const std::unordered_set< Pipeline * > &pipelinesToUse, const std::function< void *()> &onStartedUpdatingResource, const std::function< void()> &onFinishedUpdatingResource)
Definition: ShaderCpuWriteResourceBindingManager.cpp:11
std::pair< std::recursive_mutex, Resources > * getResources()
Definition: ShaderCpuWriteResourceBindingManager.cpp:120
std::variant< ShaderCpuWriteResourceBindingUniquePtr, Error > handleResourceCreation(std::variant< std::unique_ptr< ShaderCpuWriteResourceBinding >, Error > result)
Definition: ShaderCpuWriteResourceBindingManager.cpp:29
Definition: ShaderCpuWriteResourceBindingUniquePtr.h:14
Definition: ShaderCpuWriteResourceBinding.h:25
Definition: ShaderCpuWriteResourceBindingManager.h:30
std::array< std::unordered_set< ShaderCpuWriteResourceBinding * >, FrameResourceManager::getFrameResourceCount()> vToBeUpdated
Definition: ShaderCpuWriteResourceBindingManager.h:44
std::unordered_map< ShaderCpuWriteResourceBinding *, std::unique_ptr< ShaderCpuWriteResourceBinding > > all
Definition: ShaderCpuWriteResourceBindingManager.h:38