diff --git a/src/compiler/glsl/gl_nir_linker.c b/src/compiler/glsl/gl_nir_linker.c index ad6c185efc9..0066a878210 100644 --- a/src/compiler/glsl/gl_nir_linker.c +++ b/src/compiler/glsl/gl_nir_linker.c @@ -993,6 +993,41 @@ gl_nir_link_glsl(const struct gl_constants *consts, gl_nir_link_assign_atomic_counter_resources(consts, prog); gl_nir_link_check_atomic_counter_resources(consts, prog); + /* OpenGL ES < 3.1 requires that a vertex shader and a fragment shader both + * be present in a linked program. GL_ARB_ES2_compatibility doesn't say + * anything about shader linking when one of the shaders (vertex or + * fragment shader) is absent. So, the extension shouldn't change the + * behavior specified in GLSL specification. + * + * 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." + * + * However, the only scenario in 3.1+ where we don't require them both is + * when we have a compute shader. For example: + * + * - No shaders is a link error. + * - Geom or Tess without a Vertex shader is a link error which means we + * always require a Vertex shader and hence a Fragment shader. + * - Finally a Compute shader linked with any other stage is a link error. + */ + if (!prog->SeparateShader && _mesa_is_api_gles2(api) && + !prog->_LinkedShaders[MESA_SHADER_COMPUTE]) { + 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"); + } + } + if (prog->data->LinkStatus == LINKING_FAILURE) return false; diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp index 083ef4b82dc..c1807d4f6af 100644 --- a/src/compiler/glsl/linker.cpp +++ b/src/compiler/glsl/linker.cpp @@ -3899,41 +3899,6 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog) if(!link_varyings(consts, prog, mem_ctx)) goto done; - /* OpenGL ES < 3.1 requires that a vertex shader and a fragment shader both - * be present in a linked program. GL_ARB_ES2_compatibility doesn't say - * anything about shader linking when one of the shaders (vertex or - * fragment shader) is absent. So, the extension shouldn't change the - * behavior specified in GLSL specification. - * - * 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." - * - * However, the only scenario in 3.1+ where we don't require them both is - * when we have a compute shader. For example: - * - * - No shaders is a link error. - * - Geom or Tess without a Vertex shader is a link error which means we - * always require a Vertex shader and hence a Fragment shader. - * - Finally a Compute shader linked with any other stage is a link error. - */ - if (!prog->SeparateShader && _mesa_is_gles2(ctx) && - num_shaders[MESA_SHADER_COMPUTE] == 0) { - 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"); - } - } - done: for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { free(shader_list[i]);