Mesa (master): draw: fixup draw_find_shader_output

Zack Rusin zack at kemper.freedesktop.org
Wed May 29 22:08:54 UTC 2013


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

Author: Zack Rusin <zackr at vmware.com>
Date:   Fri May 24 16:39:59 2013 -0400

draw: fixup draw_find_shader_output

draw_find_shader_output like most of the code in draw used to
depend on position always being at output slot 0. which meant
that any other attribute being at 0 could signify an error.
unfortunately position can be at any of the output slots, thus
other attributes can occupy slot 0 and we need to mark the ones
which were not found by something else. This commit changes
draw_find_shader_output so that it returns -1 if it can't
find the given attribute and adjust the code that depended
on it returning >0 whenever it correctly found an attrib.

Signed-off-by: Zack Rusin <zackr at vmware.com>
Reviewed-by: José Fonseca<jfonseca at vmware.com>
Reviewed-by: Brian Paul <brianp at vmware.com>
Reviewed-by: Roland Scheidegger <sroland at vmware.com>

---

 src/gallium/auxiliary/draw/draw_context.c       |   11 ++++++-----
 src/gallium/auxiliary/draw/draw_vertex.h        |    2 +-
 src/gallium/drivers/llvmpipe/lp_state_derived.c |    8 ++++----
 src/gallium/drivers/softpipe/sp_state_derived.c |    2 +-
 4 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/src/gallium/auxiliary/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c
index 4250f10..63ccf38 100644
--- a/src/gallium/auxiliary/draw/draw_context.c
+++ b/src/gallium/auxiliary/draw/draw_context.c
@@ -493,7 +493,7 @@ draw_alloc_extra_vertex_attrib(struct draw_context *draw,
    uint n;
 
    slot = draw_find_shader_output(draw, semantic_name, semantic_index);
-   if (slot > 0) {
+   if (slot >= 0) {
       return slot;
    }
 
@@ -549,9 +549,10 @@ draw_get_shader_info(const struct draw_context *draw)
  * attributes (such as texcoords for AA lines).  The driver can call this
  * function to find those attributes.
  *
- * Zero is returned if the attribute is not found since this is
- * a don't care / undefined situtation.  Returning -1 would be a bit more
- * work for the drivers.
+ * -1 is returned if the attribute is not found since this is
+ * an undefined situtation. Note, that zero is valid and can
+ * be used by any of the attributes, because position is not
+ * required to be attribute 0 or even at all present.
  */
 int
 draw_find_shader_output(const struct draw_context *draw,
@@ -574,7 +575,7 @@ draw_find_shader_output(const struct draw_context *draw,
       }
    }
 
-   return 0;
+   return -1;
 }
 
 
diff --git a/src/gallium/auxiliary/draw/draw_vertex.h b/src/gallium/auxiliary/draw/draw_vertex.h
index c87c3d8..9e10ada 100644
--- a/src/gallium/auxiliary/draw/draw_vertex.h
+++ b/src/gallium/auxiliary/draw/draw_vertex.h
@@ -125,7 +125,7 @@ static INLINE uint
 draw_emit_vertex_attr(struct vertex_info *vinfo,
                       enum attrib_emit emit, 
                       enum interp_mode interp, /* only used by softpipe??? */
-                      uint src_index)
+                      int src_index)
 {
    const uint n = vinfo->num_attribs;
    assert(n < Elements(vinfo->attrib));
diff --git a/src/gallium/drivers/llvmpipe/lp_state_derived.c b/src/gallium/drivers/llvmpipe/lp_state_derived.c
index 9c5e847..ea24ffc 100644
--- a/src/gallium/drivers/llvmpipe/lp_state_derived.c
+++ b/src/gallium/drivers/llvmpipe/lp_state_derived.c
@@ -50,7 +50,7 @@ compute_vertex_info(struct llvmpipe_context *llvmpipe)
 {
    const struct lp_fragment_shader *lpfs = llvmpipe->fs;
    struct vertex_info *vinfo = &llvmpipe->vertex_info;
-   unsigned vs_index;
+   int vs_index;
    uint i;
 
    llvmpipe->color_slot[0] = -1;
@@ -99,7 +99,7 @@ compute_vertex_info(struct llvmpipe_context *llvmpipe)
       vs_index = draw_find_shader_output(llvmpipe->draw,
                                          TGSI_SEMANTIC_BCOLOR, i);
 
-      if (vs_index > 0) {
+      if (vs_index >= 0) {
          llvmpipe->bcolor_slot[i] = (int)vinfo->num_attribs;
          draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, vs_index);
       }
@@ -111,7 +111,7 @@ compute_vertex_info(struct llvmpipe_context *llvmpipe)
    vs_index = draw_find_shader_output(llvmpipe->draw,
                                       TGSI_SEMANTIC_PSIZE, 0);
 
-   if (vs_index > 0) {
+   if (vs_index >= 0) {
       llvmpipe->psize_slot = vinfo->num_attribs;
       draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_CONSTANT, vs_index);
    }
@@ -120,7 +120,7 @@ compute_vertex_info(struct llvmpipe_context *llvmpipe)
    vs_index = draw_find_shader_output(llvmpipe->draw,
                                       TGSI_SEMANTIC_VIEWPORT_INDEX,
                                       0);
-   if (vs_index > 0) {
+   if (vs_index >= 0) {
       llvmpipe->viewport_index_slot = vinfo->num_attribs;
       draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_CONSTANT, vs_index);
    } else {
diff --git a/src/gallium/drivers/softpipe/sp_state_derived.c b/src/gallium/drivers/softpipe/sp_state_derived.c
index 85fd47d..93cd38e 100644
--- a/src/gallium/drivers/softpipe/sp_state_derived.c
+++ b/src/gallium/drivers/softpipe/sp_state_derived.c
@@ -137,7 +137,7 @@ softpipe_get_vertex_info(struct softpipe_context *softpipe)
 
       softpipe->psize_slot = draw_find_shader_output(softpipe->draw,
                                                  TGSI_SEMANTIC_PSIZE, 0);
-      if (softpipe->psize_slot > 0) {
+      if (softpipe->psize_slot >= 0) {
          draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_CONSTANT,
                                softpipe->psize_slot);
       }




More information about the mesa-commit mailing list