st/mesa: fix lowered IO - don't call st_nir_assign_vs_in_locations twice
[mesa.git] / src / mesa / state_tracker / st_cb_rasterpos.c
index d82b2a2035f4a62f4c4dfbe4935f4ee9157c8977..c3684176071030073ce1d4161db7f08af3368417 100644 (file)
@@ -1,8 +1,8 @@
 /**************************************************************************
- * 
- * 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
  * copy of this software and associated documentation files (the
  * "Software"), to deal in the Software without restriction, including
  * distribute, sub license, and/or sell copies of the Software, and to
  * permit persons to whom the Software is furnished to do so, subject to
  * the following conditions:
- * 
+ *
  * The above copyright notice and this permission notice (including the
  * next paragraph) shall be included in all copies or substantial portions
  * of the Software.
- * 
+ *
  * 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.
- * 
+ *
  **************************************************************************/
 
 /**
  */
 
 
-#include "main/imports.h"
+
 #include "main/macros.h"
+#include "main/arrayobj.h"
 #include "main/feedback.h"
+#include "main/rastpos.h"
+#include "main/state.h"
+#include "main/varray.h"
 
 #include "st_context.h"
 #include "st_atom.h"
 #include "st_draw.h"
+#include "st_program.h"
 #include "st_cb_rasterpos.h"
-#include "st_draw.h"
+#include "st_util.h"
 #include "draw/draw_context.h"
 #include "draw/draw_pipe.h"
-#include "shader/prog_instruction.h"
 #include "vbo/vbo.h"
 
 
-
 /**
  * Our special drawing pipeline stage (replaces rasterization).
  */
 struct rastpos_stage
 {
    struct draw_stage stage;   /**< Base class */
-   GLcontext *ctx;            /**< Rendering context */
+   struct gl_context *ctx;            /**< Rendering context */
 
    /* vertex attrib info we can setup once and re-use */
-   struct gl_client_array array[VERT_ATTRIB_MAX];
-   const struct gl_client_array *arrays[VERT_ATTRIB_MAX];
+   struct gl_vertex_array_object *VAO;
    struct _mesa_prim prim;
 };
 
 
-static INLINE struct rastpos_stage *
+static inline struct rastpos_stage *
 rastpos_stage( struct draw_stage *stage )
 {
    return (struct rastpos_stage *) stage;
@@ -102,7 +104,9 @@ rastpos_line( struct draw_stage *stage, struct prim_header *prim )
 static void
 rastpos_destroy(struct draw_stage *stage)
 {
-   _mesa_free(stage);
+   struct rastpos_stage *rstage = (struct rastpos_stage*)stage;
+   _mesa_reference_vao(rstage->ctx, &rstage->VAO, NULL);
+   free(stage);
 }
 
 
@@ -111,7 +115,7 @@ rastpos_destroy(struct draw_stage *stage)
  * else copy the current attrib.
  */
 static void
-update_attrib(GLcontext *ctx, const GLuint *outputMapping,
+update_attrib(struct gl_context *ctx, const ubyte *outputMapping,
               const struct vertex_header *vert,
               GLfloat *dest,
               GLuint result, GLuint defaultAttrib)
@@ -133,10 +137,11 @@ static void
 rastpos_point(struct draw_stage *stage, struct prim_header *prim)
 {
    struct rastpos_stage *rs = rastpos_stage(stage);
-   GLcontext *ctx = rs->ctx;
-   struct st_context *st = ctx->st;
+   struct gl_context *ctx = rs->ctx;
+   struct st_context *st = st_context(ctx);
    const GLfloat height = (GLfloat) ctx->DrawBuffer->Height;
-   const GLuint *outputMapping = st->vertex_result_to_slot;
+   struct st_vertex_program *stvp = (struct st_vertex_program *)st->vp;
+   const ubyte *outputMapping = stvp->result_to_output;
    const GLfloat *pos;
    GLuint i;
 
@@ -156,16 +161,16 @@ rastpos_point(struct draw_stage *stage, struct prim_header *prim)
    /* update other raster attribs */
    update_attrib(ctx, outputMapping, prim->v[0],
                  ctx->Current.RasterColor,
-                 VERT_RESULT_COL0, VERT_ATTRIB_COLOR0);
+                 VARYING_SLOT_COL0, VERT_ATTRIB_COLOR0);
 
    update_attrib(ctx, outputMapping, prim->v[0],
                  ctx->Current.RasterSecondaryColor,
-                 VERT_RESULT_COL1, VERT_ATTRIB_COLOR1);
+                 VARYING_SLOT_COL1, VERT_ATTRIB_COLOR1);
 
    for (i = 0; i < ctx->Const.MaxTextureCoordUnits; i++) {
       update_attrib(ctx, outputMapping, prim->v[0],
                     ctx->Current.RasterTexCoords[i],
-                    VERT_RESULT_TEX0 + i, VERT_ATTRIB_TEX0 + i);
+                    VARYING_SLOT_TEX0 + i, VERT_ATTRIB_TEX0 + i);
    }
 
    if (ctx->RenderMode == GL_SELECT) {
@@ -178,10 +183,9 @@ rastpos_point(struct draw_stage *stage, struct prim_header *prim)
  * Create rasterpos "drawing" stage.
  */
 static struct rastpos_stage *
-new_draw_rastpos_stage(GLcontext *ctx, struct draw_context *draw)
+new_draw_rastpos_stage(struct gl_context *ctx, struct draw_context *draw)
 {
    struct rastpos_stage *rs = ST_CALLOC_STRUCT(rastpos_stage);
-   GLuint i;
 
    rs->stage.draw = draw;
    rs->stage.next = NULL;
@@ -194,24 +198,15 @@ new_draw_rastpos_stage(GLcontext *ctx, struct draw_context *draw)
    rs->stage.destroy = rastpos_destroy;
    rs->ctx = ctx;
 
-   for (i = 0; i < Elements(rs->array); i++) {
-      rs->array[i].Size = 4;
-      rs->array[i].Type = GL_FLOAT;
-      rs->array[i].Format = GL_RGBA;
-      rs->array[i].Stride = 0;
-      rs->array[i].StrideB = 0;
-      rs->array[i].Ptr = (GLubyte *) ctx->Current.Attrib[i];
-      rs->array[i].Enabled = GL_TRUE;
-      rs->array[i].Normalized = GL_TRUE;
-      rs->array[i].BufferObj = NULL;
-      rs->arrays[i] = &rs->array[i];
-   }
+   rs->VAO = _mesa_new_vao(ctx, ~((GLuint)0));
+   _mesa_vertex_attrib_binding(ctx, rs->VAO, VERT_ATTRIB_POS, 0);
+   _mesa_update_array_format(ctx, rs->VAO, VERT_ATTRIB_POS, 4, GL_FLOAT,
+                             GL_RGBA, GL_FALSE, GL_FALSE, GL_FALSE, 0);
+   _mesa_enable_vertex_array_attrib(ctx, rs->VAO, 0);
 
    rs->prim.mode = GL_POINTS;
-   rs->prim.indexed = 0;
    rs->prim.begin = 1;
    rs->prim.end = 1;
-   rs->prim.weak = 0;
    rs->prim.start = 0;
    rs->prim.count = 1;
 
@@ -220,12 +215,24 @@ new_draw_rastpos_stage(GLcontext *ctx, struct draw_context *draw)
 
 
 static void
-st_RasterPos(GLcontext *ctx, const GLfloat v[4])
+st_RasterPos(struct gl_context *ctx, const GLfloat v[4])
 {
-   struct st_context *st = ctx->st;
-   struct draw_context *draw = st->draw;
+   struct st_context *st = st_context(ctx);
+   struct draw_context *draw = st_get_draw_context(st);
    struct rastpos_stage *rs;
 
+   if (!st->draw)
+      return;
+
+   if (ctx->VertexProgram._Current == NULL ||
+       ctx->VertexProgram._Current == ctx->VertexProgram._TnlProgram) {
+      /* No vertex shader/program is enabled, used the simple/fast fixed-
+       * function implementation of RasterPos.
+       */
+      _mesa_RasterPos(ctx, v);
+      return;
+   }
+
    if (st->rastpos_stage) {
       /* get rastpos stage info */
       rs = rastpos_stage(st->rastpos_stage);
@@ -240,7 +247,7 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4])
    draw_set_rasterize_stage(st->draw, st->rastpos_stage);
 
    /* make sure everything's up to date */
-   st_validate_state(ctx->st);
+   st_validate_state(st, ST_PIPELINE_RENDER);
 
    /* This will get set only if rastpos_point(), above, gets called */
    ctx->Current.RasterPosValid = GL_FALSE;
@@ -248,10 +255,21 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4])
    /* All vertex attribs but position were previously initialized above.
     * Just plug in position pointer now.
     */
-   rs->array[0].Ptr = (GLubyte *) v;
+   rs->VAO->VertexAttrib[VERT_ATTRIB_POS].Ptr = (GLubyte *) v;
+   rs->VAO->NewArrays |= VERT_BIT_POS;
+   _mesa_set_draw_vao(ctx, rs->VAO, VERT_BIT_POS);
+
+   /* Draw the point. */
+   st_feedback_draw_vbo(ctx, &rs->prim, 1, NULL, GL_TRUE, 0, 1, 1, 0,
+                        NULL, 0);
 
-   /* draw the point */
-   st_feedback_draw_vbo(ctx, rs->arrays, &rs->prim, 1, NULL, GL_TRUE, 0, 1);
+   /* restore draw's rasterization stage depending on rendermode */
+   if (ctx->RenderMode == GL_FEEDBACK) {
+      draw_set_rasterize_stage(draw, st->feedback_stage);
+   }
+   else if (ctx->RenderMode == GL_SELECT) {
+      draw_set_rasterize_stage(draw, st->selection_stage);
+   }
 }