svga_state_need_swtnl.c 6.3 KB
Newer Older
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/**********************************************************
 * Copyright 2008-2009 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 without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, 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 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
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * 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.
 *
 **********************************************************/

26
#include "util/u_inlines.h"
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
27 28
#include "pipe/p_state.h"
#include "svga_context.h"
29
#include "svga_shader.h"
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
30 31 32 33
#include "svga_state.h"
#include "svga_debug.h"
#include "svga_hw_reg.h"

Brian Paul's avatar
Brian Paul committed
34

35
static enum pipe_error
36
update_need_swvfetch(struct svga_context *svga, unsigned dirty)
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
37
{
38 39
   if (!svga->curr.velems) {
      /* No vertex elements bound. */
40
      return PIPE_OK;
41 42
   }

43 44
   if (svga->state.sw.need_swvfetch != svga->curr.velems->need_swvfetch) {
      svga->state.sw.need_swvfetch = svga->curr.velems->need_swvfetch;
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
45 46
      svga->dirty |= SVGA_NEW_NEED_SWVFETCH;
   }
47

48
   return PIPE_OK;
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
49 50
}

51
struct svga_tracked_state svga_update_need_swvfetch =
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
52 53 54 55 56 57 58 59
{
   "update need_swvfetch",
   ( SVGA_NEW_VELEMENT ),
   update_need_swvfetch
};



60
static enum pipe_error
61
update_need_pipeline(struct svga_context *svga, unsigned dirty)
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
62 63
{
   boolean need_pipeline = FALSE;
64
   struct svga_vertex_shader *vs = svga->curr.vs;
65
   const char *reason = "";
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
66 67 68 69

   /* SVGA_NEW_RAST, SVGA_NEW_REDUCED_PRIMITIVE
    */
   if (svga->curr.rast->need_pipeline & (1 << svga->curr.reduced_prim)) {
70
      SVGA_DBG(DEBUG_SWTNL, "%s: rast need_pipeline (0x%x) & prim (0x%x)\n",
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
71 72 73
                 __FUNCTION__,
                 svga->curr.rast->need_pipeline,
                 (1 << svga->curr.reduced_prim) );
74 75 76 77 78
      SVGA_DBG(DEBUG_SWTNL, "%s: rast need_pipeline tris (%s), lines (%s), points (%s)\n",
                 __FUNCTION__,
                 svga->curr.rast->need_pipeline_tris_str,
                 svga->curr.rast->need_pipeline_lines_str,
                 svga->curr.rast->need_pipeline_points_str);
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
79
      need_pipeline = TRUE;
80 81 82 83 84 85 86 87 88 89 90 91 92 93

      switch (svga->curr.reduced_prim) {
      case PIPE_PRIM_POINTS:
         reason = svga->curr.rast->need_pipeline_points_str;
         break;
      case PIPE_PRIM_LINES:
         reason = svga->curr.rast->need_pipeline_lines_str;
         break;
      case PIPE_PRIM_TRIANGLES:
         reason = svga->curr.rast->need_pipeline_tris_str;
         break;
      default:
         assert(!"Unexpected reduced prim type");
      }
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
94 95
   }

96
   /* EDGEFLAGS
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
97
    */
98
    if (vs && vs->base.info.writes_edgeflag) {
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
99 100
      SVGA_DBG(DEBUG_SWTNL, "%s: edgeflags\n", __FUNCTION__);
      need_pipeline = TRUE;
101
      reason = "edge flags";
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
102 103
   }

104 105 106 107
   /* SVGA_NEW_FS, SVGA_NEW_RAST, SVGA_NEW_REDUCED_PRIMITIVE
    */
   if (svga->curr.reduced_prim == PIPE_PRIM_POINTS) {
      unsigned sprite_coord_gen = svga->curr.rast->templ.sprite_coord_enable;
108 109
      unsigned generic_inputs =
         svga->curr.fs ? svga->curr.fs->generic_inputs : 0;
110

111
      if (!svga_have_vgpu10(svga) && sprite_coord_gen &&
112 113 114 115 116 117 118 119 120 121 122
          (generic_inputs & ~sprite_coord_gen)) {
         /* The fragment shader is using some generic inputs that are
          * not being replaced by auto-generated point/sprite coords (and
          * auto sprite coord generation is turned on).
          * The SVGA3D interface does not support that: if we enable
          * SVGA3D_RS_POINTSPRITEENABLE it gets enabled for _all_
          * texture coordinate sets.
          * To solve this, we have to use the draw-module's wide/sprite
          * point stage.
          */
         need_pipeline = TRUE;
123
         reason = "point sprite coordinate generation";
124 125 126
      }
   }

Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
127 128 129 130 131
   if (need_pipeline != svga->state.sw.need_pipeline) {
      svga->state.sw.need_pipeline = need_pipeline;
      svga->dirty |= SVGA_NEW_NEED_PIPELINE;
   }

Brian Paul's avatar
Brian Paul committed
132 133 134 135
   /* DEBUG */
   if (0 && svga->state.sw.need_pipeline)
      debug_printf("sw.need_pipeline = %d\n", svga->state.sw.need_pipeline);

136 137 138 139 140 141
   if (svga->state.sw.need_pipeline) {
      assert(reason);
      pipe_debug_message(&svga->debug.callback, FALLBACK,
                         "Using semi-fallback for %s", reason);
   }

142
   return PIPE_OK;
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
143 144 145
}


146
struct svga_tracked_state svga_update_need_pipeline =
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
147 148 149
{
   "need pipeline",
   (SVGA_NEW_RAST |
150
    SVGA_NEW_FS |
151
    SVGA_NEW_VS |
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
152 153 154 155 156
    SVGA_NEW_REDUCED_PRIMITIVE),
   update_need_pipeline
};


157
static enum pipe_error
158
update_need_swtnl(struct svga_context *svga, unsigned dirty)
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
159 160 161 162
{
   boolean need_swtnl;

   if (svga->debug.no_swtnl) {
163 164
      svga->state.sw.need_swvfetch = FALSE;
      svga->state.sw.need_pipeline = FALSE;
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
165 166 167 168 169 170
   }

   need_swtnl = (svga->state.sw.need_swvfetch ||
                 svga->state.sw.need_pipeline);

   if (svga->debug.force_swtnl) {
171
      need_swtnl = TRUE;
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
172 173
   }

174
   /*
175
    * Some state changes the draw module does makes us believe we
176 177 178 179
    * we don't need swtnl. This causes the vdecl code to pickup
    * the wrong buffers and vertex formats. Try trivial/line-wide.
    */
   if (svga->state.sw.in_swtnl_draw)
180
      need_swtnl = TRUE;
181

Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
182 183
   if (need_swtnl != svga->state.sw.need_swtnl) {
      SVGA_DBG(DEBUG_SWTNL|DEBUG_PERF,
184
               "%s: need_swvfetch %s, need_pipeline %s\n",
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
185 186 187 188 189 190 191 192
               __FUNCTION__,
               svga->state.sw.need_swvfetch ? "true" : "false",
               svga->state.sw.need_pipeline ? "true" : "false");

      svga->state.sw.need_swtnl = need_swtnl;
      svga->dirty |= SVGA_NEW_NEED_SWTNL;
      svga->swtnl.new_vdecl = TRUE;
   }
193

194
   return PIPE_OK;
Jakob Bornecrantz's avatar
Jakob Bornecrantz committed
195 196 197 198 199 200 201 202 203 204
}


struct svga_tracked_state svga_update_need_swtnl =
{
   "need swtnl",
   (SVGA_NEW_NEED_PIPELINE |
    SVGA_NEW_NEED_SWVFETCH),
   update_need_swtnl
};