summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineVulkan
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/GraphicsEngineVulkan
parentUpdated readme (diff)
downloadDiligentCore-9ae620ef8cb2e876af331c3c330d42f68ba2f76e.tar.gz
DiligentCore-9ae620ef8cb2e876af331c3c330d42f68ba2f76e.zip
Added draw/dispatch command argument validation
Removed DrawAttribs::IsIndirect
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
-rw-r--r--Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp73
1 files changed, 23 insertions, 50 deletions
diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
index 16885c3d..c6746b1d 100644
--- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
@@ -385,24 +385,16 @@ namespace Diligent
LOG_ERROR_MESSAGE(ss.str());
}
- void DeviceContextVkImpl::Draw( DrawAttribs &DrawAttribs )
+ void DeviceContextVkImpl::Draw( DrawAttribs &drawAttribs )
{
#ifdef DEVELOPMENT
- if (!m_pPipelineState)
- {
- LOG_ERROR("No pipeline state is bound");
+ if (!DvpVerifyDrawArguments(drawAttribs))
return;
- }
- if (m_pPipelineState->GetDesc().IsComputePipeline)
- {
- LOG_ERROR("No graphics pipeline state is bound");
- return;
- }
#endif
EnsureVkCmdBuffer();
- if ( DrawAttribs.IsIndexed )
+ if ( drawAttribs.IsIndexed )
{
#ifdef DEVELOPMENT
if (m_pIndexBuffer == nullptr)
@@ -416,8 +408,8 @@ namespace Diligent
if (!pBuffVk->CheckAccessFlags(VK_ACCESS_INDEX_READ_BIT))
BufferMemoryBarrier(*pBuffVk, VK_ACCESS_INDEX_READ_BIT);
- DEV_CHECK_ERR(DrawAttribs.IndexType == VT_UINT16 || DrawAttribs.IndexType == VT_UINT32, "Unsupported index format. Only R16_UINT and R32_UINT are allowed.");
- VkIndexType vkIndexType = DrawAttribs.IndexType == VT_UINT16 ? VK_INDEX_TYPE_UINT16 : VK_INDEX_TYPE_UINT32;
+ DEV_CHECK_ERR(drawAttribs.IndexType == VT_UINT16 || drawAttribs.IndexType == VT_UINT32, "Unsupported index format. Only R16_UINT and R32_UINT are allowed.");
+ VkIndexType vkIndexType = drawAttribs.IndexType == VT_UINT16 ? VK_INDEX_TYPE_UINT16 : VK_INDEX_TYPE_UINT32;
m_CommandBuffer.BindIndexBuffer(pBuffVk->GetVkBuffer(), m_IndexDataStartOffset + pBuffVk->GetDynamicOffset(m_ContextId, this), vkIndexType);
}
@@ -437,21 +429,13 @@ namespace Diligent
}
#endif
#endif
- if ( DrawAttribs.IsIndirect )
- {
-#ifdef DEVELOPMENT
- if (DrawAttribs.pIndirectDrawAttribs == nullptr)
- {
- LOG_ERROR("Valid pIndirectDrawAttribs must be provided for indirect draw command");
- return;
- }
-#endif
- auto *pBufferVk = ValidatedCast<BufferVkImpl>(DrawAttribs.pIndirectDrawAttribs);
-
+ auto* pIndirectDrawAttribsVk = ValidatedCast<BufferVkImpl>(drawAttribs.pIndirectDrawAttribs);
+ if (pIndirectDrawAttribsVk != nullptr)
+ {
// Buffer memory barries must be executed outside of render pass
- if (!pBufferVk->CheckAccessFlags(VK_ACCESS_INDIRECT_COMMAND_READ_BIT))
- BufferMemoryBarrier(*pBufferVk, VK_ACCESS_INDIRECT_COMMAND_READ_BIT);
+ if (!pIndirectDrawAttribsVk->CheckAccessFlags(VK_ACCESS_INDIRECT_COMMAND_READ_BIT))
+ BufferMemoryBarrier(*pIndirectDrawAttribsVk, VK_ACCESS_INDIRECT_COMMAND_READ_BIT);
}
#ifdef DEVELOPMENT
@@ -463,29 +447,26 @@ namespace Diligent
CommitRenderPassAndFramebuffer();
- if ( DrawAttribs.IsIndirect )
+ if (pIndirectDrawAttribsVk != nullptr)
{
- if ( auto *pBufferVk = ValidatedCast<BufferVkImpl>(DrawAttribs.pIndirectDrawAttribs) )
- {
#ifdef DEVELOPMENT
- if (pBufferVk->GetDesc().Usage == USAGE_DYNAMIC)
- pBufferVk->DvpVerifyDynamicAllocation(this);
+ if (pIndirectDrawAttribsVk->GetDesc().Usage == USAGE_DYNAMIC)
+ pIndirectDrawAttribsVk->DvpVerifyDynamicAllocation(this);
#endif
- if (!pBufferVk->CheckAccessFlags(VK_ACCESS_INDIRECT_COMMAND_READ_BIT))
- BufferMemoryBarrier(*pBufferVk, VK_ACCESS_INDIRECT_COMMAND_READ_BIT);
+ if (!pIndirectDrawAttribsVk->CheckAccessFlags(VK_ACCESS_INDIRECT_COMMAND_READ_BIT))
+ BufferMemoryBarrier(*pIndirectDrawAttribsVk, VK_ACCESS_INDIRECT_COMMAND_READ_BIT);
- if ( DrawAttribs.IsIndexed )
- m_CommandBuffer.DrawIndexedIndirect(pBufferVk->GetVkBuffer(), pBufferVk->GetDynamicOffset(m_ContextId, this) + DrawAttribs.IndirectDrawArgsOffset, 1, 0);
- else
- m_CommandBuffer.DrawIndirect(pBufferVk->GetVkBuffer(), pBufferVk->GetDynamicOffset(m_ContextId, this) + DrawAttribs.IndirectDrawArgsOffset, 1, 0);
- }
+ if ( drawAttribs.IsIndexed )
+ m_CommandBuffer.DrawIndexedIndirect(pIndirectDrawAttribsVk->GetVkBuffer(), pIndirectDrawAttribsVk->GetDynamicOffset(m_ContextId, this) + drawAttribs.IndirectDrawArgsOffset, 1, 0);
+ else
+ m_CommandBuffer.DrawIndirect(pIndirectDrawAttribsVk->GetVkBuffer(), pIndirectDrawAttribsVk->GetDynamicOffset(m_ContextId, this) + drawAttribs.IndirectDrawArgsOffset, 1, 0);
}
else
{
- if ( DrawAttribs.IsIndexed )
- m_CommandBuffer.DrawIndexed(DrawAttribs.NumIndices, DrawAttribs.NumInstances, DrawAttribs.FirstIndexLocation, DrawAttribs.BaseVertex, DrawAttribs.FirstInstanceLocation);
+ if ( drawAttribs.IsIndexed )
+ m_CommandBuffer.DrawIndexed(drawAttribs.NumIndices, drawAttribs.NumInstances, drawAttribs.FirstIndexLocation, drawAttribs.BaseVertex, drawAttribs.FirstInstanceLocation);
else
- m_CommandBuffer.Draw(DrawAttribs.NumVertices, DrawAttribs.NumInstances, DrawAttribs.StartVertexLocation, DrawAttribs.FirstInstanceLocation );
+ m_CommandBuffer.Draw(drawAttribs.NumVertices, drawAttribs.NumInstances, drawAttribs.StartVertexLocation, drawAttribs.FirstInstanceLocation );
}
++m_State.NumCommands;
@@ -494,16 +475,8 @@ namespace Diligent
void DeviceContextVkImpl::DispatchCompute( const DispatchComputeAttribs &DispatchAttrs )
{
#ifdef DEVELOPMENT
- if (!m_pPipelineState)
- {
- LOG_ERROR("No pipeline state is bound");
+ if (!DvpVerifyDispatchArguments(DispatchAttrs))
return;
- }
- if (!m_pPipelineState->GetDesc().IsComputePipeline)
- {
- LOG_ERROR("No compute pipeline state is bound");
- return;
- }
#endif
EnsureVkCmdBuffer();