From cc418917fcf9a95873401a3f59b68771c8c4a1e7 Mon Sep 17 00:00:00 2001 From: Omar Rizwan Date: Thu, 12 Oct 2023 12:42:56 -0400 Subject: text: Batch glyphs into one wish -- fixes performance. --- virtual-programs/display.folk | 8 ++++++++ virtual-programs/display/text.folk | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'virtual-programs') diff --git a/virtual-programs/display.folk b/virtual-programs/display.folk index 07b94825..387d300a 100644 --- a/virtual-programs/display.folk +++ b/virtual-programs/display.folk @@ -101,6 +101,8 @@ Start process "display" { [list /someone/ wishes the GPU compiles pipeline /name/ /source/] Wish $::thisProcess receives statements like \ [list /someone/ wishes the GPU draws pipeline /name/ with arguments /args/] + Wish $::thisProcess receives statements like \ + [list /someone/ wishes the GPU draws pipeline /name/ with instances /args/] Wish $::thisProcess shares statements like \ [list /someone/ claims the display time is /displayTime/] @@ -115,6 +117,12 @@ Start process "display" { foreach match [Statements::findMatches {/someone/ wishes the GPU draws pipeline /name/ with arguments /args/}] { lappend ::displayList [list Gpu::draw [dict get $::pipelines [dict get $match name]] {*}[dict get $match args]] } + foreach match [Statements::findMatches {/someone/ wishes the GPU draws pipeline /name/ with instances /instances/}] { + set pipeline [dict get $::pipelines [dict get $match name]] + foreach instance [dict get $match instances] { + lappend ::displayList [list Gpu::draw $pipeline {*}$instance] + } + } set renderTime [baretime { Gpu::drawStart diff --git a/virtual-programs/display/text.folk b/virtual-programs/display/text.folk index 992e77b1..a6c828b9 100644 --- a/virtual-programs/display/text.folk +++ b/virtual-programs/display/text.folk @@ -124,6 +124,7 @@ On process "display" { set x $x0; set y $y0 set lineNum 0 + set instances [list] for {set i 0} {$i < [string length $text]} {incr i} { set char [string index $text $i] if {$char eq "\n"} { @@ -140,12 +141,16 @@ On process "display" { } lassign $glyphInfo advance planeBounds atlasBounds if {$char ne " "} { - Wish the GPU draws pipeline "glyph" with arguments \ + lappend instances \ [list $fontAtlas $fontAtlasSize \ $atlasBounds $planeBounds [list $x $y] $radians $em] } lassign [vec2 add [list $x $y] \ [vec2 rotate [list [* $advance $em] 0] $radians]] x y } + + # We need to batch into one wish so we don't deal with n^2 + # checks for existing statements for n glyphs. + Wish the GPU draws pipeline "glyph" with instances $instances } } -- cgit v1.2.3