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

#include <HlslShaderTextureResourceBinding.h>

Inheritance diagram for ne::HlslShaderTextureResourceBinding:
ne::ShaderTextureResourceBinding ne::ShaderResourceBindingBase

Public Member Functions

void copyResourceIndexToRootConstants (PipelineShaderConstantsManager *pShaderConstantsManager, DirectXPso *pUsedPipeline)
 
virtual std::optional< ErroruseNewTexture (std::unique_ptr< TextureHandle > pTextureToUse) override
 
virtual std::optional< ErrorchangeUsedPipelines (const std::unordered_set< Pipeline * > &pipelinesToUse) override
 
virtual std::optional< ErroruseNewTexture (std::unique_ptr< TextureHandle > pTextureToUse)=0
 
- Public Member Functions inherited from ne::ShaderResourceBindingBase
virtual std::optional< ErrorchangeUsedPipelines (const std::unordered_set< Pipeline * > &pipelinesToUse)=0
 
std::string getShaderResourceName () const
 

Protected Member Functions

 HlslShaderTextureResourceBinding (const std::string &sResourceName, std::unique_ptr< TextureHandle > pTextureToUse, std::unordered_map< DirectXPso *, std::pair< ContinuousDirectXDescriptorRange *, size_t > > &&usedDescriptorRanges)
 
virtual std::optional< ErroronAfterAllPipelinesRefreshedResources () override
 
- Protected Member Functions inherited from ne::ShaderTextureResourceBinding
 ShaderTextureResourceBinding (const std::string &sShaderResourceName)
 
- Protected Member Functions inherited from ne::ShaderResourceBindingBase
 ShaderResourceBindingBase (const std::string &sShaderResourceName)
 
virtual std::optional< ErroronAfterAllPipelinesRefreshedResources ()=0
 

Static Private Member Functions

static std::variant< std::unique_ptr< ShaderTextureResourceBinding >, Errorcreate (const std::string &sShaderResourceName, const std::unordered_set< Pipeline * > &pipelinesToUse, std::unique_ptr< TextureHandle > pTextureToUse)
 
static std::variant< std::pair< ContinuousDirectXDescriptorRange *, size_t >, ErrorgetSrvDescriptorRangeAndRootConstantIndex (DirectXPso *pPipeline, const std::string &sShaderResourceName)
 

Private Attributes

std::pair< std::mutex, std::unique_ptr< TextureHandle > > mtxUsedTexture
 
std::pair< std::recursive_mutex, std::unordered_map< DirectXPso *, std::pair< ContinuousDirectXDescriptorRange *, size_t > > > mtxUsedPipelineDescriptorRanges
 

Static Private Attributes

static constexpr bool bBindSrvToCubemapFaces = false
 

Friends

class ShaderTextureResourceBindingManager
 

Detailed Description

References some texture from shader code.

Constructor & Destructor Documentation

◆ HlslShaderTextureResourceBinding()

ne::HlslShaderTextureResourceBinding::HlslShaderTextureResourceBinding ( const std::string &  sResourceName,
std::unique_ptr< TextureHandle pTextureToUse,
std::unordered_map< DirectXPso *, std::pair< ContinuousDirectXDescriptorRange *, size_t > > &&  usedDescriptorRanges 
)
protected

Initializes the resource.

Remarks
Used internally, for outside usage prefer to use create.
Parameters
sResourceNameName of the resource we are referencing (should be exactly the same as the resource name written in the shader file we are referencing).
pTextureToUseTexture to which a descriptor should be binded.
usedDescriptorRangesDescriptor ranges that have an SRV binded to the specified texture and a shader constant index for our shader resource.

Member Function Documentation

◆ changeUsedPipelines()

std::optional< Error > ne::HlslShaderTextureResourceBinding::changeUsedPipelines ( const std::unordered_set< Pipeline * > &  pipelinesToUse)
overridevirtual

Called to make the resource to discard currently used pipelines and bind/reference other pipelines.

Warning
Expects that the caller is using some mutex to protect this shader resource from being used in the draw function while this function is not finished (i.e. make sure the CPU will not queue a new frame while this function is not finished).
Remarks
For example, for this function can be called from a mesh node that changed its geometry and thus added/removed some material slots, or if some material that mesh node is using changed its pipeline.
Parameters
pipelinesToUsePipelines to use instead of the current ones.
Returns
Error if something went wrong.

Implements ne::ShaderResourceBindingBase.

◆ copyResourceIndexToRootConstants()

void ne::HlslShaderTextureResourceBinding::copyResourceIndexToRootConstants ( PipelineShaderConstantsManager pShaderConstantsManager,
DirectXPso pUsedPipeline 
)
inline

Copies resource index (into shader arrays) to a root constant.

Parameters
pShaderConstantsManagerShader constants manager.
pUsedPipelineCurrent pipeline.

◆ create()

std::variant< std::unique_ptr< ShaderTextureResourceBinding >, Error > ne::HlslShaderTextureResourceBinding::create ( const std::string &  sShaderResourceName,
const std::unordered_set< Pipeline * > &  pipelinesToUse,
std::unique_ptr< TextureHandle pTextureToUse 
)
staticprivate

Creates a new HLSL shader resource.

Parameters
sShaderResourceNameName of the resource we are referencing (should be exactly the same as the resource name written in the shader file we are referencing).
pipelinesToUsePipelines that use shader/parameters we are referencing.
pTextureToUseTexture to which a descriptor should be binded.
Returns
Error if something went wrong, otherwise created shader resource.

◆ getSrvDescriptorRangeAndRootConstantIndex()

std::variant< std::pair< ContinuousDirectXDescriptorRange *, size_t >, Error > ne::HlslShaderTextureResourceBinding::getSrvDescriptorRangeAndRootConstantIndex ( DirectXPso pPipeline,
const std::string &  sShaderResourceName 
)
staticprivate

In the specified pipeline looks for a descriptor range that handles a shader resource with the specified name (creates a new descriptor range if not found and returns a pointer to it).

Parameters
pPipelinePipeline to look in.
sShaderResourceNameShader resource to look for.
Returns
Error if something went wrong, otherwise a pointer to descriptor range from the pipeline and an index of the root constant that is used to index into our shader resource.

◆ onAfterAllPipelinesRefreshedResources()

std::optional< Error > ne::HlslShaderTextureResourceBinding::onAfterAllPipelinesRefreshedResources ( )
overrideprotectedvirtual

Called from pipeline manager to notify that all pipelines released their internal resources and now restored them so their internal resources (for example push constants) might be different now and shader resource now needs to check that everything that it needs is still there and possibly re-bind to pipeline's descriptors since these might have been also re-created.

Returns
Error if something went wrong.

Implements ne::ShaderResourceBindingBase.

◆ useNewTexture()

std::optional< Error > ne::HlslShaderTextureResourceBinding::useNewTexture ( std::unique_ptr< TextureHandle pTextureToUse)
overridevirtual

Makes the shader resource to reference the new (specified) texture.

Warning
Expects that the caller is using some mutex to protect this shader resource from being used in the draw function while this function is not finished (i.e. make sure the CPU will not queue a new frame while this function is not finished).
Parameters
pTextureToUseTexture to reference.
Returns
Error if something went wrong.

Implements ne::ShaderTextureResourceBinding.

Member Data Documentation

◆ bBindSrvToCubemapFaces

constexpr bool ne::HlslShaderTextureResourceBinding::bBindSrvToCubemapFaces = false
staticconstexprprivate

false to avoid binding descriptors to cubemap faces - I don't see any point in that here, we don't use individual cubemap faces in this case

◆ mtxUsedPipelineDescriptorRanges

std::pair< std::recursive_mutex, std::unordered_map<DirectXPso*, std::pair<ContinuousDirectXDescriptorRange*, size_t> > > ne::HlslShaderTextureResourceBinding::mtxUsedPipelineDescriptorRanges
private

Stores a raw pointer (per-pipeline) to a descriptor range (from the pipeline) that was used to bind an SRV to mtxUsedTexture and an offset of the shader constant for our shader resource.

Remarks
Storing raw pointers to descriptor ranges here is safe because before a PSO releases its internal resources (and destroys descriptor ranges) it will pause the rendering then destroy its descriptor tables, then we will be notified through onAfterAllPipelinesRefreshedResources to reference new descriptor ranges.

◆ mtxUsedTexture

std::pair<std::mutex, std::unique_ptr<TextureHandle> > ne::HlslShaderTextureResourceBinding::mtxUsedTexture
private

Texture to which a descriptor should be binded.


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