Go to the documentation of this file.
34 #include "../../GraphicsEngine/interface/RenderDevice.h"
35 #include "../../GraphicsEngine/interface/DeviceContext.h"
36 #include "../../GraphicsEngine/interface/Buffer.h"
37 #include "../../../Common/interface/RefCntAutoPtr.hpp"
60 m_BufferSize{CI.BuffDesc.uiSizeInBytes},
61 m_OnBufferResizeCallback{CI.OnBufferResizeCallback},
62 m_MapInfo(CI.NumContexts)
66 CI.pDevice->CreateBuffer(CI.BuffDesc,
nullptr, &m_pBuffer);
68 if (m_OnBufferResizeCallback)
69 m_OnBufferResizeCallback(m_pBuffer);
80 for (
const auto& mapInfo : m_MapInfo)
82 VERIFY(!mapInfo.m_MappedData,
"Destroying streaming buffer that is still mapped");
91 auto& MapInfo = m_MapInfo[CtxNum];
93 if (MapInfo.m_CurrOffset + Size > m_BufferSize)
99 if (Size > m_BufferSize)
101 while (m_BufferSize < Size)
104 auto BuffDesc = m_pBuffer->GetDesc();
105 BuffDesc.uiSizeInBytes = m_BufferSize;
107 std::string Name = BuffDesc.Name;
108 BuffDesc.Name = Name.c_str();
112 if (m_OnBufferResizeCallback)
113 m_OnBufferResizeCallback(m_pBuffer);
115 LOG_INFO_MESSAGE(
"Extended streaming buffer '", BuffDesc.Name,
"' to ", m_BufferSize,
" bytes");
119 if (!m_UsePersistentMap)
121 VERIFY(MapInfo.m_MappedData ==
nullptr,
"Streaming buffer must be unmapped before it can be mapped next time when persistent mapping is not used");
124 if (MapInfo.m_MappedData ==
nullptr)
132 auto Offset = MapInfo.m_CurrOffset;
134 MapInfo.m_CurrOffset += Size;
141 auto Offset =
Map(pCtx, pDevice, Size, CtxNum);
143 memcpy(pCPUAddress, pData, Size);
151 if (!m_UsePersistentMap)
153 m_MapInfo[CtxNum].m_MappedData.Unmap();
159 m_MapInfo[CtxNum].m_MappedData.Unmap();
160 m_MapInfo[CtxNum].m_CurrOffset = 0;
165 for (
Uint32 ctx = 0; ctx < m_MapInfo.size(); ++ctx)
173 return m_MapInfo[CtxNum].m_MappedData;
177 bool m_UsePersistentMap =
false;
183 std::function<void(
IBuffer*)> m_OnBufferResizeCallback;
191 std::vector<MapInfo> m_MapInfo;
virtual void METHOD() CreateBuffer(const BufferDesc &BuffDesc, const BufferData *pBuffData, IBuffer **ppBuffer)
Creates a new buffer object.
BufferDesc BuffDesc
Definition: StreamingBuffer.hpp:46
StreamingBuffer() noexcept
Definition: StreamingBuffer.hpp:55
Uint32 Map(IDeviceContext *pCtx, IRenderDevice *pDevice, Uint32 Size, size_t CtxNum=0)
Definition: StreamingBuffer.hpp:87
bool AllowPersistentMapping
Definition: StreamingBuffer.hpp:49
@ MAP_FLAG_DISCARD
Previous contents of the resource will be undefined. This flag is only compatible with MAP_WRITE D3D...
Definition: GraphicsTypes.h:241
@ MAP_FLAG_NO_OVERWRITE
The system will not synchronize pending operations before mapping the buffer. It is responsibility of...
Definition: GraphicsTypes.h:247
std::function< void(IBuffer *)> OnBufferResizeCallback
Definition: StreamingBuffer.hpp:47
Definition: StreamingBuffer.hpp:43
virtual const DeviceCaps &METHOD() GetDeviceCaps() const
Gets the device capabilities, see Diligent::DeviceCaps for details.
@ USAGE_DYNAMIC
A resource that can be read by the GPU and written at least once per frame by the CPU....
Definition: GraphicsTypes.h:161
void Reset()
Definition: StreamingBuffer.hpp:163
void * GetMappedCPUAddress(size_t CtxNum=0)
Definition: StreamingBuffer.hpp:171
Buffer interface.
Definition: Buffer.h:187
IRenderDevice * pDevice
Definition: StreamingBuffer.hpp:45
Render device interface.
Definition: RenderDevice.h:75
#define LOG_INFO_MESSAGE(...)
Definition: Errors.hpp:124
IBuffer * GetBuffer() const
Definition: StreamingBuffer.hpp:169
bool IsVulkanDevice() const
Definition: GraphicsTypes.h:1872
StreamingBuffer & operator=(const StreamingBuffer &)=delete
Uint32 NumContexts
Definition: StreamingBuffer.hpp:48
Template class that implements reference counting.
Definition: RefCntAutoPtr.hpp:73
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
void Flush(size_t CtxNum=0)
Definition: StreamingBuffer.hpp:157
@ MAP_WRITE
The resource is mapped for writing. D3D11 counterpart: D3D11_MAP_WRITE. OpenGL counterpart: GL_MAP_...
Definition: GraphicsTypes.h:214
Uint32 Update(IDeviceContext *pCtx, IRenderDevice *pDevice, const void *pData, Uint32 Size, size_t CtxNum=0)
Definition: StreamingBuffer.hpp:138
StreamingBuffer(const StreamingBufferCreateInfo &CI)
Definition: StreamingBuffer.hpp:58
Buffer description.
Definition: Buffer.h:74
void Unmap(size_t CtxNum=0)
Definition: StreamingBuffer.hpp:149
@ RENDER_DEVICE_TYPE_D3D12
D3D12 device.
Definition: GraphicsTypes.h:1483
Device context interface.
Definition: DeviceContext.h:1460
uint8_t Uint8
8-bit unsigned integer
Definition: BasicTypes.h:53
#define VERIFY_EXPR(...)
Definition: DebugUtilities.hpp:79
#define VERIFY(...)
Definition: DebugUtilities.hpp:76
~StreamingBuffer()
Definition: StreamingBuffer.hpp:78
enum RENDER_DEVICE_TYPE DevType
Device type. See Diligent::DeviceType.
Definition: GraphicsTypes.h:1836
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
Definition: StreamingBuffer.hpp:52