Skip to content

Commit 485cdf9

Browse files
GPUUploadManagerImpl::Page: add debug asserts; clarify debug-only method names
1 parent e2aa260 commit 485cdf9

3 files changed

Lines changed: 19 additions & 15 deletions

File tree

Graphics/GraphicsTools/include/GPUUploadManagerImpl.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ class GPUUploadManagerImpl final : public ObjectBase<IGPUUploadManager>
141141
Uint32 GetSize() const { return m_Size; }
142142

143143
// Returns the number of pending operations. This is used for testing and debugging purposes.
144-
size_t GetNumPendingOps() const { return m_NumPendingOps.load(std::memory_order_relaxed); }
144+
size_t DbgGetNumPendingOps() const { return m_NumPendingOps.load(std::memory_order_relaxed); }
145145

146146
// Returns the number of active writers. This is used for testing and debugging purposes.
147-
Uint32 GetWriterCount() const { return m_State.load(std::memory_order_acquire) & WRITER_MASK; }
147+
Uint32 DbgGetWriterCount() const { return m_State.load(std::memory_order_relaxed) & WRITER_MASK; }
148148

149149
// Returns true if the page is sealed for new writes. This is used for testing and debugging purposes.
150-
bool IsSealed() const { return (m_State.load(std::memory_order_acquire) & SEALED_BIT) != 0; }
150+
bool DbgIsSealed() const { return (m_State.load(std::memory_order_relaxed) & SEALED_BIT) != 0; }
151151

152152
private:
153153
// Schedules a buffer update operation on the page.

Graphics/GraphicsTools/src/GPUUploadManagerImpl.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ GPUUploadManagerImpl::Page::Writer& GPUUploadManagerImpl::Page::Writer::operator
4646
{
4747
if (this != &Other)
4848
{
49+
VERIFY(m_pPage == nullptr, "Assigning to a non-empty writer. End writing before assignment or use move assignment operator only for empty writers.");
50+
4951
m_pPage = Other.m_pPage;
5052
Other.m_pPage = nullptr;
5153
}
@@ -187,7 +189,7 @@ bool GPUUploadManagerImpl::Page::ScheduleBufferUpdate(IBuffer*
187189
GPUUploadEnqueuedCallbackType Callback,
188190
void* pCallbackData)
189191
{
190-
VERIFY_EXPR(GetWriterCount() > 0);
192+
VERIFY_EXPR(DbgGetWriterCount() > 0);
191193

192194
// Note that the page may be sealed for new writes at this point,
193195
// but we can still schedule the update since we have an active writer
@@ -228,18 +230,19 @@ bool GPUUploadManagerImpl::Page::ScheduleBufferUpdate(IBuffer*
228230

229231
void GPUUploadManagerImpl::Page::ExecutePendingOps(IDeviceContext* pContext, Uint64 FenceValue)
230232
{
231-
VERIFY(IsSealed(), "Page must be sealed before executing pending operations");
232-
VERIFY(GetWriterCount() == 0, "All writers must finish before executing pending operations");
233+
VERIFY(DbgIsSealed(), "Page must be sealed before executing pending operations");
234+
VERIFY(DbgGetWriterCount() == 0, "All writers must finish before executing pending operations");
233235

234-
if (pContext != nullptr)
236+
if (m_pData != nullptr)
235237
{
238+
VERIFY_EXPR(pContext != nullptr);
236239
pContext->UnmapBuffer(m_pStagingBuffer, MAP_WRITE);
237240
m_pData = nullptr;
238241
}
239242

240243
for (PendingOp Op; m_PendingOps.Dequeue(Op);)
241244
{
242-
if (pContext != nullptr)
245+
if (pContext != nullptr && Op.NumBytes > 0)
243246
{
244247
pContext->CopyBuffer(m_pStagingBuffer, Op.SrcOffset, RESOURCE_STATE_TRANSITION_MODE_TRANSITION,
245248
Op.pDstBuffer, Op.DstOffset, Op.NumBytes, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
@@ -256,13 +259,14 @@ void GPUUploadManagerImpl::Page::ExecutePendingOps(IDeviceContext* pContext, Uin
256259

257260
void GPUUploadManagerImpl::Page::Reset(IDeviceContext* pContext)
258261
{
259-
VERIFY(GetWriterCount() == 0, "All writers must finish before resetting the page");
262+
VERIFY(DbgGetWriterCount() == 0, "All writers must finish before resetting the page");
260263
VERIFY(m_PendingOps.IsEmpty(), "All pending operations must be executed before resetting the page");
261264

262265
m_Offset.store(0);
263266
m_State.store(0);
264267
m_NumPendingOps.store(0);
265268
m_Enqueued.store(false);
269+
m_FenceValue = 0;
266270

267271
if (pContext != nullptr)
268272
{
@@ -273,8 +277,8 @@ void GPUUploadManagerImpl::Page::Reset(IDeviceContext* pContext)
273277

274278
bool GPUUploadManagerImpl::Page::TryEnqueue()
275279
{
276-
VERIFY(IsSealed(), "Page must be sealed before it can be enqueued for execution");
277-
VERIFY(GetWriterCount() == 0, "All writers must finish before the page can be enqueued");
280+
VERIFY(DbgIsSealed(), "Page must be sealed before it can be enqueued for execution");
281+
VERIFY(DbgGetWriterCount() == 0, "All writers must finish before the page can be enqueued");
278282

279283
bool Expected = false;
280284
return m_Enqueued.compare_exchange_strong(Expected, true, std::memory_order_acq_rel);

Tests/DiligentCoreTest/src/GraphicsTools/GPUUploadManagerPageTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ TEST(GPUUploadManagerPageTest, States)
8383
EXPECT_TRUE(Writer.ScheduleBufferUpdate(nullptr, 0, 512, nullptr, nullptr, nullptr));
8484
EXPECT_TRUE(Writer.ScheduleBufferUpdate(nullptr, 512, 512, nullptr, nullptr, nullptr));
8585
EXPECT_FALSE(Writer.ScheduleBufferUpdate(nullptr, 1024, 512, nullptr, nullptr, nullptr)) << "Should not be able to schedule an update that exceeds the page size";
86-
EXPECT_EQ(Page.GetNumPendingOps(), size_t{2});
86+
EXPECT_EQ(Page.DbgGetNumPendingOps(), size_t{2});
8787
EXPECT_TRUE(Writer.EndWriting() == GPUUploadManagerImpl::Page::WritingStatus::NotSealed) << "Page should not be sealed";
8888
EXPECT_EQ(Page.TrySeal(), GPUUploadManagerImpl::Page::SealStatus::Ready) << "Page with no active writers should be ready immediately";
89-
EXPECT_EQ(Page.GetNumPendingOps(), size_t{2});
89+
EXPECT_EQ(Page.DbgGetNumPendingOps(), size_t{2});
9090
Page.ExecutePendingOps(nullptr, 0);
91-
EXPECT_EQ(Page.GetNumPendingOps(), size_t{0});
91+
EXPECT_EQ(Page.DbgGetNumPendingOps(), size_t{0});
9292
}
9393

9494
{
@@ -272,7 +272,7 @@ TEST(GPUUploadManagerPageTest, ScheduleBufferUpdateParallel)
272272
for (auto& thread : threads)
273273
thread.join();
274274

275-
EXPECT_EQ(Page.GetNumPendingOps(), kNumUpdates);
275+
EXPECT_EQ(Page.DbgGetNumPendingOps(), kNumUpdates);
276276
EXPECT_EQ(UpdatesScheduled.load(), kNumUpdates) << "Should be able to schedule updates until the page size is reached";
277277
EXPECT_EQ(Page.TrySeal() == GPUUploadManagerImpl::Page::SealStatus::Ready, true) << "Page should be ready for sealing after all updates are scheduled";
278278
Page.ExecutePendingOps(nullptr, 0);

0 commit comments

Comments
 (0)