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