diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-05-29 16:42:46 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-05-29 16:42:46 +0000 |
| commit | 6388f03e180c73890e8e1ebe5acb81d447e7f8bd (patch) | |
| tree | 8199c5100b9864ff4cc1190009a5e9db7f1a1a5e /Graphics/GraphicsEngineVulkan | |
| parent | Implemened index buffer committing in Vulkan (diff) | |
| download | DiligentCore-6388f03e180c73890e8e1ebe5acb81d447e7f8bd.tar.gz DiligentCore-6388f03e180c73890e8e1ebe5acb81d447e7f8bd.zip | |
Added vertex buffer committing in Vk
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
3 files changed, 43 insertions, 43 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h index 14f5bd93..17f8844c 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h @@ -138,8 +138,8 @@ public: private: void CommitRenderPassAndFramebuffer(class PipelineStateVkImpl *pPipelineStateVk); void CommitVkIndexBuffer(VALUE_TYPE IndexType); - void CommitVkVertexBuffers(class GraphicsContext &GraphCtx); - void TransitionVkVertexBuffers(class GraphicsContext &GraphCtx); + void CommitVkVertexBuffers(); + void TransitionVkVertexBuffers(); void CommitRenderTargets(); void CommitViewports(); void CommitScissorRects(); diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.h b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.h index 8e23f085..905e8400 100644 --- a/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.h +++ b/Graphics/GraphicsEngineVulkan/include/VulkanUtilities/VulkanCommandBuffer.h @@ -259,6 +259,12 @@ namespace VulkanUtilities m_State.IndexType = IndexType; } + void BindVertexBuffers(uint32_t firstBinding, uint32_t bindingCount, const VkBuffer* pBuffers, const VkDeviceSize* pOffsets) + { + VERIFY_EXPR(m_VkCmdBuffer != VK_NULL_HANDLE); + vkCmdBindVertexBuffers(m_VkCmdBuffer, firstBinding, bindingCount, pBuffers, pOffsets); + } + static void TransitionImageLayout(VkCommandBuffer CmdBuffer, VkImage Image, VkImageLayout OldLayout, diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 965e9fd6..78291140 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -341,64 +341,63 @@ namespace Diligent m_State.CommittedIBUpToDate = true;//!IsDynamic; } - void DeviceContextVkImpl::TransitionVkVertexBuffers(GraphicsContext &GraphCtx) + void DeviceContextVkImpl::TransitionVkVertexBuffers() { -#if 0 for( UINT Buff = 0; Buff < m_NumVertexStreams; ++Buff ) { auto &CurrStream = m_VertexStreams[Buff]; VERIFY( CurrStream.pBuffer, "Attempting to bind a null buffer for rendering" ); - auto *pBufferVk = static_cast<BufferVkImpl*>(CurrStream.pBuffer.RawPtr()); - if(!pBufferVk->CheckAllStates(Vk_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER)) - GraphCtx.TransitionResource(pBufferVk, Vk_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER); + auto *pBufferVk = CurrStream.pBuffer.RawPtr<BufferVkImpl>(); + if(pBufferVk->GetAccessFlags() != VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT) + BufferMemoryBarrier(*pBufferVk, VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT); } -#endif } - void DeviceContextVkImpl::CommitVkVertexBuffers(GraphicsContext &GraphCtx) + void DeviceContextVkImpl::CommitVkVertexBuffers() { +#ifdef _DEBUG auto *pPipelineStateVk = m_pPipelineState.RawPtr<PipelineStateVkImpl>(); -#if 0 + VERIFY( m_NumVertexStreams >= pPipelineStateVk->GetNumBufferSlotsUsed(), "Currently bound pipeline state \"", pPipelineStateVk->GetDesc().Name, "\" expects ", pPipelineStateVk->GetNumBufferSlotsUsed(), " input buffer slots, but only ", m_NumVertexStreams, " is bound"); +#endif // Do not initialize array with zeroes for performance reasons - Vk_VERTEX_BUFFER_VIEW VBViews[MaxBufferSlots];// = {} + VkBuffer vkVertexBuffers[MaxBufferSlots];// = {} + VkDeviceSize Offsets[MaxBufferSlots]; VERIFY( m_NumVertexStreams <= MaxBufferSlots, "Too many buffers are being set" ); - const auto *TightStrides = pPipelineStateVk->GetTightStrides(); - bool DynamicBufferPresent = false; - for( UINT Buff = 0; Buff < m_NumVertexStreams; ++Buff ) + //bool DynamicBufferPresent = false; + for( UINT slot = 0; slot < m_NumVertexStreams; ++slot ) { - auto &CurrStream = m_VertexStreams[Buff]; - auto &VBView = VBViews[Buff]; + auto &CurrStream = m_VertexStreams[slot]; + //auto &VBView = VBViews[Buff]; VERIFY( CurrStream.pBuffer, "Attempting to bind a null buffer for rendering" ); - auto *pBufferVk = static_cast<BufferVkImpl*>(CurrStream.pBuffer.RawPtr()); - if (pBufferVk->GetDesc().Usage == USAGE_DYNAMIC) - { - DynamicBufferPresent = true; -#ifdef _DEBUG - pBufferVk->DbgVerifyDynamicAllocation(m_ContextId); -#endif - } - - GraphCtx.TransitionResource(pBufferVk, Vk_RESOURCE_STATE_VERTEX_AND_CONSTANT_BUFFER); + auto *pBufferVk = CurrStream.pBuffer.RawPtr<BufferVkImpl>(); +// if (pBufferVk->GetDesc().Usage == USAGE_DYNAMIC) +// { +// DynamicBufferPresent = true; +//#ifdef _DEBUG +// pBufferVk->DbgVerifyDynamicAllocation(m_ContextId); +//#endif +// } + if(pBufferVk->GetAccessFlags() != VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT) + BufferMemoryBarrier(*pBufferVk, VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT); // Device context keeps strong references to all vertex buffers. // When a buffer is unbound, a reference to Vk resource is added to the context, // so there is no need to reference the resource here //GraphicsCtx.AddReferencedObject(pVkResource); - VBView.BufferLocation = pBufferVk->GetGPUAddress(m_ContextId) + CurrStream.Offset; - VBView.StrideInBytes = CurrStream.Stride ? CurrStream.Stride : TightStrides[Buff]; - // Note that for a dynamic buffer, what we use here is the size of the buffer itself, not the upload heap buffer! - VBView.SizeInBytes = pBufferVk->GetDesc().uiSizeInBytes - CurrStream.Offset; + vkVertexBuffers[slot] = pBufferVk->GetVkBuffer(); + Offsets[slot] = CurrStream.Offset; + + ///VBView.BufferLocation = pBufferVk->GetGPUAddress(m_ContextId) + CurrStream.Offset; } - GraphCtx.FlushResourceBarriers(); - GraphCtx.SetVertexBuffers( 0, m_NumVertexStreams, VBViews ); + //GraphCtx.FlushResourceBarriers(); + m_CommandBuffer.BindVertexBuffers( 0, m_NumVertexStreams, vkVertexBuffers, Offsets ); // GPU virtual address of a dynamic vertex buffer can change every time // a draw command is invoked - m_bCommittedVkVBsUpToDate = !DynamicBufferPresent; -#endif + m_State.CommittedVBsUpToDate = true;//!DynamicBufferPresent; } @@ -438,16 +437,12 @@ namespace Diligent CommitVkIndexBuffer(DrawAttribs.IndexType); } -#if 0 - - auto VkTopology = TopologyToVkTopology( DrawAttribs.Topology ); - GraphCtx.SetPrimitiveTopology(VkTopology); - - if(m_bCommittedVkVBsUpToDate) - TransitionVkVertexBuffers(GraphCtx); + if(m_State.CommittedVBsUpToDate) + TransitionVkVertexBuffers(); else - CommitVkVertexBuffers(GraphCtx); + CommitVkVertexBuffers(); +#if 0 GraphCtx.SetRootSignature( pPipelineStateVk->GetVkRootSignature() ); if(m_pCommittedResourceCache != nullptr) @@ -462,7 +457,6 @@ namespace Diligent } #endif #endif - if( DrawAttribs.IsIndirect ) { #if 0 |
