Closed Bug 1674443 Opened 4 years ago Closed 4 years ago

Investigate tighter texture atlas packing for glyphs

Categories

(Core :: Graphics: WebRender, task, P3)

task

Tracking

()

RESOLVED FIXED
84 Branch
Tracking Status
firefox84 --- disabled
firefox85 --- fixed

People

(Reporter: nical, Assigned: nical)

References

(Blocks 2 open bugs)

Details

Attachments

(5 files)

Let's figure out whether we can pack more glyphs in the same amount of texture memory. Packing glyphs into fewer textures will translate into less memory usage and better batching.

I put together a quick tool to record all glyph allocations and print out distributions. Here is the result after a few thousand allocations (visited a wipedia page and theverge.com) on a 4k screen with device-pixel ratio of 2:

# Widths:
size:		8	16	24	32	40	48	56	64	80	96	128	256+
count:		895	3537	1374	214	68	3	6	4	23	12	0	0
# Heights:
size:		8	16	24	32	40	48	56	64	80	96	128	256+
count:		231	1807	3023	712	69	51	148	2	12	81	0	0



		8	16	24	32	40	48	56	64	80	96	128	256+
	
	-	-	-	-	-	-	-	-	-	-	-	-	-
8	|	175	36	9	10	0	0	1	0	0	0	0	0
16	|	133	1431	233	10	0	0	0	0	0	0	0	0
24	|	468	1800	699	47	9	0	0	0	0	0	0	0
32	|	97	231	290	88	5	1	0	0	0	0	0	0
40	|	16	4	41	4	4	0	0	0	0	0	0	0
48	|	3	15	6	18	7	0	0	2	0	0	0	0
56	|	3	16	92	30	5	2	0	0	0	0	0	0
64	|	0	0	0	0	0	0	2	0	0	0	0	0
80	|	0	0	2	0	9	0	1	0	0	0	0	0
96	|	0	4	2	7	29	0	2	2	23	12	0	0
128	|	0	0	0	0	0	0	0	0	0	0	0	0
256	|	0	0	0	0	0	0	0	0	0	0	0	0

Here is roughly the same workload with device-pixel ratio of 1:

# Widths:
size:		8	16	24	32	40	48	56	64	80	96	128	256+
count:		3549	1906	130	19	30	12	0	0	0	0	0	0
# Heights:
size:		8	16	24	32	40	48	56	64	80	96	128	256+
count:		1619	3467	278	177	20	85	0	0	0	0	0	0



		8	16	24	32	40	48	56	64	80	96	128	256+
	
	-	-	-	-	-	-	-	-	-	-	-	-	-
8	|	1382	223	9	5	0	0	0	0	0	0	0	0
16	|	2090	1340	36	1	0	0	0	0	0	0	0	0
24	|	52	185	37	4	0	0	0	0	0	0	0	0
32	|	21	146	6	4	0	0	0	0	0	0	0	0
40	|	0	1	9	3	6	1	0	0	0	0	0	0
48	|	4	11	33	2	24	11	0	0	0	0	0	0
56	|	0	0	0	0	0	0	0	0	0	0	0	0
64	|	0	0	0	0	0	0	0	0	0	0	0	0
80	|	0	0	0	0	0	0	0	0	0	0	0	0
96	|	0	0	0	0	0	0	0	0	0	0	0	0
128	|	0	0	0	0	0	0	0	0	0	0	0	0
256	|	0	0	0	0	0	0	0	0	0	0	0	0

This shows that we can easily save memory on glyphs by having more granularity for small slab sizes, and perhaps have smaller regions to minimize the waste from partially occupied regions. For example we could make regions 128x128 for glyphs and place the rare glyphs that are larger than 128px into the color8_linear texture.

In the next patch we'll set a smaller region size for the glyph texture.

Since glyphs are rarely larger than 128x128, we can reduce the amount of wasted space from partially used glyph regions by having smaller ones (and more of them).

Depends on D95756

Also tweak the visualization in various ways so that having a large amount of regions (glyphs) doesn't bring down simple SVG viewing software.

Depends on D95757

This patch simplifies the slab allocator in various ways, most importantly separating the packing logic and texture cache glue (dealing with swizzling, cache entries, etc.). The former is moved into TextureUnits/TextureUnit and the latter is mostly contained into TextureCache.

This patch should have no functional change. The goal to make it easier to introduce custom slab sizes for glyphs in a followup patch, and later use different packing algorithms.

This is a modest win on hidpi and a larger win on lowdpi. We can improve further by introducing more granularity between 16 and 32px, this puts in place the basic infrastructure on top of which we can experiment.

Depends on D95869

Summary: Investigate tighter texture atlas packing for flyphs → Investigate tighter texture atlas packing for glyphs
Pushed by nsilva@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/e18cf134339a Support multiple texture region sizes. r=jnicol https://hg.mozilla.org/integration/autoland/rev/bbbf988c2940 Use 128x128 regions in the glyph atlas. r=jnicol https://hg.mozilla.org/integration/autoland/rev/2c2dc8dab741 Lay regions out in a grid in the texture cache SVG dump. r=jnicol https://hg.mozilla.org/integration/autoland/rev/6319f8438a3a Refactor the texture cache slab allocator. r=gw
Pushed by nsilva@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/aaf0ff52517d Introduce custom slab sizes for glyphs. r=jnicol,gw

This was backed out from 84 for landing during the soft freeze and causing bug 1677771. It remains landed for 85+.
https://hg.mozilla.org/releases/mozilla-beta/rev/829d402760bc

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: