1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 /* Authors: Keith Whitwell <keith@tungstengraphics.com>
31 #include "fo_context.h"
34 /* This looks like a lot of work at the moment - we're keeping a
35 * duplicate copy of the state up-to-date.
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.
44 * This works as a proof-of-concept, but a final version will have
51 failover_create_blend_state( struct pipe_context
*pipe
,
52 const struct pipe_blend_state
*blend
)
54 struct fo_state
*state
= malloc(sizeof(struct fo_state
));
55 struct failover_context
*failover
= failover_context(pipe
);
57 state
->sw_state
= failover
->sw
->create_blend_state(failover
->sw
, blend
);
58 state
->hw_state
= failover
->hw
->create_blend_state(failover
->hw
, blend
);
64 failover_bind_blend_state( struct pipe_context
*pipe
,
67 struct failover_context
*failover
= failover_context(pipe
);
68 struct fo_state
*state
= (struct fo_state
*)blend
;
69 failover
->blend
= state
;
70 failover
->dirty
|= FO_NEW_BLEND
;
71 failover
->sw
->bind_blend_state( failover
->sw
, state
->sw_state
);
72 failover
->hw
->bind_blend_state( failover
->hw
, state
->hw_state
);
76 failover_delete_blend_state( struct pipe_context
*pipe
,
79 struct fo_state
*state
= (struct fo_state
*)blend
;
80 struct failover_context
*failover
= failover_context(pipe
);
82 failover
->sw
->delete_blend_state(failover
->sw
, state
->sw_state
);
83 failover
->hw
->delete_blend_state(failover
->hw
, state
->hw_state
);
90 failover_set_blend_color( struct pipe_context
*pipe
,
91 const struct pipe_blend_color
*blend_color
)
93 struct failover_context
*failover
= failover_context(pipe
);
95 failover
->blend_color
= *blend_color
;
96 failover
->dirty
|= FO_NEW_BLEND_COLOR
;
97 failover
->sw
->set_blend_color( failover
->sw
, blend_color
);
98 failover
->hw
->set_blend_color( failover
->hw
, blend_color
);
102 failover_set_clip_state( struct pipe_context
*pipe
,
103 const struct pipe_clip_state
*clip
)
105 struct failover_context
*failover
= failover_context(pipe
);
107 failover
->clip
= *clip
;
108 failover
->dirty
|= FO_NEW_CLIP
;
109 failover
->sw
->set_clip_state( failover
->sw
, clip
);
110 failover
->hw
->set_clip_state( failover
->hw
, clip
);
115 failover_create_depth_stencil_state(struct pipe_context
*pipe
,
116 const struct pipe_depth_stencil_alpha_state
*templ
)
118 struct fo_state
*state
= malloc(sizeof(struct fo_state
));
119 struct failover_context
*failover
= failover_context(pipe
);
121 state
->sw_state
= failover
->sw
->create_depth_stencil_alpha_state(failover
->sw
, templ
);
122 state
->hw_state
= failover
->hw
->create_depth_stencil_alpha_state(failover
->hw
, templ
);
128 failover_bind_depth_stencil_state(struct pipe_context
*pipe
,
131 struct failover_context
*failover
= failover_context(pipe
);
132 struct fo_state
*state
= (struct fo_state
*)depth_stencil
;
133 failover
->depth_stencil
= state
;
134 failover
->dirty
|= FO_NEW_DEPTH_STENCIL
;
135 failover
->sw
->bind_depth_stencil_alpha_state(failover
->sw
, state
->sw_state
);
136 failover
->hw
->bind_depth_stencil_alpha_state(failover
->hw
, state
->hw_state
);
140 failover_delete_depth_stencil_state(struct pipe_context
*pipe
,
143 struct fo_state
*state
= (struct fo_state
*)ds
;
144 struct failover_context
*failover
= failover_context(pipe
);
146 failover
->sw
->delete_depth_stencil_alpha_state(failover
->sw
, state
->sw_state
);
147 failover
->hw
->delete_depth_stencil_alpha_state(failover
->hw
, state
->hw_state
);
154 failover_set_framebuffer_state(struct pipe_context
*pipe
,
155 const struct pipe_framebuffer_state
*framebuffer
)
157 struct failover_context
*failover
= failover_context(pipe
);
159 failover
->framebuffer
= *framebuffer
;
160 failover
->dirty
|= FO_NEW_FRAMEBUFFER
;
161 failover
->sw
->set_framebuffer_state( failover
->sw
, framebuffer
);
162 failover
->hw
->set_framebuffer_state( failover
->hw
, framebuffer
);
167 failover_create_fs_state(struct pipe_context
*pipe
,
168 const struct pipe_shader_state
*templ
)
170 struct fo_state
*state
= malloc(sizeof(struct fo_state
));
171 struct failover_context
*failover
= failover_context(pipe
);
173 state
->sw_state
= failover
->sw
->create_fs_state(failover
->sw
, templ
);
174 state
->hw_state
= failover
->hw
->create_fs_state(failover
->hw
, templ
);
180 failover_bind_fs_state(struct pipe_context
*pipe
, void *fs
)
182 struct failover_context
*failover
= failover_context(pipe
);
183 struct fo_state
*state
= (struct fo_state
*)fs
;
184 failover
->fragment_shader
= state
;
185 failover
->dirty
|= FO_NEW_FRAGMENT_SHADER
;
186 failover
->sw
->bind_fs_state(failover
->sw
, state
->sw_state
);
187 failover
->hw
->bind_fs_state(failover
->hw
, state
->hw_state
);
191 failover_delete_fs_state(struct pipe_context
*pipe
,
194 struct fo_state
*state
= (struct fo_state
*)fs
;
195 struct failover_context
*failover
= failover_context(pipe
);
197 failover
->sw
->delete_fs_state(failover
->sw
, state
->sw_state
);
198 failover
->hw
->delete_fs_state(failover
->hw
, state
->hw_state
);
205 failover_create_vs_state(struct pipe_context
*pipe
,
206 const struct pipe_shader_state
*templ
)
208 struct fo_state
*state
= malloc(sizeof(struct fo_state
));
209 struct failover_context
*failover
= failover_context(pipe
);
211 state
->sw_state
= failover
->sw
->create_vs_state(failover
->sw
, templ
);
212 state
->hw_state
= failover
->hw
->create_vs_state(failover
->hw
, templ
);
218 failover_bind_vs_state(struct pipe_context
*pipe
,
221 struct failover_context
*failover
= failover_context(pipe
);
223 struct fo_state
*state
= (struct fo_state
*)vs
;
224 failover
->vertex_shader
= state
;
225 failover
->dirty
|= FO_NEW_VERTEX_SHADER
;
226 failover
->sw
->bind_vs_state(failover
->sw
, state
->sw_state
);
227 failover
->hw
->bind_vs_state(failover
->hw
, state
->hw_state
);
231 failover_delete_vs_state(struct pipe_context
*pipe
,
234 struct fo_state
*state
= (struct fo_state
*)vs
;
235 struct failover_context
*failover
= failover_context(pipe
);
237 failover
->sw
->delete_vs_state(failover
->sw
, state
->sw_state
);
238 failover
->hw
->delete_vs_state(failover
->hw
, state
->hw_state
);
245 failover_set_polygon_stipple( struct pipe_context
*pipe
,
246 const struct pipe_poly_stipple
*stipple
)
248 struct failover_context
*failover
= failover_context(pipe
);
250 failover
->poly_stipple
= *stipple
;
251 failover
->dirty
|= FO_NEW_STIPPLE
;
252 failover
->sw
->set_polygon_stipple( failover
->sw
, stipple
);
253 failover
->hw
->set_polygon_stipple( failover
->hw
, stipple
);
258 failover_create_rasterizer_state(struct pipe_context
*pipe
,
259 const struct pipe_rasterizer_state
*templ
)
261 struct fo_state
*state
= malloc(sizeof(struct fo_state
));
262 struct failover_context
*failover
= failover_context(pipe
);
264 state
->sw_state
= failover
->sw
->create_rasterizer_state(failover
->sw
, templ
);
265 state
->hw_state
= failover
->hw
->create_rasterizer_state(failover
->hw
, templ
);
271 failover_bind_rasterizer_state(struct pipe_context
*pipe
,
274 struct failover_context
*failover
= failover_context(pipe
);
276 struct fo_state
*state
= (struct fo_state
*)raster
;
277 failover
->rasterizer
= state
;
278 failover
->dirty
|= FO_NEW_RASTERIZER
;
279 failover
->sw
->bind_rasterizer_state(failover
->sw
, state
->sw_state
);
280 failover
->hw
->bind_rasterizer_state(failover
->hw
, state
->hw_state
);
284 failover_delete_rasterizer_state(struct pipe_context
*pipe
,
287 struct fo_state
*state
= (struct fo_state
*)raster
;
288 struct failover_context
*failover
= failover_context(pipe
);
290 failover
->sw
->delete_rasterizer_state(failover
->sw
, state
->sw_state
);
291 failover
->hw
->delete_rasterizer_state(failover
->hw
, state
->hw_state
);
299 failover_set_scissor_state( struct pipe_context
*pipe
,
300 const struct pipe_scissor_state
*scissor
)
302 struct failover_context
*failover
= failover_context(pipe
);
304 failover
->scissor
= *scissor
;
305 failover
->dirty
|= FO_NEW_SCISSOR
;
306 failover
->sw
->set_scissor_state( failover
->sw
, scissor
);
307 failover
->hw
->set_scissor_state( failover
->hw
, scissor
);
312 failover_create_sampler_state(struct pipe_context
*pipe
,
313 const struct pipe_sampler_state
*templ
)
315 struct fo_state
*state
= malloc(sizeof(struct fo_state
));
316 struct failover_context
*failover
= failover_context(pipe
);
318 state
->sw_state
= failover
->sw
->create_sampler_state(failover
->sw
, templ
);
319 state
->hw_state
= failover
->hw
->create_sampler_state(failover
->hw
, templ
);
325 failover_bind_sampler_state(struct pipe_context
*pipe
,
326 unsigned unit
, void *sampler
)
328 struct failover_context
*failover
= failover_context(pipe
);
329 struct fo_state
*state
= (struct fo_state
*)sampler
;
330 failover
->sampler
[unit
] = state
;
331 failover
->dirty
|= FO_NEW_SAMPLER
;
332 failover
->dirty_sampler
|= (1<<unit
);
333 failover
->sw
->bind_sampler_state(failover
->sw
, unit
,
335 failover
->hw
->bind_sampler_state(failover
->hw
, unit
,
340 failover_delete_sampler_state(struct pipe_context
*pipe
, void *sampler
)
342 struct fo_state
*state
= (struct fo_state
*)sampler
;
343 struct failover_context
*failover
= failover_context(pipe
);
345 failover
->sw
->delete_sampler_state(failover
->sw
, state
->sw_state
);
346 failover
->hw
->delete_sampler_state(failover
->hw
, state
->hw_state
);
354 failover_set_sampler_texture(struct pipe_context
*pipe
,
356 struct pipe_texture
*texture
)
358 struct failover_context
*failover
= failover_context(pipe
);
360 failover
->texture
[unit
] = texture
;
361 failover
->dirty
|= FO_NEW_TEXTURE
;
362 failover
->dirty_texture
|= (1<<unit
);
363 failover
->sw
->set_sampler_texture( failover
->sw
, unit
, texture
);
364 failover
->hw
->set_sampler_texture( failover
->hw
, unit
, texture
);
369 failover_set_viewport_state( struct pipe_context
*pipe
,
370 const struct pipe_viewport_state
*viewport
)
372 struct failover_context
*failover
= failover_context(pipe
);
374 failover
->viewport
= *viewport
;
375 failover
->dirty
|= FO_NEW_VIEWPORT
;
376 failover
->sw
->set_viewport_state( failover
->sw
, viewport
);
377 failover
->hw
->set_viewport_state( failover
->hw
, viewport
);
382 failover_set_vertex_buffer(struct pipe_context
*pipe
,
384 const struct pipe_vertex_buffer
*vertex_buffer
)
386 struct failover_context
*failover
= failover_context(pipe
);
388 failover
->vertex_buffer
[unit
] = *vertex_buffer
;
389 failover
->dirty
|= FO_NEW_VERTEX_BUFFER
;
390 failover
->dirty_vertex_buffer
|= (1<<unit
);
391 failover
->sw
->set_vertex_buffer( failover
->sw
, unit
, vertex_buffer
);
392 failover
->hw
->set_vertex_buffer( failover
->hw
, unit
, vertex_buffer
);
397 failover_set_vertex_element(struct pipe_context
*pipe
,
399 const struct pipe_vertex_element
*vertex_element
)
401 struct failover_context
*failover
= failover_context(pipe
);
403 failover
->vertex_element
[unit
] = *vertex_element
;
404 failover
->dirty
|= FO_NEW_VERTEX_ELEMENT
;
405 failover
->dirty_vertex_element
|= (1<<unit
);
406 failover
->sw
->set_vertex_element( failover
->sw
, unit
, vertex_element
);
407 failover
->hw
->set_vertex_element( failover
->hw
, unit
, vertex_element
);
411 failover_set_constant_buffer(struct pipe_context
*pipe
,
412 uint shader
, uint index
,
413 const struct pipe_constant_buffer
*buf
)
415 struct failover_context
*failover
= failover_context(pipe
);
417 assert(shader
< PIPE_SHADER_TYPES
);
420 failover
->sw
->set_constant_buffer(failover
->sw
, shader
, index
, buf
);
421 failover
->hw
->set_constant_buffer(failover
->hw
, shader
, index
, buf
);
426 failover_init_state_functions( struct failover_context
*failover
)
428 failover
->pipe
.create_blend_state
= failover_create_blend_state
;
429 failover
->pipe
.bind_blend_state
= failover_bind_blend_state
;
430 failover
->pipe
.delete_blend_state
= failover_delete_blend_state
;
431 failover
->pipe
.create_sampler_state
= failover_create_sampler_state
;
432 failover
->pipe
.bind_sampler_state
= failover_bind_sampler_state
;
433 failover
->pipe
.delete_sampler_state
= failover_delete_sampler_state
;
434 failover
->pipe
.create_depth_stencil_alpha_state
= failover_create_depth_stencil_state
;
435 failover
->pipe
.bind_depth_stencil_alpha_state
= failover_bind_depth_stencil_state
;
436 failover
->pipe
.delete_depth_stencil_alpha_state
= failover_delete_depth_stencil_state
;
437 failover
->pipe
.create_rasterizer_state
= failover_create_rasterizer_state
;
438 failover
->pipe
.bind_rasterizer_state
= failover_bind_rasterizer_state
;
439 failover
->pipe
.delete_rasterizer_state
= failover_delete_rasterizer_state
;
440 failover
->pipe
.create_fs_state
= failover_create_fs_state
;
441 failover
->pipe
.bind_fs_state
= failover_bind_fs_state
;
442 failover
->pipe
.delete_fs_state
= failover_delete_fs_state
;
443 failover
->pipe
.create_vs_state
= failover_create_vs_state
;
444 failover
->pipe
.bind_vs_state
= failover_bind_vs_state
;
445 failover
->pipe
.delete_vs_state
= failover_delete_vs_state
;
447 failover
->pipe
.set_blend_color
= failover_set_blend_color
;
448 failover
->pipe
.set_clip_state
= failover_set_clip_state
;
449 failover
->pipe
.set_framebuffer_state
= failover_set_framebuffer_state
;
450 failover
->pipe
.set_polygon_stipple
= failover_set_polygon_stipple
;
451 failover
->pipe
.set_scissor_state
= failover_set_scissor_state
;
452 failover
->pipe
.set_sampler_texture
= failover_set_sampler_texture
;
453 failover
->pipe
.set_viewport_state
= failover_set_viewport_state
;
454 failover
->pipe
.set_vertex_buffer
= failover_set_vertex_buffer
;
455 failover
->pipe
.set_vertex_element
= failover_set_vertex_element
;
456 failover
->pipe
.set_constant_buffer
= failover_set_constant_buffer
;