0

Displayio slow draw speeds
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Displayio slow draw speeds

by raven_coda on Sun Jul 03, 2022 12:08 am

I'm doing some benchmarks and found the displayio module very slow. I'm hoping it is because I don't understand how to use the library efficiently. Using the following displayio I code I only get 3 FPS

Code: Select all | TOGGLE FULL SIZE
display_bus = displayio.FourWire(spi, command=board.GP20, chip_select=board.GP22, reset=board.GP21, baudrate=100000000)
display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240, auto_refresh=False)

cb = displayio.Bitmap(320,240,1_)
cp = displayio.Palette(1)
bgs=displayio.TileGrid(cb, pixel_shader=cp, x=0, y=0)
group.append(bgs)

while True:
    cp[0] = 0xFF0000
    display.refresh()
    cp[0] = 0x0000FF
    display.refresh()


However, if I use the following code to send the data directly to the fourwire interface I get 21 FPS, 7x the speed.
Code: Select all | TOGGLE FULL SIZE
while True:
    display_bus.send(0x2A, b"\0\0\x01\x40")
    display_bus.send(0x2b, b"\0\0\0\xf0")
    display_bus.send(0x2c, b"\xFC\0"*240*320)
    display_bus.send(0x2A, b"\0\0\x01\x40")
    display_bus.send(0x2b, b"\0\0\0\xf0")
    display_bus.send(0x2c, b"\0\x3F"*240*320)


Is there a way I could make the displayio library more performant? For reference, I'm using the RP2040 which has more than enough RAM to hold a frame buffer in memory if that would address the issue.

raven_coda
 
Posts: 3
Joined: Sun Jul 03, 2022 12:01 am

Re: Displayio slow draw speeds

by blakebr on Sun Jul 03, 2022 1:53 pm

Tracking

blakebr
 
Posts: 349
Joined: Tue Apr 17, 2012 6:23 pm

Re: Displayio slow draw speeds

by blakebr on Mon Jul 04, 2022 3:50 pm

raven_coda,

Can you post your entire code.py file. I just got an ILI3941 and I would like to see how you made it work.

Thanks,
Bruce

blakebr
 
Posts: 349
Joined: Tue Apr 17, 2012 6:23 pm

Re: Displayio slow draw speeds

by raven_coda on Mon Jul 04, 2022 9:31 pm

Here is a more polished version
Code: Select all | TOGGLE FULL SIZE
import board
import displayio
import adafruit_ili9341
import time
from busio import SPI

direct = False  #change this to true to compare

displayio.release_displays()
spi = SPI(clock=board.GP18, MOSI=board.GP19, MISO=board.GP16)

display_bus = displayio.FourWire(spi, command=board.GP20, chip_select=board.GP22, reset=board.GP21,baudrate=125000000)
display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240, auto_refresh=False)

group = displayio.Group()
display.show(group)

cb = displayio.Bitmap(320,240,1_)
cp = displayio.Palette(1)
cp[0] = 0x00FF00
bgs=displayio.TileGrid(cb, pixel_shader=cp, x=0, y=0)
group.append(bgs)

while True:
    start = time.monotonic()
    for i in range(10):
        if direct:
            display_bus.send(0x2A, b"\0\0\x01\x40")
            display_bus.send(0x2b, b"\0\0\0\xf0")
            display_bus.send(0x2c, b"\xFC\0"*240*320)
            display_bus.send(0x2A, b"\0\0\x01\x40")
            display_bus.send(0x2b, b"\0\0\0\xf0")
            display_bus.send(0x2c, b"\0\x3F"*240*320)
        else:
            display.refresh()
            cp[0] = 0x0000FF
            display.refresh()
            cp[0] = 0xFF0000
    span = time.monotonic()-start
    print(20 / span)

raven_coda
 
Posts: 3
Joined: Sun Jul 03, 2022 12:01 am

Re: Displayio slow draw speeds

by blakebr on Tue Jul 05, 2022 2:08 pm

Thank you!

blakebr
 
Posts: 349
Joined: Tue Apr 17, 2012 6:23 pm

Re: Displayio slow draw speeds

by tannewt on Tue Jul 05, 2022 3:21 pm

raven_coda wrote:I'm doing some benchmarks and found the displayio module very slow.

Is there a way I could make the displayio library more performant? For reference, I'm using the RP2040 which has more than enough RAM to hold a frame buffer in memory if that would address the issue.


displayio isn't designed to be performant when updating the entire display. It trades speed for reduced memory use by computing pixels as need and in chunks. It also does dirty rectangle tracking for you to know where to update. Dirty rectangle tracking reduces data transferred to displays that have their own framebuffer. displayio is used across many microcontrollers so it isn't easy to rewrite for the rp2040.

What are you actually trying to do with displayio? Your benchmark is one of the worst cases. (Reading pixels from a file with OnDiskBitmap can also be very slow.)

tannewt
 
Posts: 2991
Joined: Thu Oct 06, 2016 8:48 pm

Re: Displayio slow draw speeds

by raven_coda on Wed Jul 06, 2022 10:36 am

I was just doing some benchmarks but the end goal is to implement a tile-based side scroller game. Since most of the screen would need updating I don't think the dirty rectangle optimization will work for my needs. Thanks for the reply though.

raven_coda
 
Posts: 3
Joined: Sun Jul 03, 2022 12:01 am

Re: Displayio slow draw speeds

by tannewt on Wed Jul 06, 2022 2:19 pm

For side scrolling I had intended on supporting the built in scroll ability of displays. However, it is only one direction usually and often it is the wrong axis.

tannewt
 
Posts: 2991
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.