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