From 4d57f2c2bbd147d8b141cbf49fd49eafd014e69b Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Thu, 27 Apr 2017 09:53:50 -0700 Subject: sparkler: enable rudimentary threaded rendering This moves most of the particle system maintenance into the serially executed sparkler_prepare_frame(), divides the frame into ncpus fragments, and leaves the draw to occur concurrently. The drawing must still currently process all particles and simply skips drawing those falling outside the fragment. Moving more of the computation out of prepare_frame() and into render_fragment() is left for future improvements, as it's a bit complex to do gainfully. --- src/modules/sparkler/sparkler.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/modules/sparkler/sparkler.c b/src/modules/sparkler/sparkler.c index 6d8d354..a2210dc 100644 --- a/src/modules/sparkler/sparkler.c +++ b/src/modules/sparkler/sparkler.c @@ -58,28 +58,36 @@ static void sparkler_destroy_context(void *context) } +static void sparkler_prepare_frame(void *context, unsigned ncpus, fb_fragment_t *fragment, rototiller_frame_t *res_frame) +{ + sparkler_context_t *ctxt = context; + + fb_fragment_divide(fragment, ncpus, res_frame->fragments); + res_frame->n_fragments = ncpus; + + particles_sim(ctxt->particles); + particles_add_particles(ctxt->particles, NULL, &simple_ops, INIT_PARTS / 4); + particles_age(ctxt->particles); +} + + /* Render a 3D particle system */ static void sparkler_render_fragment(void *context, fb_fragment_t *fragment) { sparkler_context_t *ctxt = context; - uint32_t *buf = fragment->buf; - fb_fragment_zero(fragment); - - particles_age(ctxt->particles); particles_draw(ctxt->particles, fragment); - particles_sim(ctxt->particles); - particles_add_particles(ctxt->particles, NULL, &simple_ops, INIT_PARTS / 4); } rototiller_module_t sparkler_module = { .create_context = sparkler_create_context, .destroy_context = sparkler_destroy_context, + .prepare_frame = sparkler_prepare_frame, .render_fragment = sparkler_render_fragment, .name = "sparkler", - .description = "Particle system with spatial interactions", + .description = "Particle system with spatial interactions (threaded (poorly))", .author = "Vito Caputo ", .license = "GPLv2", }; -- cgit v1.2.1