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/julia/julia.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/modules/julia/julia.c') diff --git a/src/modules/julia/julia.c b/src/modules/julia/julia.c index 3215902..f2fb87d 100644 --- a/src/modules/julia/julia.c +++ b/src/modules/julia/julia.c @@ -13,11 +13,12 @@ /* TODO: explore using C99 complex.h and its types? */ typedef struct julia_context_t { - float rr; - float realscale; - float imagscale; - float creal; - float cimag; + float rr; + float realscale; + float imagscale; + float creal; + float cimag; + unsigned n_cpus; } julia_context_t; static uint32_t colors[] = { @@ -100,13 +101,21 @@ static inline unsigned julia_iter(float real, float imag, float creal, float cim } +static int julia_fragmenter(void *context, const fb_fragment_t *fragment, unsigned num, fb_fragment_t *res_fragment) +{ + julia_context_t *ctxt = context; + + return fb_fragment_divide_single(fragment, ctxt->n_cpus, num, res_fragment); +} + + /* Prepare a frame for concurrent drawing of fragment using multiple fragments */ -static void julia_prepare_frame(void *context, unsigned n_cpus, fb_fragment_t *fragment, rototiller_frame_t *res_frame) +static void julia_prepare_frame(void *context, unsigned n_cpus, fb_fragment_t *fragment, rototiller_fragmenter_t *res_fragmenter) { julia_context_t *ctxt = context; - res_frame->n_fragments = n_cpus; - fb_fragment_divide(fragment, n_cpus, res_frame->fragments); + *res_fragmenter = julia_fragmenter; + ctxt->n_cpus = n_cpus; ctxt->rr += .01; /* Rather than just sweeping creal,cimag from -2.0-+2.0, I try to keep things confined -- cgit v1.2.3