laurentlb / shader-minifier

Minify and obfuscate GLSL or HLSL code

Home Page:https://ctrl-alt-test.fr/minifier/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

C# API

laurentlb opened this issue · comments

We could provide a better, documented API usable from C#. This would help tools minify code without having to call the .exe (and saving content to disk and parsing error messages).

I'd love this. Maybe it would be also possible to expose an API to the AST?

What would you like to do with the AST?

I'd like to be cautious. If we expose too much, we won't be able to keep the API stable.

What would you like to do with the AST?

I had a tool in mind for some time that performs a file size optimization on a specific intro using a global optimization technique (like CMA-ES). The optimization parameter space would be "shaders that produce identical results on screen", the cost function would be "build the intro with a specific shader, link it with a compressing linker and determine the file size."

So the task in the first step would be to generate shaders from an existing input shader with all the identical source transformations that do not change the shader output; like reordering independent nodes (for example independent elements of initializer lists or independent statements, functions, ...).

While it is perfectly possible to achieve with a separate parser/rewriter and using the shader_minifier executable in the cost function, it would be much cleaner to use shader_minifier's AST for this imho.

I'd like to be cautious. If we expose too much, we won't be able to keep the API stable.

I agree. Maybe just using the executable is the way :)

generate shaders from an existing input shader with all the identical source transformations that do not change the shader output;

This sounds like a feature that should be built inside Shader Minifier.

This sounds like a feature that should be built inside Shader Minifier.

that would be even cooler! :)

The C# is very simple; feel free to file new feature requests as needed.