summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/cell/ppu/cell_context.c
blob: 35cd6874a27ba2a4a78a029830bfa15708922e87 (plain)
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
/**************************************************************************
 * 
 * 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 "util/u_memory.h"
#include "pipe/p_winsys.h"
#include "pipe/p_screen.h"

#include "draw/draw_context.h"
#include "draw/draw_private.h"

#include "cell/common.h"
#include "cell_batch.h"
#include "cell_clear.h"
#include "cell_context.h"
#include "cell_draw_arrays.h"
#include "cell_flush.h"
#include "cell_state.h"
#include "cell_surface.h"
#include "cell_spu.h"
#include "cell_pipe_state.h"
#include "cell_texture.h"
#include "cell_vbuf.h"



static void
cell_destroy_context( struct pipe_context *pipe )
{
   struct cell_context *cell = cell_context(pipe);

   util_delete_keymap(cell->fragment_ops_cache, NULL);

   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 0 /* broken */
   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;
   }
#endif

   return draw;
}


static const struct debug_named_value cell_debug_flags[] = {
   {"checker", CELL_DEBUG_CHECKER},/**< modulate tile clear color by SPU ID */
   {"asm", CELL_DEBUG_ASM},        /**< dump SPU asm code */
   {"sync", CELL_DEBUG_SYNC},      /**< SPUs do synchronous DMA */
   {"fragops", CELL_DEBUG_FRAGMENT_OPS}, /**< SPUs emit fragment ops debug messages*/
   {"fragopfallback", CELL_DEBUG_FRAGMENT_OP_FALLBACK}, /**< SPUs use reference implementation for fragment ops*/
   {NULL, 0}
};


struct pipe_context *
cell_create_context(struct pipe_screen *screen,
                    struct cell_winsys *cws)
{
   struct cell_context *cell;

   /* 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 = screen->winsys;
   cell->pipe.screen = screen;
   cell->pipe.destroy = cell_destroy_context;

   cell->pipe.clear = cell_clear_surface;
   cell->pipe.flush = cell_flush;

#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_draw_functions(cell);
   cell_init_state_functions(cell);
   cell_init_shader_functions(cell);
   cell_init_surface_functions(cell);
   cell_init_texture_functions(cell);
   cell_init_vertex_functions(cell);

   cell->draw = cell_draw_create(cell);

   /* Create cache of fragment ops generated code */
   cell->fragment_ops_cache =
      util_new_keymap(sizeof(struct cell_fragment_ops_key), ~0, NULL);

   cell_init_vbuf(cell);

   draw_set_rasterize_stage(cell->draw, cell->vbuf);

   /* convert all points/lines to tris for the time being */
   draw_wide_point_threshold(cell->draw, 0.0);
   draw_wide_line_threshold(cell->draw, 0.0);

   /* get env vars or read config file to get debug flags */
   cell->debug_flags = debug_get_flags_option("CELL_DEBUG", 
                                              cell_debug_flags, 
                                              0 );

   /*
    * SPU stuff
    */
   cell->num_spus = 6;
   /* XXX is this in SDK 3.0 only?
   cell->num_spus = spe_cpu_info_get(SPE_COUNT_PHYSICAL_SPES, -1);
   */

   cell_start_spus(cell);

   cell_init_batch_buffers(cell);

   /* make sure SPU initializations are done before proceeding */
   cell_flush_int(cell, CELL_FLUSH_WAIT);

   return &cell->pipe;
}