1cd577c23caae9cffbdea0f2e3bd62f6cc6749a3
[mesa.git] / src / gallium / drivers / cell / spu / spu_main.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 #ifndef SPU_MAIN_H
29 #define SPU_MAIN_H
30
31
32 #include <spu_mfcio.h>
33
34 #include "cell/common.h"
35 #include "draw/draw_vertex.h"
36 #include "pipe/p_state.h"
37
38
39
40 #define MAX_WIDTH 1024
41 #define MAX_HEIGHT 1024
42
43
44 /**
45 * A tile is basically a TILE_SIZE x TILE_SIZE block of 4-byte pixels.
46 * The data may be addressed through several different types.
47 */
48 typedef union {
49 ushort us[TILE_SIZE][TILE_SIZE];
50 uint ui[TILE_SIZE][TILE_SIZE];
51 vector unsigned short us8[TILE_SIZE/2][TILE_SIZE/4];
52 vector unsigned int ui4[TILE_SIZE/2][TILE_SIZE/2];
53 } tile_t;
54
55
56 #define TILE_STATUS_CLEAR 1
57 #define TILE_STATUS_DEFINED 2 /**< defined in FB, but not in local store */
58 #define TILE_STATUS_CLEAN 3 /**< in local store, but not changed */
59 #define TILE_STATUS_DIRTY 4 /**< modified locally, but not put back yet */
60 #define TILE_STATUS_GETTING 5 /**< mfc_get() called but not yet arrived */
61
62
63 /** Function for sampling textures */
64 typedef vector float (*spu_sample_texture_func)(uint unit,
65 vector float texcoord);
66
67 /** Function for performing per-fragment ops */
68 typedef void (*spu_fragment_ops_func)(uint x, uint y,
69 tile_t *colorTile,
70 tile_t *depthStencilTile,
71 vector float fragZ,
72 vector float fragRed,
73 vector float fragGreen,
74 vector float fragBlue,
75 vector float fragAlpha,
76 vector unsigned int mask,
77 uint facing);
78
79 /** Function for running fragment program */
80 typedef void (*spu_fragment_program_func)(vector float *inputs,
81 vector float *outputs,
82 vector float *constants);
83
84
85 struct spu_framebuffer
86 {
87 void *color_start; /**< addr of color surface in main memory */
88 void *depth_start; /**< addr of depth surface in main memory */
89 enum pipe_format color_format;
90 enum pipe_format depth_format;
91 uint width, height; /**< size in pixels */
92 uint width_tiles, height_tiles; /**< width and height in tiles */
93
94 uint color_clear_value;
95 uint depth_clear_value;
96
97 uint zsize; /**< 0, 2 or 4 bytes per Z */
98 float zscale; /**< 65535.0, 2^24-1 or 2^32-1 */
99 } ALIGN16_ATTRIB;
100
101
102 struct spu_texture
103 {
104 void *start;
105 ushort width, height;
106 ushort tiles_per_row;
107 vector float tex_size;
108 vector unsigned int tex_size_mask; /**< == int(size - 1) */
109 vector unsigned int tex_size_x_mask; /**< == int(size - 1) */
110 vector unsigned int tex_size_y_mask; /**< == int(size - 1) */
111 } ALIGN16_ATTRIB;
112
113
114 /**
115 * All SPU global/context state will be in a singleton object of this type:
116 */
117 struct spu_global
118 {
119 /** One-time init/constant info */
120 struct cell_init_info init;
121
122 /*
123 * Current state
124 */
125 struct spu_framebuffer fb;
126 struct pipe_depth_stencil_alpha_state depth_stencil_alpha;
127 struct pipe_blend_state blend;
128 struct pipe_sampler_state sampler[PIPE_MAX_SAMPLERS];
129 struct spu_texture texture[PIPE_MAX_SAMPLERS];
130 struct vertex_info vertex_info;
131
132 /** Current color and Z tiles */
133 tile_t ctile ALIGN16_ATTRIB;
134 tile_t ztile ALIGN16_ATTRIB;
135
136 /** Read depth/stencil tiles? */
137 boolean read_depth;
138 boolean read_stencil;
139
140 /** Current tiles' status */
141 ubyte cur_ctile_status, cur_ztile_status;
142
143 /** Status of all tiles in framebuffer */
144 ubyte ctile_status[MAX_HEIGHT/TILE_SIZE][MAX_WIDTH/TILE_SIZE] ALIGN16_ATTRIB;
145 ubyte ztile_status[MAX_HEIGHT/TILE_SIZE][MAX_WIDTH/TILE_SIZE] ALIGN16_ATTRIB;
146
147 /** Current fragment ops machine code, at 8-byte boundary */
148 uint fragment_ops_code[SPU_MAX_FRAGMENT_OPS_INSTS] ALIGN8_ATTRIB;
149 /** Current fragment ops function */
150 spu_fragment_ops_func fragment_ops;
151
152 /** Current fragment program machine code, at 8-byte boundary */
153 uint fragment_program_code[SPU_MAX_FRAGMENT_PROGRAM_INSTS] ALIGN8_ATTRIB;
154 /** Current fragment ops function */
155 spu_fragment_program_func fragment_program;
156
157 /** Current texture sampler function */
158 spu_sample_texture_func sample_texture[CELL_MAX_SAMPLERS];
159
160 /** Fragment program constants (XXX preliminary/used) */
161 #define MAX_CONSTANTS 32
162 vector float constants[MAX_CONSTANTS];
163
164 } ALIGN16_ATTRIB;
165
166
167 extern struct spu_global spu;
168 extern boolean Debug;
169
170
171
172
173 /* DMA TAGS */
174
175 #define TAG_SURFACE_CLEAR 10
176 #define TAG_VERTEX_BUFFER 11
177 #define TAG_READ_TILE_COLOR 12
178 #define TAG_READ_TILE_Z 13
179 #define TAG_WRITE_TILE_COLOR 14
180 #define TAG_WRITE_TILE_Z 15
181 #define TAG_INDEX_BUFFER 16
182 #define TAG_BATCH_BUFFER 17
183 #define TAG_MISC 18
184 #define TAG_DCACHE0 20
185 #define TAG_DCACHE1 21
186 #define TAG_DCACHE2 22
187 #define TAG_DCACHE3 23
188
189
190
191 static INLINE void
192 wait_on_mask(unsigned tagMask)
193 {
194 mfc_write_tag_mask( tagMask );
195 /* wait for completion of _any_ DMAs specified by tagMask */
196 mfc_read_tag_status_any();
197 }
198
199
200 static INLINE void
201 wait_on_mask_all(unsigned tagMask)
202 {
203 mfc_write_tag_mask( tagMask );
204 /* wait for completion of _any_ DMAs specified by tagMask */
205 mfc_read_tag_status_all();
206 }
207
208
209
210
211
212 static INLINE void
213 memset16(ushort *d, ushort value, uint count)
214 {
215 uint i;
216 for (i = 0; i < count; i++)
217 d[i] = value;
218 }
219
220
221 static INLINE void
222 memset32(uint *d, uint value, uint count)
223 {
224 uint i;
225 for (i = 0; i < count; i++)
226 d[i] = value;
227 }
228
229
230 #endif /* SPU_MAIN_H */