Merge remote branch 'origin/mesa_7_7_branch'
[mesa.git] / src / gallium / drivers / svga / svga_context.h
1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 **********************************************************/
25
26 #ifndef SVGA_CONTEXT_H
27 #define SVGA_CONTEXT_H
28
29
30 #include "pipe/p_context.h"
31 #include "pipe/p_defines.h"
32 #include "pipe/p_state.h"
33
34 #include "util/u_double_list.h"
35
36 #include "tgsi/tgsi_scan.h"
37
38
39 #define SVGA_TEX_UNITS 8
40
41 struct draw_vertex_shader;
42 struct svga_shader_result;
43 struct SVGACmdMemory;
44 struct util_bitmask;
45 struct u_upload_mgr;
46
47
48 struct svga_shader
49 {
50 const struct tgsi_token *tokens;
51
52 struct tgsi_shader_info info;
53
54 struct svga_shader_result *results;
55
56 unsigned id;
57
58 boolean use_sm30;
59 };
60
61 struct svga_fragment_shader
62 {
63 struct svga_shader base;
64 };
65
66 struct svga_vertex_shader
67 {
68 struct svga_shader base;
69
70 struct draw_vertex_shader *draw_shader;
71 };
72
73
74 struct svga_cache_context;
75 struct svga_tracked_state;
76
77 struct svga_blend_state {
78
79 boolean need_white_fragments;
80
81 /* Should be per-render-target:
82 */
83 struct {
84 uint8_t writemask;
85
86 boolean blend_enable;
87 uint8_t srcblend;
88 uint8_t dstblend;
89 uint8_t blendeq;
90
91 boolean separate_alpha_blend_enable;
92 uint8_t srcblend_alpha;
93 uint8_t dstblend_alpha;
94 uint8_t blendeq_alpha;
95
96 } rt[1];
97 };
98
99 struct svga_depth_stencil_state {
100 unsigned zfunc:8;
101 unsigned zenable:1;
102 unsigned zwriteenable:1;
103
104 unsigned alphatestenable:1;
105 unsigned alphafunc:8;
106
107 struct {
108 unsigned enabled:1;
109 unsigned func:8;
110 unsigned fail:8;
111 unsigned zfail:8;
112 unsigned pass:8;
113 } stencil[2];
114
115 /* SVGA3D has one ref/mask/writemask triple shared between front &
116 * back face stencil. We really need two:
117 */
118 unsigned stencil_ref:8;
119 unsigned stencil_mask:8;
120 unsigned stencil_writemask:8;
121
122 float alpharef;
123 };
124
125 #define SVGA_UNFILLED_DISABLE 0
126 #define SVGA_UNFILLED_LINE 1
127 #define SVGA_UNFILLED_POINT 2
128
129 #define SVGA_PIPELINE_FLAG_POINTS (1<<PIPE_PRIM_POINTS)
130 #define SVGA_PIPELINE_FLAG_LINES (1<<PIPE_PRIM_LINES)
131 #define SVGA_PIPELINE_FLAG_TRIS (1<<PIPE_PRIM_TRIANGLES)
132
133 struct svga_rasterizer_state {
134 struct pipe_rasterizer_state templ; /* needed for draw module */
135
136 unsigned shademode:8;
137 unsigned cullmode:8;
138 unsigned scissortestenable:1;
139 unsigned multisampleantialias:1;
140 unsigned antialiasedlineenable:1;
141 unsigned lastpixel:1;
142
143 unsigned linepattern;
144
145 float slopescaledepthbias;
146 float depthbias;
147 float pointsize;
148 float pointsize_min;
149 float pointsize_max;
150
151 unsigned hw_unfilled:16; /* PIPE_POLYGON_MODE_x */
152 unsigned need_pipeline:16; /* which prims do we need help for? */
153 };
154
155 struct svga_sampler_state {
156 unsigned mipfilter;
157 unsigned magfilter;
158 unsigned minfilter;
159 unsigned aniso_level;
160 float lod_bias;
161 unsigned addressu;
162 unsigned addressv;
163 unsigned addressw;
164 unsigned bordercolor;
165 unsigned normalized_coords:1;
166 unsigned compare_mode:1;
167 unsigned compare_func:3;
168
169 unsigned min_lod;
170 unsigned view_min_lod;
171 unsigned view_max_lod;
172 };
173
174 /* Use to calculate differences between state emitted to hardware and
175 * current driver-calculated state.
176 */
177 struct svga_state
178 {
179 const struct svga_blend_state *blend;
180 const struct svga_depth_stencil_state *depth;
181 const struct svga_rasterizer_state *rast;
182 const struct svga_sampler_state *sampler[PIPE_MAX_SAMPLERS];
183
184 struct pipe_texture *texture[PIPE_MAX_SAMPLERS]; /* or texture ID's? */
185 struct svga_fragment_shader *fs;
186 struct svga_vertex_shader *vs;
187
188 struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
189 struct pipe_vertex_element ve[PIPE_MAX_ATTRIBS];
190 struct pipe_buffer *cb[PIPE_SHADER_TYPES];
191
192 struct pipe_framebuffer_state framebuffer;
193 float depthscale;
194
195 /* Hack to limit the number of different render targets between
196 * flushes. Helps avoid blowing out our surface cache in EXA.
197 */
198 int nr_fbs;
199
200 struct pipe_poly_stipple poly_stipple;
201 struct pipe_scissor_state scissor;
202 struct pipe_blend_color blend_color;
203 struct pipe_clip_state clip;
204 struct pipe_viewport_state viewport;
205
206 unsigned num_samplers;
207 unsigned num_textures;
208 unsigned num_vertex_elements;
209 unsigned num_vertex_buffers;
210 unsigned reduced_prim;
211
212 struct {
213 unsigned flag_1d;
214 unsigned flag_srgb;
215 } tex_flags;
216
217 boolean any_user_vertex_buffers;
218
219 unsigned zero_stride_vertex_elements;
220 unsigned num_zero_stride_vertex_elements;
221 /* ### maybe dynamically allocate this */
222 float zero_stride_constants[PIPE_MAX_ATTRIBS*4];
223 };
224
225 #define RS_MAX 97
226 #define TS_MAX 30
227 #define CB_MAX 256
228
229 struct svga_prescale {
230 float translate[4];
231 float scale[4];
232 boolean enabled;
233 };
234
235
236 /* Updated by calling svga_update_state( SVGA_STATE_HW_VIEWPORT )
237 */
238 struct svga_hw_clear_state
239 {
240 struct {
241 unsigned x,y,w,h;
242 } viewport;
243
244 struct {
245 float zmin, zmax;
246 } depthrange;
247
248 struct pipe_framebuffer_state framebuffer;
249 struct svga_prescale prescale;
250 };
251
252 struct svga_hw_view_state
253 {
254 struct pipe_texture *texture;
255 struct svga_sampler_view *v;
256 unsigned min_lod;
257 unsigned max_lod;
258 int dirty;
259 };
260
261 /* Updated by calling svga_update_state( SVGA_STATE_HW_DRAW )
262 */
263 struct svga_hw_draw_state
264 {
265 unsigned rs[RS_MAX];
266 unsigned ts[16][TS_MAX];
267 float cb[PIPE_SHADER_TYPES][CB_MAX][4];
268
269 struct svga_shader_result *fs;
270 struct svga_shader_result *vs;
271 struct svga_hw_view_state views[PIPE_MAX_SAMPLERS];
272
273 unsigned num_views;
274 };
275
276
277 /* Updated by calling svga_update_state( SVGA_STATE_NEED_SWTNL )
278 */
279 struct svga_sw_state
280 {
281 unsigned ve_format[PIPE_MAX_ATTRIBS]; /* NEW_VELEMENT */
282
283 /* which parts we need */
284 boolean need_swvfetch;
285 boolean need_pipeline;
286 boolean need_swtnl;
287 };
288
289
290 /* Queue some state updates (like rss) and submit them to hardware in
291 * a single packet.
292 */
293 struct svga_hw_queue;
294
295 struct svga_query;
296
297 struct svga_context
298 {
299 struct pipe_context pipe;
300 struct svga_winsys_context *swc;
301
302 struct {
303 boolean no_swtnl;
304 boolean force_swtnl;
305 boolean use_min_mipmap;
306
307 /* incremented for each shader */
308 unsigned shader_id;
309
310 unsigned disable_shader;
311 } debug;
312
313 struct {
314 struct draw_context *draw;
315 struct vbuf_render *backend;
316 unsigned hw_prim;
317 boolean new_vbuf;
318 boolean new_vdecl;
319 } swtnl;
320
321 /* Bitmask of used shader IDs */
322 struct util_bitmask *fs_bm;
323 struct util_bitmask *vs_bm;
324
325 struct {
326 unsigned dirty[4];
327
328 unsigned texture_timestamp;
329
330 /* Internally generated shaders:
331 */
332 unsigned white_fs_id;
333
334 /*
335 */
336 struct svga_sw_state sw;
337 struct svga_hw_draw_state hw_draw;
338 struct svga_hw_clear_state hw_clear;
339 } state;
340
341 struct svga_state curr; /* state from the state tracker */
342 unsigned dirty; /* statechanges since last update_state() */
343
344 struct u_upload_mgr *upload_ib;
345 struct u_upload_mgr *upload_vb;
346 struct svga_hwtnl *hwtnl;
347
348 /** The occlusion query currently in progress */
349 struct svga_query *sq;
350
351 /** List of buffers with queued transfers */
352 struct list_head dirty_buffers;
353 };
354
355 /* A flag for each state_tracker state object:
356 */
357 #define SVGA_NEW_BLEND 0x1
358 #define SVGA_NEW_DEPTH_STENCIL 0x2
359 #define SVGA_NEW_RAST 0x4
360 #define SVGA_NEW_SAMPLER 0x8
361 #define SVGA_NEW_TEXTURE 0x10
362 #define SVGA_NEW_VBUFFER 0x20
363 #define SVGA_NEW_VELEMENT 0x40
364 #define SVGA_NEW_FS 0x80
365 #define SVGA_NEW_VS 0x100
366 #define SVGA_NEW_FS_CONST_BUFFER 0x200
367 #define SVGA_NEW_VS_CONST_BUFFER 0x400
368 #define SVGA_NEW_FRAME_BUFFER 0x800
369 #define SVGA_NEW_STIPPLE 0x1000
370 #define SVGA_NEW_SCISSOR 0x2000
371 #define SVGA_NEW_BLEND_COLOR 0x4000
372 #define SVGA_NEW_CLIP 0x8000
373 #define SVGA_NEW_VIEWPORT 0x10000
374 #define SVGA_NEW_PRESCALE 0x20000
375 #define SVGA_NEW_REDUCED_PRIMITIVE 0x40000
376 #define SVGA_NEW_TEXTURE_BINDING 0x80000
377 #define SVGA_NEW_NEED_PIPELINE 0x100000
378 #define SVGA_NEW_NEED_SWVFETCH 0x200000
379 #define SVGA_NEW_NEED_SWTNL 0x400000
380 #define SVGA_NEW_FS_RESULT 0x800000
381 #define SVGA_NEW_VS_RESULT 0x1000000
382 #define SVGA_NEW_ZERO_STRIDE 0x2000000
383 #define SVGA_NEW_TEXTURE_FLAGS 0x4000000
384
385
386
387
388
389 /***********************************************************************
390 * svga_clear.c:
391 */
392 void svga_clear(struct pipe_context *pipe,
393 unsigned buffers,
394 const float *rgba,
395 double depth,
396 unsigned stencil);
397
398
399 /***********************************************************************
400 * svga_screen_texture.c:
401 */
402 void svga_mark_surfaces_dirty(struct svga_context *svga);
403
404
405
406
407 void svga_init_state_functions( struct svga_context *svga );
408 void svga_init_flush_functions( struct svga_context *svga );
409 void svga_init_string_functions( struct svga_context *svga );
410 void svga_init_blit_functions(struct svga_context *svga);
411
412 void svga_init_blend_functions( struct svga_context *svga );
413 void svga_init_depth_stencil_functions( struct svga_context *svga );
414 void svga_init_misc_functions( struct svga_context *svga );
415 void svga_init_rasterizer_functions( struct svga_context *svga );
416 void svga_init_sampler_functions( struct svga_context *svga );
417 void svga_init_fs_functions( struct svga_context *svga );
418 void svga_init_vs_functions( struct svga_context *svga );
419 void svga_init_vertex_functions( struct svga_context *svga );
420 void svga_init_constbuffer_functions( struct svga_context *svga );
421 void svga_init_draw_functions( struct svga_context *svga );
422 void svga_init_query_functions( struct svga_context *svga );
423
424 void svga_cleanup_vertex_state( struct svga_context *svga );
425 void svga_cleanup_tss_binding( struct svga_context *svga );
426 void svga_cleanup_framebuffer( struct svga_context *svga );
427
428 void svga_context_flush( struct svga_context *svga,
429 struct pipe_fence_handle **pfence );
430
431 void svga_hwtnl_flush_retry( struct svga_context *svga );
432
433
434 /***********************************************************************
435 * Inline conversion functions. These are better-typed than the
436 * macros used previously:
437 */
438 static INLINE struct svga_context *
439 svga_context( struct pipe_context *pipe )
440 {
441 return (struct svga_context *)pipe;
442 }
443
444
445
446 #endif