summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2017-04-27 09:53:50 -0700
committerVito Caputo <vcaputo@pengaru.com>2017-04-27 14:17:07 -0700
commit4d57f2c2bbd147d8b141cbf49fd49eafd014e69b (patch)
tree70d9d00578c3aeb1cc316c41972281b1f2a3f18d
parentfc4e5f9d1e734affab9917558f19102a1331942f (diff)
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.
-rw-r--r--src/modules/sparkler/sparkler.c22
1 files 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 <vcaputo@pengaru.com>",
.license = "GPLv2",
};
© All Rights Reserved