diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2017-09-08 19:09:57 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2017-09-14 17:52:34 -0700 |
commit | 7e999e37a5cf65e466091f4d8eeb36a6cea20f52 (patch) | |
tree | fa1778c1daf753f46dcc1ca16d492dfa888f6fd3 /src/modules/ray | |
parent | 77f6d721564ceba589af14554685821aedfc8462 (diff) |
*: 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.
Diffstat (limited to 'src/modules/ray')
-rw-r--r-- | src/modules/ray/ray.c | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/src/modules/ray/ray.c b/src/modules/ray/ray.c index 4af9715..f442928 100644 --- a/src/modules/ray/ray.c +++ b/src/modules/ray/ray.c @@ -117,12 +117,38 @@ static ray_scene_t scene = { static float r; +typedef struct ray_context_t { + unsigned n_cpus; +} ray_context_t; + +static void * ray_create_context(void) +{ + return calloc(1, sizeof(ray_context_t)); +} + + +static void ray_destroy_context(void *context) +{ + free(context); +} + + +static int ray_fragmenter(void *context, const fb_fragment_t *fragment, unsigned num, fb_fragment_t *res_fragment) +{ + ray_context_t *ctxt = context; + + return fb_fragment_divide_single(fragment, ctxt->n_cpus * 64, num, res_fragment); +} + + /* prepare a frame for concurrent rendering */ -static void ray_prepare_frame(void *context, unsigned n_cpus, fb_fragment_t *fragment, rototiller_frame_t *res_frame) +static void ray_prepare_frame(void *context, unsigned n_cpus, fb_fragment_t *fragment, rototiller_fragmenter_t *res_fragmenter) { + ray_context_t *ctxt = context; + /* TODO experiment with tiled fragments vs. rows */ - res_frame->n_fragments = n_cpus * 64; - fb_fragment_divide(fragment, n_cpus * 64, res_frame->fragments); + ctxt->n_cpus = n_cpus; + *res_fragmenter = ray_fragmenter; /* TODO: the camera doesn't need the width and height anymore, the fragment has the frame_width/frame_height */ camera.width = fragment->frame_width, @@ -161,6 +187,8 @@ static void ray_render_fragment(void *context, fb_fragment_t *fragment) rototiller_module_t ray_module = { + .create_context = ray_create_context, + .destroy_context = ray_destroy_context, .prepare_frame = ray_prepare_frame, .render_fragment = ray_render_fragment, .name = "ray", |