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

#include <RootSignatureGenerator.h>

Classes

struct  CollectedInfo
 
struct  Generated
 
class  RootParameter
 

Public Member Functions

 RootSignatureGenerator (const RootSignatureGenerator &)=delete
 
RootSignatureGeneratoroperator= (const RootSignatureGenerator &)=delete
 

Static Public Member Functions

static std::variant< CollectedInfo, ErrorcollectInfoFromReflection (ID3D12Device *pDevice, const ComPtr< ID3D12ShaderReflection > &pShaderReflection)
 
static std::variant< Generated, ErrorgenerateGraphics (DirectXRenderer *pRenderer, HlslShader *pVertexShader, HlslShader *pPixelShader)
 
static std::variant< Generated, ErrorgenerateCompute (DirectXRenderer *pRenderer, HlslShader *pComputeShader)
 

Static Private Member Functions

static std::variant< SamplerType, ErrorfindStaticSamplerForSamplerResource (const D3D12_SHADER_INPUT_BIND_DESC &samplerResourceDescription)
 
static void addSpecialResourceRootParametersIfUsed (std::unordered_map< std::string, std::pair< UINT, RootSignatureGenerator::RootParameter > > &shaderRootParameterIndices, std::vector< CD3DX12_ROOT_PARAMETER > &vRootParameters, std::vector< CD3DX12_DESCRIPTOR_RANGE > &vTableRanges, std::set< std::string > &addedRootParameterNames, std::unordered_map< std::string, UINT > &rootParameterIndices, std::array< UINT, static_cast< unsigned int >(SpecialRootParameterSlot::SIZE)> &vSpecialRootParameterIndices)
 
static std::optional< ErroraddUniquePairResourceNameRootParameterIndex (std::unordered_map< std::string, std::pair< UINT, RootParameter > > &mapToAddTo, const std::string &sResourceName, UINT iRootParameterIndex, const RootParameter &parameter)
 
static std::optional< ErroraddCbufferRootParameter (std::vector< RootParameter > &vRootParameters, std::unordered_map< std::string, std::pair< UINT, RootParameter > > &rootParameterIndices, const D3D12_SHADER_INPUT_BIND_DESC &resourceDescription)
 
static std::optional< ErroraddTexture2DRootParameter (std::vector< RootParameter > &vRootParameters, std::unordered_map< std::string, std::pair< UINT, RootParameter > > &rootParameterIndices, const D3D12_SHADER_INPUT_BIND_DESC &resourceDescription, bool bIsReadWrite)
 
static std::optional< ErroraddStructuredBufferRootParameter (std::vector< RootParameter > &vRootParameters, std::unordered_map< std::string, std::pair< UINT, RootParameter > > &rootParameterIndices, const D3D12_SHADER_INPUT_BIND_DESC &resourceDescription, bool bIsReadWrite)
 
static std::variant< bool, ErrorprocessRootConstantsIfFound (const ComPtr< ID3D12ShaderReflection > &pShaderReflection, const D3D12_SHADER_INPUT_BIND_DESC &resourceDescription, std::unordered_map< std::string, size_t > &rootConstantOffsets, std::vector< RootParameter > &vRootParameters, std::unordered_map< std::string, std::pair< UINT, RootParameter > > &rootParameterIndices)
 

Static Private Attributes

static const std::string sRootConstantsVariableName = "constants"
 
static const std::string sRootConstantsTypeName = "RootConstants"
 

Detailed Description

Generates Root Signature based on HLSL code.

Member Function Documentation

◆ addCbufferRootParameter()

std::optional< Error > ne::RootSignatureGenerator::addCbufferRootParameter ( std::vector< RootParameter > &  vRootParameters,
std::unordered_map< std::string, std::pair< UINT, RootParameter > > &  rootParameterIndices,
const D3D12_SHADER_INPUT_BIND_DESC &  resourceDescription 
)
staticprivate

Adds a cbuffer shader resource to root parameters.

Parameters
vRootParametersParameters to add the new resource to.
rootParameterIndicesMap to add new parameter to.
resourceDescriptionShader resource description.
Returns
Error if something went wrong.

◆ addSpecialResourceRootParametersIfUsed()

void ne::RootSignatureGenerator::addSpecialResourceRootParametersIfUsed ( std::unordered_map< std::string, std::pair< UINT, RootSignatureGenerator::RootParameter > > &  shaderRootParameterIndices,
std::vector< CD3DX12_ROOT_PARAMETER > &  vRootParameters,
std::vector< CD3DX12_DESCRIPTOR_RANGE > &  vTableRanges,
std::set< std::string > &  addedRootParameterNames,
std::unordered_map< std::string, UINT > &  rootParameterIndices,
std::array< UINT, static_cast< unsigned int >(SpecialRootParameterSlot::SIZE)> &  vSpecialRootParameterIndices 
)
staticprivate

Adds special root signature resources (if they are actually used).

Parameters
shaderRootParameterIndicesUsed resources of shaders.
vRootParametersSingle root parameters of the root signature that will be generated.
vTableRangesRange root parameters of the root signature that will be generated.
addedRootParameterNamesNames of the root parameters that were added.
rootParameterIndicesPairs of "resource name" - "root parameter index" that were added.
vSpecialRootParameterIndicesIndices of special root parameters.

◆ addStructuredBufferRootParameter()

std::optional< Error > ne::RootSignatureGenerator::addStructuredBufferRootParameter ( std::vector< RootParameter > &  vRootParameters,
std::unordered_map< std::string, std::pair< UINT, RootParameter > > &  rootParameterIndices,
const D3D12_SHADER_INPUT_BIND_DESC &  resourceDescription,
bool  bIsReadWrite 
)
staticprivate

Adds a (RW)StructuredBuffer shader resource to root parameters.

Parameters
vRootParametersParameters to add the new resource to.
rootParameterIndicesMap to add new parameter to.
resourceDescriptionShader resource description.
bIsReadWritetrue if buffer is read/write, false if only read.
Returns
Error if something went wrong.

◆ addTexture2DRootParameter()

std::optional< Error > ne::RootSignatureGenerator::addTexture2DRootParameter ( std::vector< RootParameter > &  vRootParameters,
std::unordered_map< std::string, std::pair< UINT, RootParameter > > &  rootParameterIndices,
const D3D12_SHADER_INPUT_BIND_DESC &  resourceDescription,
bool  bIsReadWrite 
)
staticprivate

Adds a (RW)Texture2D shader resource to root parameters.

Parameters
vRootParametersParameters to add the new resource to.
rootParameterIndicesMap to add new parameter to.
resourceDescriptionShader resource description.
bIsReadWritetrue if buffer is read/write, false if only read.
Returns
Error if something went wrong.

◆ addUniquePairResourceNameRootParameterIndex()

std::optional< Error > ne::RootSignatureGenerator::addUniquePairResourceNameRootParameterIndex ( std::unordered_map< std::string, std::pair< UINT, RootParameter > > &  mapToAddTo,
const std::string &  sResourceName,
UINT  iRootParameterIndex,
const RootParameter parameter 
)
staticprivate

Adds a new pair of resource name - root parameter index to the specified map, additionally checks if a resource with this name already exists in the map and returns error in this case.

Parameters
mapToAddToMap to add new pair to.
sResourceNameResource name.
iRootParameterIndexRoot parameter index of the resource.
parameterParameter to add.
Returns
Error if a resource with this name already exists in the map.

◆ collectInfoFromReflection()

std::variant< RootSignatureGenerator::CollectedInfo, Error > ne::RootSignatureGenerator::collectInfoFromReflection ( ID3D12Device *  pDevice,
const ComPtr< ID3D12ShaderReflection > &  pShaderReflection 
)
static

Generates root signature based on HLSL code reflection.

Parameters
pDeviceDirectX device.
pShaderReflectionReflection from compiled HLSL shader.
Returns
Error if something was wrong, otherwise generated root signature with used parameters.

◆ findStaticSamplerForSamplerResource()

std::variant< SamplerType, Error > ne::RootSignatureGenerator::findStaticSamplerForSamplerResource ( const D3D12_SHADER_INPUT_BIND_DESC &  samplerResourceDescription)
staticprivate

Finds static sampler for the specified sampler resource.

Parameters
samplerResourceDescriptionHLSL resource description.
Returns
Error if static sampler is not found, otherwise found static sampler.

◆ generateCompute()

std::variant< RootSignatureGenerator::Generated, Error > ne::RootSignatureGenerator::generateCompute ( DirectXRenderer pRenderer,
HlslShader pComputeShader 
)
static

Generates a new root signature using the compute shader info.

Remarks
Expects that root signature information is already collected for shader (see collectInfoFromReflection), otherwise returns error.
Parameters
pRendererDirectX renderer.
pComputeShaderCompute shader.
Returns
Error if something went wrong, otherwise generated root signature.

◆ generateGraphics()

std::variant< RootSignatureGenerator::Generated, Error > ne::RootSignatureGenerator::generateGraphics ( DirectXRenderer pRenderer,
HlslShader pVertexShader,
HlslShader pPixelShader 
)
static

Generates a new root signature using the vertex and pixel shader info.

Remarks
Expects that root signature information is already collected for both shaders (see collectInfoFromReflection), otherwise returns error.
Warning
If a shader uses a static sampler this function will take the current texture filtering setting from the RenderSettings and will set it as a static sampler. This means that once the current texture filtering setting is changed you need to re-run this function to set a new filter into the root signature's static sampler.
Parameters
pRendererDirectX renderer.
pVertexShaderVertex shader.
pPixelShaderPixel shader. Specify nullptr to generate root signature only for vertex shader.
Returns
Error if something went wrong, otherwise generated root signature.

◆ processRootConstantsIfFound()

std::variant< bool, Error > ne::RootSignatureGenerator::processRootConstantsIfFound ( const ComPtr< ID3D12ShaderReflection > &  pShaderReflection,
const D3D12_SHADER_INPUT_BIND_DESC &  resourceDescription,
std::unordered_map< std::string, size_t > &  rootConstantOffsets,
std::vector< RootParameter > &  vRootParameters,
std::unordered_map< std::string, std::pair< UINT, RootParameter > > &  rootParameterIndices 
)
staticprivate

Looks if the specified cbuffer resource description stores root constants (sRootConstantsTypeName) and if it does adds root constant offsets to the specified map.

Parameters
pShaderReflectionShader reflection.
resourceDescriptionCbuffer description.
rootConstantOffsetsIf found root constants, their offsets will be added here.
vRootParametersParameters to add the new resource to (if root constants are found).
rootParameterIndicesMap to add new parameter to (if root constants are found).
Returns
Error if something went wrong, otherwise false if no root constants were found and true if root constants were found and variable offsets were added.

Member Data Documentation

◆ sRootConstantsTypeName

const std::string ne::RootSignatureGenerator::sRootConstantsTypeName = "RootConstants"
inlinestaticprivate

Name of the shader struct that stores root constants.

◆ sRootConstantsVariableName

const std::string ne::RootSignatureGenerator::sRootConstantsVariableName = "constants"
inlinestaticprivate

Name of the shader cbuffer that will be considered as buffer that stores root constants.


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