Skip to content

JIT bitmap text rendering blog post - #156

Merged
raphlinus merged 2 commits into
mainfrom
jit_text
Nov 7, 2026
Merged

raphlinus merged 2 commits into
mainfrom
jit_text

Conversation

@raphlinus

Copy link
Copy Markdown
Contributor

No description provided.

All this gives us everything we need to implement text rendering as an instance of display objects.

The text object itself contains the string (1 byte per character), a pointer to the font, and foreground and background colors.
RAM is precious, and more so for the display list because it's double buffered.

@tomcur tomcur Nov 7, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Line 58 also mentions needing to be careful about the display list memory footprint due to the two copies.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm leaving it in, I feel it's important enough to be mentioned in slightly different contexts. But thanks.

The packing also makes sure no glyph straddles a 32-pixel chunk boundary, so one row of font pixels can always be read with a single 32 bit load.
If a glyph has space on either side of the glyph, that's not stored in the packed bitmap; rather, the space is in the per-glyph metadata.

In the spirit of micro-optimization, the packing algorithm also detects overlaps, as there's no requirement that pixels be unique to a single glyph.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fun!

The JIT output is about a 10x expansion over the input string.
And, from the numbers above, it's clear that the cost of running the JIT is minimal.

The name "just in time" is apt; in the implementation in vic-2350, the JIT compiler runs under 100µs before scanout of the video line.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's neat 🕦

Comment on lines +235 to +236
Basically, each glyph has two bitvectors, one each for the left and right side.
To kern two glyphs, take the `and` of the right bitvector of the first glyph and the left bitvector of the second, then the popcount (number of `1` bits) of that, resulting in the number of pixels to kern.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What do the bits stand for, and how are they chosen?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've added a section.

@raphlinus
raphlinus merged commit 902d7ff into main Nov 7, 2026
2 checks passed
@raphlinus
raphlinus deleted the jit_text branch November 7, 2026 22:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants