diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-03-03 07:57:57 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-03-03 07:57:57 +0000 |
| commit | 6f479d4aa4e49b1ac4b1a6fbfc8b52dbd3bf58d6 (patch) | |
| tree | 8b5a6684fd8ba1dfb39910b3992cbf86ad95df04 /Graphics/GraphicsEngineD3DBase | |
| parent | Reworked ShaderResourcesD3D11 to comply with the updated API (diff) | |
| download | DiligentCore-6f479d4aa4e49b1ac4b1a6fbfc8b52dbd3bf58d6.tar.gz DiligentCore-6f479d4aa4e49b1ac4b1a6fbfc8b52dbd3bf58d6.zip | |
Partially reworked ShaderResourceLayoutD3D11
Diffstat (limited to 'Graphics/GraphicsEngineD3DBase')
| -rw-r--r-- | Graphics/GraphicsEngineD3DBase/include/ShaderResources.h | 11 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp | 78 |
2 files changed, 89 insertions, 0 deletions
diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h index 97fe7490..64c8fe61 100644 --- a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h +++ b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h @@ -62,6 +62,7 @@ #include "HashUtils.h" #include "StringPool.h" #include "D3DShaderResourceLoader.h" +#include "PipelineState.h" namespace Diligent { @@ -223,6 +224,10 @@ public: SamplerOrTexSRVId == Attribs.SamplerOrTexSRVId; } + SHADER_RESOURCE_VARIABLE_TYPE FindVariableType(SHADER_TYPE ShaderType, + const PipelineResourceLayoutDesc& ResourceLayoutDesc, + const char* CombinedSamplerSuffix)const; + size_t GetHash()const { return ComputeHash(BindPoint, BindCount, InputType, SRVDimension, SamplerOrTexSRVId); @@ -318,6 +323,12 @@ public: size_t GetHash()const; + D3DShaderResourceCounters CountResources(const PipelineResourceLayoutDesc& ResourceLayout, + SHADER_TYPE ShaderStage, + const char* CombinedSamplerSuffix, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes)const noexcept; + protected: template<typename D3D_SHADER_DESC, typename D3D_SHADER_INPUT_BIND_DESC, diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp index 847e2675..97107560 100644 --- a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp +++ b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp @@ -26,10 +26,30 @@ #include "StringTools.h" #include "ShaderResources.h" #include "HashUtils.h" +#include "ShaderResourceVariableBase.h" namespace Diligent { +SHADER_RESOURCE_VARIABLE_TYPE D3DShaderResourceAttribs::FindVariableType(SHADER_TYPE ShaderType, + const PipelineResourceLayoutDesc& ResourceLayoutDesc, + const char* CombinedSamplerSuffix)const +{ + if (GetInputType() == D3D_SIT_SAMPLER) + { + // Only use CombinedSamplerSuffix when looking for the sampler variable type + return GetShaderVariableType(ShaderType, ResourceLayoutDesc.DefaultVariableType, ResourceLayoutDesc.Variables, ResourceLayoutDesc.NumVariables, + [&](const char* VarName) + { + return StreqSuff(Name, VarName, CombinedSamplerSuffix); + }); + } + else + { + return GetShaderVariableType(ShaderType, Name, ResourceLayoutDesc); + } +} + ShaderResources::~ShaderResources() { for(Uint32 n=0; n < GetNumCBs(); ++n) @@ -96,6 +116,64 @@ ShaderResources::ShaderResources(SHADER_TYPE ShaderType): { } + +D3DShaderResourceCounters ShaderResources::CountResources(const PipelineResourceLayoutDesc& ResourceLayout, + SHADER_TYPE ShaderStage, + const char* CombinedSamplerSuffix, + const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes, + Uint32 NumAllowedTypes)const noexcept +{ + auto AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes); + + D3DShaderResourceCounters Counters; + ProcessResources( + [&](const D3DShaderResourceAttribs& CB, Uint32) + { + auto VarType = CB.FindVariableType(ShaderStage, ResourceLayout, CombinedSamplerSuffix); + if (IsAllowedType(VarType, AllowedTypeBits)) + ++Counters.NumCBs; + }, + [&](const D3DShaderResourceAttribs& Sam, Uint32) + { + auto VarType = Sam.FindVariableType(ShaderStage, ResourceLayout, CombinedSamplerSuffix); + if (IsAllowedType(VarType, AllowedTypeBits)) + { + // Skip static samplers + //if (!Sam.IsStaticSampler()) + ++Counters.NumSamplers; + } + }, + [&](const D3DShaderResourceAttribs& TexSRV, Uint32) + { + auto VarType = TexSRV.FindVariableType(ShaderStage, ResourceLayout, CombinedSamplerSuffix); + if (IsAllowedType(VarType, AllowedTypeBits)) + ++Counters.NumTexSRVs; + }, + [&](const D3DShaderResourceAttribs& TexUAV, Uint32) + { + auto VarType = TexUAV.FindVariableType(ShaderStage, ResourceLayout, CombinedSamplerSuffix); + if (IsAllowedType(VarType, AllowedTypeBits)) + ++Counters.NumTexUAVs; + }, + [&](const D3DShaderResourceAttribs& BufSRV, Uint32) + { + auto VarType = BufSRV.FindVariableType(ShaderStage, ResourceLayout, CombinedSamplerSuffix); + if (IsAllowedType(VarType, AllowedTypeBits)) + ++Counters.NumBufSRVs; + }, + [&](const D3DShaderResourceAttribs& BufUAV, Uint32) + { + auto VarType = BufUAV.FindVariableType(ShaderStage, ResourceLayout, CombinedSamplerSuffix); + if (IsAllowedType(VarType, AllowedTypeBits)) + ++Counters.NumBufUAVs; + } + ); + + return Counters; +} + + + Uint32 ShaderResources::FindAssignedSamplerId(const D3DShaderResourceAttribs& TexSRV, const char* SamplerSuffix)const { VERIFY_EXPR(SamplerSuffix != nullptr && *SamplerSuffix != 0); |
