cell: minor texture improvements
[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 #include "pipe/p_state.h"
40
41
42 /** The standard assert macro doesn't seem to work reliably */
43 #define ASSERT(x) \
44 if (!(x)) { \
45 ubyte *p = NULL; \
46 fprintf(stderr, "%s:%d: %s(): assertion %s failed.\n", \
47 __FILE__, __LINE__, __FUNCTION__, #x); \
48 *p = 0; \
49 exit(1); \
50 }
51
52
53 /** for sanity checking */
54 #define ASSERT_ALIGN16(ptr) \
55 ASSERT((((unsigned long) (ptr)) & 0xf) == 0);
56
57
58 /** round up value to next multiple of 4 */
59 #define ROUNDUP4(k) (((k) + 0x3) & ~0x3)
60
61 /** round up value to next multiple of 8 */
62 #define ROUNDUP8(k) (((k) + 0x7) & ~0x7)
63
64 /** round up value to next multiple of 16 */
65 #define ROUNDUP16(k) (((k) + 0xf) & ~0xf)
66
67
68 #define CELL_MAX_SPUS 6
69
70 #define CELL_MAX_SAMPLERS 4
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_DEPTH_STENCIL 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_BLEND 19
97 #define CELL_CMD_STATE_ATTRIB_FETCH 20
98 #define CELL_CMD_STATE_LOGICOP 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
110
111 /**
112 */
113 struct cell_command_depth_stencil_alpha_test {
114 uint64_t base; /**< Effective address of code start. */
115 unsigned size; /**< Size in bytes of SPE code. */
116 unsigned read_depth; /**< Flag: should depth be read? */
117 unsigned read_stencil; /**< Flag: should stencil be read? */
118 };
119
120
121 /**
122 * Upload code to perform framebuffer blend operation
123 */
124 struct cell_command_blend {
125 uint64_t base; /**< Effective address of code start. */
126 unsigned size; /**< Size in bytes of SPE code. */
127 unsigned read_fb; /**< Flag: should framebuffer be read? */
128 };
129
130
131 struct cell_command_logicop {
132 uint64_t base; /**< Effective address of code start. */
133 unsigned size; /**< Size in bytes of SPE code. */
134 };
135
136
137 /**
138 * Tell SPUs about the framebuffer size, location
139 */
140 struct cell_command_framebuffer
141 {
142 uint64_t opcode; /**< CELL_CMD_FRAMEBUFFER */
143 int width, height;
144 void *color_start, *depth_start;
145 enum pipe_format color_format, depth_format;
146 };
147
148
149 /**
150 * Clear framebuffer to the given value/color.
151 */
152 struct cell_command_clear_surface
153 {
154 uint64_t opcode; /**< CELL_CMD_CLEAR_SURFACE */
155 uint surface; /**< Temporary: 0=color, 1=Z */
156 uint value;
157 };
158
159
160 /**
161 * Array info used by the vertex shader's vertex puller.
162 */
163 struct cell_array_info
164 {
165 uint64_t base; /**< Base address of the 0th element. */
166 uint attr; /**< Attribute that this state is for. */
167 uint pitch; /**< Byte pitch from one entry to the next. */
168 uint size;
169 uint function_offset;
170 };
171
172
173 struct cell_attribute_fetch_code {
174 uint64_t base;
175 uint size;
176 };
177
178
179 struct cell_buffer_range {
180 uint64_t base;
181 unsigned size;
182 };
183
184
185 struct cell_shader_info
186 {
187 uint64_t declarations;
188 uint64_t instructions;
189 uint64_t immediates;
190
191 unsigned num_outputs;
192 unsigned num_declarations;
193 unsigned num_instructions;
194 unsigned num_immediates;
195 };
196
197
198 #define SPU_VERTS_PER_BATCH 64
199 struct cell_command_vs
200 {
201 uint64_t opcode; /**< CELL_CMD_VS_EXECUTE */
202 uint64_t vOut[SPU_VERTS_PER_BATCH];
203 unsigned num_elts;
204 unsigned elts[SPU_VERTS_PER_BATCH];
205 float plane[12][4];
206 unsigned nr_planes;
207 unsigned nr_attrs;
208 };
209
210
211 struct cell_command_render
212 {
213 uint64_t opcode; /**< CELL_CMD_RENDER */
214 uint prim_type; /**< PIPE_PRIM_x */
215 uint num_verts;
216 uint vertex_size; /**< bytes per vertex */
217 uint num_indexes;
218 uint vertex_buf; /**< which cell->buffer[] contains the vertex data */
219 float xmin, ymin, xmax, ymax; /* XXX another dummy field */
220 uint min_index;
221 boolean inline_verts;
222 };
223
224
225 struct cell_command_release_verts
226 {
227 uint64_t opcode; /**< CELL_CMD_RELEASE_VERTS */
228 uint vertex_buf; /**< in [0, CELL_NUM_BUFFERS-1] */
229 };
230
231
232 struct cell_command_sampler
233 {
234 uint64_t opcode; /**< CELL_CMD_STATE_SAMPLER */
235 uint unit;
236 struct pipe_sampler_state state;
237 };
238
239
240 struct cell_command_texture
241 {
242 uint64_t opcode; /**< CELL_CMD_STATE_TEXTURE */
243 uint unit;
244 void *start; /**< Address in main memory */
245 ushort width, height;
246 };
247
248
249 /** XXX unions don't seem to work */
250 /* XXX this should go away; all commands should be placed in batch buffers */
251 struct cell_command
252 {
253 #if 0
254 struct cell_command_framebuffer fb;
255 struct cell_command_clear_surface clear;
256 struct cell_command_render render;
257 #endif
258 struct cell_command_vs vs;
259 } ALIGN16_ATTRIB;
260
261
262 /** This is the object passed to spe_create_thread() */
263 struct cell_init_info
264 {
265 unsigned id;
266 unsigned num_spus;
267 struct cell_command *cmd;
268
269 /** Buffers for command batches, vertex/index data */
270 ubyte *buffers[CELL_NUM_BUFFERS];
271 uint *buffer_status; /**< points at cell_context->buffer_status */
272 } ALIGN16_ATTRIB;
273
274
275 #endif /* CELL_COMMON_H */