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