74ebf90d5803d928d676087a6aa8ac7850553126
[profile/ivi/mesa.git] / src / gallium / drivers / llvmpipe / lp_state.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 /* Authors:  Keith Whitwell <keith@tungstengraphics.com>
29  */
30
31 #ifndef LP_STATE_H
32 #define LP_STATE_H
33
34 #include "gallivm/lp_bld.h"
35
36 #include "pipe/p_state.h"
37 #include "tgsi/tgsi_scan.h"
38 #include "lp_jit.h"
39 #include "gallivm/lp_bld_sample.h" /* for struct lp_sampler_static_state */
40
41
42 #define LP_NEW_VIEWPORT      0x1
43 #define LP_NEW_RASTERIZER    0x2
44 #define LP_NEW_FS            0x4
45 #define LP_NEW_BLEND         0x8
46 #define LP_NEW_CLIP          0x10
47 #define LP_NEW_SCISSOR       0x20
48 #define LP_NEW_STIPPLE       0x40
49 #define LP_NEW_FRAMEBUFFER   0x80
50 #define LP_NEW_DEPTH_STENCIL_ALPHA 0x100
51 #define LP_NEW_CONSTANTS     0x200
52 #define LP_NEW_SAMPLER       0x400
53 #define LP_NEW_SAMPLER_VIEW  0x800
54 #define LP_NEW_VERTEX        0x1000
55 #define LP_NEW_VS            0x2000
56 #define LP_NEW_QUERY         0x4000
57 #define LP_NEW_BLEND_COLOR   0x8000
58
59
60 struct vertex_info;
61 struct pipe_context;
62 struct llvmpipe_context;
63
64 struct lp_fragment_shader;
65
66
67 struct lp_fragment_shader_variant_key
68 {
69    struct pipe_depth_state depth;
70    struct pipe_stencil_state stencil[2];
71    struct pipe_alpha_state alpha;
72    struct pipe_blend_state blend;
73    enum pipe_format zsbuf_format;
74    unsigned nr_cbufs:8;
75    unsigned flatshade:1;
76    unsigned scissor:1;
77
78    struct {
79       ubyte colormask;
80    } cbuf_blend[PIPE_MAX_COLOR_BUFS];
81    
82    struct lp_sampler_static_state sampler[PIPE_MAX_SAMPLERS];
83 };
84
85
86 struct lp_fragment_shader_variant
87 {
88    struct lp_fragment_shader *shader;
89
90    struct lp_fragment_shader_variant_key key;
91
92    LLVMValueRef function[2];
93
94    lp_jit_frag_func jit_function[2];
95
96    struct lp_fragment_shader_variant *next;
97 };
98
99
100 /**
101  * Subclass of pipe_shader_state (though it doesn't really need to be).
102  *
103  * This is starting to look an awful lot like a quad pipeline stage...
104  */
105 struct lp_fragment_shader
106 {
107    struct pipe_shader_state base;
108
109    struct tgsi_shader_info info;
110
111    struct lp_fragment_shader_variant *variants;
112
113    struct lp_fragment_shader_variant *current;
114 };
115
116
117 /** Subclass of pipe_shader_state */
118 struct lp_vertex_shader {
119    struct pipe_shader_state shader;
120    struct draw_vertex_shader *draw_data;
121 };
122
123 struct lp_velems_state {
124    unsigned count;
125    struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS];
126 };
127
128
129 void *
130 llvmpipe_create_blend_state(struct pipe_context *,
131                             const struct pipe_blend_state *);
132 void llvmpipe_bind_blend_state(struct pipe_context *,
133                                void *);
134 void llvmpipe_delete_blend_state(struct pipe_context *,
135                                  void *);
136
137 void *
138 llvmpipe_create_sampler_state(struct pipe_context *,
139                               const struct pipe_sampler_state *);
140 void llvmpipe_bind_sampler_states(struct pipe_context *, unsigned, void **);
141 void
142 llvmpipe_bind_vertex_sampler_states(struct pipe_context *,
143                                     unsigned num_samplers,
144                                     void **samplers);
145 void llvmpipe_delete_sampler_state(struct pipe_context *, void *);
146
147 void *
148 llvmpipe_create_depth_stencil_state(struct pipe_context *,
149                                     const struct pipe_depth_stencil_alpha_state *);
150 void llvmpipe_bind_depth_stencil_state(struct pipe_context *, void *);
151 void llvmpipe_delete_depth_stencil_state(struct pipe_context *, void *);
152
153 void *
154 llvmpipe_create_rasterizer_state(struct pipe_context *,
155                                  const struct pipe_rasterizer_state *);
156 void llvmpipe_bind_rasterizer_state(struct pipe_context *, void *);
157 void llvmpipe_delete_rasterizer_state(struct pipe_context *, void *);
158
159 void llvmpipe_set_framebuffer_state( struct pipe_context *,
160                                      const struct pipe_framebuffer_state * );
161
162 void llvmpipe_set_blend_color( struct pipe_context *pipe,
163                                const struct pipe_blend_color *blend_color );
164
165 void llvmpipe_set_stencil_ref( struct pipe_context *pipe,
166                                const struct pipe_stencil_ref *stencil_ref );
167
168 void llvmpipe_set_clip_state( struct pipe_context *,
169                               const struct pipe_clip_state * );
170
171 void llvmpipe_set_constant_buffer(struct pipe_context *,
172                                   uint shader, uint index,
173                                   struct pipe_buffer *buf);
174
175 void *llvmpipe_create_fs_state(struct pipe_context *,
176                                const struct pipe_shader_state *);
177 void llvmpipe_bind_fs_state(struct pipe_context *, void *);
178 void llvmpipe_delete_fs_state(struct pipe_context *, void *);
179 void *llvmpipe_create_vs_state(struct pipe_context *,
180                                const struct pipe_shader_state *);
181 void llvmpipe_bind_vs_state(struct pipe_context *, void *);
182 void llvmpipe_delete_vs_state(struct pipe_context *, void *);
183
184 void *llvmpipe_create_vertex_elements_state(struct pipe_context *,
185                                             unsigned count,
186                                             const struct pipe_vertex_element *);
187 void llvmpipe_bind_vertex_elements_state(struct pipe_context *, void *);
188 void llvmpipe_delete_vertex_elements_state(struct pipe_context *, void *);
189
190 void llvmpipe_set_polygon_stipple( struct pipe_context *,
191                                    const struct pipe_poly_stipple * );
192
193 void llvmpipe_set_scissor_state( struct pipe_context *,
194                                  const struct pipe_scissor_state * );
195
196 void llvmpipe_set_fragment_sampler_views(struct pipe_context *,
197                                          unsigned num,
198                                          struct pipe_sampler_view **);
199
200 void
201 llvmpipe_set_vertex_sampler_views(struct pipe_context *,
202                                   unsigned num,
203                                   struct pipe_sampler_view **);
204
205 struct pipe_sampler_view *
206 llvmpipe_create_sampler_view(struct pipe_context *pipe,
207                             struct pipe_texture *texture,
208                             const struct pipe_sampler_view *templ);
209
210 void
211 llvmpipe_sampler_view_destroy(struct pipe_context *pipe,
212                               struct pipe_sampler_view *view);
213
214 void llvmpipe_set_viewport_state( struct pipe_context *,
215                                   const struct pipe_viewport_state * );
216
217 void llvmpipe_set_vertex_buffers(struct pipe_context *,
218                                  unsigned count,
219                                  const struct pipe_vertex_buffer *);
220
221 void llvmpipe_update_fs(struct llvmpipe_context *lp);
222
223 void llvmpipe_update_derived( struct llvmpipe_context *llvmpipe );
224
225
226 void llvmpipe_draw_arrays(struct pipe_context *pipe, unsigned mode,
227                              unsigned start, unsigned count);
228
229 void llvmpipe_draw_elements(struct pipe_context *pipe,
230                                struct pipe_buffer *indexBuffer,
231                                unsigned indexSize,
232                                unsigned mode, unsigned start, unsigned count);
233 void
234 llvmpipe_draw_range_elements(struct pipe_context *pipe,
235                              struct pipe_buffer *indexBuffer,
236                              unsigned indexSize,
237                              unsigned min_index,
238                              unsigned max_index,
239                              unsigned mode, unsigned start, unsigned count);
240
241 void
242 llvmpipe_map_texture_surfaces(struct llvmpipe_context *lp);
243
244 void
245 llvmpipe_unmap_texture_surfaces(struct llvmpipe_context *lp);
246
247
248 #endif