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

#include <HlslShaderTextureResource.h>

Inheritance diagram for ne::HlslShaderTextureResource:
ne::ShaderTextureResource ne::ShaderResourceBase

Public Member Functions

void setGraphicsRootDescriptorTableOfOnlyPipeline (const ComPtr< ID3D12GraphicsCommandList > &pCommandList) const
 
void setGraphicsRootDescriptorTableOfPipeline (const ComPtr< ID3D12GraphicsCommandList > &pCommandList, DirectXPso *pUsedPipeline) const
 
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::ShaderResourceBase
virtual std::optional< ErrorchangeUsedPipelines (const std::unordered_set< Pipeline * > &pipelinesToUse)=0
 
std::string getResourceName () const
 

Protected Member Functions

 HlslShaderTextureResource (const std::string &sResourceName, std::unique_ptr< TextureHandle > pTextureToUse, const std::unordered_map< DirectXPso *, UINT > &rootParameterIndices)
 
virtual std::optional< ErroronAfterAllPipelinesRefreshedResources () override
 
- Protected Member Functions inherited from ne::ShaderTextureResource
 ShaderTextureResource (const std::string &sResourceName)
 
- Protected Member Functions inherited from ne::ShaderResourceBase
 ShaderResourceBase (const std::string &sResourceName)
 
virtual std::optional< ErroronAfterAllPipelinesRefreshedResources ()=0
 

Static Private Member Functions

static std::variant< std::unique_ptr< ShaderTextureResource >, Errorcreate (const std::string &sShaderResourceName, const std::unordered_set< Pipeline * > &pipelinesToUse, std::unique_ptr< TextureHandle > pTextureToUse)
 

Private Attributes

std::pair< std::mutex, std::unique_ptr< TextureHandle > > mtxUsedTexture
 
DirectXDescriptorpTextureSrv = nullptr
 
DirectXDescriptorHeappSrvHeap = nullptr
 
UINT iSrvDescriptorSize = 0
 
std::pair< std::recursive_mutex, std::unordered_map< DirectXPso *, UINT > > mtxRootParameterIndices
 

Friends

class ShaderTextureResourceManager
 

Detailed Description

References some texture from shader code.

Constructor & Destructor Documentation

◆ HlslShaderTextureResource()

ne::HlslShaderTextureResource::HlslShaderTextureResource ( const std::string &  sResourceName,
std::unique_ptr< TextureHandle pTextureToUse,
const std::unordered_map< DirectXPso *, UINT > &  rootParameterIndices 
)
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.
rootParameterIndicesIndices of this resource in root signature.

Member Function Documentation

◆ changeUsedPipelines()

std::optional< Error > ne::HlslShaderTextureResource::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::ShaderResourceBase.

◆ create()

std::variant< std::unique_ptr< ShaderTextureResource >, Error > ne::HlslShaderTextureResource::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.

◆ onAfterAllPipelinesRefreshedResources()

std::optional< Error > ne::HlslShaderTextureResource::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::ShaderResourceBase.

◆ setGraphicsRootDescriptorTableOfOnlyPipeline()

void ne::HlslShaderTextureResource::setGraphicsRootDescriptorTableOfOnlyPipeline ( const ComPtr< ID3D12GraphicsCommandList > &  pCommandList) const
inline

Adds a new command to the specified command list to use this shader resource.

Warning
Expects that this shader resource uses only 1 pipeline. Generally used for material's resources because material can only reference 1 pipeline unlike mesh nodes.
Parameters
pCommandListCommand list to add new command to.

◆ setGraphicsRootDescriptorTableOfPipeline()

void ne::HlslShaderTextureResource::setGraphicsRootDescriptorTableOfPipeline ( const ComPtr< ID3D12GraphicsCommandList > &  pCommandList,
DirectXPso pUsedPipeline 
) const
inline

Adds a new command to the specified command list to use this shader resource.

Parameters
pCommandListCommand list to add new command to.
pUsedPipelineCurrent pipeline.

◆ useNewTexture()

std::optional< Error > ne::HlslShaderTextureResource::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::ShaderTextureResource.

Member Data Documentation

◆ iSrvDescriptorSize

UINT ne::HlslShaderTextureResource::iSrvDescriptorSize = 0
private

Size of one SRV descriptor.

◆ mtxRootParameterIndices

std::pair<std::recursive_mutex, std::unordered_map<DirectXPso*, UINT> > ne::HlslShaderTextureResource::mtxRootParameterIndices
private

Indices of this resource in root signature to bind this resource during the draw operation.

◆ mtxUsedTexture

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

Texture to which a descriptor should be binded.

◆ pSrvHeap

DirectXDescriptorHeap* ne::HlslShaderTextureResource::pSrvHeap = nullptr
private

SRV heap.

◆ pTextureSrv

DirectXDescriptor* ne::HlslShaderTextureResource::pTextureSrv = nullptr
private

Descriptor binded to mtxUsedTexture.


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