Skip to content

Commit a52dc0d

Browse files
GPUUploadManager: fix render-thread deadlock when upload stream reaches max page count
1 parent 3319c60 commit a52dc0d

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Graphics/GraphicsTools/src/GPUUploadManagerImpl.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,10 +1141,15 @@ void GPUUploadManagerImpl::ScheduleTextureUpdate(const ScheduleTextureUpdateInfo
11411141

11421142
GPUUploadManagerImpl::Page* GPUUploadManagerImpl::UploadStream::CreatePage(IDeviceContext* pContext, Uint32 RequiredSize)
11431143
{
1144-
const Uint32 MaxExistingPageSize = m_PageSizeToCount.empty() ? 0 : m_PageSizeToCount.rbegin()->first;
1145-
if (m_MaxPageCount != 0 && m_Pages.size() >= m_MaxPageCount && RequiredSize <= MaxExistingPageSize)
1144+
// Always create a new page from the render thread (when pContext is not null) to avoid deadlock in
1145+
// UploadStream::ScheduleUpdate.
1146+
if (pContext == nullptr)
11461147
{
1147-
return nullptr;
1148+
const Uint32 MaxExistingPageSize = m_PageSizeToCount.empty() ? 0 : m_PageSizeToCount.rbegin()->first;
1149+
if (m_MaxPageCount != 0 && m_Pages.size() >= m_MaxPageCount && RequiredSize <= MaxExistingPageSize)
1150+
{
1151+
return nullptr;
1152+
}
11481153
}
11491154

11501155
Uint32 PageSize = m_PageSize;

Tests/DiligentCoreAPITest/src/GPUUploadManagerTest.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ TEST(GPUUploadManagerTest, ScheduleBufferUpdatesWithCopyBufferCallback)
157157
RefCntAutoPtr<IGPUUploadManager> pUploadManager;
158158
GPUUploadManagerCreateInfo CreateInfo{pDevice, pContext, 1024, 2048};
159159
CreateInfo.InitialPageCount = 2;
160-
CreateInfo.MaxPageCount = 0;
160+
// Set small max page count to test that ScheduleBufferUpdate creates new pages even when the limit
161+
// is reached when called from the render thread.
162+
CreateInfo.MaxPageCount = 2;
163+
CreateInfo.MaxLargePageCount = 1;
161164
CreateGPUUploadManager(CreateInfo, &pUploadManager);
162165
ASSERT_TRUE(pUploadManager != nullptr);
163166

0 commit comments

Comments
 (0)