util/simple_mtx: add assert_locked()
[mesa.git] / src / gallium / auxiliary / draw / draw_pipe_wide_point.c
index 8e0a117843e715ac63cefa38d4e7319f3ab14ef3..e9bbb67a95838cd7c948a2e2bf8b0b66cf30f1ca 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************
  * 
- * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2007 VMware, Inc.
  * All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * 
  **************************************************************************/
 
-/* Authors:  Keith Whitwell <keith@tungstengraphics.com>
+/* Authors:  Keith Whitwell <keithw@vmware.com>
  */
 
 /**
@@ -52,6 +52,7 @@
  */
 
 
+#include "pipe/p_screen.h"
 #include "pipe/p_context.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
@@ -74,12 +75,15 @@ struct widepoint_stage {
    uint num_texcoord_gen;
    uint texcoord_gen_slot[PIPE_MAX_SHADER_OUTPUTS];
 
+   /* TGSI_SEMANTIC to which sprite_coord_enable applies */
+   enum tgsi_semantic sprite_coord_semantic;
+
    int psize_slot;
 };
 
 
 
-static INLINE struct widepoint_stage *
+static inline struct widepoint_stage *
 widepoint_stage( struct draw_stage *stage )
 {
    return (struct widepoint_stage *)stage;
@@ -203,7 +207,7 @@ widepoint_first_point(struct draw_stage *stage,
    wide->xbias = 0.0;
    wide->ybias = 0.0;
 
-   if (rast->gl_rasterization_rules) {
+   if (rast->half_pixel_center) {
       wide->xbias = 0.125;
       wide->ybias = -0.125;
    }
@@ -233,42 +237,36 @@ widepoint_first_point(struct draw_stage *stage,
 
       wide->num_texcoord_gen = 0;
 
-      /* Loop over fragment shader inputs looking for generic inputs
+      /* Loop over fragment shader inputs looking for the PCOORD input or inputs
        * for which bit 'k' in sprite_coord_enable is set.
        */
       for (i = 0; i < fs->info.num_inputs; i++) {
-         if (fs->info.input_semantic_name[i] == TGSI_SEMANTIC_GENERIC) {
-            const int generic_index = fs->info.input_semantic_index[i];
-            /* Note that sprite_coord enable is a bitfield of
-             * PIPE_MAX_SHADER_OUTPUTS bits.
-             */
-            if (generic_index < PIPE_MAX_SHADER_OUTPUTS &&
-                (rast->sprite_coord_enable & (1 << generic_index))) {
-               /* OK, this generic attribute needs to be replaced with a
-                * texcoord (see above).
-                */
-               int slot = draw_alloc_extra_vertex_attrib(draw,
-                                                         TGSI_SEMANTIC_GENERIC,
-                                                         generic_index);
-
-               /* add this slot to the texcoord-gen list */
-               wide->texcoord_gen_slot[wide->num_texcoord_gen++] = slot;
-            }
+         int slot;
+         const enum tgsi_semantic sn = fs->info.input_semantic_name[i];
+         const unsigned si = fs->info.input_semantic_index[i];
+
+         if (sn == wide->sprite_coord_semantic) {
+            /* Note that sprite_coord_enable is a bitfield of 32 bits. */
+            if (si >= 32 || !(rast->sprite_coord_enable & (1 << si)))
+               continue;
+         } else if (sn != TGSI_SEMANTIC_PCOORD) {
+            continue;
          }
+
+         /* OK, this generic attribute needs to be replaced with a
+          * sprite coord (see above).
+          */
+         slot = draw_alloc_extra_vertex_attrib(draw, sn, si);
+
+         /* add this slot to the texcoord-gen list */
+         wide->texcoord_gen_slot[wide->num_texcoord_gen++] = slot;
       }
    }
 
    wide->psize_slot = -1;
    if (rast->point_size_per_vertex) {
       /* find PSIZ vertex output */
-      const struct draw_vertex_shader *vs = draw->vs.vertex_shader;
-      uint i;
-      for (i = 0; i < vs->info.num_outputs; i++) {
-         if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_PSIZE) {
-            wide->psize_slot = i;
-            break;
-         }
-      }
+      wide->psize_slot = draw_find_shader_output(draw, TGSI_SEMANTIC_PSIZE, 0);
    }
    
    stage->point( stage, header );
@@ -310,7 +308,7 @@ static void widepoint_destroy( struct draw_stage *stage )
 struct draw_stage *draw_wide_point_stage( struct draw_context *draw )
 {
    struct widepoint_stage *wide = CALLOC_STRUCT(widepoint_stage);
-   if (wide == NULL)
+   if (!wide)
       goto fail;
 
    wide->stage.draw = draw;
@@ -326,6 +324,11 @@ struct draw_stage *draw_wide_point_stage( struct draw_context *draw )
    if (!draw_alloc_temp_verts( &wide->stage, 4 ))
       goto fail;
 
+   wide->sprite_coord_semantic =
+      draw->pipe->screen->get_param(draw->pipe->screen, PIPE_CAP_TGSI_TEXCOORD)
+      ?
+      TGSI_SEMANTIC_TEXCOORD : TGSI_SEMANTIC_GENERIC;
+
    return &wide->stage;
 
  fail: