1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
/**************************************************************************
*
* Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
/**
* Authors
* Brian Paul
*/
#include <stdio.h>
#include "pipe/p_defines.h"
#include "pipe/p_format.h"
#include "pipe/p_util.h"
#include "pipe/p_winsys.h"
#include "cell/common.h"
#include "draw/draw_context.h"
#include "draw/draw_private.h"
#include "cell_clear.h"
#include "cell_context.h"
#include "cell_draw_arrays.h"
#include "cell_flush.h"
#include "cell_render.h"
#include "cell_state.h"
#include "cell_surface.h"
#include "cell_spu.h"
#include "cell_texture.h"
#include "cell_vbuf.h"
static boolean
cell_is_format_supported( struct pipe_context *pipe,
enum pipe_format format, uint type )
{
/*struct cell_context *cell = cell_context( pipe );*/
switch (type) {
case PIPE_TEXTURE:
/* cell supports all texture formats, XXX for now anyway */
return TRUE;
case PIPE_SURFACE:
/* cell supports all (off-screen) surface formats, XXX for now */
return TRUE;
default:
assert(0);
return FALSE;
}
}
static int cell_get_param(struct pipe_context *pipe, int param)
{
switch (param) {
case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
return 8;
case PIPE_CAP_NPOT_TEXTURES:
return 1;
case PIPE_CAP_TWO_SIDED_STENCIL:
return 1;
case PIPE_CAP_GLSL:
return 1;
case PIPE_CAP_S3TC:
return 0;
case PIPE_CAP_ANISOTROPIC_FILTER:
return 0;
case PIPE_CAP_POINT_SPRITE:
return 1;
case PIPE_CAP_MAX_RENDER_TARGETS:
return 1;
case PIPE_CAP_OCCLUSION_QUERY:
return 1;
case PIPE_CAP_TEXTURE_SHADOW_MAP:
return 1;
case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
return 12; /* max 2Kx2K */
case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
return 8; /* max 128x128x128 */
case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
return 12; /* max 2Kx2K */
default:
return 0;
}
}
static float cell_get_paramf(struct pipe_context *pipe, int param)
{
switch (param) {
case PIPE_CAP_MAX_LINE_WIDTH:
/* fall-through */
case PIPE_CAP_MAX_LINE_WIDTH_AA:
return 255.0; /* arbitrary */
case PIPE_CAP_MAX_POINT_WIDTH:
/* fall-through */
case PIPE_CAP_MAX_POINT_WIDTH_AA:
return 255.0; /* arbitrary */
case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
return 0.0;
case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
return 16.0; /* arbitrary */
default:
return 0;
}
}
static const char *
cell_get_name( struct pipe_context *pipe )
{
return "Cell";
}
static const char *
cell_get_vendor( struct pipe_context *pipe )
{
return "Tungsten Graphics, Inc.";
}
static void
cell_destroy_context( struct pipe_context *pipe )
{
struct cell_context *cell = cell_context(pipe);
cell_spu_exit(cell);
align_free(cell);
}
static struct draw_context *
cell_draw_create(struct cell_context *cell)
{
struct draw_context *draw = draw_create();
if (getenv("GALLIUM_CELL_VS")) {
/* plug in SPU-based vertex transformation code */
draw->shader_queue_flush = cell_vertex_shader_queue_flush;
draw->driver_private = cell;
}
return draw;
}
struct pipe_context *
cell_create_context(struct pipe_winsys *winsys, struct cell_winsys *cws)
{
struct cell_context *cell;
uint spu, buf;
/* some fields need to be 16-byte aligned, so align the whole object */
cell = (struct cell_context*) align_malloc(sizeof(struct cell_context), 16);
if (!cell)
return NULL;
memset(cell, 0, sizeof(*cell));
cell->winsys = cws;
cell->pipe.winsys = winsys;
cell->pipe.destroy = cell_destroy_context;
/* queries */
cell->pipe.is_format_supported = cell_is_format_supported;
cell->pipe.get_name = cell_get_name;
cell->pipe.get_vendor = cell_get_vendor;
cell->pipe.get_param = cell_get_param;
cell->pipe.get_paramf = cell_get_paramf;
/* state setters */
cell->pipe.create_blend_state = cell_create_blend_state;
cell->pipe.bind_blend_state = cell_bind_blend_state;
cell->pipe.delete_blend_state = cell_delete_blend_state;
cell->pipe.create_sampler_state = cell_create_sampler_state;
cell->pipe.bind_sampler_state = cell_bind_sampler_state;
cell->pipe.delete_sampler_state = cell_delete_sampler_state;
cell->pipe.create_depth_stencil_alpha_state = cell_create_depth_stencil_alpha_state;
cell->pipe.bind_depth_stencil_alpha_state = cell_bind_depth_stencil_alpha_state;
cell->pipe.delete_depth_stencil_alpha_state = cell_delete_depth_stencil_alpha_state;
cell->pipe.create_rasterizer_state = cell_create_rasterizer_state;
cell->pipe.bind_rasterizer_state = cell_bind_rasterizer_state;
cell->pipe.delete_rasterizer_state = cell_delete_rasterizer_state;
cell->pipe.create_fs_state = cell_create_fs_state;
cell->pipe.bind_fs_state = cell_bind_fs_state;
cell->pipe.delete_fs_state = cell_delete_fs_state;
cell->pipe.create_vs_state = cell_create_vs_state;
cell->pipe.bind_vs_state = cell_bind_vs_state;
cell->pipe.delete_vs_state = cell_delete_vs_state;
cell->pipe.set_blend_color = cell_set_blend_color;
cell->pipe.set_clip_state = cell_set_clip_state;
cell->pipe.set_constant_buffer = cell_set_constant_buffer;
cell->pipe.set_framebuffer_state = cell_set_framebuffer_state;
cell->pipe.set_polygon_stipple = cell_set_polygon_stipple;
cell->pipe.set_scissor_state = cell_set_scissor_state;
cell->pipe.set_viewport_state = cell_set_viewport_state;
cell->pipe.set_vertex_buffer = cell_set_vertex_buffer;
cell->pipe.set_vertex_element = cell_set_vertex_element;
cell->pipe.draw_arrays = cell_draw_arrays;
cell->pipe.draw_elements = cell_draw_elements;
cell->pipe.clear = cell_clear_surface;
cell->pipe.flush = cell_flush;
/* textures */
cell->pipe.texture_create = cell_texture_create;
cell->pipe.texture_release = cell_texture_release;
cell->pipe.get_tex_surface = cell_get_tex_surface;
cell->pipe.set_sampler_texture = cell_set_sampler_texture;
#if 0
cell->pipe.begin_query = cell_begin_query;
cell->pipe.end_query = cell_end_query;
cell->pipe.wait_query = cell_wait_query;
#endif
cell_init_surface_functions(cell);
cell->draw = cell_draw_create(cell);
cell_init_vbuf(cell);
draw_set_rasterize_stage(cell->draw, cell->vbuf);
/*
* SPU stuff
*/
cell->num_spus = 6;
cell_start_spus(cell);
/* init command, vertex/index buffer info */
for (buf = 0; buf < CELL_NUM_BUFFERS; buf++) {
cell->buffer_size[buf] = 0;
/* init batch buffer status values,
* mark 0th buffer as used, rest as free.
*/
for (spu = 0; spu < cell->num_spus; spu++) {
if (buf == 0)
cell->buffer_status[spu][buf][0] = CELL_BUFFER_STATUS_USED;
else
cell->buffer_status[spu][buf][0] = CELL_BUFFER_STATUS_FREE;
}
}
return &cell->pipe;
}
|