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