cell: insert a (disabled) call to spe_cpu_info_get()
[mesa.git] / src / gallium / drivers / cell / ppu / cell_context.c
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 * Authors
30 * Brian Paul
31 */
32
33
34 #include <stdio.h>
35
36 #include "pipe/p_defines.h"
37 #include "pipe/p_format.h"
38 #include "pipe/p_util.h"
39 #include "pipe/p_winsys.h"
40 #include "cell/common.h"
41 #include "draw/draw_context.h"
42 #include "draw/draw_private.h"
43 #include "cell_clear.h"
44 #include "cell_context.h"
45 #include "cell_draw_arrays.h"
46 #include "cell_flush.h"
47 #include "cell_render.h"
48 #include "cell_state.h"
49 #include "cell_surface.h"
50 #include "cell_spu.h"
51 #include "cell_pipe_state.h"
52 #include "cell_texture.h"
53 #include "cell_vbuf.h"
54
55
56
57 static boolean
58 cell_is_format_supported( struct pipe_context *pipe,
59 enum pipe_format format, uint type )
60 {
61 /*struct cell_context *cell = cell_context( pipe );*/
62
63 switch (type) {
64 case PIPE_TEXTURE:
65 /* cell supports all texture formats, XXX for now anyway */
66 return TRUE;
67 case PIPE_SURFACE:
68 /* cell supports all (off-screen) surface formats, XXX for now */
69 return TRUE;
70 default:
71 assert(0);
72 return FALSE;
73 }
74 }
75
76
77 static int cell_get_param(struct pipe_context *pipe, int param)
78 {
79 switch (param) {
80 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
81 return 8;
82 case PIPE_CAP_NPOT_TEXTURES:
83 return 1;
84 case PIPE_CAP_TWO_SIDED_STENCIL:
85 return 1;
86 case PIPE_CAP_GLSL:
87 return 1;
88 case PIPE_CAP_S3TC:
89 return 0;
90 case PIPE_CAP_ANISOTROPIC_FILTER:
91 return 0;
92 case PIPE_CAP_POINT_SPRITE:
93 return 1;
94 case PIPE_CAP_MAX_RENDER_TARGETS:
95 return 1;
96 case PIPE_CAP_OCCLUSION_QUERY:
97 return 1;
98 case PIPE_CAP_TEXTURE_SHADOW_MAP:
99 return 1;
100 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
101 return 12; /* max 2Kx2K */
102 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
103 return 8; /* max 128x128x128 */
104 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
105 return 12; /* max 2Kx2K */
106 default:
107 return 0;
108 }
109 }
110
111 static float cell_get_paramf(struct pipe_context *pipe, int param)
112 {
113 switch (param) {
114 case PIPE_CAP_MAX_LINE_WIDTH:
115 /* fall-through */
116 case PIPE_CAP_MAX_LINE_WIDTH_AA:
117 return 255.0; /* arbitrary */
118
119 case PIPE_CAP_MAX_POINT_WIDTH:
120 /* fall-through */
121 case PIPE_CAP_MAX_POINT_WIDTH_AA:
122 return 255.0; /* arbitrary */
123
124 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
125 return 0.0;
126
127 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
128 return 16.0; /* arbitrary */
129
130 default:
131 return 0;
132 }
133 }
134
135
136 static const char *
137 cell_get_name( struct pipe_context *pipe )
138 {
139 return "Cell";
140 }
141
142 static const char *
143 cell_get_vendor( struct pipe_context *pipe )
144 {
145 return "Tungsten Graphics, Inc.";
146 }
147
148
149
150 static void
151 cell_destroy_context( struct pipe_context *pipe )
152 {
153 struct cell_context *cell = cell_context(pipe);
154
155 cell_spu_exit(cell);
156
157 align_free(cell);
158 }
159
160
161 static struct draw_context *
162 cell_draw_create(struct cell_context *cell)
163 {
164 struct draw_context *draw = draw_create();
165
166 if (getenv("GALLIUM_CELL_VS")) {
167 /* plug in SPU-based vertex transformation code */
168 draw->shader_queue_flush = cell_vertex_shader_queue_flush;
169 draw->driver_private = cell;
170 }
171
172 return draw;
173 }
174
175
176 struct pipe_context *
177 cell_create_context(struct pipe_winsys *winsys, struct cell_winsys *cws)
178 {
179 struct cell_context *cell;
180 uint spu, buf;
181
182 /* some fields need to be 16-byte aligned, so align the whole object */
183 cell = (struct cell_context*) align_malloc(sizeof(struct cell_context), 16);
184 if (!cell)
185 return NULL;
186
187 memset(cell, 0, sizeof(*cell));
188
189 cell->winsys = cws;
190 cell->pipe.winsys = winsys;
191 cell->pipe.destroy = cell_destroy_context;
192
193 /* queries */
194 cell->pipe.is_format_supported = cell_is_format_supported;
195 cell->pipe.get_name = cell_get_name;
196 cell->pipe.get_vendor = cell_get_vendor;
197 cell->pipe.get_param = cell_get_param;
198 cell->pipe.get_paramf = cell_get_paramf;
199
200
201 /* state setters */
202 cell->pipe.set_vertex_buffer = cell_set_vertex_buffer;
203 cell->pipe.set_vertex_element = cell_set_vertex_element;
204
205 cell->pipe.draw_arrays = cell_draw_arrays;
206 cell->pipe.draw_elements = cell_draw_elements;
207
208 cell->pipe.clear = cell_clear_surface;
209 cell->pipe.flush = cell_flush;
210
211 #if 0
212 cell->pipe.begin_query = cell_begin_query;
213 cell->pipe.end_query = cell_end_query;
214 cell->pipe.wait_query = cell_wait_query;
215 #endif
216
217 cell_init_state_functions(cell);
218 cell_init_shader_functions(cell);
219 cell_init_surface_functions(cell);
220 cell_init_texture_functions(cell);
221
222 cell->draw = cell_draw_create(cell);
223
224 cell_init_vbuf(cell);
225 draw_set_rasterize_stage(cell->draw, cell->vbuf);
226
227 /*
228 * SPU stuff
229 */
230 cell->num_spus = 6;
231 /* XXX is this in SDK 3.0 only?
232 cell->num_spus = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1);
233 */
234
235 cell_start_spus(cell);
236
237 /* init command, vertex/index buffer info */
238 for (buf = 0; buf < CELL_NUM_BUFFERS; buf++) {
239 cell->buffer_size[buf] = 0;
240
241 /* init batch buffer status values,
242 * mark 0th buffer as used, rest as free.
243 */
244 for (spu = 0; spu < cell->num_spus; spu++) {
245 if (buf == 0)
246 cell->buffer_status[spu][buf][0] = CELL_BUFFER_STATUS_USED;
247 else
248 cell->buffer_status[spu][buf][0] = CELL_BUFFER_STATUS_FREE;
249 }
250 }
251
252 return &cell->pipe;
253 }