Commit 01c9607
committed
Improve rendering: ink-bounds, draw batching, text cache
This introduces rendering optimizations that reduce backend overhead for
partial-redraw and text-heavy UI scenes:
1. iui_emit_box: universal draw interception point replacing all direct
ctx->renderer.draw_box() calls. Route through ink-bounds tracking and
optional batch system.
2. Ink-bounds tracking: per-frame union bounding box of all draw calls
(boxes, text, lines, circles, arcs). Backend can query
iui_ink_bounds_get() to blit only the dirty region instead of full
framebuffer. Uses FLT_MAX/-FLT_MAX initialization to eliminate
first-extend branch on Arm Cortex-M pipeline. Negative width/height
inputs are normalized before accumulation.
3. Draw call batching — 256-command buffer with clip-rect grouping on
flush. All primitive types (rect, text, line, circle, arc) are routed
through the batch when enabled, preserving draw order. Vector font
text correctly bypasses the text batch (renders through
iui_emit_box which is already batch-aware).
4. Text width cache — 64-entry hash table with linear probing and LFU
eviction. Eliminates 99% of backend text_width callbacks. Cache key
includes font_height to prevent cross-size poisoning when typography
helpers temporarily mutate font metrics. Amortized O(k) decay per
frame avoids O(N) scan. IUI_TEXT_CACHE_SIZE enforced as power-of-two
via _Static_assert.
Benchmark (noop backend, 480x800, 5000 frames, median-of-3):
- Settings scene: 58 draws/frame, 1.9 us baseline
- Dashboard scene: 98 draws/frame, 2.4 us baseline
- Form scene: 66 draws/frame, 0.8 us baseline
- Text cache: 99% text_width elimination across all scenes
- Ink-bounds coverage: 100-119% of screen area (tight)
The ink-bounds overhead (47-72%) measured with noop backend is expected:
zero-cost draw calls make tracking arithmetic dominate. With a real
GPU/framebuffer backend, the dirty-rect savings from partial redraws
offset this cost significantly.1 parent aa955a7 commit 01c9607
20 files changed
Lines changed: 1306 additions & 421 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3245 | 3245 | | |
3246 | 3246 | | |
3247 | 3247 | | |
3248 | | - | |
| 3248 | + | |
3249 | 3249 | | |
3250 | 3250 | | |
3251 | | - | |
| 3251 | + | |
| 3252 | + | |
3252 | 3253 | | |
3253 | 3254 | | |
3254 | 3255 | | |
3255 | 3256 | | |
| 3257 | + | |
3256 | 3258 | | |
3257 | 3259 | | |
3258 | 3260 | | |
| |||
3291 | 3293 | | |
3292 | 3294 | | |
3293 | 3295 | | |
| 3296 | + | |
| 3297 | + | |
| 3298 | + | |
| 3299 | + | |
| 3300 | + | |
| 3301 | + | |
| 3302 | + | |
| 3303 | + | |
| 3304 | + | |
| 3305 | + | |
| 3306 | + | |
| 3307 | + | |
| 3308 | + | |
| 3309 | + | |
| 3310 | + | |
3294 | 3311 | | |
3295 | 3312 | | |
3296 | 3313 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
112 | | - | |
| 111 | + | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
117 | | - | |
| 116 | + | |
| 117 | + | |
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| |||
237 | 237 | | |
238 | 238 | | |
239 | 239 | | |
240 | | - | |
241 | | - | |
| 240 | + | |
| 241 | + | |
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
245 | | - | |
246 | | - | |
| 245 | + | |
| 246 | + | |
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
46 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | | - | |
68 | | - | |
| 66 | + | |
| 67 | + | |
69 | 68 | | |
70 | 69 | | |
71 | 70 | | |
| |||
92 | 91 | | |
93 | 92 | | |
94 | 93 | | |
95 | | - | |
96 | | - | |
97 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
98 | 97 | | |
99 | 98 | | |
100 | 99 | | |
| |||
288 | 287 | | |
289 | 288 | | |
290 | 289 | | |
291 | | - | |
292 | | - | |
| 290 | + | |
293 | 291 | | |
294 | 292 | | |
295 | 293 | | |
296 | 294 | | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
301 | 299 | | |
302 | 300 | | |
303 | 301 | | |
| |||
379 | 377 | | |
380 | 378 | | |
381 | 379 | | |
382 | | - | |
383 | | - | |
384 | | - | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
385 | 383 | | |
386 | 384 | | |
387 | 385 | | |
| |||
415 | 413 | | |
416 | 414 | | |
417 | 415 | | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
422 | 420 | | |
423 | 421 | | |
424 | 422 | | |
| |||
439 | 437 | | |
440 | 438 | | |
441 | 439 | | |
442 | | - | |
443 | | - | |
| 440 | + | |
444 | 441 | | |
445 | 442 | | |
446 | 443 | | |
| |||
636 | 633 | | |
637 | 634 | | |
638 | 635 | | |
639 | | - | |
640 | | - | |
| 636 | + | |
641 | 637 | | |
642 | 638 | | |
643 | 639 | | |
644 | 640 | | |
645 | 641 | | |
646 | | - | |
647 | | - | |
648 | | - | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
649 | 645 | | |
650 | 646 | | |
651 | 647 | | |
| |||
660 | 656 | | |
661 | 657 | | |
662 | 658 | | |
663 | | - | |
| 659 | + | |
| 660 | + | |
664 | 661 | | |
665 | | - | |
| 662 | + | |
666 | 663 | | |
667 | 664 | | |
668 | 665 | | |
| |||
672 | 669 | | |
673 | 670 | | |
674 | 671 | | |
675 | | - | |
| 672 | + | |
| 673 | + | |
676 | 674 | | |
677 | 675 | | |
678 | | - | |
679 | | - | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
680 | 679 | | |
681 | 680 | | |
682 | | - | |
| 681 | + | |
683 | 682 | | |
684 | 683 | | |
685 | 684 | | |
| |||
883 | 882 | | |
884 | 883 | | |
885 | 884 | | |
886 | | - | |
887 | | - | |
| 885 | + | |
888 | 886 | | |
889 | 887 | | |
890 | | - | |
891 | | - | |
| 888 | + | |
892 | 889 | | |
893 | 890 | | |
894 | 891 | | |
895 | | - | |
896 | | - | |
| 892 | + | |
897 | 893 | | |
898 | 894 | | |
899 | 895 | | |
| |||
0 commit comments