briansemrau / godot_box2d

A C++ module that integrates the Box2D library with the Godot game engine by providing nodes for standard Box2D objects.
MIT License
44 stars 4 forks source link

debug draw slow #34

Open jordo opened 3 years ago

jordo commented 3 years ago

investigate a little more why debug draw is very slow. Some initial timer profile caps:

Screen Shot 2020-12-10 at 1 42 53 PM Screen Shot 2020-12-10 at 1 43 22 PM
jordo commented 3 years ago

going to take a crack at polishing this up a bit:

jordo commented 3 years ago

still may be slow with a lot of joints on screen (still drawn every frame). Will address later when joints are done

briansemrau commented 3 years ago

It might take a great deal of effort to optimize joint drawing. Not only do they have to redraw when just about any joint property is changed (and there are lots of properties), but anchors and several lines need to be redrawn whenever the relative transform between joint and connected bodies changes.

I don't expect this is a good reason to not optimize joint debug drawing, just know the change won't be small.

jordo commented 3 years ago

I’ll probably change or fix how this work is submitted. Even updating every frame should not be a performance hit. All the debug geometry is the same and should be submitted to the gpu together. The only thing that’s really changing is a single vertex attribute for color really. It should be really fast regardless. I’ll probably dig a bit deeper next week, but it shouldn’t be a performance hit at all

On Dec 12, 2020, at 7:38 PM, Brian Semrau notifications@github.com wrote:

 It might take a great deal of effort to optimize joint drawing. Not only do they have to redraw when just about any joint property is changed (and there are lots of properties), but anchors and several lines need to be redrawn whenever the relative transform between joint and connected bodies changes.

I don't expect this is a good reason to not optimize joint debug drawing, just know the change won't be small.

— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub, or unsubscribe.

jordo commented 3 years ago

Actually it looks like lines draw fast (there is no buffer allocation). canvas_item_add_polygon is the bottleneck.

For joints if we're just drawing canvas_item_add_line it's going to still be quite fast.

If we really have to draw everything every frame, I think i would batch everything together in draw node wrapper (individual nodes submit their draws to this controller), and that debug draw will just do everything in a large canvas_item_add_triangle_array.

Going to just push this back for now, the more we can use use canvas_item_add_line for joints the better.