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