Skip to content

Commit a1684cb

Browse files
GPUUploadManager: improve texture page size selection and stats logging
1 parent 1bb5b3e commit a1684cb

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

Graphics/GraphicsTools/src/GPUUploadManagerImpl.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ GPUUploadManagerImpl::UploadStream::UploadStream(GPUUploadManagerImpl& Mgr,
724724
Uint32 InitialPageCount,
725725
TEXTURE_FORMAT Format) noexcept :
726726
m_Mgr{Mgr},
727-
m_PageSize{AlignUpToPowerOfTwo(PageSize)},
727+
m_PageSize{Format == TEX_FORMAT_UNKNOWN ? AlignUpToPowerOfTwo(PageSize) : AlignUp(PageSize, 32u)},
728728
m_MaxPageCount{MaxPageCount},
729729
m_Format{Format}
730730
{
@@ -795,11 +795,13 @@ GPUUploadManagerImpl::UploadStream* GPUUploadManagerImpl::TextureUploadStreams::
795795
const TextureFormatAttribs& FmtAttribs = GetTextureFormatAttribs(Format);
796796

797797
const float BPP =
798-
static_cast<float>(FmtAttribs.ComponentSize * FmtAttribs.NumComponents) /
798+
static_cast<float>(FmtAttribs.GetElementSize()) /
799799
static_cast<float>(FmtAttribs.BlockWidth * FmtAttribs.BlockHeight);
800800

801-
const float fPageSize = std::sqrt(static_cast<float>(m_PageSizeInBytes) / BPP);
802-
const Uint32 PageSize = std::min(std::max(64u, AlignUpToPowerOfTwo(static_cast<Uint32>(fPageSize))), 16384u);
801+
float fPageSize = std::sqrt(static_cast<float>(m_PageSizeInBytes) / BPP);
802+
Uint32 PageSize = std::max(static_cast<Uint32>(fPageSize), 64u);
803+
PageSize = PageSize < 1024 ? AlignUpToPowerOfTwo(PageSize) : AlignUp(PageSize, 2048u);
804+
PageSize = std::min(PageSize, 16384u);
803805

804806
// Don't create initial pages from worker threads because this requires access to
805807
// m_InFlightPages, which is not protected by a mutex.
@@ -1478,7 +1480,10 @@ std::string GetGPUUploadManagerStatsString(const GPUUploadManagerStats& MgrStats
14781480
}
14791481
else
14801482
{
1481-
ss << GetTextureFormatAttribs(StreamStats.Format).Name << ' ' << StreamStats.PageSize << 'x' << StreamStats.PageSize << std::endl;
1483+
const TextureFormatAttribs& FmtAttribs = GetTextureFormatAttribs(StreamStats.Format);
1484+
const Uint32 PageSizeInBytes = StreamStats.PageSize * StreamStats.PageSize * FmtAttribs.GetElementSize() / (FmtAttribs.BlockWidth * FmtAttribs.BlockHeight);
1485+
ss << GetTextureFormatAttribs(StreamStats.Format).Name << ' ' << StreamStats.PageSize << 'x' << StreamStats.PageSize
1486+
<< " (" << GetMemorySizeString(PageSizeInBytes) << ')' << std::endl;
14821487
}
14831488
ss << " NumPages: " << StreamStats.NumPages << std::endl;
14841489

@@ -1503,9 +1508,17 @@ std::string GetGPUUploadManagerStatsString(const GPUUploadManagerStats& MgrStats
15031508
}
15041509

15051510
ss << " NumFreePages: " << StreamStats.NumFreePages << std::endl
1506-
<< " PeakNumPages: " << StreamStats.PeakNumPages << std::endl
1507-
<< " PeakTotalPendingUpdateSize: " << GetMemorySizeString(StreamStats.PeakTotalPendingUpdateSize) << std::endl
1508-
<< " PeakUpdateSize: " << GetMemorySizeString(StreamStats.PeakUpdateSize) << std::endl;
1511+
<< " PeakNumPages: " << StreamStats.PeakNumPages << std::endl;
1512+
1513+
if (StreamStats.Format == TEX_FORMAT_UNKNOWN)
1514+
{
1515+
ss << " PeakTotalPendingUpdateSize: " << GetMemorySizeString(StreamStats.PeakTotalPendingUpdateSize) << std::endl
1516+
<< " PeakUpdateSize: " << GetMemorySizeString(StreamStats.PeakUpdateSize) << std::endl;
1517+
}
1518+
else
1519+
{
1520+
ss << " PeakUpdateDim: " << StreamStats.PeakUpdateSize << std::endl;
1521+
}
15091522
}
15101523

15111524
ss << "NumInFlightPages: " << MgrStats.NumInFlightPages << std::endl;

0 commit comments

Comments
 (0)