43b9757b319b94e62913b2e824e894aa3cd1a198
[mesa.git] / src / mesa / pipe / failover / fo_state.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
34 /* This looks like a lot of work at the moment - we're keeping a
35 * duplicate copy of the state up-to-date.
36 *
37 * This can change in two ways:
38 * - With constant state objects we would only need to save a pointer,
39 * not the whole object.
40 * - By adding a callback in the state tracker to re-emit state. The
41 * state tracker knows the current state already and can re-emit it
42 * without additional complexity.
43 *
44 * This works as a proof-of-concept, but a final version will have
45 * lower overheads.
46 */
47
48 static void
49 failover_set_alpha_test_state(struct pipe_context *pipe,
50 const struct pipe_alpha_test_state *alpha)
51 {
52 struct failover_context *failover = failover_context(pipe);
53
54 failover->alpha_test = *alpha;
55 failover->dirty |= FO_NEW_ALPHA_TEST;
56 failover->hw->set_alpha_test_state( failover->hw, alpha );
57 }
58
59
60 static void
61 failover_bind_blend_state( struct pipe_context *pipe,
62 const struct pipe_blend_state *blend )
63 {
64 struct failover_context *failover = failover_context(pipe);
65
66 failover->blend = blend;
67 failover->dirty |= FO_NEW_BLEND;
68 failover->hw->bind_blend_state( failover->hw, blend );
69 }
70
71
72 static void
73 failover_set_blend_color( struct pipe_context *pipe,
74 const struct pipe_blend_color *blend_color )
75 {
76 struct failover_context *failover = failover_context(pipe);
77
78 failover->blend_color = *blend_color;
79 failover->dirty |= FO_NEW_BLEND_COLOR;
80 failover->hw->set_blend_color( failover->hw, blend_color );
81 }
82
83 static void
84 failover_set_clip_state( struct pipe_context *pipe,
85 const struct pipe_clip_state *clip )
86 {
87 struct failover_context *failover = failover_context(pipe);
88
89 failover->clip = *clip;
90 failover->dirty |= FO_NEW_CLIP;
91 failover->hw->set_clip_state( failover->hw, clip );
92 }
93
94 static void
95 failover_set_clear_color_state( struct pipe_context *pipe,
96 const struct pipe_clear_color_state *clear_color )
97 {
98 struct failover_context *failover = failover_context(pipe);
99
100 failover->clear_color = *clear_color;
101 failover->dirty |= FO_NEW_CLEAR_COLOR;
102 failover->hw->set_clear_color_state( failover->hw, clear_color );
103 }
104
105 static void
106 failover_bind_depth_stencil_state(struct pipe_context *pipe,
107 const struct pipe_depth_stencil_state *depth_stencil)
108 {
109 struct failover_context *failover = failover_context(pipe);
110
111 failover->depth_stencil = depth_stencil;
112 failover->dirty |= FO_NEW_DEPTH_STENCIL;
113 failover->hw->bind_depth_stencil_state( failover->hw, depth_stencil );
114 }
115
116 static void
117 failover_set_framebuffer_state(struct pipe_context *pipe,
118 const struct pipe_framebuffer_state *framebuffer)
119 {
120 struct failover_context *failover = failover_context(pipe);
121
122 failover->framebuffer = *framebuffer;
123 failover->dirty |= FO_NEW_FRAMEBUFFER;
124 failover->hw->set_framebuffer_state( failover->hw, framebuffer );
125 }
126
127 static void
128 failover_set_fs_state(struct pipe_context *pipe,
129 const struct pipe_shader_state *fs)
130 {
131 struct failover_context *failover = failover_context(pipe);
132
133 failover->fragment_shader = *fs;
134 failover->dirty |= FO_NEW_FRAGMENT_SHADER;
135 failover->hw->set_fs_state( failover->hw, fs );
136 }
137
138 static void
139 failover_set_vs_state(struct pipe_context *pipe,
140 const struct pipe_shader_state *vs)
141 {
142 struct failover_context *failover = failover_context(pipe);
143
144 failover->vertex_shader = *vs;
145 failover->dirty |= FO_NEW_VERTEX_SHADER;
146 failover->hw->set_vs_state( failover->hw, vs );
147 }
148
149
150 static void
151 failover_set_polygon_stipple( struct pipe_context *pipe,
152 const struct pipe_poly_stipple *stipple )
153 {
154 struct failover_context *failover = failover_context(pipe);
155
156 failover->poly_stipple = *stipple;
157 failover->dirty |= FO_NEW_STIPPLE;
158 failover->hw->set_polygon_stipple( failover->hw, stipple );
159 }
160
161
162
163 static void
164 failover_set_setup_state( struct pipe_context *pipe,
165 const struct pipe_setup_state *setup )
166 {
167 struct failover_context *failover = failover_context(pipe);
168
169 failover->setup = *setup;
170 failover->dirty |= FO_NEW_SETUP;
171 failover->hw->set_setup_state( failover->hw, setup );
172 }
173
174
175 static void
176 failover_set_scissor_state( struct pipe_context *pipe,
177 const struct pipe_scissor_state *scissor )
178 {
179 struct failover_context *failover = failover_context(pipe);
180
181 failover->scissor = *scissor;
182 failover->dirty |= FO_NEW_SCISSOR;
183 failover->hw->set_scissor_state( failover->hw, scissor );
184 }
185
186 static void
187 failover_bind_sampler_state(struct pipe_context *pipe,
188 unsigned unit,
189 const struct pipe_sampler_state *sampler)
190 {
191 struct failover_context *failover = failover_context(pipe);
192
193 failover->sampler[unit] = sampler;
194 failover->dirty |= FO_NEW_SAMPLER;
195 failover->dirty_sampler |= (1<<unit);
196 failover->hw->bind_sampler_state( failover->hw, unit, sampler );
197 }
198
199
200 static void
201 failover_set_texture_state(struct pipe_context *pipe,
202 unsigned unit,
203 struct pipe_mipmap_tree *texture)
204 {
205 struct failover_context *failover = failover_context(pipe);
206
207 failover->texture[unit] = texture;
208 failover->dirty |= FO_NEW_TEXTURE;
209 failover->dirty_texture |= (1<<unit);
210 failover->hw->set_texture_state( failover->hw, unit, texture );
211 }
212
213
214 static void
215 failover_set_viewport_state( struct pipe_context *pipe,
216 const struct pipe_viewport_state *viewport )
217 {
218 struct failover_context *failover = failover_context(pipe);
219
220 failover->viewport = *viewport;
221 failover->dirty |= FO_NEW_VIEWPORT;
222 failover->hw->set_viewport_state( failover->hw, viewport );
223 }
224
225
226 static void
227 failover_set_vertex_buffer(struct pipe_context *pipe,
228 unsigned unit,
229 const struct pipe_vertex_buffer *vertex_buffer)
230 {
231 struct failover_context *failover = failover_context(pipe);
232
233 failover->vertex_buffer[unit] = *vertex_buffer;
234 failover->dirty |= FO_NEW_VERTEX_BUFFER;
235 failover->dirty_vertex_buffer |= (1<<unit);
236 failover->hw->set_vertex_buffer( failover->hw, unit, vertex_buffer );
237 }
238
239
240 static void
241 failover_set_vertex_element(struct pipe_context *pipe,
242 unsigned unit,
243 const struct pipe_vertex_element *vertex_element)
244 {
245 struct failover_context *failover = failover_context(pipe);
246
247 failover->vertex_element[unit] = *vertex_element;
248 failover->dirty |= FO_NEW_VERTEX_ELEMENT;
249 failover->dirty_vertex_element |= (1<<unit);
250 failover->hw->set_vertex_element( failover->hw, unit, vertex_element );
251 }
252
253
254 void
255 failover_init_state_functions( struct failover_context *failover )
256 {
257 failover->pipe.bind_blend_state = failover_bind_blend_state;
258 failover->pipe.bind_sampler_state = failover_bind_sampler_state;
259 failover->pipe.bind_depth_stencil_state = failover_bind_depth_stencil_state;
260
261 failover->pipe.set_alpha_test_state = failover_set_alpha_test_state;
262 failover->pipe.set_blend_color = failover_set_blend_color;
263 failover->pipe.set_clip_state = failover_set_clip_state;
264 failover->pipe.set_clear_color_state = failover_set_clear_color_state;
265 failover->pipe.set_framebuffer_state = failover_set_framebuffer_state;
266 failover->pipe.set_fs_state = failover_set_fs_state;
267 failover->pipe.set_vs_state = failover_set_vs_state;
268 failover->pipe.set_polygon_stipple = failover_set_polygon_stipple;
269 failover->pipe.set_scissor_state = failover_set_scissor_state;
270 failover->pipe.set_setup_state = failover_set_setup_state;
271 failover->pipe.set_texture_state = failover_set_texture_state;
272 failover->pipe.set_viewport_state = failover_set_viewport_state;
273 failover->pipe.set_vertex_buffer = failover_set_vertex_buffer;
274 failover->pipe.set_vertex_element = failover_set_vertex_element;
275 }