displayio: remove per-pixel divides from TileGrid.fill_area - #11459
Merged
Merged
Conversation
TileGrid.fill_area computed the tile index, the position inside the tile and the tile's place in the bitmap with nine integer divides per pixel. All divisors are constant for the call, and five of the divides depend only on the row. On cores without a divide instruction each one is a library call. - The row terms are computed once per row. - The x terms are stepped along the row. - The tile's position in the bitmap is recomputed only when the tile changes. - Bitmap.get_pixel computes values_per_byte only for bitmaps below 8 bits per pixel, so 8 and 16 bpp reads no longer divide. RP2040 (pajenicko_picopad), full-screen 320x240 repaint of an 8 bpp bitmap: 297 -> 203 ms. Flash +104 bytes. Output is unchanged: 12 cases (tiles of 16x16 and 12x10, partly off-screen, flip_x, flip_y, transpose, scale 2 and 3, transparency with overlap, 1/2/4/8/16 bpp, ColorConverter, dither) checksum identically through BusDisplay.fill_row.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TileGrid.fill_areadid nine integer divides per pixel. The divisors do not change during the call, and five of the divides depend only on the row. On cores without a hw divide each one is a library call.Now the row terms are computed once per row, the x terms are stepped along the row, and the tile's position in the bitmap is recomputed only when the tile changes.
Bitmap.get_pixelno longer divides for 8 and 16 bpp bitmaps.Full-screen 320x240 repaint on an RP2040: 297 ms -> 203 ms. Flash +104 bytes.
Output is unchanged, checked with checksums of 12 test scenes via
BusDisplay.fill_row(tile sizes, flips, transpose, scale, transparency, 1-16 bpp, ColorConverter, dither).This is the same approach the picogame blitters use.