Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deflect-related improvements: stream & accum frames cmdline, render throttling #402

Merged
merged 3 commits into from
Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()));
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should either be called only when streaming is enabled, or the parameter should be renamed from imageStreamFPS to something more generic (with a way to adjust/disable it when benchmarking performance).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to rename it now to not break the web API. It can already be changed on the commandline.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I would still rename it everywhere else, but up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a different parameter for this now. The tests were using the existing FPS to 'disable' streaming to speed up the execution of the tests. It also breaks nothing else at the moment hopefully.

}

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
35 changes: 21 additions & 14 deletions brayns/parameters/RenderingParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,31 @@

namespace
{
const std::string PARAM_ENGINE = "engine";
const std::string PARAM_MODULE = "module";
const std::string PARAM_RENDERER = "renderer";
const std::string PARAM_SPP = "samples-per-pixel";
const std::string PARAM_ACCUMULATION = "accumulation";
const std::string PARAM_AMBIENT_OCCLUSION = "ambient-occlusion";
const std::string PARAM_AMBIENT_OCCLUSION_DISTANCE =
"ambient-occlusion-distance";
const std::string PARAM_SHADOWS = "shadows";
const std::string PARAM_SOFT_SHADOWS = "soft-shadows";
const std::string PARAM_SHADING = "shading";
const std::string PARAM_RADIANCE = "radiance";
const std::string PARAM_BACKGROUND_COLOR = "background-color";
const std::string PARAM_CAMERA = "camera";
const std::string PARAM_DETECTION_DISTANCE = "detection-distance";
const std::string PARAM_DETECTION_FAR_COLOR = "detection-far-color";
const std::string PARAM_DETECTION_NEAR_COLOR = "detection-near-color";
const std::string PARAM_DETECTION_ON_DIFFERENT_MATERIAL =
"detection-on-different-material";
const std::string PARAM_DETECTION_NEAR_COLOR = "detection-near-color";
const std::string PARAM_DETECTION_FAR_COLOR = "detection-far-color";
const std::string PARAM_ENGINE = "engine";
const std::string PARAM_EPSILON = "epsilon";
const std::string PARAM_CAMERA = "camera";
const std::string PARAM_STEREO_MODE = "stereo-mode";
const std::string PARAM_HEAD_LIGHT = "head-light";
const std::string PARAM_VARIANCE_THRESHOLD = "variance-threshold";
const std::string PARAM_MAX_ACCUMULATION_FRAMES = "max-accumulation-frames";
const std::string PARAM_MODULE = "module";
const std::string PARAM_RADIANCE = "radiance";
const std::string PARAM_RENDERER = "renderer";
const std::string PARAM_SHADING = "shading";
const std::string PARAM_SHADOWS = "shadows";
const std::string PARAM_SOFT_SHADOWS = "soft-shadows";
const std::string PARAM_SPP = "samples-per-pixel";
const std::string PARAM_SPR = "samples-per-ray";
const std::string PARAM_STEREO_MODE = "stereo-mode";
const std::string PARAM_VARIANCE_THRESHOLD = "variance-threshold";

const std::array<std::string, 2> ENGINES = {{"ospray", "optix"}};
const std::array<std::string, 7> RENDERERS = {
Expand Down Expand Up @@ -119,7 +120,9 @@ RenderingParameters::RenderingParameters()
PARAM_VARIANCE_THRESHOLD.c_str(), po::value<float>(),
"Threshold for adaptive accumulation [float]")(PARAM_SPR.c_str(),
po::value<size_t>(),
"Samples per ray [int]");
"Samples per ray [int]")(
PARAM_MAX_ACCUMULATION_FRAMES.c_str(), po::value<size_t>(),
"Maximum number of accumulation frames");

initializeDefaultRenderers();
initializeDefaultCameras();
Expand Down Expand Up @@ -249,6 +252,8 @@ void RenderingParameters::parse(const po::variables_map& vm)
_varianceThreshold = vm[PARAM_VARIANCE_THRESHOLD].as<float>();
if (vm.count(PARAM_SPR))
_spr = vm[PARAM_SPR].as<size_t>();
if (vm.count(PARAM_MAX_ACCUMULATION_FRAMES))
_maxAccumFrames = vm[PARAM_MAX_ACCUMULATION_FRAMES].as<size_t>();
markModified();
}

Expand Down Expand Up @@ -296,6 +301,8 @@ void RenderingParameters::print()
BRAYNS_INFO << "Accumulation : "
<< (_accumulation ? "on" : "off") << std::endl;
BRAYNS_INFO << "Samples per ray : " << _spr << std::endl;
BRAYNS_INFO << "Max. accumulation frames : " << _maxAccumFrames
<< std::endl;
}

const std::string& RenderingParameters::getEngineAsString(
Expand Down
47 changes: 44 additions & 3 deletions brayns/parameters/StreamParameters.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* Copyright (c) 2015-2016, EPFL/Blue Brain Project
/* Copyright (c) 2015-2018, EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
* Responsible Author: Cyrille Favreau <cyrille.favreau@epfl.ch>
*
* This file is part of Brayns <https://github.com/BlueBrain/Brayns>
*
Expand All @@ -20,15 +19,57 @@

#include "StreamParameters.h"

namespace
{
const std::string PARAM_STREAM_COMPRESSION = "stream-use-compression";
const std::string PARAM_STREAM_HOST = "stream-host";
const std::string PARAM_STREAM_ID = "stream-id";
const std::string PARAM_STREAM_PORT = "stream-port";
const std::string PARAM_STREAM_QUALITY = "stream-quality";
}

namespace brayns
{
StreamParameters::StreamParameters()
: AbstractParameters("Stream")
: AbstractParameters("Streaming")
{
_parameters.add_options()(PARAM_STREAM_COMPRESSION.c_str(),
po::value<bool>(),
"Enable/disable JPEG compression")(
PARAM_STREAM_HOST.c_str(), po::value<std::string>(),
"Hostname of Deflect server")(PARAM_STREAM_ID.c_str(),
po::value<std::string>(),
"Name of stream")(
PARAM_STREAM_PORT.c_str(), po::value<unsigned>(),
"Port of Deflect server")(PARAM_STREAM_QUALITY.c_str(),
po::value<unsigned>(),
"JPEG quality of stream");
}

void StreamParameters::parse(const po::variables_map& vm)
{
if (vm.count(PARAM_STREAM_COMPRESSION))
_compression = vm[PARAM_STREAM_COMPRESSION].as<bool>();
if (vm.count(PARAM_STREAM_HOST))
_host = vm[PARAM_STREAM_HOST].as<std::string>();
if (vm.count(PARAM_STREAM_ID))
_id = vm[PARAM_STREAM_ID].as<std::string>();
if (vm.count(PARAM_STREAM_PORT))
_port = vm[PARAM_STREAM_PORT].as<unsigned>();
if (vm.count(PARAM_STREAM_QUALITY))
_quality = vm[PARAM_STREAM_QUALITY].as<unsigned>();
markModified();
}

void StreamParameters::print()
{
AbstractParameters::print();
BRAYNS_INFO << "Stream compression :"
<< (_compression ? "on" : "off") << std::endl;
BRAYNS_INFO << "Stream host :" << _host << std::endl;
BRAYNS_INFO << "Stream ID :" << _id << std::endl;
BRAYNS_INFO << "Stream port :" << _port << std::endl;
BRAYNS_INFO << "Stream quality :" << _quality
<< std::endl;
}
}
5 changes: 2 additions & 3 deletions brayns/parameters/StreamParameters.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* Copyright (c) 2015-2016, EPFL/Blue Brain Project
/* Copyright (c) 2015-2018, EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
* Responsible Author: Cyrille Favreau <cyrille.favreau@epfl.ch>
*
* This file is part of Brayns <https://github.com/BlueBrain/Brayns>
*
Expand Down Expand Up @@ -58,7 +57,7 @@ class StreamParameters : public AbstractParameters
unsigned getPort() const { return _port; }
void setPort(const unsigned port) { _updateValue(_port, port); }
private:
void parse(const po::variables_map&) final {}
void parse(const po::variables_map& vm);
std::string _host;
bool _enabled{true};
std::string _id;
Expand Down