Skip to content

Commit cd18bc0

Browse files
Radient: make texture upload test waits time-based
Use a wall-clock timeout instead of a fixed retry count and avoid busy-waiting while asynchronous texture uploads are pending.
1 parent 5c325c3 commit cd18bc0

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

Tests/RadientGPUTest/src/RadientAssetManagerGPUTest.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ using namespace std::chrono_literals;
5151
namespace
5252
{
5353

54+
static constexpr auto TextureManagerWaitTimeout = std::chrono::seconds{10};
55+
5456
std::vector<Uint8> MakeTexturePixels(Uint32 Width,
5557
Uint32 Height,
5658
Uint32 Stride,
@@ -105,14 +107,15 @@ bool IsPendingOrOK(RADIENT_STATUS Status)
105107

106108
bool WaitForPendingCopyCommandEnqueueCallbacks(RadientAssetManagerImpl& AssetManager)
107109
{
108-
for (Uint32 i = 0; i < 256; ++i)
110+
const auto Deadline = std::chrono::steady_clock::now() + TextureManagerWaitTimeout;
111+
do
109112
{
110113
const RadientTextureAssetManagerStats Stats = AssetManager.GetTextureManagerStats();
111114
if (Stats.PendingCopyCommandEnqueueCallbacks != 0)
112115
return true;
113116

114117
std::this_thread::sleep_for(1ms);
115-
}
118+
} while (std::chrono::steady_clock::now() < Deadline);
116119

117120
return AssetManager.GetTextureManagerStats().PendingCopyCommandEnqueueCallbacks != 0;
118121
}
@@ -121,7 +124,8 @@ bool WaitForTextureManagerIdle(RadientAssetManagerImpl& AssetManager,
121124
IRenderDevice* pDevice,
122125
IDeviceContext* pContext)
123126
{
124-
for (Uint32 i = 0; i < 256; ++i)
127+
const auto Deadline = std::chrono::steady_clock::now() + TextureManagerWaitTimeout;
128+
do
125129
{
126130
const RadientTextureAssetManagerStats Stats = AssetManager.GetTextureManagerStats();
127131
if (Stats.PendingTextureLoads == 0 &&
@@ -137,11 +141,10 @@ bool WaitForTextureManagerIdle(RadientAssetManagerImpl& AssetManager,
137141
pContext->Flush();
138142
pContext->FinishFrame();
139143
}
140-
else
141-
{
142-
std::this_thread::sleep_for(1ms);
143-
}
144-
}
144+
145+
// Avoid busy-waiting while asynchronous texture work is in progress.
146+
std::this_thread::sleep_for(1ms);
147+
} while (std::chrono::steady_clock::now() < Deadline);
145148

146149
const RadientTextureAssetManagerStats Stats = AssetManager.GetTextureManagerStats();
147150
return Stats.PendingTextureLoads == 0 &&

Tests/RadientGPUTest/src/RadientGPUTestHelpers.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ namespace RadientGPUTest
4545
namespace
4646
{
4747

48-
static constexpr Uint32 TestVertexPoolSize = 1024;
49-
static constexpr Uint64 TestIndexBufferSize = 1024 * 1024;
50-
static constexpr Uint32 TestTextureAtlasMaxSlice = 16;
48+
static constexpr Uint32 TestVertexPoolSize = 1024;
49+
static constexpr Uint64 TestIndexBufferSize = 1024 * 1024;
50+
static constexpr Uint32 TestTextureAtlasMaxSlice = 16;
51+
static constexpr auto TextureManagerWaitTimeout = std::chrono::seconds{10};
5152

5253
Uint32 GetTextureStride(const TestTextureParams& Params)
5354
{
@@ -214,17 +215,19 @@ bool WaitForTextureManagerIdle(const RadientTextureAssetManagerSharedPtr& Manage
214215
{
215216
using namespace std::chrono_literals;
216217

217-
for (Uint32 i = 0; i < 256; ++i)
218+
const auto Deadline = std::chrono::steady_clock::now() + TextureManagerWaitTimeout;
219+
do
218220
{
219221
const RadientTextureAssetManagerStats Stats = Manager->GetStats();
220222
if (IsTextureManagerIdle(Stats))
221223
return true;
222224

223225
if (Stats.PendingCopyCommandEnqueueCallbacks != 0)
224226
PumpUploadManager(UploadManager, Context);
225-
else
226-
std::this_thread::sleep_for(1ms);
227-
}
227+
228+
// Avoid busy-waiting while asynchronous texture work is in progress.
229+
std::this_thread::sleep_for(1ms);
230+
} while (std::chrono::steady_clock::now() < Deadline);
228231

229232
return IsTextureManagerIdle(Manager->GetStats());
230233
}
@@ -233,14 +236,15 @@ bool WaitForPendingCopyCommandEnqueueCallbacks(const RadientTextureAssetManagerS
233236
{
234237
using namespace std::chrono_literals;
235238

236-
for (Uint32 i = 0; i < 256; ++i)
239+
const auto Deadline = std::chrono::steady_clock::now() + TextureManagerWaitTimeout;
240+
do
237241
{
238242
const RadientTextureAssetManagerStats Stats = Manager->GetStats();
239243
if (Stats.PendingCopyCommandEnqueueCallbacks != 0)
240244
return true;
241245

242246
std::this_thread::sleep_for(1ms);
243-
}
247+
} while (std::chrono::steady_clock::now() < Deadline);
244248

245249
return Manager->GetStats().PendingCopyCommandEnqueueCallbacks != 0;
246250
}

0 commit comments

Comments
 (0)