Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/auxiliary/draw/draw_private.h
4565 views
1
/**************************************************************************
2
*
3
* Copyright 2007 VMware, Inc.
4
* All Rights Reserved.
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining a
7
* copy of this software and associated documentation files (the
8
* "Software"), to deal in the Software without restriction, including
9
* without limitation the rights to use, copy, modify, merge, publish,
10
* distribute, sub license, and/or sell copies of the Software, and to
11
* permit persons to whom the Software is furnished to do so, subject to
12
* the following conditions:
13
*
14
* The above copyright notice and this permission notice (including the
15
* next paragraph) shall be included in all copies or substantial portions
16
* of the Software.
17
*
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
*
26
**************************************************************************/
27
28
/**
29
* Private data structures, etc for the draw module.
30
*/
31
32
33
/**
34
* Authors:
35
* Keith Whitwell <[email protected]>
36
* Brian Paul
37
*/
38
39
40
#ifndef DRAW_PRIVATE_H
41
#define DRAW_PRIVATE_H
42
43
44
#include "pipe/p_state.h"
45
#include "pipe/p_defines.h"
46
47
#include "tgsi/tgsi_scan.h"
48
49
#ifdef DRAW_LLVM_AVAILABLE
50
struct gallivm_state;
51
#endif
52
53
54
/** Sum of frustum planes and user-defined planes */
55
#define DRAW_TOTAL_CLIP_PLANES (6 + PIPE_MAX_CLIP_PLANES)
56
57
/**
58
* The largest possible index of a vertex that can be fetched.
59
*/
60
#define DRAW_MAX_FETCH_IDX 0xffffffff
61
62
/**
63
* Maximum number of extra shader outputs. These are allocated by:
64
* - draw_pipe_aaline.c (1)
65
* - draw_pipe_aapoint.c (1)
66
* - draw_pipe_unfilled.c (1)
67
* - draw_pipe_wide_point.c (up to 32)
68
* - draw_prim_assembler.c (1)
69
*/
70
#define DRAW_MAX_EXTRA_SHADER_OUTPUTS 32
71
72
/**
73
* Despite some efforts to determine the number of extra shader outputs ahead
74
* of time, the matter of fact is that this number will vary as primitives
75
* flow through the draw pipeline. In particular, aaline/aapoint stages
76
* only allocate their extra shader outputs on the first line/point.
77
*
78
* Consequently dup_vert() ends up copying vertices larger than those
79
* allocated.
80
*
81
* Ideally we'd keep track of incoming/outgoing vertex sizes (and strides)
82
* throughout the draw pipeline, but unfortunately we recompute these all over
83
* the place, so preemptively expanding the vertex stride/size does not work
84
* as mismatches ensue.
85
*
86
* As stopgap to prevent buffer read overflows, we allocate an extra bit of
87
* padding at the end of temporary vertex buffers, allowing dup_vert() to copy
88
* more vertex attributes than allocated.
89
*/
90
#define DRAW_EXTRA_VERTICES_PADDING \
91
(DRAW_MAX_EXTRA_SHADER_OUTPUTS * sizeof(float[4]))
92
93
struct pipe_context;
94
struct draw_vertex_shader;
95
struct draw_context;
96
struct draw_stage;
97
struct vbuf_render;
98
struct tgsi_exec_machine;
99
struct tgsi_sampler;
100
struct tgsi_image;
101
struct tgsi_buffer;
102
struct draw_pt_front_end;
103
struct draw_assembler;
104
struct draw_llvm;
105
struct lp_cached_code;
106
107
/**
108
* Represents the mapped vertex buffer.
109
*/
110
struct draw_vertex_buffer {
111
const void *map;
112
uint32_t size;
113
};
114
115
/**
116
* Basic vertex info.
117
* Carry some useful information around with the vertices in the prim pipe.
118
*/
119
struct vertex_header {
120
unsigned clipmask:DRAW_TOTAL_CLIP_PLANES;
121
unsigned edgeflag:1;
122
unsigned pad:1;
123
unsigned vertex_id:16;
124
125
float clip_pos[4];
126
127
/* This will probably become float (*data)[4] soon:
128
*/
129
float data[][4];
130
};
131
132
/* NOTE: It should match vertex_id size above */
133
#define UNDEFINED_VERTEX_ID 0xffff
134
135
136
/* maximum number of shader variants we can cache */
137
#define DRAW_MAX_SHADER_VARIANTS 512
138
139
/**
140
* Private context for the drawing module.
141
*/
142
struct draw_context
143
{
144
struct pipe_context *pipe;
145
146
/** Drawing/primitive pipeline stages */
147
struct {
148
struct draw_stage *first; /**< one of the following */
149
150
struct draw_stage *validate;
151
152
/* stages (in logical order) */
153
struct draw_stage *flatshade;
154
struct draw_stage *clip;
155
struct draw_stage *cull;
156
struct draw_stage *user_cull;
157
struct draw_stage *twoside;
158
struct draw_stage *offset;
159
struct draw_stage *unfilled;
160
struct draw_stage *stipple;
161
struct draw_stage *aapoint;
162
struct draw_stage *aaline;
163
struct draw_stage *pstipple;
164
struct draw_stage *wide_line;
165
struct draw_stage *wide_point;
166
struct draw_stage *rasterize;
167
168
float wide_point_threshold; /**< convert pnts to tris if larger than this */
169
float wide_line_threshold; /**< convert lines to tris if wider than this */
170
boolean wide_point_sprites; /**< convert points to tris for sprite mode */
171
boolean line_stipple; /**< do line stipple? */
172
boolean point_sprite; /**< convert points to quads for sprites? */
173
174
/* Temporary storage while the pipeline is being run:
175
*/
176
char *verts;
177
unsigned vertex_stride;
178
unsigned vertex_count;
179
} pipeline;
180
181
182
struct vbuf_render *render;
183
184
/* Support prototype passthrough path:
185
*/
186
struct {
187
/* Current active frontend */
188
struct draw_pt_front_end *frontend;
189
unsigned prim;
190
unsigned opt; /**< bitmask of PT_x flags */
191
unsigned eltSize; /* saved eltSize for flushing */
192
ubyte vertices_per_patch;
193
boolean rebind_parameters;
194
195
struct {
196
struct draw_pt_middle_end *fetch_shade_emit;
197
struct draw_pt_middle_end *general;
198
struct draw_pt_middle_end *llvm;
199
} middle;
200
201
struct {
202
struct draw_pt_front_end *vsplit;
203
} front;
204
205
struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
206
unsigned nr_vertex_buffers;
207
208
/*
209
* This is the largest legal index value for the current set of
210
* bound vertex buffers. Regardless of any other consideration,
211
* all vertex lookups need to be clamped to 0..max_index to
212
* prevent out-of-bound access.
213
*/
214
unsigned max_index;
215
216
struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS];
217
unsigned nr_vertex_elements;
218
219
/* user-space vertex data, buffers */
220
struct {
221
/** vertex element/index buffer (ex: glDrawElements) */
222
const void *elts;
223
/** bytes per index (0, 1, 2 or 4) */
224
unsigned eltSizeIB;
225
unsigned eltSize;
226
unsigned eltMax;
227
int eltBias;
228
unsigned min_index;
229
unsigned max_index;
230
unsigned drawid;
231
bool increment_draw_id;
232
unsigned viewid;
233
234
/** vertex arrays */
235
struct draw_vertex_buffer vbuffer[PIPE_MAX_ATTRIBS];
236
237
/** constant buffers (for vertex/geometry shader) */
238
const void *vs_constants[PIPE_MAX_CONSTANT_BUFFERS];
239
unsigned vs_constants_size[PIPE_MAX_CONSTANT_BUFFERS];
240
const void *gs_constants[PIPE_MAX_CONSTANT_BUFFERS];
241
unsigned gs_constants_size[PIPE_MAX_CONSTANT_BUFFERS];
242
const void *tcs_constants[PIPE_MAX_CONSTANT_BUFFERS];
243
unsigned tcs_constants_size[PIPE_MAX_CONSTANT_BUFFERS];
244
const void *tes_constants[PIPE_MAX_CONSTANT_BUFFERS];
245
unsigned tes_constants_size[PIPE_MAX_CONSTANT_BUFFERS];
246
247
/** shader buffers (for vertex/geometry shader) */
248
const void *vs_ssbos[PIPE_MAX_SHADER_BUFFERS];
249
unsigned vs_ssbos_size[PIPE_MAX_SHADER_BUFFERS];
250
const void *gs_ssbos[PIPE_MAX_SHADER_BUFFERS];
251
unsigned gs_ssbos_size[PIPE_MAX_SHADER_BUFFERS];
252
const void *tcs_ssbos[PIPE_MAX_SHADER_BUFFERS];
253
unsigned tcs_ssbos_size[PIPE_MAX_SHADER_BUFFERS];
254
const void *tes_ssbos[PIPE_MAX_SHADER_BUFFERS];
255
unsigned tes_ssbos_size[PIPE_MAX_SHADER_BUFFERS];
256
257
/* pointer to planes */
258
float (*planes)[DRAW_TOTAL_CLIP_PLANES][4];
259
} user;
260
261
boolean test_fse; /* enable FSE even though its not correct (eg for softpipe) */
262
boolean no_fse; /* disable FSE even when it is correct */
263
} pt;
264
265
struct {
266
boolean bypass_clip_xy;
267
boolean bypass_clip_z;
268
boolean guard_band_xy;
269
boolean bypass_clip_points;
270
} driver;
271
272
boolean quads_always_flatshade_last;
273
274
boolean flushing; /**< debugging/sanity */
275
boolean suspend_flushing; /**< internally set */
276
277
/* Flags set if API requires clipping in these planes and the
278
* driver doesn't indicate that it can do it for us.
279
*/
280
boolean clip_xy;
281
boolean clip_z;
282
boolean clip_user;
283
boolean guard_band_xy;
284
boolean guard_band_points_xy;
285
286
boolean dump_vs;
287
288
/** Depth format and bias related settings. */
289
boolean floating_point_depth;
290
double mrd; /**< minimum resolvable depth value, for polygon offset */
291
292
/** Current rasterizer state given to us by the driver */
293
const struct pipe_rasterizer_state *rasterizer;
294
/** Driver CSO handle for the current rasterizer state */
295
void *rast_handle;
296
297
/** Rasterizer CSOs without culling/stipple/etc */
298
void *rasterizer_no_cull[2][2][2];
299
300
struct pipe_viewport_state viewports[PIPE_MAX_VIEWPORTS];
301
boolean identity_viewport;
302
boolean bypass_viewport;
303
304
/** Vertex shader state */
305
struct {
306
struct draw_vertex_shader *vertex_shader;
307
uint num_vs_outputs; /**< convenience, from vertex_shader */
308
uint position_output;
309
uint edgeflag_output;
310
uint clipvertex_output;
311
uint ccdistance_output[2];
312
313
/** Fields for TGSI interpreter / execution */
314
struct {
315
struct tgsi_exec_machine *machine;
316
317
struct tgsi_sampler *sampler;
318
struct tgsi_image *image;
319
struct tgsi_buffer *buffer;
320
} tgsi;
321
322
struct translate *fetch;
323
struct translate_cache *fetch_cache;
324
struct translate *emit;
325
struct translate_cache *emit_cache;
326
} vs;
327
328
/** Geometry shader state */
329
struct {
330
struct draw_geometry_shader *geometry_shader;
331
uint num_gs_outputs; /**< convenience, from geometry_shader */
332
uint position_output;
333
334
/** Fields for TGSI interpreter / execution */
335
struct {
336
struct tgsi_exec_machine *machine;
337
338
struct tgsi_sampler *sampler;
339
struct tgsi_image *image;
340
struct tgsi_buffer *buffer;
341
} tgsi;
342
343
} gs;
344
345
/* Tessellation state */
346
struct {
347
struct draw_tess_ctrl_shader *tess_ctrl_shader;
348
349
/** Fields for TGSI interpreter / execution */
350
struct {
351
struct tgsi_exec_machine *machine;
352
353
struct tgsi_sampler *sampler;
354
struct tgsi_image *image;
355
struct tgsi_buffer *buffer;
356
} tgsi;
357
} tcs;
358
359
struct {
360
struct draw_tess_eval_shader *tess_eval_shader;
361
uint position_output;
362
363
/** Fields for TGSI interpreter / execution */
364
struct {
365
struct tgsi_exec_machine *machine;
366
367
struct tgsi_sampler *sampler;
368
struct tgsi_image *image;
369
struct tgsi_buffer *buffer;
370
} tgsi;
371
} tes;
372
373
/** Fragment shader state */
374
struct {
375
struct draw_fragment_shader *fragment_shader;
376
} fs;
377
378
/** Stream output (vertex feedback) state */
379
struct {
380
struct draw_so_target *targets[PIPE_MAX_SO_BUFFERS];
381
uint num_targets;
382
} so;
383
384
/* Clip derived state:
385
*/
386
float plane[DRAW_TOTAL_CLIP_PLANES][4];
387
388
/* If a prim stage introduces new vertex attributes, they'll be stored here
389
*/
390
struct {
391
uint num;
392
uint semantic_name[DRAW_MAX_EXTRA_SHADER_OUTPUTS];
393
uint semantic_index[DRAW_MAX_EXTRA_SHADER_OUTPUTS];
394
uint slot[DRAW_MAX_EXTRA_SHADER_OUTPUTS];
395
} extra_shader_outputs;
396
397
unsigned instance_id;
398
unsigned start_instance;
399
unsigned start_index;
400
unsigned constant_buffer_stride;
401
struct draw_llvm *llvm;
402
403
/** Texture sampler and sampler view state.
404
* Note that we have arrays indexed by shader type. At this time
405
* we only handle vertex and geometry shaders in the draw module, but
406
* there may be more in the future (ex: hull and tessellation).
407
*/
408
struct pipe_sampler_view *sampler_views[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_SAMPLER_VIEWS];
409
unsigned num_sampler_views[PIPE_SHADER_TYPES];
410
const struct pipe_sampler_state *samplers[PIPE_SHADER_TYPES][PIPE_MAX_SAMPLERS];
411
unsigned num_samplers[PIPE_SHADER_TYPES];
412
413
struct pipe_image_view *images[PIPE_SHADER_TYPES][PIPE_MAX_SHADER_IMAGES];
414
unsigned num_images[PIPE_SHADER_TYPES];
415
416
struct pipe_query_data_pipeline_statistics statistics;
417
boolean collect_statistics;
418
419
float default_outer_tess_level[4];
420
float default_inner_tess_level[2];
421
bool collect_primgen;
422
423
struct draw_assembler *ia;
424
425
void *disk_cache_cookie;
426
void (*disk_cache_find_shader)(void *cookie,
427
struct lp_cached_code *cache,
428
unsigned char ir_sha1_cache_key[20]);
429
void (*disk_cache_insert_shader)(void *cookie,
430
struct lp_cached_code *cache,
431
unsigned char ir_sha1_cache_key[20]);
432
433
void *driver_private;
434
};
435
436
437
struct draw_fetch_info {
438
boolean linear;
439
unsigned start;
440
const unsigned *elts;
441
unsigned count;
442
};
443
444
struct draw_vertex_info {
445
struct vertex_header *verts;
446
unsigned vertex_size;
447
unsigned stride;
448
unsigned count;
449
};
450
451
/* these flags are set if the primitive is a segment of a larger one */
452
#define DRAW_SPLIT_BEFORE 0x1
453
#define DRAW_SPLIT_AFTER 0x2
454
#define DRAW_LINE_LOOP_AS_STRIP 0x4
455
456
struct draw_prim_info {
457
boolean linear;
458
unsigned start;
459
460
const ushort *elts;
461
unsigned count;
462
463
unsigned prim;
464
unsigned flags;
465
unsigned *primitive_lengths;
466
unsigned primitive_count;
467
};
468
469
470
/*******************************************************************************
471
* Draw common initialization code
472
*/
473
boolean draw_init(struct draw_context *draw);
474
void draw_new_instance(struct draw_context *draw);
475
476
/*******************************************************************************
477
* Vertex shader code:
478
*/
479
boolean draw_vs_init( struct draw_context *draw );
480
void draw_vs_destroy( struct draw_context *draw );
481
482
483
/*******************************************************************************
484
* Geometry shading code:
485
*/
486
boolean draw_gs_init( struct draw_context *draw );
487
488
489
void draw_gs_destroy( struct draw_context *draw );
490
491
/*******************************************************************************
492
* Common shading code:
493
*/
494
uint draw_current_shader_outputs(const struct draw_context *draw);
495
uint draw_current_shader_position_output(const struct draw_context *draw);
496
uint draw_current_shader_viewport_index_output(const struct draw_context *draw);
497
uint draw_current_shader_clipvertex_output(const struct draw_context *draw);
498
uint draw_current_shader_ccdistance_output(const struct draw_context *draw, int index);
499
uint draw_current_shader_num_written_clipdistances(const struct draw_context *draw);
500
uint draw_current_shader_num_written_culldistances(const struct draw_context *draw);
501
int draw_alloc_extra_vertex_attrib(struct draw_context *draw,
502
uint semantic_name, uint semantic_index);
503
void draw_remove_extra_vertex_attribs(struct draw_context *draw);
504
boolean draw_current_shader_uses_viewport_index(
505
const struct draw_context *draw);
506
507
508
/*******************************************************************************
509
* Vertex processing (was passthrough) code:
510
*/
511
boolean draw_pt_init( struct draw_context *draw );
512
void draw_pt_destroy( struct draw_context *draw );
513
void draw_pt_reset_vertex_ids( struct draw_context *draw );
514
void draw_pt_flush( struct draw_context *draw, unsigned flags );
515
516
517
/*******************************************************************************
518
* Primitive processing (pipeline) code:
519
*/
520
521
boolean draw_pipeline_init( struct draw_context *draw );
522
void draw_pipeline_destroy( struct draw_context *draw );
523
524
525
526
527
528
/*
529
* These flags are used by the pipeline when unfilled and/or line stipple modes
530
* are operational.
531
*/
532
#define DRAW_PIPE_EDGE_FLAG_0 0x1
533
#define DRAW_PIPE_EDGE_FLAG_1 0x2
534
#define DRAW_PIPE_EDGE_FLAG_2 0x4
535
#define DRAW_PIPE_EDGE_FLAG_ALL 0x7
536
#define DRAW_PIPE_RESET_STIPPLE 0x8
537
538
void draw_pipeline_run( struct draw_context *draw,
539
const struct draw_vertex_info *vert,
540
const struct draw_prim_info *prim);
541
542
void draw_pipeline_run_linear( struct draw_context *draw,
543
const struct draw_vertex_info *vert,
544
const struct draw_prim_info *prim);
545
546
547
548
549
void draw_pipeline_flush( struct draw_context *draw,
550
unsigned flags );
551
552
553
554
/*******************************************************************************
555
* Flushing
556
*/
557
558
#define DRAW_FLUSH_PARAMETER_CHANGE 0x1 /**< Constants, viewport, etc */
559
#define DRAW_FLUSH_STATE_CHANGE 0x2 /**< Other/heavy state changes */
560
#define DRAW_FLUSH_BACKEND 0x4 /**< Flush the output buffer */
561
562
563
void draw_do_flush( struct draw_context *draw, unsigned flags );
564
565
566
567
void *
568
draw_get_rasterizer_no_cull( struct draw_context *draw,
569
const struct pipe_rasterizer_state *rast );
570
571
void
572
draw_stats_clipper_primitives(struct draw_context *draw,
573
const struct draw_prim_info *prim_info);
574
575
void draw_update_clip_flags(struct draw_context *draw);
576
void draw_update_viewport_flags(struct draw_context *draw);
577
578
/**
579
* Return index i from the index buffer.
580
* If the index buffer would overflow we return index 0.
581
*/
582
#define DRAW_GET_IDX(_elts, _i) \
583
(((_i) >= draw->pt.user.eltMax) ? 0 : (_elts)[_i])
584
585
/**
586
* Return index of the given viewport clamping it
587
* to be between 0 <= and < PIPE_MAX_VIEWPORTS
588
*/
589
static inline unsigned
590
draw_clamp_viewport_idx(int idx)
591
{
592
return ((PIPE_MAX_VIEWPORTS > idx && idx >= 0) ? idx : 0);
593
}
594
595
/**
596
* Adds two unsigned integers and if the addition
597
* overflows then it returns the value from
598
* the overflow_value variable.
599
*/
600
static inline unsigned
601
draw_overflow_uadd(unsigned a, unsigned b,
602
unsigned overflow_value)
603
{
604
unsigned res = a + b;
605
if (res < a) {
606
res = overflow_value;
607
}
608
return res;
609
}
610
611
#endif /* DRAW_PRIVATE_H */
612
613