Repository navigation
Return int from the NaN-safe multiplication of two ints - #1067
Open
Coastrnaut wants to merge 1 commit into
Open
Coastrnaut wants to merge 1 commit into
Coastrnaut wants to merge 1 commit into
Conversation
With Flag_AlternateNanPropagation, which projectM uses for all preset shaders, the GLSL generator replaces every multiplication with a helper function. The int * int overload returned a float, but in HLSL the product of two ints is an int, and the generated code uses it as one, e.g. "mult0(a, b) + 1" or "int c = mult0(a, b)". Desktop GLSL converts implicitly, but GLSL ES has no implicit int/float conversions, so these shaders failed to compile on OpenGL ES. Make the int overload return an int, and add the missing ivec overloads. Integers have no NaN, so a plain multiplication gives the same result. Related to projectM-visualizer#998
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.
Related to #998
With
Flag_AlternateNanPropagation, which projectM uses for all preset shaders, the GLSL generator replaces every multiplication with amult0()helper. Theint * intoverload returned afloat, but in HLSL the product of two ints is an int, and the generated code uses it as one, e.g.mult0(a, b) + 1,mult0(a, b) / 2orint mask = mult0(a, b). Desktop GLSL converts int to float implicitly, so this mostly went unnoticed there, but GLSL ES has no implicit conversions, and these shaders fail to compile on OpenGL ES:This makes the int overload return an int and adds the missing
ivec2/ivec3/ivec4overloads. Integers have no NaN, so a plain multiplication gives the same result. The float, vector and matrix overloads are unchanged.How I found it
Master accepts GLES 3.0 contexts since e98fca8, so I compiled all 14,536 presets from cream-of-the-crop, en-d, milkdrop-original and projectm-classic with a GLES build in an OpenGL ES context (NVIDIA, via
WGL_EXT_create_context_es2_profile) and compared with desktop GL 3.3. All of projectM's shaders use#version 300 es, so the driver applies GLSL ES 3.00 rules. 10 presets failed only on GLES:sampleas an identifier, which GLSL ES reserves. Fix HLSL constructs in Milkdrop presets that failed to transpile #1062 renames it.martin - stratospheric turbulences,EVET - Doom Vortex,EVET - Spiracology 2.martin - funky illusionsfailed on both desktop and GLES because of the int ← float assignment.Testing
sampleones that Fix HLSL constructs in Milkdrop presets that failed to transpile #1062 fixes; everything else that fails on GLES fails on desktop as well.martin - funky illusionsnow compiles. Rendered one by one, the frames are identical to master except for two presets (martin - gate to moria,martin - mucus cervix) whose generated shaders only differ in the unused helper definitions and which also render differently between runs of master itself.HLSLAlternateMultiplyTestwith 3 tests; 2 of them fail on master. All unit tests pass.The NVIDIA driver always creates a GLES 3.2 context, so this covers the GLSL ES 3.00 language rules, not the 3.0 API limits mentioned in #998 (e.g. rendering to the
GL_RG16Fmotion vector texture).Retested on current master (2026-11-12)
martin - funky illusions, which now compiles. All frames before it are identical to master; later ones differ because each preset continues from the state the previous one left behind.