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 **************************************************************************/
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"
51 #include "cell_texture.h"
52 #include "cell_vbuf.h"
57 cell_is_format_supported( struct pipe_context
*pipe
,
58 enum pipe_format format
, uint type
)
60 /*struct cell_context *cell = cell_context( pipe );*/
64 /* cell supports all texture formats, XXX for now anyway */
67 /* cell supports all (off-screen) surface formats, XXX for now */
76 static int cell_get_param(struct pipe_context
*pipe
, int param
)
79 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS
:
81 case PIPE_CAP_NPOT_TEXTURES
:
83 case PIPE_CAP_TWO_SIDED_STENCIL
:
89 case PIPE_CAP_ANISOTROPIC_FILTER
:
91 case PIPE_CAP_POINT_SPRITE
:
93 case PIPE_CAP_MAX_RENDER_TARGETS
:
95 case PIPE_CAP_OCCLUSION_QUERY
:
97 case PIPE_CAP_TEXTURE_SHADOW_MAP
:
99 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS
:
100 return 12; /* max 2Kx2K */
101 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS
:
102 return 8; /* max 128x128x128 */
103 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS
:
104 return 12; /* max 2Kx2K */
110 static float cell_get_paramf(struct pipe_context
*pipe
, int param
)
113 case PIPE_CAP_MAX_LINE_WIDTH
:
115 case PIPE_CAP_MAX_LINE_WIDTH_AA
:
116 return 255.0; /* arbitrary */
118 case PIPE_CAP_MAX_POINT_WIDTH
:
120 case PIPE_CAP_MAX_POINT_WIDTH_AA
:
121 return 255.0; /* arbitrary */
123 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY
:
126 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS
:
127 return 16.0; /* arbitrary */
136 cell_get_name( struct pipe_context
*pipe
)
142 cell_get_vendor( struct pipe_context
*pipe
)
144 return "Tungsten Graphics, Inc.";
150 cell_destroy_context( struct pipe_context
*pipe
)
152 struct cell_context
*cell
= cell_context(pipe
);
160 static struct draw_context
*
161 cell_draw_create(struct cell_context
*cell
)
163 struct draw_context
*draw
= draw_create();
165 if (getenv("GALLIUM_CELL_VS")) {
166 /* plug in SPU-based vertex transformation code */
167 draw
->shader_queue_flush
= cell_vertex_shader_queue_flush
;
168 draw
->driver_private
= cell
;
175 struct pipe_context
*
176 cell_create_context(struct pipe_winsys
*winsys
, struct cell_winsys
*cws
)
178 struct cell_context
*cell
;
181 /* some fields need to be 16-byte aligned, so align the whole object */
182 cell
= (struct cell_context
*) align_malloc(sizeof(struct cell_context
), 16);
186 memset(cell
, 0, sizeof(*cell
));
189 cell
->pipe
.winsys
= winsys
;
190 cell
->pipe
.destroy
= cell_destroy_context
;
193 cell
->pipe
.is_format_supported
= cell_is_format_supported
;
194 cell
->pipe
.get_name
= cell_get_name
;
195 cell
->pipe
.get_vendor
= cell_get_vendor
;
196 cell
->pipe
.get_param
= cell_get_param
;
197 cell
->pipe
.get_paramf
= cell_get_paramf
;
201 cell
->pipe
.create_blend_state
= cell_create_blend_state
;
202 cell
->pipe
.bind_blend_state
= cell_bind_blend_state
;
203 cell
->pipe
.delete_blend_state
= cell_delete_blend_state
;
205 cell
->pipe
.create_sampler_state
= cell_create_sampler_state
;
206 cell
->pipe
.bind_sampler_state
= cell_bind_sampler_state
;
207 cell
->pipe
.delete_sampler_state
= cell_delete_sampler_state
;
209 cell
->pipe
.create_depth_stencil_alpha_state
= cell_create_depth_stencil_alpha_state
;
210 cell
->pipe
.bind_depth_stencil_alpha_state
= cell_bind_depth_stencil_alpha_state
;
211 cell
->pipe
.delete_depth_stencil_alpha_state
= cell_delete_depth_stencil_alpha_state
;
213 cell
->pipe
.create_rasterizer_state
= cell_create_rasterizer_state
;
214 cell
->pipe
.bind_rasterizer_state
= cell_bind_rasterizer_state
;
215 cell
->pipe
.delete_rasterizer_state
= cell_delete_rasterizer_state
;
217 cell
->pipe
.create_fs_state
= cell_create_fs_state
;
218 cell
->pipe
.bind_fs_state
= cell_bind_fs_state
;
219 cell
->pipe
.delete_fs_state
= cell_delete_fs_state
;
221 cell
->pipe
.create_vs_state
= cell_create_vs_state
;
222 cell
->pipe
.bind_vs_state
= cell_bind_vs_state
;
223 cell
->pipe
.delete_vs_state
= cell_delete_vs_state
;
225 cell
->pipe
.set_blend_color
= cell_set_blend_color
;
226 cell
->pipe
.set_clip_state
= cell_set_clip_state
;
227 cell
->pipe
.set_constant_buffer
= cell_set_constant_buffer
;
229 cell
->pipe
.set_framebuffer_state
= cell_set_framebuffer_state
;
231 cell
->pipe
.set_polygon_stipple
= cell_set_polygon_stipple
;
232 cell
->pipe
.set_scissor_state
= cell_set_scissor_state
;
233 cell
->pipe
.set_viewport_state
= cell_set_viewport_state
;
235 cell
->pipe
.set_vertex_buffer
= cell_set_vertex_buffer
;
236 cell
->pipe
.set_vertex_element
= cell_set_vertex_element
;
238 cell
->pipe
.draw_arrays
= cell_draw_arrays
;
239 cell
->pipe
.draw_elements
= cell_draw_elements
;
241 cell
->pipe
.clear
= cell_clear_surface
;
242 cell
->pipe
.flush
= cell_flush
;
245 cell
->pipe
.texture_create
= cell_texture_create
;
246 cell
->pipe
.texture_release
= cell_texture_release
;
247 cell
->pipe
.get_tex_surface
= cell_get_tex_surface
;
249 cell
->pipe
.set_sampler_texture
= cell_set_sampler_texture
;
252 cell
->pipe
.begin_query
= cell_begin_query
;
253 cell
->pipe
.end_query
= cell_end_query
;
254 cell
->pipe
.wait_query
= cell_wait_query
;
257 cell_init_surface_functions(cell
);
259 cell
->draw
= cell_draw_create(cell
);
261 cell_init_vbuf(cell
);
262 draw_set_rasterize_stage(cell
->draw
, cell
->vbuf
);
269 cell_start_spus(cell
);
271 /* init command, vertex/index buffer info */
272 for (buf
= 0; buf
< CELL_NUM_BUFFERS
; buf
++) {
273 cell
->buffer_size
[buf
] = 0;
275 /* init batch buffer status values,
276 * mark 0th buffer as used, rest as free.
278 for (spu
= 0; spu
< cell
->num_spus
; spu
++) {
280 cell
->buffer_status
[spu
][buf
][0] = CELL_BUFFER_STATUS_USED
;
282 cell
->buffer_status
[spu
][buf
][0] = CELL_BUFFER_STATUS_FREE
;