svga: add svga_have_gb_objects/dma() functions
[mesa.git] / src / gallium / drivers / svga / svga_pipe_misc.c
1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 **********************************************************/
25
26 #include "svga_cmd.h"
27
28 #include "util/u_inlines.h"
29
30 #include "svga_context.h"
31 #include "svga_screen.h"
32 #include "svga_surface.h"
33
34
35 static void svga_set_scissor_states( struct pipe_context *pipe,
36 unsigned start_slot,
37 unsigned num_scissors,
38 const struct pipe_scissor_state *scissors )
39 {
40 struct svga_context *svga = svga_context(pipe);
41
42 memcpy( &svga->curr.scissor, scissors, sizeof(*scissors) );
43 svga->dirty |= SVGA_NEW_SCISSOR;
44 }
45
46
47 static void svga_set_polygon_stipple( struct pipe_context *pipe,
48 const struct pipe_poly_stipple *stipple )
49 {
50 /* overridden by the draw module */
51 }
52
53
54 void svga_cleanup_framebuffer(struct svga_context *svga)
55 {
56 struct svga_screen *svgascreen = svga_screen(svga->pipe.screen);
57 struct pipe_framebuffer_state *curr = &svga->curr.framebuffer;
58 struct pipe_framebuffer_state *hw = &svga->state.hw_clear.framebuffer;
59 unsigned i;
60
61 for (i = 0; i < svgascreen->max_color_buffers; i++) {
62 pipe_surface_reference(&curr->cbufs[i], NULL);
63 pipe_surface_reference(&hw->cbufs[i], NULL);
64 }
65
66 pipe_surface_reference(&curr->zsbuf, NULL);
67 pipe_surface_reference(&hw->zsbuf, NULL);
68 }
69
70
71 #define DEPTH_BIAS_SCALE_FACTOR_D16 ((float)(1<<15))
72 #define DEPTH_BIAS_SCALE_FACTOR_D24S8 ((float)(1<<23))
73 #define DEPTH_BIAS_SCALE_FACTOR_D32 ((float)(1<<31))
74
75
76 static void svga_set_framebuffer_state(struct pipe_context *pipe,
77 const struct pipe_framebuffer_state *fb)
78 {
79 struct svga_context *svga = svga_context(pipe);
80 struct pipe_framebuffer_state *dst = &svga->curr.framebuffer;
81 boolean propagate = FALSE;
82 unsigned i;
83
84 dst->width = fb->width;
85 dst->height = fb->height;
86 dst->nr_cbufs = fb->nr_cbufs;
87
88 /* check if we need to propagate any of the target surfaces */
89 for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
90 if (dst->cbufs[i] && dst->cbufs[i] != fb->cbufs[i])
91 if (svga_surface_needs_propagation(dst->cbufs[i]))
92 propagate = TRUE;
93 }
94
95 if (propagate) {
96 /* make sure that drawing calls comes before propagation calls */
97 svga_hwtnl_flush_retry( svga );
98
99 for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++)
100 if (dst->cbufs[i] && dst->cbufs[i] != fb->cbufs[i])
101 svga_propagate_surface(svga, dst->cbufs[i]);
102 }
103
104 /* XXX: Actually the virtual hardware may support rendertargets with
105 * different size, depending on the host API and driver, but since we cannot
106 * know that make no such assumption here. */
107 for(i = 0; i < fb->nr_cbufs; ++i) {
108 if (fb->zsbuf && fb->cbufs[i]) {
109 assert(fb->zsbuf->width == fb->cbufs[i]->width);
110 assert(fb->zsbuf->height == fb->cbufs[i]->height);
111 }
112 }
113
114 for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
115 pipe_surface_reference(&dst->cbufs[i],
116 (i < fb->nr_cbufs) ? fb->cbufs[i] : NULL);
117 }
118 pipe_surface_reference(&dst->zsbuf, fb->zsbuf);
119
120
121 if (svga->curr.framebuffer.zsbuf)
122 {
123 switch (svga->curr.framebuffer.zsbuf->format) {
124 case PIPE_FORMAT_Z16_UNORM:
125 svga->curr.depthscale = 1.0f / DEPTH_BIAS_SCALE_FACTOR_D16;
126 break;
127 case PIPE_FORMAT_Z24_UNORM_S8_UINT:
128 case PIPE_FORMAT_Z24X8_UNORM:
129 case PIPE_FORMAT_S8_UINT_Z24_UNORM:
130 case PIPE_FORMAT_X8Z24_UNORM:
131 svga->curr.depthscale = 1.0f / DEPTH_BIAS_SCALE_FACTOR_D24S8;
132 break;
133 case PIPE_FORMAT_Z32_UNORM:
134 svga->curr.depthscale = 1.0f / DEPTH_BIAS_SCALE_FACTOR_D32;
135 break;
136 case PIPE_FORMAT_Z32_FLOAT:
137 svga->curr.depthscale = 1.0f / ((float)(1<<23));
138 break;
139 default:
140 svga->curr.depthscale = 0.0f;
141 break;
142 }
143 }
144 else {
145 svga->curr.depthscale = 0.0f;
146 }
147
148 svga->dirty |= SVGA_NEW_FRAME_BUFFER;
149 }
150
151
152
153 static void svga_set_clip_state( struct pipe_context *pipe,
154 const struct pipe_clip_state *clip )
155 {
156 struct svga_context *svga = svga_context(pipe);
157
158 svga->curr.clip = *clip; /* struct copy */
159
160 svga->dirty |= SVGA_NEW_CLIP;
161 }
162
163
164
165 /* Called when driver state tracker notices changes to the viewport
166 * matrix:
167 */
168 static void svga_set_viewport_states( struct pipe_context *pipe,
169 unsigned start_slot,
170 unsigned num_viewports,
171 const struct pipe_viewport_state *viewports )
172 {
173 struct svga_context *svga = svga_context(pipe);
174
175 svga->curr.viewport = *viewports; /* struct copy */
176
177 svga->dirty |= SVGA_NEW_VIEWPORT;
178 }
179
180
181
182 void svga_init_misc_functions( struct svga_context *svga )
183 {
184 svga->pipe.set_scissor_states = svga_set_scissor_states;
185 svga->pipe.set_polygon_stipple = svga_set_polygon_stipple;
186 svga->pipe.set_framebuffer_state = svga_set_framebuffer_state;
187 svga->pipe.set_clip_state = svga_set_clip_state;
188 svga->pipe.set_viewport_states = svga_set_viewport_states;
189 }
190
191