diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-02-28 15:35:57 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-02-28 15:35:57 +0000 |
| commit | 6384ebb550a265f60dc30220d21460164df07936 (patch) | |
| tree | 9aee0579f67b8cbb32ee198c2cb5a7a342f69d46 /Graphics | |
| parent | Fixed memory leak (diff) | |
| download | DiligentCore-6384ebb550a265f60dc30220d21460164df07936.tar.gz DiligentCore-6384ebb550a265f60dc30220d21460164df07936.zip | |
Improved shader resource binding error reporting in ShaderResourceLayoutVk
Diffstat (limited to 'Graphics')
4 files changed, 42 insertions, 3 deletions
diff --git a/Graphics/GraphicsAccessories/interface/GraphicsAccessories.h b/Graphics/GraphicsAccessories/interface/GraphicsAccessories.h index ef769bfc..4ad6ba4a 100644 --- a/Graphics/GraphicsAccessories/interface/GraphicsAccessories.h +++ b/Graphics/GraphicsAccessories/interface/GraphicsAccessories.h @@ -183,6 +183,12 @@ const Char *GetBufferViewTypeLiteralName(BUFFER_VIEW_TYPE ViewType); /// \return Literal name of the shader type. const Char *GetShaderTypeLiteralName(SHADER_TYPE ShaderType); +/// \param [in] ShaderStages - Shader stages. +/// \return The string representing the shader stages. For example, +/// if ShaderStages == SHADER_TYPE_VERTEX | SHADER_TYPE_PIXEL, +/// the following string will be returned: +/// "SHADER_TYPE_VERTEX, SHADER_TYPE_PIXEL" +String GetShaderStagesString(SHADER_TYPE ShaderStages); /// Returns the literal name of a shader variable type. For instance, /// for SHADER_RESOURCE_VARIABLE_TYPE_STATIC, if bGetFullName == true, "SHADER_RESOURCE_VARIABLE_TYPE_STATIC" will be returned; diff --git a/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp b/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp index 3613076f..7a8b1226 100644 --- a/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp +++ b/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp @@ -471,10 +471,28 @@ const Char *GetShaderTypeLiteralName( SHADER_TYPE ShaderType ) RETURN_SHADER_TYPE_NAME( SHADER_TYPE_COMPUTE ) #undef RETURN_SHADER_TYPE_NAME - default: UNEXPECTED( "Unknown shader type" ); return "<Unknown shader type>"; + default: UNEXPECTED( "Unknown shader type constant ", Uint32{ShaderType} ); return "<Unknown shader type>"; } } +String GetShaderStagesString(SHADER_TYPE ShaderStages) +{ + String StagesStr; + while(ShaderStages != 0) + for( Uint32 Stage = SHADER_TYPE_VERTEX; ShaderStages != 0 && Stage <= SHADER_TYPE_COMPUTE; Stage <<= 1 ) + { + if( ShaderStages&Stage ) + { + if( StagesStr.length() ) + StagesStr += ", "; + StagesStr += GetShaderTypeLiteralName( static_cast<SHADER_TYPE>(Stage)); + ShaderStages &= ~static_cast<SHADER_TYPE>(Stage); + } + } + VERIFY_EXPR( ShaderStages == 0); + return StagesStr; +} + const Char *GetShaderVariableTypeLiteralName(SHADER_RESOURCE_VARIABLE_TYPE VarType, bool bGetFullName) { static const Char* ShortVarTypeNameStrings[SHADER_RESOURCE_VARIABLE_TYPE_NUM_TYPES]; diff --git a/Graphics/GraphicsEngine/interface/Shader.h b/Graphics/GraphicsEngine/interface/Shader.h index 43d6021a..2ac6a2c6 100644 --- a/Graphics/GraphicsEngine/interface/Shader.h +++ b/Graphics/GraphicsEngine/interface/Shader.h @@ -27,6 +27,7 @@ /// Definition of the Diligent::IShader interface and related data structures #include "../../../Primitives/interface/FileStream.h" +#include "../../../Primitives/interface/FlagEnum.h" #include "DeviceObject.h" namespace Diligent @@ -47,6 +48,7 @@ enum SHADER_TYPE : Uint32 SHADER_TYPE_DOMAIN = 0x010, ///< Domain (tessellation evaluation) shader SHADER_TYPE_COMPUTE = 0x020 ///< Compute shader }; +DEFINE_FLAG_ENUM_OPERATORS(SHADER_TYPE); enum SHADER_PROFILE : Uint8 { diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp index 201fadc6..7f1eb1bb 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderResourceLayoutVk.cpp @@ -225,6 +225,11 @@ void ShaderResourceLayoutVk::Initialize(IRenderDevice* { bool VariableFound = false; const auto& VarDesc = LayoutDesc.Variables[v]; + if (VarDesc.ShaderStages == SHADER_TYPE_UNKNOWN) + { + LOG_WARNING_MESSAGE("No allowed shader stages specified for variable '", VarDesc.Name, "' labeled as ", GetShaderVariableTypeLiteralName(VarDesc.Type), "."); + } + for(Uint32 s=0; s < NumShaders && !VariableFound; ++s) { const auto& Resources = *pShaderResources[s]; @@ -239,17 +244,25 @@ void ShaderResourceLayoutVk::Initialize(IRenderDevice* } if (!VariableFound) { - LOG_WARNING_MESSAGE("Variable '", VarDesc.Name, "' labeled as ", GetShaderVariableTypeLiteralName(VarDesc.Type), " is not found in any of shader stages"); + LOG_WARNING_MESSAGE("Variable '", VarDesc.Name, "' labeled as ", GetShaderVariableTypeLiteralName(VarDesc.Type), " is not found in any of the specified shader stages: ", GetShaderStagesString(VarDesc.ShaderStages)); } } for (Uint32 sam = 0; sam < LayoutDesc.NumStaticSamplers; ++sam) { const auto& StSamDesc = LayoutDesc.StaticSamplers[sam]; + if (StSamDesc.ShaderStages == SHADER_TYPE_UNKNOWN) + { + LOG_WARNING_MESSAGE("No allowed shader stages specified for static sampler '", StSamDesc.SamplerOrTextureName, "."); + } + bool SamplerFound = false; for(Uint32 s=0; s < NumShaders && !SamplerFound; ++s) { const auto& Resources = *pShaderResources[s]; + if ( (StSamDesc.ShaderStages & Resources.GetShaderType()) == 0 ) + continue; + // Irrespective of whether HLSL-style combined image samplers are used, // a static sampler can be assigned to GLSL sampled image (i.e. sampler2D g_tex) for (Uint32 i = 0; i < Resources.GetNumSmpldImgs() && !SamplerFound; ++i) @@ -276,7 +289,7 @@ void ShaderResourceLayoutVk::Initialize(IRenderDevice* if (!SamplerFound) { - LOG_WARNING_MESSAGE("Static sampler '", StSamDesc.SamplerOrTextureName, "' is not found in any of shader stages"); + LOG_WARNING_MESSAGE("Static sampler '", StSamDesc.SamplerOrTextureName, "' is not found in any of the specified shader stages: ", GetShaderStagesString(StSamDesc.ShaderStages)); } } #endif |
