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

Refactor density graph rendering (BG video supported!) #167

Merged
merged 1 commit into from
Nov 11, 2019
Merged

Refactor density graph rendering (BG video supported!) #167

merged 1 commit into from
Nov 11, 2019

Conversation

natano
Copy link
Member

@natano natano commented Nov 2, 2019

So, I sat down today and implemented what we discussed in #166.

Previously for a scrolling NPS graph all the vertices were rendered from the beginning and the screen edges and a "fake" background image were used to hide the overhang.

After this only the vertices that should be visible are rendered. No overlap truncation required and all background features are suppored now: hiding, dimming, change, videos.

The calculations for positioning the NPS graph with Center1Player is a bit messy, but I couldn't find a cleaner way to properly align it.

@quietly-turning
Copy link
Contributor

quietly-turning commented Nov 2, 2019

Woah.

I admit I wasn't expecting this, and am immensely grateful for and humbled by your enthusiasm and tangible contributions. Thank you!

This looks like it was a lot of work. How long did you spend working on this?


The calculations for positioning the NPS graph with Center1Player is a bit messy, but I couldn't find a cleaner way to properly align it.

Yeah, my code there was ugly for sure, so don't worry about it. I rushed that out in 2018 as part of an an effort to completely abandon the theme after the v4.7 release. I should probably go back and clean it up someday...


I don't have a working build of SM5 right now, so I'll need to rely on input from other people who can test this and report on FPS during gameplay.

Thank you for working on this!

@quietly-turning
Copy link
Contributor

It looks like this effectively undoes the fixes from #153. Was this intentional on your part?

@natano
Copy link
Member Author

natano commented Nov 3, 2019

Thank you for your kind words :) I would guess I worked on this for about 10-12 hours. I like this theme a lot, so it's worth the effort!

It looks like this effectively undoes the fixes from #153. Was this intentional on your part?

No, that was just me pulling everything apart and not assembling it back correctly. I assumed the first second is always >= 0. If the first second is < 0 it makes me wonder where the life bar should start... I will update the PR with a fix.

@natano
Copy link
Member Author

natano commented Nov 3, 2019

I amended the commit to contain a fix for the issue described in #153.

To understand the code it's necessary to understand how timing works in SM. This is what I found out:

  • 0 intuitively is the point in time where the song starts playing. This is where the first update occurs and where we start drawing the life line.
  • GetElapsedTimeFromBeat(0) returns the point in time where the first beat/measure starts. This might be less than 0 in case the start of the first measure is before the start of the song.
  • GetFirstSecond() not exactly sure what this does... It seems to be the point in time of the first beat after the song started playing, if my math is correct. Often does not equal GetElapsedTimeFromBeat(0). It's not used during rendering of the NPS graph.
  • For completeness: GetLastSecond() returns the point in time where song stops playing

Instead of always beginning the NPS graph at 0 the code now uses either 0 or the point in time where the first measure starts, whichever occurrs first. With that approach we truncate neither the lifeline nor the NPS graph.

@natano
Copy link
Member Author

natano commented Nov 3, 2019

I also snuck another improvement in there to reduce vertex updates in the scrolling NPS histogram implementation. Now we only actually call :SetVertices(visible_vertices) if we are currently scrolling. That should save some cycles for short (< 4min) songs and might be helpful for people with slow machines.

@natano
Copy link
Member Author

natano commented Nov 8, 2019

@dguzek I did some performance tests today. The tests were down on my two laptops. I'm sure there are people out there running StepMania on slower machines, but at least on the two machines I have the new step statistics don't cause any slowdown.

Both machines run Linux, with SM ofc using OpenGL.

The Song used for testing is "Endless Sacrifice (14)" from the Ultramarathon Gigapack with 2x rate and autoplay. The song is > 10 minutes, so the graph scrolled during the test. I did this to make sure that scrolling also doesn't cause framedrop.

Thinkpad T470 with Intel HD Graphics 620

mode resolution graph FPS VPF
windowed 1280x800 off 60 700-950
windowed 1280x800 on 60 1300-1750
fullscreen 1920x1080 off 60 700-950
fullscreen 1920x1080 on 60 1300-1750

Acer TravelMate B117 with some integrated Intel GPU

mode resolution graph FPS VPF
windowed 960x600 off 60 700-950
windowed 960x600 on 60 1300-1750
fullscreen 1366x768 off 60 700-950
fullscreen 1366x768 on 60 1300-1750

With the "old" density graph rendering (beta branch) the VPF is consistently higher, about 1700-1800. The longer the song the bigger the discrepancy.

@quietly-turning
Copy link
Contributor

quietly-turning commented Nov 8, 2019

Thanks for putting in the time to test this, @natano! I still do not have a working SM5 build and won't for the foreseeable future, so this helps.


Since you didn't specify, how did you collect your data for FPS and VPF? I'm guessing you enabled ShowStats and observed during gameplay, but I am curious.

Did FPS never go above 60 in your tests? I'd found that with macOS builds of SM5, the ShowStats display seemed to cap at 60fps, but that on Linux and Windows it would report numbers much larger (when applicable).

This made it difficult for me to evaluate the performance of projects like Your Drifting Mind. My MacBook would report a steady 60fps the entire duration of gameplay, but other players' tests on Windows showed a steady drop from ~400 to ~70 fps as the visuals became more complex. There was a clear need for improvement, but it was difficult for me to realize this on macOS then with the numbers I was seeing.

So, I am wondering how you got the numbers you reported here.

@natano
Copy link
Member Author

natano commented Nov 9, 2019

Yes, I observed the in-game stats. Your comment made me re-run the tests with vsync turned off. (I had to use this hack to really disable it on Linux with Intel HD Graphics.)

Unfortunately vsync off does uncover an issue. The VPF count increases over the duration of the song and the FPS dips. I don't know what is going on there. Somehow vertices are leaking when vsync is off. I will investigate what is going on there.

Thinkpad T470 with Intel HD Graphics 620

mode resolution graph FPS VPF
windowed 1280x800 off 270-300 700-1150
windowed 1280x800 on 180-260 1500-19500
fullscreen 1920x1080 off 150-170 700-1150
fullscreen 1920x1080 on 130-160 1500-19500
fullscreen 1920x1080 on ("old") 120-140 1700-2500

Acer TravelMate B117 with some integrated Intel GPU

mode ratio graph fps vpf
windowed 960x600 off 110-190 700-1150
windowed 960x600 on 50-140 1500-19500
fullscreen 1366x768 off 100-170 700-1150
fullscreen 1366x768 on 45-140 1500-19500

Previously for a scrolling NPS graph all the vertices were rendered
from the beginning and the screen edges and a "fake" background image
were used to hide the overhang.

After this only the vertices that should be visible are rendered. No
overlap truncation required and all background features are suppored
now: hiding, dimming, change, videos.

The calculations for positioning the NPS graph with Center1Player is a
bit messy, but I couldn't find a cleaner way to properly align it.
@natano
Copy link
Member Author

natano commented Nov 10, 2019

So, I found the issue: The high VPF count was caused by the life line!. When refactoring the code I removed the condensing of the life line. I deemed it unnecessary because we don't keep the whole thing around anymore but truncate it on the left. Turns out the line strip rendering in StepMania is quite inefficient. For line strip rendering every vertex in the ActorMulitVertex translates to actually about 38 vertices being rendered.

With the life line condensing code back in place, the numbers look much better. This time I added debug output with the FPS/VPS numbers to the Update function and wrote a script to interpret them.

Thinkpad T470 with Intel HD Graphics 620

mode ratio vsync FPS VPF
windowed 1280x800 off 239 (146-287) 1837 (1137-2226)
windowed 1280x800 on 60 1587 (1130-1857)
fullscreen 1920x1080 off 153 (132-156) 1595 (1132-1894)
fullscreen 1920x1080 on 60 1587 (1130-1858)

Acer TravelMate B117 with some integrated Intel GPU

mode ratio vsync FPS VPF
windowed 960x600 off 128 (85-176) 1684 (1136-2180)
windowed 960x600 on 60 1589 (1130-1923)
fullscreen 1366x768 off 120 (82-157) 1656 (1136-2183)
fullscreen 1366x768 on 60 1587 (1130-1859)

@dguzek I don't know what your perfomance goals are for the theme, but the numbers look acceptable to me.

@quietly-turning
Copy link
Contributor

quietly-turning commented Nov 10, 2019

First off, thank you so very, very much for your incredible effort on this. It is uncommon to receive a pull request that:

  1. is completely unexpected
  2. fixes an existing problem that is complex
  3. accurately describes what the problem is and how the changes made address it
  4. tests the changes
  5. describes how testing was performed using clear and concise language
  6. is neatly contained in intent and not laden with extraneous Git noise or other unrelated changes

This is one of the few pull requests I've received that has made things easier for me rather than harder. I've done no work here but feel fairly confident that I'm ready to merge this.

I could go on all day, so I'll conclude by affirming that your programming efforts and words here are very truly appreciated. Thank you. 💛


So, yeah, I'm okay with merging this as-is; I just have one last thing I'll ask you to check. Your discovery that

Turns out the line strip rendering in StepMania is quite inefficient. For line strip rendering every vertex in the ActorMulitVertex translates to actually about 38 vertices being rendered.

makes me wonder how toggling SmoothLines on/off might impact VPF and FPS. Since you have a testing environment and workflow established, can you run one last performance test, similar to your previous test, with SmoothLines flipped to however it was set previously?

I think there might be a performance improvement with SmoothLines=0, and I'll want to update the help text that appears in the Operator Menu if so. I do not anticipate you needing to change anything further for this PR. 🙂

@natano
Copy link
Member Author

natano commented Nov 11, 2019

The numbers abover where collected with SmoothLines off. Smooth lines do affect rendering efficiency, but not in the way that you would expect: Turning smooth lines on actually causes the OpenGL backend to use GL_LINE_STRIP and GL_DOTS (drawing about 2 real vertices for each vertex in the ActorMultiVertex) instead of the generic/non-smooth fallback code which blows up the vertex count 40 fold. So drawing smooth lines is actually more efficient than non-smooth lines with OpenGL!

(D3D always draws non-smooth lines, even when the option is on.)

Following number are with SmoothLines on. Note that the VPF number are too optimistic because the OpenGL backend seems (as far as I can see) to not record vertices used for smooth lines in the statistics. The FPS numbers should be fine.

Thinkpad T470 with Intel HD Graphics 620

mode ratio vsync fps vpf
windowed 1280x800 off 241 (124 - 286) 1621 (1249 - 2116)
windowed 1280x800 on 60 1484 (1087 - 1776)
fullscreen 1920x1080 off 150 (124 - 156) 1490 (1132 - 1810)
fullscreen 1920x1080 on 60 1485 (1130 - 1789)

Acer TravelMate B117 with some integrated Intel GPU

mode ratio vsync fps vpf
windowed 960x600 off 129 (86 - 180) 1578 (1136 - 2068)
windowed 960x600 on 60 1480 (1130 - 1774)
fullscreen 1366x768 off 125 (76 - 160) 1546 (1132 - 2031)
fullscreen 1366x768 on 60 1482 (1130 - 1777)

@quietly-turning
Copy link
Contributor

quietly-turning commented Nov 11, 2019

This is interesting stuff. The FPS numbers look close enough that I don't think I'll change any of the help text. Thanks for looking into it on my behalf.

Someday I'll achieve C++ proficiency and have a better understanding of the StepMania engine and then I will die of old age. In the meantime, the post-ITG community is surely in your debt.

@quietly-turning quietly-turning merged commit 434881c into Simply-Love:beta Nov 11, 2019
@natano natano deleted the bgvideo branch November 11, 2019 18:50
@natano
Copy link
Member Author

natano commented Nov 11, 2019

Here is a short video where you can see the refactored density graph in action.

I'm a developer myself, so I know how it feels to get vague PRs. Glad I was able to provide you with a better experience! :)

quietly-turning referenced this pull request Jun 11, 2020
re: github.com/quietly-turning/Simply-Love-SM5/pull/167#issuecomment-549084002

"Yeah, my code there was ugly for sure, so don't worry about it. I
rushed that out in 2018 as part of an effort to completely abandon the
theme after the v4.7 release. I should probably go back and clean it up
someday..."
@quietly-turning quietly-turning added the enhancement Improve existing functionality label Aug 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants