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

Improve fps counter #1886

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

GabrielNakamoto
Copy link

@GabrielNakamoto GabrielNakamoto commented Jan 5, 2025

Accumulate it over a few frames to give an average instead of showing the last frame performance only

  • In vtkF3DUIActor I changed SetFpsValue() to UpdateFpsValue() which will automatically accumulate fps values before setting the display value to the average. The number of frames it waits to average is decided by the static member variable vtkF3DUIActor::FramesToAverage

Updating it only when the whole scene is rendered

  • In the vtkF3DRenderer::Render() function I updated it to check if its information has vtkF3DRenderPass::RENDER_UI_ONLY() set to 1 If it does it calculates the fps value and calls the UI Actor's UpdateFpsValue()

Let me know what you think the number of frames to average should be (currently set to 5).

From building it and using some of the example models it seems that the render UI only is working however I may be wrong.

Seeing this is my first time contributing I'm starting a pull request to get some advice.

Copy link

codecov bot commented Jan 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.67%. Comparing base (91310bd) to head (e42a67c).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1886      +/-   ##
==========================================
- Coverage   95.69%   95.67%   -0.03%     
==========================================
  Files         125      125              
  Lines        9926     9945      +19     
==========================================
+ Hits         9499     9515      +16     
- Misses        427      430       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


if (this->FramesAccumulated == vtkF3DUIActor::FramesToAverage)
{
this->FpsValue = static_cast<int>(this->AccumulatedFpsValue / this->FramesAccumulated);
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO it should be a slided average, wdyt ?

Copy link
Author

Choose a reason for hiding this comment

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

Yes that looks better. I can add that once I'm home from school.

Copy link
Member

Choose a reason for hiding this comment

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

I think the average must be done in frame time, rather than fps.
So maybe you could pass the elapsed time in this function, average the elapsed time, and only inverse it at the end to convert to fps.
If you don't do that, the average will be biased with highest fps values.

Also, I don't like the idea of the fps value at 0 for the first 5 frames.

About the slided average, I'm afraid it will still produce large variation of fps and will still make the fps value unreadable. But maybe if we increase the window size to something larger than 5, this effect could be mitigated.

Here's a suggestion:

  • Add the elapsed time in a container (std::queue but maybe another container is more adapted)
  • Remove the oldest value if the number of elements is above the window size
  • Average all the elements
  • Inverse the value to get the fps value

Let's see if the value can be read and if changing the window size have an effect

Copy link
Author

Choose a reason for hiding this comment

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

Sounds good will try to implement this.

Copy link
Author

Choose a reason for hiding this comment

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

  • Remove the oldest value if the number of elements is above the window size

How can the renderer get the window size (in it's information maybe?). And why should that affect the fps average?

Copy link
Contributor

@mwestphal mwestphal left a comment

Choose a reason for hiding this comment

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

This is looking good, wdyt @Meakk ?

@mwestphal mwestphal requested a review from Meakk January 6, 2025 07:02
@GabrielNakamoto
Copy link
Author

GabrielNakamoto commented Jan 6, 2025

I don't think the last commit works but I don't know why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants