Cell: implement pipe_screen for cell driver
[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 "pipe/p_screen.h"
41
42 #include "draw/draw_context.h"
43 #include "draw/draw_private.h"
44
45 #include "cell/common.h"
46 #include "cell_clear.h"
47 #include "cell_context.h"
48 #include "cell_draw_arrays.h"
49 #include "cell_flush.h"
50 #include "cell_render.h"
51 #include "cell_state.h"
52 #include "cell_surface.h"
53 #include "cell_spu.h"
54 #include "cell_pipe_state.h"
55 #include "cell_texture.h"
56 #include "cell_vbuf.h"
57
58
59
60 static boolean
61 cell_is_format_supported( struct pipe_context *pipe,
62 enum pipe_format format, uint type )
63 {
64 /*struct cell_context *cell = cell_context( pipe );*/
65
66 switch (type) {
67 case PIPE_TEXTURE:
68 /* cell supports all texture formats, XXX for now anyway */
69 return TRUE;
70 case PIPE_SURFACE:
71 /* cell supports all (off-screen) surface formats, XXX for now */
72 return TRUE;
73 default:
74 assert(0);
75 return FALSE;
76 }
77 }
78
79
80 static int cell_get_param(struct pipe_context *pipe, int param)
81 {
82 return pipe->screen->get_param(pipe->screen, param);
83 }
84
85 static float cell_get_paramf(struct pipe_context *pipe, int param)
86 {
87 return pipe->screen->get_paramf(pipe->screen, param);
88 }
89
90 static const char *
91 cell_get_name( struct pipe_context *pipe )
92 {
93 return pipe->screen->get_name(pipe->screen);
94 }
95
96 static const char *
97 cell_get_vendor( struct pipe_context *pipe )
98 {
99 return pipe->screen->get_vendor(pipe->screen);
100 }
101
102
103
104 static void
105 cell_destroy_context( struct pipe_context *pipe )
106 {
107 struct cell_context *cell = cell_context(pipe);
108
109 cell_spu_exit(cell);
110
111 align_free(cell);
112 }
113
114
115 static struct draw_context *
116 cell_draw_create(struct cell_context *cell)
117 {
118 struct draw_context *draw = draw_create();
119
120 if (getenv("GALLIUM_CELL_VS")) {
121 /* plug in SPU-based vertex transformation code */
122 draw->shader_queue_flush = cell_vertex_shader_queue_flush;
123 draw->driver_private = cell;
124 }
125
126 return draw;
127 }
128
129
130 struct pipe_context *
131 cell_create_context(struct pipe_screen *screen,
132 struct cell_winsys *cws)
133 {
134 struct cell_context *cell;
135 uint spu, buf;
136
137 /* some fields need to be 16-byte aligned, so align the whole object */
138 cell = (struct cell_context*) align_malloc(sizeof(struct cell_context), 16);
139 if (!cell)
140 return NULL;
141
142 memset(cell, 0, sizeof(*cell));
143
144 cell->winsys = cws;
145 cell->pipe.winsys = screen->winsys;
146 cell->pipe.screen = screen;
147 cell->pipe.destroy = cell_destroy_context;
148
149 /* queries */
150 cell->pipe.is_format_supported = cell_is_format_supported;
151 cell->pipe.get_name = cell_get_name;
152 cell->pipe.get_vendor = cell_get_vendor;
153 cell->pipe.get_param = cell_get_param;
154 cell->pipe.get_paramf = cell_get_paramf;
155
156
157 /* state setters */
158 cell->pipe.set_vertex_buffer = cell_set_vertex_buffer;
159 cell->pipe.set_vertex_element = cell_set_vertex_element;
160
161 cell->pipe.draw_arrays = cell_draw_arrays;
162 cell->pipe.draw_elements = cell_draw_elements;
163
164 cell->pipe.clear = cell_clear_surface;
165 cell->pipe.flush = cell_flush;
166
167 #if 0
168 cell->pipe.begin_query = cell_begin_query;
169 cell->pipe.end_query = cell_end_query;
170 cell->pipe.wait_query = cell_wait_query;
171 #endif
172
173 cell_init_state_functions(cell);
174 cell_init_shader_functions(cell);
175 cell_init_surface_functions(cell);
176 cell_init_texture_functions(cell);
177
178 cell->draw = cell_draw_create(cell);
179
180 cell_init_vbuf(cell);
181 draw_set_rasterize_stage(cell->draw, cell->vbuf);
182
183 /*
184 * SPU stuff
185 */
186 cell->num_spus = 6;
187 /* XXX is this in SDK 3.0 only?
188 cell->num_spus = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1);
189 */
190
191 cell_start_spus(cell);
192
193 /* init command, vertex/index buffer info */
194 for (buf = 0; buf < CELL_NUM_BUFFERS; buf++) {
195 cell->buffer_size[buf] = 0;
196
197 /* init batch buffer status values,
198 * mark 0th buffer as used, rest as free.
199 */
200 for (spu = 0; spu < cell->num_spus; spu++) {
201 if (buf == 0)
202 cell->buffer_status[spu][buf][0] = CELL_BUFFER_STATUS_USED;
203 else
204 cell->buffer_status[spu][buf][0] = CELL_BUFFER_STATUS_FREE;
205 }
206 }
207
208 return &cell->pipe;
209 }