cell: initial work for mipmap texture filtering
[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_format.h"
38 #include "pipe/p_state.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 CELL_MAX_SAMPLERS 4
70 #define CELL_MAX_TEXTURE_LEVELS 12 /* 2k x 2k */
71
72 #define TILE_SIZE 32
73
74
75 /**
76 * The low byte of a mailbox word contains the command opcode.
77 * Remaining higher bytes are command specific.
78 */
79 #define CELL_CMD_OPCODE_MASK 0xff
80
81 #define CELL_CMD_EXIT 1
82 #define CELL_CMD_CLEAR_SURFACE 2
83 #define CELL_CMD_FINISH 3
84 #define CELL_CMD_RENDER 4
85 #define CELL_CMD_BATCH 5
86 #define CELL_CMD_RELEASE_VERTS 6
87 #define CELL_CMD_STATE_FRAMEBUFFER 10
88 #define CELL_CMD_STATE_FRAGMENT_OPS 11
89 #define CELL_CMD_STATE_SAMPLER 12
90 #define CELL_CMD_STATE_TEXTURE 13
91 #define CELL_CMD_STATE_VERTEX_INFO 14
92 #define CELL_CMD_STATE_VIEWPORT 15
93 #define CELL_CMD_STATE_UNIFORMS 16
94 #define CELL_CMD_STATE_VS_ARRAY_INFO 17
95 #define CELL_CMD_STATE_BIND_VS 18
96 #define CELL_CMD_STATE_FRAGMENT_PROGRAM 19
97 #define CELL_CMD_STATE_ATTRIB_FETCH 20
98 #define CELL_CMD_STATE_FS_CONSTANTS 21
99 #define CELL_CMD_VS_EXECUTE 22
100 #define CELL_CMD_FLUSH_BUFFER_RANGE 23
101
102
103 #define CELL_NUM_BUFFERS 4
104 #define CELL_BUFFER_SIZE (4*1024) /**< 16KB would be the max */
105
106 #define CELL_BUFFER_STATUS_FREE 10
107 #define CELL_BUFFER_STATUS_USED 20
108
109 #define CELL_DEBUG_CHECKER (1 << 0)
110 #define CELL_DEBUG_ASM (1 << 1)
111 #define CELL_DEBUG_SYNC (1 << 2)
112 #define CELL_DEBUG_FRAGMENT_OPS (1 << 3)
113 #define CELL_DEBUG_FRAGMENT_OP_FALLBACK (1 << 4)
114
115 /** Max instructions for doing per-fragment operations */
116 #define SPU_MAX_FRAGMENT_OPS_INSTS 64
117
118
119 /**
120 * Command to specify per-fragment operations state and generated code.
121 */
122 struct cell_command_fragment_ops
123 {
124 uint64_t opcode; /**< CELL_CMD_STATE_FRAGMENT_OPS */
125 struct pipe_depth_stencil_alpha_state dsa;
126 struct pipe_blend_state blend;
127 unsigned code[SPU_MAX_FRAGMENT_OPS_INSTS];
128 };
129
130
131 /** Max instructions for fragment programs */
132 #define SPU_MAX_FRAGMENT_PROGRAM_INSTS 512
133
134 /**
135 * Command to send a fragment program to SPUs.
136 */
137 struct cell_command_fragment_program
138 {
139 uint64_t opcode; /**< CELL_CMD_STATE_FRAGMENT_PROGRAM */
140 uint num_inst; /**< Number of instructions */
141 unsigned code[SPU_MAX_FRAGMENT_PROGRAM_INSTS];
142 };
143
144
145 /**
146 * Tell SPUs about the framebuffer size, location
147 */
148 struct cell_command_framebuffer
149 {
150 uint64_t opcode; /**< CELL_CMD_FRAMEBUFFER */
151 int width, height;
152 void *color_start, *depth_start;
153 enum pipe_format color_format, depth_format;
154 };
155
156
157 /**
158 * Clear framebuffer to the given value/color.
159 */
160 struct cell_command_clear_surface
161 {
162 uint64_t opcode; /**< CELL_CMD_CLEAR_SURFACE */
163 uint surface; /**< Temporary: 0=color, 1=Z */
164 uint value;
165 };
166
167
168 /**
169 * Array info used by the vertex shader's vertex puller.
170 */
171 struct cell_array_info
172 {
173 uint64_t base; /**< Base address of the 0th element. */
174 uint attr; /**< Attribute that this state is for. */
175 uint pitch; /**< Byte pitch from one entry to the next. */
176 uint size;
177 uint function_offset;
178 };
179
180
181 struct cell_attribute_fetch_code
182 {
183 uint64_t base;
184 uint size;
185 };
186
187
188 struct cell_buffer_range
189 {
190 uint64_t base;
191 unsigned size;
192 };
193
194
195 struct cell_shader_info
196 {
197 uint64_t declarations;
198 uint64_t instructions;
199 uint64_t immediates;
200
201 unsigned num_outputs;
202 unsigned num_declarations;
203 unsigned num_instructions;
204 unsigned num_immediates;
205 };
206
207
208 #define SPU_VERTS_PER_BATCH 64
209 struct cell_command_vs
210 {
211 uint64_t opcode; /**< CELL_CMD_VS_EXECUTE */
212 uint64_t vOut[SPU_VERTS_PER_BATCH];
213 unsigned num_elts;
214 unsigned elts[SPU_VERTS_PER_BATCH];
215 float plane[12][4];
216 unsigned nr_planes;
217 unsigned nr_attrs;
218 };
219
220
221 struct cell_command_render
222 {
223 uint64_t opcode; /**< CELL_CMD_RENDER */
224 uint prim_type; /**< PIPE_PRIM_x */
225 uint num_verts;
226 uint vertex_size; /**< bytes per vertex */
227 uint num_indexes;
228 uint vertex_buf; /**< which cell->buffer[] contains the vertex data */
229 float xmin, ymin, xmax, ymax; /* XXX another dummy field */
230 uint min_index;
231 boolean inline_verts;
232 uint front_winding; /* the rasterizer needs to be able to determine facing to apply front/back-facing stencil */
233 };
234
235
236 struct cell_command_release_verts
237 {
238 uint64_t opcode; /**< CELL_CMD_RELEASE_VERTS */
239 uint vertex_buf; /**< in [0, CELL_NUM_BUFFERS-1] */
240 };
241
242
243 struct cell_command_sampler
244 {
245 uint64_t opcode; /**< CELL_CMD_STATE_SAMPLER */
246 uint unit;
247 struct pipe_sampler_state state;
248 };
249
250
251 struct cell_command_texture
252 {
253 uint64_t opcode; /**< CELL_CMD_STATE_TEXTURE */
254 uint unit;
255 void *start[CELL_MAX_TEXTURE_LEVELS]; /**< Address in main memory */
256 ushort width[CELL_MAX_TEXTURE_LEVELS];
257 ushort height[CELL_MAX_TEXTURE_LEVELS];
258 };
259
260
261 /** XXX unions don't seem to work */
262 /* XXX this should go away; all commands should be placed in batch buffers */
263 struct cell_command
264 {
265 #if 0
266 struct cell_command_framebuffer fb;
267 struct cell_command_clear_surface clear;
268 struct cell_command_render render;
269 #endif
270 struct cell_command_vs vs;
271 } ALIGN16_ATTRIB;
272
273
274 #define MAX_SPU_FUNCTIONS 12
275 /**
276 * Used to tell the PPU about the address of particular functions in the
277 * SPU's address space.
278 */
279 struct cell_spu_function_info
280 {
281 uint num;
282 char names[MAX_SPU_FUNCTIONS][16];
283 uint addrs[MAX_SPU_FUNCTIONS];
284 char pad[12]; /**< Pad struct to multiple of 16 bytes (256 currently) */
285 };
286
287
288 /** This is the object passed to spe_create_thread() */
289 struct cell_init_info
290 {
291 unsigned id;
292 unsigned num_spus;
293 unsigned debug_flags; /**< mask of CELL_DEBUG_x flags */
294 struct cell_command *cmd;
295
296 /** Buffers for command batches, vertex/index data */
297 ubyte *buffers[CELL_NUM_BUFFERS];
298 uint *buffer_status; /**< points at cell_context->buffer_status */
299
300 struct cell_spu_function_info *spu_functions;
301 } ALIGN16_ATTRIB;
302
303
304 #endif /* CELL_COMMON_H */