From 3d6ba50682bb1384eb487789275f95c87930944c Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Sun, 31 Dec 2023 14:30:56 -0800 Subject: modules/swab: update sample coords piecemeal Now that din() leaves the input coordinate alone as a const, the rendering loop can reuse the unchanging members across din() calls and only refresh the changing members as needed. Good for a small 62->64FPS boost on the i7 X230 in `--module=swab --video=mem --defaults` tests --- src/modules/swab/swab.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/modules/swab/swab.c b/src/modules/swab/swab.c index c4f1c91..952046d 100644 --- a/src/modules/swab/swab.c +++ b/src/modules/swab/swab.c @@ -114,21 +114,42 @@ static void swab_render_fragment(til_module_context_t *context, til_stream_t *st float xscale = 1.f / (float)fragment->frame_width; float yscale = 1.f / (float)fragment->frame_height; float yscaled; + v3f_t t_coord = { + .z = -z2 + }; + v3f_t r_coord = { + .z = z1 + }; + v3f_t g_coord = { + .z = -z1 + }; + v3f_t b_coord = { + .z = z2 + }; yscaled = (float)fragment->y * yscale; for (unsigned y = 0; y < frag_h; y++, yscaled += yscale) { float xscaled = (float)fragment->x * xscale; + t_coord.y = yscaled * .5f; + r_coord.y = yscaled * .7f; + g_coord.y = yscaled * .93f; + b_coord.y = yscaled * .81f; + for (unsigned x = 0; x < frag_w; x++, xscaled += xscale) { color_t color; uint32_t pixel; float t; - t = din(ctxt->din, &(v3f_t){ .x = xscaled * .5f, .y = yscaled * .5f, .z = -z2 }) * 33.f; + t_coord.x = xscaled * .5f; + r_coord.x = xscaled * .7f; + g_coord.x = xscaled * .93f; + b_coord.x = xscaled * .81f; - color.r = din(ctxt->din, &(v3f_t){ .x = xscaled * .7f, .y = yscaled * .7f, .z = z1 }) * t; - color.g = din(ctxt->din, &(v3f_t){ .x = xscaled * .93f, .y = yscaled * .93f, .z = -z1 }) * t; - color.b = din(ctxt->din, &(v3f_t){ .x = xscaled * .81f, .y = yscaled * .81f, .z = z2 }) * t; + t = din(ctxt->din, &t_coord) * 33.f; + color.r = din(ctxt->din, &r_coord) * t; + color.g = din(ctxt->din, &g_coord) * t; + color.b = din(ctxt->din, &b_coord) * t; pixel = color_to_uint32(color); til_fb_fragment_put_pixel_unchecked(fragment, 0, fragment->x + x, fragment->y + y, pixel); -- cgit v1.2.3