1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
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:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
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
24 **********************************************************/
26 #ifndef SVGA_CONTEXT_H
27 #define SVGA_CONTEXT_H
30 #include "pipe/p_context.h"
31 #include "pipe/p_defines.h"
32 #include "pipe/p_state.h"
34 #include "util/u_double_list.h"
36 #include "tgsi/tgsi_scan.h"
38 #include "svga_state.h"
41 #define SVGA_TEX_UNITS 8
42 #define SVGA_MAX_POINTSIZE 80.0
44 struct draw_vertex_shader
;
45 struct svga_shader_result
;
53 const struct tgsi_token
*tokens
;
55 struct tgsi_shader_info info
;
57 struct svga_shader_result
*results
;
64 struct svga_fragment_shader
66 struct svga_shader base
;
69 struct svga_vertex_shader
71 struct svga_shader base
;
73 struct draw_vertex_shader
*draw_shader
;
77 struct svga_cache_context
;
78 struct svga_tracked_state
;
80 struct svga_blend_state
{
82 boolean need_white_fragments
;
84 /* Should be per-render-target:
94 boolean separate_alpha_blend_enable
;
95 uint8_t srcblend_alpha
;
96 uint8_t dstblend_alpha
;
97 uint8_t blendeq_alpha
;
102 struct svga_depth_stencil_state
{
105 unsigned zwriteenable
:1;
107 unsigned alphatestenable
:1;
108 unsigned alphafunc
:8;
118 /* SVGA3D has one ref/mask/writemask triple shared between front &
119 * back face stencil. We really need two:
121 unsigned stencil_mask
:8;
122 unsigned stencil_writemask
:8;
127 #define SVGA_UNFILLED_DISABLE 0
128 #define SVGA_UNFILLED_LINE 1
129 #define SVGA_UNFILLED_POINT 2
131 #define SVGA_PIPELINE_FLAG_POINTS (1<<PIPE_PRIM_POINTS)
132 #define SVGA_PIPELINE_FLAG_LINES (1<<PIPE_PRIM_LINES)
133 #define SVGA_PIPELINE_FLAG_TRIS (1<<PIPE_PRIM_TRIANGLES)
135 struct svga_rasterizer_state
{
136 struct pipe_rasterizer_state templ
; /* needed for draw module */
138 unsigned shademode
:8;
140 unsigned scissortestenable
:1;
141 unsigned multisampleantialias
:1;
142 unsigned antialiasedlineenable
:1;
143 unsigned lastpixel
:1;
144 unsigned pointsprite
:1;
146 unsigned linepattern
;
148 float slopescaledepthbias
;
152 unsigned hw_unfilled
:16; /* PIPE_POLYGON_MODE_x */
154 /** Which prims do we need help for? Bitmask of (1 << PIPE_PRIM_x) flags */
155 unsigned need_pipeline
:16;
157 /** For debugging: */
158 const char* need_pipeline_tris_str
;
159 const char* need_pipeline_lines_str
;
160 const char* need_pipeline_points_str
;
163 struct svga_sampler_state
{
167 unsigned aniso_level
;
172 unsigned bordercolor
;
173 unsigned normalized_coords
:1;
174 unsigned compare_mode
:1;
175 unsigned compare_func
:3;
178 unsigned view_min_lod
;
179 unsigned view_max_lod
;
182 struct svga_velems_state
{
184 struct pipe_vertex_element velem
[PIPE_MAX_ATTRIBS
];
187 /* Use to calculate differences between state emitted to hardware and
188 * current driver-calculated state.
192 const struct svga_blend_state
*blend
;
193 const struct svga_depth_stencil_state
*depth
;
194 const struct svga_rasterizer_state
*rast
;
195 const struct svga_sampler_state
*sampler
[PIPE_MAX_SAMPLERS
];
196 const struct svga_velems_state
*velems
;
198 struct pipe_sampler_view
*sampler_views
[PIPE_MAX_SAMPLERS
]; /* or texture ID's? */
199 struct svga_fragment_shader
*fs
;
200 struct svga_vertex_shader
*vs
;
202 struct pipe_vertex_buffer vb
[PIPE_MAX_ATTRIBS
];
203 struct pipe_index_buffer ib
;
204 struct pipe_resource
*cb
[PIPE_SHADER_TYPES
];
206 struct pipe_framebuffer_state framebuffer
;
209 /* Hack to limit the number of different render targets between
210 * flushes. Helps avoid blowing out our surface cache in EXA.
214 struct pipe_poly_stipple poly_stipple
;
215 struct pipe_scissor_state scissor
;
216 struct pipe_blend_color blend_color
;
217 struct pipe_stencil_ref stencil_ref
;
218 struct pipe_clip_state clip
;
219 struct pipe_viewport_state viewport
;
221 unsigned num_samplers
;
222 unsigned num_sampler_views
;
223 unsigned num_vertex_buffers
;
224 unsigned reduced_prim
;
231 boolean any_user_vertex_buffers
;
233 unsigned zero_stride_vertex_elements
;
234 unsigned num_zero_stride_vertex_elements
;
235 /* ### maybe dynamically allocate this */
236 float zero_stride_constants
[PIPE_MAX_ATTRIBS
*4];
243 struct svga_prescale
{
250 /* Updated by calling svga_update_state( SVGA_STATE_HW_CLEAR )
252 struct svga_hw_clear_state
262 struct pipe_framebuffer_state framebuffer
;
263 struct svga_prescale prescale
;
266 struct svga_hw_view_state
268 struct pipe_resource
*texture
;
269 struct svga_sampler_view
*v
;
275 /* Updated by calling svga_update_state( SVGA_STATE_HW_DRAW )
277 struct svga_hw_draw_state
280 unsigned ts
[16][TS_MAX
];
281 float cb
[PIPE_SHADER_TYPES
][CB_MAX
][4];
283 struct svga_shader_result
*fs
;
284 struct svga_shader_result
*vs
;
285 struct svga_hw_view_state views
[PIPE_MAX_SAMPLERS
];
291 /* Updated by calling svga_update_state( SVGA_STATE_NEED_SWTNL )
295 unsigned ve_format
[PIPE_MAX_ATTRIBS
]; /* NEW_VELEMENT */
297 /* which parts we need */
298 boolean need_swvfetch
;
299 boolean need_pipeline
;
302 /* Flag to make sure that need sw is on while
303 * updating state within a swtnl call.
305 boolean in_swtnl_draw
;
309 /* Queue some state updates (like rss) and submit them to hardware in
312 struct svga_hw_queue
;
318 struct pipe_context pipe
;
319 struct svga_winsys_context
*swc
;
324 boolean use_min_mipmap
;
326 /* incremented for each shader */
329 unsigned disable_shader
;
331 boolean no_line_width
;
332 boolean force_hw_line_stipple
;
336 struct draw_context
*draw
;
337 struct vbuf_render
*backend
;
343 /* Bitmask of used shader IDs */
344 struct util_bitmask
*fs_bm
;
345 struct util_bitmask
*vs_bm
;
348 unsigned dirty
[SVGA_STATE_MAX
];
350 unsigned texture_timestamp
;
354 struct svga_sw_state sw
;
355 struct svga_hw_draw_state hw_draw
;
356 struct svga_hw_clear_state hw_clear
;
359 struct svga_state curr
; /* state from the state tracker */
360 unsigned dirty
; /* statechanges since last update_state() */
363 unsigned rendertargets
:1;
364 unsigned texture_samplers
:1;
367 struct u_upload_mgr
*upload_ib
;
368 struct u_upload_mgr
*upload_vb
;
369 struct svga_hwtnl
*hwtnl
;
371 /** The occlusion query currently in progress */
372 struct svga_query
*sq
;
374 /** List of buffers with queued transfers */
375 struct list_head dirty_buffers
;
378 /* A flag for each state_tracker state object:
380 #define SVGA_NEW_BLEND 0x1
381 #define SVGA_NEW_DEPTH_STENCIL 0x2
382 #define SVGA_NEW_RAST 0x4
383 #define SVGA_NEW_SAMPLER 0x8
384 #define SVGA_NEW_TEXTURE 0x10
385 #define SVGA_NEW_VBUFFER 0x20
386 #define SVGA_NEW_VELEMENT 0x40
387 #define SVGA_NEW_FS 0x80
388 #define SVGA_NEW_VS 0x100
389 #define SVGA_NEW_FS_CONST_BUFFER 0x200
390 #define SVGA_NEW_VS_CONST_BUFFER 0x400
391 #define SVGA_NEW_FRAME_BUFFER 0x800
392 #define SVGA_NEW_STIPPLE 0x1000
393 #define SVGA_NEW_SCISSOR 0x2000
394 #define SVGA_NEW_BLEND_COLOR 0x4000
395 #define SVGA_NEW_CLIP 0x8000
396 #define SVGA_NEW_VIEWPORT 0x10000
397 #define SVGA_NEW_PRESCALE 0x20000
398 #define SVGA_NEW_REDUCED_PRIMITIVE 0x40000
399 #define SVGA_NEW_TEXTURE_BINDING 0x80000
400 #define SVGA_NEW_NEED_PIPELINE 0x100000
401 #define SVGA_NEW_NEED_SWVFETCH 0x200000
402 #define SVGA_NEW_NEED_SWTNL 0x400000
403 #define SVGA_NEW_FS_RESULT 0x800000
404 #define SVGA_NEW_VS_RESULT 0x1000000
405 #define SVGA_NEW_ZERO_STRIDE 0x2000000
406 #define SVGA_NEW_TEXTURE_FLAGS 0x4000000
407 #define SVGA_NEW_STENCIL_REF 0x8000000
413 /***********************************************************************
416 void svga_clear(struct pipe_context
*pipe
,
418 const union pipe_color_union
*color
,
423 /***********************************************************************
424 * svga_screen_texture.c:
426 void svga_mark_surfaces_dirty(struct svga_context
*svga
);
431 void svga_init_state_functions( struct svga_context
*svga
);
432 void svga_init_flush_functions( struct svga_context
*svga
);
433 void svga_init_string_functions( struct svga_context
*svga
);
434 void svga_init_blit_functions(struct svga_context
*svga
);
436 void svga_init_blend_functions( struct svga_context
*svga
);
437 void svga_init_depth_stencil_functions( struct svga_context
*svga
);
438 void svga_init_misc_functions( struct svga_context
*svga
);
439 void svga_init_rasterizer_functions( struct svga_context
*svga
);
440 void svga_init_sampler_functions( struct svga_context
*svga
);
441 void svga_init_fs_functions( struct svga_context
*svga
);
442 void svga_init_vs_functions( struct svga_context
*svga
);
443 void svga_init_vertex_functions( struct svga_context
*svga
);
444 void svga_init_constbuffer_functions( struct svga_context
*svga
);
445 void svga_init_draw_functions( struct svga_context
*svga
);
446 void svga_init_query_functions( struct svga_context
*svga
);
447 void svga_init_surface_functions(struct svga_context
*svga
);
449 void svga_cleanup_vertex_state( struct svga_context
*svga
);
450 void svga_cleanup_tss_binding( struct svga_context
*svga
);
451 void svga_cleanup_framebuffer( struct svga_context
*svga
);
453 void svga_context_flush( struct svga_context
*svga
,
454 struct pipe_fence_handle
**pfence
);
456 void svga_hwtnl_flush_retry( struct svga_context
*svga
);
458 void svga_surfaces_flush(struct svga_context
*svga
);
460 struct pipe_context
*
461 svga_context_create(struct pipe_screen
*screen
,
465 /***********************************************************************
466 * Inline conversion functions. These are better-typed than the
467 * macros used previously:
469 static INLINE
struct svga_context
*
470 svga_context( struct pipe_context
*pipe
)
472 return (struct svga_context
*)pipe
;