From 02745f14a6b534f7a704ef3c512c9a0b4c999665 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 10 Jul 2023 14:40:01 -0700 Subject: til_fb: fast-path til_fb_fragment_clear() a bit What this really should have is a general memset32() implementation, but for now it's a small improvement at least for clearing since that's known to be a 0-pixel case where memset() is applicable. memset() isn't usable for actual RGBA pixels since it operates strictly on bytes. There's some hacks for using memmove() to get closer where you store the first four bytes, then memove the start of the buffer to the remaining, doubling the size of the move each time for log(n) calls to memmove. Maybe that makes sense as a stop-gap for the general case, it needs implementing+benchmarking first. This commit is dead simple though and an obvious little FPS gain for clearing. --- src/til_fb.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/til_fb.h b/src/til_fb.h index f6763e1..21699c2 100644 --- a/src/til_fb.h +++ b/src/til_fb.h @@ -162,9 +162,13 @@ static inline void _til_fb_fragment_fill(til_fb_fragment_t *fragment, uint32_t p /* TODO: there should be a fast-path for non-divided fragments where there's no stride to skip */ for (int y = 0; y < fragment->height; y++, buf += fragment->pitch) { - /* TODO: this should use something memset-like for perf */ - for (int x = 0; x < fragment->width; x++) - buf[x] = pixel; + if (!pixel) { + memset(buf, pixel, fragment->width * sizeof(pixel)); + } else { + /* TODO: this should use something memset-like for perf */ + for (int x = 0; x < fragment->width; x++) + buf[x] = pixel; + } } } -- cgit v1.2.3