Add API function for querying frame stats.
Replaces the current GetFrameRate function. PiperOrigin-RevId: 911897360 Change-Id: I4199ba9ce40d1d8bc37b551fa7058d964186641d
This commit is contained in:
committed by
Copybara-Service
parent
e1b27afcda
commit
f2da6cabdf
@@ -181,6 +181,13 @@ uintptr_t MjrFilamentRenderer::UploadGuiImage(uintptr_t tex_id,
|
|||||||
return imgui_bridge_->UploadImage(tex_id, pixels, width, height, bpp);
|
return imgui_bridge_->UploadImage(tex_id, pixels, width, height, bpp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double MjrFilamentRenderer::GetFrameRate() const {
|
||||||
|
mjrFrameStats stats;
|
||||||
|
mjr_defaultFrameStats(&stats);
|
||||||
|
filament_context_->GetFrameStats(0, &stats);
|
||||||
|
return stats.frame_rate;
|
||||||
|
}
|
||||||
|
|
||||||
void MjrFilamentRenderer::UpdateGui() {
|
void MjrFilamentRenderer::UpdateGui() {
|
||||||
mjrf_DEBUG_drawImguiEditor(scene_bridge_->GetScene());
|
mjrf_DEBUG_drawImguiEditor(scene_bridge_->GetScene());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,9 +65,7 @@ class MjrFilamentRenderer {
|
|||||||
// Renders an ImGui window containing Filament-specific editor UI.
|
// Renders an ImGui window containing Filament-specific editor UI.
|
||||||
void UpdateGui();
|
void UpdateGui();
|
||||||
|
|
||||||
double GetFrameRate() const {
|
double GetFrameRate() const;
|
||||||
return filament_context_->GetFrameRate();
|
|
||||||
}
|
|
||||||
|
|
||||||
MjrFilamentRenderer(const MjrFilamentRenderer&) = delete;
|
MjrFilamentRenderer(const MjrFilamentRenderer&) = delete;
|
||||||
MjrFilamentRenderer& operator=(const MjrFilamentRenderer&) = delete;
|
MjrFilamentRenderer& operator=(const MjrFilamentRenderer&) = delete;
|
||||||
|
|||||||
@@ -183,14 +183,16 @@ void FilamentContext::SetClearColor(const filament::math::float4& color) {
|
|||||||
renderer_->setClearOptions(opts);
|
renderer_->setClearOptions(opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
double FilamentContext::GetFrameRate() const {
|
void FilamentContext::GetFrameStats(mjrFrameHandle frame,
|
||||||
|
mjrFrameStats* stats_out) const {
|
||||||
utils::FixedCapacityVector<filament::Renderer::FrameInfo> frame_info =
|
utils::FixedCapacityVector<filament::Renderer::FrameInfo> frame_info =
|
||||||
renderer_->getFrameInfoHistory(1);
|
renderer_->getFrameInfoHistory(1);
|
||||||
if (frame_info.empty()) {
|
if (!frame_info.empty()) {
|
||||||
return 0;
|
const int64_t ns = frame_info[0].denoisedGpuFrameDuration;
|
||||||
|
stats_out->frame_rate = 1.0e9 / static_cast<double>(ns);
|
||||||
|
} else {
|
||||||
|
stats_out->frame_rate = 0.0;
|
||||||
}
|
}
|
||||||
const int64_t ns = frame_info[0].denoisedGpuFrameDuration;
|
|
||||||
return 1.0e9 / static_cast<double>(ns);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mujoco
|
} // namespace mujoco
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ class FilamentContext : public mjrfContext {
|
|||||||
// Sets the clear color for the renderer.
|
// Sets the clear color for the renderer.
|
||||||
void SetClearColor(const filament::math::float4& color);
|
void SetClearColor(const filament::math::float4& color);
|
||||||
|
|
||||||
// Returns the current frame rate of the renderer.
|
// Returns information about the frame.
|
||||||
double GetFrameRate() const;
|
void GetFrameStats(mjrFrameHandle frame, mjrFrameStats* stats_out) const;
|
||||||
|
|
||||||
filament::Engine* GetEngine() const { return engine_; }
|
filament::Engine* GetEngine() const { return engine_; }
|
||||||
|
|
||||||
|
|||||||
@@ -145,6 +145,10 @@ void mjr_defaultReadPixelsRequest(mjrReadPixelsRequest* request) {
|
|||||||
memset(request, 0, sizeof(mjrReadPixelsRequest));
|
memset(request, 0, sizeof(mjrReadPixelsRequest));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mjr_defaultFrameStats(mjrFrameStats* stats) {
|
||||||
|
memset(stats, 0, sizeof(mjrFrameStats));
|
||||||
|
}
|
||||||
|
|
||||||
mjrfContext* mjrf_createContext(const mjrFilamentConfig* config) {
|
mjrfContext* mjrf_createContext(const mjrFilamentConfig* config) {
|
||||||
return new mujoco::FilamentContext(config);
|
return new mujoco::FilamentContext(config);
|
||||||
}
|
}
|
||||||
@@ -355,6 +359,11 @@ void mjrf_waitForFrame(mjrfContext* ctx, mjrFrameHandle frame) {
|
|||||||
mujoco::FilamentContext::downcast(ctx)->WaitForFrame(frame);
|
mujoco::FilamentContext::downcast(ctx)->WaitForFrame(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mjrf_getFrameStats(mjrfContext* ctx, mjrFrameHandle frame,
|
||||||
|
mjrFrameStats* stats_out) {
|
||||||
|
mujoco::FilamentContext::downcast(ctx)->GetFrameStats(frame, stats_out);
|
||||||
|
}
|
||||||
|
|
||||||
// Legacy API, to be deprecated.
|
// Legacy API, to be deprecated.
|
||||||
|
|
||||||
void mjrf_makeFilamentContext(const mjModel* m, mjrContext* con,
|
void mjrf_makeFilamentContext(const mjModel* m, mjrContext* con,
|
||||||
|
|||||||
@@ -406,6 +406,15 @@ struct mjrReadPixelsRequest {
|
|||||||
// Initializes the mjrReadPixelsRequest to default values.
|
// Initializes the mjrReadPixelsRequest to default values.
|
||||||
void mjr_defaultReadPixelsRequest(mjrReadPixelsRequest* request);
|
void mjr_defaultReadPixelsRequest(mjrReadPixelsRequest* request);
|
||||||
|
|
||||||
|
// Information about a single frame of rendering.
|
||||||
|
struct mjrFrameStats {
|
||||||
|
// The frame rate of the renderer, in frames per second.
|
||||||
|
double frame_rate;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Initializes the mjrFrameStats to default values.
|
||||||
|
void mjr_defaultFrameStats(mjrFrameStats* stats);
|
||||||
|
|
||||||
// Configuration parameters for the filament rendering context.
|
// Configuration parameters for the filament rendering context.
|
||||||
struct mjrFilamentConfig {
|
struct mjrFilamentConfig {
|
||||||
// The native window handle into which we can render directly.
|
// The native window handle into which we can render directly.
|
||||||
@@ -562,6 +571,10 @@ mjrFrameHandle mjrf_render(mjrfContext* ctx, const mjrRenderRequest* req,
|
|||||||
// Waits for the rendering to complete for the given frame handle.
|
// Waits for the rendering to complete for the given frame handle.
|
||||||
void mjrf_waitForFrame(mjrfContext* ctx, mjrFrameHandle frame);
|
void mjrf_waitForFrame(mjrfContext* ctx, mjrFrameHandle frame);
|
||||||
|
|
||||||
|
// Returns the stats for the given frame but updating the given `stats_out`.
|
||||||
|
void mjrf_getFrameStats(mjrfContext* ctx, mjrFrameHandle frame,
|
||||||
|
mjrFrameStats* stats_out);
|
||||||
|
|
||||||
// Draws an ImGui editor for the given scene, exposing filament-specific
|
// Draws an ImGui editor for the given scene, exposing filament-specific
|
||||||
// settings.
|
// settings.
|
||||||
void mjrf_DEBUG_drawImguiEditor(mjrScene* scene);
|
void mjrf_DEBUG_drawImguiEditor(mjrScene* scene);
|
||||||
|
|||||||
Reference in New Issue
Block a user