Report the actual GPU framerate rather than the main thread submit rate when using the filament renderer.
PiperOrigin-RevId: 838775463 Change-Id: If66644d284a4a9e0263cf31bfbd1785b18e0209b
This commit is contained in:
committed by
Copybara-Service
parent
4896e698f6
commit
448fc0e4d5
@@ -33,6 +33,7 @@
|
|||||||
#include <filament/Texture.h>
|
#include <filament/Texture.h>
|
||||||
#include <filament/View.h>
|
#include <filament/View.h>
|
||||||
#include <math/vec4.h>
|
#include <math/vec4.h>
|
||||||
|
#include <utils/FixedCapacityVector.h>
|
||||||
#include <mujoco/mjmodel.h>
|
#include <mujoco/mjmodel.h>
|
||||||
#include <mujoco/mjvisualize.h>
|
#include <mujoco/mjvisualize.h>
|
||||||
#include <mujoco/mujoco.h>
|
#include <mujoco/mujoco.h>
|
||||||
@@ -310,4 +311,15 @@ void FilamentContext::UploadFont(const uint8_t* pixels, int width, int height,
|
|||||||
int id) {
|
int id) {
|
||||||
object_manager_->UploadFont(pixels, width, height, id);
|
object_manager_->UploadFont(pixels, width, height, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double FilamentContext::GetFrameRate() const {
|
||||||
|
utils::FixedCapacityVector<filament::Renderer::FrameInfo> frame_info =
|
||||||
|
renderer_->getFrameInfoHistory(1);
|
||||||
|
if (frame_info.empty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
const int64_t ns = frame_info[0].denoisedGpuFrameDuration;
|
||||||
|
return 1.0e9 / static_cast<double>(ns);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace mujoco
|
} // namespace mujoco
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ class FilamentContext {
|
|||||||
|
|
||||||
void UploadFont(const uint8_t* pixels, int width, int height, int id);
|
void UploadFont(const uint8_t* pixels, int width, int height, int id);
|
||||||
|
|
||||||
|
double GetFrameRate() const;
|
||||||
|
|
||||||
FilamentContext(const FilamentContext&) = delete;
|
FilamentContext(const FilamentContext&) = delete;
|
||||||
FilamentContext& operator=(const FilamentContext&) = delete;
|
FilamentContext& operator=(const FilamentContext&) = delete;
|
||||||
|
|
||||||
|
|||||||
@@ -146,4 +146,9 @@ void mjr_uploadFont(const unsigned char* pixels, int width, int height, int bpp,
|
|||||||
g_filament_context->UploadFont(pixels, width, height, id);
|
g_filament_context->UploadFont(pixels, width, height, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double mjr_getFrameRate(const mjrContext* con) {
|
||||||
|
CheckFilamentContext();
|
||||||
|
return g_filament_context->GetFrameRate();
|
||||||
|
}
|
||||||
|
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|||||||
@@ -78,6 +78,8 @@ MJAPI void mjr_setBuffer(int framebuffer, mjrContext* con);
|
|||||||
MJAPI void mjr_readPixels(unsigned char* rgb, float* depth, mjrRect viewport,
|
MJAPI void mjr_readPixels(unsigned char* rgb, float* depth, mjrRect viewport,
|
||||||
const mjrContext* con);
|
const mjrContext* con);
|
||||||
|
|
||||||
|
double mjr_getFrameRate(const mjrContext* con);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -57,17 +57,6 @@ void Renderer::Render(const mjModel* model, mjData* data,
|
|||||||
|
|
||||||
mjrRect main_viewport = {0, 0, width, height};
|
mjrRect main_viewport = {0, 0, width, height};
|
||||||
mjr_render(main_viewport, data ? &scene_ : nullptr, &render_context_);
|
mjr_render(main_viewport, data ? &scene_ : nullptr, &render_context_);
|
||||||
|
|
||||||
auto now = std::chrono::steady_clock::now();
|
|
||||||
auto delta_time = now - last_fps_update_;
|
|
||||||
const double interval = std::chrono::duration<double>(delta_time).count();
|
|
||||||
|
|
||||||
++frames_;
|
|
||||||
if (interval > 0.2) { // only update FPS stat at most 5 times per second
|
|
||||||
last_fps_update_ = now;
|
|
||||||
fps_ = frames_ / interval;
|
|
||||||
frames_ = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::SaveScreenshot(const std::string& filename, int width,
|
void Renderer::SaveScreenshot(const std::string& filename, int width,
|
||||||
|
|||||||
@@ -54,15 +54,10 @@ class Renderer {
|
|||||||
// Rendering flags.
|
// Rendering flags.
|
||||||
mjtByte* GetRenderFlags() { return scene_.flags; }
|
mjtByte* GetRenderFlags() { return scene_.flags; }
|
||||||
|
|
||||||
// Returns the current, average frame rate.
|
|
||||||
double GetFrameRate() const { return fps_; }
|
|
||||||
|
|
||||||
// Returns the render context.
|
// Returns the render context.
|
||||||
const mjrContext& GetContext() const { return render_context_; }
|
const mjrContext& GetContext() const { return render_context_; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using TimePoint = std::chrono::time_point<std::chrono::steady_clock>;
|
|
||||||
|
|
||||||
// Resets the renderer; no rendering will occur until Init() is called again.
|
// Resets the renderer; no rendering will occur until Init() is called again.
|
||||||
void Deinit();
|
void Deinit();
|
||||||
|
|
||||||
@@ -70,10 +65,6 @@ class Renderer {
|
|||||||
mjrContext render_context_;
|
mjrContext render_context_;
|
||||||
mjvScene scene_;
|
mjvScene scene_;
|
||||||
bool initialized_ = false;
|
bool initialized_ = false;
|
||||||
|
|
||||||
int frames_ = 0;
|
|
||||||
TimePoint last_fps_update_;
|
|
||||||
double fps_ = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mujoco::platform
|
} // namespace mujoco::platform
|
||||||
|
|||||||
@@ -16,6 +16,9 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#if defined(USE_CLASSIC_OPENGL)
|
||||||
|
#include <chrono>
|
||||||
|
#endif
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@@ -369,6 +372,21 @@ void App::Render() {
|
|||||||
data_->timer[i].number = 0;
|
data_->timer[i].number = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_CLASSIC_OPENGL
|
||||||
|
TimePoint now = std::chrono::steady_clock::now();
|
||||||
|
TimePoint::duration delta_time = now - last_fps_update_;
|
||||||
|
const double interval = std::chrono::duration<double>(delta_time).count();
|
||||||
|
|
||||||
|
++frames_;
|
||||||
|
if (interval > 0.2) { // only update FPS stat at most 5 times per second
|
||||||
|
last_fps_update_ = now;
|
||||||
|
fps_ = frames_ / interval;
|
||||||
|
frames_ = 0;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
fps_ = mjr_getFrameRate(&renderer_->GetContext());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::HandleMouseEvents() {
|
void App::HandleMouseEvents() {
|
||||||
@@ -797,8 +815,7 @@ void App::BuildGui() {
|
|||||||
platform::ScopedStyle style;
|
platform::ScopedStyle style;
|
||||||
style.Var(ImGuiStyleVar_Alpha, 0.6f);
|
style.Var(ImGuiStyleVar_Alpha, 0.6f);
|
||||||
if (ImGui::Begin("Info", &tmp_.info)) {
|
if (ImGui::Begin("Info", &tmp_.info)) {
|
||||||
platform::InfoGui(model_, data_, step_control_.IsPaused(),
|
platform::InfoGui(model_, data_, step_control_.IsPaused(), fps_);
|
||||||
renderer_->GetFrameRate());
|
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -182,6 +182,10 @@ class App {
|
|||||||
|
|
||||||
UiState ui_;
|
UiState ui_;
|
||||||
UiTempState tmp_;
|
UiTempState tmp_;
|
||||||
|
|
||||||
|
int frames_ = 0;
|
||||||
|
TimePoint last_fps_update_;
|
||||||
|
double fps_ = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mujoco::studio
|
} // namespace mujoco::studio
|
||||||
|
|||||||
Reference in New Issue
Block a user