summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3DBase
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-10-14 08:04:05 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-10-14 08:04:05 +0000
commitb3fec8bd40e80115086281bce74774617aa95e23 (patch)
tree99c9b3250484d6a5f3283320aea8b7b90f3f30c1 /Graphics/GraphicsEngineD3DBase
parentShader variable access test: fixed issue with raw buffers in GL/VK/Metal (diff)
downloadDiligentCore-b3fec8bd40e80115086281bce74774617aa95e23.tar.gz
DiligentCore-b3fec8bd40e80115086281bce74774617aa95e23.zip
Added buffer mode validation when binding buffer views
Diffstat (limited to 'Graphics/GraphicsEngineD3DBase')
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.hpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.hpp b/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.hpp
index 0ea6e397..2497b17d 100644
--- a/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.hpp
+++ b/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.hpp
@@ -86,4 +86,53 @@ protected:
const SHADER_RESOURCE_VARIABLE_TYPE m_VariableType;
};
+
+template <typename BufferViewImplType>
+bool VerifyBufferViewModeD3D(BufferViewImplType* pViewD3D11, const D3DShaderResourceAttribs& Attribs, const char* ShaderName)
+{
+ if (pViewD3D11 == nullptr)
+ return true;
+
+ const auto& ViewDesc = pViewD3D11->GetDesc();
+ const auto& BuffDesc = pViewD3D11->GetBuffer()->GetDesc();
+
+ auto LogBufferBindingError = [&](const char* Msg) //
+ {
+ LOG_ERROR_MESSAGE("Error binding buffer view '", ViewDesc.Name, "' of buffer '", BuffDesc.Name,
+ "' to shader variable '", Attribs.Name, "' in shader '", ShaderName, "': ", Msg);
+ };
+
+ switch (Attribs.GetInputType())
+ {
+ case D3D_SIT_TEXTURE:
+ case D3D_SIT_UAV_RWTYPED:
+ if (BuffDesc.Mode != BUFFER_MODE_FORMATTED || ViewDesc.Format.ValueType == VT_UNDEFINED)
+ {
+ LogBufferBindingError("formatted buffer view is expected.");
+ return false;
+ }
+ break;
+
+ case D3D_SIT_STRUCTURED:
+ case D3D_SIT_UAV_RWSTRUCTURED:
+ if (BuffDesc.Mode != BUFFER_MODE_STRUCTURED)
+ {
+ LogBufferBindingError("structured buffer view is expected.");
+ return false;
+ }
+ break;
+
+ case D3D_SIT_BYTEADDRESS:
+ case D3D_SIT_UAV_RWBYTEADDRESS:
+ if (BuffDesc.Mode != BUFFER_MODE_RAW)
+ {
+ LogBufferBindingError("raw buffer view is expected.");
+ return false;
+ }
+ break;
+ }
+
+ return true;
+}
+
} // namespace Diligent