Repository navigation
Fix array initializers and unused functions in generated GLSL - #1070
Open
Coastrnaut wants to merge 2 commits into
Open
Coastrnaut wants to merge 2 commits into
Coastrnaut wants to merge 2 commits into
Conversation
Many presets declare an array with a flat list of values, e.g.
"const float4 samples[5] = { 0, 0, 0, 11.0/3.0, ... };", which HLSL
allows. The GLSL generator produced two errors for these:
- Static globals are initialized at the start of main(), but the
assignment was written with the declaration syntax, "samples[5] = ...",
assigning to an element out of bounds instead of the whole array.
- The values were passed to the array constructor as is, but GLSL's
array constructor needs one value per element, e.g. vec4 values for a
vec4 array.
Write only the variable name for the assignment, and group values into
element constructors when the number of components doesn't match.
HLSL compilers only compile functions that are reachable from the entry
point, so some presets contain unused functions that aren't valid, e.g.
"float2 rsp(float2 uv_in) { }" without a return statement. GLSL
compilers check every function and reject these shaders.
Add HideUnusedFunctions(), which hides all top-level functions that
aren't called from the entry function or a global initializer, directly
or indirectly, and call it before generating GLSL. Unlike PruneTree(), it
leaves all other declarations untouched.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two GLSL generator fixes for preset shaders that failed to compile on every platform. Together they fix all 64 presets in the four packs below whose shaders compiled on neither desktop GL nor GLES.
Array initializers (57 presets). Many presets declare an array with a flat list of values, which HLSL allows:
The generated GLSL had two errors. Static globals are initialized at the start of
main(), but the assignment was written with the declaration syntax,samples[5] = ..., which assigns to an element out of bounds instead of the array. And the values were passed tovec4[](...)as is, while GLSL's array constructor needs one value per element. The assignment now only writes the name, and values are grouped into element constructors when their number of components doesn't match.Unused functions (7 presets). HLSL compilers only compile functions that the entry point uses, so some presets contain unused functions that aren't valid, e.g.
float2 rsp(float2 uv_in) { }without a return statement. GLSL compilers reject these. The newHideUnusedFunctions()hides top-level functions that aren't reachable from the entry function or a global initializer before the GLSL is generated. UnlikePruneTree(), it leaves all other declarations alone.Results
HLSLArrayInitializerTestandHLSLUnusedFunctionTest. All unit tests pass.How I tested it
I loaded all 14,536 presets from cream-of-the-crop, en-d, milkdrop-original and projectm-classic one after another (Windows, RTX A6000, GL 3.3 core and GLES contexts), with the preset folders as texture search path, rendered 30 frames each with fixed audio and frame times, and recorded shader compile/link results, failed loads and frame hashes. For the pixel comparison both builds had their random seeds fixed (a local patch only, identical on both sides). The presets this PR fixes are excluded from the pixel comparison, since loading them changes shared state (e.g. the expression evaluator's random generator) for every preset after them.
Retested on current master (2026-11-12)