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 "util/u_memory.h"
39 #include "pipe/internal/p_winsys_screen.h"
40 #include "pipe/p_screen.h"
42 #include "draw/draw_context.h"
43 #include "draw/draw_private.h"
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_fence.h"
51 #include "cell_flush.h"
52 #include "cell_state.h"
53 #include "cell_surface.h"
55 #include "cell_pipe_state.h"
56 #include "cell_texture.h"
57 #include "cell_vbuf.h"
62 cell_destroy_context( struct pipe_context
*pipe
)
64 struct cell_context
*cell
= cell_context(pipe
);
66 util_delete_keymap(cell
->fragment_ops_cache
, NULL
);
74 static struct draw_context
*
75 cell_draw_create(struct cell_context
*cell
)
77 struct draw_context
*draw
= draw_create();
80 if (getenv("GALLIUM_CELL_VS")) {
81 /* plug in SPU-based vertex transformation code */
82 draw
->shader_queue_flush
= cell_vertex_shader_queue_flush
;
83 draw
->driver_private
= cell
;
91 static const struct debug_named_value cell_debug_flags
[] = {
92 {"checker", CELL_DEBUG_CHECKER
},/**< modulate tile clear color by SPU ID */
93 {"asm", CELL_DEBUG_ASM
}, /**< dump SPU asm code */
94 {"sync", CELL_DEBUG_SYNC
}, /**< SPUs do synchronous DMA */
95 {"fragops", CELL_DEBUG_FRAGMENT_OPS
}, /**< SPUs emit fragment ops debug messages*/
96 {"fragopfallback", CELL_DEBUG_FRAGMENT_OP_FALLBACK
}, /**< SPUs use reference implementation for fragment ops*/
97 {"cmd", CELL_DEBUG_CMD
}, /**< SPUs dump command buffer info */
98 {"cache", CELL_DEBUG_CACHE
}, /**< report texture cache stats on exit */
103 struct pipe_context
*
104 cell_create_context(struct pipe_screen
*screen
,
105 struct cell_winsys
*cws
)
107 struct cell_context
*cell
;
110 /* some fields need to be 16-byte aligned, so align the whole object */
111 cell
= (struct cell_context
*) align_malloc(sizeof(struct cell_context
), 16);
115 memset(cell
, 0, sizeof(*cell
));
118 cell
->pipe
.winsys
= screen
->winsys
;
119 cell
->pipe
.screen
= screen
;
120 cell
->pipe
.destroy
= cell_destroy_context
;
122 cell
->pipe
.clear
= cell_clear_surface
;
123 cell
->pipe
.flush
= cell_flush
;
126 cell
->pipe
.begin_query
= cell_begin_query
;
127 cell
->pipe
.end_query
= cell_end_query
;
128 cell
->pipe
.wait_query
= cell_wait_query
;
131 cell_init_draw_functions(cell
);
132 cell_init_state_functions(cell
);
133 cell_init_shader_functions(cell
);
134 cell_init_surface_functions(cell
);
135 cell_init_vertex_functions(cell
);
137 cell
->draw
= cell_draw_create(cell
);
139 /* Create cache of fragment ops generated code */
140 cell
->fragment_ops_cache
=
141 util_new_keymap(sizeof(struct cell_fragment_ops_key
), ~0, NULL
);
143 cell_init_vbuf(cell
);
145 draw_set_rasterize_stage(cell
->draw
, cell
->vbuf
);
147 /* convert all points/lines to tris for the time being */
148 draw_wide_point_threshold(cell
->draw
, 0.0);
149 draw_wide_line_threshold(cell
->draw
, 0.0);
151 /* get env vars or read config file to get debug flags */
152 cell
->debug_flags
= debug_get_flags_option("CELL_DEBUG",
156 for (i
= 0; i
< CELL_NUM_BUFFERS
; i
++)
157 cell_fence_init(&cell
->fenced_buffers
[i
].fence
);
163 /* This call only works with SDK 3.0. Anyone still using 2.1??? */
164 cell
->num_cells
= spe_cpu_info_get(SPE_COUNT_PHYSICAL_CPU_NODES
, -1);
165 cell
->num_spus
= spe_cpu_info_get(SPE_COUNT_USABLE_SPES
, -1);
166 if (cell
->debug_flags
) {
167 printf("Cell: found %d Cell(s) with %u SPUs\n",
168 cell
->num_cells
, cell
->num_spus
);
170 if (getenv("CELL_NUM_SPUS")) {
171 cell
->num_spus
= atoi(getenv("CELL_NUM_SPUS"));
172 assert(cell
->num_spus
> 0);
175 cell_start_spus(cell
);
177 cell_init_batch_buffers(cell
);
179 /* make sure SPU initializations are done before proceeding */
180 cell_flush_int(cell
, CELL_FLUSH_WAIT
);