Mesa (master): linker: Use app-specified fragment data location during linking

Ian Romanick idr at kemper.freedesktop.org
Tue Nov 8 19:11:07 UTC 2011


Module: Mesa
Branch: master
Commit: b12b5d9ab5c0153c93ca5ad9cd93cb36e41be4eb
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b12b5d9ab5c0153c93ca5ad9cd93cb36e41be4eb

Author: Ian Romanick <ian.d.romanick at intel.com>
Date:   Fri Nov  4 16:08:52 2011 -0700

linker: Use app-specified fragment data location during linking

Fixes piglit's bindfragdata-link-error.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Reviewed-by: Paul Berry <stereotype441 at gmail.com>
Reviewed-by: Eric Anholt <eric at anholt.net>

---

 src/glsl/linker.cpp            |   16 +++++++++-------
 src/mesa/main/mtypes.h         |    9 +++++++++
 src/mesa/main/shader_query.cpp |    2 +-
 src/mesa/main/shaderobj.c      |    6 ++++++
 4 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp
index d2f68cb..0306b7a 100644
--- a/src/glsl/linker.cpp
+++ b/src/glsl/linker.cpp
@@ -1139,12 +1139,6 @@ find_available_slots(unsigned used_mask, unsigned needed_count)
  * \return
  * If locations are successfully assigned, true is returned.  Otherwise an
  * error is emitted to the shader link log and false is returned.
- *
- * \bug
- * Locations set via \c glBindFragDataLocation are not currently supported.
- * Only locations assigned automatically by the linker, explicitly set by a
- * layout qualifier, or explicitly set by a built-in variable (e.g., \c
- * gl_FragColor) are supported for fragment shaders.
  */
 bool
 assign_attribute_or_color_locations(gl_shader_program *prog,
@@ -1168,7 +1162,8 @@ assign_attribute_or_color_locations(gl_shader_program *prog,
     * 1. Invalidate the location assignments for all vertex shader inputs.
     *
     * 2. Assign locations for inputs that have user-defined (via
-    *    glBindVertexAttribLocation) locations.
+    *    glBindVertexAttribLocation) locations and outputs that have
+    *    user-defined locations (via glBindFragDataLocation).
     *
     * 3. Sort the attributes without assigned locations by number of slots
     *    required in decreasing order.  Fragmentation caused by attribute
@@ -1229,6 +1224,13 @@ assign_attribute_or_color_locations(gl_shader_program *prog,
 	    assert(binding >= VERT_ATTRIB_GENERIC0);
 	    var->location = binding;
 	 }
+      } else if (target_index == MESA_SHADER_FRAGMENT) {
+	 unsigned binding;
+
+	 if (prog->FragDataBindings->get(binding, var->name)) {
+	    assert(binding >= FRAG_RESULT_DATA0);
+	    var->location = binding;
+	 }
       }
 
       /* If the variable is not a built-in and has a location statically
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 5f2456c..ae6a33e 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -2185,6 +2185,15 @@ struct gl_shader_program
     */
    struct string_to_uint_map *AttributeBindings;
 
+   /**
+    * User-defined fragment data bindings
+    *
+    * These are set via \c glBindFragDataLocation and are used to direct the
+    * GLSL linker.  These are \b not the values used in the compiled shader,
+    * and they are \b not the values returned by \c glGetFragDataLocation.
+    */
+   struct string_to_uint_map *FragDataBindings;
+
    /** Transform feedback varyings */
    struct {
       GLenum BufferMode;
diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
index 0694b48..23667a1 100644
--- a/src/mesa/main/shader_query.cpp
+++ b/src/mesa/main/shader_query.cpp
@@ -267,7 +267,7 @@ _mesa_BindFragDataLocation(GLuint program, GLuint colorNumber,
     * FRAG_RESULT_DATA0 because that's how the linker differentiates
     * between built-in attributes and user-defined attributes.
     */
-
+   shProg->FragDataBindings->put(colorNumber + FRAG_RESULT_DATA0, name);
 
    /*
     * Note that this binding won't go into effect until
diff --git a/src/mesa/main/shaderobj.c b/src/mesa/main/shaderobj.c
index 9abf606..454007f 100644
--- a/src/mesa/main/shaderobj.c
+++ b/src/mesa/main/shaderobj.c
@@ -240,6 +240,7 @@ _mesa_init_shader_program(struct gl_context *ctx, struct gl_shader_program *prog
    prog->RefCount = 1;
 
    prog->AttributeBindings = string_to_uint_map_ctor();
+   prog->FragDataBindings = string_to_uint_map_ctor();
 
 #if FEATURE_ARB_geometry_shader4
    prog->Geom.VerticesOut = 0;
@@ -316,6 +317,11 @@ _mesa_free_shader_program_data(struct gl_context *ctx,
       shProg->AttributeBindings = NULL;
    }
 
+   if (shProg->FragDataBindings) {
+      string_to_uint_map_dtor(shProg->FragDataBindings);
+      shProg->FragDataBindings = NULL;
+   }
+
    /* detach shaders */
    for (i = 0; i < shProg->NumShaders; i++) {
       _mesa_reference_shader(ctx, &shProg->Shaders[i], NULL);




More information about the mesa-commit mailing list