Skip to content

Conversation

@bruvzg
Copy link
Member

@bruvzg bruvzg commented Jul 7, 2025

Pre-sort text draw calls to improve batching, should significantly reduce draw call number for languages with a lot of glyphs and multiline text with outlines/shadow.

Before:

Screenshot 2025-07-07 at 09 21 28

After:

Screenshot 2025-07-07 at 10 43 35

Fixes #107109
Fixes #104537

@bruvzg
Copy link
Member Author

bruvzg commented Jul 9, 2025

Some extra tests:

1. Label with CJK test using system font fallback.

Screenshot 2025-07-09 at 11 54 17

4.5 beta 3 - FPS: 330, draw calls 967
this PR - FPS: 1980, draw calls 14

2. Label with Latin text.

Screenshot 2025-07-09 at 11 54 23

4.5 beta 3 - FPS: 1570, draw calls 50
this PR - FPS: 1740, draw calls 2
(as expected, much lower difference)

3. RTL with CJK text:

Screenshot 2025-07-09 at 11 54 27

4.5 beta 3 - FPS: 315, draw calls 980
this PR - FPS: 2080, draw calls 15

4. BBCode demo:

Screenshot 2025-07-09 at 11 55 05

4.5 beta 3 - FPS: 145, draw calls 45
this PR - FPS: 145, draw calls 23
(FPS seems to be linited by constant redraws of the RTL, not number draw calls)

5. 500 random Labels with outline.

Screenshot 2025-07-09 at 12 01 11

4.5 beta 3 - FPS: 380, draw calls 1000
this PR - FPS: 380, draw calls 1000
(can't be batched, labels are different canvas items and have specific draw order)

@bruvzg bruvzg force-pushed the text_draw_presort branch from 579ce25 to 61cf4fa Compare July 9, 2025 09:52
@bruvzg bruvzg force-pushed the text_draw_presort branch 2 times, most recently from 2ea9abf to 5cbc9d3 Compare October 14, 2025 08:48
@bruvzg bruvzg changed the title [WIP] Presort text draw calls. Presort text draw calls. Oct 14, 2025
@bruvzg bruvzg force-pushed the text_draw_presort branch 4 times, most recently from e6f38fd to 3245a94 Compare October 15, 2025 06:03
@bruvzg bruvzg marked this pull request as ready for review October 15, 2025 06:47
@bruvzg bruvzg requested review from a team as code owners October 15, 2025 06:47
@Bromeon Bromeon dismissed their stale review October 16, 2025 05:16

Compatibility break actually fixes an incorrect earlier definition.

@bruvzg bruvzg force-pushed the text_draw_presort branch from 3245a94 to ad37465 Compare October 16, 2025 05:37
Copy link
Member

@Mickeon Mickeon left a comment

Choose a reason for hiding this comment

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

Given how fairly important batching text calls seems to be, the class reference is a bit lacking in recommendations on how to make use of the API introduced in this PR.

<param index="5" name="color" type="Color" default="Color(1, 1, 1, 1)" />
<param index="6" name="oversampling" type="float" default="0.0" />
<description>
Adds draw calls for dropcap glyph outlines to the draw list [param list].
Copy link
Member

Choose a reason for hiding this comment

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

This can be seen as huge nitpick but I had to get it off of my chest someday.

All of these very brief descriptions in the TextServer may seem good at a glance, but they're quite unwelcoming. Hard to parse, difficult to localize, devoid of information. Yes, as an experienced developer with decent English knowledge, it's reasonably easy to understand what each parameter does, but that's not every one. Neither are the parameter names taken for granted in most of the class reference.
In this PR the descriptions are mostly okay, in my opinion, considering it's better to keep them consistent with the surrounding TextServer-related documentation (which is arguably more important), as well as to avoid redundancy. Regardless, it will be worth doing a huge pass someday.

Again, it's easy to understand these as a professional, but exposing methods and assigning them very terse and cryptid descriptions is one sure way to make the reader feel uneasy, like they're interacting with something they shouldn't be doing.

Draws all draw calls in the draw list to the canvas item [param ci]. If [param free] is [code]true[/code], draw list is automatically deleted.
</description>
</method>
<method name="draw_list_reserve">
Copy link
Member

Choose a reason for hiding this comment

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

Are we sure we want to expose what is essentially a reserve method to the public API? I would be very wary since this is a very prickly topic of discussion.
(Note that clayjohn got originally confused by the purpose of the linked PR).

Copy link
Member Author

Choose a reason for hiding this comment

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

With the way TextServer is implemented (to be implementable as GDExtension), I do not think it is possible to have non-exposed methods. And unlike Dictionary, TextServer is a low level API most users won't ever interact with, so it should not be an issue.

@bruvzg bruvzg force-pushed the text_draw_presort branch from ad37465 to bc5bc87 Compare October 17, 2025 21:38
@Mickeon Mickeon self-requested a review October 17, 2025 21:39
@bruvzg bruvzg force-pushed the text_draw_presort branch from bc5bc87 to 11bcba5 Compare October 18, 2025 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

4 participants