diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-05-31 03:00:13 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-05-31 03:00:13 +0000 |
| commit | b4ac02ef8b9ec4a90f800435a180e70ef4612fe0 (patch) | |
| tree | b0da4b2c2856f55771e8eb7128cff5b688328503 /Graphics/GraphicsEngineVulkan | |
| parent | Fixed issues with VulkanRingBuffer not moving vulkan memory object (diff) | |
| download | DiligentCore-b4ac02ef8b9ec4a90f800435a180e70ef4612fe0.tar.gz DiligentCore-b4ac02ef8b9ec4a90f800435a180e70ef4612fe0.zip | |
Implemented UpdateData() for buffer vk
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
3 files changed, 19 insertions, 34 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h index 799ccb31..5e4dac38 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.h @@ -104,7 +104,6 @@ public: m_SignalSemaphores.push_back(Semaphore); } -#if 0 ///// Clears the state caches. This function is called once per frame ///// (before present) to release all outstanding objects ///// that are only kept alive by references in the cache @@ -113,8 +112,9 @@ public: ///// Number of different shader types (Vertex, Pixel, Geometry, Domain, Hull, Compute) //static constexpr int NumShaderTypes = 6; - void UpdateBufferRegion(class BufferVkImpl *pBuffVk, struct DynamicAllocation& Allocation, Uint64 DstOffset, Uint64 NumBytes); + void UpdateBufferRegion(class BufferVkImpl *pBuffVk, struct VulkanDynamicAllocation& Allocation, Uint64 DstOffset, Uint64 NumBytes); void UpdateBufferRegion(class BufferVkImpl *pBuffVk, const void *pData, Uint64 DstOffset, Uint64 NumBytes); +#if 0 void CopyBufferRegion(class BufferVkImpl *pSrcBuffVk, class BufferVkImpl *pDstBuffVk, Uint64 SrcOffset, Uint64 DstOffset, Uint64 NumBytes); void CopyTextureRegion(class TextureVkImpl *pSrcTexture, Uint32 SrcSubResIndex, const Vk_BOX *pVkSrcBox, class TextureVkImpl *pDstTexture, Uint32 DstSubResIndex, Uint32 DstX, Uint32 DstY, Uint32 DstZ); diff --git a/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp index 32bf143c..70612b05 100644 --- a/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp @@ -321,12 +321,10 @@ void BufferVkImpl::UpdateData( IDeviceContext *pContext, Uint32 Offset, Uint32 S { TBufferBase::UpdateData( pContext, Offset, Size, pData ); -#if 0 // We must use cmd context from the device context provided, otherwise there will // be resource barrier issues in the cmd list in the device context auto *pDeviceContextVk = ValidatedCast<DeviceContextVkImpl>(pContext); pDeviceContextVk->UpdateBufferRegion(this, pData, Offset, Size); -#endif } void BufferVkImpl :: CopyData(IDeviceContext *pContext, IBuffer *pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size) diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index 390357b4..e41db8c5 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -350,7 +350,8 @@ namespace Diligent } //GraphCtx.FlushResourceBarriers(); - m_CommandBuffer.BindVertexBuffers( 0, m_NumVertexStreams, vkVertexBuffers, Offsets ); + if(m_NumVertexStreams > 0) + 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 @@ -898,24 +899,21 @@ namespace Diligent SetViewports(1, nullptr, 0, 0); } } - -#if 0 - DynamicAllocation DeviceContextVkImpl::AllocateDynamicSpace(size_t NumBytes) - { - return m_pUploadHeap->Allocate(NumBytes); - } -#endif -#if 0 - void DeviceContextVkImpl::UpdateBufferRegion(class BufferVkImpl *pBuffVk, DynamicAllocation& Allocation, Uint64 DstOffset, Uint64 NumBytes) + void DeviceContextVkImpl::UpdateBufferRegion(BufferVkImpl *pBuffVk, VulkanDynamicAllocation& Allocation, Uint64 DstOffset, Uint64 NumBytes) { - auto pCmdCtx = RequestCmdContext(); - VERIFY_EXPR( static_cast<size_t>(NumBytes) == NumBytes ); - pCmdCtx->TransitionResource(pBuffVk, Vk_RESOURCE_STATE_COPY_DEST, true); - size_t DstBuffDataStartByteOffset; - auto *pVkBuff = pBuffVk->GetVkBuffer(DstBuffDataStartByteOffset, m_ContextId); - VERIFY(DstBuffDataStartByteOffset == 0, "Dst buffer must not be suballocated"); - pCmdCtx->GetCommandList()->CopyBufferRegion( pVkBuff, DstOffset + DstBuffDataStartByteOffset, Allocation.pBuffer, Allocation.Offset, NumBytes); + VERIFY(DstOffset + NumBytes <= pBuffVk->GetDesc().uiSizeInBytes, "Update region is out of buffer"); + VERIFY_EXPR(NumBytes <= Allocation.Size); + EnsureVkCmdBuffer(); + if(!pBuffVk->CheckAccessFlags(VK_ACCESS_TRANSFER_WRITE_BIT)) + { + BufferMemoryBarrier(*pBuffVk, VK_ACCESS_TRANSFER_WRITE_BIT); + } + VkBufferCopy CopyRegion; + CopyRegion.srcOffset = Allocation.Offset; + CopyRegion.dstOffset = DstOffset; + CopyRegion.size = NumBytes; + m_CommandBuffer.CopyBuffer(Allocation.vkBuffer, pBuffVk->GetVkBuffer(), 1, &CopyRegion); ++m_State.NumCommands; } @@ -923,11 +921,10 @@ namespace Diligent { VERIFY(pBuffVk->GetDesc().Usage != USAGE_DYNAMIC, "Dynamic buffers must be updated via Map()"); VERIFY_EXPR( static_cast<size_t>(NumBytes) == NumBytes ); - auto TmpSpace = m_pUploadHeap->Allocate(static_cast<size_t>(NumBytes)); + auto TmpSpace = m_pDevice.RawPtr<RenderDeviceVkImpl>()->AllocateDynamicUploadSpace(m_ContextId, NumBytes, 0); memcpy(TmpSpace.CPUAddress, pData, static_cast<size_t>(NumBytes)); UpdateBufferRegion(pBuffVk, TmpSpace, DstOffset, NumBytes); } -#endif #if 0 void DeviceContextVkImpl::CopyBufferRegion(BufferVkImpl *pSrcBuffVk, BufferVkImpl *pDstBuffVk, Uint64 SrcOffset, Uint64 DstOffset, Uint64 NumBytes) @@ -1151,17 +1148,7 @@ namespace Diligent auto CurrentFrame = m_pDevice.RawPtr<RenderDeviceVkImpl>()->GetCurrentFrameNumber(); VERIFY(it->second.FrameNum == CurrentFrame, "Dynamic allocation is out-of-date. Dynamic buffer \"", pBuffer->GetDesc().Name, "\" must be unmapped in the same frame it is used."); #endif - EnsureVkCmdBuffer(); - if(!pBuffer->CheckAccessFlags(VK_ACCESS_TRANSFER_WRITE_BIT)) - { - BufferMemoryBarrier(*pBuffer, VK_ACCESS_TRANSFER_WRITE_BIT); - } - VkBufferCopy CopyRegion; - CopyRegion.srcOffset = it->second.Offset; - CopyRegion.dstOffset = 0; - CopyRegion.size = it->second.Size; - m_CommandBuffer.CopyBuffer(it->second.vkBuffer, pBuffer->GetVkBuffer(), 1, &CopyRegion); - + UpdateBufferRegion(pBuffer, it->second, 0, pBuffer->GetDesc().uiSizeInBytes); m_UploadAllocations.erase(it); } else |
