mesa: Refactor copying of linked program data.
authorPaul Berry <stereotype441@gmail.com>
Sat, 23 Mar 2013 17:51:53 +0000 (10:51 -0700)
committerPaul Berry <stereotype441@gmail.com>
Fri, 2 Aug 2013 03:21:26 +0000 (20:21 -0700)
This patch creates a single function to copy the the UsesClipDistance
flag from gl_shader_program.Vert to gl_vertex_program.  Previously
this logic was duplicated in the i965-specific function
brw_link_shader() and the core mesa function _mesa_ir_link_shader().

This logic will have to be expanded to support geometry shaders, and I
don't want to have to update it in two separate places.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_shader.cpp
src/mesa/main/mtypes.h
src/mesa/main/shaderapi.c
src/mesa/main/shaderapi.h
src/mesa/program/ir_to_mesa.cpp

index 418ea9b033158e8bed0676a3cd4c8a2d53419fd0..9a2e8bebfd0ad51cff5baecc7f2c24fd7382341e 100644 (file)
@@ -29,6 +29,7 @@ extern "C" {
 #include "brw_fs.h"
 #include "glsl/ir_optimization.h"
 #include "glsl/glsl_parser_extras.h"
+#include "main/shaderapi.h"
 
 struct gl_shader *
 brw_new_shader(struct gl_context *ctx, GLuint name, GLuint type)
@@ -127,10 +128,7 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
        return false;
       prog->Parameters = _mesa_new_parameter_list();
 
-      if (stage == 0) {
-        struct gl_vertex_program *vp = (struct gl_vertex_program *) prog;
-        vp->UsesClipDistance = shProg->Vert.UsesClipDistance;
-      }
+      _mesa_copy_linked_program_data((gl_shader_type) stage, shProg, prog);
 
       void *mem_ctx = ralloc_context(NULL);
       bool progress;
index c78fe855f6c75fe5f0534e3c698b19be61f15489..c166645aa0fc5ddcf98dd9a93048fe7dbd2d3f19 100644 (file)
@@ -2329,9 +2329,13 @@ struct gl_shader_program
       GLenum OutputType; /**< GL_POINTS, GL_LINE_STRIP or GL_TRIANGLE_STRIP */
    } Geom;
 
-   /** Vertex shader state - copied into gl_vertex_program at link time */
+   /** Vertex shader state */
    struct {
-      GLboolean UsesClipDistance; /**< True if gl_ClipDistance is written to. */
+      /**
+       * True if gl_ClipDistance is written to.  Copied into gl_vertex_program
+       * by _mesa_copy_linked_program_data().
+       */
+      GLboolean UsesClipDistance;
       GLuint ClipDistanceArraySize; /**< Size of the gl_ClipDistance array, or
                                          0 if not present. */
    } Vert;
index 3f9402c598cb42cb807abcb98f698a63f1051ed9..8a0909be13f51fe1211bead26052f6e07f699492 100644 (file)
@@ -1842,3 +1842,24 @@ _mesa_CreateShaderProgramEXT(GLenum type, const GLchar *string)
 
    return program;
 }
+
+
+/**
+ * Copy program-specific data generated by linking from the gl_shader_program
+ * object to a specific gl_program object.
+ */
+void
+_mesa_copy_linked_program_data(gl_shader_type type,
+                               const struct gl_shader_program *src,
+                               struct gl_program *dst)
+{
+   switch (type) {
+   case MESA_SHADER_VERTEX: {
+      struct gl_vertex_program *dst_vp = (struct gl_vertex_program *) dst;
+      dst_vp->UsesClipDistance = src->Vert.UsesClipDistance;
+   }
+      break;
+   default:
+      break;
+   }
+}
index 1cd4ffcea0321c5761d131857d0e3996bb9e13f3..fe58e7de9bde435b26638d5c0af3f5034e60d1e3 100644 (file)
@@ -210,6 +210,11 @@ _mesa_ActiveProgramEXT(GLuint program);
 extern GLuint GLAPIENTRY
 _mesa_CreateShaderProgramEXT(GLenum type, const GLchar *string);
 
+extern void
+_mesa_copy_linked_program_data(gl_shader_type type,
+                               const struct gl_shader_program *src,
+                               struct gl_program *dst);
+
 
 #ifdef __cplusplus
 }
index ae78aca19d387ea788270a6ed3ee34b92a82abcf..f612f41baff0dd6be897ac6772ce6aadf5cee616 100644 (file)
@@ -3087,10 +3087,7 @@ _mesa_ir_link_shader(struct gl_context *ctx, struct gl_shader_program *prog)
       linked_prog = get_mesa_program(ctx, prog, prog->_LinkedShaders[i]);
 
       if (linked_prog) {
-        if (i == MESA_SHADER_VERTEX) {
-            ((struct gl_vertex_program *)linked_prog)->UsesClipDistance
-               = prog->Vert.UsesClipDistance;
-        }
+         _mesa_copy_linked_program_data((gl_shader_type) i, prog, linked_prog);
 
         _mesa_reference_program(ctx, &prog->_LinkedShaders[i]->Program,
                                 linked_prog);