From 45d1f956b35fa9003106716e42425cc86cadc7a1 Mon Sep 17 00:00:00 2001
From: Vito Caputo <vcaputo@pengaru.com>
Date: Sun, 1 May 2022 11:27:23 -0700
Subject: til: introduce some generic fragmenters for convenience

Most of the threaded modules have settled down on two basic forms
of fragmenter function:

1. a slice per cpu, where tile-oriented locality isn't useful
2. ~64x64 tiles, in scenarios where screen-space locality helps

Now that n_cpus is wired up to the fragmenter, #1 can be
fulfilled without requiring a module-private context plumbing
n_cpus from create_context().

A future commit will replace some module-specific fragmenters by
returning one of these instead as res_fragmenter in their
prepare_frame(), wherever applicable.
---
 src/til.c | 14 ++++++++++++++
 src/til.h |  2 ++
 2 files changed, 16 insertions(+)

diff --git a/src/til.c b/src/til.c
index 5d375c3..ce880b3 100644
--- a/src/til.c
+++ b/src/til.c
@@ -291,3 +291,17 @@ int til_module_randomize_setup(const til_module_t *module, til_setup_t **res_set
 
 	return r;
 }
+
+
+/* generic fragmenter using a horizontal slice per cpu according to n_cpus */
+int til_fragmenter_slice_per_cpu(void *context, unsigned n_cpus, const til_fb_fragment_t *fragment, unsigned number, til_fb_fragment_t *res_fragment)
+{
+	return til_fb_fragment_slice_single(fragment, n_cpus, number, res_fragment);
+}
+
+
+/* generic fragmenter using 64x64 tiles, ignores n_cpus */
+int til_fragmenter_tile64(void *context, unsigned n_cpus, const til_fb_fragment_t *fragment, unsigned number, til_fb_fragment_t *res_fragment)
+{
+	return til_fb_fragment_tile_single(fragment, 64, number, res_fragment);
+}
diff --git a/src/til.h b/src/til.h
index 605dba1..c422914 100644
--- a/src/til.h
+++ b/src/til.h
@@ -38,5 +38,7 @@ int til_module_create_context(const til_module_t *module, unsigned ticks, til_se
 void * til_module_destroy_context(const til_module_t *module, void *context);
 int til_module_setup(til_settings_t *settings, til_setting_t **res_setting, const til_setting_desc_t **res_desc, til_setup_t **res_setup);
 int til_module_randomize_setup(const til_module_t *module, til_setup_t **res_setup, char **res_arg);
+int til_fragmenter_slice_per_cpu(void *context, unsigned n_cpus, const til_fb_fragment_t *fragment, unsigned number, til_fb_fragment_t *res_fragment);
+int til_fragmenter_tile64(void *context, unsigned n_cpus, const til_fb_fragment_t *fragment, unsigned number, til_fb_fragment_t *res_fragment);
 
 #endif
-- 
cgit v1.2.3