Skip to content

Commit 3319c60

Browse files
GPUUploadManagerTest: extend ParallelBufferAndTextureUpdates to multiple texture formats
1 parent cf28074 commit 3319c60

File tree

1 file changed

+65
-37
lines changed

1 file changed

+65
-37
lines changed

Tests/DiligentCoreAPITest/src/GPUUploadManagerTest.cpp

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,46 +1135,71 @@ TEST(GPUUploadManagerTest, ParallelBufferAndTextureUpdates)
11351135
CreateGPUUploadManager(CreateInfo, &pUploadManager);
11361136
ASSERT_TRUE(pUploadManager != nullptr);
11371137

1138-
TextureDesc TexDesc;
1139-
TexDesc.Name = "GPUUploadManagerTest texture";
1140-
TexDesc.Type = RESOURCE_DIM_TEX_2D_ARRAY;
1141-
TexDesc.Format = TEX_FORMAT_RGBA8_UNORM;
1142-
TexDesc.Usage = USAGE_DEFAULT;
1143-
TexDesc.Width = 512;
1144-
TexDesc.Height = 512;
1145-
TexDesc.ArraySize = 32;
1146-
TexDesc.MipLevels = 4;
1147-
TexDesc.BindFlags = BIND_SHADER_RESOURCE;
1148-
RefCntAutoPtr<ITexture> pTexture;
1149-
pDevice->CreateTexture(TexDesc, nullptr, &pTexture);
1150-
ASSERT_NE(pTexture, nullptr);
1151-
1152-
const std::vector<std::vector<Uint8>> SubresData = GenerateTextureSubresData(TexDesc);
1138+
struct TextureAndSubresData
1139+
{
1140+
RefCntAutoPtr<ITexture> pTexture;
1141+
std::vector<std::vector<Uint8>> SubresData;
1142+
};
1143+
1144+
constexpr TEXTURE_FORMAT Formats[] = {
1145+
TEX_FORMAT_R8_UNORM,
1146+
TEX_FORMAT_RG8_UNORM,
1147+
TEX_FORMAT_RGBA8_UNORM,
1148+
TEX_FORMAT_RG16_UINT,
1149+
TEX_FORMAT_RGBA32_UINT,
1150+
};
1151+
std::array<TextureAndSubresData, _countof(Formats)> TexAndData;
11531152

11541153
std::vector<ScheduleTextureUpdateInfo> TextureUpdates;
1155-
for (Uint32 MipLevel = 0; MipLevel < TexDesc.MipLevels; ++MipLevel)
1154+
for (size_t i = 0; i < TexAndData.size(); ++i)
11561155
{
1157-
const MipLevelProperties Mip = GetMipLevelProperties(TexDesc, MipLevel);
1158-
for (Uint32 ArraySlice = 0; ArraySlice < TexDesc.ArraySize; ++ArraySlice)
1159-
{
1160-
const std::vector<Uint8>& MipData = SubresData[GetSubresourceIndex(TexDesc, MipLevel, ArraySlice)];
1156+
const std::string Name = std::string{"GPUUploadManagerTest texture"} + GetTextureFormatAttribs(Formats[i]).Name;
1157+
1158+
TextureDesc TexDesc;
1159+
TexDesc.Name = Name.c_str();
1160+
TexDesc.Type = RESOURCE_DIM_TEX_2D_ARRAY;
1161+
TexDesc.Format = Formats[i];
1162+
TexDesc.Usage = USAGE_DEFAULT;
1163+
TexDesc.Width = 512;
1164+
TexDesc.Height = 512;
1165+
TexDesc.ArraySize = 32;
1166+
TexDesc.MipLevels = 7;
1167+
TexDesc.BindFlags = BIND_SHADER_RESOURCE;
1168+
RefCntAutoPtr<ITexture>& pTexture = TexAndData[i].pTexture;
1169+
pDevice->CreateTexture(TexDesc, nullptr, &pTexture);
1170+
ASSERT_NE(pTexture, nullptr);
1171+
1172+
std::vector<std::vector<Uint8>>& SubresData{TexAndData[i].SubresData};
1173+
SubresData = GenerateTextureSubresData(TexDesc);
11611174

1162-
constexpr Uint32 UpdateWidth = 32;
1163-
constexpr Uint32 UpdateHeight = 32;
1164-
for (Uint32 x = 0; x < Mip.LogicalWidth; x += UpdateWidth)
1175+
for (Uint32 MipLevel = 0; MipLevel < TexDesc.MipLevels; ++MipLevel)
1176+
{
1177+
const MipLevelProperties Mip = GetMipLevelProperties(TexDesc, MipLevel);
1178+
for (Uint32 ArraySlice = 0; ArraySlice < TexDesc.ArraySize; ++ArraySlice)
11651179
{
1166-
for (Uint32 y = 0; y < Mip.LogicalHeight; y += UpdateHeight)
1180+
const std::vector<Uint8>& MipData = SubresData[GetSubresourceIndex(TexDesc, MipLevel, ArraySlice)];
1181+
1182+
const TextureFormatAttribs& FmtAttribs = GetTextureFormatAttribs(TexDesc.Format);
1183+
const Uint32 ElementSize = FmtAttribs.ComponentSize * FmtAttribs.NumComponents;
1184+
1185+
const Uint32 UpdateWidth = std::min((ArraySlice % 4 == 0) ? Mip.LogicalWidth / 2 : 32, Mip.LogicalWidth);
1186+
const Uint32 UpdateHeight = std::min((ArraySlice % 4 == 0) ? Mip.LogicalHeight / 2 : 32, Mip.LogicalHeight);
1187+
for (Uint32 x = 0; x < Mip.LogicalWidth; x += UpdateWidth)
11671188
{
1168-
ScheduleTextureUpdateInfo UpdateInfo;
1169-
UpdateInfo.pDstTexture = pTexture;
1170-
UpdateInfo.DstBox.MinX = x;
1171-
UpdateInfo.DstBox.MinY = y;
1172-
UpdateInfo.DstBox.MaxX = x + UpdateWidth;
1173-
UpdateInfo.DstBox.MaxY = y + UpdateHeight;
1174-
UpdateInfo.DstMipLevel = MipLevel;
1175-
UpdateInfo.DstSlice = ArraySlice;
1176-
UpdateInfo.pSrcData = &MipData[static_cast<size_t>(Mip.RowSize * y + x * 4)];
1177-
TextureUpdates.push_back(UpdateInfo);
1189+
for (Uint32 y = 0; y < Mip.LogicalHeight; y += UpdateHeight)
1190+
{
1191+
ScheduleTextureUpdateInfo UpdateInfo;
1192+
UpdateInfo.pDstTexture = pTexture;
1193+
UpdateInfo.DstBox.MinX = x;
1194+
UpdateInfo.DstBox.MinY = y;
1195+
UpdateInfo.DstBox.MaxX = x + UpdateWidth;
1196+
UpdateInfo.DstBox.MaxY = y + UpdateHeight;
1197+
UpdateInfo.DstMipLevel = MipLevel;
1198+
UpdateInfo.DstSlice = ArraySlice;
1199+
UpdateInfo.pSrcData = &MipData[static_cast<size_t>(Mip.RowSize * y + x * ElementSize)];
1200+
UpdateInfo.Stride = Mip.RowSize;
1201+
TextureUpdates.push_back(UpdateInfo);
1202+
}
11781203
}
11791204
}
11801205
}
@@ -1198,7 +1223,6 @@ TEST(GPUUploadManagerTest, ParallelBufferAndTextureUpdates)
11981223
pDevice->CreateBuffer(Desc, nullptr, &pBuffer);
11991224
ASSERT_TRUE(pBuffer);
12001225

1201-
12021226
const size_t kNumThreads = std::max(2u, std::thread::hardware_concurrency() - 1);
12031227
LOG_INFO_MESSAGE("Number of threads: ", kNumThreads);
12041228

@@ -1273,9 +1297,13 @@ TEST(GPUUploadManagerTest, ParallelBufferAndTextureUpdates)
12731297
thread.join();
12741298
}
12751299

1276-
LogUploadManagerStats(pUploadManager);
12771300
VerifyBufferContents(pBuffer, BufferData);
1278-
VerifyTextureContents(pTexture, SubresData);
1301+
for (const TextureAndSubresData& Data : TexAndData)
1302+
{
1303+
VerifyTextureContents(Data.pTexture, Data.SubresData);
1304+
}
1305+
1306+
LogUploadManagerStats(pUploadManager);
12791307
}
12801308

12811309

0 commit comments

Comments
 (0)