glsl-optimizer icon indicating copy to clipboard operation
glsl-optimizer copied to clipboard

Does not give proper GLSL code

Open SuicSoft opened this issue 9 years ago • 3 comments

I am trying to optimize this vertex shader

uniform mat4 ModelViewMatrix;
uniform vec3 Position;
uniform vec2 Size;

#if __VERSION__ >= 330
layout(location = 0) in vec2 Corner;
layout(location = 3) in vec2 Texcoord;
#else
in vec2 Corner;
in vec2 Texcoord;
#endif

out vec2 uv;

void main(void)
{
    uv = Texcoord;
    vec4 Center = ModelViewMatrix * vec4(Position, 1.);
    gl_Position = ProjectionMatrix * (Center + vec4(Size * Corner, 0., 0.));
}

But when I click optimize I get

򀨑R

SuicSoft avatar Aug 26 '16 03:08 SuicSoft

Seeing similar behavior sometimes.

I had to call it with glVersion = 2 to keep this from happening on a shader using gl_PointCoord - else I got this weird output instead of an error message, for instance.

@zz85 It might be a good idea to pull up the code.

To have an easy life and be on the safe side, just revert my patch and compile with -fno-strict-aliasing option for now. I got some notifications on the Mesa issue which I filed back then, so an upstream fix will float around eventually.

I recently revived the node script from glslunit to bake GLSL to source files and added optimization based on this tool (work in progress in the glslprep.js repository). This way, it's a single & easy to invoke build step without native code to be packaged. It takes a template for the wrapper source code, so should adapt to pretty much anything.

tschw avatar Aug 29 '16 18:08 tschw

@tschw How can I do that ?

SuicSoft avatar Aug 30 '16 01:08 SuicSoft

@SuicSoft https://github.com/tschw/glslprep.js/blob/gh-pages/src/glslunit/compiler/preprocessor.js#L238-L265

tschw avatar Aug 30 '16 20:08 tschw