r600g: mipmap early support + EX2/ABS instruction + culling
[mesa.git] / src / gallium / drivers / failover / fo_context.c
1 /**************************************************************************
2 *
3 * Copyright 2003 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
29 #include "pipe/p_defines.h"
30 #include "util/u_memory.h"
31 #include "pipe/p_context.h"
32
33 #include "fo_context.h"
34 #include "fo_winsys.h"
35
36
37
38 static void failover_destroy( struct pipe_context *pipe )
39 {
40 struct failover_context *failover = failover_context( pipe );
41
42 FREE( failover );
43 }
44
45
46 void failover_fail_over( struct failover_context *failover )
47 {
48 failover->dirty = TRUE;
49 failover->mode = FO_SW;
50 }
51
52
53 static void failover_draw_vbo( struct pipe_context *pipe,
54 const struct pipe_draw_info *info)
55 {
56 struct failover_context *failover = failover_context( pipe );
57
58 /* If there has been any statechange since last time, try hardware
59 * rendering again:
60 */
61 if (failover->dirty) {
62 failover->mode = FO_HW;
63 }
64
65 /* Try hardware:
66 */
67 if (failover->mode == FO_HW) {
68 failover->hw->draw_vbo( failover->hw, info );
69 }
70
71 /* Possibly try software:
72 */
73 if (failover->mode == FO_SW) {
74
75 if (failover->dirty) {
76 failover->hw->flush( failover->hw, ~0, NULL );
77 failover_state_emit( failover );
78 }
79
80 failover->sw->draw_vbo( failover->sw, info );
81
82 /* Be ready to switch back to hardware rendering without an
83 * intervening flush. Unlikely to be much performance impact to
84 * this:
85 */
86 failover->sw->flush( failover->sw, ~0, NULL );
87 }
88 }
89
90 static unsigned int
91 failover_is_resource_referenced( struct pipe_context *_pipe,
92 struct pipe_resource *resource,
93 unsigned face, unsigned level)
94 {
95 struct failover_context *failover = failover_context( _pipe );
96 struct pipe_context *pipe = (failover->mode == FO_HW) ?
97 failover->hw : failover->sw;
98
99 return pipe->is_resource_referenced(pipe, resource, face, level);
100 }
101
102 struct pipe_context *failover_create( struct pipe_context *hw,
103 struct pipe_context *sw )
104 {
105 struct failover_context *failover = CALLOC_STRUCT(failover_context);
106 if (failover == NULL)
107 return NULL;
108
109 failover->hw = hw;
110 failover->sw = sw;
111 failover->pipe.winsys = hw->winsys;
112 failover->pipe.screen = hw->screen;
113 failover->pipe.destroy = failover_destroy;
114 #if 0
115 failover->pipe.is_format_supported = hw->is_format_supported;
116 failover->pipe.get_name = hw->get_name;
117 failover->pipe.get_vendor = hw->get_vendor;
118 failover->pipe.get_param = hw->get_param;
119 failover->pipe.get_paramf = hw->get_paramf;
120 #endif
121
122 failover->pipe.draw_vbo = failover_draw_vbo;
123 failover->pipe.clear = hw->clear;
124 failover->pipe.clear_render_target = hw->clear_render_target;
125 failover->pipe.clear_depth_stencil = hw->clear_depth_stencil;
126
127 /* No software occlusion fallback (or other optional functionality)
128 * at this point - if the hardware doesn't support it, don't
129 * advertise it to the application.
130 */
131 failover->pipe.begin_query = hw->begin_query;
132 failover->pipe.end_query = hw->end_query;
133
134 failover_init_state_functions( failover );
135
136 failover->pipe.resource_copy_region = hw->resource_copy_region;
137
138 #if 0
139 failover->pipe.texture_create = hw->texture_create;
140 failover->pipe.texture_destroy = hw->texture_destroy;
141 failover->pipe.get_tex_surface = hw->get_tex_surface;
142 failover->pipe.texture_update = hw->texture_update;
143 #endif
144
145 failover->pipe.flush = hw->flush;
146 failover->pipe.is_resource_referenced = failover_is_resource_referenced;
147
148 failover->dirty = 0;
149
150 return &failover->pipe;
151 }
152