summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/failover/fo_state_emit.c
blob: 42bd6929a7fbe3433d66d9cbc31a28a589148b3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/**************************************************************************
 * 
 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 * 
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 **************************************************************************/

/* Authors:  Keith Whitwell <keith@tungstengraphics.com>
 */

#include "fo_context.h"

/* This looks like a lot of work at the moment - we're keeping a
 * duplicate copy of the state up-to-date.  
 *
 * This can change in two ways:
 * - With constant state objects we would only need to save a pointer,
 *     not the whole object.
 * - By adding a callback in the state tracker to re-emit state.  The
 *     state tracker knows the current state already and can re-emit it 
 *     without additional complexity.
 *
 * This works as a proof-of-concept, but a final version will have
 * lower overheads.
 */


/* Bring the software pipe uptodate with current state.
 * 
 * With constant state objects we would probably just send all state
 * to both rasterizers all the time???
 */
void
failover_state_emit( struct failover_context *failover )
{
   if (failover->dirty & FO_NEW_BLEND)
      failover->sw->bind_blend_state( failover->sw,
                                      failover->blend->sw_state );

   if (failover->dirty & FO_NEW_BLEND_COLOR)
      failover->sw->set_blend_color( failover->sw, &failover->blend_color );

   if (failover->dirty & FO_NEW_CLIP)
      failover->sw->set_clip_state( failover->sw, &failover->clip );

   if (failover->dirty & FO_NEW_DEPTH_STENCIL)
      failover->sw->bind_depth_stencil_alpha_state( failover->sw,
                                                    failover->depth_stencil->sw_state );

   if (failover->dirty & FO_NEW_STENCIL_REF)
      failover->sw->set_stencil_ref( failover->sw, &failover->stencil_ref );

   if (failover->dirty & FO_NEW_FRAMEBUFFER)
      failover->sw->set_framebuffer_state( failover->sw, &failover->framebuffer );

   if (failover->dirty & FO_NEW_FRAGMENT_SHADER)
      failover->sw->bind_fs_state( failover->sw,
                                   failover->fragment_shader->sw_state );

   if (failover->dirty & FO_NEW_VERTEX_SHADER)
      failover->sw->bind_vs_state( failover->sw,
                                   failover->vertex_shader->sw_state );

   if (failover->dirty & FO_NEW_VERTEX_ELEMENT)
      failover->sw->bind_vertex_elements_state( failover->sw,
                                                failover->vertex_elements->sw_state );

   if (failover->dirty & FO_NEW_STIPPLE)
      failover->sw->set_polygon_stipple( failover->sw, &failover->poly_stipple );

   if (failover->dirty & FO_NEW_RASTERIZER)
      failover->sw->bind_rasterizer_state( failover->sw,
                                           failover->rasterizer->sw_state );

   if (failover->dirty & FO_NEW_SCISSOR)
      failover->sw->set_scissor_state( failover->sw, &failover->scissor );

   if (failover->dirty & FO_NEW_VIEWPORT)
      failover->sw->set_viewport_state( failover->sw, &failover->viewport );

   if (failover->dirty & FO_NEW_SAMPLER) {
      failover->sw->bind_fragment_sampler_states( failover->sw, failover->num_samplers,
                                                  failover->sw_sampler_state );
      failover->sw->bind_vertex_sampler_states(failover->sw,
                                               failover->num_vertex_samplers,
                                               failover->sw_vertex_sampler_state);
   }

   if (failover->dirty & FO_NEW_SAMPLER_VIEW) {
      struct pipe_sampler_view *fragment_views[PIPE_MAX_SAMPLERS];
      struct pipe_sampler_view *vertex_views[PIPE_MAX_VERTEX_SAMPLERS];
      uint i;

      for (i = 0; i < failover->num_fragment_sampler_views; i++) {
         fragment_views[i] = failover->fragment_sampler_views[i]->sw;
      }
      failover->sw->set_fragment_sampler_views(failover->sw,
                                               failover->num_fragment_sampler_views,
                                               fragment_views);

      for (i = 0; i < failover->num_vertex_sampler_views; i++) {
         vertex_views[i] = failover->vertex_sampler_views[i]->sw;
      }
      failover->sw->set_vertex_sampler_views(failover->sw,
                                             failover->num_vertex_sampler_views,
                                             vertex_views);
   }

   if (failover->dirty & FO_NEW_VERTEX_BUFFER) {
      failover->sw->set_vertex_buffers( failover->sw,
                                        failover->num_vertex_buffers,
                                        failover->vertex_buffers );
   }

   failover->dirty = 0;
}