[Mesa-dev] [PATCH 2/2] glsl: error out on ES 3.1 if VS or FS present but not both

Ilia Mirkin imirkin at alum.mit.edu
Thu Sep 3 11:54:18 PDT 2015


On Thu, Sep 3, 2015 at 7:58 AM, Tapani Pälli <tapani.palli at intel.com> wrote:
> Signed-off-by: Tapani Pälli <tapani.palli at intel.com>
> ---
>  src/glsl/linker.cpp | 31 +++++++++++++++++++++++++++----
>  1 file changed, 27 insertions(+), 4 deletions(-)
>
> diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
> index bc76af6..2be5660 100644
> --- a/src/glsl/linker.cpp
> +++ b/src/glsl/linker.cpp
> @@ -3890,10 +3890,33 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
>      * behavior specified in GLSL specification.
>      */
>     if (!prog->SeparateShader && ctx->API == API_OPENGLES2) {
> -      if (prog->_LinkedShaders[MESA_SHADER_VERTEX] == NULL) {
> -        linker_error(prog, "program lacks a vertex shader\n");
> -      } else if (prog->_LinkedShaders[MESA_SHADER_FRAGMENT] == NULL) {
> -        linker_error(prog, "program lacks a fragment shader\n");
> +      /* With ES < 3.1 one needs to have always vertex + fragment shader. */
> +      if (ctx->Version < 31) {
> +         if (prog->_LinkedShaders[MESA_SHADER_VERTEX] == NULL) {
> +           linker_error(prog, "program lacks a vertex shader\n");
> +         } else if (prog->_LinkedShaders[MESA_SHADER_FRAGMENT] == NULL) {
> +           linker_error(prog, "program lacks a fragment shader\n");
> +         }
> +      } else {
> +         /* From OpenGL ES 3.1 specification (7.3 Program Objects):
> +          *     "Linking can fail for a variety of reasons as specified in the
> +          *     OpenGL ES Shading Language Specification, as well as any of the
> +          *     following reasons:
> +          *
> +          *     ...
> +          *
> +          *     * program contains objects to form either a vertex shader or
> +          *       fragment shader, and program is not separable, and does not
> +          *       contain objects to form both a vertex shader and fragment
> +          *       shader."
> +          */
> +         if ((prog->_LinkedShaders[MESA_SHADER_VERTEX] ||
> +             prog->_LinkedShaders[MESA_SHADER_FRAGMENT]) &&

indentation appears to be off-by-1 here and below (prog's should line
up). Otherwise this is

Reviewed-by: Ilia Mirkin <imirkin at alum.mit.edu>

Another quick way to do this is, btw,

!!vertex ^ !!fragment

Which will be 1 iff only one of them is set.

> +             (!prog->_LinkedShaders[MESA_SHADER_VERTEX] ||
> +             !prog->_LinkedShaders[MESA_SHADER_FRAGMENT])) {
> +            linker_error(prog, "Program needs to contain both vertex and fragment "
> +                         "shaders.\n");
> +         }
>        }
>     }
>
> --
> 2.4.3
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list