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 128
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 */
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) */
201 struct draw_vertex_buffer vbuffer
[PIPE_MAX_ATTRIBS
];
203 /** constant buffers (for vertex/geometry shader) */
204 const void *vs_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
205 unsigned vs_constants_size
[PIPE_MAX_CONSTANT_BUFFERS
];
206 const void *gs_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
207 unsigned gs_constants_size
[PIPE_MAX_CONSTANT_BUFFERS
];
209 /* pointer to planes */
210 float (*planes
)[DRAW_TOTAL_CLIP_PLANES
][4];
213 boolean test_fse
; /* enable FSE even though its not correct (eg for softpipe) */
214 boolean no_fse
; /* disable FSE even when it is correct */
218 boolean bypass_clip_xy
;
219 boolean bypass_clip_z
;
220 boolean guard_band_xy
;
221 boolean bypass_clip_points
;
224 boolean quads_always_flatshade_last
;
226 boolean flushing
; /**< debugging/sanity */
227 boolean suspend_flushing
; /**< internally set */
229 /* Flags set if API requires clipping in these planes and the
230 * driver doesn't indicate that it can do it for us.
235 boolean guard_band_xy
;
236 boolean guard_band_points_xy
;
238 boolean force_passthrough
; /**< never clip or shade */
242 /** Depth format and bias related settings. */
243 boolean floating_point_depth
;
244 double mrd
; /**< minimum resolvable depth value, for polygon offset */
246 /** Current rasterizer state given to us by the driver */
247 const struct pipe_rasterizer_state
*rasterizer
;
248 /** Driver CSO handle for the current rasterizer state */
251 /** Rasterizer CSOs without culling/stipple/etc */
252 void *rasterizer_no_cull
[2][2];
254 struct pipe_viewport_state viewports
[PIPE_MAX_VIEWPORTS
];
255 boolean identity_viewport
;
256 boolean bypass_viewport
;
258 /** Vertex shader state */
260 struct draw_vertex_shader
*vertex_shader
;
261 uint num_vs_outputs
; /**< convenience, from vertex_shader */
262 uint position_output
;
263 uint edgeflag_output
;
264 uint clipvertex_output
;
265 uint ccdistance_output
[2];
267 /** Fields for TGSI interpreter / execution */
269 struct tgsi_exec_machine
*machine
;
271 struct tgsi_sampler
*sampler
;
272 struct tgsi_image
*image
;
273 struct tgsi_buffer
*buffer
;
276 struct translate
*fetch
;
277 struct translate_cache
*fetch_cache
;
278 struct translate
*emit
;
279 struct translate_cache
*emit_cache
;
282 /** Geometry shader state */
284 struct draw_geometry_shader
*geometry_shader
;
285 uint num_gs_outputs
; /**< convenience, from geometry_shader */
286 uint position_output
;
288 /** Fields for TGSI interpreter / execution */
290 struct tgsi_exec_machine
*machine
;
292 struct tgsi_sampler
*sampler
;
293 struct tgsi_image
*image
;
294 struct tgsi_buffer
*buffer
;
299 /** Fragment shader state */
301 struct draw_fragment_shader
*fragment_shader
;
304 /** Stream output (vertex feedback) state */
306 struct draw_so_target
*targets
[PIPE_MAX_SO_BUFFERS
];
310 /* Clip derived state:
312 float plane
[DRAW_TOTAL_CLIP_PLANES
][4];
314 /* If a prim stage introduces new vertex attributes, they'll be stored here
318 uint semantic_name
[10];
319 uint semantic_index
[10];
321 } extra_shader_outputs
;
323 unsigned instance_id
;
324 unsigned start_instance
;
325 unsigned start_index
;
327 struct draw_llvm
*llvm
;
329 /** Texture sampler and sampler view state.
330 * Note that we have arrays indexed by shader type. At this time
331 * we only handle vertex and geometry shaders in the draw module, but
332 * there may be more in the future (ex: hull and tessellation).
334 struct pipe_sampler_view
*sampler_views
[PIPE_SHADER_TYPES
][PIPE_MAX_SHADER_SAMPLER_VIEWS
];
335 unsigned num_sampler_views
[PIPE_SHADER_TYPES
];
336 const struct pipe_sampler_state
*samplers
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
337 unsigned num_samplers
[PIPE_SHADER_TYPES
];
339 struct pipe_query_data_pipeline_statistics statistics
;
340 boolean collect_statistics
;
342 struct draw_assembler
*ia
;
344 void *driver_private
;
348 struct draw_fetch_info
{
351 const unsigned *elts
;
355 struct draw_vertex_info
{
356 struct vertex_header
*verts
;
357 unsigned vertex_size
;
362 /* these flags are set if the primitive is a segment of a larger one */
363 #define DRAW_SPLIT_BEFORE 0x1
364 #define DRAW_SPLIT_AFTER 0x2
365 #define DRAW_LINE_LOOP_AS_STRIP 0x4
367 struct draw_prim_info
{
376 unsigned *primitive_lengths
;
377 unsigned primitive_count
;
381 /*******************************************************************************
382 * Draw common initialization code
384 boolean
draw_init(struct draw_context
*draw
);
385 void draw_new_instance(struct draw_context
*draw
);
387 /*******************************************************************************
388 * Vertex shader code:
390 boolean
draw_vs_init( struct draw_context
*draw
);
391 void draw_vs_destroy( struct draw_context
*draw
);
394 /*******************************************************************************
395 * Geometry shading code:
397 boolean
draw_gs_init( struct draw_context
*draw
);
400 void draw_gs_destroy( struct draw_context
*draw
);
402 /*******************************************************************************
403 * Common shading code:
405 uint
draw_current_shader_outputs(const struct draw_context
*draw
);
406 uint
draw_current_shader_position_output(const struct draw_context
*draw
);
407 uint
draw_current_shader_viewport_index_output(const struct draw_context
*draw
);
408 uint
draw_current_shader_clipvertex_output(const struct draw_context
*draw
);
409 uint
draw_current_shader_ccdistance_output(const struct draw_context
*draw
, int index
);
410 uint
draw_current_shader_num_written_clipdistances(const struct draw_context
*draw
);
411 uint
draw_current_shader_num_written_culldistances(const struct draw_context
*draw
);
412 int draw_alloc_extra_vertex_attrib(struct draw_context
*draw
,
413 uint semantic_name
, uint semantic_index
);
414 void draw_remove_extra_vertex_attribs(struct draw_context
*draw
);
415 boolean
draw_current_shader_uses_viewport_index(
416 const struct draw_context
*draw
);
419 /*******************************************************************************
420 * Vertex processing (was passthrough) code:
422 boolean
draw_pt_init( struct draw_context
*draw
);
423 void draw_pt_destroy( struct draw_context
*draw
);
424 void draw_pt_reset_vertex_ids( struct draw_context
*draw
);
425 void draw_pt_flush( struct draw_context
*draw
, unsigned flags
);
428 /*******************************************************************************
429 * Primitive processing (pipeline) code:
432 boolean
draw_pipeline_init( struct draw_context
*draw
);
433 void draw_pipeline_destroy( struct draw_context
*draw
);
440 * These flags are used by the pipeline when unfilled and/or line stipple modes
443 #define DRAW_PIPE_EDGE_FLAG_0 0x1
444 #define DRAW_PIPE_EDGE_FLAG_1 0x2
445 #define DRAW_PIPE_EDGE_FLAG_2 0x4
446 #define DRAW_PIPE_EDGE_FLAG_ALL 0x7
447 #define DRAW_PIPE_RESET_STIPPLE 0x8
449 void draw_pipeline_run( struct draw_context
*draw
,
450 const struct draw_vertex_info
*vert
,
451 const struct draw_prim_info
*prim
);
453 void draw_pipeline_run_linear( struct draw_context
*draw
,
454 const struct draw_vertex_info
*vert
,
455 const struct draw_prim_info
*prim
);
460 void draw_pipeline_flush( struct draw_context
*draw
,
465 /*******************************************************************************
469 #define DRAW_FLUSH_PARAMETER_CHANGE 0x1 /**< Constants, viewport, etc */
470 #define DRAW_FLUSH_STATE_CHANGE 0x2 /**< Other/heavy state changes */
471 #define DRAW_FLUSH_BACKEND 0x4 /**< Flush the output buffer */
474 void draw_do_flush( struct draw_context
*draw
, unsigned flags
);
479 draw_get_rasterizer_no_cull( struct draw_context
*draw
,
484 draw_stats_clipper_primitives(struct draw_context
*draw
,
485 const struct draw_prim_info
*prim_info
);
487 void draw_update_clip_flags(struct draw_context
*draw
);
488 void draw_update_viewport_flags(struct draw_context
*draw
);
491 * Return index i from the index buffer.
492 * If the index buffer would overflow we return index 0.
494 #define DRAW_GET_IDX(_elts, _i) \
495 (((_i) >= draw->pt.user.eltMax) ? 0 : (_elts)[_i])
498 * Return index of the given viewport clamping it
499 * to be between 0 <= and < PIPE_MAX_VIEWPORTS
501 static inline unsigned
502 draw_clamp_viewport_idx(int idx
)
504 return ((PIPE_MAX_VIEWPORTS
> idx
&& idx
>= 0) ? idx
: 0);
508 * Adds two unsigned integers and if the addition
509 * overflows then it returns the value from
510 * the overflow_value variable.
512 static inline unsigned
513 draw_overflow_uadd(unsigned a
, unsigned b
,
514 unsigned overflow_value
)
516 unsigned res
= a
+ b
;
518 res
= overflow_value
;
523 #endif /* DRAW_PRIVATE_H */