Skip to content

Commit

Permalink
Introduce max-render-FPS to throttle rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
tribal-tec committed Jun 1, 2018
1 parent 99b2f3a commit 7b9a389
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
20 changes: 16 additions & 4 deletions brayns/Brayns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,11 +389,23 @@ struct Brayns::Impl : public PluginAPI

void render()
{
std::lock_guard<std::mutex> lock{_renderMutex};
{
std::lock_guard<std::mutex> lock{_renderMutex};

_renderTimer.start();
_engine->render();
_renderTimer.stop();
}

_renderTimer.start();
_engine->render();
_renderTimer.stop();
const auto& params = _parametersManager.getApplicationParameters();
const auto fps = params.getMaxRenderFPS();
const auto delta = _renderTimer.perSecondSmoothed() - fps;
if (delta > 0)
{
const int64_t targetTime = (1. / fps) * 1000.f;
std::this_thread::sleep_for(std::chrono::milliseconds(
targetTime - _renderTimer.milliseconds()));
}
}

Engine& getEngine() { return *_engine; }
Expand Down
8 changes: 7 additions & 1 deletion brayns/parameters/ApplicationParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const std::string PARAM_IMAGE_STREAM_FPS = "image-stream-fps";
const std::string PARAM_INPUT_PATHS = "input-paths";
const std::string PARAM_JPEG_COMPRESSION = "jpeg-compression";
const std::string PARAM_JPEG_SIZE = "jpeg-size";
const std::string PARAM_MAX_RENDER_FPS = "max-render-fps";
const std::string PARAM_PLUGIN = "plugin";
const std::string PARAM_SYNCHRONOUS_MODE = "synchronous-mode";
const std::string PARAM_TMP_FOLDER = "tmp-folder";
Expand Down Expand Up @@ -78,7 +79,8 @@ ApplicationParameters::ApplicationParameters()
PARAM_FILTERS.c_str(), po::value<strings>()->multitoken(),
"Screen space filters [string]")(
PARAM_FRAME_EXPORT_FOLDER.c_str(), po::value<std::string>(),
"Folder where frames are exported as PNG images [string]");
"Folder where frames are exported as PNG images [string]")(
PARAM_MAX_RENDER_FPS.c_str(), po::value<size_t>(), "Max. render FPS");

_positionalArgs.add(PARAM_INPUT_PATHS.c_str(), -1);
}
Expand Down Expand Up @@ -112,6 +114,8 @@ void ApplicationParameters::parse(const po::variables_map& vm)
_synchronousMode = vm[PARAM_SYNCHRONOUS_MODE].as<bool>();
if (vm.count(PARAM_IMAGE_STREAM_FPS))
_imageStreamFPS = vm[PARAM_IMAGE_STREAM_FPS].as<size_t>();
if (vm.count(PARAM_MAX_RENDER_FPS))
_maxRenderFPS = vm[PARAM_MAX_RENDER_FPS].as<size_t>();

markModified();
}
Expand All @@ -129,5 +133,7 @@ void ApplicationParameters::print()
<< std::endl;
BRAYNS_INFO << "Image stream FPS : " << _imageStreamFPS
<< std::endl;
BRAYNS_INFO << "Max. render FPS : " << _maxRenderFPS
<< std::endl;
}
}
3 changes: 3 additions & 0 deletions brayns/parameters/ApplicationParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class ApplicationParameters : public AbstractParameters
_updateValue(_imageStreamFPS, fps);
}

/** Max render FPS to limit */
size_t getMaxRenderFPS() const { return _maxRenderFPS; }
const strings& getFilters() const { return _filters; }
void setFrameExportFolder(const std::string& folder)
{
Expand Down Expand Up @@ -100,6 +102,7 @@ class ApplicationParameters : public AbstractParameters
std::string _tmpFolder;
bool _synchronousMode{false};
size_t _imageStreamFPS{60};
size_t _maxRenderFPS{std::numeric_limits<size_t>::max()};
std::string _httpServerURI;

strings _inputPaths;
Expand Down

0 comments on commit 7b9a389

Please sign in to comment.