-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Fix lagging TileSet view for large TileSets in Editor #84963
base: master
Are you sure you want to change the base?
Fix lagging TileSet view for large TileSets in Editor #84963
Conversation
Replace grid made of rectangles (quadratic of the size of TileSet) with grid made of lines (linear)
da04bc1
to
d002a94
Compare
Would be worth testing with both OpenGL (native and ANGLE) and Vulkan (Metal) to make sure it's an optimization for both. Drawing lines in OpenGL can have horrendous performance on some hardware. See #84591 for context. |
Thanks for the contribution!
I believe this is not the right solution. The problem arises when you have a separation value higher than 0, and a texture region size bigger than the tile size. This is often the case for isometric/hexagonal tile shapes. In such a case, each tile has a texture region clearly separated from the others, making it a rectangle around the tile, not really a "grid". So this solution cannot be used. I think drawing a rect should not use that much CPU, and the problem is likely elsewhere. However I guess some drivers might be bad at drawing rects anyway, so we might use the another solution: we could use an You can have a look to how it's done in |
Thank you for the context!
I'd bet drawing rectangles was not the problem too.
I was testing on MacBook pro m1 with Vulkan, and I can test on iMac on Intel. |
Oh no, I agree that drawing rectangles was indeed the problem. By "elsewhere", I meant more, like, in a lower level of the code (either the rendering servers or the graphics drivers). Basically that means that fixing the problem here will solve the TileMap editor being slow, but we'll still have an underlying problem of draw_rect being slow anyway. But yeah, any workaround will work for now, and I believe ArrayMesh should work. |
hi guys, Could you please let me know when we can expect this issue to be resolved? |
Hi, I'll be looking at it shortly |
Any progress on this? Maybe this could help: copying and adapting the following from index 039213e545..c3f1b34ccd 100644
--- a/editor/plugins/tiles/tile_atlas_view.cpp
+++ b/editor/plugins/tiles/tile_atlas_view.cpp
@@ -337,7 +337,10 @@ void TileAtlasView::_draw_base_tiles_texture_grid() {
}
} else {
// Draw the grid.
- base_tiles_texture_grid->draw_rect(Rect2i(origin, texture_region_size), Color(0.7, 0.7, 0.7, 0.1), false);
+ Transform2D tile_xform;
+ tile_xform.set_origin(Rect2(origin, texture_region_size).get_center());
+ tile_xform.set_scale(texture_region_size);
+ tile_set->draw_tile_shape(base_tiles_texture_grid, tile_xform, Color(0.7, 0.7, 0.7, 0.1));
}
}
} |
As reported in godotengine#72405 and godotengine#84963 the tileset editor becomes unusable when editing large tileset atlases due to repeated calls to `draw_rect` to draw the tile grid. This commit is a workaround which replaces `CanvasItem::draw_rect` calls with `TileSet::draw_tile_shape` which does not seem to display the same performance issues.
The TileSet panel is lagging on big TileSets since on every draw cycle the whole grid re-draws the rectangles.
For TileSets of size > 100x100 the TileSet panel becomes unusable.
Relevant discussion:
#72405 (comment)
This PR replaces the grid made of rectangles (quadratic of the size of TileSet) with grid made of lines (linear) within Atlas view.
This optimisation solves the lag.
Profiling before the fix shows that drawing and removing rectangles eats up all the CPU.
Profiling after the fix shows that the grid drawing only takes 1.7% of the CPU time: