From d4b8e0c30214065e63d428be3219f6db18e02a2d Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 23 Dec 2019 12:33:55 -0800 Subject: Fixed staging buffers in Vulkan and D3D12 backends (https://github.com/DiligentGraphics/DiligentEngine/issues/69). Added buffer access test. --- .../src/DeviceContextD3D12Impl.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'Graphics/GraphicsEngineD3D12') diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index 12de666b..5d35eb82 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -1083,10 +1083,16 @@ void DeviceContextD3D12Impl::MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, MAP_F if (MapType == MAP_READ) { - LOG_WARNING_MESSAGE_ONCE("Mapping CPU buffer for reading on D3D12 currently requires flushing context and idling GPU"); - Flush(); - m_pDevice->IdleGPU(); - VERIFY(BuffDesc.Usage == USAGE_STAGING, "Buffer must be created as USAGE_STAGING to be mapped for reading"); + DEV_CHECK_ERR(BuffDesc.Usage == USAGE_STAGING, "Buffer must be created as USAGE_STAGING to be mapped for reading"); + DEV_CHECK_ERR(pd3d12Resource != nullptr, "USAGE_STAGING buffer must intialize D3D12 resource"); + + if ((MapFlags & MAP_FLAG_DO_NOT_WAIT) == 0) + { + LOG_WARNING_MESSAGE("D3D12 backend never waits for GPU when mapping staging buffers for reading. " + "Applications must use fences or other synchronization methods to explicitly synchronize " + "access and use MAP_FLAG_DO_NOT_WAIT flag."); + } + D3D12_RANGE MapRange; MapRange.Begin = 0; MapRange.End = BuffDesc.uiSizeInBytes; @@ -1096,7 +1102,7 @@ void DeviceContextD3D12Impl::MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, MAP_F { if (BuffDesc.Usage == USAGE_STAGING) { - VERIFY(pd3d12Resource != nullptr, "USAGE_STAGING buffer mapped for writing must intialize D3D12 resource"); + DEV_CHECK_ERR(pd3d12Resource != nullptr, "USAGE_STAGING buffer mapped for writing must intialize D3D12 resource"); if (MapFlags & MAP_FLAG_DISCARD) { } @@ -1104,7 +1110,7 @@ void DeviceContextD3D12Impl::MapBuffer(IBuffer* pBuffer, MAP_TYPE MapType, MAP_F } else if (BuffDesc.Usage == USAGE_DYNAMIC) { - VERIFY((MapFlags & (MAP_FLAG_DISCARD | MAP_FLAG_NO_OVERWRITE)) != 0, "D3D12 buffer must be mapped for writing with MAP_FLAG_DISCARD or MAP_FLAG_NO_OVERWRITE flag"); + DEV_CHECK_ERR((MapFlags & (MAP_FLAG_DISCARD | MAP_FLAG_NO_OVERWRITE)) != 0, "D3D12 buffer must be mapped for writing with MAP_FLAG_DISCARD or MAP_FLAG_NO_OVERWRITE flag"); auto& DynamicData = pBufferD3D12->m_DynamicData[m_ContextId]; if ((MapFlags & MAP_FLAG_DISCARD) != 0 || DynamicData.CPUAddress == nullptr) { @@ -1564,9 +1570,9 @@ void DeviceContextD3D12Impl::MapTextureSubresource(ITexture* pTe { if ((MapFlags & MAP_FLAG_DO_NOT_WAIT) == 0) { - LOG_WARNING_MESSAGE("Mapping staging textures for reading never blocks or waits for GPU in D3D12 backend. " + LOG_WARNING_MESSAGE("D3D12 backend never waits for GPU when mapping staging textures for reading. " "Applications must use fences or other synchronization methods to explicitly synchronize " - "access and map texture with MAP_FLAG_DO_NOT_WAIT flag."); + "access and use MAP_FLAG_DO_NOT_WAIT flag."); } DEV_CHECK_ERR((TexDesc.CPUAccessFlags & CPU_ACCESS_READ), "Texture '", TexDesc.Name, "' was not created with CPU_ACCESS_READ flag and can't be mapped for reading"); -- cgit v1.2.3