summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngine
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-10-19 18:41:13 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-10-19 18:41:13 +0000
commitf6181c0d90eb7a6135353113ea153942df276bdc (patch)
tree64da0ba73c1761b4ef61e82c60b4977e9439eb51 /Graphics/GraphicsEngine
parentAdded convenience constructor to LayoutElement struct (diff)
downloadDiligentCore-f6181c0d90eb7a6135353113ea153942df276bdc.tar.gz
DiligentCore-f6181c0d90eb7a6135353113ea153942df276bdc.zip
Reworked Draw and DispatchCompute commands (Updated API version to 240033)
Diffstat (limited to 'Graphics/GraphicsEngine')
-rw-r--r--Graphics/GraphicsEngine/include/DeviceContextBase.h230
-rw-r--r--Graphics/GraphicsEngine/interface/APIInfo.h2
-rw-r--r--Graphics/GraphicsEngine/interface/DeviceContext.h381
3 files changed, 432 insertions, 181 deletions
diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.h b/Graphics/GraphicsEngine/include/DeviceContextBase.h
index 44a5ed7f..f468f83a 100644
--- a/Graphics/GraphicsEngine/include/DeviceContextBase.h
+++ b/Graphics/GraphicsEngine/include/DeviceContextBase.h
@@ -193,19 +193,31 @@ protected:
inline void ClearStateCache();
#ifdef DEVELOPMENT
- bool DvpVerifyDrawArguments(const DrawAttribs& drawAttribs);
- void DvpVerifyRenderTargets();
- bool DvpVerifyDispatchArguments(const DispatchComputeAttribs &DispatchAttrs);
- void DvpVerifyStateTransitionDesc(const StateTransitionDesc& Barrier);
- bool DvpVerifyTextureState(const TextureImplType& Texture, RESOURCE_STATE RequiredState, const char* OperationName);
- bool DvpVerifyBufferState (const BufferImplType& Buffer, RESOURCE_STATE RequiredState, const char* OperationName);
+ bool DvpVerifyDrawArguments (const DrawAttribs& Attribs)const;
+ bool DvpVerifyDrawIndexedArguments (const DrawIndexedAttribs& Attribs)const;
+ bool DvpVerifyDrawIndirectArguments (const DrawIndirectAttribs& Attribs, const IBuffer* pAttribsBuffer)const;
+ bool DvpVerifyDrawIndexedIndirectArguments(const DrawIndexedIndirectAttribs& Attribs, const IBuffer* pAttribsBuffer)const;
+
+ bool DvpVerifyDispatchArguments (const DispatchComputeAttribs& Attribs)const;
+ bool DvpVerifyDispatchIndirectArguments(const DispatchComputeIndirectAttribs& Attribs, const IBuffer* pAttribsBuffer)const;
+
+ void DvpVerifyRenderTargets()const;
+ void DvpVerifyStateTransitionDesc(const StateTransitionDesc& Barrier)const;
+ bool DvpVerifyTextureState(const TextureImplType& Texture, RESOURCE_STATE RequiredState, const char* OperationName)const;
+ bool DvpVerifyBufferState (const BufferImplType& Buffer, RESOURCE_STATE RequiredState, const char* OperationName)const;
#else
-# define DvpVerifyDrawArguments (...)[](){return true;}()
-# define DvpVerifyRenderTargets (...)[](){return true;}()
-# define DvpVerifyDispatchArguments (...)[](){return true;}()
-# define DvpVerifyStateTransitionDesc(...)do{}while(false)
-# define DvpVerifyTextureState (...)[](){return true;}()
-# define DvpVerifyBufferState (...)[](){return true;}()
+ bool DvpVerifyDrawArguments (const DrawAttribs& Attribs)const {return true;}
+ bool DvpVerifyDrawIndexedArguments (const DrawIndexedAttribs& Attribs)const {return true;}
+ bool DvpVerifyDrawIndirectArguments (const DrawIndirectAttribs& Attribs, const IBuffer* pAttribsBuffer)const {return true;}
+ bool DvpVerifyDrawIndexedIndirectArguments(const DrawIndexedIndirectAttribs& Attribs, const IBuffer* pAttribsBuffer)const {return true;}
+
+ bool DvpVerifyDispatchArguments (const DispatchComputeAttribs& Attribs)const {return true;}
+ bool DvpVerifyDispatchIndirectArguments(const DispatchComputeIndirectAttribs& Attribs, const IBuffer* pAttribsBuffer)const {return true;}
+
+ void DvpVerifyRenderTargets()const {}
+ void DvpVerifyStateTransitionDesc(const StateTransitionDesc& Barrier)const {}
+ bool DvpVerifyTextureState(const TextureImplType& Texture, RESOURCE_STATE RequiredState, const char* OperationName)const {return true;}
+ bool DvpVerifyBufferState (const BufferImplType& Buffer, RESOURCE_STATE RequiredState, const char* OperationName)const {return true;}
#endif
/// Strong reference to the device.
@@ -871,41 +883,150 @@ inline void DeviceContextBase<BaseInterface,ImplementationTraits> ::
#ifdef DEVELOPMENT
template<typename BaseInterface, typename ImplementationTraits>
inline bool DeviceContextBase<BaseInterface,ImplementationTraits> ::
- DvpVerifyDrawArguments(const DrawAttribs& drawAttribs)
+ DvpVerifyDrawArguments(const DrawAttribs& Attribs)const
{
+ if ((Attribs.Flags & DRAW_FLAG_VERIFY_DRAW_ATTRIBS) == 0)
+ return true;
+
if (!m_pPipelineState)
{
- LOG_ERROR_MESSAGE("No pipeline state is bound for a draw command");
+ LOG_ERROR_MESSAGE("Draw command arguments are invalid: no pipeline state is bound.");
return false;
}
if (m_pPipelineState->GetDesc().IsComputePipeline)
{
- LOG_ERROR_MESSAGE("Pipeline state bound for a draw command is a compute pipeline");
+ LOG_ERROR_MESSAGE("Draw command arguments are invalid: pipeline state '", m_pPipelineState->GetDesc().Name, "' is a compute pipeline.");
+ return false;
+ }
+
+ if (Attribs.NumVertices == 0)
+ {
+ LOG_WARNING_MESSAGE("Draw command arguments are invalid: number of vertices to draw is zero.");
+ }
+
+ return true;
+}
+
+template<typename BaseInterface, typename ImplementationTraits>
+inline bool DeviceContextBase<BaseInterface,ImplementationTraits> ::
+ DvpVerifyDrawIndexedArguments(const DrawIndexedAttribs& Attribs)const
+{
+ if ((Attribs.Flags & DRAW_FLAG_VERIFY_DRAW_ATTRIBS) == 0)
+ return true;
+
+ if (!m_pPipelineState)
+ {
+ LOG_ERROR_MESSAGE("DrawIndexed command arguments are invalid: no pipeline state is bound.");
return false;
}
- if (drawAttribs.pIndirectDrawAttribs == nullptr)
+ if (m_pPipelineState->GetDesc().IsComputePipeline)
{
- if (drawAttribs.NumIndices == 0)
- LOG_WARNING_MESSAGE(drawAttribs.IsIndexed ? "Number of indices to draw is zero" : "Number of vertices to draw is zero");
+ LOG_ERROR_MESSAGE("DrawIndexed command arguments are invalid: pipeline state '", m_pPipelineState->GetDesc().Name, "' is a compute pipeline.");
+ return false;
+ }
- if (drawAttribs.NumInstances == 0)
+ if (Attribs.IndexType != VT_UINT16 && Attribs.IndexType != VT_UINT32)
+ {
+ LOG_ERROR_MESSAGE("DrawIndexed command arguments are invalid: IndexType (", GetValueTypeString(Attribs.IndexType), ") must be VT_UINT16 or VT_UINT32.");
+ return false;
+ }
+
+ if (!m_pIndexBuffer)
+ {
+ LOG_ERROR_MESSAGE("DrawIndexed command arguments are invalid: no index buffer is bound.");
+ return false;
+ }
+
+ if (Attribs.NumIndices == 0)
+ {
+ LOG_WARNING_MESSAGE("DrawIndexed command arguments are invalid: number of indices to draw is zero.");
+ }
+
+ return true;
+}
+
+template<typename BaseInterface, typename ImplementationTraits>
+inline bool DeviceContextBase<BaseInterface,ImplementationTraits> ::
+ DvpVerifyDrawIndirectArguments(const DrawIndirectAttribs& Attribs, const IBuffer* pAttribsBuffer)const
+{
+ if ((Attribs.Flags & DRAW_FLAG_VERIFY_DRAW_ATTRIBS) == 0)
+ return true;
+
+ if (!m_pPipelineState)
+ {
+ LOG_ERROR_MESSAGE("DrawIndirect command arguments are invalid: no pipeline state is bound.");
+ return false;
+ }
+
+ if (m_pPipelineState->GetDesc().IsComputePipeline)
+ {
+ LOG_ERROR_MESSAGE("DrawIndirect command arguments are invalid: pipeline state '", m_pPipelineState->GetDesc().Name, "' is a compute pipeline.");
+ return false;
+ }
+
+ if (pAttribsBuffer != nullptr)
+ {
+ if ((pAttribsBuffer->GetDesc().BindFlags & BIND_INDIRECT_DRAW_ARGS) == 0)
{
- LOG_ERROR_MESSAGE("Number of instances cannot be 0. Use 1 for a non-instanced draw command.");
+ LOG_ERROR_MESSAGE("DrawIndirect command arguments are invalid: indirect draw arguments buffer '",
+ pAttribsBuffer->GetDesc().Name, "' was not created with BIND_INDIRECT_DRAW_ARGS flag.");
return false;
}
}
+ else
+ {
+ LOG_ERROR_MESSAGE("DrawIndirect command arguments are invalid: indirect draw arguments buffer is null.");
+ return false;
+ }
- if (drawAttribs.IsIndexed && drawAttribs.IndexType != VT_UINT16 && drawAttribs.IndexType != VT_UINT32)
+ return true;
+}
+
+template<typename BaseInterface, typename ImplementationTraits>
+inline bool DeviceContextBase<BaseInterface,ImplementationTraits> ::
+ DvpVerifyDrawIndexedIndirectArguments(const DrawIndexedIndirectAttribs& Attribs, const IBuffer* pAttribsBuffer)const
+{
+ if ((Attribs.Flags & DRAW_FLAG_VERIFY_DRAW_ATTRIBS) == 0)
+ return true;
+
+ if (!m_pPipelineState)
+ {
+ LOG_ERROR_MESSAGE("DrawIndexedIndirect command arguments are invalid: no pipeline state is bound.");
+ return false;
+ }
+
+ if (m_pPipelineState->GetDesc().IsComputePipeline)
{
- LOG_ERROR_MESSAGE("For an indexed draw command IndexType must be VT_UINT16 or VT_UINT32");
+ LOG_ERROR_MESSAGE("DrawIndexedIndirect command arguments are invalid: pipeline state '", m_pPipelineState->GetDesc().Name, "' is a compute pipeline.");
+ return false;
+ }
+
+ if (Attribs.IndexType != VT_UINT16 && Attribs.IndexType != VT_UINT32)
+ {
+ LOG_ERROR_MESSAGE("DrawIndexedIndirect command arguments are invalid: IndexType (", GetValueTypeString(Attribs.IndexType), ") must be VT_UINT16 or VT_UINT32.");
return false;
}
- if (drawAttribs.IsIndexed && !m_pIndexBuffer)
+ if (!m_pIndexBuffer)
+ {
+ LOG_ERROR_MESSAGE("DrawIndexedIndirect command arguments are invalid: no index buffer is bound.");
+ return false;
+ }
+
+ if (pAttribsBuffer != nullptr)
+ {
+ if ((pAttribsBuffer->GetDesc().BindFlags & BIND_INDIRECT_DRAW_ARGS) == 0)
+ {
+ LOG_ERROR_MESSAGE("DrawIndexedIndirect command arguments are invalid: indirect draw arguments buffer '",
+ pAttribsBuffer->GetDesc().Name, "' was not created with BIND_INDIRECT_DRAW_ARGS flag.");
+ return false;
+ }
+ }
+ else
{
- LOG_ERROR_MESSAGE("No index buffer is bound for indexed draw command");
+ LOG_ERROR_MESSAGE("DrawIndexedIndirect command arguments are invalid: indirect draw arguments buffer is null.");
return false;
}
@@ -913,7 +1034,8 @@ inline bool DeviceContextBase<BaseInterface,ImplementationTraits> ::
}
template<typename BaseInterface, typename ImplementationTraits>
-inline void DeviceContextBase<BaseInterface,ImplementationTraits> :: DvpVerifyRenderTargets()
+inline void DeviceContextBase<BaseInterface,ImplementationTraits> ::
+ DvpVerifyRenderTargets()const
{
if (!m_pPipelineState)
{
@@ -979,38 +1101,70 @@ inline void DeviceContextBase<BaseInterface,ImplementationTraits> :: DvpVerifyRe
template<typename BaseInterface, typename ImplementationTraits>
inline bool DeviceContextBase<BaseInterface,ImplementationTraits> ::
- DvpVerifyDispatchArguments(const DispatchComputeAttribs& DispatchAttrs)
+ DvpVerifyDispatchArguments(const DispatchComputeAttribs& Attribs)const
{
if (!m_pPipelineState)
{
- LOG_ERROR("No pipeline state is bound for a dispatch command");
+ LOG_ERROR_MESSAGE("DispatchCompute command arguments are invalid: no pipeline state is bound.");
return false;
}
if (!m_pPipelineState->GetDesc().IsComputePipeline)
{
- LOG_ERROR("Pipeline state bound for a draw command is a graphics pipeline");
+ LOG_ERROR_MESSAGE("DispatchCompute command arguments are invalid: pipeline state '", m_pPipelineState->GetDesc().Name, "' is a graphics pipeline.");
return false;
}
- if(DispatchAttrs.pIndirectDispatchAttribs == nullptr)
+ if (Attribs.ThreadGroupCountX == 0)
+ LOG_WARNING_MESSAGE("DispatchCompute command arguments are invalid: ThreadGroupCountX is zero.");
+
+ if (Attribs.ThreadGroupCountY == 0)
+ LOG_WARNING_MESSAGE("DispatchCompute command arguments are invalid: ThreadGroupCountY is zero.");
+
+ if (Attribs.ThreadGroupCountZ == 0)
+ LOG_WARNING_MESSAGE("DispatchCompute command arguments are invalid: ThreadGroupCountZ is zero.");
+
+ return true;
+}
+
+template<typename BaseInterface, typename ImplementationTraits>
+inline bool DeviceContextBase<BaseInterface,ImplementationTraits> ::
+ DvpVerifyDispatchIndirectArguments(const DispatchComputeIndirectAttribs& Attribs, const IBuffer* pAttribsBuffer)const
+{
+ if (!m_pPipelineState)
{
- if (DispatchAttrs.ThreadGroupCountX == 0)
- LOG_WARNING_MESSAGE("ThreadGroupCountX is zero");
+ LOG_ERROR_MESSAGE("DispatchComputeIndirect command arguments are invalid: no pipeline state is bound.");
+ return false;
+ }
- if (DispatchAttrs.ThreadGroupCountY == 0)
- LOG_WARNING_MESSAGE("ThreadGroupCountY is zero");
+ if (!m_pPipelineState->GetDesc().IsComputePipeline)
+ {
+ LOG_ERROR_MESSAGE("DispatchComputeIndirect command arguments are invalid: pipeline state '", m_pPipelineState->GetDesc().Name, "' is a graphics pipeline.");
+ return false;
+ }
- if (DispatchAttrs.ThreadGroupCountZ == 0)
- LOG_WARNING_MESSAGE("ThreadGroupCountZ is zero");
+ if (pAttribsBuffer != nullptr)
+ {
+ if ((pAttribsBuffer->GetDesc().BindFlags & BIND_INDIRECT_DRAW_ARGS) == 0)
+ {
+ LOG_ERROR_MESSAGE("DispatchComputeIndirect command arguments are invalid: indirect dispatch arguments buffer '",
+ pAttribsBuffer->GetDesc().Name, "' was not created with BIND_INDIRECT_DRAW_ARGS flag.");
+ return false;
+ }
+ }
+ else
+ {
+ LOG_ERROR_MESSAGE("DispatchComputeIndirect command arguments are invalid: indirect dispatch arguments buffer is null.");
+ return false;
}
return true;
}
+
template<typename BaseInterface, typename ImplementationTraits>
void DeviceContextBase<BaseInterface,ImplementationTraits> ::
- DvpVerifyStateTransitionDesc(const StateTransitionDesc& Barrier)
+ DvpVerifyStateTransitionDesc(const StateTransitionDesc& Barrier)const
{
DEV_CHECK_ERR((Barrier.pTexture != nullptr) ^ (Barrier.pBuffer != nullptr), "Exactly one of pTexture or pBuffer members of StateTransitionDesc must not be null");
DEV_CHECK_ERR(Barrier.NewState != RESOURCE_STATE_UNKNOWN, "New resource state can't be unknown");
@@ -1067,7 +1221,7 @@ void DeviceContextBase<BaseInterface,ImplementationTraits> ::
template<typename BaseInterface, typename ImplementationTraits>
bool DeviceContextBase<BaseInterface,ImplementationTraits> ::
- DvpVerifyTextureState(const TextureImplType& Texture, RESOURCE_STATE RequiredState, const char* OperationName)
+ DvpVerifyTextureState(const TextureImplType& Texture, RESOURCE_STATE RequiredState, const char* OperationName)const
{
if (Texture.IsInKnownState() && !Texture.CheckState(RequiredState))
{
@@ -1082,7 +1236,7 @@ bool DeviceContextBase<BaseInterface,ImplementationTraits> ::
template<typename BaseInterface, typename ImplementationTraits>
bool DeviceContextBase<BaseInterface,ImplementationTraits> ::
- DvpVerifyBufferState(const BufferImplType& Buffer, RESOURCE_STATE RequiredState, const char* OperationName)
+ DvpVerifyBufferState(const BufferImplType& Buffer, RESOURCE_STATE RequiredState, const char* OperationName)const
{
if (Buffer.IsInKnownState() && !Buffer.CheckState(RequiredState))
{
diff --git a/Graphics/GraphicsEngine/interface/APIInfo.h b/Graphics/GraphicsEngine/interface/APIInfo.h
index 2d7d66f5..418291ae 100644
--- a/Graphics/GraphicsEngine/interface/APIInfo.h
+++ b/Graphics/GraphicsEngine/interface/APIInfo.h
@@ -26,7 +26,7 @@
/// \file
/// Diligent API information
-#define DILIGENT_API_VERSION 240032
+#define DILIGENT_API_VERSION 240033
#include "../../../Primitives/interface/BasicTypes.h"
diff --git a/Graphics/GraphicsEngine/interface/DeviceContext.h b/Graphics/GraphicsEngine/interface/DeviceContext.h
index dabeccd3..45f057c9 100644
--- a/Graphics/GraphicsEngine/interface/DeviceContext.h
+++ b/Graphics/GraphicsEngine/interface/DeviceContext.h
@@ -108,142 +108,201 @@ enum RESOURCE_STATE_TRANSITION_MODE : Uint8
RESOURCE_STATE_TRANSITION_MODE_VERIFY
};
+
/// Defines the draw command attributes.
-/// This structure is used by IRenderDevice::Draw().
+/// This structure is used by IDeviceContext::Draw().
struct DrawAttribs
{
- union
- {
- /// For a non-indexed draw call, number of vertices to draw.
- Uint32 NumVertices = 0;
-
- /// For an indexed draw call, number of indices to draw.
- Uint32 NumIndices;
- };
-
- /// 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;
+ /// The number of vertices to draw.
+ Uint32 NumVertices = 0;
/// Additional flags, see Diligent::DRAW_FLAGS.
- DRAW_FLAGS Flags = DRAW_FLAG_NONE;
-
- /// State transition mode for indirect draw arguments buffer. Ignored if pIndirectDrawAttribs member is null.
- RESOURCE_STATE_TRANSITION_MODE IndirectAttribsBufferStateTransitionMode = RESOURCE_STATE_TRANSITION_MODE_NONE;
+ DRAW_FLAGS Flags = DRAW_FLAG_NONE;
- /// Number of instances to draw. If more than one instance is specified,
+ /// The number of instances to draw. If more than one instance is specified,
/// instanced draw call will be performed.
- Uint32 NumInstances = 1;
-
- /// For indexed rendering, a constant which is added to each index before
- /// accessing the vertex buffer.
- Uint32 BaseVertex = 0;
+ Uint32 NumInstances = 1;
- /// 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;
+ /// LOCATION (or INDEX, but NOT the byte offset) of the first vertex in the
+ /// vertex buffer to start reading vertices from.
+ Uint32 StartVertexLocation = 0;
- union
- {
- /// For non-indexed rendering, LOCATION (or INDEX, but NOT the byte offset) of the
- /// first vertex in the vertex buffer to start reading vertices from.
- Uint32 StartVertexLocation = 0;
-
- /// For indexed rendering, LOCATION (NOT the byte offset) of the first index in
- /// the index buffer to start reading indices from.
- Uint32 FirstIndexLocation;
- };
- /// For instanced rendering, LOCATION (or INDEX, but NOT the byte offset) in the vertex
- /// buffer to start reading instance data from.
- Uint32 FirstInstanceLocation = 0;
+ /// LOCATION (or INDEX, but NOT the byte offset) in the vertex buffer to start
+ /// reading instance data from.
+ Uint32 FirstInstanceLocation = 0;
- /// For indirect rendering, pointer to the buffer, from which
- /// draw attributes will be read.
- IBuffer* pIndirectDrawAttribs = nullptr;
-
- /// Initializes the structure members with default values
+ /// Initializes the structure members with default values.
/// Default values:
+ ///
/// Member | Default value
/// -----------------------------------------|--------------------------------------
/// NumVertices | 0
- /// IsIndexed | False
- /// IndexType | VT_UNDEFINED
- /// IndirectAttribsBufferStateTransitionMode | RESOURCE_STATE_TRANSITION_MODE_NONE
/// Flags | DRAW_FLAG_NONE
/// NumInstances | 1
- /// BaseVertex | 0
- /// IndirectDrawArgsOffset | 0
/// StartVertexLocation | 0
/// FirstInstanceLocation | 0
- /// pIndirectDrawAttribs | nullptr
DrawAttribs()noexcept{}
- /// Initializes the structure to perform non-indexed draw call.
+ /// Initializes the structure with user-specified values.
DrawAttribs(Uint32 _NumVertices,
DRAW_FLAGS _Flags,
Uint32 _NumInstances = 1,
- Uint32 _BaseVertex = 0,
Uint32 _StartVertexLocation = 0,
Uint32 _FirstInstanceLocation = 0)noexcept :
- NumVertices (_NumVertices),
- Flags (_Flags),
- NumInstances (_NumInstances),
- BaseVertex (_BaseVertex),
- StartVertexLocation (_StartVertexLocation),
- FirstInstanceLocation(_FirstInstanceLocation)
+ NumVertices {_NumVertices },
+ Flags {_Flags },
+ NumInstances {_NumInstances },
+ StartVertexLocation {_StartVertexLocation },
+ FirstInstanceLocation{_FirstInstanceLocation}
{}
+};
+
+
+/// Defines the indexed draw command attributes.
+
+/// This structure is used by IDeviceContext::DrawIndexed().
+struct DrawIndexedAttribs
+{
+ /// The number of indices to draw.
+ Uint32 NumIndices = 0;
+
+ /// The type of elements in the index buffer.
+ /// Allowed values: VT_UINT16 and VT_UINT32.
+ VALUE_TYPE IndexType = VT_UNDEFINED;
+
+ /// Additional flags, see Diligent::DRAW_FLAGS.
+ DRAW_FLAGS Flags = DRAW_FLAG_NONE;
+
+ /// Number of instances to draw. If more than one instance is specified,
+ /// instanced draw call will be performed.
+ Uint32 NumInstances = 1;
+
+ /// A constant which is added to each index before accessing the vertex buffer.
+ Uint32 BaseVertex = 0;
+
+ /// LOCATION (NOT the byte offset) of the first index in
+ /// the index buffer to start reading indices from.
+ Uint32 FirstIndexLocation = 0;
+
+ /// LOCATION (or INDEX, but NOT the byte offset) in the vertex
+ /// buffer to start reading instance data from.
+ Uint32 FirstInstanceLocation = 0;
+
+
+ /// Initializes the structure members with default values.
- /// Initializes the structure to perform indexed draw call.
- DrawAttribs(Uint32 _NumIndices,
- VALUE_TYPE _IndexType,
- DRAW_FLAGS _Flags,
- Uint32 _NumInstances = 1,
- Uint32 _BaseVertex = 0,
- Uint32 _FirstIndexLocation = 0,
- Uint32 _FirstInstanceLocation = 0)noexcept :
- NumIndices (_NumIndices),
- IsIndexed (true),
- IndexType (_IndexType),
- Flags (_Flags),
- NumInstances (_NumInstances),
- BaseVertex (_BaseVertex),
- FirstIndexLocation (_FirstIndexLocation),
- FirstInstanceLocation(_FirstInstanceLocation)
+ /// Default values:
+ /// Member | Default value
+ /// -----------------------------------------|--------------------------------------
+ /// NumIndices | 0
+ /// IndexType | VT_UNDEFINED
+ /// Flags | DRAW_FLAG_NONE
+ /// NumInstances | 1
+ /// BaseVertex | 0
+ /// FirstIndexLocation | 0
+ /// FirstInstanceLocation | 0
+ DrawIndexedAttribs()noexcept{}
+
+ /// Initializes the structure members with user-specified values.
+ DrawIndexedAttribs(Uint32 _NumIndices,
+ VALUE_TYPE _IndexType,
+ DRAW_FLAGS _Flags,
+ Uint32 _NumInstances = 1,
+ Uint32 _BaseVertex = 0,
+ Uint32 _FirstIndexLocation = 0,
+ Uint32 _FirstInstanceLocation = 0)noexcept :
+ NumIndices {_NumIndices },
+ IndexType {_IndexType },
+ Flags {_Flags },
+ NumInstances {_NumInstances },
+ BaseVertex {_BaseVertex },
+ FirstIndexLocation {_FirstIndexLocation },
+ FirstInstanceLocation{_FirstInstanceLocation}
{}
+};
- /// Initializes the structure to perform non-indexed indirect draw call.
- DrawAttribs(IBuffer* _pIndirectDrawAttribs,
- DRAW_FLAGS _Flags,
- RESOURCE_STATE_TRANSITION_MODE _IndirectAttribsBufferStateTransitionMode,
- Uint32 _IndirectDrawArgsOffset = 0)noexcept :
- Flags (_Flags),
- IndirectAttribsBufferStateTransitionMode(_IndirectAttribsBufferStateTransitionMode),
- IndirectDrawArgsOffset (_IndirectDrawArgsOffset),
- pIndirectDrawAttribs (_pIndirectDrawAttribs)
+/// Defines the indirect draw command attributes.
+
+/// This structure is used by IDeviceContext::DrawIndirect().
+struct DrawIndirectAttribs
+{
+ /// Additional flags, see Diligent::DRAW_FLAGS.
+ DRAW_FLAGS Flags = DRAW_FLAG_NONE;
+
+ /// State transition mode for indirect draw arguments buffer.
+ RESOURCE_STATE_TRANSITION_MODE IndirectAttribsBufferStateTransitionMode = RESOURCE_STATE_TRANSITION_MODE_NONE;
+
+ /// Offset from the beginning of the buffer to the location of draw command attributes.
+ Uint32 IndirectDrawArgsOffset = 0;
+
+ /// Initializes the structure members with default values
+
+ /// Default values:
+ /// Member | Default value
+ /// -----------------------------------------|--------------------------------------
+ /// Flags | DRAW_FLAG_NONE
+ /// IndirectAttribsBufferStateTransitionMode | RESOURCE_STATE_TRANSITION_MODE_NONE
+ /// IndirectDrawArgsOffset | 0
+ DrawIndirectAttribs()noexcept{}
+
+ /// Initializes the structure members with user-specified values.
+ DrawIndirectAttribs(DRAW_FLAGS _Flags,
+ RESOURCE_STATE_TRANSITION_MODE _IndirectAttribsBufferStateTransitionMode,
+ Uint32 _IndirectDrawArgsOffset = 0)noexcept :
+ Flags {_Flags },
+ IndirectAttribsBufferStateTransitionMode{_IndirectAttribsBufferStateTransitionMode},
+ IndirectDrawArgsOffset {_IndirectDrawArgsOffset }
{}
+};
+
+
+/// Defines the indexed indirect draw command attributes.
+
+/// This structure is used by IDeviceContext::DrawIndexedIndirect().
+struct DrawIndexedIndirectAttribs
+{
+ /// The type of the elements in the index buffer.
+ /// Allowed values: VT_UINT16 and VT_UINT32. Ignored if DrawAttribs::IsIndexed is False.
+ VALUE_TYPE IndexType = VT_UNDEFINED;
+
+ /// Additional flags, see Diligent::DRAW_FLAGS.
+ DRAW_FLAGS Flags = DRAW_FLAG_NONE;
+
+ /// State transition mode for indirect draw arguments buffer.
+ RESOURCE_STATE_TRANSITION_MODE IndirectAttribsBufferStateTransitionMode = RESOURCE_STATE_TRANSITION_MODE_NONE;
+
+ /// Offset from the beginning of the buffer to the location of draw command attributes.
+ Uint32 IndirectDrawArgsOffset = 0;
+
- /// Initializes the structure to perform indirect indexed draw call.
- DrawAttribs(IBuffer* _pIndirectDrawAttribs,
- VALUE_TYPE _IndexType,
- DRAW_FLAGS _Flags,
- RESOURCE_STATE_TRANSITION_MODE _IndirectAttribsBufferStateTransitionMode,
- Uint32 _IndirectDrawArgsOffset = 0)noexcept :
- IsIndexed (true),
- IndexType (_IndexType),
- Flags (_Flags),
- IndirectAttribsBufferStateTransitionMode(_IndirectAttribsBufferStateTransitionMode),
- IndirectDrawArgsOffset (_IndirectDrawArgsOffset),
- pIndirectDrawAttribs (_pIndirectDrawAttribs)
+ /// Initializes the structure members with default values
+
+ /// Default values:
+ /// Member | Default value
+ /// -----------------------------------------|--------------------------------------
+ /// IndexType | VT_UNDEFINED
+ /// Flags | DRAW_FLAG_NONE
+ /// IndirectAttribsBufferStateTransitionMode | RESOURCE_STATE_TRANSITION_MODE_NONE
+ /// IndirectDrawArgsOffset | 0
+ DrawIndexedIndirectAttribs()noexcept{}
+
+ /// Initializes the structure members with user-specified values.
+ DrawIndexedIndirectAttribs(VALUE_TYPE _IndexType,
+ DRAW_FLAGS _Flags,
+ RESOURCE_STATE_TRANSITION_MODE _IndirectAttribsBufferStateTransitionMode,
+ Uint32 _IndirectDrawArgsOffset = 0)noexcept :
+ IndexType {_IndexType },
+ Flags {_Flags },
+ IndirectAttribsBufferStateTransitionMode{_IndirectAttribsBufferStateTransitionMode},
+ IndirectDrawArgsOffset {_IndirectDrawArgsOffset }
{}
};
+
/// Defines which parts of the depth-stencil buffer to clear.
/// These flags are used by IDeviceContext::ClearDepthStencil().
@@ -270,48 +329,35 @@ struct DispatchComputeAttribs
Uint32 ThreadGroupCountY = 1; ///< Number of groups dispatched in Y direction.
Uint32 ThreadGroupCountZ = 1; ///< Number of groups dispatched in Z direction.
- /// Pointer to the buffer containing dispatch arguments.
- /// If not nullptr, then indirect dispatch command is executed, and
- /// ThreadGroupCountX, ThreadGroupCountY, and ThreadGroupCountZ are ignored.
- IBuffer* pIndirectDispatchAttribs = nullptr;
-
- /// If pIndirectDispatchAttribs is not nullptr, indicates offset from the beginning
- /// of the buffer to the dispatch command arguments. Ignored otherwise.
- Uint32 DispatchArgsByteOffset = 0;
+ DispatchComputeAttribs()noexcept{}
+
+ /// Initializes the structure with user-specified values.
+ DispatchComputeAttribs(Uint32 GroupsX, Uint32 GroupsY, Uint32 GroupsZ = 1)noexcept :
+ ThreadGroupCountX {GroupsX},
+ ThreadGroupCountY {GroupsY},
+ ThreadGroupCountZ {GroupsZ}
+ {}
+};
+
+/// Describes dispatch command arguments.
- /// State transition mode for indirect dispatch attributes buffer. This member is ignored if pIndirectDispatchAttribs member is null.
+/// This structure is used by IDeviceContext::DispatchComputeIndirect().
+struct DispatchComputeIndirectAttribs
+{
+ /// State transition mode for indirect dispatch attributes buffer.
RESOURCE_STATE_TRANSITION_MODE IndirectAttribsBufferStateTransitionMode = RESOURCE_STATE_TRANSITION_MODE_NONE;
- DispatchComputeAttribs()noexcept{}
+ /// The offset from the beginning of the buffer to the dispatch command arguments.
+ Uint32 DispatchArgsByteOffset = 0;
- /// Initializes the structure to perform non-indirect dispatch command.
-
- /// \param [in] GroupsX - Number of groups dispatched in X direction. Default value is 1.
- /// \param [in] GroupsY - Number of groups dispatched in Y direction. Default value is 1.
- /// \param [in] GroupsZ - Number of groups dispatched in Z direction. Default value is 1.
- explicit
- DispatchComputeAttribs(Uint32 GroupsX, Uint32 GroupsY = 1, Uint32 GroupsZ = 1)noexcept :
- ThreadGroupCountX (GroupsX),
- ThreadGroupCountY (GroupsY),
- ThreadGroupCountZ (GroupsZ),
- pIndirectDispatchAttribs(nullptr),
- DispatchArgsByteOffset (0)
- {}
+ DispatchComputeIndirectAttribs()noexcept{}
- /// Initializes the structure to perform indirect dispatch command.
-
- /// \param [in] pDispatchAttribs - Pointer to the buffer containing dispatch arguments.
- /// \param [in] Offset - Offset from the beginning of the buffer to the dispatch command
- /// arguments. Default value is 0.
- DispatchComputeAttribs(IBuffer* pDispatchAttribs,
- RESOURCE_STATE_TRANSITION_MODE StateTransitionMode,
- Uint32 Offset = 0) :
- ThreadGroupCountX (0),
- ThreadGroupCountY (0),
- ThreadGroupCountZ (0),
- pIndirectDispatchAttribs (pDispatchAttribs),
- DispatchArgsByteOffset (Offset),
- IndirectAttribsBufferStateTransitionMode(StateTransitionMode)
+ /// Initializes the structure with user-specified values.
+ explicit
+ DispatchComputeIndirectAttribs(RESOURCE_STATE_TRANSITION_MODE StateTransitionMode,
+ Uint32 Offset = 0) :
+ IndirectAttribsBufferStateTransitionMode{StateTransitionMode},
+ DispatchArgsByteOffset {Offset }
{}
};
@@ -688,10 +734,37 @@ public:
/// Executes a draw command.
- /// \param [in] DrawAttribs - Structure describing draw command attributes, see Diligent::DrawAttribs for details.
+ /// \param [in] Attribs - Draw command attributes, see Diligent::DrawAttribs for details.
+ ///
+ /// \remarks If Diligent::DRAW_FLAG_VERIFY_STATES flag is set, the method reads the state of vertex
+ /// buffers, so no other threads are allowed to alter the states of the same resources.
+ /// It is OK to read these states.
+ ///
+ /// If the application intends to use the same resources in other threads simultaneously, it needs to
+ /// explicitly manage the states using IDeviceContext::TransitionResourceStates() method.
+ virtual void Draw(const DrawAttribs& Attribs) = 0;
+
+
+ /// Executes an indexed draw command.
+
+ /// \param [in] Attribs - Draw command attributes, see Diligent::DrawIndexedAttribs for details.
+ ///
+ /// \remarks If Diligent::DRAW_FLAG_VERIFY_STATES flag is set, the method reads the state of vertex/index
+ /// buffers, so no other threads are allowed to alter the states of the same resources.
+ /// It is OK to read these states.
+ ///
+ /// If the application intends to use the same resources in other threads simultaneously, it needs to
+ /// explicitly manage the states using IDeviceContext::TransitionResourceStates() method.
+ virtual void DrawIndexed(const DrawIndexedAttribs& Attribs) = 0;
+
+
+ /// Executes an indirect draw command.
+
+ /// \param [in] Attribs - Structure describing the command attributes, see Diligent::DrawIndirectAttribs for details.
+ /// \param [in] pAttribsBuffer - Pointer to the buffer, from which indirect draw attributes will be read.
///
/// \remarks If IndirectAttribsBufferStateTransitionMode member is Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION,
- /// the method may transition the state of indirect draw arguments buffer. This is not a thread safe operation,
+ /// the method may transition the state of the indirect draw arguments buffer. This is not a thread safe operation,
/// so no other thread is allowed to read or write the state of the buffer.
///
/// If Diligent::DRAW_FLAG_VERIFY_STATES flag is set, the method reads the state of vertex/index
@@ -700,13 +773,37 @@ public:
///
/// If the application intends to use the same resources in other threads simultaneously, it needs to
/// explicitly manage the states using IDeviceContext::TransitionResourceStates() method.
- virtual void Draw(DrawAttribs &DrawAttribs) = 0;
-
+ virtual void DrawIndirect(const DrawIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) = 0;
+
+
+ /// Executes an indexed indirect draw command.
+
+ /// \param [in] Attribs - Structure describing the command attributes, see Diligent::DrawIndexedIndirectAttribs for details.
+ /// \param [in] pAttribsBuffer - Pointer to the buffer, from which indirect draw attributes will be read.
+ ///
+ /// \remarks If IndirectAttribsBufferStateTransitionMode member is Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION,
+ /// the method may transition the state of the indirect draw arguments buffer. This is not a thread safe operation,
+ /// so no other thread is allowed to read or write the state of the buffer.
+ ///
+ /// If Diligent::DRAW_FLAG_VERIFY_STATES flag is set, the method reads the state of vertex/index
+ /// buffers, so no other threads are allowed to alter the states of the same resources.
+ /// It is OK to read these states.
+ ///
+ /// If the application intends to use the same resources in other threads simultaneously, it needs to
+ /// explicitly manage the states using IDeviceContext::TransitionResourceStates() method.
+ virtual void DrawIndexedIndirect(const DrawIndexedIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) = 0;
+
/// Executes a dispatch compute command.
- /// \param [in] DispatchAttrs - Structure describing dispatch command attributes,
- /// see Diligent::DispatchComputeAttribs for details.
+ /// \param [in] Attribs - Dispatch command attributes, see Diligent::DispatchComputeAttribs for details.
+ virtual void DispatchCompute(const DispatchComputeAttribs& Attribs) = 0;
+
+
+ /// Executes an indirect dispatch compute command.
+
+ /// \param [in] Attribs - The command attributes, see Diligent::DispatchComputeIndirectAttribs for details.
+ /// \param [in] pAttribsBuffer - Pointer to the buffer containing indirect dispatch arguments.
///
/// \remarks If IndirectAttribsBufferStateTransitionMode member is Diligent::RESOURCE_STATE_TRANSITION_MODE_TRANSITION,
/// the method may transition the state of indirect dispatch arguments buffer. This is not a thread safe operation,
@@ -714,7 +811,7 @@ public:
///
/// If the application intends to use the same resources in other threads simultaneously, it needs to
/// explicitly manage the states using IDeviceContext::TransitionResourceStates() method.
- virtual void DispatchCompute(const DispatchComputeAttribs &DispatchAttrs) = 0;
+ virtual void DispatchComputeIndirect(const DispatchComputeIndirectAttribs& Attribs, IBuffer* pAttribsBuffer) = 0;
/// Clears a depth-stencil view.