draw: fixup draw_find_shader_output
authorZack Rusin <zackr@vmware.com>
Fri, 24 May 2013 20:39:59 +0000 (16:39 -0400)
committerZack Rusin <zackr@vmware.com>
Sat, 25 May 2013 13:49:20 +0000 (09:49 -0400)
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@vmware.com>
Reviewed-by: José Fonseca<jfonseca@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/gallium/auxiliary/draw/draw_context.c
src/gallium/auxiliary/draw/draw_vertex.h
src/gallium/drivers/llvmpipe/lp_state_derived.c
src/gallium/drivers/softpipe/sp_state_derived.c

index 4250f10d13a257239f3505e7c555389f06ce180a..63ccf386f298cc9d9ac67480a2ef19a7fad9a55b 100644 (file)
@@ -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;
 }
 
 
index c87c3d84ce2a91b3199777c47db3478760f2baeb..9e10ada1a59ad482bcb119550a07d04e30de8b4c 100644 (file)
@@ -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));
index 9c5e84722f1230e2e9e8e235c2beb573b0a130fe..ea24ffcd6b6c2ebd532a0f02570312ac9902d026 100644 (file)
@@ -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 {
index 85fd47d58799bf5a6286b5647b20a32d6b96e3d3..93cd38ee7a48a336dd37d6c85cb24c7c1ee97c81 100644 (file)
@@ -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);
       }