summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngine
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-08-26 22:57:45 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-08-26 22:57:45 +0000
commit9ae620ef8cb2e876af331c3c330d42f68ba2f76e (patch)
tree4778f18d3fd95faea1de4a1873444fb022ae2e6e /Graphics/GraphicsEngine
parentUpdated readme (diff)
downloadDiligentCore-9ae620ef8cb2e876af331c3c330d42f68ba2f76e.tar.gz
DiligentCore-9ae620ef8cb2e876af331c3c330d42f68ba2f76e.zip
Added draw/dispatch command argument validation
Removed DrawAttribs::IsIndirect
Diffstat (limited to 'Graphics/GraphicsEngine')
-rw-r--r--Graphics/GraphicsEngine/include/DeviceContextBase.h71
-rw-r--r--Graphics/GraphicsEngine/interface/DeviceContext.h21
2 files changed, 79 insertions, 13 deletions
diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.h b/Graphics/GraphicsEngine/include/DeviceContextBase.h
index 8eb752d1..a1052c9b 100644
--- a/Graphics/GraphicsEngine/include/DeviceContextBase.h
+++ b/Graphics/GraphicsEngine/include/DeviceContextBase.h
@@ -141,6 +141,11 @@ protected:
/// Clears all cached resources
inline void ClearStateCache();
+#ifdef DEVELOPMENT
+ bool DvpVerifyDrawArguments(const DrawAttribs& drawAttribs);
+ bool DvpVerifyDispatchArguments(const DispatchComputeAttribs &DispatchAttrs);
+#endif
+
/// Strong reference to the device.
RefCntAutoPtr<IRenderDevice> m_pDevice;
@@ -619,4 +624,70 @@ inline void DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType
m_pBoundDepthStencil.Release();
}
+#ifdef DEVELOPMENT
+template<typename BaseInterface, typename BufferImplType, typename TextureViewImplType, typename PipelineStateImplType>
+inline bool DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType, PipelineStateImplType> :: DvpVerifyDrawArguments(const DrawAttribs& drawAttribs)
+{
+ if (!m_pPipelineState)
+ {
+ LOG_ERROR("No pipeline state is bound for a draw command");
+ return false;
+ }
+
+ if (m_pPipelineState->GetDesc().IsComputePipeline)
+ {
+ LOG_ERROR("Pipeline state bound for a draw command is a compute pipeline");
+ return false;
+ }
+
+ if (drawAttribs.NumIndices == 0)
+ {
+ LOG_WARNING_MESSAGE(drawAttribs.IsIndexed ? "Number of indices to draw is zero" : "Number of vertices to draw is zero");
+ }
+
+ if (drawAttribs.NumInstances == 0)
+ {
+ LOG_ERROR("Number of instances cannot be 0. Use 1 for a non-instanced draw command.");
+ return false;
+ }
+
+ if (drawAttribs.IsIndexed && drawAttribs.IndexType != VT_UINT16 && drawAttribs.IndexType != VT_UINT32)
+ {
+ LOG_ERROR("For an indexed draw command IndexType must be VT_UINT16 or VT_UINT32");
+ return false;
+ }
+
+ return true;
+}
+
+template<typename BaseInterface, typename BufferImplType, typename TextureViewImplType, typename PipelineStateImplType>
+inline bool DeviceContextBase<BaseInterface, BufferImplType, TextureViewImplType, PipelineStateImplType> :: DvpVerifyDispatchArguments(const DispatchComputeAttribs &DispatchAttrs)
+{
+ if (!m_pPipelineState)
+ {
+ LOG_ERROR("No pipeline state is bound for a dispatch command");
+ return false;
+ }
+
+ if (!m_pPipelineState->GetDesc().IsComputePipeline)
+ {
+ LOG_ERROR("Pipeline state bound for a draw command is a graphics pipeline");
+ return false;
+ }
+
+ if (DispatchAttrs.ThreadGroupCountX == 0)
+ LOG_WARNING_MESSAGE("ThreadGroupCountX is zero");
+
+ if (DispatchAttrs.ThreadGroupCountY == 0)
+ LOG_WARNING_MESSAGE("ThreadGroupCountY is zero");
+
+ if (DispatchAttrs.ThreadGroupCountZ == 0)
+ LOG_WARNING_MESSAGE("ThreadGroupCountZ is zero");
+
+ return true;
+}
+
+#endif
+
+
}
diff --git a/Graphics/GraphicsEngine/interface/DeviceContext.h b/Graphics/GraphicsEngine/interface/DeviceContext.h
index 72904ecd..ccbe8745 100644
--- a/Graphics/GraphicsEngine/interface/DeviceContext.h
+++ b/Graphics/GraphicsEngine/interface/DeviceContext.h
@@ -64,28 +64,24 @@ struct DrawAttribs
/// For an indexed draw call, number of indices to draw
Uint32 NumIndices;
};
- /// For an indexed draw call, type of elements in the index buffer.
- /// Allowed values: VT_UINT16 and VT_UINT32. Ignored if DrawAttribs::IsIndexed is False.
- VALUE_TYPE IndexType = VT_UNDEFINED;
/// Indicates if index buffer will be used to index input vertices
Bool IsIndexed = False;
+ /// For an indexed draw call, type of elements in the index buffer.
+ /// Allowed values: VT_UINT16 and VT_UINT32. Ignored if DrawAttribs::IsIndexed is False.
+ VALUE_TYPE IndexType = VT_UNDEFINED;
+
/// Number of instances to draw. If more than one instance is specified,
/// instanced draw call will be performed.
Uint32 NumInstances = 1;
- /// Indicates if indirect draw call will be performed. If set to True,
- /// pIndirectDrawAttribs must contain valid pointer to the buffer, from which
- /// draw attributes will be read.
- Bool IsIndirect = False;
-
/// For indexed rendering, a constant which is added to each index before
/// accessing the vertex buffer.
Uint32 BaseVertex = 0;
- /// For indirect rendering, offset from the beginning of the buffer to the
- /// location of draw command attributes. Ignored if DrawAttribs::IsIndirect is False.
+ /// For indirect rendering, offset from the beginning of the buffer to the location
+ /// of draw command attributes. Ignored if DrawAttribs::pIndirectDrawAttribs is null.
Uint32 IndirectDrawArgsOffset = 0;
union
@@ -103,7 +99,7 @@ struct DrawAttribs
Uint32 FirstInstanceLocation = 0;
/// For indirect rendering, pointer to the buffer, from which
- /// draw attributes will be read. Ignored if DrawAttribs::IsIndirect is False.
+ /// draw attributes will be read.
IBuffer* pIndirectDrawAttribs = nullptr;
@@ -113,10 +109,9 @@ struct DrawAttribs
/// Member | Default value
/// ------------------------|--------------
/// NumVertices | 0
- /// IndexType | VT_UNDEFINED
/// IsIndexed | False
+ /// IndexType | VT_UNDEFINED
/// NumInstances | 1
- /// IsIndirect | False
/// BaseVertex | 0
/// IndirectDrawArgsOffset | 0
/// StartVertexLocation | 0