cell: keep track of num_vertex_attribs/buffers for shorter loops
[mesa.git] / src / gallium / drivers / cell / ppu / cell_context.h
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
29 #ifndef CELL_CONTEXT_H
30 #define CELL_CONTEXT_H
31
32
33 #include "pipe/p_context.h"
34 #include "pipe/p_defines.h"
35 #include "draw/draw_vertex.h"
36 #include "draw/draw_vbuf.h"
37 #include "cell_winsys.h"
38 #include "cell/common.h"
39 #include "rtasm/rtasm_ppc_spe.h"
40 #include "tgsi/util/tgsi_scan.h"
41
42 struct cell_vbuf_render;
43
44 struct cell_vertex_shader_state
45 {
46 struct pipe_shader_state shader;
47 struct tgsi_shader_info info;
48 void *draw_data;
49 };
50
51
52 struct cell_fragment_shader_state
53 {
54 struct pipe_shader_state shader;
55 struct tgsi_shader_info info;
56 void *data;
57 };
58
59
60 struct cell_blend_state {
61 struct pipe_blend_state base;
62
63 /**
64 * Generated code to perform alpha blending
65 */
66 struct spe_function code;
67 };
68
69
70 struct cell_depth_stencil_alpha_state {
71 struct pipe_depth_stencil_alpha_state base;
72
73 /**
74 * Generated code to perform alpha, stencil, and depth testing on the SPE
75 */
76 struct spe_function code;
77
78 };
79
80
81 struct cell_context
82 {
83 struct pipe_context pipe;
84
85 struct cell_winsys *winsys;
86
87 const struct cell_blend_state *blend;
88 const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS];
89 uint num_samplers;
90 const struct cell_depth_stencil_alpha_state *depth_stencil;
91 const struct pipe_rasterizer_state *rasterizer;
92 const struct cell_vertex_shader_state *vs;
93 const struct cell_fragment_shader_state *fs;
94
95 struct spe_function logic_op;
96
97 struct pipe_blend_color blend_color;
98 struct pipe_clip_state clip;
99 struct pipe_constant_buffer constants[2];
100 struct pipe_framebuffer_state framebuffer;
101 struct pipe_poly_stipple poly_stipple;
102 struct pipe_scissor_state scissor;
103 struct cell_texture *texture[PIPE_MAX_SAMPLERS];
104 uint num_textures;
105 struct pipe_viewport_state viewport;
106 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
107 uint num_vertex_buffers;
108 struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS];
109 uint num_vertex_elements;
110
111 ubyte *cbuf_map[PIPE_MAX_COLOR_BUFS];
112 ubyte *zsbuf_map;
113
114 struct pipe_surface *tex_surf;
115 uint *tex_map;
116
117 uint dirty;
118
119 /** The primitive drawing context */
120 struct draw_context *draw;
121 struct draw_stage *render_stage;
122
123 /** For post-transformed vertex buffering: */
124 struct cell_vbuf_render *vbuf_render;
125 struct draw_stage *vbuf;
126
127 struct vertex_info vertex_info;
128
129 /** Mapped constant buffers */
130 void *mapped_constants[PIPE_SHADER_TYPES];
131
132
133 uint num_spus;
134
135 /** Buffers for command batches, vertex/index data */
136 uint buffer_size[CELL_NUM_BUFFERS];
137 ubyte buffer[CELL_NUM_BUFFERS][CELL_BUFFER_SIZE] ALIGN16_ATTRIB;
138
139 int cur_batch; /**< which buffer is being filled w/ commands */
140
141 /** [4] to ensure 16-byte alignment for each status word */
142 uint buffer_status[CELL_MAX_SPUS][CELL_NUM_BUFFERS][4] ALIGN16_ATTRIB;
143
144
145 struct spe_function attrib_fetch;
146 unsigned attrib_fetch_offsets[PIPE_MAX_ATTRIBS];
147 };
148
149
150
151
152 static INLINE struct cell_context *
153 cell_context(struct pipe_context *pipe)
154 {
155 return (struct cell_context *) pipe;
156 }
157
158
159 extern struct pipe_context *
160 cell_create_context(struct pipe_screen *screen, struct cell_winsys *cws);
161
162 extern void
163 cell_vertex_shader_queue_flush(struct draw_context *draw);
164
165
166 /* XXX find a better home for this */
167 extern void cell_update_vertex_fetch(struct draw_context *draw);
168
169
170 #endif /* CELL_CONTEXT_H */