diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-05-29 15:54:31 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-05-29 15:54:31 +0000 |
| commit | fafaba571ba8b42a505a5a1abf7d118fa3eb91ab (patch) | |
| tree | bb3940789e74fb9a801695869583b1711b6555a7 /Graphics/GraphicsEngineVulkan | |
| parent | Moved vertex buffer stride definition from IDeviceContext::SetVertexBuffers()... (diff) | |
| download | DiligentCore-fafaba571ba8b42a505a5a1abf7d118fa3eb91ab.tar.gz DiligentCore-fafaba571ba8b42a505a5a1abf7d118fa3eb91ab.zip | |
Implemened index buffer committing in Vulkan
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h | 16 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp | 85 |
2 files changed, 46 insertions, 55 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h index 4b04ead8..14f5bd93 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h @@ -149,7 +149,7 @@ private: VulkanUtilities::VulkanCommandBuffer m_CommandBuffer; - const Uint32 m_NumCommandsToFlush = 192; + const Uint32 m_NumCommandsToFlush = 192; struct ContextState { /// Flag indicating if currently committed vertex buffers are up to date @@ -158,14 +158,20 @@ private: /// Flag indicating if currently committed index buffer is up to date bool CommittedIBUpToDate = false; + /// Format of the currently committed index buffer + VALUE_TYPE CommittedIBFormat = VT_UNDEFINED; + /// Offset in the currently committed index buffer + Uint32 CommittedVkIndexDataStartOffset = 0; + /// Currently committed index buffer + VkBuffer CommittedVkIndexBuffer = VK_NULL_HANDLE; + Uint32 NumCommands = 0; }m_State; -#if 0 - CComPtr<IVkResource> m_CommittedVkIndexBuffer; - VALUE_TYPE m_CommittedIBFormat = VT_UNDEFINED; - Uint32 m_CommittedVkIndexDataStartOffset = 0; + + +#if 0 CComPtr<IVkCommandSignature> m_pDrawIndirectSignature; CComPtr<IVkCommandSignature> m_pDrawIndexedIndirectSignature; CComPtr<IVkCommandSignature> m_pDispatchIndirectSignature; diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 474abd27..965e9fd6 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -302,56 +302,43 @@ namespace Diligent void DeviceContextVkImpl::CommitVkIndexBuffer(VALUE_TYPE IndexType) { - VERIFY( m_pIndexBuffer != nullptr, "Index buffer is not set up for indexed draw command" ); -#if 0 - Vk_INDEX_BUFFER_VIEW IBView; - BufferVkImpl *pBuffVk = static_cast<BufferVkImpl *>(m_pIndexBuffer.RawPtr()); - IBView.BufferLocation = pBuffVk->GetGPUAddress(m_ContextId) + m_IndexDataStartOffset; - if( IndexType == VT_UINT32 ) - IBView.Format = DXGI_FORMAT_R32_UINT; - else if( IndexType == VT_UINT16 ) - IBView.Format = DXGI_FORMAT_R16_UINT; - else - { - UNEXPECTED( "Unsupported index format. Only R16_UINT and R32_UINT are allowed." ); - } - // Note that for a dynamic buffer, what we use here is the size of the buffer itself, not the upload heap buffer! - IBView.SizeInBytes = pBuffVk->GetDesc().uiSizeInBytes - m_IndexDataStartOffset; + BufferVkImpl *pBuffVk = m_pIndexBuffer.RawPtr<BufferVkImpl>(); // Device context keeps strong reference to bound index buffer. // When the buffer is unbound, the reference to the Vk resource // is added to the context. There is no need to add reference here - //auto &GraphicsCtx = RequestCmdContext()->AsGraphicsContext(); - //auto *pVkResource = pBuffVk->GetVkBuffer(); - //GraphicsCtx.AddReferencedObject(pVkResource); - bool IsDynamic = pBuffVk->GetDesc().Usage == USAGE_DYNAMIC; -#ifdef _DEBUG - if(IsDynamic) - pBuffVk->DbgVerifyDynamicAllocation(m_ContextId); -#endif - auto &GraphicsCtx = RequestCmdContext()->AsGraphicsContext(); - // Resource transitioning must always be performed! - GraphicsCtx.TransitionResource(pBuffVk, Vk_RESOURCE_STATE_INDEX_BUFFER, true); +// bool IsDynamic = pBuffVk->GetDesc().Usage == USAGE_DYNAMIC; +//#ifdef _DEBUG +// if(IsDynamic) +// pBuffVk->DbgVerifyDynamicAllocation(m_ContextId); +//#endif - size_t BuffDataStartByteOffset; - auto *pVkBuff = pBuffVk->GetVkBuffer(BuffDataStartByteOffset, m_ContextId); + size_t BuffDataStartByteOffset = 0; + auto *vkBuffer = pBuffVk->GetVkBuffer(); - if( IsDynamic || - m_CommittedVkIndexBuffer != pVkBuff || - m_CommittedIBFormat != IndexType || - m_CommittedVkIndexDataStartOffset != m_IndexDataStartOffset + BuffDataStartByteOffset) + if( //IsDynamic || + m_State.CommittedVkIndexBuffer != vkBuffer || + m_State.CommittedIBFormat != IndexType || + m_State.CommittedVkIndexDataStartOffset != m_IndexDataStartOffset + BuffDataStartByteOffset) { - m_CommittedVkIndexBuffer = pVkBuff; - m_CommittedIBFormat = IndexType; - m_CommittedVkIndexDataStartOffset = m_IndexDataStartOffset + static_cast<Uint32>(BuffDataStartByteOffset); - GraphicsCtx.SetIndexBuffer( IBView ); + m_State.CommittedVkIndexBuffer = vkBuffer; + m_State.CommittedIBFormat = IndexType; + m_State.CommittedVkIndexDataStartOffset = m_IndexDataStartOffset + static_cast<Uint32>(BuffDataStartByteOffset); + VkIndexType vkIndexType; + if( IndexType == VT_UINT32 ) + vkIndexType = VK_INDEX_TYPE_UINT32; + else + { + VERIFY(IndexType == VT_UINT16, "Unsupported index format. Only R16_UINT and R32_UINT are allowed."); + vkIndexType = VK_INDEX_TYPE_UINT16; + } + m_CommandBuffer.BindIndexBuffer(m_State.CommittedVkIndexBuffer, m_State.CommittedVkIndexDataStartOffset, vkIndexType); } // GPU virtual address of a dynamic index buffer can change every time // a draw command is invoked - m_bCommittedVkIBUpToDate = !IsDynamic; -#endif + m_State.CommittedIBUpToDate = true;//!IsDynamic; } void DeviceContextVkImpl::TransitionVkVertexBuffers(GraphicsContext &GraphCtx) @@ -436,24 +423,22 @@ namespace Diligent if(m_CommandBuffer.GetState().RenderPass == VK_NULL_HANDLE) CommitRenderPassAndFramebuffer(pPipelineStateVk); -#if 0 - auto &GraphCtx = RequestCmdContext()->AsGraphicsContext(); if( DrawAttribs.IsIndexed ) { - if( m_CommittedIBFormat != DrawAttribs.IndexType ) - m_bCommittedVkIBUpToDate = false; + VERIFY( m_pIndexBuffer != nullptr, "Index buffer is not set up for indexed draw command" ); - if(m_bCommittedVkIBUpToDate) - { - BufferVkImpl *pBuffVk = static_cast<BufferVkImpl *>(m_pIndexBuffer.RawPtr()); - if(!pBuffVk->CheckAllStates(Vk_RESOURCE_STATE_INDEX_BUFFER)) - GraphCtx.TransitionResource(pBuffVk, Vk_RESOURCE_STATE_INDEX_BUFFER, true); - } - else + if( m_State.CommittedIBFormat != DrawAttribs.IndexType ) + m_State.CommittedIBUpToDate = false; + + BufferVkImpl *pBuffVk = m_pIndexBuffer.RawPtr<BufferVkImpl>(); + if(pBuffVk->GetAccessFlags() != VK_ACCESS_INDEX_READ_BIT) + BufferMemoryBarrier(*pBuffVk, VK_ACCESS_INDEX_READ_BIT); + + if(!m_State.CommittedIBUpToDate) CommitVkIndexBuffer(DrawAttribs.IndexType); } - +#if 0 auto VkTopology = TopologyToVkTopology( DrawAttribs.Topology ); GraphCtx.SetPrimitiveTopology(VkTopology); |
