1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
32 #include <spu_mfcio.h>
34 #include "cell/common.h"
35 #include "draw/draw_vertex.h"
36 #include "pipe/p_state.h"
40 /* These debug macros use the unusual construction ", ##__VA_ARGS__"
41 * which expands to the expected comma + args if variadic arguments
42 * are supplied, but swallows the comma if there are no variadic
43 * arguments (which avoids syntax errors that would otherwise occur).
45 #define D_PRINTF(flag, format,...) \
46 if (spu.init.debug_flags & (flag)) \
47 printf("SPU %u: " format, spu.init.id, ##__VA_ARGS__)
54 * A tile is basically a TILE_SIZE x TILE_SIZE block of 4-byte pixels.
55 * The data may be addressed through several different types.
58 ushort us
[TILE_SIZE
][TILE_SIZE
];
59 uint ui
[TILE_SIZE
][TILE_SIZE
];
60 vector
unsigned short us8
[TILE_SIZE
/2][TILE_SIZE
/4];
61 vector
unsigned int ui4
[TILE_SIZE
/2][TILE_SIZE
/2];
65 #define TILE_STATUS_CLEAR 1
66 #define TILE_STATUS_DEFINED 2 /**< defined in FB, but not in local store */
67 #define TILE_STATUS_CLEAN 3 /**< in local store, but not changed */
68 #define TILE_STATUS_DIRTY 4 /**< modified locally, but not put back yet */
69 #define TILE_STATUS_GETTING 5 /**< mfc_get() called but not yet arrived */
72 /** Function for sampling textures */
73 typedef void (*spu_sample_texture4_func
)(vector
float s
,
77 uint unit
, uint level
, uint face
,
78 vector
float colors
[4]);
81 /** Function for performing per-fragment ops */
82 typedef void (*spu_fragment_ops_func
)(uint x
, uint y
,
84 tile_t
*depthStencilTile
,
87 vector
float fragGreen
,
88 vector
float fragBlue
,
89 vector
float fragAlpha
,
90 vector
unsigned int mask
,
93 /** Function for running fragment program */
94 typedef void (*spu_fragment_program_func
)(vector
float *inputs
,
95 vector
float *outputs
,
96 vector
float *constants
);
99 struct spu_framebuffer
101 void *color_start
; /**< addr of color surface in main memory */
102 void *depth_start
; /**< addr of depth surface in main memory */
103 enum pipe_format color_format
;
104 enum pipe_format depth_format
;
105 uint width
, height
; /**< size in pixels */
106 uint width_tiles
, height_tiles
; /**< width and height in tiles */
108 uint color_clear_value
;
109 uint depth_clear_value
;
111 uint zsize
; /**< 0, 2 or 4 bytes per Z */
112 float zscale
; /**< 65535.0, 2^24-1 or 2^32-1 */
116 /** per-texture level info */
117 struct spu_texture_level
120 ushort width
, height
, depth
;
121 ushort tiles_per_row
;
122 uint bytes_per_image
;
123 /** texcoord scale factors */
124 vector
float scale_s
, scale_t
, scale_r
;
125 /** texcoord masks (if REPEAT then size-1, else ~0) */
126 vector
signed int mask_s
, mask_t
, mask_r
;
127 /** texcoord clamp limits */
128 vector
signed int max_s
, max_t
, max_r
;
134 struct spu_texture_level level
[CELL_MAX_TEXTURE_LEVELS
];
136 uint target
; /**< PIPE_TEXTURE_x */
141 * All SPU global/context state will be in a singleton object of this type:
145 /** One-time init/constant info */
146 struct cell_init_info init
;
151 struct spu_framebuffer fb
;
152 struct pipe_depth_stencil_alpha_state depth_stencil_alpha
;
153 struct pipe_blend_state blend
;
154 struct pipe_blend_color blend_color
;
155 struct pipe_sampler_state sampler
[PIPE_MAX_SAMPLERS
];
156 struct spu_texture texture
[PIPE_MAX_SAMPLERS
];
157 struct vertex_info vertex_info
;
159 /** Current color and Z tiles */
160 tile_t ctile ALIGN16_ATTRIB
;
161 tile_t ztile ALIGN16_ATTRIB
;
163 /** Read depth/stencil tiles? */
165 boolean read_stencil
;
167 /** Current tiles' status */
168 ubyte cur_ctile_status
, cur_ztile_status
;
170 /** Status of all tiles in framebuffer */
171 ubyte ctile_status
[CELL_MAX_HEIGHT
/TILE_SIZE
][CELL_MAX_WIDTH
/TILE_SIZE
] ALIGN16_ATTRIB
;
172 ubyte ztile_status
[CELL_MAX_HEIGHT
/TILE_SIZE
][CELL_MAX_WIDTH
/TILE_SIZE
] ALIGN16_ATTRIB
;
174 /** Current fragment ops machine code, at 8-byte boundary */
175 uint fragment_ops_code
[SPU_MAX_FRAGMENT_OPS_INSTS
] ALIGN8_ATTRIB
;
176 /** Current fragment ops function */
177 spu_fragment_ops_func fragment_ops
;
179 /** Current fragment program machine code, at 8-byte boundary */
180 uint fragment_program_code
[SPU_MAX_FRAGMENT_PROGRAM_INSTS
] ALIGN8_ATTRIB
;
181 /** Current fragment ops function */
182 spu_fragment_program_func fragment_program
;
184 /** Current texture sampler function */
185 spu_sample_texture4_func sample_texture4
[CELL_MAX_SAMPLERS
];
186 spu_sample_texture4_func min_sample_texture4
[CELL_MAX_SAMPLERS
];
187 spu_sample_texture4_func mag_sample_texture4
[CELL_MAX_SAMPLERS
];
189 /** Fragment program constants */
190 vector
float constants
[4 * CELL_MAX_CONSTANTS
];
195 extern struct spu_global spu
;
201 #define TAG_SURFACE_CLEAR 10
202 #define TAG_VERTEX_BUFFER 11
203 #define TAG_READ_TILE_COLOR 12
204 #define TAG_READ_TILE_Z 13
205 #define TAG_WRITE_TILE_COLOR 14
206 #define TAG_WRITE_TILE_Z 15
207 #define TAG_INDEX_BUFFER 16
208 #define TAG_BATCH_BUFFER 17
210 #define TAG_DCACHE0 20
211 #define TAG_DCACHE1 21
212 #define TAG_DCACHE2 22
213 #define TAG_DCACHE3 23
218 wait_on_mask(unsigned tagMask
)
220 mfc_write_tag_mask( tagMask
);
221 /* wait for completion of _any_ DMAs specified by tagMask */
222 mfc_read_tag_status_any();
227 wait_on_mask_all(unsigned tagMask
)
229 mfc_write_tag_mask( tagMask
);
230 /* wait for completion of _any_ DMAs specified by tagMask */
231 mfc_read_tag_status_all();
239 memset16(ushort
*d
, ushort value
, uint count
)
242 for (i
= 0; i
< count
; i
++)
248 memset32(uint
*d
, uint value
, uint count
)
251 for (i
= 0; i
< count
; i
++)
256 #endif /* SPU_MAIN_H */