Nameless Engine
Loading...
Searching...
No Matches
ne::GlobalShaderResourceBindingManager Class Reference

#include <GlobalShaderResourceBindingManager.h>

Public Member Functions

std::optional< ErrorcreateGlobalShaderResourceBindingResourcePerFrame (const std::string &sShaderResourceName, std::array< GpuResource *, FrameResourceManager::getFrameResourceCount()> vResourcesToBind)
 
std::optional< ErrorcreateGlobalShaderResourceBindingSingleResource (const std::string &sShaderResourceName, GpuResource *pResourceToBind)
 
 ~GlobalShaderResourceBindingManager ()
 

Private Member Functions

 GlobalShaderResourceBindingManager (PipelineManager *pPipelineManager)
 
std::optional< ErroronNewGraphicsPipelineCreated (Pipeline *pNewPipeline)
 
std::optional< ErroronAllGraphicsPipelinesRecreatedInternalResources ()
 
std::optional< ErrorregisterNewBinding (GlobalShaderResourceBinding *pBinding)
 
void unregisterBinding (GlobalShaderResourceBinding *pBinding)
 

Private Attributes

std::pair< std::recursive_mutex, std::unordered_set< GlobalShaderResourceBinding * > > mtxActiveBindings
 
PipelineManager *const pPipelineManager = nullptr
 

Friends

class Renderer
 
class PipelineManager
 
class GlobalShaderResourceBinding
 

Detailed Description

Manages bindings of GPU resources as global shader resources (that don't change on a per-object basis).

Constructor & Destructor Documentation

◆ ~GlobalShaderResourceBindingManager()

ne::GlobalShaderResourceBindingManager::~GlobalShaderResourceBindingManager ( )

Makes sure no active binding exists.

◆ GlobalShaderResourceBindingManager()

ne::GlobalShaderResourceBindingManager::GlobalShaderResourceBindingManager ( PipelineManager pPipelineManager)
private

Initializes a new manager.

Parameters
pPipelineManagerManager used to interact with pipelines.

Member Function Documentation

◆ createGlobalShaderResourceBindingResourcePerFrame()

std::optional< Error > ne::GlobalShaderResourceBindingManager::createGlobalShaderResourceBindingResourcePerFrame ( const std::string &  sShaderResourceName,
std::array< GpuResource *, FrameResourceManager::getFrameResourceCount()>  vResourcesToBind 
)

Creates a new global shader resource binding (that don't change on a per-object basis) and assigns it to the specified resources (one resource per frame). When resources will be destroyed the binding will also be removed.

Remarks
If you only need to bind the same GPU resource for all frames in-flight then either use createGlobalShaderResourceBindingSingleResource that accepts a single GPU resource pointer (preferred) or just pass an array of the same pointers.
The actual type of the binding (cbuffer, uniform, structured buffer, storage buffer or etc) will be determined from the resource. For example, in DirectX in order to bind a cbuffer shader resource you need to pass a resource that already has a CBV bound and in Vulkan in order to bind a uniform you need to make sure that your resource was created with the "uniform" hint/flag.
This function will create a binding that binds a separate GPU resource per frame in-flight, this is generally used for some CPU-write resources (but there are exceptions and you can bind a single CPU-write resource in createGlobalShaderResourceBindingSingleResource if you only update the resource while it's unused by the GPU) so generally you have a CPU-write GPU buffer that you plan to update without CPU-GPU synchronization (for example each time the CPU is submitting a new frame) then you need to pass a separate buffer per frame resource to avoid modifying a buffer that may be used by the GPU.
Parameters
sShaderResourceNameName of the shader resource (name from shader code) to bind the resources.
vResourcesToBindResources to bind to pipelines.
Returns
Error if something went wrong.

◆ createGlobalShaderResourceBindingSingleResource()

std::optional< Error > ne::GlobalShaderResourceBindingManager::createGlobalShaderResourceBindingSingleResource ( const std::string &  sShaderResourceName,
GpuResource pResourceToBind 
)

Creates a new global shader resource binding (that don't change on a per-object basis) and assigns it to the specified resources. When resources will be destroyed the binding will also be removed.

Remarks
Also see createGlobalShaderResourceBindingResourcePerFrame for important remarks.
This function will create a binding that binds the same GPU resource for all frames in-flight (this can be used for textures or some buffer resources). This is used when you guarantee the CPU-GPU synchronization or don't plan to update the resource's contents from the CPU (but there are exceptions, see remarks of createGlobalShaderResourceBindingResourcePerFrame).
Parameters
sShaderResourceNameName of the shader resource (name from shader code) to bind the resource.
pResourceToBindResources to bind to pipelines.
Returns
Error if something went wrong.

◆ onAllGraphicsPipelinesRecreatedInternalResources()

std::optional< Error > ne::GlobalShaderResourceBindingManager::onAllGraphicsPipelinesRecreatedInternalResources ( )
private

Called by pipeline manager after all graphics pipelines re-created their internal state to re-bind all global shader resources to all pipelines.

Returns
Error if something went wrong.

◆ onNewGraphicsPipelineCreated()

std::optional< Error > ne::GlobalShaderResourceBindingManager::onNewGraphicsPipelineCreated ( Pipeline pNewPipeline)
private

Called by pipeline manager when a new graphics pipeline is created to maybe bind some global shader resources to it.

Parameters
pNewPipelinePipeline to bind to.
Returns
Error if something went wrong.

◆ registerNewBinding()

std::optional< Error > ne::GlobalShaderResourceBindingManager::registerNewBinding ( GlobalShaderResourceBinding pBinding)
private

Should be called by bindings upon construction.

Registers the binding and binds it to all graphics pipelines that might need that binding.

Parameters
pBindingBinding to register.
Returns
Error if something went wrong.

◆ unregisterBinding()

void ne::GlobalShaderResourceBindingManager::unregisterBinding ( GlobalShaderResourceBinding pBinding)
private

Should be called by bindings in their destructor.

Unregisters a binding that was previously registered using registerNewBinding.

Parameters
pBindingBinding to unregister.

Member Data Documentation

◆ mtxActiveBindings

std::pair<std::recursive_mutex, std::unordered_set<GlobalShaderResourceBinding*> > ne::GlobalShaderResourceBindingManager::mtxActiveBindings
private

Set of all currently existing (active) bindings.

Remarks
It's safe to store a raw pointer here because bindings will notify the manager in their destructor.

◆ pPipelineManager

PipelineManager* const ne::GlobalShaderResourceBindingManager::pPipelineManager = nullptr
private

Manager used to interact with pipelines.


The documentation for this class was generated from the following files: