1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
|
/**********************************************************
* Copyright 2008-2009 VMware, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
**********************************************************/
#ifndef SVGA_CONTEXT_H
#define SVGA_CONTEXT_H
#include "pipe/p_context.h"
#include "pipe/p_defines.h"
#include "pipe/p_state.h"
#include "util/u_double_list.h"
#include "tgsi/tgsi_scan.h"
#define SVGA_TEX_UNITS 8
#define SVGA_MAX_POINTSIZE 80.0
struct draw_vertex_shader;
struct svga_shader_result;
struct SVGACmdMemory;
struct util_bitmask;
struct u_upload_mgr;
struct svga_shader
{
const struct tgsi_token *tokens;
struct tgsi_shader_info info;
struct svga_shader_result *results;
unsigned id;
boolean use_sm30;
};
struct svga_fragment_shader
{
struct svga_shader base;
};
struct svga_vertex_shader
{
struct svga_shader base;
struct draw_vertex_shader *draw_shader;
};
struct svga_cache_context;
struct svga_tracked_state;
struct svga_blend_state {
boolean need_white_fragments;
/* Should be per-render-target:
*/
struct {
uint8_t writemask;
boolean blend_enable;
uint8_t srcblend;
uint8_t dstblend;
uint8_t blendeq;
boolean separate_alpha_blend_enable;
uint8_t srcblend_alpha;
uint8_t dstblend_alpha;
uint8_t blendeq_alpha;
} rt[1];
};
struct svga_depth_stencil_state {
unsigned zfunc:8;
unsigned zenable:1;
unsigned zwriteenable:1;
unsigned alphatestenable:1;
unsigned alphafunc:8;
struct {
unsigned enabled:1;
unsigned func:8;
unsigned fail:8;
unsigned zfail:8;
unsigned pass:8;
} stencil[2];
/* SVGA3D has one ref/mask/writemask triple shared between front &
* back face stencil. We really need two:
*/
unsigned stencil_mask:8;
unsigned stencil_writemask:8;
float alpharef;
};
#define SVGA_UNFILLED_DISABLE 0
#define SVGA_UNFILLED_LINE 1
#define SVGA_UNFILLED_POINT 2
#define SVGA_PIPELINE_FLAG_POINTS (1<<PIPE_PRIM_POINTS)
#define SVGA_PIPELINE_FLAG_LINES (1<<PIPE_PRIM_LINES)
#define SVGA_PIPELINE_FLAG_TRIS (1<<PIPE_PRIM_TRIANGLES)
struct svga_rasterizer_state {
struct pipe_rasterizer_state templ; /* needed for draw module */
unsigned shademode:8;
unsigned cullmode:8;
unsigned scissortestenable:1;
unsigned multisampleantialias:1;
unsigned antialiasedlineenable:1;
unsigned lastpixel:1;
unsigned linepattern;
float slopescaledepthbias;
float depthbias;
float pointsize;
unsigned hw_unfilled:16; /* PIPE_POLYGON_MODE_x */
unsigned need_pipeline:16; /* which prims do we need help for? */
const char* need_pipeline_tris_str;
const char* need_pipeline_lines_str;
const char* need_pipeline_points_str;
};
struct svga_sampler_state {
unsigned mipfilter;
unsigned magfilter;
unsigned minfilter;
unsigned aniso_level;
float lod_bias;
unsigned addressu;
unsigned addressv;
unsigned addressw;
unsigned bordercolor;
unsigned normalized_coords:1;
unsigned compare_mode:1;
unsigned compare_func:3;
unsigned min_lod;
unsigned view_min_lod;
unsigned view_max_lod;
};
struct svga_velems_state {
unsigned count;
struct pipe_vertex_element velem[PIPE_MAX_ATTRIBS];
};
/* Use to calculate differences between state emitted to hardware and
* current driver-calculated state.
*/
struct svga_state
{
const struct svga_blend_state *blend;
const struct svga_depth_stencil_state *depth;
const struct svga_rasterizer_state *rast;
const struct svga_sampler_state *sampler[PIPE_MAX_SAMPLERS];
const struct svga_velems_state *velems;
struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS]; /* or texture ID's? */
struct svga_fragment_shader *fs;
struct svga_vertex_shader *vs;
struct pipe_vertex_buffer vb[PIPE_MAX_ATTRIBS];
struct pipe_index_buffer ib;
struct pipe_resource *cb[PIPE_SHADER_TYPES];
struct pipe_framebuffer_state framebuffer;
float depthscale;
/* Hack to limit the number of different render targets between
* flushes. Helps avoid blowing out our surface cache in EXA.
*/
int nr_fbs;
struct pipe_poly_stipple poly_stipple;
struct pipe_scissor_state scissor;
struct pipe_blend_color blend_color;
struct pipe_stencil_ref stencil_ref;
struct pipe_clip_state clip;
struct pipe_viewport_state viewport;
unsigned num_samplers;
unsigned num_sampler_views;
unsigned num_vertex_buffers;
unsigned reduced_prim;
struct {
unsigned flag_1d;
unsigned flag_srgb;
} tex_flags;
boolean any_user_vertex_buffers;
unsigned zero_stride_vertex_elements;
unsigned num_zero_stride_vertex_elements;
/* ### maybe dynamically allocate this */
float zero_stride_constants[PIPE_MAX_ATTRIBS*4];
};
#define RS_MAX 97
#define TS_MAX 30
#define CB_MAX 256
struct svga_prescale {
float translate[4];
float scale[4];
boolean enabled;
};
/* Updated by calling svga_update_state( SVGA_STATE_HW_VIEWPORT )
*/
struct svga_hw_clear_state
{
struct {
unsigned x,y,w,h;
} viewport;
struct {
float zmin, zmax;
} depthrange;
struct pipe_framebuffer_state framebuffer;
struct svga_prescale prescale;
};
struct svga_hw_view_state
{
struct pipe_resource *texture;
struct svga_sampler_view *v;
unsigned min_lod;
unsigned max_lod;
int dirty;
};
/* Updated by calling svga_update_state( SVGA_STATE_HW_DRAW )
*/
struct svga_hw_draw_state
{
unsigned rs[RS_MAX];
unsigned ts[16][TS_MAX];
float cb[PIPE_SHADER_TYPES][CB_MAX][4];
struct svga_shader_result *fs;
struct svga_shader_result *vs;
struct svga_hw_view_state views[PIPE_MAX_SAMPLERS];
unsigned num_views;
};
/* Updated by calling svga_update_state( SVGA_STATE_NEED_SWTNL )
*/
struct svga_sw_state
{
unsigned ve_format[PIPE_MAX_ATTRIBS]; /* NEW_VELEMENT */
/* which parts we need */
boolean need_swvfetch;
boolean need_pipeline;
boolean need_swtnl;
/* Flag to make sure that need sw is on while
* updating state within a swtnl call.
*/
boolean in_swtnl_draw;
};
/* Queue some state updates (like rss) and submit them to hardware in
* a single packet.
*/
struct svga_hw_queue;
struct svga_query;
struct svga_context
{
struct pipe_context pipe;
struct svga_winsys_context *swc;
struct {
boolean no_swtnl;
boolean force_swtnl;
boolean use_min_mipmap;
/* incremented for each shader */
unsigned shader_id;
unsigned disable_shader;
boolean no_line_width;
boolean force_hw_line_stipple;
} debug;
struct {
struct draw_context *draw;
struct vbuf_render *backend;
unsigned hw_prim;
boolean new_vbuf;
boolean new_vdecl;
} swtnl;
/* Bitmask of used shader IDs */
struct util_bitmask *fs_bm;
struct util_bitmask *vs_bm;
struct {
unsigned dirty[4];
unsigned texture_timestamp;
/*
*/
struct svga_sw_state sw;
struct svga_hw_draw_state hw_draw;
struct svga_hw_clear_state hw_clear;
} state;
struct svga_state curr; /* state from the state tracker */
unsigned dirty; /* statechanges since last update_state() */
struct u_upload_mgr *upload_ib;
struct u_upload_mgr *upload_vb;
struct svga_hwtnl *hwtnl;
/** The occlusion query currently in progress */
struct svga_query *sq;
/** List of buffers with queued transfers */
struct list_head dirty_buffers;
};
/* A flag for each state_tracker state object:
*/
#define SVGA_NEW_BLEND 0x1
#define SVGA_NEW_DEPTH_STENCIL 0x2
#define SVGA_NEW_RAST 0x4
#define SVGA_NEW_SAMPLER 0x8
#define SVGA_NEW_TEXTURE 0x10
#define SVGA_NEW_VBUFFER 0x20
#define SVGA_NEW_VELEMENT 0x40
#define SVGA_NEW_FS 0x80
#define SVGA_NEW_VS 0x100
#define SVGA_NEW_FS_CONST_BUFFER 0x200
#define SVGA_NEW_VS_CONST_BUFFER 0x400
#define SVGA_NEW_FRAME_BUFFER 0x800
#define SVGA_NEW_STIPPLE 0x1000
#define SVGA_NEW_SCISSOR 0x2000
#define SVGA_NEW_BLEND_COLOR 0x4000
#define SVGA_NEW_CLIP 0x8000
#define SVGA_NEW_VIEWPORT 0x10000
#define SVGA_NEW_PRESCALE 0x20000
#define SVGA_NEW_REDUCED_PRIMITIVE 0x40000
#define SVGA_NEW_TEXTURE_BINDING 0x80000
#define SVGA_NEW_NEED_PIPELINE 0x100000
#define SVGA_NEW_NEED_SWVFETCH 0x200000
#define SVGA_NEW_NEED_SWTNL 0x400000
#define SVGA_NEW_FS_RESULT 0x800000
#define SVGA_NEW_VS_RESULT 0x1000000
#define SVGA_NEW_ZERO_STRIDE 0x2000000
#define SVGA_NEW_TEXTURE_FLAGS 0x4000000
#define SVGA_NEW_STENCIL_REF 0x8000000
#define SVGA_NEW_COMMAND_BUFFER 0x10000000
/***********************************************************************
* svga_clear.c:
*/
void svga_clear(struct pipe_context *pipe,
unsigned buffers,
const float *rgba,
double depth,
unsigned stencil);
/***********************************************************************
* svga_screen_texture.c:
*/
void svga_mark_surfaces_dirty(struct svga_context *svga);
void svga_init_state_functions( struct svga_context *svga );
void svga_init_flush_functions( struct svga_context *svga );
void svga_init_string_functions( struct svga_context *svga );
void svga_init_blit_functions(struct svga_context *svga);
void svga_init_blend_functions( struct svga_context *svga );
void svga_init_depth_stencil_functions( struct svga_context *svga );
void svga_init_misc_functions( struct svga_context *svga );
void svga_init_rasterizer_functions( struct svga_context *svga );
void svga_init_sampler_functions( struct svga_context *svga );
void svga_init_fs_functions( struct svga_context *svga );
void svga_init_vs_functions( struct svga_context *svga );
void svga_init_vertex_functions( struct svga_context *svga );
void svga_init_constbuffer_functions( struct svga_context *svga );
void svga_init_draw_functions( struct svga_context *svga );
void svga_init_query_functions( struct svga_context *svga );
void svga_init_surface_functions(struct svga_context *svga);
void svga_cleanup_vertex_state( struct svga_context *svga );
void svga_cleanup_tss_binding( struct svga_context *svga );
void svga_cleanup_framebuffer( struct svga_context *svga );
void svga_context_flush( struct svga_context *svga,
struct pipe_fence_handle **pfence );
void svga_hwtnl_flush_retry( struct svga_context *svga );
struct pipe_context *
svga_context_create(struct pipe_screen *screen,
void *priv);
/***********************************************************************
* Inline conversion functions. These are better-typed than the
* macros used previously:
*/
static INLINE struct svga_context *
svga_context( struct pipe_context *pipe )
{
return (struct svga_context *)pipe;
}
#endif
|