Skip to content

Fix HLSL constructs in Milkdrop presets that failed to transpile - #1062

Open
Coastrnaut wants to merge 2 commits into
projectM-visualizer:masterfrom
Coastrnaut:fix/shader-transpile-failures
Open

Coastrnaut wants to merge 2 commits into
projectM-visualizer:masterfrom
Coastrnaut:fix/shader-transpile-failures

Conversation

@Coastrnaut

@Coastrnaut Coastrnaut commented Nov 8, 2026 •

Copy link
Copy Markdown

Problem

Several HLSL constructs used by Milkdrop presets either failed to parse or produced invalid GLSL.

Changes

Construct Example Shaders Fix
all() intrinsic missing if (all(modi)) {...} 27 Added. GLSL's any()/all() only accept boolean vectors, so scalar and numeric vector arguments are converted, e.g. all(bvec2(modi))
sample as a variable name float3 sample = tex2D(...); 14 sample is 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 versions
saturate() of a bool saturate(!mask) 8 GLSL generation failed; the argument is now converted to float first, like HLSL does
Swizzle on a parenthesized constructor (float3(a, b, c).xyy * d) 1 Postfix operators are now parsed after a constructor inside parentheses
Comment ending with "sampler" // noise sampler + newline + float mfnoise = ...; 1 The sampler declaration regex matched the line break via \s+ and erased the following line of code. It now only matches spaces and tabs

The sampler/texsize declaration removal moved into the static MilkdropShader::RemoveSamplerAndTexSizeDeclarations(), so it can be tested without an OpenGL context.

Tests

  • New HLSLMilkdropCompatTest.cpp with 9 tests. 8 fail without this change; the 9th checks that sample still works as an interpolation modifier. libprojectM suite: 173/173.
  • Ran all 19,210 warp/comp shaders from the official preset packs and the presets_tryptonaut collection through preprocessing, hlslparser and GLSL generation, comparing master and this branch. I then compiled every generated fragment shader with the OpenGL 3.3 core driver (NVIDIA RTX A6000, driver 596.72):
master → this PR Shaders
Compiles → compiles 19,030
Parse or GLSL generation failure → compiles 51
Compiles → fails 0
GPU compile failure → GPU compile failure (unrelated, e.g. array index out of bounds) 67
Parse failure → parse failure 62
  • 55 of the 62 remaining parse failures are the sampler_state regression fixed in Remove sampler_state blocks from the shader code again #1061. With both PRs combined, 106 shaders that fail on master compile.
  • 72 shaders that already compiled get different GLSL output:
    • 69 keep a declaration of an unused variable that the old regex erased.
    • 3 have an unused variable named sample renamed.

The 7 shaders that still fail have unbalanced braces in the preset itself, or declare samplers through #define macros. Rendering wasn't checked visually.

Retested on current master (2026-11-12)

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant