1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
33 #include "util/u_memory.h"
34 #include "util/u_inlines.h"
35 #include "draw/draw_context.h"
36 #include "cell_context.h"
37 #include "cell_flush.h"
38 #include "cell_pipe_state.h"
39 #include "cell_state.h"
40 #include "cell_texture.h"
45 cell_create_blend_state(struct pipe_context
*pipe
,
46 const struct pipe_blend_state
*blend
)
48 return mem_dup(blend
, sizeof(*blend
));
53 cell_bind_blend_state(struct pipe_context
*pipe
, void *blend
)
55 struct cell_context
*cell
= cell_context(pipe
);
57 draw_flush(cell
->draw
);
59 cell
->blend
= (struct pipe_blend_state
*) blend
;
60 cell
->dirty
|= CELL_NEW_BLEND
;
65 cell_delete_blend_state(struct pipe_context
*pipe
, void *blend
)
72 cell_set_blend_color(struct pipe_context
*pipe
,
73 const struct pipe_blend_color
*blend_color
)
75 struct cell_context
*cell
= cell_context(pipe
);
77 draw_flush(cell
->draw
);
79 cell
->blend_color
= *blend_color
;
81 cell
->dirty
|= CELL_NEW_BLEND
;
88 cell_create_depth_stencil_alpha_state(struct pipe_context
*pipe
,
89 const struct pipe_depth_stencil_alpha_state
*dsa
)
91 return mem_dup(dsa
, sizeof(*dsa
));
96 cell_bind_depth_stencil_alpha_state(struct pipe_context
*pipe
,
99 struct cell_context
*cell
= cell_context(pipe
);
101 draw_flush(cell
->draw
);
103 cell
->depth_stencil
= (struct pipe_depth_stencil_alpha_state
*) dsa
;
104 cell
->dirty
|= CELL_NEW_DEPTH_STENCIL
;
109 cell_delete_depth_stencil_alpha_state(struct pipe_context
*pipe
, void *dsa
)
116 cell_set_stencil_ref(struct pipe_context
*pipe
,
117 const struct pipe_stencil_ref
*stencil_ref
)
119 struct cell_context
*cell
= cell_context(pipe
);
121 draw_flush(cell
->draw
);
123 cell
->stencil_ref
= *stencil_ref
;
125 cell
->dirty
|= CELL_NEW_DEPTH_STENCIL
;
129 cell_set_clip_state(struct pipe_context
*pipe
,
130 const struct pipe_clip_state
*clip
)
132 struct cell_context
*cell
= cell_context(pipe
);
134 /* pass the clip state to the draw module */
135 draw_set_clip_state(cell
->draw
, clip
);
140 /* Called when driver state tracker notices changes to the viewport
144 cell_set_viewport_state( struct pipe_context
*pipe
,
145 const struct pipe_viewport_state
*viewport
)
147 struct cell_context
*cell
= cell_context(pipe
);
149 cell
->viewport
= *viewport
; /* struct copy */
150 cell
->dirty
|= CELL_NEW_VIEWPORT
;
152 /* pass the viewport info to the draw module */
153 draw_set_viewport_state(cell
->draw
, viewport
);
155 /* Using tnl/ and vf/ modules is temporary while getting started.
156 * Full pipe will have vertex shader, vertex fetch of its own.
162 cell_set_scissor_state( struct pipe_context
*pipe
,
163 const struct pipe_scissor_state
*scissor
)
165 struct cell_context
*cell
= cell_context(pipe
);
167 memcpy( &cell
->scissor
, scissor
, sizeof(*scissor
) );
168 cell
->dirty
|= CELL_NEW_SCISSOR
;
173 cell_set_polygon_stipple( struct pipe_context
*pipe
,
174 const struct pipe_poly_stipple
*stipple
)
176 struct cell_context
*cell
= cell_context(pipe
);
178 memcpy( &cell
->poly_stipple
, stipple
, sizeof(*stipple
) );
179 cell
->dirty
|= CELL_NEW_STIPPLE
;
185 cell_create_rasterizer_state(struct pipe_context
*pipe
,
186 const struct pipe_rasterizer_state
*rasterizer
)
188 return mem_dup(rasterizer
, sizeof(*rasterizer
));
193 cell_bind_rasterizer_state(struct pipe_context
*pipe
, void *rast
)
195 struct pipe_rasterizer_state
*rasterizer
=
196 (struct pipe_rasterizer_state
*) rast
;
197 struct cell_context
*cell
= cell_context(pipe
);
199 /* pass-through to draw module */
200 draw_set_rasterizer_state(cell
->draw
, rasterizer
);
202 cell
->rasterizer
= rasterizer
;
204 cell
->dirty
|= CELL_NEW_RASTERIZER
;
209 cell_delete_rasterizer_state(struct pipe_context
*pipe
, void *rasterizer
)
217 cell_create_sampler_state(struct pipe_context
*pipe
,
218 const struct pipe_sampler_state
*sampler
)
220 return mem_dup(sampler
, sizeof(*sampler
));
225 cell_bind_sampler_states(struct pipe_context
*pipe
,
226 unsigned num
, void **samplers
)
228 struct cell_context
*cell
= cell_context(pipe
);
229 uint i
, changed
= 0x0;
231 assert(num
<= CELL_MAX_SAMPLERS
);
233 draw_flush(cell
->draw
);
235 for (i
= 0; i
< CELL_MAX_SAMPLERS
; i
++) {
236 struct pipe_sampler_state
*new_samp
= i
< num
? samplers
[i
] : NULL
;
237 if (cell
->sampler
[i
] != new_samp
) {
238 cell
->sampler
[i
] = new_samp
;
244 cell
->dirty
|= CELL_NEW_SAMPLER
;
245 cell
->dirty_samplers
|= changed
;
251 cell_delete_sampler_state(struct pipe_context
*pipe
,
260 cell_set_sampler_textures(struct pipe_context
*pipe
,
261 unsigned num
, struct pipe_texture
**texture
)
263 struct cell_context
*cell
= cell_context(pipe
);
264 uint i
, changed
= 0x0;
266 assert(num
<= CELL_MAX_SAMPLERS
);
268 for (i
= 0; i
< CELL_MAX_SAMPLERS
; i
++) {
269 struct cell_texture
*new_tex
= cell_texture(i
< num
? texture
[i
] : NULL
);
270 struct cell_texture
*old_tex
= cell
->texture
[i
];
271 if (old_tex
!= new_tex
) {
273 pipe_texture_reference((struct pipe_texture
**) &cell
->texture
[i
],
274 (struct pipe_texture
*) new_tex
);
280 cell
->num_textures
= num
;
283 cell
->dirty
|= CELL_NEW_TEXTURE
;
284 cell
->dirty_textures
|= changed
;
290 * Map color and z/stencil framebuffer surfaces.
293 cell_map_surfaces(struct cell_context
*cell
)
295 struct pipe_screen
*screen
= cell
->pipe
.screen
;
298 for (i
= 0; i
< 1; i
++) {
299 struct pipe_surface
*ps
= cell
->framebuffer
.cbufs
[i
];
301 struct cell_texture
*ct
= cell_texture(ps
->texture
);
302 cell
->cbuf_map
[i
] = screen
->buffer_map(screen
,
304 (PIPE_BUFFER_USAGE_GPU_READ
|
305 PIPE_BUFFER_USAGE_GPU_WRITE
));
310 struct pipe_surface
*ps
= cell
->framebuffer
.zsbuf
;
312 struct cell_texture
*ct
= cell_texture(ps
->texture
);
313 cell
->zsbuf_map
= screen
->buffer_map(screen
,
315 (PIPE_BUFFER_USAGE_GPU_READ
|
316 PIPE_BUFFER_USAGE_GPU_WRITE
));
323 * Unmap color and z/stencil framebuffer surfaces.
326 cell_unmap_surfaces(struct cell_context
*cell
)
328 struct pipe_screen
*screen
= cell
->pipe
.screen
;
331 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
332 struct pipe_surface
*ps
= cell
->framebuffer
.cbufs
[i
];
333 if (ps
&& cell
->cbuf_map
[i
]) {
334 struct cell_texture
*ct
= cell_texture(ps
->texture
);
338 screen
->buffer_unmap(screen
, ct
->buffer
);
339 cell
->cbuf_map
[i
] = NULL
;
344 struct pipe_surface
*ps
= cell
->framebuffer
.zsbuf
;
345 if (ps
&& cell
->zsbuf_map
) {
346 struct cell_texture
*ct
= cell_texture(ps
->texture
);
347 screen
->buffer_unmap(screen
, ct
->buffer
);
348 cell
->zsbuf_map
= NULL
;
355 cell_set_framebuffer_state(struct pipe_context
*pipe
,
356 const struct pipe_framebuffer_state
*fb
)
358 struct cell_context
*cell
= cell_context(pipe
);
360 if (1 /*memcmp(&cell->framebuffer, fb, sizeof(*fb))*/) {
363 /* unmap old surfaces */
364 cell_unmap_surfaces(cell
);
366 /* Finish any pending rendering to the current surface before
367 * installing a new surface!
369 cell_flush_int(cell
, CELL_FLUSH_WAIT
);
372 * (this is also where old surfaces will finally get freed)
374 cell
->framebuffer
.width
= fb
->width
;
375 cell
->framebuffer
.height
= fb
->height
;
376 cell
->framebuffer
.nr_cbufs
= fb
->nr_cbufs
;
377 for (i
= 0; i
< PIPE_MAX_COLOR_BUFS
; i
++) {
378 pipe_surface_reference(&cell
->framebuffer
.cbufs
[i
], fb
->cbufs
[i
]);
380 pipe_surface_reference(&cell
->framebuffer
.zsbuf
, fb
->zsbuf
);
382 /* map new surfaces */
383 cell_map_surfaces(cell
);
385 cell
->dirty
|= CELL_NEW_FRAMEBUFFER
;
392 cell_init_state_functions(struct cell_context
*cell
)
394 cell
->pipe
.create_blend_state
= cell_create_blend_state
;
395 cell
->pipe
.bind_blend_state
= cell_bind_blend_state
;
396 cell
->pipe
.delete_blend_state
= cell_delete_blend_state
;
398 cell
->pipe
.create_sampler_state
= cell_create_sampler_state
;
399 cell
->pipe
.bind_fragment_sampler_states
= cell_bind_sampler_states
;
400 cell
->pipe
.delete_sampler_state
= cell_delete_sampler_state
;
402 cell
->pipe
.set_fragment_sampler_textures
= cell_set_sampler_textures
;
404 cell
->pipe
.create_depth_stencil_alpha_state
= cell_create_depth_stencil_alpha_state
;
405 cell
->pipe
.bind_depth_stencil_alpha_state
= cell_bind_depth_stencil_alpha_state
;
406 cell
->pipe
.delete_depth_stencil_alpha_state
= cell_delete_depth_stencil_alpha_state
;
408 cell
->pipe
.create_rasterizer_state
= cell_create_rasterizer_state
;
409 cell
->pipe
.bind_rasterizer_state
= cell_bind_rasterizer_state
;
410 cell
->pipe
.delete_rasterizer_state
= cell_delete_rasterizer_state
;
412 cell
->pipe
.set_blend_color
= cell_set_blend_color
;
413 cell
->pipe
.set_stencil_ref
= cell_set_stencil_ref
;
414 cell
->pipe
.set_clip_state
= cell_set_clip_state
;
416 cell
->pipe
.set_framebuffer_state
= cell_set_framebuffer_state
;
418 cell
->pipe
.set_polygon_stipple
= cell_set_polygon_stipple
;
419 cell
->pipe
.set_scissor_state
= cell_set_scissor_state
;
420 cell
->pipe
.set_viewport_state
= cell_set_viewport_state
;