1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
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
24 **********************************************************/
26 #include "util/u_bitmask.h"
27 #include "util/u_debug.h"
28 #include "pipe/p_defines.h"
29 #include "util/u_memory.h"
30 #include "draw/draw_context.h"
32 #include "svga_context.h"
33 #include "svga_screen.h"
34 #include "svga_state.h"
35 #include "svga_draw.h"
37 #include "svga_hw_reg.h"
39 /* This is just enough to decide whether we need to use the draw
40 * module (swtnl) or not.
42 static const struct svga_tracked_state
*need_swtnl_state
[] =
44 &svga_update_need_swvfetch
,
45 &svga_update_need_pipeline
,
46 &svga_update_need_swtnl
,
51 /* Atoms to update hardware state prior to emitting a clear or draw
54 static const struct svga_tracked_state
*hw_clear_state
[] =
63 /* Atoms to update hardware state prior to emitting a draw packet.
65 static const struct svga_tracked_state
*hw_draw_state
[] =
67 &svga_need_tgsi_transform
,
72 &svga_hw_sampler
, /* VGPU10 */
73 &svga_hw_sampler_bindings
, /* VGPU10 */
74 &svga_hw_tss
, /* pre-VGPU10 */
75 &svga_hw_tss_binding
, /* pre-VGPU10 */
78 &svga_hw_fs_constants
,
79 &svga_hw_gs_constants
,
80 &svga_hw_vs_constants
,
85 static const struct svga_tracked_state
*swtnl_draw_state
[] =
87 &svga_update_swtnl_draw
,
88 &svga_update_swtnl_vdecl
,
92 /* Flattens the graph of state dependencies. Could swap the positions
93 * of hw_clear_state and need_swtnl_state without breaking anything.
95 static const struct svga_tracked_state
**state_levels
[] =
105 static unsigned check_state( unsigned a
,
111 static void accumulate_state( unsigned *a
,
118 static void xor_states( unsigned *result
,
127 static enum pipe_error
128 update_state(struct svga_context
*svga
,
129 const struct svga_tracked_state
*atoms
[],
132 boolean debug
= TRUE
;
133 enum pipe_error ret
= PIPE_OK
;
136 ret
= svga_hwtnl_flush( svga
->hwtnl
);
141 /* Debug version which enforces various sanity checks on the
142 * state flags which are generated and checked to help ensure
143 * state atoms are ordered correctly in the list.
145 unsigned examined
, prev
;
150 for (i
= 0; atoms
[i
] != NULL
; i
++) {
153 assert(atoms
[i
]->dirty
);
154 assert(atoms
[i
]->update
);
156 if (check_state(*state
, atoms
[i
]->dirty
)) {
158 debug_printf("update: %s\n", atoms
[i
]->name
);
159 ret
= atoms
[i
]->update( svga
, *state
);
164 /* generated = (prev ^ state)
165 * if (examined & generated)
168 xor_states(&generated
, prev
, *state
);
169 if (check_state(examined
, generated
)) {
170 debug_printf("state atom %s generated state already examined\n",
176 accumulate_state(&examined
, atoms
[i
]->dirty
);
180 for (i
= 0; atoms
[i
] != NULL
; i
++) {
181 if (check_state(*state
, atoms
[i
]->dirty
)) {
182 ret
= atoms
[i
]->update( svga
, *state
);
195 svga_update_state(struct svga_context
*svga
, unsigned max_level
)
197 struct svga_screen
*screen
= svga_screen(svga
->pipe
.screen
);
198 enum pipe_error ret
= PIPE_OK
;
201 /* Check for updates to bound textures. This can't be done in an
202 * atom as there is no flag which could provoke this test, and we
205 if (svga
->state
.texture_timestamp
!= screen
->texture_timestamp
) {
206 svga
->state
.texture_timestamp
= screen
->texture_timestamp
;
207 svga
->dirty
|= SVGA_NEW_TEXTURE
;
210 for (i
= 0; i
<= max_level
; i
++) {
211 svga
->dirty
|= svga
->state
.dirty
[i
];
214 ret
= update_state( svga
,
220 svga
->state
.dirty
[i
] = 0;
224 for (; i
< SVGA_STATE_MAX
; i
++)
225 svga
->state
.dirty
[i
] |= svga
->dirty
;
234 void svga_update_state_retry( struct svga_context
*svga
,
239 ret
= svga_update_state( svga
, max_level
);
241 if (ret
== PIPE_ERROR_OUT_OF_MEMORY
) {
242 svga_context_flush(svga
, NULL
);
243 ret
= svga_update_state( svga
, max_level
);
246 assert( ret
== PIPE_OK
);
251 #define EMIT_RS(_rs, _count, _name, _value) \
253 _rs[_count].state = _name; \
254 _rs[_count].uintValue = _value; \
259 /* Setup any hardware state which will be constant through the life of
262 enum pipe_error
svga_emit_initial_state( struct svga_context
*svga
)
264 if (svga_have_vgpu10(svga
)) {
265 SVGA3dRasterizerStateId id
= util_bitmask_add(svga
->rast_object_id_bm
);
268 /* XXX preliminary code */
269 ret
= SVGA3D_vgpu10_DefineRasterizerState(svga
->swc
,
271 SVGA3D_FILLMODE_FILL
,
273 1, /* frontCounterClockwise */
275 0.0f
, /* depthBiasClamp */
276 0.0f
, /* slopeScaledDepthBiasClamp */
277 0, /* depthClampEnable */
278 0, /* scissorEnable */
279 0, /* multisampleEnable */
280 0, /* aalineEnable */
281 1.0f
, /* lineWidth */
282 0, /* lineStippleEnable */
283 0, /* lineStippleFactor */
284 0, /* lineStipplePattern */
285 0); /* provokingVertexLast */
288 assert(ret
== PIPE_OK
);
290 ret
= SVGA3D_vgpu10_SetRasterizerState(svga
->swc
, id
);
294 SVGA3dRenderState
*rs
;
296 const unsigned COUNT
= 2;
299 ret
= SVGA3D_BeginSetRenderState( svga
->swc
, &rs
, COUNT
);
303 /* Always use D3D style coordinate space as this is the only one
304 * which is implemented on all backends.
306 EMIT_RS(rs
, count
, SVGA3D_RS_COORDINATETYPE
,
307 SVGA3D_COORDINATE_LEFTHANDED
);
308 EMIT_RS(rs
, count
, SVGA3D_RS_FRONTWINDING
, SVGA3D_FRONTWINDING_CW
);
310 assert( COUNT
== count
);
311 SVGA_FIFOCommitAll( svga
->swc
);