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
PlotCurveItem OpenGL : avoid automatic conversion from float64 to float32 #2111
Conversation
if we are going to use the float32 version of glVertexPointer, then we should just pass in a float32 array. otherwise there will be an automatic conversion by PyOpenGL. on the other hand, if the intention of using float64 arrays was to have float64 precision, then the use of glVertexPointf would be a bug.
Nice find @pijyoi I'm not sure what the consequences are of going to double-precision, so I'm inclined to think that we should probably maintain the single point precision given that's how it's been. |
I can't help but feel that single-wide floats with a resolution of only around 1E-7 are a little weak for showing arbitrary data. On the other hand, the placement of OpenGL in the library currently seems to be "fast at all costs", so sticking with single floats is probably justified. The viewing range and axis tick calculations would still work CPU-side, using doubles, I guess. So at least this should not require any special treatment of range limitations (like in the various breakages we get when zooming out too far). How reliable is OpenGL support for double-wide float vertices? Are there platforms that we want to support where On a somewhat modern system, is there still a performance penalty for operation with double vertices? |
Yes, that's correct. #2020 has an example with artifacts when using OpenGL.
And also the OpenGL codepath has been untouched for ages. So not changing its behavior is the easiest course of action.
I remember reading language somewhere that an implementation is only needed to provide 24-bits of precision.
If you use CUDA with consumer graphics cards, there is a 32x performance penalty to using double precision versus single precision. So I would suspect that that would be true when using OpenGL too. Either that or the driver truncates it to float32 anyway, which still makes it compliant. |
I'd say that is a fairly strong point for sticking to single-wide floats, then. There is a still a lot that can be done with 23 bits of mantissa. Is there a good place to mention the single float limitation in the docs? |
32x performance penalty?!?!?! that's brutal When I started reading more about cross-platform openGL code, I was coming across some articles (granted, they were ancient, like most openGL content) indicating that 64 bit float support within opengl drivers was fairly inconsistent... anyway that's a lot of reasons listed above to keep things as they are. I am 👍🏻 on @NilsNemitz 's suggestion on adding a blurb in the docs about this limitation. |
See the comments in the following link regarding double precision: Basically, double precision is not used for processing even if the API allows you to provide double precision values. |
I was just chatting with the moderngl maintainers and they explained more or less the same thing to me |
Where would be a good place to put blurb? |
I was thinking in the Broadly speaking, and this is way outside the scope of this PR, but we should likely add a separate section in the docs about benefits/consequences of enabling openGL for GraphicsView. |
Thanks @pijyoi ! I'm not an rst wizard, but can we get ordering/numbering to not be in-line in the rendered document? https://pyqtgraph--2111.org.readthedocs.build/en/2111/config_options.html |
would need some help here... |
I'll take a look I'm a bit; once I figure it out would you like me to push to your branch? |
Yes, please go ahead. |
welp, I got it, it's ugly as we run into a known issue with the but the end result isn't offensive at least... |
4f3e803
to
affc257
Compare
@pijyoi since I requested the documentation bit, and it's added, I'm going to merge as soon as the CI comes back green. Thanks for the PR! |
Could you open a new issue on this? |
There is an inefficiency in the current PlotCurveItem OpenGL implementation:
This PR changes step (1) to use a temporary float32 buffer right from the start.
This gains a few fps with 1,000,000 points:
examples\PlotSpeedTest.py --opengl --frames 3 --nsamples 1000000
Alternatively, if it is considered a bug that
glVertexPointerf
was used, then that should be changed instead toglVertexPointer(2, gl.GL_DOUBLE, 0, pos)
. However, this would then be a change in behavior to use double precision, and in addition, the calls to setting up the stencil should also be changed to double precision.