cell: move batch buffer init code
[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 "util/u_memory.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_batch.h"
47 #include "cell_clear.h"
48 #include "cell_context.h"
49 #include "cell_draw_arrays.h"
50 #include "cell_flush.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 void
61 cell_destroy_context( struct pipe_context *pipe )
62 {
63 struct cell_context *cell = cell_context(pipe);
64
65 cell_spu_exit(cell);
66
67 align_free(cell);
68 }
69
70
71 static struct draw_context *
72 cell_draw_create(struct cell_context *cell)
73 {
74 struct draw_context *draw = draw_create();
75
76 #if 0 /* broken */
77 if (getenv("GALLIUM_CELL_VS")) {
78 /* plug in SPU-based vertex transformation code */
79 draw->shader_queue_flush = cell_vertex_shader_queue_flush;
80 draw->driver_private = cell;
81 }
82 #endif
83
84 return draw;
85 }
86
87
88 #ifdef DEBUG
89 static const struct debug_named_value cell_debug_flags[] = {
90 {"checker", CELL_DEBUG_CHECKER},/**< modulate tile clear color by SPU ID */
91 {"sync", CELL_DEBUG_SYNC}, /**< SPUs do synchronous DMA */
92 {NULL, 0}
93 };
94 #endif
95
96
97 struct pipe_context *
98 cell_create_context(struct pipe_screen *screen,
99 struct cell_winsys *cws)
100 {
101 struct cell_context *cell;
102
103 /* some fields need to be 16-byte aligned, so align the whole object */
104 cell = (struct cell_context*) align_malloc(sizeof(struct cell_context), 16);
105 if (!cell)
106 return NULL;
107
108 memset(cell, 0, sizeof(*cell));
109
110 cell->winsys = cws;
111 cell->pipe.winsys = screen->winsys;
112 cell->pipe.screen = screen;
113 cell->pipe.destroy = cell_destroy_context;
114
115 cell->pipe.clear = cell_clear_surface;
116 cell->pipe.flush = cell_flush;
117
118 #if 0
119 cell->pipe.begin_query = cell_begin_query;
120 cell->pipe.end_query = cell_end_query;
121 cell->pipe.wait_query = cell_wait_query;
122 #endif
123
124 cell_init_draw_functions(cell);
125 cell_init_state_functions(cell);
126 cell_init_shader_functions(cell);
127 cell_init_surface_functions(cell);
128 cell_init_texture_functions(cell);
129 cell_init_vertex_functions(cell);
130
131 cell->draw = cell_draw_create(cell);
132
133 cell_init_vbuf(cell);
134
135 draw_set_rasterize_stage(cell->draw, cell->vbuf);
136
137 /* convert all points/lines to tris for the time being */
138 draw_wide_point_threshold(cell->draw, 0.0);
139 draw_wide_line_threshold(cell->draw, 0.0);
140
141 /* get env vars or read config file to get debug flags */
142 cell->debug_flags = debug_get_flags_option("CELL_DEBUG",
143 cell_debug_flags,
144 0 );
145
146 /*
147 * SPU stuff
148 */
149 cell->num_spus = 6;
150 /* XXX is this in SDK 3.0 only?
151 cell->num_spus = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1);
152 */
153
154 cell_start_spus(cell);
155
156 cell_init_batch_buffers(cell);
157
158 return &cell->pipe;
159 }