Scene graph optimizations
Recreating the shaders on every single frame is obviously a bit wasteful. While this does amount to simply looking it up in the cache, and seems for the most part unproblematic on modern systems, it does represent pointless CPU load - and some clients may not want to keep around all the state needed to recreate the specific shader they want to re-execute multiple times. It may also be relevant for battery lifetime on mobile.
The idea I had to solve both of these problems is to introduce a sort of "dispatch graph", which is an extra type of opaque state object belonging to the pl_dispatch
API. When executing a pl_dispatch_finish
or pl_dispatch_compute
command, users can specify an optional dispatch graph to record the invocation into. (In which case, the actual dispatch command will always succeed - assuming no resource exhaustion etc.). These dispatch graphs can then be later re-executed, as many times as the user wants, without needing to pay the shader generation cost. To support swapping out e.g. texture descriptors, one idea I had is to allow specifying a list of "dynamic descriptors" at dispatch graph creation time, which the dispatch graph will intercept when recording pl_pass_run
arguments and allow replacing by different descriptors when re-executing the scene graph.
It's up to the user to ensure the validity of any objects referenced by the dispatch graph, as well as compatibility between dynamic descriptor objects and the objects the shader was generated against. In the pl_renderer
I will most likely do a hard memcmp
of the various params structs and destroy the dispatch graph if anything at all has changed.