summaryrefslogtreecommitdiff
path: root/src/til_threads.c
AgeCommit message (Collapse)Author
2022-08-07til: til_fb_fragment_t **fragment_ptr all the thingsVito Caputo
Preparatory commit for enabling cloneable/swappable fragments There's an outstanding issue with the til_fb_page_t submission, see comments. Doesn't matter for now since cloning doesn't happen yet, but will need to be addressed before they do.
2022-06-10til: introduce til_frame_plan_t and .cpu_affinityVito Caputo
modules/checkers w/fill_module=$module requires a consistent mapping of cpu to fragnum since it creates a per-cpu til_module_context_t for the fill_module. The existing implementation for threaded rendering maximizes performance by letting *any* scheduled to run thread advance fragnum atomically and render the acquired fragnum indiscriminately. A side effect of this is any given frame, even rendered by the same module, will have a random mapping of cpus/threads to fragnums. With this change, the simple til_module_t.prepare_frame() API of returning a bare fragmenter function is changed to instead return a "frame plan" in til_frame_plan_t. Right now til_frame_plan_t just contains the same fragmenter as before, but also has a .cpu_affinity member for setting if the frame requires a stable relationship of cpu/thread to fragnum. Setting .cpu_affinity should be avoided if unnecessary, and that is the default if you don't mention .cpu_affinity at all when initializing the plan in the ergonomic manner w/designated initializers. This is because the way .cpu_affinity is implemented will leave threads spinning while they poll for *their* next fragnum using atomic intrinsics. There's probably some room for improvement here, but this is good enough for now to get things working and correct.
2022-06-10til_threads: remove vestigial n_fragments counterVito Caputo
This is leftover from 4e5286 which was mostly removed when frame zeroing was simplified, but for some reason this was missed. Just get rid of the count as it's not used.
2022-05-29*: pivot to til_module_context_tVito Caputo
- modules now allocate their contexts using til_module_context_new() instead of [cm]alloc(). - modules simply embed til_module_context_t at the start of their respective private context structs, if they do anything with contexts - modules that do nothing with contexts (lack a create_context() method), will now *always* get a til_module_context_t supplied to their other methods regardless of their create_context() presence. So even if you don't have a create_context(), your prepare_frame() and/or render_fragment() methods can still access seed and n_cpus from within the til_module_context_t passed in as context, *always*. - modules that *do* have a create_context() method, implying they have their own private context type, will have to cast the til_module_context_t supplied to the other methods to their private context type. By embedding the til_module_context_t at the *start* of their private context struct, a simple cast is all that's needed. If it's placed somewhere else, more annoying container_of() style macros are needed - this is strongly discouraged, just put it at the start of struct. - til_module_create_context() now takes n_cpus, which may be set to 0 for automatically assigning the number of threads in its place. Any non-zero value is treated as an explicit n_cpus, primarily intended for setting it to 1 for single-threaded contexts necessary when embedded within an already-threaded composite module. - modules like montage which open-coded a single-threaded render are now using the same til_module_render_fragment() as everything else, since til_module_create_context() is accepting n_cpus. - til_module_create_context() now produces a real type, not void *, that is til_module_context_t *. All the other module context functions now operate on this type, and since til_module_context_t.module tracks the module this context relates to, those functions no longer require both the module and context be passed in. This is especially helpful for compositing modules which do a lot of module context creation and destruction; the module handle is now only needed to create the contexts. Everything else operating on that context only needs the single context pointer, not module+context pairs, which was unnecessarily annoying. - if your module's context can be destroyed with a simple free(), without any deeper knowledge or freeing of nested pointers, you can now simply omit destroy_context() altogether. When destroy_context() is missing, til_module_context_free() will automatically use libc's free() on the pointer returned from your create_context() (or on the pointer that was automatically created if you omitted create_context() too, for the bare til_module_context_t that got created on your behalf anyways). For the most part, these changes don't affect module creation. In some ways this eases module creation by making it more convenient access seed and n_cpus if you had no further requirement for a context struct. In other ways it's slightly annoying to have to do type-casts when you're working with your own context type, since before it was all void* and didn't require casts when assigning to your typed context variables. The elimination for requiring a destroy_context() method in simple free() of private context scenarios removes some boilerplate in simple cases. I think it's a wash for module writers, or maybe a slight win for the simple cases.
2022-05-23til: simplify fragment->cleared maintenanceVito Caputo
Just assume a fragment has been logically cleared after til_module_render() has done all its potential steps. I'm not certain this doesn't break some existing assumptions WRT fragmented/threaded clears and their propagation out to the outer frame. But I've been operating under the assumption that this was already happening in terms of an implicit setting of til_fb_fragment_t.cleared after a module's render happened. Except I don't see anything in the existing code or history actually doing that, which is odd. For modules that don't invoke til_fb_fragment_clear() explicitly because they are frame-fillers (think submit, swab, ray, julia, plasma, these are all full-frame renders that don't benefit from pre-clearing), they weren't leaving fragment->cleared set, despite having fully initialized the frame's contents. We should be able to just assume after prepare/render/finish has happened for a given module, the target fragment has been cleared. Commit 4e5286 had introduced somewhat complicated .cleared maintenance and propagation for threaded renders, but when we just treat all finished module renders into a given fragment as logically clearing the fragment we can just skip all that.
2022-05-01til: wire n_cpus up to the fragmenter functionVito Caputo
Fragmenting is often dimensioned according to the number of cpus, and by not supplying this to the fragmenter it was made rather common for module contexts to plumb this themselves - in some cases incorporating a context type/create/destroy rigamarole for the n_cpus circuit alone. So just plumb it in libtil, and the prepare_frame functions can choose to ignore it if they have something more desirable onhand. Future commits will remove a bunch of n_cpus from module contexts in favor of this.
2022-04-19*: s/til_fb_fragment_zero/til_fb_fragment_clear/Vito Caputo
Mechanical renaming of "zero" to "clear" throughout for this context.
2022-04-15til_threads: propagate threaded til_fb_fragment.zeroedVito Caputo
Currently when a threaded renderer performed til_fb_fragment_zero() in render_fragment() vs. prepare_frame(), the til_fb_fragment.zeroed maintenance would stay isolated to the ephemeral fragment generated by the fragmenter. With this commit, when all ephemeral fragments rendered in a threaded fashion for a given frame returned a set .zeroed member, the outer frame's .zeroed member gets set. This should enable proper threaded zeroing of the frame in render_fragment(). Note that since it's careful to actually count the number of zeroed ephemeral subfragments and only propagates when that count matches the number of subfragments rendered in the entire frame, it's also supported to use til_fb_fragment_zero() conditionally on just some fragments while not zeroing others and the entire frame will not get its .zeroed member set. Imagine a renderer which randomly zeroes out some fragments, while drawing into others, this will be honored as a non-zeroed frame on the whole.
2021-10-01*: librototiller->libtilVito Caputo
Largely mechanical rename of librototiller -> libtil, but introducing a til_ prefix to all librototiller (now libtil) functions and types where a rototiller prefix was absent. This is just a step towards a more libized librototiller, and til is just a nicer to type/read prefix than rototiller_.
© All Rights Reserved