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 **************************************************************************/
29 * Types and tokens which are common to the SPU and PPU code.
36 #include "pipe/p_compiler.h"
37 #include "pipe/p_format.h"
38 #include "pipe/p_state.h"
41 /** The standard assert macro doesn't seem to work reliably */
45 fprintf(stderr, "%s:%d: %s(): assertion %s failed.\n", \
46 __FILE__, __LINE__, __FUNCTION__, #x); \
52 /** for sanity checking */
53 #define ASSERT_ALIGN16(ptr) \
54 ASSERT((((unsigned long) (ptr)) & 0xf) == 0);
57 /** round up value to next multiple of 4 */
58 #define ROUNDUP4(k) (((k) + 0x3) & ~0x3)
60 /** round up value to next multiple of 8 */
61 #define ROUNDUP8(k) (((k) + 0x7) & ~0x7)
63 /** round up value to next multiple of 16 */
64 #define ROUNDUP16(k) (((k) + 0xf) & ~0xf)
67 #define CELL_MAX_SPUS 6
69 #define CELL_MAX_SAMPLERS 4
75 * The low byte of a mailbox word contains the command opcode.
76 * Remaining higher bytes are command specific.
78 #define CELL_CMD_OPCODE_MASK 0xff
80 #define CELL_CMD_EXIT 1
81 #define CELL_CMD_CLEAR_SURFACE 2
82 #define CELL_CMD_FINISH 3
83 #define CELL_CMD_RENDER 4
84 #define CELL_CMD_BATCH 5
85 #define CELL_CMD_RELEASE_VERTS 6
86 #define CELL_CMD_STATE_FRAMEBUFFER 10
87 #define CELL_CMD_STATE_FRAGMENT_OPS 11
88 #define CELL_CMD_STATE_SAMPLER 12
89 #define CELL_CMD_STATE_TEXTURE 13
90 #define CELL_CMD_STATE_VERTEX_INFO 14
91 #define CELL_CMD_STATE_VIEWPORT 15
92 #define CELL_CMD_STATE_UNIFORMS 16
93 #define CELL_CMD_STATE_VS_ARRAY_INFO 17
94 #define CELL_CMD_STATE_BIND_VS 18
95 #define CELL_CMD_STATE_FRAGMENT_PROGRAM 19
96 #define CELL_CMD_STATE_ATTRIB_FETCH 20
97 #define CELL_CMD_VS_EXECUTE 22
98 #define CELL_CMD_FLUSH_BUFFER_RANGE 23
101 #define CELL_NUM_BUFFERS 4
102 #define CELL_BUFFER_SIZE (4*1024) /**< 16KB would be the max */
104 #define CELL_BUFFER_STATUS_FREE 10
105 #define CELL_BUFFER_STATUS_USED 20
107 #define CELL_DEBUG_CHECKER (1 << 0)
108 #define CELL_DEBUG_ASM (1 << 1)
109 #define CELL_DEBUG_SYNC (1 << 2)
110 #define CELL_DEBUG_FRAGMENT_OPS (1 << 3)
111 #define CELL_DEBUG_FRAGMENT_OP_FALLBACK (1 << 4)
113 /** Max instructions for doing per-fragment operations */
114 #define SPU_MAX_FRAGMENT_OPS_INSTS 64
118 * Command to specify per-fragment operations state and generated code.
120 struct cell_command_fragment_ops
122 uint64_t opcode
; /**< CELL_CMD_STATE_FRAGMENT_OPS */
123 struct pipe_depth_stencil_alpha_state dsa
;
124 struct pipe_blend_state blend
;
125 unsigned code
[SPU_MAX_FRAGMENT_OPS_INSTS
];
129 /** Max instructions for fragment programs */
130 #define SPU_MAX_FRAGMENT_PROGRAM_INSTS 128
133 * Command to send a fragment program to SPUs.
135 struct cell_command_fragment_program
137 uint64_t opcode
; /**< CELL_CMD_STATE_FRAGMENT_PROGRAM */
138 uint num_inst
; /**< Number of instructions */
139 unsigned code
[SPU_MAX_FRAGMENT_PROGRAM_INSTS
];
144 * Tell SPUs about the framebuffer size, location
146 struct cell_command_framebuffer
148 uint64_t opcode
; /**< CELL_CMD_FRAMEBUFFER */
150 void *color_start
, *depth_start
;
151 enum pipe_format color_format
, depth_format
;
156 * Clear framebuffer to the given value/color.
158 struct cell_command_clear_surface
160 uint64_t opcode
; /**< CELL_CMD_CLEAR_SURFACE */
161 uint surface
; /**< Temporary: 0=color, 1=Z */
167 * Array info used by the vertex shader's vertex puller.
169 struct cell_array_info
171 uint64_t base
; /**< Base address of the 0th element. */
172 uint attr
; /**< Attribute that this state is for. */
173 uint pitch
; /**< Byte pitch from one entry to the next. */
175 uint function_offset
;
179 struct cell_attribute_fetch_code
186 struct cell_buffer_range
193 struct cell_shader_info
195 uint64_t declarations
;
196 uint64_t instructions
;
199 unsigned num_outputs
;
200 unsigned num_declarations
;
201 unsigned num_instructions
;
202 unsigned num_immediates
;
206 #define SPU_VERTS_PER_BATCH 64
207 struct cell_command_vs
209 uint64_t opcode
; /**< CELL_CMD_VS_EXECUTE */
210 uint64_t vOut
[SPU_VERTS_PER_BATCH
];
212 unsigned elts
[SPU_VERTS_PER_BATCH
];
219 struct cell_command_render
221 uint64_t opcode
; /**< CELL_CMD_RENDER */
222 uint prim_type
; /**< PIPE_PRIM_x */
224 uint vertex_size
; /**< bytes per vertex */
226 uint vertex_buf
; /**< which cell->buffer[] contains the vertex data */
227 float xmin
, ymin
, xmax
, ymax
; /* XXX another dummy field */
229 boolean inline_verts
;
233 struct cell_command_release_verts
235 uint64_t opcode
; /**< CELL_CMD_RELEASE_VERTS */
236 uint vertex_buf
; /**< in [0, CELL_NUM_BUFFERS-1] */
240 struct cell_command_sampler
242 uint64_t opcode
; /**< CELL_CMD_STATE_SAMPLER */
244 struct pipe_sampler_state state
;
248 struct cell_command_texture
250 uint64_t opcode
; /**< CELL_CMD_STATE_TEXTURE */
252 void *start
; /**< Address in main memory */
253 ushort width
, height
;
257 /** XXX unions don't seem to work */
258 /* XXX this should go away; all commands should be placed in batch buffers */
262 struct cell_command_framebuffer fb
;
263 struct cell_command_clear_surface clear
;
264 struct cell_command_render render
;
266 struct cell_command_vs vs
;
270 #define MAX_SPU_FUNCTIONS 12
272 * Used to tell the PPU about the address of particular functions in the
273 * SPU's address space.
275 struct cell_spu_function_info
278 char names
[MAX_SPU_FUNCTIONS
][16];
279 uint addrs
[MAX_SPU_FUNCTIONS
];
280 char pad
[12]; /**< Pad struct to multiple of 16 bytes (256 currently) */
284 /** This is the object passed to spe_create_thread() */
285 struct cell_init_info
289 unsigned debug_flags
; /**< mask of CELL_DEBUG_x flags */
290 struct cell_command
*cmd
;
292 /** Buffers for command batches, vertex/index data */
293 ubyte
*buffers
[CELL_NUM_BUFFERS
];
294 uint
*buffer_status
; /**< points at cell_context->buffer_status */
296 struct cell_spu_function_info
*spu_functions
;
300 #endif /* CELL_COMMON_H */