1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 <keith@tungstengraphics.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"
55 /** Sum of frustum planes and user-defined planes */
56 #define DRAW_TOTAL_CLIP_PLANES (6 + PIPE_MAX_CLIP_PLANES)
60 struct draw_vertex_shader
;
64 struct tgsi_exec_machine
;
66 struct draw_pt_front_end
;
70 * Represents the mapped vertex buffer.
72 struct draw_vertex_buffer
{
79 * Carry some useful information around with the vertices in the prim pipe.
81 struct vertex_header
{
82 unsigned clipmask
:DRAW_TOTAL_CLIP_PLANES
;
84 unsigned have_clipdist
:1;
85 unsigned vertex_id
:16;
88 float pre_clip_pos
[4];
90 /* This will probably become float (*data)[4] soon:
95 /* NOTE: It should match vertex_id size above */
96 #define UNDEFINED_VERTEX_ID 0xffff
99 /* maximum number of shader variants we can cache */
100 #define DRAW_MAX_SHADER_VARIANTS 128
103 * Private context for the drawing module.
107 struct pipe_context
*pipe
;
109 /** Drawing/primitive pipeline stages */
111 struct draw_stage
*first
; /**< one of the following */
113 struct draw_stage
*validate
;
115 /* stages (in logical order) */
116 struct draw_stage
*flatshade
;
117 struct draw_stage
*clip
;
118 struct draw_stage
*cull
;
119 struct draw_stage
*twoside
;
120 struct draw_stage
*offset
;
121 struct draw_stage
*unfilled
;
122 struct draw_stage
*stipple
;
123 struct draw_stage
*aapoint
;
124 struct draw_stage
*aaline
;
125 struct draw_stage
*pstipple
;
126 struct draw_stage
*wide_line
;
127 struct draw_stage
*wide_point
;
128 struct draw_stage
*rasterize
;
130 float wide_point_threshold
; /**< convert pnts to tris if larger than this */
131 float wide_line_threshold
; /**< convert lines to tris if wider than this */
132 boolean wide_point_sprites
; /**< convert points to tris for sprite mode */
133 boolean line_stipple
; /**< do line stipple? */
134 boolean point_sprite
; /**< convert points to quads for sprites? */
136 /* Temporary storage while the pipeline is being run:
139 unsigned vertex_stride
;
140 unsigned vertex_count
;
144 struct vbuf_render
*render
;
146 /* Support prototype passthrough path:
149 /* Current active frontend */
150 struct draw_pt_front_end
*frontend
;
152 unsigned opt
; /**< bitmask of PT_x flags */
153 unsigned eltSize
; /* saved eltSize for flushing */
155 boolean rebind_parameters
;
158 struct draw_pt_middle_end
*fetch_emit
;
159 struct draw_pt_middle_end
*fetch_shade_emit
;
160 struct draw_pt_middle_end
*general
;
161 struct draw_pt_middle_end
*llvm
;
165 struct draw_pt_front_end
*vsplit
;
168 struct pipe_vertex_buffer vertex_buffer
[PIPE_MAX_ATTRIBS
];
169 unsigned nr_vertex_buffers
;
172 * This is the largest legal index value for the current set of
173 * bound vertex buffers. Regardless of any other consideration,
174 * all vertex lookups need to be clamped to 0..max_index to
175 * prevent out-of-bound access.
179 struct pipe_vertex_element vertex_element
[PIPE_MAX_ATTRIBS
];
180 unsigned nr_vertex_elements
;
182 /* user-space vertex data, buffers */
184 /** vertex element/index buffer (ex: glDrawElements) */
186 /** bytes per index (0, 1, 2 or 4) */
195 struct draw_vertex_buffer vbuffer
[PIPE_MAX_ATTRIBS
];
197 /** constant buffers (for vertex/geometry shader) */
198 const void *vs_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
199 unsigned vs_constants_size
[PIPE_MAX_CONSTANT_BUFFERS
];
200 const void *gs_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
201 unsigned gs_constants_size
[PIPE_MAX_CONSTANT_BUFFERS
];
203 /* pointer to planes */
204 float (*planes
)[DRAW_TOTAL_CLIP_PLANES
][4];
207 boolean test_fse
; /* enable FSE even though its not correct (eg for softpipe) */
208 boolean no_fse
; /* disable FSE even when it is correct */
212 boolean bypass_clip_xy
;
213 boolean bypass_clip_z
;
214 boolean guard_band_xy
;
217 boolean quads_always_flatshade_last
;
219 boolean flushing
; /**< debugging/sanity */
220 boolean suspend_flushing
; /**< internally set */
222 /* Flags set if API requires clipping in these planes and the
223 * driver doesn't indicate that it can do it for us.
228 boolean guard_band_xy
;
230 boolean force_passthrough
; /**< never clip or shade */
234 double mrd
; /**< minimum resolvable depth value, for polygon offset */
236 /** Current rasterizer state given to us by the driver */
237 const struct pipe_rasterizer_state
*rasterizer
;
238 /** Driver CSO handle for the current rasterizer state */
241 /** Rasterizer CSOs without culling/stipple/etc */
242 void *rasterizer_no_cull
[2][2];
244 struct pipe_viewport_state viewports
[PIPE_MAX_VIEWPORTS
];
245 boolean identity_viewport
;
247 /** Vertex shader state */
249 struct draw_vertex_shader
*vertex_shader
;
250 uint num_vs_outputs
; /**< convenience, from vertex_shader */
251 uint position_output
;
252 uint edgeflag_output
;
253 uint clipvertex_output
;
254 uint clipdistance_output
[2];
256 /** Fields for TGSI interpreter / execution */
258 struct tgsi_exec_machine
*machine
;
260 struct tgsi_sampler
*sampler
;
263 struct translate
*fetch
;
264 struct translate_cache
*fetch_cache
;
265 struct translate
*emit
;
266 struct translate_cache
*emit_cache
;
269 /** Geometry shader state */
271 struct draw_geometry_shader
*geometry_shader
;
272 uint num_gs_outputs
; /**< convenience, from geometry_shader */
273 uint position_output
;
275 /** Fields for TGSI interpreter / execution */
277 struct tgsi_exec_machine
*machine
;
279 struct tgsi_sampler
*sampler
;
284 /** Fragment shader state */
286 struct draw_fragment_shader
*fragment_shader
;
289 /** Stream output (vertex feedback) state */
291 struct draw_so_target
*targets
[PIPE_MAX_SO_BUFFERS
];
295 /* Clip derived state:
297 float plane
[DRAW_TOTAL_CLIP_PLANES
][4];
299 /* If a prim stage introduces new vertex attributes, they'll be stored here
303 uint semantic_name
[10];
304 uint semantic_index
[10];
306 } extra_shader_outputs
;
308 unsigned instance_id
;
311 struct draw_llvm
*llvm
;
314 /** Texture sampler and sampler view state.
315 * Note that we have arrays indexed by shader type. At this time
316 * we only handle vertex and geometry shaders in the draw module, but
317 * there may be more in the future (ex: hull and tessellation).
319 struct pipe_sampler_view
*sampler_views
[PIPE_SHADER_TYPES
][PIPE_MAX_SHADER_SAMPLER_VIEWS
];
320 unsigned num_sampler_views
[PIPE_SHADER_TYPES
];
321 const struct pipe_sampler_state
*samplers
[PIPE_SHADER_TYPES
][PIPE_MAX_SAMPLERS
];
322 unsigned num_samplers
[PIPE_SHADER_TYPES
];
324 struct pipe_query_data_pipeline_statistics statistics
;
325 boolean collect_statistics
;
327 void *driver_private
;
331 struct draw_fetch_info
{
334 const unsigned *elts
;
338 struct draw_vertex_info
{
339 struct vertex_header
*verts
;
340 unsigned vertex_size
;
345 /* these flags are set if the primitive is a segment of a larger one */
346 #define DRAW_SPLIT_BEFORE 0x1
347 #define DRAW_SPLIT_AFTER 0x2
349 struct draw_prim_info
{
358 unsigned *primitive_lengths
;
359 unsigned primitive_count
;
363 /*******************************************************************************
364 * Draw common initialization code
366 boolean
draw_init(struct draw_context
*draw
);
367 void draw_new_instance(struct draw_context
*draw
);
369 /*******************************************************************************
370 * Vertex shader code:
372 boolean
draw_vs_init( struct draw_context
*draw
);
373 void draw_vs_destroy( struct draw_context
*draw
);
376 /*******************************************************************************
377 * Geometry shading code:
379 boolean
draw_gs_init( struct draw_context
*draw
);
382 void draw_gs_destroy( struct draw_context
*draw
);
384 /*******************************************************************************
385 * Common shading code:
387 uint
draw_current_shader_outputs(const struct draw_context
*draw
);
388 uint
draw_current_shader_position_output(const struct draw_context
*draw
);
389 uint
draw_current_shader_viewport_index_output(const struct draw_context
*draw
);
390 uint
draw_current_shader_clipvertex_output(const struct draw_context
*draw
);
391 uint
draw_current_shader_clipdistance_output(const struct draw_context
*draw
, int index
);
392 uint
draw_current_shader_num_written_clipdistances(const struct draw_context
*draw
);
393 uint
draw_current_shader_culldistance_output(const struct draw_context
*draw
, int index
);
394 uint
draw_current_shader_num_written_culldistances(const struct draw_context
*draw
);
395 int draw_alloc_extra_vertex_attrib(struct draw_context
*draw
,
396 uint semantic_name
, uint semantic_index
);
397 void draw_remove_extra_vertex_attribs(struct draw_context
*draw
);
398 boolean
draw_current_shader_uses_viewport_index(
399 const struct draw_context
*draw
);
402 /*******************************************************************************
403 * Vertex processing (was passthrough) code:
405 boolean
draw_pt_init( struct draw_context
*draw
);
406 void draw_pt_destroy( struct draw_context
*draw
);
407 void draw_pt_reset_vertex_ids( struct draw_context
*draw
);
408 void draw_pt_flush( struct draw_context
*draw
, unsigned flags
);
411 /*******************************************************************************
412 * Primitive processing (pipeline) code:
415 boolean
draw_pipeline_init( struct draw_context
*draw
);
416 void draw_pipeline_destroy( struct draw_context
*draw
);
423 * These flags are used by the pipeline when unfilled and/or line stipple modes
426 #define DRAW_PIPE_EDGE_FLAG_0 0x1
427 #define DRAW_PIPE_EDGE_FLAG_1 0x2
428 #define DRAW_PIPE_EDGE_FLAG_2 0x4
429 #define DRAW_PIPE_EDGE_FLAG_ALL 0x7
430 #define DRAW_PIPE_RESET_STIPPLE 0x8
432 void draw_pipeline_run( struct draw_context
*draw
,
433 const struct draw_vertex_info
*vert
,
434 const struct draw_prim_info
*prim
);
436 void draw_pipeline_run_linear( struct draw_context
*draw
,
437 const struct draw_vertex_info
*vert
,
438 const struct draw_prim_info
*prim
);
443 void draw_pipeline_flush( struct draw_context
*draw
,
448 /*******************************************************************************
452 #define DRAW_FLUSH_PARAMETER_CHANGE 0x1 /**< Constants, viewport, etc */
453 #define DRAW_FLUSH_STATE_CHANGE 0x2 /**< Other/heavy state changes */
454 #define DRAW_FLUSH_BACKEND 0x4 /**< Flush the output buffer */
457 void draw_do_flush( struct draw_context
*draw
, unsigned flags
);
462 draw_get_rasterizer_no_cull( struct draw_context
*draw
,
467 draw_stats_clipper_primitives(struct draw_context
*draw
,
468 const struct draw_prim_info
*prim_info
);
472 * Return index i from the index buffer.
473 * If the index buffer would overflow we return the
474 * index of the first element in the vb.
476 #define DRAW_GET_IDX(_elts, _i) \
477 (((_i) >= draw->pt.user.eltMax) ? 0 : (_elts)[_i])
480 * Return index of the given viewport clamping it
481 * to be between 0 <= and < PIPE_MAX_VIEWPORTS
483 static INLINE
unsigned
484 draw_clamp_viewport_idx(int idx
)
486 return ((PIPE_MAX_VIEWPORTS
> idx
|| idx
< 0) ? idx
: 0);
490 #endif /* DRAW_PRIVATE_H */