String templates v2
Partial solution for the string concatenation problem.
What this PR does:
- define new helper
pl_str_builder
which can be used to cheaply concatenate a list of templates, plus their corresponding arguments - use
pl_str_builder
instead ofpl_str
for generating shaders insidepl_shader
andpl_dispatch
- use a (relatively cheaper) hash of the
pl_str_builder
(list of templates + args) to look up programs in the dispatch cache - make
pl_dispatch
defer execution of thepl_str_builder
(i.e. formatting the actual strings) until it's strictly necessary - use a preprocessor macro to avoid
printf()
overhead for pure constant strings without format specifiers
This series ended up defining a very general, flexible string builder, one which we can easily expand on and build upon in the future. For example, it would be easy to move some of the more expensive shader operations (such as generating unrolled polar filter kernels) into a dedicated pl_str_template
function which receives as input only the relevant arguments.
But in the long term, I want to use this abstraction as the staging grounds for more dedicated GLSL templating syntax, in the spirit of e.g. !369 (comment 370145)