f7e2284445d5879b6439c0a7e0baba5254c6c37c
[profile/ivi/mesa.git] / src / gallium / drivers / cell / ppu / cell_context.h
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 #ifndef CELL_CONTEXT_H
30 #define CELL_CONTEXT_H
31
32
33 #include "pipe/p_context.h"
34 #include "pipe/p_defines.h"
35 #include "draw/draw_vertex.h"
36 #include "draw/draw_vbuf.h"
37 /*#include "cell_winsys.h"*/
38 #include "cell/common.h"
39 #include "rtasm/rtasm_ppc_spe.h"
40 #include "tgsi/tgsi_scan.h"
41 #include "util/u_keymap.h"
42
43
44 struct cell_vbuf_render;
45
46
47 /**
48  * Cell vertex shader state, subclass of pipe_shader_state.
49  */
50 struct cell_vertex_shader_state
51 {
52    struct pipe_shader_state shader;
53    struct tgsi_shader_info info;
54    void *draw_data;
55 };
56
57
58 /**
59  * Cell fragment shader state, subclass of pipe_shader_state.
60  */
61 struct cell_fragment_shader_state
62 {
63    struct pipe_shader_state shader;
64    struct tgsi_shader_info info;
65    struct spe_function code;
66    void *data;
67 };
68
69
70 /**
71  * Key for mapping per-fragment state to cached SPU machine code.
72  *  keymap(cell_fragment_ops_key) => cell_command_fragment_ops
73  */
74 struct cell_fragment_ops_key
75 {
76    struct pipe_blend_state blend;
77    struct pipe_blend_color blend_color;
78    struct pipe_depth_stencil_alpha_state dsa;
79    enum pipe_format color_format;
80    enum pipe_format zs_format;
81 };
82
83
84 struct cell_buffer_node;
85
86 /**
87  * Fenced buffer list.  List of buffers which can be unreferenced after
88  * the fence has been executed/signalled.
89  */
90 struct cell_buffer_list
91 {
92    PIPE_ALIGN_VAR(16) struct cell_fence fence;
93    struct cell_buffer_node *head;
94 };
95
96 struct cell_velems_state
97 {
98    unsigned count;
99    struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS];
100 };
101
102 /**
103  * Per-context state, subclass of pipe_context.
104  */
105 struct cell_context
106 {
107    struct pipe_context pipe;
108
109    struct cell_winsys *winsys;
110
111    const struct pipe_blend_state *blend;
112    const struct pipe_sampler_state *sampler[PIPE_MAX_SAMPLERS];
113    uint num_samplers;
114    const struct pipe_depth_stencil_alpha_state *depth_stencil;
115    const struct pipe_rasterizer_state *rasterizer;
116    const struct cell_vertex_shader_state *vs;
117    const struct cell_fragment_shader_state *fs;
118    const struct cell_velems_state *velems;
119
120    struct spe_function logic_op;
121
122    struct pipe_blend_color blend_color;
123    struct pipe_stencil_ref stencil_ref;
124    struct pipe_clip_state clip;
125    struct pipe_buffer *constants[2];
126    struct pipe_framebuffer_state framebuffer;
127    struct pipe_poly_stipple poly_stipple;
128    struct pipe_scissor_state scissor;
129    struct cell_texture *texture[PIPE_MAX_SAMPLERS];
130    struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
131    uint num_textures;
132    struct pipe_viewport_state viewport;
133    struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
134    uint num_vertex_buffers;
135
136    ubyte *cbuf_map[PIPE_MAX_COLOR_BUFS];
137    ubyte *zsbuf_map;
138
139    uint dirty;
140    uint dirty_textures;  /* bitmask of texture units */
141    uint dirty_samplers;  /* bitmask of sampler units */
142
143    /** Cache of code generated for per-fragment ops */
144    struct keymap *fragment_ops_cache;
145
146    /** The primitive drawing context */
147    struct draw_context *draw;
148    struct draw_stage *render_stage;
149
150    /** For post-transformed vertex buffering: */
151    struct cell_vbuf_render *vbuf_render;
152    struct draw_stage *vbuf;
153
154    struct vertex_info vertex_info;
155
156    /** Mapped constant buffers */
157    void *mapped_constants[PIPE_SHADER_TYPES];
158
159    PIPE_ALIGN_VAR(16) struct cell_spu_function_info spu_functions;
160
161    uint num_cells, num_spus;
162
163    /** Buffers for command batches, vertex/index data */
164    uint buffer_size[CELL_NUM_BUFFERS];
165    PIPE_ALIGN_VAR(16) ubyte buffer[CELL_NUM_BUFFERS][CELL_BUFFER_SIZE];
166
167    int cur_batch;  /**< which buffer is being filled w/ commands */
168
169    /** [4] to ensure 16-byte alignment for each status word */
170    PIPE_ALIGN_VAR(16) uint buffer_status[CELL_MAX_SPUS][CELL_NUM_BUFFERS][4];
171
172
173    /** Associated with each command/batch buffer is a list of pipe_buffers
174     * that are fenced.  When the last command in a buffer is executed, the
175     * fence will be signalled, indicating that any pipe_buffers preceeding
176     * that fence can be unreferenced (and probably freed).
177     */
178    struct cell_buffer_list fenced_buffers[CELL_NUM_BUFFERS];
179
180
181    struct spe_function attrib_fetch;
182    unsigned attrib_fetch_offsets[PIPE_MAX_ATTRIBS];
183
184    unsigned debug_flags;
185 };
186
187
188
189
190 static INLINE struct cell_context *
191 cell_context(struct pipe_context *pipe)
192 {
193    return (struct cell_context *) pipe;
194 }
195
196
197 struct pipe_context *
198 cell_create_context(struct pipe_screen *screen,
199                     void *priv );
200
201 extern void
202 cell_vertex_shader_queue_flush(struct draw_context *draw);
203
204
205 /* XXX find a better home for this */
206 extern void cell_update_vertex_fetch(struct draw_context *draw);
207
208
209 #endif /* CELL_CONTEXT_H */