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 **************************************************************************/
28 #include "pipe/p_util.h"
29 #include "cell_context.h"
30 #include "cell_state.h"
31 #include "cell_state_emit.h"
32 #include "cell_batch.h"
33 #include "cell_texture.h"
34 #include "draw/draw_context.h"
35 #include "draw/draw_private.h"
39 emit_state_cmd(struct cell_context
*cell
, uint cmd
,
40 const void *state
, uint state_size
)
42 uint64_t *dst
= (uint64_t *)
43 cell_batch_alloc(cell
, ROUNDUP8(sizeof(uint64_t) + state_size
));
45 memcpy(dst
+ 1, state
, state_size
);
51 cell_emit_state(struct cell_context
*cell
)
53 if (cell
->dirty
& CELL_NEW_FRAMEBUFFER
) {
54 struct pipe_surface
*cbuf
= cell
->framebuffer
.cbufs
[0];
55 struct pipe_surface
*zbuf
= cell
->framebuffer
.zsbuf
;
56 struct cell_command_framebuffer
*fb
57 = cell_batch_alloc(cell
, sizeof(*fb
));
58 fb
->opcode
= CELL_CMD_STATE_FRAMEBUFFER
;
59 fb
->color_start
= cell
->cbuf_map
[0];
60 fb
->color_format
= cbuf
->format
;
61 fb
->depth_start
= cell
->zsbuf_map
;
62 fb
->depth_format
= zbuf
? zbuf
->format
: PIPE_FORMAT_NONE
;
63 fb
->width
= cell
->framebuffer
.cbufs
[0]->width
;
64 fb
->height
= cell
->framebuffer
.cbufs
[0]->height
;
67 if (cell
->dirty
& CELL_NEW_BLEND
) {
68 emit_state_cmd(cell
, CELL_CMD_STATE_BLEND
,
70 sizeof(struct pipe_blend_state
));
73 if (cell
->dirty
& CELL_NEW_DEPTH_STENCIL
) {
74 emit_state_cmd(cell
, CELL_CMD_STATE_DEPTH_STENCIL
,
76 sizeof(struct pipe_depth_stencil_alpha_state
));
79 if (cell
->dirty
& CELL_NEW_SAMPLER
) {
80 emit_state_cmd(cell
, CELL_CMD_STATE_SAMPLER
,
81 cell
->sampler
[0], sizeof(struct pipe_sampler_state
));
84 if (cell
->dirty
& CELL_NEW_TEXTURE
) {
85 struct cell_command_texture texture
;
86 if (cell
->texture
[0]) {
87 texture
.start
= cell
->texture
[0]->tiled_data
;
88 texture
.width
= cell
->texture
[0]->base
.width
[0];
89 texture
.height
= cell
->texture
[0]->base
.height
[0];
97 emit_state_cmd(cell
, CELL_CMD_STATE_TEXTURE
,
98 &texture
, sizeof(struct cell_command_texture
));
101 if (cell
->dirty
& CELL_NEW_VERTEX_INFO
) {
102 emit_state_cmd(cell
, CELL_CMD_STATE_VERTEX_INFO
,
103 &cell
->vertex_info
, sizeof(struct vertex_info
));
106 if (cell
->dirty
& CELL_NEW_VS
) {
107 const struct draw_context
*const draw
= cell
->draw
;
108 struct cell_shader_info info
;
110 info
.num_outputs
= draw
->num_vs_outputs
;
111 info
.declarations
= (uintptr_t) draw
->machine
.Declarations
;
112 info
.num_declarations
= draw
->machine
.NumDeclarations
;
113 info
.instructions
= (uintptr_t) draw
->machine
.Instructions
;
114 info
.num_instructions
= draw
->machine
.NumInstructions
;
115 info
.immediates
= (uintptr_t) draw
->machine
.Imms
;
116 info
.num_immediates
= draw
->machine
.ImmLimit
/ 4;
118 emit_state_cmd(cell
, CELL_CMD_STATE_BIND_VS
,
119 & info
, sizeof(info
));