From 7e999e37a5cf65e466091f4d8eeb36a6cea20f52 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Fri, 8 Sep 2017 19:09:57 -0700 Subject: *: use fragment generator Rather than laying out all fragments in a frame up-front in ray_module_t.prepare_frame(), return a fragment generator (rototiller_fragmenter_t) which produces the numbered fragment as needed. This removes complexity from the serially-executed prepare_frame() and allows the individual fragments to be computed in parallel by the different threads. It also eliminates the need for a fragments array in the rototiller_frame_t, indeed rototiller_frame_t is eliminated altogether. --- src/modules/roto/roto.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/modules/roto') diff --git a/src/modules/roto/roto.c b/src/modules/roto/roto.c index 2074414..f076188 100644 --- a/src/modules/roto/roto.c +++ b/src/modules/roto/roto.c @@ -25,6 +25,7 @@ typedef struct color_t { typedef struct roto_context_t { unsigned r, rr; + unsigned n_cpus; } roto_context_t; static int32_t costab[FIXED_TRIG_LUT_SIZE], sintab[FIXED_TRIG_LUT_SIZE]; @@ -168,8 +169,16 @@ static void init_roto(uint8_t texture[256][256], int32_t *costab, int32_t *sinta } +static int roto_fragmenter(void *context, const fb_fragment_t *fragment, unsigned num, fb_fragment_t *res_fragment) +{ + roto_context_t *ctxt = context; + + return fb_fragment_divide_single(fragment, ctxt->n_cpus, num, res_fragment); +} + + /* prepare a frame for concurrent rendering */ -static void roto_prepare_frame(void *context, unsigned n_cpus, fb_fragment_t *fragment, rototiller_frame_t *res_frame) +static void roto_prepare_frame(void *context, unsigned n_cpus, fb_fragment_t *fragment, rototiller_fragmenter_t *res_fragmenter) { roto_context_t *ctxt = context; static int initialized; @@ -180,8 +189,8 @@ static void roto_prepare_frame(void *context, unsigned n_cpus, fb_fragment_t *fr init_roto(texture, costab, sintab); } - res_frame->n_fragments = n_cpus; - fb_fragment_divide(fragment, n_cpus, res_frame->fragments); + *res_fragmenter = roto_fragmenter; + ctxt->n_cpus = n_cpus; // This governs the rotation and color cycle. ctxt->r += FIXED_TO_INT(FIXED_MULT(FIXED_SIN(ctxt->rr), FIXED_NEW(16))); -- cgit v1.2.1