Skip to content

Commit deb956d

Browse files
GPUUploadManager: use TickSignal to wait for page rotation
1 parent 28c4587 commit deb956d

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Graphics/GraphicsTools/include/GPUUploadManagerImpl.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "ObjectBase.hpp"
3535
#include "RefCntAutoPtr.hpp"
3636
#include "MPSCQueue.hpp"
37+
#include "ThreadSignal.hpp"
3738

3839
#include <memory>
3940
#include <vector>
@@ -250,7 +251,8 @@ class GPUUploadManagerImpl final : public ObjectBase<IGPUUploadManager>
250251
RefCntAutoPtr<IFence> m_pFence;
251252
Uint64 m_NextFenceValue = 1;
252253

253-
std::atomic<Page*> m_pCurrentPage{nullptr};
254+
std::atomic<Page*> m_pCurrentPage{nullptr};
255+
Threading::TickSignal m_PageRotatedSignal;
254256

255257
std::vector<std::unique_ptr<Page>> m_Pages;
256258

Graphics/GraphicsTools/src/GPUUploadManagerImpl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ void GPUUploadManagerImpl::RenderThreadUpdate(IDeviceContext* pContext)
372372
ProcessPendingPages(pContext);
373373

374374
pContext->EnqueueSignal(m_pFence, m_NextFenceValue++);
375+
m_PageRotatedSignal.Tick();
375376
}
376377

377378
void GPUUploadManagerImpl::ScheduleBufferUpdate(IDeviceContext* pContext,
@@ -393,9 +394,10 @@ void GPUUploadManagerImpl::ScheduleBufferUpdate(IDeviceContext* pC
393394
m_TotalPendingUpdateSize.fetch_add(NumBytes, std::memory_order_relaxed);
394395
IsFirstAttempt = false;
395396
}
397+
Uint64 PageEpoch = m_PageRotatedSignal.CurrentEpoch();
396398
if (!TryRotatePage(pContext, P))
397399
{
398-
std::this_thread::yield();
400+
m_PageRotatedSignal.WaitNext(PageEpoch);
399401
}
400402
};
401403

@@ -484,6 +486,7 @@ bool GPUUploadManagerImpl::TryRotatePage(IDeviceContext* pContext, Page* Expecte
484486
if (ExpectedCurrent && ExpectedCurrent->TrySeal() == Page::SealStatus::Ready)
485487
TryEnqueuePage(ExpectedCurrent);
486488

489+
m_PageRotatedSignal.Tick();
487490
return true;
488491
}
489492

0 commit comments

Comments
 (0)