Repository navigation
Fix HLSL constructs in Milkdrop presets that failed to transpile - #1062
Open
Coastrnaut wants to merge 2 commits into
Open
Coastrnaut wants to merge 2 commits into
Coastrnaut wants to merge 2 commits into
Conversation
Several shader constructs used by presets either failed to parse or
generated invalid GLSL:
- all() was missing as an intrinsic. GLSL's any() and all() also only
accept boolean vectors, so scalar and numeric vector arguments are
now converted, e.g. all(modi) becomes all(bvec2(modi)).
- "sample" was always treated as an interpolation modifier, so it
couldn't be used as a variable name ("float3 sample = ...;"). It's
now only a modifier if an identifier follows, and it is renamed in
the GLSL output, as it's a keyword in newer GLSL versions.
- A swizzle or other postfix operator directly after a parenthesized
constructor, like "(float3(a, b, c).xyy * d)", was a syntax error.
- saturate() of a bool failed in the GLSL generator, it's now
converted to float first like HLSL does.
- The regex removing sampler declarations matched a line break after
the keyword, so a comment ending with the word "sampler" erased the
whole following line of code, e.g. a variable declaration.
The declaration removal moved into a static function so it can be
tested without an OpenGL context.
Of 19,210 warp/comp shaders in the preset packs, 51 shaders now
transpile and compile with the OpenGL driver. All shaders that compiled
before still do; 72 of them get different GLSL: in 69, a declaration of
an unused variable is no longer erased, in 3, an unused variable named
"sample" is renamed.
Moves the declaration away from the lines around PreprocessPresetShader() that projectM-visualizer#1061 changes, so the two branches merge without a conflict.
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.
Problem
Several HLSL constructs used by Milkdrop presets either failed to parse or produced invalid GLSL.
Changes
all()intrinsic missingif (all(modi)) {...}any()/all()only accept boolean vectors, so scalar and numeric vector arguments are converted, e.g.all(bvec2(modi))sampleas a variable namefloat3 sample = tex2D(...);sampleis only treated as an interpolation modifier if an identifier follows. It's renamed in the GLSL output, as it's a keyword in newer GLSL versionssaturate()of a boolsaturate(!mask)(float3(a, b, c).xyy * d)// noise sampler+ newline +float mfnoise = ...;\s+and erased the following line of code. It now only matches spaces and tabsThe sampler/texsize declaration removal moved into the static
MilkdropShader::RemoveSamplerAndTexSizeDeclarations(), so it can be tested without an OpenGL context.Tests
HLSLMilkdropCompatTest.cppwith 9 tests. 8 fail without this change; the 9th checks thatsamplestill works as an interpolation modifier. libprojectM suite: 173/173.sampler_stateregression fixed in Remove sampler_state blocks from the shader code again #1061. With both PRs combined, 106 shaders that fail on master compile.samplerenamed.The 7 shaders that still fail have unbalanced braces in the preset itself, or declare samplers through
#definemacros. Rendering wasn't checked visually.Retested on current master (2026-11-12)