4141#include < mutex>
4242#include < map>
4343#include < unordered_map>
44+ #include < variant>
4445
4546namespace Diligent
4647{
4748
49+ struct BufferToTextureCopyInfo ;
50+
4851// / Implementation of the asynchronous GPU upload manager.
4952class GPUUploadManagerImpl final : public ObjectBase<IGPUUploadManager>
5053{
@@ -58,6 +61,8 @@ class GPUUploadManagerImpl final : public ObjectBase<IGPUUploadManager>
5861
5962 virtual void DILIGENT_CALL_TYPE ScheduleBufferUpdate (const ScheduleBufferUpdateInfo& UpdateInfo) override final ;
6063
64+ virtual void DILIGENT_CALL_TYPE ScheduleTextureUpdate (const ScheduleTextureUpdateInfo& UpdateInfo) override final ;
65+
6166 virtual void DILIGENT_CALL_TYPE GetStats (GPUUploadManagerStats& Stats) const override final ;
6267
6368 class Page
@@ -88,6 +93,9 @@ class GPUUploadManagerImpl final : public ObjectBase<IGPUUploadManager>
8893 // clang-format on
8994
9095 bool ScheduleBufferUpdate (const ScheduleBufferUpdateInfo& UpdateInfo);
96+ bool ScheduleTextureUpdate (const ScheduleTextureUpdateInfo& UpdateInfo,
97+ const BufferToTextureCopyInfo& CopyInfo,
98+ Uint32 OffsetAlignment);
9199
92100 WritingStatus EndWriting ();
93101
@@ -155,6 +163,17 @@ class GPUUploadManagerImpl final : public ObjectBase<IGPUUploadManager>
155163 // Returns true if the operation was successfully scheduled, and false otherwise.
156164 bool ScheduleBufferUpdate (const ScheduleBufferUpdateInfo& UpdateInfo);
157165
166+ // Schedules a texture update operation on the page.
167+ // Returns true if the operation was successfully scheduled, and false otherwise.
168+ bool ScheduleTextureUpdate (const ScheduleTextureUpdateInfo& UpdateInfo,
169+ const BufferToTextureCopyInfo& CopyInfo,
170+ Uint32 OffsetAlignment);
171+
172+ // Allocates a block of memory from the page for a new update operation.
173+ // Returns the offset of the allocated block within the page.
174+ // If there is not enough space in the page for the requested allocation, returns ~0u.
175+ Uint32 Allocate (Uint32 NumBytes, Uint32 Alignment);
176+
158177 WritingStatus EndWriting ();
159178
160179 private:
@@ -175,27 +194,55 @@ class GPUUploadManagerImpl final : public ObjectBase<IGPUUploadManager>
175194
176195 Uint64 m_FenceValue = 0 ;
177196
178- struct PendingOp
197+ static constexpr Uint32 kMinimumOffsetAlignment = 16 ;
198+
199+ struct PendingBufferOp
179200 {
180201 RefCntAutoPtr<IBuffer> pDstBuffer;
181202
182203 CopyStagingBufferCallbackType CopyBuffer = nullptr ;
183204 void * pCopyBufferData = nullptr ;
184205
185- GPUUploadEnqueuedCallbackType UploadEnqueued = nullptr ;
186- void * pUploadEnqueuedData = nullptr ;
206+ GPUBufferUploadEnqueuedCallbackType UploadEnqueued = nullptr ;
207+ void * pUploadEnqueuedData = nullptr ;
187208
188209 Uint32 SrcOffset = 0 ;
189210 Uint32 DstOffset = 0 ;
190211 Uint32 NumBytes = 0 ;
191212
192- PendingOp () noexcept = default ;
213+ PendingBufferOp () noexcept = default ;
214+ };
215+
216+
217+ struct PendingTextureOp
218+ {
219+ RefCntAutoPtr<ITexture> pDstTexture;
220+
221+ Uint32 SrcOffset = 0 ;
222+ Uint32 SrcStride = 0 ;
223+ Uint32 SrcDepthStride = 0 ;
224+
225+ Uint32 DstMipLevel = 0 ;
226+ Uint32 DstSlice = 0 ;
227+ Box DstBox;
228+
229+ CopyStagingTextureCallbackType CopyTexture = nullptr ;
230+ void * pCopyTextureData = nullptr ;
231+
232+ GPUTextureUploadEnqueuedCallbackType UploadEnqueued = nullptr ;
233+ void * pUploadEnqueuedData = nullptr ;
193234 };
194235
236+ using PendingOp = std::variant<PendingBufferOp, PendingTextureOp>;
195237 MPSCQueue<PendingOp> m_PendingOps;
196238 };
197239
198240private:
241+ void ScheduleUpdate (IDeviceContext* pContext,
242+ Uint32 UpdateSize,
243+ const void * pUpdateInfo,
244+ bool ScheduleUpdate (Page::Writer& Writer, const void * pUpdateInfo));
245+
199246 void ReclaimCompletedPages (IDeviceContext* pContext);
200247 bool SealAndSwapCurrentPage (IDeviceContext* pContext);
201248 void AddFreePages (IDeviceContext* pContext);
@@ -214,6 +261,9 @@ class GPUUploadManagerImpl final : public ObjectBase<IGPUUploadManager>
214261 RefCntAutoPtr<IRenderDevice> m_pDevice;
215262 RefCntAutoPtr<IDeviceContext> m_pContext;
216263
264+ const Uint32 m_TextureUpdateOffsetAlignment;
265+ const Uint32 m_TextureUpdateStrideAlignment;
266+
217267 // Pages that are pending for execution.
218268 MPSCQueue<Page*> m_PendingPages;
219269
0 commit comments