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

Editor Icons - needs optimizations #1220

Open
Maksims opened this issue Nov 8, 2024 · 3 comments
Open

Editor Icons - needs optimizations #1220

Maksims opened this issue Nov 8, 2024 · 3 comments

Comments

@Maksims
Copy link
Collaborator

Maksims commented Nov 8, 2024

Icons - is a useful visual tool for selecting entities and delivering some information based on viewport, for example icons for light sources that have no models, or script entities.

While it is a useful tool, it is implemented in a bit "brute-force" manner. Which basically creates a plane entity for each entity in scene, and updates it every frame. Even if the icon is disabled, or not even visible (e.g. when entity has render component).

In projects with thousands of entities (we have projects with 10k+), this leads to a significant performance hit.

So here are a list of issues:

  1. It creates an entity for each entity in scene.
  2. It renders it as a separate draw call (render component with plane primitive).
  3. It iterates through all icons every frame to identify a need of update.
  4. It can take half of a frame time during rendering on just icons processing.

How to improve:

  1. Use instancing for rendering quads.
  2. Consider using PRIMITIVE_POINTS, although it will have a limit on icon size on the screen based on resolution, so two triangles might be better.
  3. Orient icons towards the camera in vertex shader.
  4. Make sure instance buffer data is very slim (just position, and index of icon within atlas).
  5. Use atlas texture for icons, so that all different icons - can be drawn as a single instanced drawcall.
  6. Update icons using mostly events.
  7. For cases when update of icon won't be possible using an event, implement immediate checks for icons of selected entities on every frame.
  8. For not selected entities, for icon updates that cannot be done using events, make sure it does run not on every frame, but with some periodical delay (not more often than one update on every 200ms). Ideally it would not iterate through all icons, but only visible and potentially in chunks.
  9. If in Editor settings "Icons Size" is 0 (disabled), ensure there is no extra work and overhead from icons.
@mvaligursky
Copy link

repro projects, with lots of entities with scripts and no visuals:
https://playcanvas.com/project/1273594/overview/script-icons-performance

this takes 26ms per frame on apple m1 pro

Screenshot 2024-11-08 at 09 53 33

Instancing might not be completely straightforward as that is not compatible with instancing - all instances generate the same ID for picking.

@Maksims
Copy link
Collaborator Author

Maksims commented Nov 8, 2024

Instancing might not be completely straightforward as that is not compatible with instancing - all instances generate the same ID for picking.

Is it possible to add instance ID to instancing data and custom shader that will use it during picker render pass instead of a solid color?

@mvaligursky
Copy link

mvaligursky commented Nov 8, 2024

There are solutions for sure to handle it. Just saying that i'd need more work to manage IDs even. Currently we use meshInstnce.id as it's id. We'd need to allocate range for instances and similar.

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

No branches or pull requests

2 participants