[Mesa-dev] [PATCH 12/34] mesa: Refactor copying of linked program data.

Paul Berry stereotype441 at gmail.com
Sun Jul 28 23:03:38 PDT 2013


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.
---
 src/mesa/drivers/dri/i965/brw_shader.cpp |  6 ++----
 src/mesa/main/mtypes.h                   |  8 ++++++--
 src/mesa/main/shaderapi.c                | 21 +++++++++++++++++++++
 src/mesa/main/shaderapi.h                |  5 +++++
 src/mesa/program/ir_to_mesa.cpp          |  5 +----
 5 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp
index 418ea9b..9a2e8be 100644
--- a/src/mesa/drivers/dri/i965/brw_shader.cpp
+++ b/src/mesa/drivers/dri/i965/brw_shader.cpp
@@ -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;
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 2725eef..f2f0280 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2328,9 +2328,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;
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index e8303c8..38caa58 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -1833,3 +1833,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;
+   }
+}
diff --git a/src/mesa/main/shaderapi.h b/src/mesa/main/shaderapi.h
index 1cd4ffc..fe58e7d 100644
--- a/src/mesa/main/shaderapi.h
+++ b/src/mesa/main/shaderapi.h
@@ -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
 }
diff --git a/src/mesa/program/ir_to_mesa.cpp b/src/mesa/program/ir_to_mesa.cpp
index 914aca4..86a7bb8 100644
--- a/src/mesa/program/ir_to_mesa.cpp
+++ b/src/mesa/program/ir_to_mesa.cpp
@@ -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);
-- 
1.8.3.4



More information about the mesa-dev mailing list