1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
29 * Private data structures, etc for the draw module.
35 * Keith Whitwell <keithw@vmware.com>
40 #ifndef DRAW_PRIVATE_H
41 #define DRAW_PRIVATE_H
44 #include "pipe/p_state.h"
45 #include "pipe/p_defines.h"
47 #include "tgsi/tgsi_scan.h"
54 /** Sum of frustum planes and user-defined planes */
55 #define DRAW_TOTAL_CLIP_PLANES (6 + PIPE_MAX_CLIP_PLANES)
58 * The largest possible index of a vertex that can be fetched.
60 #define DRAW_MAX_FETCH_IDX 0xffffffff
63 struct draw_vertex_shader
;
67 struct tgsi_exec_machine
;
71 struct draw_pt_front_end
;
72 struct draw_assembler
;
77 * Represents the mapped vertex buffer.
79 struct draw_vertex_buffer
{
86 * Carry some useful information around with the vertices in the prim pipe.
88 struct vertex_header
{
89 unsigned clipmask
:DRAW_TOTAL_CLIP_PLANES
;
92 unsigned vertex_id
:16;
96 /* This will probably become float (*data)[4] soon:
101 /* NOTE: It should match vertex_id size above */
102 #define UNDEFINED_VERTEX_ID 0xffff
105 /* maximum number of shader variants we can cache */
106 #define DRAW_MAX_SHADER_VARIANTS 512
109 * Private context for the drawing module.
113 struct pipe_context
*pipe
;
115 /** Drawing/primitive pipeline stages */
117 struct draw_stage
*first
; /**< one of the following */
119 struct draw_stage
*validate
;
121 /* stages (in logical order) */
122 struct draw_stage
*flatshade
;
123 struct draw_stage
*clip
;
124 struct draw_stage
*cull
;
125 struct draw_stage
*twoside
;
126 struct draw_stage
*offset
;
127 struct draw_stage
*unfilled
;
128 struct draw_stage
*stipple
;
129 struct draw_stage
*aapoint
;
130 struct draw_stage
*aaline
;
131 struct draw_stage
*pstipple
;
132 struct draw_stage
*wide_line
;
133 struct draw_stage
*wide_point
;
134 struct draw_stage
*rasterize
;
136 float wide_point_threshold
; /**< convert pnts to tris if larger than this */
137 float wide_line_threshold
; /**< convert lines to tris if wider than this */
138 boolean wide_point_sprites
; /**< convert points to tris for sprite mode */
139 boolean line_stipple
; /**< do line stipple? */
140 boolean point_sprite
; /**< convert points to quads for sprites? */
142 /* Temporary storage while the pipeline is being run:
145 unsigned vertex_stride
;
146 unsigned vertex_count
;
150 struct vbuf_render
*render
;
152 /* Support prototype passthrough path:
155 /* Current active frontend */
156 struct draw_pt_front_end
*frontend
;
158 unsigned opt
; /**< bitmask of PT_x flags */
159 unsigned eltSize
; /* saved eltSize for flushing */
160 ubyte vertices_per_patch
;
161 boolean rebind_parameters
;
164 struct draw_pt_middle_end
*fetch_emit
;
165 struct draw_pt_middle_end
*fetch_shade_emit
;
166 struct draw_pt_middle_end
*general
;
167 struct draw_pt_middle_end
*llvm
;
171 struct draw_pt_front_end
*vsplit
;
174 struct pipe_vertex_buffer vertex_buffer
[PIPE_MAX_ATTRIBS
];
175 unsigned nr_vertex_buffers
;
178 * This is the largest legal index value for the current set of
179 * bound vertex buffers. Regardless of any other consideration,
180 * all vertex lookups need to be clamped to 0..max_index to
181 * prevent out-of-bound access.
185 struct pipe_vertex_element vertex_element
[PIPE_MAX_ATTRIBS
];
186 unsigned nr_vertex_elements
;
188 /* user-space vertex data, buffers */
190 /** vertex element/index buffer (ex: glDrawElements) */
192 /** bytes per index (0, 1, 2 or 4) */
202 struct draw_vertex_buffer vbuffer
[PIPE_MAX_ATTRIBS
];
204 /** constant buffers (for vertex/geometry shader) */
205 const void *vs_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
206 unsigned vs_constants_size
[PIPE_MAX_CONSTANT_BUFFERS
];
207 const void *gs_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
208 unsigned gs_constants_size
[PIPE_MAX_CONSTANT_BUFFERS
];
209 const void *tcs_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
210 unsigned tcs_constants_size
[PIPE_MAX_CONSTANT_BUFFERS
];
211 const void *tes_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
212 unsigned tes_constants_size
[PIPE_MAX_CONSTANT_BUFFERS
];
214 /** shader buffers (for vertex/geometry shader) */
215 const void *vs_ssbos
[PIPE_MAX_SHADER_BUFFERS
];
216 unsigned vs_ssbos_size
[PIPE_MAX_SHADER_BUFFERS
];
217 const void *gs_ssbos
[PIPE_MAX_SHADER_BUFFERS
];
218 unsigned gs_ssbos_size
[PIPE_MAX_SHADER_BUFFERS
];
219 const void *tcs_ssbos
[PIPE_MAX_SHADER_BUFFERS
];
220 unsigned tcs_ssbos_size
[PIPE_MAX_SHADER_BUFFERS
];
221 const void *tes_ssbos
[PIPE_MAX_SHADER_BUFFERS
];
222 unsigned tes_ssbos_size
[PIPE_MAX_SHADER_BUFFERS
];
224 /* pointer to planes */
225 float (*planes
)[DRAW_TOTAL_CLIP_PLANES
][4];
228 boolean test_fse
; /* enable FSE even though its not correct (eg for softpipe) */
229 boolean no_fse
; /* disable FSE even when it is correct */
233 boolean bypass_clip_xy
;
234 boolean bypass_clip_z
;
235 boolean guard_band_xy
;
236 boolean bypass_clip_points
;
239 boolean quads_always_flatshade_last
;
241 boolean flushing
; /**< debugging/sanity */
242 boolean suspend_flushing
; /**< internally set */
244 /* Flags set if API requires clipping in these planes and the
245 * driver doesn't indicate that it can do it for us.
250 boolean guard_band_xy
;
251 boolean guard_band_points_xy
;
253 boolean force_passthrough
; /**< never clip or shade */
257 /** Depth format and bias related settings. */
258 boolean floating_point_depth
;
259 double mrd
; /**< minimum resolvable depth value, for polygon offset */
261 /** Current rasterizer state given to us by the driver */
262 const struct pipe_rasterizer_state
*rasterizer
;
263 /** Driver CSO handle for the current rasterizer state */
266 /** Rasterizer CSOs without culling/stipple/etc */
267 void *rasterizer_no_cull
[2][2];
269 struct pipe_viewport_state viewports
[PIPE_MAX_VIEWPORTS
];
270 boolean identity_viewport
;
271 boolean bypass_viewport
;
273 /** Vertex shader state */
275 struct draw_vertex_shader
*vertex_shader
;
276 uint num_vs_outputs
; /**< convenience, from vertex_shader */
277 uint position_output
;
278 uint edgeflag_output
;
279 uint clipvertex_output
;
280 uint ccdistance_output
[2];
282 /** Fields for TGSI interpreter / execution */
284 struct tgsi_exec_machine
*machine
;
286 struct tgsi_sampler
*sampler
;
287 struct tgsi_image
*image
;
288 struct tgsi_buffer
*buffer
;
291 struct translate
*fetch
;
292 struct translate_cache
*fetch_cache
;
293 struct translate
*emit
;
294 struct translate_cache
*emit_cache
;
297 /** Geometry shader state */
299 struct draw_geometry_shader
*geometry_shader
;
300 uint num_gs_outputs
; /**< convenience, from geometry_shader */
301 uint position_output
;
303 /** Fields for TGSI interpreter / execution */
305 struct tgsi_exec_machine
*machine
;
307 struct tgsi_sampler
*sampler
;
308 struct tgsi_image
*image
;
309 struct tgsi_buffer
*buffer
;
314 /* Tessellation state */
316 struct draw_tess_ctrl_shader
*tess_ctrl_shader
;
318 /** Fields for TGSI interpreter / execution */
320 struct tgsi_exec_machine
*machine
;
322 struct tgsi_sampler
*sampler
;
323 struct tgsi_image
*image
;
324 struct tgsi_buffer
*buffer
;
329 struct draw_tess_eval_shader
*tess_eval_shader
;
330 uint position_output
;
332 /** Fields for TGSI interpreter / execution */
334 struct tgsi_exec_machine
*machine
;
336 struct tgsi_sampler
*sampler
;
337 struct tgsi_image
*image
;
338 struct tgsi_buffer
*buffer
;
342 /** Fragment shader state */
344 struct draw_fragment_shader
*fragment_shader
;
347 /** Stream output (vertex feedback) state */
349 struct draw_so_target
*targets
[PIPE_MAX_SO_BUFFERS
];
353 /* Clip derived state:
355 float plane
[DRAW_TOTAL_CLIP_PLANES
][4];
357 /* If a prim stage introduces new vertex attributes, they'll be stored here
361 uint semantic_name
[10];
362 uint semantic_index
[10];
364 } extra_shader_outputs
;
366 unsigned instance_id
;
367 unsigned start_instance
;
368 unsigned start_index
;
370 struct draw_llvm
*llvm
;
372 /** Texture sampler and sampler view state.
373 * Note that we have arrays indexed by shader type. At this time
374 * we only handle vertex and geometry shaders in the draw module, but
375 * there may be more in the future (ex: hull and tessellation).
377 struct pipe_sampler_view
*sampler_views
[PIPE_SHADER_TYPES
][PIPE_MAX_SHADER_SAMPLER_VIEWS
];
378 unsigned num_sampler_views
[PIPE_SHADER_TYPES
];
379 const struct pipe_sampler_state
*samplers
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
380 unsigned num_samplers
[PIPE_SHADER_TYPES
];
382 struct pipe_image_view
*images
[PIPE_SHADER_TYPES
][PIPE_MAX_SHADER_IMAGES
];
383 unsigned num_images
[PIPE_SHADER_TYPES
];
385 struct pipe_query_data_pipeline_statistics statistics
;
386 boolean collect_statistics
;
388 float default_outer_tess_level
[4];
389 float default_inner_tess_level
[2];
390 bool collect_primgen
;
392 struct draw_assembler
*ia
;
394 void *driver_private
;
398 struct draw_fetch_info
{
401 const unsigned *elts
;
405 struct draw_vertex_info
{
406 struct vertex_header
*verts
;
407 unsigned vertex_size
;
412 /* these flags are set if the primitive is a segment of a larger one */
413 #define DRAW_SPLIT_BEFORE 0x1
414 #define DRAW_SPLIT_AFTER 0x2
415 #define DRAW_LINE_LOOP_AS_STRIP 0x4
417 struct draw_prim_info
{
426 unsigned *primitive_lengths
;
427 unsigned primitive_count
;
431 /*******************************************************************************
432 * Draw common initialization code
434 boolean
draw_init(struct draw_context
*draw
);
435 void draw_new_instance(struct draw_context
*draw
);
437 /*******************************************************************************
438 * Vertex shader code:
440 boolean
draw_vs_init( struct draw_context
*draw
);
441 void draw_vs_destroy( struct draw_context
*draw
);
444 /*******************************************************************************
445 * Geometry shading code:
447 boolean
draw_gs_init( struct draw_context
*draw
);
450 void draw_gs_destroy( struct draw_context
*draw
);
452 /*******************************************************************************
453 * Common shading code:
455 uint
draw_current_shader_outputs(const struct draw_context
*draw
);
456 uint
draw_current_shader_position_output(const struct draw_context
*draw
);
457 uint
draw_current_shader_viewport_index_output(const struct draw_context
*draw
);
458 uint
draw_current_shader_clipvertex_output(const struct draw_context
*draw
);
459 uint
draw_current_shader_ccdistance_output(const struct draw_context
*draw
, int index
);
460 uint
draw_current_shader_num_written_clipdistances(const struct draw_context
*draw
);
461 uint
draw_current_shader_num_written_culldistances(const struct draw_context
*draw
);
462 int draw_alloc_extra_vertex_attrib(struct draw_context
*draw
,
463 uint semantic_name
, uint semantic_index
);
464 void draw_remove_extra_vertex_attribs(struct draw_context
*draw
);
465 boolean
draw_current_shader_uses_viewport_index(
466 const struct draw_context
*draw
);
469 /*******************************************************************************
470 * Vertex processing (was passthrough) code:
472 boolean
draw_pt_init( struct draw_context
*draw
);
473 void draw_pt_destroy( struct draw_context
*draw
);
474 void draw_pt_reset_vertex_ids( struct draw_context
*draw
);
475 void draw_pt_flush( struct draw_context
*draw
, unsigned flags
);
478 /*******************************************************************************
479 * Primitive processing (pipeline) code:
482 boolean
draw_pipeline_init( struct draw_context
*draw
);
483 void draw_pipeline_destroy( struct draw_context
*draw
);
490 * These flags are used by the pipeline when unfilled and/or line stipple modes
493 #define DRAW_PIPE_EDGE_FLAG_0 0x1
494 #define DRAW_PIPE_EDGE_FLAG_1 0x2
495 #define DRAW_PIPE_EDGE_FLAG_2 0x4
496 #define DRAW_PIPE_EDGE_FLAG_ALL 0x7
497 #define DRAW_PIPE_RESET_STIPPLE 0x8
499 void draw_pipeline_run( struct draw_context
*draw
,
500 const struct draw_vertex_info
*vert
,
501 const struct draw_prim_info
*prim
);
503 void draw_pipeline_run_linear( struct draw_context
*draw
,
504 const struct draw_vertex_info
*vert
,
505 const struct draw_prim_info
*prim
);
510 void draw_pipeline_flush( struct draw_context
*draw
,
515 /*******************************************************************************
519 #define DRAW_FLUSH_PARAMETER_CHANGE 0x1 /**< Constants, viewport, etc */
520 #define DRAW_FLUSH_STATE_CHANGE 0x2 /**< Other/heavy state changes */
521 #define DRAW_FLUSH_BACKEND 0x4 /**< Flush the output buffer */
524 void draw_do_flush( struct draw_context
*draw
, unsigned flags
);
529 draw_get_rasterizer_no_cull( struct draw_context
*draw
,
534 draw_stats_clipper_primitives(struct draw_context
*draw
,
535 const struct draw_prim_info
*prim_info
);
537 void draw_update_clip_flags(struct draw_context
*draw
);
538 void draw_update_viewport_flags(struct draw_context
*draw
);
541 * Return index i from the index buffer.
542 * If the index buffer would overflow we return index 0.
544 #define DRAW_GET_IDX(_elts, _i) \
545 (((_i) >= draw->pt.user.eltMax) ? 0 : (_elts)[_i])
548 * Return index of the given viewport clamping it
549 * to be between 0 <= and < PIPE_MAX_VIEWPORTS
551 static inline unsigned
552 draw_clamp_viewport_idx(int idx
)
554 return ((PIPE_MAX_VIEWPORTS
> idx
&& idx
>= 0) ? idx
: 0);
558 * Adds two unsigned integers and if the addition
559 * overflows then it returns the value from
560 * the overflow_value variable.
562 static inline unsigned
563 draw_overflow_uadd(unsigned a
, unsigned b
,
564 unsigned overflow_value
)
566 unsigned res
= a
+ b
;
568 res
= overflow_value
;
573 #endif /* DRAW_PRIVATE_H */