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

Faster editor line drawing - Path2D and draw_line #54377

Merged
merged 1 commit into from
Nov 30, 2021

Conversation

lawnjelly
Copy link
Member

@lawnjelly lawnjelly commented Oct 29, 2021

Changes the Path2D drawing to use POLYLINE instead of thick lines.
Add a path to translate thick lines (that are not using anti-aliasing) to draw as polygons instead. This should be faster because polygons can be batched.

Fixes #38543
May fix #52703

Notes

  • Drawing thick lines as polys could potentially be a lot faster as it will use batching where there are a lot of lines (thin lines are already batched when not anti-aliased)
  • As well as drawing faster the Path2D should now be neater because there are not the gaps between line segments.
  • I haven't absolutely tested the Path2D speed, in terms of I don't get a massive slowdown on mine with the old version. One thing I did here is leave anti-aliasing on, it seems like it would draw the anti-aliased edge as a line strip rather than individual lines, so it may be okay. If we get any continuing speed issues we can turn anti-aliasing off for drawing.

Before:
Screenshot from 2021-10-29 10-33-15

After:
Screenshot from 2021-10-29 12-45-56

Changes the Path2D drawing to use POLYLINE instead of thick lines.
Add a path to translate thick lines (that are not using anti-aliasing) to draw as polygons instead. This should be faster because polygons can be batched.
@lawnjelly
Copy link
Member Author

lawnjelly commented Nov 10, 2021

Just to note, got some further testing of the line drawing side of this in #54826. When trying that test project:

  • Drawing lots of thick lines is much faster, as expected due to batching (from 145fps to 870fps)
  • With a small window (200x100) I get an increase from 147fps to 4000fps. This shows as expected that it goes from vertex limited to fill rate limited.
  • Drawing without batching is actually a bit slower (255fps to 145fps), and this represents the difference between the line drawing routine and the poly drawing routine. This will also apply to single thick lines.

If anyone reports the latter as a problem, we can put in a check in the canvas_item_add_line routine to check whether batching is off, and revert to the old routine. I only haven't put this in already because it would be nicer to not introduce a dependency to the rasterizer_canvas if not necessary. It's comparable to the performance in 3.2.3 anyway.

Copy link
Member

@mhilbrunner mhilbrunner left a comment

Choose a reason for hiding this comment

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

Approved in today's PR meeting. We should investigate a port to Godot 4. Thanks!

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

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

Approved in PR review meeting.

@akien-mga akien-mga merged commit 3be0f85 into godotengine:3.x Nov 30, 2021
@akien-mga
Copy link
Member

Thanks!

@oeleo1
Copy link

oeleo1 commented Dec 1, 2021

This is not editor only, right? Eager to test this as we use custom path2Ds extensively.

@lawnjelly
Copy link
Member Author

This is not editor only, right? Eager to test this as we use custom path2Ds extensively.

This works outside the editor too.

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

Successfully merging this pull request may close these issues.

6 participants