Skip to content

Remove sampler_state blocks from the shader code again - #1061

Open
Coastrnaut wants to merge 1 commit into
projectM-visualizer:masterfrom
Coastrnaut:fix/sampler-state-removal
Open

Coastrnaut wants to merge 1 commit into
projectM-visualizer:masterfrom
Coastrnaut:fix/sampler-state-removal

Conversation

@Coastrnaut

@Coastrnaut Coastrnaut commented Nov 8, 2026 •

Copy link
Copy Markdown

Problem

Since 83292ed (#958), MilkdropShader::PreprocessPresetShader() removes sampler_state blocks only from the comment-stripped copy used for searching, not from the actual program. This has two effects:

  • The blocks stay in the shader, which then fails to parse with expected ';' near 'AddressU'.
  • The shader_body position found in the shortened copy no longer matches the program, so the entry point is inserted in the wrong place.

No release contains this regression yet.

Change

  • The block is removed from the program and the stripped copy is recreated, so positions stay in sync.
  • A range is only removed if it actually contains the sampler_state, so a malformed declaration can't remove unrelated code.
  • PreprocessPresetShader() is now a public static member that takes the shader type, so it can be unit tested without an OpenGL context. The existing SamplerStateRemoval tests in MilkdropShaderCommentParsingTest.cpp test a copy of the logic, which is why they didn't catch this.

Tests

  • New MilkdropShaderPreprocessTest.cpp with 4 tests that call the real implementation. Two of them fail on master. libprojectM suite: 168/168.
  • Ran every warp and comp shader in the 4 official preset repos (19,210 shaders) through master's and this branch's preprocessing, then through hlslparser's preprocessing, parsing and GLSL generation:
master → this PR Shaders Generated GLSL
OK → OK 19,078 identical
parse fail → OK 55 now generated (all use sampler_state)
parse fail → parse fail 69 unchanged (none use sampler_state)
GLSL generation fail → fail 8 unchanged

The GLSL wasn't compiled on a GPU and rendering wasn't checked.

Retested on current master (2026-11-12)

Since 83292ed (projectM-visualizer#958), PreprocessPresetShader() removed sampler_state
blocks only from the comment-stripped copy used for searching, not from
the actual program. The blocks stayed in the shader, which then failed
to parse with "expected ';' near 'AddressU'", and the shader_body
position found in the shortened copy no longer matched the program, so
the entry point was inserted in the wrong place.

The block is now removed from the program and the stripped copy is
recreated, keeping positions in sync. A range is only removed if it
actually contains the sampler_state, so malformed declarations can't
remove unrelated code.

PreprocessPresetShader() is now a static member taking the shader type,
so it can be unit tested without an OpenGL context. The new tests call
the actual implementation; the existing SamplerStateRemoval tests use a
copy of the logic, which is why they didn't catch this.

Of 19,210 warp/comp shaders in the official preset packs, 55 shaders
(all in cream-of-the-crop) parse again with this change. The generated
GLSL of all other shaders is unchanged.
Coastrnaut added a commit to Coastrnaut/projectm that referenced this pull request Nov 12, 2026
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