[SOLVED] Shader fails to validate on MacOS with no error log

Started by Danjb, January 24, 2020, 09:59:01

Previous topic - Next topic

Danjb

Hi,

I have a very simple vertex / fragment shader:

#version 330

uniform mat4 view_proj_matrix;

layout(location = 0) in vec2 in_vertex;
layout(location = 1) in vec2 in_tex_coord;
layout(location = 2) in vec4 in_colour;

out Data {
    vec4 colour;
    vec2 tex_coord;
} DataOut;

void main(void) {
    gl_Position = view_proj_matrix * vec4(in_vertex, 0, 1);
    
    DataOut.colour = in_colour;
    DataOut.tex_coord = in_tex_coord;
}


#version 330

uniform sampler2D tex;

uniform bool use_override_colour;
uniform vec3 override_colour;

in Data {
    vec4 colour;
    vec2 tex_coord;
} DataIn;

out vec4 frag_colour;

void main(void) {
    vec4 tex_colour = texture(tex, DataIn.tex_coord);
    if (use_override_colour) {
        frag_colour = vec4(override_colour.r, override_colour.g, override_colour.b, tex_colour.a);
    } else {
        frag_colour = DataIn.colour * tex_colour;
    }
}


On Windows all is fine, but on MacOS I get an error after validating the program, with an empty error log, e.g. "Error validating shader program: ".

        public Builder linkAndValidate() throws ShaderException {

            glLinkProgram(programId);
            int success = glGetProgrami(programId, GL_LINK_STATUS);
            if (success != GL_TRUE) {
                glDeleteProgram(programId);
                throw new ShaderException("Error linking shader program: "
                        + glGetProgramInfoLog(programId));
            }

            // Now that we have our program, we can safely delete the shader
            // objects
            glDeleteShader(vsId);
            glDeleteShader(fsId);

            glValidateProgram(programId);
            success = glGetProgrami(programId, GL_VALIDATE_STATUS);
            if (success != GL_TRUE) {
                glDeleteProgram(programId);
                throw new ShaderException("Error validating shader program: "
                        + glGetProgramInfoLog(programId));
            }

            return this;
        }


I am not sure how to debug this further given I have no information about why it failed. Does anyone have any suggestions?

Thanks,
Dan

KaiHH

Try using "#version 330 core" as the GLSL version in both shaders. Mac OS only supports the core profile and not the compatibility profile.

Danjb

Thanks for the reply, but I just tried that and there was no improvement. Any other ideas?

KaiHH

Well, according to the specification of glValidateProgram:
Quote
This function mimics the validation operation that OpenGL implementations must perform when rendering commands are issued while programmable shaders are part of current state.
So, the validation being performed is essentially the same as the one when a glDraw... call is being invoked. So, in your case, ensure that at the point where you call glValidateProgram you could also have made a draw call with the current state of the pipeline, and that draw call would have succeeded. This in particular means:
- the texture unit of the sampler in your fragment shader is bound to a valid texture object
- a valid Vertex Array Object is currently bound
- all of the three vertex attributes are enabled and bound to a vertex source (such as a buffer object)

Danjb

Quote from: KaiHH on January 25, 2020, 00:06:23
Well, according to the specification of glValidateProgram:
Quote
This function mimics the validation operation that OpenGL implementations must perform when rendering commands are issued while programmable shaders are part of current state.
So, the validation being performed is essentially the same as the one when a glDraw... call is being invoked. So, in your case, ensure that at the point where you call glValidateProgram you could also have made a draw call with the current state of the pipeline, and that draw call would have succeeded. This in particular means:
- the texture unit of the sampler in your fragment shader is bound to a valid texture object
- a valid Vertex Array Object is currently bound
- all of the three vertex attributes are enabled and bound to a vertex source (such as a buffer object)

Thanks a lot, that sounds like the problem!

I have just found a very similar answer here:
https://stackoverflow.com/a/27629868/1624459

I was validating the program immediately after compiling, which now I understand is not the correct thing to do.