Repository navigation
Fix shaders that declare or name samplers through macros - #1072
Open
Coastrnaut wants to merge 2 commits into
Open
Coastrnaut wants to merge 2 commits into
Coastrnaut wants to merge 2 commits into
Conversation
The HLSL preprocessor built macro values from the trimmed tokens, so "#define smp sampler sampler_manyfish;" got the value "samplersampler_manyfish;", and it put every value in parentheses when substituting it, which is only valid for expressions. A macro expanding to a declaration, as used in "Fed + Geiss - Color Pox Remix", became "(samplersampler_manyfish;)", and the shader failed to parse. Keep the whitespace between the tokens of a value, and insert values containing a semicolon, i.e. statements and declarations, without parentheses. Expression macros are still wrapped as before.
Presets can name a sampler through a macro, e.g. "#define base01 main", "sampler base01;" and "tex2D(base01, uv)", which the HLSL preprocessor turns into "sampler_fw_main". projectM only searched the original code for "sampler_" names, so it didn't declare this sampler and the shader failed to parse. Search the macro-expanded code as well.
This was referenced Nov 13, 2026
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.
Shaders that name samplers through macros failed to parse:
Fed + Geiss - Color Pox Remix). hlslparser built macro values from the trimmed tokens, so#define smp sampler sampler_manyfish;got the valuesamplersampler_manyfish;, and it put every value in parentheses when substituting it, which is only valid for expressions. The expansion became(samplersampler_manyfish;). Values now keep the whitespace between their tokens (in all three places where they're built), and values containing a semicolon, i.e. statements and declarations, are inserted without parentheses. Expression macros are still wrapped as before.[dylan] cube in a room …, 2 presets).#define base01 main,sampler base01;andtex2D(base01, uv)turn intosampler_fw_mainin the preprocessor, but projectM only searched the original code forsampler_names, so it didn't declare it.GetReferencedSamplers()now searches the macro-expanded code as well.Results
shifter + flexi - liquid circuitry …ones: their composite shader has an extra}left over from a commented-out loop, so it doesn't compile in Milkdrop either.#define, shader compile/link results and rendered frames are identical to master.HLSLPreprocessorTest. 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 and without the preset folders as texture search path, rendered frames with fixed audio and frame times, and recorded shader compile/link results, failed loads, logged shader fallbacks 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)