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