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"
50 #include <llvm-c/ExecutionEngine.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
;
71 * Carry some useful information around with the vertices in the prim pipe.
73 struct vertex_header
{
74 unsigned clipmask
:DRAW_TOTAL_CLIP_PLANES
;
76 unsigned have_clipdist
:1;
77 unsigned vertex_id
:16;
80 float pre_clip_pos
[4];
82 /* This will probably become float (*data)[4] soon:
87 /* NOTE: It should match vertex_id size above */
88 #define UNDEFINED_VERTEX_ID 0xffff
91 /* maximum number of shader variants we can cache */
92 #define DRAW_MAX_SHADER_VARIANTS 128
95 * Private context for the drawing module.
99 struct pipe_context
*pipe
;
101 /** Drawing/primitive pipeline stages */
103 struct draw_stage
*first
; /**< one of the following */
105 struct draw_stage
*validate
;
107 /* stages (in logical order) */
108 struct draw_stage
*flatshade
;
109 struct draw_stage
*clip
;
110 struct draw_stage
*cull
;
111 struct draw_stage
*twoside
;
112 struct draw_stage
*offset
;
113 struct draw_stage
*unfilled
;
114 struct draw_stage
*stipple
;
115 struct draw_stage
*aapoint
;
116 struct draw_stage
*aaline
;
117 struct draw_stage
*pstipple
;
118 struct draw_stage
*wide_line
;
119 struct draw_stage
*wide_point
;
120 struct draw_stage
*rasterize
;
122 float wide_point_threshold
; /**< convert pnts to tris if larger than this */
123 float wide_line_threshold
; /**< convert lines to tris if wider than this */
124 boolean wide_point_sprites
; /**< convert points to tris for sprite mode */
125 boolean line_stipple
; /**< do line stipple? */
126 boolean point_sprite
; /**< convert points to quads for sprites? */
128 /* Temporary storage while the pipeline is being run:
131 unsigned vertex_stride
;
132 unsigned vertex_count
;
136 struct vbuf_render
*render
;
138 /* Support prototype passthrough path:
141 /* Current active frontend */
142 struct draw_pt_front_end
*frontend
;
145 unsigned eltSize
; /* saved eltSize for flushing */
148 struct draw_pt_middle_end
*fetch_emit
;
149 struct draw_pt_middle_end
*fetch_shade_emit
;
150 struct draw_pt_middle_end
*general
;
151 struct draw_pt_middle_end
*llvm
;
155 struct draw_pt_front_end
*vsplit
;
158 struct pipe_vertex_buffer vertex_buffer
[PIPE_MAX_ATTRIBS
];
159 unsigned nr_vertex_buffers
;
162 * This is the largest legal index value for the current set of
163 * bound vertex buffers. Regardless of any other consideration,
164 * all vertex lookups need to be clamped to 0..max_index to
165 * prevent out-of-bound access.
169 struct pipe_vertex_element vertex_element
[PIPE_MAX_ATTRIBS
];
170 unsigned nr_vertex_elements
;
172 /* user-space vertex data, buffers */
174 /** vertex element/index buffer (ex: glDrawElements) */
176 /** bytes per index (0, 1, 2 or 4) */
183 const void *vbuffer
[PIPE_MAX_ATTRIBS
];
185 /** constant buffers (for vertex/geometry shader) */
186 const void *vs_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
187 unsigned vs_constants_size
[PIPE_MAX_CONSTANT_BUFFERS
];
188 const void *gs_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
189 unsigned gs_constants_size
[PIPE_MAX_CONSTANT_BUFFERS
];
191 /* pointer to planes */
192 float (*planes
)[DRAW_TOTAL_CLIP_PLANES
][4];
195 boolean test_fse
; /* enable FSE even though its not correct (eg for softpipe) */
196 boolean no_fse
; /* disable FSE even when it is correct */
200 boolean bypass_clip_xy
;
201 boolean bypass_clip_z
;
202 boolean guard_band_xy
;
205 boolean quads_always_flatshade_last
;
207 boolean flushing
; /**< debugging/sanity */
208 boolean suspend_flushing
; /**< internally set */
210 /* Flags set if API requires clipping in these planes and the
211 * driver doesn't indicate that it can do it for us.
216 boolean guard_band_xy
;
218 boolean force_passthrough
; /**< never clip or shade */
222 double mrd
; /**< minimum resolvable depth value, for polygon offset */
224 /** Current rasterizer state given to us by the driver */
225 const struct pipe_rasterizer_state
*rasterizer
;
226 /** Driver CSO handle for the current rasterizer state */
229 /** Rasterizer CSOs without culling/stipple/etc */
230 void *rasterizer_no_cull
[2][2];
232 struct pipe_viewport_state viewport
;
233 boolean identity_viewport
;
235 /** Vertex shader state */
237 struct draw_vertex_shader
*vertex_shader
;
238 uint num_vs_outputs
; /**< convenience, from vertex_shader */
239 uint position_output
;
240 uint edgeflag_output
;
241 uint clipvertex_output
;
242 uint clipdistance_output
[2];
243 /** TGSI program interpreter runtime state */
244 struct tgsi_exec_machine
*machine
;
247 struct tgsi_sampler
**samplers
;
250 const void *aligned_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
252 const void *aligned_constant_storage
[PIPE_MAX_CONSTANT_BUFFERS
];
253 unsigned const_storage_size
[PIPE_MAX_CONSTANT_BUFFERS
];
256 struct translate
*fetch
;
257 struct translate_cache
*fetch_cache
;
258 struct translate
*emit
;
259 struct translate_cache
*emit_cache
;
262 /** Geometry shader state */
264 struct draw_geometry_shader
*geometry_shader
;
265 uint num_gs_outputs
; /**< convenience, from geometry_shader */
266 uint position_output
;
268 /** TGSI program interpreter runtime state */
269 struct tgsi_exec_machine
*machine
;
272 struct tgsi_sampler
**samplers
;
275 /** Fragment shader state */
277 struct draw_fragment_shader
*fragment_shader
;
280 /** Stream output (vertex feedback) state */
282 struct pipe_stream_output_info state
;
283 struct draw_so_target
*targets
[PIPE_MAX_SO_BUFFERS
];
287 /* Clip derived state:
289 float plane
[DRAW_TOTAL_CLIP_PLANES
][4];
291 /* If a prim stage introduces new vertex attributes, they'll be stored here
295 uint semantic_name
[10];
296 uint semantic_index
[10];
298 } extra_shader_outputs
;
300 unsigned instance_id
;
303 struct draw_llvm
*llvm
;
304 struct gallivm_state
*own_gallivm
;
307 struct pipe_sampler_view
*sampler_views
[PIPE_MAX_VERTEX_SAMPLERS
];
308 unsigned num_sampler_views
;
309 const struct pipe_sampler_state
*samplers
[PIPE_MAX_VERTEX_SAMPLERS
];
310 unsigned num_samplers
;
312 void *driver_private
;
316 struct draw_fetch_info
{
319 const unsigned *elts
;
323 struct draw_vertex_info
{
324 struct vertex_header
*verts
;
325 unsigned vertex_size
;
330 /* these flags are set if the primitive is a segment of a larger one */
331 #define DRAW_SPLIT_BEFORE 0x1
332 #define DRAW_SPLIT_AFTER 0x2
334 struct draw_prim_info
{
343 unsigned *primitive_lengths
;
344 unsigned primitive_count
;
348 /*******************************************************************************
349 * Draw common initialization code
351 boolean
draw_init(struct draw_context
*draw
);
353 /*******************************************************************************
354 * Vertex shader code:
356 boolean
draw_vs_init( struct draw_context
*draw
);
357 void draw_vs_destroy( struct draw_context
*draw
);
359 void draw_vs_set_viewport( struct draw_context
*,
360 const struct pipe_viewport_state
* );
363 draw_vs_set_constants(struct draw_context
*,
365 const void *constants
,
370 /*******************************************************************************
371 * Geometry shading code:
373 boolean
draw_gs_init( struct draw_context
*draw
);
376 draw_gs_set_constants(struct draw_context
*,
378 const void *constants
,
381 void draw_gs_destroy( struct draw_context
*draw
);
383 /*******************************************************************************
384 * Common shading code:
386 uint
draw_current_shader_outputs(const struct draw_context
*draw
);
387 uint
draw_current_shader_position_output(const struct draw_context
*draw
);
388 uint
draw_current_shader_clipvertex_output(const struct draw_context
*draw
);
389 uint
draw_current_shader_clipdistance_output(const struct draw_context
*draw
, int index
);
390 int draw_alloc_extra_vertex_attrib(struct draw_context
*draw
,
391 uint semantic_name
, uint semantic_index
);
392 void draw_remove_extra_vertex_attribs(struct draw_context
*draw
);
395 /*******************************************************************************
396 * Vertex processing (was passthrough) code:
398 boolean
draw_pt_init( struct draw_context
*draw
);
399 void draw_pt_destroy( struct draw_context
*draw
);
400 void draw_pt_reset_vertex_ids( struct draw_context
*draw
);
401 void draw_pt_flush( struct draw_context
*draw
, unsigned flags
);
404 /*******************************************************************************
405 * Primitive processing (pipeline) code:
408 boolean
draw_pipeline_init( struct draw_context
*draw
);
409 void draw_pipeline_destroy( struct draw_context
*draw
);
416 * These flags are used by the pipeline when unfilled and/or line stipple modes
419 #define DRAW_PIPE_EDGE_FLAG_0 0x1
420 #define DRAW_PIPE_EDGE_FLAG_1 0x2
421 #define DRAW_PIPE_EDGE_FLAG_2 0x4
422 #define DRAW_PIPE_EDGE_FLAG_ALL 0x7
423 #define DRAW_PIPE_RESET_STIPPLE 0x8
425 void draw_pipeline_run( struct draw_context
*draw
,
426 const struct draw_vertex_info
*vert
,
427 const struct draw_prim_info
*prim
);
429 void draw_pipeline_run_linear( struct draw_context
*draw
,
430 const struct draw_vertex_info
*vert
,
431 const struct draw_prim_info
*prim
);
436 void draw_pipeline_flush( struct draw_context
*draw
,
441 /*******************************************************************************
445 #define DRAW_FLUSH_STATE_CHANGE 0x8
446 #define DRAW_FLUSH_BACKEND 0x10
449 void draw_do_flush( struct draw_context
*draw
, unsigned flags
);
454 draw_get_rasterizer_no_cull( struct draw_context
*draw
,
459 #endif /* DRAW_PRIVATE_H */