Shader_Minifier icon indicating copy to clipboard operation
Shader_Minifier copied to clipboard

C# API

Open laurentlb opened this issue 2 years ago • 5 comments
trafficstars

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).

laurentlb avatar Sep 19 '23 19:09 laurentlb

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

LeStahL avatar Feb 20 '24 13:02 LeStahL

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.

laurentlb avatar Feb 20 '24 14:02 laurentlb

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 :)

LeStahL avatar Feb 20 '24 15:02 LeStahL

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.

laurentlb avatar Feb 20 '24 15:02 laurentlb

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

that would be even cooler! :)

LeStahL avatar Feb 20 '24 16:02 LeStahL

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

laurentlb avatar Jun 01 '24 23:06 laurentlb