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