Skip to content

Minify GLSL shaders in release export templates to reduce binary size#59203

Open
Calinou wants to merge 1 commit intogodotengine:masterfrom
Calinou:scons-minify-glsl-shaders
Open

Minify GLSL shaders in release export templates to reduce binary size#59203
Calinou wants to merge 1 commit intogodotengine:masterfrom
Calinou:scons-minify-glsl-shaders

Conversation

@Calinou
Copy link
Copy Markdown
Member

@Calinou Calinou commented Mar 16, 2022

This reduces release export template binary sizes by about 103 KB. To avoid interfering with debugging, only target=template_release builds make use of GLSL minification.

TODO

  • Figure out how to avoid copy-pasting the list of minification replacements in both GLES3 and Vulkan builders.

@Calinou Calinou added this to the 4.0 milestone Mar 16, 2022
@Calinou Calinou requested a review from a team as a code owner March 16, 2022 17:41
@reduz
Copy link
Copy Markdown
Member

reduz commented Aug 3, 2022

This is really not a good idea, the shader is printed on error so it should not be modified. Instead, I would look into compressing the shader using zlib or something else like we compress docs and other things.

@Calinou
Copy link
Copy Markdown
Member Author

Calinou commented Aug 3, 2022

This is really not a good idea, the shader is printed on error so it should not be modified. Instead, I would look into compressing the shader using zlib or something else like we compress docs and other things.

Note that comments are already stripped from shaders (even in target=debug builds), so line numbers printed by Godot already don't match those you find in the original shader file.

Compressing text resources in the binary is still a valuable thing, but ideally, we should do both minification and compression.

@YuriSizov YuriSizov modified the milestones: 4.0, 4.1 Feb 9, 2023
@YuriSizov YuriSizov modified the milestones: 4.1, 4.2 Jun 14, 2023
@Calinou Calinou force-pushed the scons-minify-glsl-shaders branch 2 times, most recently from c3ce00a to f9980ea Compare July 17, 2023 10:02
@Calinou Calinou changed the title Minify GLSL shaders in non-debug targets to reduce binary size Minify GLSL shaders in release export templates to reduce binary size Jul 17, 2023
@Calinou
Copy link
Copy Markdown
Member Author

Calinou commented Jul 17, 2023

I've amended the PR to avoid code duplication for the minification routine, and also changed it to only affect release export templates. The binary size reduction has also increased somewhat since I opened this PR (-90 KB -> -103 KB on a stripped Linux x86_64 release export template with LTO).

@Calinou
Copy link
Copy Markdown
Member Author

Calinou commented Jan 12, 2025

Rebased and tested again, it works as expected.

The binary size improvement has further increased since I last tested this PR (sizes are for a Linux x86_64 release export template, stripped with LTO):

  • master: 71,782,136 bytes
  • This PR: 71,503,608 bytes

That's a difference of almost 280 KB. This is likely due to the inclusion of a lot more GLSL code nowadays (e.g. for FSR2).

This reduces release export template binary sizes by about 103 KB.
To avoid interfering with debugging, only `target=template_release`
builds make use of GLSL minification.
@Calinou Calinou force-pushed the scons-minify-glsl-shaders branch from 393a272 to 4322837 Compare January 13, 2025 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants