noop: implement stream output
[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 #include "svga_state.h"
39 #include "svga_tgsi.h"
40 #include "svga_hw_reg.h"
41 #include "svga3d_shaderdefs.h"
42
43
44 #define SVGA_TEX_UNITS 8
45 #define SVGA_MAX_POINTSIZE 80.0
46
47 struct draw_vertex_shader;
48 struct draw_fragment_shader;
49 struct svga_shader_result;
50 struct SVGACmdMemory;
51 struct util_bitmask;
52 struct u_upload_mgr;
53
54
55 struct svga_shader
56 {
57 const struct tgsi_token *tokens;
58
59 struct tgsi_shader_info info;
60
61 struct svga_shader_result *results;
62
63 unsigned id;
64
65 boolean use_sm30;
66 };
67
68 struct svga_fragment_shader
69 {
70 struct svga_shader base;
71
72 struct draw_fragment_shader *draw_shader;
73
74 /** Mask of which generic varying variables are read by this shader */
75 unsigned generic_inputs;
76 /** Table mapping original TGSI generic indexes to low integers */
77 int8_t generic_remap_table[MAX_GENERIC_VARYING];
78 };
79
80 struct svga_vertex_shader
81 {
82 struct svga_shader base;
83
84 struct draw_vertex_shader *draw_shader;
85 };
86
87
88 struct svga_cache_context;
89 struct svga_tracked_state;
90
91 struct svga_blend_state {
92
93 boolean need_white_fragments;
94
95 /* Should be per-render-target:
96 */
97 struct {
98 uint8_t writemask;
99
100 boolean blend_enable;
101 uint8_t srcblend;
102 uint8_t dstblend;
103 uint8_t blendeq;
104
105 boolean separate_alpha_blend_enable;
106 uint8_t srcblend_alpha;
107 uint8_t dstblend_alpha;
108 uint8_t blendeq_alpha;
109
110 } rt[1];
111 };
112
113 struct svga_depth_stencil_state {
114 unsigned zfunc:8;
115 unsigned zenable:1;
116 unsigned zwriteenable:1;
117
118 unsigned alphatestenable:1;
119 unsigned alphafunc:8;
120
121 struct {
122 unsigned enabled:1;
123 unsigned func:8;
124 unsigned fail:8;
125 unsigned zfail:8;
126 unsigned pass:8;
127 } stencil[2];
128
129 /* SVGA3D has one ref/mask/writemask triple shared between front &
130 * back face stencil. We really need two:
131 */
132 unsigned stencil_mask:8;
133 unsigned stencil_writemask:8;
134
135 float alpharef;
136 };
137
138 #define SVGA_UNFILLED_DISABLE 0
139 #define SVGA_UNFILLED_LINE 1
140 #define SVGA_UNFILLED_POINT 2
141
142 #define SVGA_PIPELINE_FLAG_POINTS (1<<PIPE_PRIM_POINTS)
143 #define SVGA_PIPELINE_FLAG_LINES (1<<PIPE_PRIM_LINES)
144 #define SVGA_PIPELINE_FLAG_TRIS (1<<PIPE_PRIM_TRIANGLES)
145
146 struct svga_rasterizer_state {
147 struct pipe_rasterizer_state templ; /* needed for draw module */
148
149 unsigned shademode:8;
150 unsigned cullmode:8;
151 unsigned scissortestenable:1;
152 unsigned multisampleantialias:1;
153 unsigned antialiasedlineenable:1;
154 unsigned lastpixel:1;
155 unsigned pointsprite:1;
156
157 unsigned linepattern;
158
159 float slopescaledepthbias;
160 float depthbias;
161 float pointsize;
162
163 unsigned hw_unfilled:16; /* PIPE_POLYGON_MODE_x */
164
165 /** Which prims do we need help for? Bitmask of (1 << PIPE_PRIM_x) flags */
166 unsigned need_pipeline:16;
167
168 /** For debugging: */
169 const char* need_pipeline_tris_str;
170 const char* need_pipeline_lines_str;
171 const char* need_pipeline_points_str;
172 };
173
174 struct svga_sampler_state {
175 unsigned mipfilter;
176 unsigned magfilter;
177 unsigned minfilter;
178 unsigned aniso_level;
179 float lod_bias;
180 unsigned addressu;
181 unsigned addressv;
182 unsigned addressw;
183 unsigned bordercolor;
184 unsigned normalized_coords:1;
185 unsigned compare_mode:1;
186 unsigned compare_func:3;
187
188 unsigned min_lod;
189 unsigned view_min_lod;
190 unsigned view_max_lod;
191 };
192
193 struct svga_velems_state {
194 unsigned count;
195 struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS];
196 };
197
198 /* Use to calculate differences between state emitted to hardware and
199 * current driver-calculated state.
200 */
201 struct svga_state
202 {
203 const struct svga_blend_state *blend;
204 const struct svga_depth_stencil_state *depth;
205 const struct svga_rasterizer_state *rast;
206 const struct svga_sampler_state *sampler[PIPE_MAX_SAMPLERS];
207 const struct svga_velems_state *velems;
208
209 struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; /* or texture ID's? */
210 struct svga_fragment_shader *fs;
211 struct svga_vertex_shader *vs;
212
213 struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
214 struct pipe_index_buffer ib;
215 struct pipe_resource *cb[PIPE_SHADER_TYPES];
216
217 struct pipe_framebuffer_state framebuffer;
218 float depthscale;
219
220 /* Hack to limit the number of different render targets between
221 * flushes. Helps avoid blowing out our surface cache in EXA.
222 */
223 int nr_fbs;
224
225 struct pipe_poly_stipple poly_stipple;
226 struct pipe_scissor_state scissor;
227 struct pipe_blend_color blend_color;
228 struct pipe_stencil_ref stencil_ref;
229 struct pipe_clip_state clip;
230 struct pipe_viewport_state viewport;
231
232 unsigned num_samplers;
233 unsigned num_sampler_views;
234 unsigned num_vertex_buffers;
235 unsigned reduced_prim;
236
237 struct {
238 unsigned flag_1d;
239 unsigned flag_srgb;
240 } tex_flags;
241
242 boolean any_user_vertex_buffers;
243
244 unsigned zero_stride_vertex_elements;
245 unsigned num_zero_stride_vertex_elements;
246 /* ### maybe dynamically allocate this */
247 float zero_stride_constants[PIPE_MAX_ATTRIBS*4];
248 };
249
250 struct svga_prescale {
251 float translate[4];
252 float scale[4];
253 boolean enabled;
254 };
255
256
257 /* Updated by calling svga_update_state( SVGA_STATE_HW_CLEAR )
258 */
259 struct svga_hw_clear_state
260 {
261 struct {
262 unsigned x,y,w,h;
263 } viewport;
264
265 struct {
266 float zmin, zmax;
267 } depthrange;
268
269 struct pipe_framebuffer_state framebuffer;
270 struct svga_prescale prescale;
271 };
272
273 struct svga_hw_view_state
274 {
275 struct pipe_resource *texture;
276 struct svga_sampler_view *v;
277 unsigned min_lod;
278 unsigned max_lod;
279 int dirty;
280 };
281
282 /* Updated by calling svga_update_state( SVGA_STATE_HW_DRAW )
283 */
284 struct svga_hw_draw_state
285 {
286 unsigned rs[SVGA3D_RS_MAX];
287 unsigned ts[SVGA3D_PIXEL_SAMPLERREG_MAX][SVGA3D_TS_MAX];
288 float cb[PIPE_SHADER_TYPES][SVGA3D_CONSTREG_MAX][4];
289
290 struct svga_shader_result *fs;
291 struct svga_shader_result *vs;
292 struct svga_hw_view_state views[PIPE_MAX_SAMPLERS];
293
294 unsigned num_views;
295 };
296
297
298 /* Updated by calling svga_update_state( SVGA_STATE_NEED_SWTNL )
299 */
300 struct svga_sw_state
301 {
302 unsigned ve_format[PIPE_MAX_ATTRIBS]; /* NEW_VELEMENT */
303
304 /* which parts we need */
305 boolean need_swvfetch;
306 boolean need_pipeline;
307 boolean need_swtnl;
308
309 /* Flag to make sure that need sw is on while
310 * updating state within a swtnl call.
311 */
312 boolean in_swtnl_draw;
313 };
314
315
316 /* Queue some state updates (like rss) and submit them to hardware in
317 * a single packet.
318 */
319 struct svga_hw_queue;
320
321 struct svga_query;
322
323 struct svga_context
324 {
325 struct pipe_context pipe;
326 struct svga_winsys_context *swc;
327
328 struct {
329 boolean no_swtnl;
330 boolean force_swtnl;
331 boolean use_min_mipmap;
332
333 /* incremented for each shader */
334 unsigned shader_id;
335
336 unsigned disable_shader;
337
338 boolean no_line_width;
339 boolean force_hw_line_stipple;
340 } debug;
341
342 struct {
343 struct draw_context *draw;
344 struct vbuf_render *backend;
345 unsigned hw_prim;
346 boolean new_vbuf;
347 boolean new_vdecl;
348 } swtnl;
349
350 /* Bitmask of used shader IDs */
351 struct util_bitmask *fs_bm;
352 struct util_bitmask *vs_bm;
353
354 struct {
355 unsigned dirty[SVGA_STATE_MAX];
356
357 unsigned texture_timestamp;
358
359 /*
360 */
361 struct svga_sw_state sw;
362 struct svga_hw_draw_state hw_draw;
363 struct svga_hw_clear_state hw_clear;
364 } state;
365
366 struct svga_state curr; /* state from the state tracker */
367 unsigned dirty; /* statechanges since last update_state() */
368
369 struct {
370 unsigned rendertargets:1;
371 unsigned texture_samplers:1;
372 } rebind;
373
374 struct u_upload_mgr *upload_ib;
375 struct u_upload_mgr *upload_vb;
376 struct svga_hwtnl *hwtnl;
377
378 /** The occlusion query currently in progress */
379 struct svga_query *sq;
380
381 /** List of buffers with queued transfers */
382 struct list_head dirty_buffers;
383 };
384
385 /* A flag for each state_tracker state object:
386 */
387 #define SVGA_NEW_BLEND 0x1
388 #define SVGA_NEW_DEPTH_STENCIL 0x2
389 #define SVGA_NEW_RAST 0x4
390 #define SVGA_NEW_SAMPLER 0x8
391 #define SVGA_NEW_TEXTURE 0x10
392 #define SVGA_NEW_VBUFFER 0x20
393 #define SVGA_NEW_VELEMENT 0x40
394 #define SVGA_NEW_FS 0x80
395 #define SVGA_NEW_VS 0x100
396 #define SVGA_NEW_FS_CONST_BUFFER 0x200
397 #define SVGA_NEW_VS_CONST_BUFFER 0x400
398 #define SVGA_NEW_FRAME_BUFFER 0x800
399 #define SVGA_NEW_STIPPLE 0x1000
400 #define SVGA_NEW_SCISSOR 0x2000
401 #define SVGA_NEW_BLEND_COLOR 0x4000
402 #define SVGA_NEW_CLIP 0x8000
403 #define SVGA_NEW_VIEWPORT 0x10000
404 #define SVGA_NEW_PRESCALE 0x20000
405 #define SVGA_NEW_REDUCED_PRIMITIVE 0x40000
406 #define SVGA_NEW_TEXTURE_BINDING 0x80000
407 #define SVGA_NEW_NEED_PIPELINE 0x100000
408 #define SVGA_NEW_NEED_SWVFETCH 0x200000
409 #define SVGA_NEW_NEED_SWTNL 0x400000
410 #define SVGA_NEW_FS_RESULT 0x800000
411 #define SVGA_NEW_VS_RESULT 0x1000000
412 #define SVGA_NEW_ZERO_STRIDE 0x2000000
413 #define SVGA_NEW_TEXTURE_FLAGS 0x4000000
414 #define SVGA_NEW_STENCIL_REF 0x8000000
415
416
417
418
419
420 /***********************************************************************
421 * svga_clear.c:
422 */
423 void svga_clear(struct pipe_context *pipe,
424 unsigned buffers,
425 const union pipe_color_union *color,
426 double depth,
427 unsigned stencil);
428
429
430 /***********************************************************************
431 * svga_screen_texture.c:
432 */
433 void svga_mark_surfaces_dirty(struct svga_context *svga);
434
435
436
437
438 void svga_init_state_functions( struct svga_context *svga );
439 void svga_init_flush_functions( struct svga_context *svga );
440 void svga_init_string_functions( struct svga_context *svga );
441 void svga_init_blit_functions(struct svga_context *svga);
442
443 void svga_init_blend_functions( struct svga_context *svga );
444 void svga_init_depth_stencil_functions( struct svga_context *svga );
445 void svga_init_misc_functions( struct svga_context *svga );
446 void svga_init_rasterizer_functions( struct svga_context *svga );
447 void svga_init_sampler_functions( struct svga_context *svga );
448 void svga_init_fs_functions( struct svga_context *svga );
449 void svga_init_vs_functions( struct svga_context *svga );
450 void svga_init_vertex_functions( struct svga_context *svga );
451 void svga_init_constbuffer_functions( struct svga_context *svga );
452 void svga_init_draw_functions( struct svga_context *svga );
453 void svga_init_query_functions( struct svga_context *svga );
454 void svga_init_surface_functions(struct svga_context *svga);
455
456 void svga_cleanup_vertex_state( struct svga_context *svga );
457 void svga_cleanup_tss_binding( struct svga_context *svga );
458 void svga_cleanup_framebuffer( struct svga_context *svga );
459
460 void svga_context_flush( struct svga_context *svga,
461 struct pipe_fence_handle **pfence );
462
463 void svga_hwtnl_flush_retry( struct svga_context *svga );
464 void svga_hwtnl_flush_buffer( struct svga_context *svga,
465 struct pipe_resource *buffer );
466
467 void svga_surfaces_flush(struct svga_context *svga);
468
469 struct pipe_context *
470 svga_context_create(struct pipe_screen *screen,
471 void *priv);
472
473
474 /***********************************************************************
475 * Inline conversion functions. These are better-typed than the
476 * macros used previously:
477 */
478 static INLINE struct svga_context *
479 svga_context( struct pipe_context *pipe )
480 {
481 return (struct svga_context *)pipe;
482 }
483
484
485
486 #endif