Skip to content

Commit f742dda

Browse files
committed
uploading assets to gpu memory does not affect dynamic resolution
1 parent 69781d0 commit f742dda

File tree

3 files changed

+46
-19
lines changed

3 files changed

+46
-19
lines changed

sources/libsimple/engine.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ namespace cage
1313
void graphicsEmit(uint64 time); // control thread
1414
void graphicsPrepare(uint64 time, uint32 &drawCalls, uint32 &drawPrimitives, Real &dynamicResolution); // prepare thread
1515
void graphicsDispatch(); // opengl thread
16-
void graphicsSwap(uint64 &gpuTime); // opengl thread
16+
void graphicsSwap(); // opengl thread
17+
void graphicsFrameStart(); // opengl thread
18+
void graphicsFrameFinish(uint64 &gpuTime); // opengl thread
1719

1820
void soundCreate(const EngineCreateConfig &config);
1921
void soundDestroy();

sources/libsimple/gameloop.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ namespace cage
207207
{
208208
ProfilingScope profiling("graphics dispatch", ProfilingFrameTag());
209209
ScopedTimer timing(profilingBufferFrameTime);
210+
{
211+
ProfilingScope profiling("frame start");
212+
graphicsFrameStart();
213+
}
210214
{
211215
ProfilingScope profiling("graphics dispatch callback");
212216
graphicsDispatchThread().dispatch.dispatch();
@@ -224,23 +228,27 @@ namespace cage
224228
CAGE_CHECK_GL_ERROR_DEBUG();
225229
}
226230
{
227-
ProfilingScope profiling("graphics assets");
228-
const uint64 start = applicationTime();
229-
while (assets->processCustomThread(1))
230-
{
231-
if (applicationTime() > start + 5'000)
232-
break;
233-
}
231+
ProfilingScope profiling("frame finish");
232+
uint64 gpuTime = 0;
233+
graphicsFrameFinish(gpuTime);
234+
profilingBufferGpuTime.add(gpuTime);
234235
}
235236
{
236237
ProfilingScope profiling("swap callback");
237238
graphicsDispatchThread().swap.dispatch();
238239
}
239240
{
240241
ProfilingScope profiling("swap");
241-
uint64 gpuTime = 0;
242-
graphicsSwap(gpuTime);
243-
profilingBufferGpuTime.add(gpuTime);
242+
graphicsSwap();
243+
}
244+
{
245+
ProfilingScope profiling("graphics assets");
246+
const uint64 start = applicationTime();
247+
while (assets->processCustomThread(1))
248+
{
249+
if (applicationTime() > start + 5'000)
250+
break;
251+
}
244252
}
245253
}
246254

sources/libsimple/graphics.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,7 @@ namespace cage
206206

207207
void updateDynamicResolution()
208208
{
209-
// dynamic resolution may update every 4 frames at most
210-
if ((frameIndex % 4) != 0 || frameIndex < 100)
209+
if (frameIndex < nextAllowedDrFrameIndex)
211210
return;
212211

213212
if (!engineDynamicResolution().enabled)
@@ -226,8 +225,11 @@ namespace cage
226225
if (!valid(k))
227226
return;
228227
k = clamp(k, engineDynamicResolution().minimumScale, 1);
229-
if (abs(dynamicResolution - k) > 0.02)
230-
dynamicResolution = k;
228+
if (abs(dynamicResolution - k) < 0.02)
229+
return;
230+
231+
dynamicResolution = k;
232+
nextAllowedDrFrameIndex = frameIndex + 5;
231233
}
232234

233235
void prepareCameras(const RenderPipelineConfig &cfg, Holder<VirtualRealityGraphicsFrame> vrFrame)
@@ -474,11 +476,15 @@ namespace cage
474476
void swap() // opengl thread
475477
{
476478
CAGE_CHECK_GL_ERROR_DEBUG();
479+
engineWindow()->swapBuffers();
480+
}
481+
482+
void frameStart() { timeQueries[0].start(); }
483+
484+
void frameFinish()
485+
{
477486
timeQueries[0].finish();
478487
std::rotate(timeQueries.begin(), timeQueries.begin() + 1, timeQueries.end());
479-
engineWindow()->swapBuffers();
480-
// this is where the engine should be waiting for the gpu
481-
timeQueries[0].start();
482488
}
483489

484490
Holder<RenderQueue> renderQueue;
@@ -491,6 +497,7 @@ namespace cage
491497
uint64 lastDispatchTime = 0;
492498
uint32 frameIndex = 0;
493499
Real dynamicResolution = 1;
500+
uint32 nextAllowedDrFrameIndex = 100; // do not update DR at the very start
494501
std::array<TimeQuery, 3> timeQueries = {};
495502
};
496503

@@ -535,9 +542,19 @@ namespace cage
535542
graphics->dispatch();
536543
}
537544

538-
void graphicsSwap(uint64 &gpuTime)
545+
void graphicsSwap()
539546
{
540547
graphics->swap();
548+
}
549+
550+
void graphicsFrameStart()
551+
{
552+
graphics->frameStart();
553+
}
554+
555+
void graphicsFrameFinish(uint64 &gpuTime)
556+
{
557+
graphics->frameFinish();
541558
gpuTime = graphics->timeQueries[0].time / 1000;
542559
}
543560

0 commit comments

Comments
 (0)