Skip to content

String templates v2

Niklas Haas requested to merge string_templates_v2 into master

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 of pl_str for generating shaders inside pl_shader and pl_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 the pl_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)

Merge request reports

Loading