summaryrefslogtreecommitdiffstats
path: root/Graphics
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2018-07-22 18:47:37 +0000
committerEgor Yusov <egor.yusov@gmail.com>2018-07-22 18:47:37 +0000
commit5eca9ecce9770af037006c31f206bdad22b10be2 (patch)
treebd8f40bbf333f64c5390b1b0d8cbfd063741e8dc /Graphics
parentFixed release build error (diff)
downloadDiligentCore-5eca9ecce9770af037006c31f206bdad22b10be2.tar.gz
DiligentCore-5eca9ecce9770af037006c31f206bdad22b10be2.zip
Implemented mapping with MAP_FLAG_DO_NOT_SYNCHRONIZE flag in Vulkan and D3D12
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GraphicsEngine/include/BufferBase.h6
-rw-r--r--Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp13
-rw-r--r--Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp23
3 files changed, 31 insertions, 11 deletions
diff --git a/Graphics/GraphicsEngine/include/BufferBase.h b/Graphics/GraphicsEngine/include/BufferBase.h
index 66096e3c..d3eaf2d4 100644
--- a/Graphics/GraphicsEngine/include/BufferBase.h
+++ b/Graphics/GraphicsEngine/include/BufferBase.h
@@ -173,8 +173,9 @@ void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: Cop
template<class BaseInterface, class BufferViewImplType, class TBuffViewObjAllocator>
-void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: Map( IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData )
+void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: Map( IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData )
{
+ pMappedData = nullptr;
switch( MapType )
{
case MAP_READ:
@@ -200,7 +201,8 @@ void BufferBase<BaseInterface, BufferViewImplType, TBuffViewObjAllocator> :: Map
if (this->m_Desc.Usage == USAGE_DYNAMIC)
{
- VERIFY_BUFFER((MapFlags & MAP_FLAG_DISCARD) != 0 && MapType == MAP_WRITE, "Dynamic buffers can only be mapped for writing with discard flag");
+ VERIFY_BUFFER((MapFlags & (MAP_FLAG_DISCARD | MAP_FLAG_DO_NOT_SYNCHRONIZE)) != 0 && MapType == MAP_WRITE, "Dynamic buffers can only be mapped for writing with MAP_FLAG_DISCARD or MAP_FLAG_DO_NOT_SYNCHRONIZE flag");
+ VERIFY_BUFFER((MapFlags & (MAP_FLAG_DISCARD | MAP_FLAG_DO_NOT_SYNCHRONIZE)) != (MAP_FLAG_DISCARD | MAP_FLAG_DO_NOT_SYNCHRONIZE), "When mapping dynamic buffer, only one of MAP_FLAG_DISCARD or MAP_FLAG_DO_NOT_SYNCHRONIZE flags must be specified");
}
if ( (MapFlags & MAP_FLAG_DISCARD) != 0 )
diff --git a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp
index 07438730..0942014a 100644
--- a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp
@@ -349,10 +349,19 @@ void BufferD3D12Impl :: Map(IDeviceContext* pContext, MAP_TYPE MapType, Uint32 M
}
else if (m_Desc.Usage == USAGE_DYNAMIC)
{
- VERIFY(MapFlags & MAP_FLAG_DISCARD, "D3D12 buffer must be mapped for writing with MAP_FLAG_DISCARD flag");
+ VERIFY( (MapFlags & (MAP_FLAG_DISCARD | MAP_FLAG_DO_NOT_SYNCHRONIZE)) != 0, "D3D12 buffer must be mapped for writing with MAP_FLAG_DISCARD or MAP_FLAG_DO_NOT_SYNCHRONIZE flag");
+
auto *pCtxD3D12 = ValidatedCast<DeviceContextD3D12Impl>(pContext);
auto ContextId = pDeviceContextD3D12->GetContextId();
- m_DynamicData[ContextId] = pCtxD3D12->AllocateDynamicSpace(m_Desc.uiSizeInBytes);
+ if ((MapFlags & MAP_FLAG_DISCARD) != 0 || m_DynamicData[ContextId].CPUAddress == nullptr)
+ {
+ m_DynamicData[ContextId] = pCtxD3D12->AllocateDynamicSpace(m_Desc.uiSizeInBytes);
+ }
+ else
+ {
+ VERIFY_EXPR(MapFlags & MAP_FLAG_DO_NOT_SYNCHRONIZE);
+ // Reuse previously mapped region
+ }
pMappedData = m_DynamicData[ContextId].CPUAddress;
}
else
diff --git a/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp
index 90cc149f..c81361d8 100644
--- a/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp
@@ -282,7 +282,7 @@ void BufferVkImpl :: CopyData(IDeviceContext* pContext, IBuffer* pSrcBuffer, Uin
pDeviceContextVk->CopyBufferRegion(ValidatedCast<BufferVkImpl>(pSrcBuffer), this, SrcOffset, DstOffset, Size);
}
-void BufferVkImpl :: Map(IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData)
+void BufferVkImpl :: Map(IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid& pMappedData)
{
TBufferBase::Map( pContext, MapType, MapFlags, pMappedData );
@@ -326,20 +326,29 @@ void BufferVkImpl :: Map(IDeviceContext* pContext, MAP_TYPE MapType, Uint32 MapF
else if (m_Desc.Usage == USAGE_DYNAMIC)
{
#ifdef DEVELOPMENT
- if( (MapFlags & MAP_FLAG_DISCARD) == 0 )
+ if( (MapFlags & (MAP_FLAG_DISCARD | MAP_FLAG_DO_NOT_SYNCHRONIZE)) == 0 )
{
- LOG_ERROR_MESSAGE("Failed to map buffer '", m_Desc.Name, "': Vk buffer must be mapped for writing with MAP_FLAG_DISCARD flag. Context Id: ", pDeviceContextVk->GetContextId());
+ LOG_ERROR_MESSAGE("Failed to map buffer '", m_Desc.Name, "': Vk buffer must be mapped for writing with MAP_FLAG_DISCARD or MAP_FLAG_DO_NOT_SYNCHRONIZE flag. Context Id: ", pDeviceContextVk->GetContextId());
return;
}
#endif
- auto DynAlloc = pDeviceContextVk->AllocateDynamicSpace(m_Desc.uiSizeInBytes);
- if(DynAlloc.pParentDynamicHeap != nullptr)
+ auto& DynAllocation = m_DynamicAllocations[pDeviceContextVk->GetContextId()];
+ if ( (MapFlags & MAP_FLAG_DISCARD) != 0 || DynAllocation.pParentDynamicHeap == nullptr )
+ {
+ DynAllocation = pDeviceContextVk->AllocateDynamicSpace(m_Desc.uiSizeInBytes);
+ }
+ else
+ {
+ VERIFY_EXPR(MapFlags & MAP_FLAG_DO_NOT_SYNCHRONIZE);
+ // Reuse the same allocation
+ }
+
+ if (DynAllocation.pParentDynamicHeap != nullptr)
{
const auto& DynamicHeap = pDeviceVk->GetDynamicHeapRingBuffer();
auto* CPUAddress = DynamicHeap.GetCPUAddress();
- pMappedData = CPUAddress + DynAlloc.Offset;
- m_DynamicAllocations[pDeviceContextVk->GetContextId()] = std::move(DynAlloc);
+ pMappedData = CPUAddress + DynAllocation.Offset;
}
else
{