cell: remove unneeded blend/depth_stencil subclasses
[mesa.git] / src / gallium / drivers / cell / ppu / cell_pipe_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:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 * Brian Paul
31 */
32
33 #include "util/u_memory.h"
34 #include "pipe/p_inlines.h"
35 #include "draw/draw_context.h"
36 #include "cell_context.h"
37 #include "cell_flush.h"
38 #include "cell_state.h"
39 #include "cell_texture.h"
40
41
42
43 static void *
44 cell_create_blend_state(struct pipe_context *pipe,
45 const struct pipe_blend_state *blend)
46 {
47 return mem_dup(blend, sizeof(*blend));
48 }
49
50
51 static void
52 cell_bind_blend_state(struct pipe_context *pipe, void *state)
53 {
54 struct cell_context *cell = cell_context(pipe);
55
56 draw_flush(cell->draw);
57
58 cell->blend = (struct pipe_blend_state *) state;
59 cell->dirty |= CELL_NEW_BLEND;
60 }
61
62
63 static void
64 cell_delete_blend_state(struct pipe_context *pipe, void *blend)
65 {
66 FREE(blend);
67 }
68
69
70 static void
71 cell_set_blend_color(struct pipe_context *pipe,
72 const struct pipe_blend_color *blend_color)
73 {
74 struct cell_context *cell = cell_context(pipe);
75
76 draw_flush(cell->draw);
77
78 cell->blend_color = *blend_color;
79
80 cell->dirty |= CELL_NEW_BLEND;
81 }
82
83
84
85
86 static void *
87 cell_create_depth_stencil_alpha_state(struct pipe_context *pipe,
88 const struct pipe_depth_stencil_alpha_state *dsa)
89 {
90 return mem_dup(dsa, sizeof(*dsa));
91 }
92
93
94 static void
95 cell_bind_depth_stencil_alpha_state(struct pipe_context *pipe,
96 void *dsa)
97 {
98 struct cell_context *cell = cell_context(pipe);
99
100 draw_flush(cell->draw);
101
102 cell->depth_stencil = (struct pipe_depth_stencil_alpha_state *) dsa;
103 cell->dirty |= CELL_NEW_DEPTH_STENCIL;
104 }
105
106
107 static void
108 cell_delete_depth_stencil_alpha_state(struct pipe_context *pipe, void *dsa)
109 {
110 FREE(dsa);
111 }
112
113
114 static void
115 cell_set_clip_state(struct pipe_context *pipe,
116 const struct pipe_clip_state *clip)
117 {
118 struct cell_context *cell = cell_context(pipe);
119
120 /* pass the clip state to the draw module */
121 draw_set_clip_state(cell->draw, clip);
122 }
123
124
125
126 /* Called when driver state tracker notices changes to the viewport
127 * matrix:
128 */
129 static void
130 cell_set_viewport_state( struct pipe_context *pipe,
131 const struct pipe_viewport_state *viewport )
132 {
133 struct cell_context *cell = cell_context(pipe);
134
135 cell->viewport = *viewport; /* struct copy */
136 cell->dirty |= CELL_NEW_VIEWPORT;
137
138 /* pass the viewport info to the draw module */
139 draw_set_viewport_state(cell->draw, viewport);
140
141 /* Using tnl/ and vf/ modules is temporary while getting started.
142 * Full pipe will have vertex shader, vertex fetch of its own.
143 */
144 }
145
146
147 static void
148 cell_set_scissor_state( struct pipe_context *pipe,
149 const struct pipe_scissor_state *scissor )
150 {
151 struct cell_context *cell = cell_context(pipe);
152
153 memcpy( &cell->scissor, scissor, sizeof(*scissor) );
154 cell->dirty |= CELL_NEW_SCISSOR;
155 }
156
157
158 static void
159 cell_set_polygon_stipple( struct pipe_context *pipe,
160 const struct pipe_poly_stipple *stipple )
161 {
162 struct cell_context *cell = cell_context(pipe);
163
164 memcpy( &cell->poly_stipple, stipple, sizeof(*stipple) );
165 cell->dirty |= CELL_NEW_STIPPLE;
166 }
167
168
169
170 static void *
171 cell_create_rasterizer_state(struct pipe_context *pipe,
172 const struct pipe_rasterizer_state *setup)
173 {
174 struct pipe_rasterizer_state *state
175 = MALLOC(sizeof(struct pipe_rasterizer_state));
176 memcpy(state, setup, sizeof(struct pipe_rasterizer_state));
177 return state;
178 }
179
180
181 static void
182 cell_bind_rasterizer_state(struct pipe_context *pipe, void *setup)
183 {
184 struct cell_context *cell = cell_context(pipe);
185
186 /* pass-through to draw module */
187 draw_set_rasterizer_state(cell->draw, setup);
188
189 cell->rasterizer = (struct pipe_rasterizer_state *)setup;
190
191 cell->dirty |= CELL_NEW_RASTERIZER;
192 }
193
194
195 static void
196 cell_delete_rasterizer_state(struct pipe_context *pipe, void *rasterizer)
197 {
198 FREE(rasterizer);
199 }
200
201
202
203 static void *
204 cell_create_sampler_state(struct pipe_context *pipe,
205 const struct pipe_sampler_state *sampler)
206 {
207 return mem_dup(sampler, sizeof(*sampler));
208 }
209
210
211 static void
212 cell_bind_sampler_states(struct pipe_context *pipe,
213 unsigned num, void **samplers)
214 {
215 struct cell_context *cell = cell_context(pipe);
216
217 assert(num <= CELL_MAX_SAMPLERS);
218
219 draw_flush(cell->draw);
220
221 memcpy(cell->sampler, samplers, num * sizeof(void *));
222 memset(&cell->sampler[num], 0, (CELL_MAX_SAMPLERS - num) *
223 sizeof(void *));
224 cell->num_samplers = num;
225
226 cell->dirty |= CELL_NEW_SAMPLER;
227 }
228
229
230 static void
231 cell_delete_sampler_state(struct pipe_context *pipe,
232 void *sampler)
233 {
234 FREE( sampler );
235 }
236
237
238
239 static void
240 cell_set_sampler_textures(struct pipe_context *pipe,
241 unsigned num, struct pipe_texture **texture)
242 {
243 struct cell_context *cell = cell_context(pipe);
244 uint i;
245
246 assert(num <= CELL_MAX_SAMPLERS);
247
248 /* Check for no-op */
249 if (num == cell->num_textures &&
250 !memcmp(cell->texture, texture, num * sizeof(struct pipe_texture *)))
251 return;
252
253 draw_flush(cell->draw);
254
255 for (i = 0; i < CELL_MAX_SAMPLERS; i++) {
256 struct pipe_texture *tex = i < num ? texture[i] : NULL;
257
258 pipe_texture_reference((struct pipe_texture **) &cell->texture[i], tex);
259 }
260 cell->num_textures = num;
261
262 cell_update_texture_mapping(cell);
263
264 cell->dirty |= CELL_NEW_TEXTURE;
265 }
266
267
268
269 static void
270 cell_set_framebuffer_state(struct pipe_context *pipe,
271 const struct pipe_framebuffer_state *fb)
272 {
273 struct cell_context *cell = cell_context(pipe);
274
275 if (1 /*memcmp(&cell->framebuffer, fb, sizeof(*fb))*/) {
276 struct pipe_surface *csurf = fb->cbufs[0];
277 struct pipe_surface *zsurf = fb->zsbuf;
278 uint i;
279 uint flags = (PIPE_BUFFER_USAGE_GPU_WRITE |
280 PIPE_BUFFER_USAGE_GPU_READ);
281
282 /* unmap old surfaces */
283 for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
284 if (cell->framebuffer.cbufs[i] && cell->cbuf_map[i]) {
285 pipe_surface_unmap(cell->framebuffer.cbufs[i]);
286 cell->cbuf_map[i] = NULL;
287 }
288 }
289
290 if (cell->framebuffer.zsbuf && cell->zsbuf_map) {
291 pipe_surface_unmap(cell->framebuffer.zsbuf);
292 cell->zsbuf_map = NULL;
293 }
294
295 /* Finish any pending rendering to the current surface before
296 * installing a new surface!
297 */
298 cell_flush_int(cell, CELL_FLUSH_WAIT);
299
300 /* update my state
301 * (this is also where old surfaces will finally get freed)
302 */
303 cell->framebuffer.width = fb->width;
304 cell->framebuffer.height = fb->height;
305 cell->framebuffer.num_cbufs = fb->num_cbufs;
306 for (i = 0; i < PIPE_MAX_COLOR_BUFS; i++) {
307 pipe_surface_reference(&cell->framebuffer.cbufs[i], fb->cbufs[i]);
308 }
309 pipe_surface_reference(&cell->framebuffer.zsbuf, fb->zsbuf);
310
311 /* map new surfaces */
312 if (csurf)
313 cell->cbuf_map[0] = pipe_surface_map(csurf, flags);
314
315 if (zsurf)
316 cell->zsbuf_map = pipe_surface_map(zsurf, flags);
317
318 cell->dirty |= CELL_NEW_FRAMEBUFFER;
319 }
320 }
321
322
323
324 void
325 cell_init_state_functions(struct cell_context *cell)
326 {
327 cell->pipe.create_blend_state = cell_create_blend_state;
328 cell->pipe.bind_blend_state = cell_bind_blend_state;
329 cell->pipe.delete_blend_state = cell_delete_blend_state;
330
331 cell->pipe.create_sampler_state = cell_create_sampler_state;
332 cell->pipe.bind_sampler_states = cell_bind_sampler_states;
333 cell->pipe.delete_sampler_state = cell_delete_sampler_state;
334
335 cell->pipe.set_sampler_textures = cell_set_sampler_textures;
336
337 cell->pipe.create_depth_stencil_alpha_state = cell_create_depth_stencil_alpha_state;
338 cell->pipe.bind_depth_stencil_alpha_state = cell_bind_depth_stencil_alpha_state;
339 cell->pipe.delete_depth_stencil_alpha_state = cell_delete_depth_stencil_alpha_state;
340
341 cell->pipe.create_rasterizer_state = cell_create_rasterizer_state;
342 cell->pipe.bind_rasterizer_state = cell_bind_rasterizer_state;
343 cell->pipe.delete_rasterizer_state = cell_delete_rasterizer_state;
344
345 cell->pipe.set_blend_color = cell_set_blend_color;
346 cell->pipe.set_clip_state = cell_set_clip_state;
347
348 cell->pipe.set_framebuffer_state = cell_set_framebuffer_state;
349
350 cell->pipe.set_polygon_stipple = cell_set_polygon_stipple;
351 cell->pipe.set_scissor_state = cell_set_scissor_state;
352 cell->pipe.set_viewport_state = cell_set_viewport_state;
353 }