1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**********************************************************
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2008-2009 VMware, Inc.  All rights reserved.
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * obtaining a copy of this software and associated documentation
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * files (the "Software"), to deal in the Software without
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * restriction, including without limitation the rights to use, copy,
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * modify, merge, publish, distribute, sublicense, and/or sell copies
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * of the Software, and to permit persons to whom the Software is
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * furnished to do so, subject to the following conditions:
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice shall be
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * included in all copies or substantial portions of the Software.
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * SOFTWARE.
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org **********************************************************/
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "util/u_inlines.h"
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "pipe/p_state.h"
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "svga_context.h"
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "svga_state.h"
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "svga_debug.h"
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "svga_hw_reg.h"
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/***********************************************************************
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Given a gallium vertex element format, return the corresponding SVGA3D
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * format.  Return SVGA3D_DECLTYPE_MAX for unsupported gallium formats.
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE SVGA3dDeclType
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgsvga_translate_vertex_format(enum pipe_format format)
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   switch (format) {
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PIPE_FORMAT_R32_FLOAT:            return SVGA3D_DECLTYPE_FLOAT1;
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PIPE_FORMAT_R32G32_FLOAT:         return SVGA3D_DECLTYPE_FLOAT2;
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PIPE_FORMAT_R32G32B32_FLOAT:      return SVGA3D_DECLTYPE_FLOAT3;
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PIPE_FORMAT_R32G32B32A32_FLOAT:   return SVGA3D_DECLTYPE_FLOAT4;
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PIPE_FORMAT_B8G8R8A8_UNORM:       return SVGA3D_DECLTYPE_D3DCOLOR;
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PIPE_FORMAT_R8G8B8A8_USCALED:     return SVGA3D_DECLTYPE_UBYTE4;
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PIPE_FORMAT_R16G16_SSCALED:       return SVGA3D_DECLTYPE_SHORT2;
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PIPE_FORMAT_R16G16B16A16_SSCALED: return SVGA3D_DECLTYPE_SHORT4;
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PIPE_FORMAT_R8G8B8A8_UNORM:       return SVGA3D_DECLTYPE_UBYTE4N;
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PIPE_FORMAT_R16G16_SNORM:         return SVGA3D_DECLTYPE_SHORT2N;
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PIPE_FORMAT_R16G16B16A16_SNORM:   return SVGA3D_DECLTYPE_SHORT4N;
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PIPE_FORMAT_R16G16_UNORM:         return SVGA3D_DECLTYPE_USHORT2N;
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PIPE_FORMAT_R16G16B16A16_UNORM:   return SVGA3D_DECLTYPE_USHORT4N;
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PIPE_FORMAT_R10G10B10X2_USCALED:  return SVGA3D_DECLTYPE_UDEC3;
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PIPE_FORMAT_R10G10B10X2_SNORM:    return SVGA3D_DECLTYPE_DEC3N;
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PIPE_FORMAT_R16G16_FLOAT:         return SVGA3D_DECLTYPE_FLOAT16_2;
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   case PIPE_FORMAT_R16G16B16A16_FLOAT:   return SVGA3D_DECLTYPE_FLOAT16_4;
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   default:
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      /* There are many formats without hardware support.  This case
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       * will be hit regularly, meaning we'll need swvfetch.
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org       */
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return SVGA3D_DECLTYPE_MAX;
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic enum pipe_error
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgupdate_need_swvfetch( struct svga_context *svga,
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                      unsigned dirty )
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   unsigned i;
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   boolean need_swvfetch = FALSE;
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (!svga->curr.velems) {
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      /* No vertex elements bound. */
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      return 0;
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   for (i = 0; i < svga->curr.velems->count; i++) {
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      svga->state.sw.ve_format[i] = svga_translate_vertex_format(svga->curr.velems->velem[i].src_format);
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      if (svga->state.sw.ve_format[i] == SVGA3D_DECLTYPE_MAX) {
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         /* Unsupported format - use software fetch */
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         need_swvfetch = TRUE;
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         break;
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      }
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (need_swvfetch != svga->state.sw.need_swvfetch) {
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      svga->state.sw.need_swvfetch = need_swvfetch;
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      svga->dirty |= SVGA_NEW_NEED_SWVFETCH;
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return PIPE_OK;
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct svga_tracked_state svga_update_need_swvfetch =
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   "update need_swvfetch",
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   ( SVGA_NEW_VELEMENT ),
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   update_need_swvfetch
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/***********************************************************************
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic enum pipe_error
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgupdate_need_pipeline( struct svga_context *svga,
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                      unsigned dirty )
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   boolean need_pipeline = FALSE;
120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct svga_vertex_shader *vs = svga->curr.vs;
121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* SVGA_NEW_RAST, SVGA_NEW_REDUCED_PRIMITIVE
123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    */
124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (svga->curr.rast->need_pipeline & (1 << svga->curr.reduced_prim)) {
125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      SVGA_DBG(DEBUG_SWTNL, "%s: rast need_pipeline (0x%x) & prim (0x%x)\n",
126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                 __FUNCTION__,
127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                 svga->curr.rast->need_pipeline,
128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                 (1 << svga->curr.reduced_prim) );
129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      SVGA_DBG(DEBUG_SWTNL, "%s: rast need_pipeline tris (%s), lines (%s), points (%s)\n",
130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                 __FUNCTION__,
131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                 svga->curr.rast->need_pipeline_tris_str,
132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                 svga->curr.rast->need_pipeline_lines_str,
133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                 svga->curr.rast->need_pipeline_points_str);
134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      need_pipeline = TRUE;
135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* EDGEFLAGS
138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    */
139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    if (vs && vs->base.info.writes_edgeflag) {
140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      SVGA_DBG(DEBUG_SWTNL, "%s: edgeflags\n", __FUNCTION__);
141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      need_pipeline = TRUE;
142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* SVGA_NEW_FS, SVGA_NEW_RAST, SVGA_NEW_REDUCED_PRIMITIVE
145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    */
146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (svga->curr.reduced_prim == PIPE_PRIM_POINTS) {
147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      unsigned sprite_coord_gen = svga->curr.rast->templ.sprite_coord_enable;
148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      unsigned generic_inputs =
149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         svga->curr.fs ? svga->curr.fs->generic_inputs : 0;
150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      if (sprite_coord_gen &&
152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org          (generic_inputs & ~sprite_coord_gen)) {
153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         /* The fragment shader is using some generic inputs that are
154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org          * not being replaced by auto-generated point/sprite coords (and
155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org          * auto sprite coord generation is turned on).
156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org          * The SVGA3D interface does not support that: if we enable
157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org          * SVGA3D_RS_POINTSPRITEENABLE it gets enabled for _all_
158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org          * texture coordinate sets.
159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org          * To solve this, we have to use the draw-module's wide/sprite
160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org          * point stage.
161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org          */
162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org         need_pipeline = TRUE;
163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      }
164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (need_pipeline != svga->state.sw.need_pipeline) {
167f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      svga->state.sw.need_pipeline = need_pipeline;
168f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      svga->dirty |= SVGA_NEW_NEED_PIPELINE;
169f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
170f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
171f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* DEBUG */
172f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (0 && svga->state.sw.need_pipeline)
173f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      debug_printf("sw.need_pipeline = %d\n", svga->state.sw.need_pipeline);
174f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
175f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return PIPE_OK;
176f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
177f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
178f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
179f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct svga_tracked_state svga_update_need_pipeline =
180f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
181f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   "need pipeline",
182f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   (SVGA_NEW_RAST |
183f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    SVGA_NEW_FS |
184f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    SVGA_NEW_VS |
185f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    SVGA_NEW_REDUCED_PRIMITIVE),
186f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   update_need_pipeline
187f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
188f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
189f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
190f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/***********************************************************************
191f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
192f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
193f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic enum pipe_error
194f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgupdate_need_swtnl( struct svga_context *svga,
195f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                   unsigned dirty )
196f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
197f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   boolean need_swtnl;
198f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
199f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (svga->debug.no_swtnl) {
200f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      svga->state.sw.need_swvfetch = FALSE;
201f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      svga->state.sw.need_pipeline = FALSE;
202f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
203f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
204f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   need_swtnl = (svga->state.sw.need_swvfetch ||
205f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                 svga->state.sw.need_pipeline);
206f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
207f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (svga->debug.force_swtnl) {
208f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      need_swtnl = TRUE;
209f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
210f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
211f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /*
212f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    * Some state changes the draw module does makes us believe we
213f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    * we don't need swtnl. This causes the vdecl code to pickup
214f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    * the wrong buffers and vertex formats. Try trivial/line-wide.
215f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    */
216f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (svga->state.sw.in_swtnl_draw)
217f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      need_swtnl = TRUE;
218f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
219f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   if (need_swtnl != svga->state.sw.need_swtnl) {
220f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      SVGA_DBG(DEBUG_SWTNL|DEBUG_PERF,
221f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               "%s: need_swvfetch %s, need_pipeline %s\n",
222f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               __FUNCTION__,
223f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               svga->state.sw.need_swvfetch ? "true" : "false",
224f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               svga->state.sw.need_pipeline ? "true" : "false");
225f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
226f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      svga->state.sw.need_swtnl = need_swtnl;
227f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      svga->dirty |= SVGA_NEW_NEED_SWTNL;
228f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      svga->swtnl.new_vdecl = TRUE;
229f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
230f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
231f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return PIPE_OK;
232f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
233f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
234f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
235f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct svga_tracked_state svga_update_need_swtnl =
236f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
237f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   "need swtnl",
238f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   (SVGA_NEW_NEED_PIPELINE |
239f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    SVGA_NEW_NEED_SWVFETCH),
240f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   update_need_swtnl
241f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
242