Skip to content

Commit aa51d4e

Browse files
GPUUploadManager: add bucket info to stats
1 parent ab1966d commit aa51d4e

4 files changed

Lines changed: 59 additions & 3 deletions

File tree

Graphics/GraphicsTools/include/GPUUploadManagerImpl.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ class GPUUploadManagerImpl final : public ObjectBase<IGPUUploadManager>
218218
Page* AcquireFreePage(IDeviceContext* pContext, Uint32 RequiredSize = 0);
219219
Page* CreatePage(IDeviceContext* pContext, Uint32 RequiredSize = 0);
220220
void ProcessPagesToRelease(IDeviceContext* pContext);
221+
void UpdateBucketInfo();
221222

222223
private:
223224
const Uint32 m_PageSize;
@@ -257,6 +258,7 @@ class GPUUploadManagerImpl final : public ObjectBase<IGPUUploadManager>
257258

258259
std::unordered_map<Page*, std::unique_ptr<Page>> m_Pages;
259260
std::map<Uint32, Uint32> m_PageSizeToCount;
261+
std::vector<GPUUploadManagerBucketInfo> m_BucketInfo;
260262

261263
// The number of running ScheduleBufferUpdate operations.
262264
std::atomic<Uint32> m_NumRunningUpdates{0};

Graphics/GraphicsTools/interface/GPUUploadManager.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ typedef void (*GPUUploadEnqueuedCallbackType)(IBuffer* pDstBuffer,
6565
void* pUserData);
6666

6767

68+
/// GPU upload manager page bucket information.
69+
struct GPUUploadManagerBucketInfo
70+
{
71+
/// Page size in bytes.
72+
Uint32 PageSize DEFAULT_INITIALIZER(0);
73+
74+
/// Number of pages currently in the manager.
75+
Uint32 NumPages DEFAULT_INITIALIZER(0);
76+
};
77+
typedef struct GPUUploadManagerBucketInfo GPUUploadManagerBucketInfo;
78+
79+
6880
/// GPU upload manager statistics.
6981
struct GPUUploadManagerStats
7082
{
@@ -87,6 +99,13 @@ struct GPUUploadManagerStats
8799

88100
/// Peak size of a single update in bytes.
89101
Uint32 PeakUpdateSize DEFAULT_INITIALIZER(0);
102+
103+
/// The number of buckets in the manager. Each bucket corresponds to a specific page size.
104+
Uint32 NumBuckets DEFAULT_INITIALIZER(0);
105+
106+
/// Information about each bucket. The array contains NumBuckets valid entries.
107+
/// The pointer is valid only until the next call to GetStats() method and only while the manager is alive.
108+
const GPUUploadManagerBucketInfo* pBucketInfo DEFAULT_INITIALIZER(nullptr);
90109
};
91110
typedef struct GPUUploadManagerStats GPUUploadManagerStats;
92111

Graphics/GraphicsTools/src/GPUUploadManagerImpl.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ GPUUploadManagerImpl::Page* GPUUploadManagerImpl::CreatePage(IDeviceContext* pCo
591591
}
592592
m_Pages.emplace(P, std::move(NewPage));
593593
m_PageSizeToCount[PageSize]++;
594+
UpdateBucketInfo();
594595
m_PeakPageCount = std::max(m_PeakPageCount, static_cast<Uint32>(m_Pages.size()));
595596

596597
return P;
@@ -760,6 +761,7 @@ void GPUUploadManagerImpl::ProcessPagesToRelease(IDeviceContext* pContext)
760761
UNEXPECTED("Page size not found in the map");
761762
}
762763
m_Pages.erase(pPage);
764+
UpdateBucketInfo();
763765
}
764766
else
765767
{
@@ -806,6 +808,15 @@ GPUUploadManagerImpl::Page* GPUUploadManagerImpl::AcquireFreePage(IDeviceContext
806808
return P;
807809
}
808810

811+
void GPUUploadManagerImpl::UpdateBucketInfo()
812+
{
813+
m_BucketInfo.clear();
814+
for (const auto& it : m_PageSizeToCount)
815+
{
816+
m_BucketInfo.emplace_back(GPUUploadManagerBucketInfo{it.first, it.second});
817+
}
818+
}
819+
809820
void GPUUploadManagerImpl::GetStats(GPUUploadManagerStats& Stats) const
810821
{
811822
Stats.NumPages = static_cast<Uint32>(m_Pages.size());
@@ -815,6 +826,9 @@ void GPUUploadManagerImpl::GetStats(GPUUploadManagerStats& Stats) const
815826

816827
Stats.PeakTotalPendingUpdateSize = m_PeakTotalPendingUpdateSize;
817828
Stats.PeakUpdateSize = m_PeakUpdateSize.load(std::memory_order_relaxed);
829+
830+
Stats.NumBuckets = static_cast<Uint32>(m_PageSizeToCount.size());
831+
Stats.pBucketInfo = m_BucketInfo.data();
818832
}
819833

820834
void CreateGPUUploadManager(const GPUUploadManagerCreateInfo& CreateInfo,

Tests/DiligentCoreAPITest/src/GPUUploadManagerTest.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,25 @@ using namespace std::chrono_literals;
4545
namespace
4646
{
4747

48+
std::string PrintBucketInfo(const GPUUploadManagerStats& Stats)
49+
{
50+
std::string Result;
51+
for (Uint32 i = 0; i < Stats.NumBuckets; ++i)
52+
{
53+
if (!Result.empty())
54+
Result.push_back('\n');
55+
Result += " ";
56+
const GPUUploadManagerBucketInfo& BucketInfo = Stats.pBucketInfo[i];
57+
Result += GetMemorySizeString(BucketInfo.PageSize) + ": ";
58+
for (Uint32 j = 0; j < BucketInfo.NumPages; ++j)
59+
{
60+
Result.push_back('#');
61+
}
62+
Result += " " + std::to_string(BucketInfo.NumPages);
63+
}
64+
return Result;
65+
}
66+
4867
TEST(GPUUploadManagerTest, Creation)
4968
{
5069
GPUTestingEnvironment* pEnv = GPUTestingEnvironment::GetInstance();
@@ -233,7 +252,8 @@ TEST(GPUUploadManagerTest, ParallelUpdates)
233252
"\n NumFreePages ", Stats.NumFreePages,
234253
"\n NumInFlightPages ", Stats.NumInFlightPages,
235254
"\n PeakTotalPendingUpdateSize ", Stats.PeakTotalPendingUpdateSize,
236-
"\n PeakUpdateSize ", Stats.PeakUpdateSize);
255+
"\n PeakUpdateSize ", Stats.PeakUpdateSize,
256+
"\n Buckets:\n", PrintBucketInfo(Stats));
237257

238258
VerifyBufferContents(pBuffer, BufferData);
239259
}
@@ -373,7 +393,8 @@ TEST(GPUUploadManagerTest, CreateWithNullContext)
373393
"\n NumFreePages ", Stats.NumFreePages,
374394
"\n NumInFlightPages ", Stats.NumInFlightPages,
375395
"\n PeakTotalPendingUpdateSize ", Stats.PeakTotalPendingUpdateSize,
376-
"\n PeakUpdateSize ", Stats.PeakUpdateSize);
396+
"\n PeakUpdateSize ", Stats.PeakUpdateSize,
397+
"\n Buckets:\n", PrintBucketInfo(Stats));
377398
}
378399

379400

@@ -455,7 +476,7 @@ TEST(GPUUploadManagerTest, MaxPageCount)
455476

456477
GPUUploadManagerStats Stats;
457478
pUploadManager->GetStats(Stats);
458-
LOG_INFO_MESSAGE("Peak number of pages: ", Stats.PeakNumPages);
479+
LOG_INFO_MESSAGE("Peak number of pages: ", Stats.PeakNumPages, "\nBucket info:\n", PrintBucketInfo(Stats));
459480
EXPECT_EQ(Stats.NumPages, CreateInfo.MaxPageCount) << "Page count should not exceed the specified maximum";
460481
}
461482

0 commit comments

Comments
 (0)