summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngine
diff options
context:
space:
mode:
authorazhirnov <zh1dron@gmail.com>2020-10-17 17:03:38 +0000
committerazhirnov <zh1dron@gmail.com>2020-10-17 17:03:38 +0000
commit5b479de14d5893f6f27b15e7ce9c1740f6bcafe8 (patch)
tree9075d3810d8ed5bdb6ca5a9b27d54e56435023dd /Graphics/GraphicsEngine
parentFixed compilation, some fixes after review (diff)
parentAll backends: added resource dimension validation when setting shader variables (diff)
downloadDiligentCore-5b479de14d5893f6f27b15e7ce9c1740f6bcafe8.tar.gz
DiligentCore-5b479de14d5893f6f27b15e7ce9c1740f6bcafe8.zip
Merge branch 'master' into pso_refactoring
Diffstat (limited to 'Graphics/GraphicsEngine')
-rw-r--r--Graphics/GraphicsEngine/include/BufferBase.hpp10
-rw-r--r--Graphics/GraphicsEngine/include/ShaderResourceVariableBase.hpp61
-rw-r--r--Graphics/GraphicsEngine/include/TextureBase.hpp3
-rw-r--r--Graphics/GraphicsEngine/interface/GraphicsTypes.h20
4 files changed, 79 insertions, 15 deletions
diff --git a/Graphics/GraphicsEngine/include/BufferBase.hpp b/Graphics/GraphicsEngine/include/BufferBase.hpp
index 9ae6db92..605bc2ed 100644
--- a/Graphics/GraphicsEngine/include/BufferBase.hpp
+++ b/Graphics/GraphicsEngine/include/BufferBase.hpp
@@ -30,12 +30,14 @@
/// \file
/// Implementation of the Diligent::BufferBase template class
+#include <memory>
+
#include "Buffer.h"
#include "GraphicsTypes.h"
#include "DeviceObjectBase.hpp"
#include "GraphicsAccessories.hpp"
#include "STDAllocator.hpp"
-#include <memory>
+#include "FormatString.hpp"
namespace Diligent
{
@@ -232,6 +234,9 @@ void BufferBase<BaseInterface, RenderDeviceImplType, BufferViewImplType, TBuffVi
{
BufferViewDesc ViewDesc;
ViewDesc.ViewType = BUFFER_VIEW_UNORDERED_ACCESS;
+ auto UAVName = FormatString("Default UAV of buffer '", this->m_Desc.Name, '\'');
+ ViewDesc.Name = UAVName.c_str();
+
IBufferView* pUAV = nullptr;
CreateViewInternal(ViewDesc, &pUAV, true);
m_pDefaultUAV.reset(static_cast<BufferViewImplType*>(pUAV));
@@ -242,6 +247,9 @@ void BufferBase<BaseInterface, RenderDeviceImplType, BufferViewImplType, TBuffVi
{
BufferViewDesc ViewDesc;
ViewDesc.ViewType = BUFFER_VIEW_SHADER_RESOURCE;
+ auto SRVName = FormatString("Default SRV of buffer '", this->m_Desc.Name, '\'');
+ ViewDesc.Name = SRVName.c_str();
+
IBufferView* pSRV = nullptr;
CreateViewInternal(ViewDesc, &pSRV, true);
m_pDefaultSRV.reset(static_cast<BufferViewImplType*>(pSRV));
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/include/TextureBase.hpp b/Graphics/GraphicsEngine/include/TextureBase.hpp
index 1805f7d3..559df1ea 100644
--- a/Graphics/GraphicsEngine/include/TextureBase.hpp
+++ b/Graphics/GraphicsEngine/include/TextureBase.hpp
@@ -30,13 +30,14 @@
/// \file
/// Implementation of the Diligent::TextureBase template class
+#include <memory>
+
#include "Texture.h"
#include "GraphicsTypes.h"
#include "DeviceObjectBase.hpp"
#include "GraphicsAccessories.hpp"
#include "STDAllocator.hpp"
#include "FormatString.hpp"
-#include <memory>
namespace Diligent
{
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