Merge branch 'gallium-format-cleanup'
[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_A8R8G8B8_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
56 /* These formats don't exist yet:
57 *
58 case PIPE_FORMAT_R10G10B10_USCALED: return SVGA3D_DECLTYPE_UDEC3;
59 case PIPE_FORMAT_R10G10B10_SNORM: return SVGA3D_DECLTYPE_DEC3N;
60 case PIPE_FORMAT_R16G16_FLOAT: return SVGA3D_DECLTYPE_FLOAT16_2;
61 case PIPE_FORMAT_R16G16B16A16_FLOAT: return SVGA3D_DECLTYPE_FLOAT16_4;
62 */
63
64 default:
65 /* There are many formats without hardware support. This case
66 * will be hit regularly, meaning we'll need swvfetch.
67 */
68 return SVGA3D_DECLTYPE_MAX;
69 }
70 }
71
72
73 static int update_need_swvfetch( struct svga_context *svga,
74 unsigned dirty )
75 {
76 unsigned i;
77 boolean need_swvfetch = FALSE;
78
79 for (i = 0; i < svga->curr.num_vertex_elements; i++) {
80 svga->state.sw.ve_format[i] = svga_translate_vertex_format(svga->curr.ve[i].src_format);
81 if (svga->state.sw.ve_format[i] == SVGA3D_DECLTYPE_MAX) {
82 need_swvfetch = TRUE;
83 break;
84 }
85 }
86
87 if (need_swvfetch != svga->state.sw.need_swvfetch) {
88 svga->state.sw.need_swvfetch = need_swvfetch;
89 svga->dirty |= SVGA_NEW_NEED_SWVFETCH;
90 }
91
92 return 0;
93 }
94
95 struct svga_tracked_state svga_update_need_swvfetch =
96 {
97 "update need_swvfetch",
98 ( SVGA_NEW_VELEMENT ),
99 update_need_swvfetch
100 };
101
102
103 /***********************************************************************
104 */
105
106 static int update_need_pipeline( struct svga_context *svga,
107 unsigned dirty )
108 {
109
110 boolean need_pipeline = FALSE;
111 struct svga_vertex_shader *vs = svga->curr.vs;
112
113 /* SVGA_NEW_RAST, SVGA_NEW_REDUCED_PRIMITIVE
114 */
115 if (svga->curr.rast->need_pipeline & (1 << svga->curr.reduced_prim)) {
116 SVGA_DBG(DEBUG_SWTNL, "%s: rast need_pipeline (%d) & prim (%x)\n",
117 __FUNCTION__,
118 svga->curr.rast->need_pipeline,
119 (1 << svga->curr.reduced_prim) );
120 need_pipeline = TRUE;
121 }
122
123 /* EDGEFLAGS
124 */
125 if (vs->base.info.writes_edgeflag) {
126 SVGA_DBG(DEBUG_SWTNL, "%s: edgeflags\n", __FUNCTION__);
127 need_pipeline = TRUE;
128 }
129
130 /* SVGA_NEW_CLIP
131 */
132 if (svga->curr.clip.nr) {
133 SVGA_DBG(DEBUG_SWTNL, "%s: userclip\n", __FUNCTION__);
134 need_pipeline = TRUE;
135 }
136
137 if (need_pipeline != svga->state.sw.need_pipeline) {
138 svga->state.sw.need_pipeline = need_pipeline;
139 svga->dirty |= SVGA_NEW_NEED_PIPELINE;
140 }
141
142 return 0;
143 }
144
145
146 struct svga_tracked_state svga_update_need_pipeline =
147 {
148 "need pipeline",
149 (SVGA_NEW_RAST |
150 SVGA_NEW_CLIP |
151 SVGA_NEW_VS |
152 SVGA_NEW_REDUCED_PRIMITIVE),
153 update_need_pipeline
154 };
155
156
157 /***********************************************************************
158 */
159
160 static int update_need_swtnl( struct svga_context *svga,
161 unsigned dirty )
162 {
163 boolean need_swtnl;
164
165 if (svga->debug.no_swtnl) {
166 svga->state.sw.need_swvfetch = 0;
167 svga->state.sw.need_pipeline = 0;
168 }
169
170 need_swtnl = (svga->state.sw.need_swvfetch ||
171 svga->state.sw.need_pipeline);
172
173 if (svga->debug.force_swtnl) {
174 need_swtnl = 1;
175 }
176
177 if (need_swtnl != svga->state.sw.need_swtnl) {
178 SVGA_DBG(DEBUG_SWTNL|DEBUG_PERF,
179 "%s need_swvfetch: %s, need_pipeline %s\n",
180 __FUNCTION__,
181 svga->state.sw.need_swvfetch ? "true" : "false",
182 svga->state.sw.need_pipeline ? "true" : "false");
183
184 svga->state.sw.need_swtnl = need_swtnl;
185 svga->dirty |= SVGA_NEW_NEED_SWTNL;
186 svga->swtnl.new_vdecl = TRUE;
187 }
188
189 return 0;
190 }
191
192
193 struct svga_tracked_state svga_update_need_swtnl =
194 {
195 "need swtnl",
196 (SVGA_NEW_NEED_PIPELINE |
197 SVGA_NEW_NEED_SWVFETCH),
198 update_need_swtnl
199 };