Merge remote branch 'upstream/gallium-0.1' into nouveau-gallium-0.1
[mesa.git] / src / gallium / drivers / cell / common.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 * Types and tokens which are common to the SPU and PPU code.
30 */
31
32
33 #ifndef CELL_COMMON_H
34 #define CELL_COMMON_H
35
36 #include "pipe/p_compiler.h"
37 #include "pipe/p_util.h"
38 #include "pipe/p_format.h"
39
40
41 /** The standard assert macro doesn't seem to work reliably */
42 #define ASSERT(x) \
43 if (!(x)) { \
44 ubyte *p = NULL; \
45 fprintf(stderr, "%s:%d: %s(): assertion %s failed.\n", \
46 __FILE__, __LINE__, __FUNCTION__, #x); \
47 *p = 0; \
48 exit(1); \
49 }
50
51
52 /** for sanity checking */
53 #define ASSERT_ALIGN16(ptr) \
54 ASSERT((((unsigned long) (ptr)) & 0xf) == 0);
55
56
57 /** round up value to next multiple of 4 */
58 #define ROUNDUP4(k) (((k) + 0x3) & ~0x3)
59
60 /** round up value to next multiple of 8 */
61 #define ROUNDUP8(k) (((k) + 0x7) & ~0x7)
62
63 /** round up value to next multiple of 16 */
64 #define ROUNDUP16(k) (((k) + 0xf) & ~0xf)
65
66
67 #define CELL_MAX_SPUS 6
68
69 #define TILE_SIZE 32
70
71
72 /**
73 * The low byte of a mailbox word contains the command opcode.
74 * Remaining higher bytes are command specific.
75 */
76 #define CELL_CMD_OPCODE_MASK 0xff
77
78 #define CELL_CMD_EXIT 1
79 #define CELL_CMD_CLEAR_SURFACE 2
80 #define CELL_CMD_FINISH 3
81 #define CELL_CMD_RENDER 4
82 #define CELL_CMD_BATCH 5
83 #define CELL_CMD_RELEASE_VERTS 6
84 #define CELL_CMD_STATE_FRAMEBUFFER 10
85 #define CELL_CMD_STATE_DEPTH_STENCIL 11
86 #define CELL_CMD_STATE_SAMPLER 12
87 #define CELL_CMD_STATE_TEXTURE 13
88 #define CELL_CMD_STATE_VERTEX_INFO 14
89 #define CELL_CMD_STATE_VIEWPORT 15
90 #define CELL_CMD_STATE_UNIFORMS 16
91 #define CELL_CMD_STATE_VS_ARRAY_INFO 17
92 #define CELL_CMD_STATE_BIND_VS 18
93 #define CELL_CMD_STATE_BLEND 19
94 #define CELL_CMD_STATE_ATTRIB_FETCH 20
95 #define CELL_CMD_STATE_LOGICOP 21
96 #define CELL_CMD_VS_EXECUTE 22
97 #define CELL_CMD_FLUSH_BUFFER_RANGE 23
98
99
100 #define CELL_NUM_BUFFERS 4
101 #define CELL_BUFFER_SIZE (4*1024) /**< 16KB would be the max */
102
103 #define CELL_BUFFER_STATUS_FREE 10
104 #define CELL_BUFFER_STATUS_USED 20
105
106
107
108 /**
109 */
110 struct cell_command_depth_stencil_alpha_test {
111 uint64_t base; /**< Effective address of code start. */
112 unsigned size; /**< Size in bytes of test code. */
113 unsigned read_depth; /**< Flag: should depth be read? */
114 unsigned read_stencil; /**< Flag: should stencil be read? */
115 };
116
117
118 /**
119 * Upload code to perform framebuffer blend operation
120 */
121 struct cell_command_blend {
122 uint64_t base; /**< Effective address of code start. */
123 unsigned size; /**< Size in bytes of test code. */
124 unsigned read_fb; /**< Flag: should framebuffer be read? */
125 };
126
127
128 struct cell_command_logicop {
129 uint64_t base; /**< Effective address of code start. */
130 unsigned size; /**< Size in bytes of test code. */
131 };
132
133
134 /**
135 * Tell SPUs about the framebuffer size, location
136 */
137 struct cell_command_framebuffer
138 {
139 uint64_t opcode; /**< CELL_CMD_FRAMEBUFFER */
140 int width, height;
141 void *color_start, *depth_start;
142 enum pipe_format color_format, depth_format;
143 };
144
145
146 /**
147 * Clear framebuffer to the given value/color.
148 */
149 struct cell_command_clear_surface
150 {
151 uint64_t opcode; /**< CELL_CMD_CLEAR_SURFACE */
152 uint surface; /**< Temporary: 0=color, 1=Z */
153 uint value;
154 };
155
156
157 /**
158 * Array info used by the vertex shader's vertex puller.
159 */
160 struct cell_array_info
161 {
162 uint64_t base; /**< Base address of the 0th element. */
163 uint attr; /**< Attribute that this state is for. */
164 uint pitch; /**< Byte pitch from one entry to the next. */
165 uint size;
166 uint function_offset;
167 };
168
169
170 struct cell_attribute_fetch_code {
171 uint64_t base;
172 uint size;
173 };
174
175
176 struct cell_buffer_range {
177 uint64_t base;
178 unsigned size;
179 };
180
181
182 struct cell_shader_info
183 {
184 uint64_t declarations;
185 uint64_t instructions;
186 uint64_t immediates;
187
188 unsigned num_outputs;
189 unsigned num_declarations;
190 unsigned num_instructions;
191 unsigned num_immediates;
192 };
193
194
195 #define SPU_VERTS_PER_BATCH 64
196 struct cell_command_vs
197 {
198 uint64_t opcode; /**< CELL_CMD_VS_EXECUTE */
199 uint64_t vOut[SPU_VERTS_PER_BATCH];
200 unsigned num_elts;
201 unsigned elts[SPU_VERTS_PER_BATCH];
202 float plane[12][4];
203 unsigned nr_planes;
204 unsigned nr_attrs;
205 };
206
207
208 struct cell_command_render
209 {
210 uint64_t opcode; /**< CELL_CMD_RENDER */
211 uint prim_type; /**< PIPE_PRIM_x */
212 uint num_verts;
213 uint vertex_size; /**< bytes per vertex */
214 uint num_indexes;
215 uint vertex_buf; /**< which cell->buffer[] contains the vertex data */
216 float xmin, ymin, xmax, ymax; /* XXX another dummy field */
217 uint min_index;
218 boolean inline_verts;
219 };
220
221
222 struct cell_command_release_verts
223 {
224 uint64_t opcode; /**< CELL_CMD_RELEASE_VERTS */
225 uint vertex_buf; /**< in [0, CELL_NUM_BUFFERS-1] */
226 };
227
228
229 struct cell_command_texture
230 {
231 void *start; /**< Address in main memory */
232 uint width, height;
233 };
234
235
236 /** XXX unions don't seem to work */
237 /* XXX this should go away; all commands should be placed in batch buffers */
238 struct cell_command
239 {
240 #if 0
241 struct cell_command_framebuffer fb;
242 struct cell_command_clear_surface clear;
243 struct cell_command_render render;
244 #endif
245 struct cell_command_vs vs;
246 } ALIGN16_ATTRIB;
247
248
249 /** This is the object passed to spe_create_thread() */
250 struct cell_init_info
251 {
252 unsigned id;
253 unsigned num_spus;
254 struct cell_command *cmd;
255
256 /** Buffers for command batches, vertex/index data */
257 ubyte *buffers[CELL_NUM_BUFFERS];
258 uint *buffer_status; /**< points at cell_context->buffer_status */
259 } ALIGN16_ATTRIB;
260
261
262 #endif /* CELL_COMMON_H */