diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-10-17 16:56:34 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-10-17 16:56:34 +0000 |
| commit | e7b18160a758b30dd6b701b4aa6f43c9c2061ccf (patch) | |
| tree | a990292cb0a24d6b23eec9011ad2c06b4cfa1f0a /Graphics/GraphicsEngine | |
| parent | Added buffer mode validation when binding buffer views (diff) | |
| download | DiligentCore-e7b18160a758b30dd6b701b4aa6f43c9c2061ccf.tar.gz DiligentCore-e7b18160a758b30dd6b701b4aa6f43c9c2061ccf.zip | |
All backends: added resource dimension validation when setting shader variables
Diffstat (limited to 'Graphics/GraphicsEngine')
| -rw-r--r-- | Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp | 61 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/interface/GraphicsTypes.h | 20 |
2 files changed, 68 insertions, 13 deletions
diff --git a/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp b/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp index f82f18cf..78c1832d 100644 --- a/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp +++ b/Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp @@ -215,6 +215,28 @@ inline const char* GetResourceTypeName<BUFFER_VIEW_TYPE>() return "buffer view"; } +inline RESOURCE_DIMENSION GetResourceViewDimension(const ITextureView* pTexView) +{ + VERIFY_EXPR(pTexView != nullptr); + return pTexView->GetDesc().TextureDim; +} + +inline RESOURCE_DIMENSION GetResourceViewDimension(const IBufferView* /*pBuffView*/) +{ + return RESOURCE_DIM_BUFFER; +} + +inline Uint32 GetResourceSampleCount(const ITextureView* pTexView) +{ + VERIFY_EXPR(pTexView != nullptr); + return const_cast<ITextureView*>(pTexView)->GetTexture()->GetDesc().SampleCount; +} + +inline Uint32 GetResourceSampleCount(const IBufferView* /*pBuffView*/) +{ + return 0; +} + template <typename ResourceAttribsType, typename ResourceViewImplType, typename ViewTypeEnumType> @@ -255,8 +277,6 @@ bool VerifyResourceViewBinding(const ResourceAttribsType& Attribs, if (!IsExpectedViewType) { - std::string ExpectedViewTypeName; - std::stringstream ss; ss << "Error binding " << ExpectedResourceType << " '" << pViewImpl->GetDesc().Name << "' to variable '" << Attribs.GetPrintName(ArrayIndex) << '\''; @@ -280,11 +300,45 @@ bool VerifyResourceViewBinding(const ResourceAttribsType& Attribs, BindingOK = false; } + + const auto ExpectedResourceDim = Attribs.GetResourceDimension(); + if (ExpectedResourceDim != RESOURCE_DIM_UNDEFINED) + { + auto ResourceDim = GetResourceViewDimension(pViewImpl); + if (ResourceDim != ExpectedResourceDim) + { + LOG_ERROR_MESSAGE("Error binding ", ExpectedResourceType, " '", pViewImpl->GetDesc().Name, "' to variable '", + Attribs.GetPrintName(ArrayIndex), "': incorrect resource dimension: ", + GetResourceDimString(ExpectedResourceDim), " is expected, but the actual dimension is ", + GetResourceDimString(ResourceDim)); + + BindingOK = false; + } + + if (ResourceDim == RESOURCE_DIM_TEX_2D || ResourceDim == RESOURCE_DIM_TEX_2D_ARRAY) + { + auto SampleCount = GetResourceSampleCount(pViewImpl); + auto IsMS = Attribs.IsMultisample(); + if (IsMS && SampleCount == 1) + { + LOG_ERROR_MESSAGE("Error binding ", ExpectedResourceType, " '", pViewImpl->GetDesc().Name, "' to variable '", + Attribs.GetPrintName(ArrayIndex), "': multisample texture is expected."); + BindingOK = false; + } + else if (!IsMS && SampleCount > 1) + { + LOG_ERROR_MESSAGE("Error binding ", ExpectedResourceType, " '", pViewImpl->GetDesc().Name, "' to variable '", + Attribs.GetPrintName(ArrayIndex), "': single-sample texture is expected."); + BindingOK = false; + } + } + } } if (VarType != SHADER_RESOURCE_VARIABLE_TYPE_DYNAMIC && pCachedView != nullptr && pCachedView != pViewImpl) { - auto VarTypeStr = GetShaderVariableTypeLiteralName(VarType); + const auto* VarTypeStr = GetShaderVariableTypeLiteralName(VarType); + std::stringstream ss; ss << "Non-null resource '" << pCachedView->GetDesc().Name << "' is already bound to " << VarTypeStr << " shader variable '" << Attribs.GetPrintName(ArrayIndex) << '\''; @@ -306,6 +360,7 @@ bool VerifyResourceViewBinding(const ResourceAttribsType& Attribs, BindingOK = false; } + return BindingOK; } diff --git a/Graphics/GraphicsEngine/interface/GraphicsTypes.h b/Graphics/GraphicsEngine/interface/GraphicsTypes.h index b681c498..74e16535 100644 --- a/Graphics/GraphicsEngine/interface/GraphicsTypes.h +++ b/Graphics/GraphicsEngine/interface/GraphicsTypes.h @@ -211,16 +211,16 @@ DEFINE_FLAG_ENUM_OPERATORS(MAP_FLAGS) /// - TextureViewDesc to describe texture view type DILIGENT_TYPED_ENUM(RESOURCE_DIMENSION, Uint8) { - RESOURCE_DIM_UNDEFINED = 0, ///< Texture type undefined - RESOURCE_DIM_BUFFER, ///< Buffer - RESOURCE_DIM_TEX_1D, ///< One-dimensional texture - RESOURCE_DIM_TEX_1D_ARRAY, ///< One-dimensional texture array - RESOURCE_DIM_TEX_2D, ///< Two-dimensional texture - RESOURCE_DIM_TEX_2D_ARRAY, ///< Two-dimensional texture array - RESOURCE_DIM_TEX_3D, ///< Three-dimensional texture - RESOURCE_DIM_TEX_CUBE, ///< Cube-map texture - RESOURCE_DIM_TEX_CUBE_ARRAY, ///< Cube-map array texture - RESOURCE_DIM_NUM_DIMENSIONS ///< Helper value that stores the total number of texture types in the enumeration + RESOURCE_DIM_UNDEFINED = 0, ///< Texture type undefined + RESOURCE_DIM_BUFFER, ///< Buffer + RESOURCE_DIM_TEX_1D, ///< One-dimensional texture + RESOURCE_DIM_TEX_1D_ARRAY, ///< One-dimensional texture array + RESOURCE_DIM_TEX_2D, ///< Two-dimensional texture + RESOURCE_DIM_TEX_2D_ARRAY, ///< Two-dimensional texture array + RESOURCE_DIM_TEX_3D, ///< Three-dimensional texture + RESOURCE_DIM_TEX_CUBE, ///< Cube-map texture + RESOURCE_DIM_TEX_CUBE_ARRAY, ///< Cube-map array texture + RESOURCE_DIM_NUM_DIMENSIONS ///< Helper value that stores the total number of texture types in the enumeration }; /// Texture view type |
