From 5eca9ecce9770af037006c31f206bdad22b10be2 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Sun, 22 Jul 2018 11:47:37 -0700 Subject: Implemented mapping with MAP_FLAG_DO_NOT_SYNCHRONIZE flag in Vulkan and D3D12 --- Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') 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(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 -- cgit v1.2.3