[Mesa-dev] [PATCH V2 1/2] glsl: don't attempt to link empty program

Timothy Arceri timothy.arceri at collabora.com
Mon Jan 25 14:55:47 PST 2016


Previously an empty program would go through the entire
link_shaders() function and we would have to be careful
not to cause a segfault.

In core profile also now set link_status to false by
generating an error, it was previously set to true.

>From Section 7.3 (PROGRAM OBJECTS) of the OpenGL 4.5 spec:

   "Linking can fail for a variety of reasons as specified in the
   OpenGL Shading Language Specification, as well as any of the
   following reasons:

    - No shader objects are attached to program."

V2: Only generate an error in core profile and add spec quote (Ian)

Cc: Ian Romanick <idr at freedesktop.org>
---
 src/glsl/linker.cpp | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index 6657777..b3a7fad 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -4105,14 +4105,34 @@ disable_varying_optimizations_for_sso(struct gl_shader_program *prog)
 void
 link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
 {
+   prog->Validated = false;
+   prog->_Used = false;
+
+   /* Section 7.3 (Program Objects) of the OpenGL 4.5 Core Profile spec says:
+    *
+    *     "Linking can fail for a variety of reasons as specified in the
+    *     OpenGL Shading Language Specification, as well as any of the
+    *     following reasons:
+    *
+    *     - No shader objects are attached to program."
+    *
+    * The Compatibility Profile specification does not list the error.  In
+    * Compatibility Profile missing shader stages are replaced by
+    * fixed-function.  This applies to the case where all stages are
+    * missing.
+    */
+   if (prog->NumShaders == 0) {
+      if (ctx->API == API_OPENGL_CORE)
+         linker_error(prog, "no shaders attached to the program\n");
+      return;
+   }
+
    tfeedback_decl *tfeedback_decls = NULL;
    unsigned num_tfeedback_decls = prog->TransformFeedback.NumVarying;
 
    void *mem_ctx = ralloc_context(NULL); // temporary linker context
 
    prog->LinkStatus = true; /* All error paths will set this to false */
-   prog->Validated = false;
-   prog->_Used = false;
 
    prog->ARB_fragment_coord_conventions_enable = false;
 
-- 
2.4.3



More information about the mesa-dev mailing list