llvmpipe: wait for queries being finished when asked for it or before deletion
[mesa.git] / src / gallium / drivers / failover / fo_state_emit.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /* Authors: Keith Whitwell <keith@tungstengraphics.com>
29 */
30
31 #include "fo_context.h"
32
33 /* This looks like a lot of work at the moment - we're keeping a
34 * duplicate copy of the state up-to-date.
35 *
36 * This can change in two ways:
37 * - With constant state objects we would only need to save a pointer,
38 * not the whole object.
39 * - By adding a callback in the state tracker to re-emit state. The
40 * state tracker knows the current state already and can re-emit it
41 * without additional complexity.
42 *
43 * This works as a proof-of-concept, but a final version will have
44 * lower overheads.
45 */
46
47
48 /* Bring the software pipe uptodate with current state.
49 *
50 * With constant state objects we would probably just send all state
51 * to both rasterizers all the time???
52 */
53 void
54 failover_state_emit( struct failover_context *failover )
55 {
56 if (failover->dirty & FO_NEW_BLEND)
57 failover->sw->bind_blend_state( failover->sw,
58 failover->blend->sw_state );
59
60 if (failover->dirty & FO_NEW_BLEND_COLOR)
61 failover->sw->set_blend_color( failover->sw, &failover->blend_color );
62
63 if (failover->dirty & FO_NEW_CLIP)
64 failover->sw->set_clip_state( failover->sw, &failover->clip );
65
66 if (failover->dirty & FO_NEW_SAMPLE_MASK)
67 failover->sw->set_sample_mask( failover->sw, failover->sample_mask );
68
69 if (failover->dirty & FO_NEW_DEPTH_STENCIL)
70 failover->sw->bind_depth_stencil_alpha_state( failover->sw,
71 failover->depth_stencil->sw_state );
72
73 if (failover->dirty & FO_NEW_STENCIL_REF)
74 failover->sw->set_stencil_ref( failover->sw, &failover->stencil_ref );
75
76 if (failover->dirty & FO_NEW_FRAMEBUFFER)
77 failover->sw->set_framebuffer_state( failover->sw, &failover->framebuffer );
78
79 if (failover->dirty & FO_NEW_FRAGMENT_SHADER)
80 failover->sw->bind_fs_state( failover->sw,
81 failover->fragment_shader->sw_state );
82
83 if (failover->dirty & FO_NEW_VERTEX_SHADER)
84 failover->sw->bind_vs_state( failover->sw,
85 failover->vertex_shader->sw_state );
86
87 if (failover->dirty & FO_NEW_VERTEX_ELEMENT)
88 failover->sw->bind_vertex_elements_state( failover->sw,
89 failover->vertex_elements->sw_state );
90
91 if (failover->dirty & FO_NEW_STIPPLE)
92 failover->sw->set_polygon_stipple( failover->sw, &failover->poly_stipple );
93
94 if (failover->dirty & FO_NEW_RASTERIZER)
95 failover->sw->bind_rasterizer_state( failover->sw,
96 failover->rasterizer->sw_state );
97
98 if (failover->dirty & FO_NEW_SCISSOR)
99 failover->sw->set_scissor_state( failover->sw, &failover->scissor );
100
101 if (failover->dirty & FO_NEW_VIEWPORT)
102 failover->sw->set_viewport_state( failover->sw, &failover->viewport );
103
104 if (failover->dirty & FO_NEW_SAMPLER) {
105 failover->sw->bind_fragment_sampler_states( failover->sw, failover->num_samplers,
106 failover->sw_sampler_state );
107 failover->sw->bind_vertex_sampler_states(failover->sw,
108 failover->num_vertex_samplers,
109 failover->sw_vertex_sampler_state);
110 }
111
112 if (failover->dirty & FO_NEW_SAMPLER_VIEW) {
113 struct pipe_sampler_view *fragment_views[PIPE_MAX_SAMPLERS];
114 struct pipe_sampler_view *vertex_views[PIPE_MAX_VERTEX_SAMPLERS];
115 uint i;
116
117 for (i = 0; i < failover->num_fragment_sampler_views; i++) {
118 fragment_views[i] = failover->fragment_sampler_views[i]->sw;
119 }
120 failover->sw->set_fragment_sampler_views(failover->sw,
121 failover->num_fragment_sampler_views,
122 fragment_views);
123
124 for (i = 0; i < failover->num_vertex_sampler_views; i++) {
125 vertex_views[i] = failover->vertex_sampler_views[i]->sw;
126 }
127 failover->sw->set_vertex_sampler_views(failover->sw,
128 failover->num_vertex_sampler_views,
129 vertex_views);
130 }
131
132 if (failover->dirty & FO_NEW_VERTEX_BUFFER) {
133 failover->sw->set_vertex_buffers( failover->sw,
134 failover->num_vertex_buffers,
135 failover->vertex_buffers );
136 }
137
138 failover->dirty = 0;
139 }