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

Optimize picking #630

Open
pjcozzi opened this issue Apr 12, 2013 · 10 comments
Open

Optimize picking #630

pjcozzi opened this issue Apr 12, 2013 · 10 comments

Comments

@pjcozzi
Copy link
Contributor

pjcozzi commented Apr 12, 2013

The fix for #583 slows down the fragment shader for picking because it executes the full fragment shader for materials. If we know a material doesn't have any transparent parts (and doesn't write depth in the future), we can just use a simple pass-through shader.

@pjcozzi
Copy link
Contributor Author

pjcozzi commented Apr 30, 2013

This will also optimize other passes like glow (e.g., a single bit mask) and shadow/depth pre-pass (depth only).

@pjcozzi
Copy link
Contributor Author

pjcozzi commented Sep 24, 2013

We should also better document the performance costs of Scene.pick (rendering the scene), and encourage users to only call it once from their app. If need be, we could cache the result inside Scene.pick for when the objects/time doesn't change, but it would be a lot of bookkeeping to implement at this level.

@pjcozzi
Copy link
Contributor Author

pjcozzi commented Sep 25, 2013

FYI...the bottleneck is, of course, in readPixels blocking while the GPU's pipeline flushes. In Open Philly Globe, readPixels is 40% of the profile when the Septa or Pedestrian Count layer is on and the mouse is moving. I'm not sure how much we can do about this without asynchronous readbacks using PBOs.

@pjcozzi
Copy link
Contributor Author

pjcozzi commented Nov 26, 2013

With WebGL 2.0, we can also use MRT to render the pick buffer in the same pass as the color. CC #797

@billwritescode
Copy link

billwritescode commented Feb 17, 2017

Any thoughts on addressing this? Noticing that gl.readPixels (via scene.pick) is chewing up CPU time: http://cesiumjs.org/releases/1.30/Apps/Sandcastle/?src=Hello%20World.html&label=Showcases&gist=09ea27d7643dceaacded4fe1f31a9471

@pjcozzi
Copy link
Contributor Author

pjcozzi commented Feb 18, 2017

@billwritescode the biggest win will come from not stalling the CPU and starving the GPU with WebGL's readPixels. I think this is possible with WebGL 2, #797, and we'll investigate when we ramp up WebGL 2.

@skaughtx0r
Copy link

skaughtx0r commented Feb 17, 2023

10 years later, this still has a huge performance impact. What's the status on this issue now that the WebGL Roadmap is closed and the WEBGL_draw_buffers were not addressed?

@ggetz
Copy link
Contributor

ggetz commented Feb 17, 2023

@skaughtx0r We're putting together our roadmap for our next year of development starting in March, and are hoping to take advantage of the fact that WebGL2 is now the default in CesiumJS to do some optimizations like this.

@tmarti
Copy link

tmarti commented Jun 22, 2023

It should be possible to convert gl.readPixels into async operations by wrapping the check for a webgl2 fence synchronization into an async Promise.

The result would be that, when the mouse moves, the feedback would not be synchronous with the mouse movement, but instead the feedback would come after the data is available, so a bit extra end-to-end time.

The nice thing with this, though, is that there would be no stalling of the GPU pipeline, and you could keep moving the camera while the pixels are being read 🙂.

Mention me if you want a code snippet example in this thread, it’s actually a small bit of code but of course in the consuming side it needs to be taken into account that the pixel reading operation would need to be await-ed .

@skaughtx0r
Copy link

@tmarti could you post the code snippet you mentioned?

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

No branches or pull requests

6 participants