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"
39 #define SVGA_TEX_UNITS 8
40 #define SVGA_MAX_POINTSIZE 80.0
42 struct draw_vertex_shader
;
43 struct svga_shader_result
;
51 const struct tgsi_token
*tokens
;
53 struct tgsi_shader_info info
;
55 struct svga_shader_result
*results
;
62 struct svga_fragment_shader
64 struct svga_shader base
;
67 struct svga_vertex_shader
69 struct svga_shader base
;
71 struct draw_vertex_shader
*draw_shader
;
75 struct svga_cache_context
;
76 struct svga_tracked_state
;
78 struct svga_blend_state
{
80 boolean need_white_fragments
;
82 /* Should be per-render-target:
92 boolean separate_alpha_blend_enable
;
93 uint8_t srcblend_alpha
;
94 uint8_t dstblend_alpha
;
95 uint8_t blendeq_alpha
;
100 struct svga_depth_stencil_state
{
103 unsigned zwriteenable
:1;
105 unsigned alphatestenable
:1;
106 unsigned alphafunc
:8;
116 /* SVGA3D has one ref/mask/writemask triple shared between front &
117 * back face stencil. We really need two:
119 unsigned stencil_mask
:8;
120 unsigned stencil_writemask
:8;
125 #define SVGA_UNFILLED_DISABLE 0
126 #define SVGA_UNFILLED_LINE 1
127 #define SVGA_UNFILLED_POINT 2
129 #define SVGA_PIPELINE_FLAG_POINTS (1<<PIPE_PRIM_POINTS)
130 #define SVGA_PIPELINE_FLAG_LINES (1<<PIPE_PRIM_LINES)
131 #define SVGA_PIPELINE_FLAG_TRIS (1<<PIPE_PRIM_TRIANGLES)
133 struct svga_rasterizer_state
{
134 struct pipe_rasterizer_state templ
; /* needed for draw module */
136 unsigned shademode
:8;
138 unsigned scissortestenable
:1;
139 unsigned multisampleantialias
:1;
140 unsigned antialiasedlineenable
:1;
141 unsigned lastpixel
:1;
143 unsigned linepattern
;
145 float slopescaledepthbias
;
149 unsigned hw_unfilled
:16; /* PIPE_POLYGON_MODE_x */
150 unsigned need_pipeline
:16; /* which prims do we need help for? */
153 struct svga_sampler_state
{
157 unsigned aniso_level
;
162 unsigned bordercolor
;
163 unsigned normalized_coords
:1;
164 unsigned compare_mode
:1;
165 unsigned compare_func
:3;
168 unsigned view_min_lod
;
169 unsigned view_max_lod
;
172 struct svga_velems_state
{
174 struct pipe_vertex_element velem
[PIPE_MAX_ATTRIBS
];
177 /* Use to calculate differences between state emitted to hardware and
178 * current driver-calculated state.
182 const struct svga_blend_state
*blend
;
183 const struct svga_depth_stencil_state
*depth
;
184 const struct svga_rasterizer_state
*rast
;
185 const struct svga_sampler_state
*sampler
[PIPE_MAX_SAMPLERS
];
186 const struct svga_velems_state
*velems
;
188 struct pipe_sampler_view
*sampler_views
[PIPE_MAX_SAMPLERS
]; /* or texture ID's? */
189 struct svga_fragment_shader
*fs
;
190 struct svga_vertex_shader
*vs
;
192 struct pipe_vertex_buffer vb
[PIPE_MAX_ATTRIBS
];
193 struct pipe_index_buffer ib
;
194 struct pipe_resource
*cb
[PIPE_SHADER_TYPES
];
196 struct pipe_framebuffer_state framebuffer
;
199 /* Hack to limit the number of different render targets between
200 * flushes. Helps avoid blowing out our surface cache in EXA.
204 struct pipe_poly_stipple poly_stipple
;
205 struct pipe_scissor_state scissor
;
206 struct pipe_blend_color blend_color
;
207 struct pipe_stencil_ref stencil_ref
;
208 struct pipe_clip_state clip
;
209 struct pipe_viewport_state viewport
;
211 unsigned num_samplers
;
212 unsigned num_sampler_views
;
213 unsigned num_vertex_buffers
;
214 unsigned reduced_prim
;
221 boolean any_user_vertex_buffers
;
223 unsigned zero_stride_vertex_elements
;
224 unsigned num_zero_stride_vertex_elements
;
225 /* ### maybe dynamically allocate this */
226 float zero_stride_constants
[PIPE_MAX_ATTRIBS
*4];
233 struct svga_prescale
{
240 /* Updated by calling svga_update_state( SVGA_STATE_HW_VIEWPORT )
242 struct svga_hw_clear_state
252 struct pipe_framebuffer_state framebuffer
;
253 struct svga_prescale prescale
;
256 struct svga_hw_view_state
258 struct pipe_resource
*texture
;
259 struct svga_sampler_view
*v
;
265 /* Updated by calling svga_update_state( SVGA_STATE_HW_DRAW )
267 struct svga_hw_draw_state
270 unsigned ts
[16][TS_MAX
];
271 float cb
[PIPE_SHADER_TYPES
][CB_MAX
][4];
273 struct svga_shader_result
*fs
;
274 struct svga_shader_result
*vs
;
275 struct svga_hw_view_state views
[PIPE_MAX_SAMPLERS
];
281 /* Updated by calling svga_update_state( SVGA_STATE_NEED_SWTNL )
285 unsigned ve_format
[PIPE_MAX_ATTRIBS
]; /* NEW_VELEMENT */
287 /* which parts we need */
288 boolean need_swvfetch
;
289 boolean need_pipeline
;
292 /* Flag to make sure that need sw is on while
293 * updating state within a swtnl call.
295 boolean in_swtnl_draw
;
299 /* Queue some state updates (like rss) and submit them to hardware in
302 struct svga_hw_queue
;
308 struct pipe_context pipe
;
309 struct svga_winsys_context
*swc
;
314 boolean use_min_mipmap
;
316 /* incremented for each shader */
319 unsigned disable_shader
;
323 struct draw_context
*draw
;
324 struct vbuf_render
*backend
;
330 /* Bitmask of used shader IDs */
331 struct util_bitmask
*fs_bm
;
332 struct util_bitmask
*vs_bm
;
337 unsigned texture_timestamp
;
341 struct svga_sw_state sw
;
342 struct svga_hw_draw_state hw_draw
;
343 struct svga_hw_clear_state hw_clear
;
346 struct svga_state curr
; /* state from the state tracker */
347 unsigned dirty
; /* statechanges since last update_state() */
349 struct u_upload_mgr
*upload_ib
;
350 struct u_upload_mgr
*upload_vb
;
351 struct svga_hwtnl
*hwtnl
;
353 /** The occlusion query currently in progress */
354 struct svga_query
*sq
;
356 /** List of buffers with queued transfers */
357 struct list_head dirty_buffers
;
360 /* A flag for each state_tracker state object:
362 #define SVGA_NEW_BLEND 0x1
363 #define SVGA_NEW_DEPTH_STENCIL 0x2
364 #define SVGA_NEW_RAST 0x4
365 #define SVGA_NEW_SAMPLER 0x8
366 #define SVGA_NEW_TEXTURE 0x10
367 #define SVGA_NEW_VBUFFER 0x20
368 #define SVGA_NEW_VELEMENT 0x40
369 #define SVGA_NEW_FS 0x80
370 #define SVGA_NEW_VS 0x100
371 #define SVGA_NEW_FS_CONST_BUFFER 0x200
372 #define SVGA_NEW_VS_CONST_BUFFER 0x400
373 #define SVGA_NEW_FRAME_BUFFER 0x800
374 #define SVGA_NEW_STIPPLE 0x1000
375 #define SVGA_NEW_SCISSOR 0x2000
376 #define SVGA_NEW_BLEND_COLOR 0x4000
377 #define SVGA_NEW_CLIP 0x8000
378 #define SVGA_NEW_VIEWPORT 0x10000
379 #define SVGA_NEW_PRESCALE 0x20000
380 #define SVGA_NEW_REDUCED_PRIMITIVE 0x40000
381 #define SVGA_NEW_TEXTURE_BINDING 0x80000
382 #define SVGA_NEW_NEED_PIPELINE 0x100000
383 #define SVGA_NEW_NEED_SWVFETCH 0x200000
384 #define SVGA_NEW_NEED_SWTNL 0x400000
385 #define SVGA_NEW_FS_RESULT 0x800000
386 #define SVGA_NEW_VS_RESULT 0x1000000
387 #define SVGA_NEW_ZERO_STRIDE 0x2000000
388 #define SVGA_NEW_TEXTURE_FLAGS 0x4000000
389 #define SVGA_NEW_STENCIL_REF 0x8000000
390 #define SVGA_NEW_COMMAND_BUFFER 0x10000000
396 /***********************************************************************
399 void svga_clear(struct pipe_context
*pipe
,
406 /***********************************************************************
407 * svga_screen_texture.c:
409 void svga_mark_surfaces_dirty(struct svga_context
*svga
);
414 void svga_init_state_functions( struct svga_context
*svga
);
415 void svga_init_flush_functions( struct svga_context
*svga
);
416 void svga_init_string_functions( struct svga_context
*svga
);
417 void svga_init_blit_functions(struct svga_context
*svga
);
419 void svga_init_blend_functions( struct svga_context
*svga
);
420 void svga_init_depth_stencil_functions( struct svga_context
*svga
);
421 void svga_init_misc_functions( struct svga_context
*svga
);
422 void svga_init_rasterizer_functions( struct svga_context
*svga
);
423 void svga_init_sampler_functions( struct svga_context
*svga
);
424 void svga_init_fs_functions( struct svga_context
*svga
);
425 void svga_init_vs_functions( struct svga_context
*svga
);
426 void svga_init_vertex_functions( struct svga_context
*svga
);
427 void svga_init_constbuffer_functions( struct svga_context
*svga
);
428 void svga_init_draw_functions( struct svga_context
*svga
);
429 void svga_init_query_functions( struct svga_context
*svga
);
430 void svga_init_surface_functions(struct svga_context
*svga
);
432 void svga_cleanup_vertex_state( struct svga_context
*svga
);
433 void svga_cleanup_tss_binding( struct svga_context
*svga
);
434 void svga_cleanup_framebuffer( struct svga_context
*svga
);
436 void svga_context_flush( struct svga_context
*svga
,
437 struct pipe_fence_handle
**pfence
);
439 void svga_hwtnl_flush_retry( struct svga_context
*svga
);
441 struct pipe_context
*
442 svga_context_create(struct pipe_screen
*screen
,
446 /***********************************************************************
447 * Inline conversion functions. These are better-typed than the
448 * macros used previously:
450 static INLINE
struct svga_context
*
451 svga_context( struct pipe_context
*pipe
)
453 return (struct svga_context
*)pipe
;