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>
56 struct draw_vertex_shader
;
60 struct tgsi_exec_machine
;
66 * Carry some useful information around with the vertices in the prim pipe.
68 struct vertex_header
{
72 unsigned vertex_id
:16;
76 /* This will probably become float (*data)[4] soon:
81 /* NOTE: It should match vertex_id size above */
82 #define UNDEFINED_VERTEX_ID 0xffff
85 /* maximum number of shader variants we can cache */
86 #define DRAW_MAX_SHADER_VARIANTS 1024
89 * Private context for the drawing module.
93 struct pipe_context
*pipe
;
95 /** Drawing/primitive pipeline stages */
97 struct draw_stage
*first
; /**< one of the following */
99 struct draw_stage
*validate
;
101 /* stages (in logical order) */
102 struct draw_stage
*flatshade
;
103 struct draw_stage
*clip
;
104 struct draw_stage
*cull
;
105 struct draw_stage
*twoside
;
106 struct draw_stage
*offset
;
107 struct draw_stage
*unfilled
;
108 struct draw_stage
*stipple
;
109 struct draw_stage
*aapoint
;
110 struct draw_stage
*aaline
;
111 struct draw_stage
*pstipple
;
112 struct draw_stage
*wide_line
;
113 struct draw_stage
*wide_point
;
114 struct draw_stage
*rasterize
;
116 float wide_point_threshold
; /**< convert pnts to tris if larger than this */
117 float wide_line_threshold
; /**< convert lines to tris if wider than this */
118 boolean wide_point_sprites
; /**< convert points to tris for sprite mode */
119 boolean line_stipple
; /**< do line stipple? */
120 boolean point_sprite
; /**< convert points to quads for sprites? */
122 /* Temporary storage while the pipeline is being run:
125 unsigned vertex_stride
;
126 unsigned vertex_count
;
130 struct vbuf_render
*render
;
132 /* Support prototype passthrough path:
136 struct draw_pt_middle_end
*fetch_emit
;
137 struct draw_pt_middle_end
*fetch_shade_emit
;
138 struct draw_pt_middle_end
*general
;
139 struct draw_pt_middle_end
*llvm
;
143 struct draw_pt_front_end
*vsplit
;
146 struct pipe_vertex_buffer vertex_buffer
[PIPE_MAX_ATTRIBS
];
147 unsigned nr_vertex_buffers
;
150 * This is the largest legal index value for the current set of
151 * bound vertex buffers. Regardless of any other consideration,
152 * all vertex lookups need to be clamped to 0..max_index to
153 * prevent out-of-bound access.
157 struct pipe_vertex_element vertex_element
[PIPE_MAX_ATTRIBS
];
158 unsigned nr_vertex_elements
;
160 struct pipe_index_buffer index_buffer
;
162 /* user-space vertex data, buffers */
164 /** vertex element/index buffer (ex: glDrawElements) */
166 /** bytes per index (0, 1, 2 or 4) */
173 const void *vbuffer
[PIPE_MAX_ATTRIBS
];
175 /** constant buffers (for vertex/geometry shader) */
176 const void *vs_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
177 unsigned vs_constants_size
[PIPE_MAX_CONSTANT_BUFFERS
];
178 const void *gs_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
179 unsigned gs_constants_size
[PIPE_MAX_CONSTANT_BUFFERS
];
181 /* pointer to planes */
182 float (*planes
)[12][4];
185 boolean test_fse
; /* enable FSE even though its not correct (eg for softpipe) */
186 boolean no_fse
; /* disable FSE even when it is correct */
190 boolean bypass_clip_xy
;
191 boolean bypass_clip_z
;
194 boolean flushing
; /**< debugging/sanity */
195 boolean suspend_flushing
; /**< internally set */
197 /* Flags set if API requires clipping in these planes and the
198 * driver doesn't indicate that it can do it for us.
204 boolean force_passthrough
; /**< never clip or shade */
208 double mrd
; /**< minimum resolvable depth value, for polygon offset */
210 /** Current rasterizer state given to us by the driver */
211 const struct pipe_rasterizer_state
*rasterizer
;
212 /** Driver CSO handle for the current rasterizer state */
215 /** Rasterizer CSOs without culling/stipple/etc */
216 void *rasterizer_no_cull
[2][2];
218 struct pipe_viewport_state viewport
;
219 boolean identity_viewport
;
221 /** Vertex shader state */
223 struct draw_vertex_shader
*vertex_shader
;
224 uint num_vs_outputs
; /**< convenience, from vertex_shader */
225 uint position_output
;
226 uint edgeflag_output
;
228 /** TGSI program interpreter runtime state */
229 struct tgsi_exec_machine
*machine
;
232 struct tgsi_sampler
**samplers
;
234 /* Here's another one:
236 struct aos_machine
*aos_machine
;
239 const void *aligned_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
241 const void *aligned_constant_storage
[PIPE_MAX_CONSTANT_BUFFERS
];
242 unsigned const_storage_size
[PIPE_MAX_CONSTANT_BUFFERS
];
245 struct translate
*fetch
;
246 struct translate_cache
*fetch_cache
;
247 struct translate
*emit
;
248 struct translate_cache
*emit_cache
;
251 /** Geometry shader state */
253 struct draw_geometry_shader
*geometry_shader
;
254 uint num_gs_outputs
; /**< convenience, from geometry_shader */
255 uint position_output
;
257 /** TGSI program interpreter runtime state */
258 struct tgsi_exec_machine
*machine
;
261 struct tgsi_sampler
**samplers
;
264 /** Fragment shader state */
266 struct draw_fragment_shader
*fragment_shader
;
269 /** Stream output (vertex feedback) state */
271 struct pipe_stream_output_state state
;
272 void *buffers
[PIPE_MAX_SO_BUFFERS
];
276 /* Clip derived state:
282 /* If a prim stage introduces new vertex attributes, they'll be stored here
286 uint semantic_name
[10];
287 uint semantic_index
[10];
289 } extra_shader_outputs
;
291 unsigned reduced_prim
;
293 unsigned instance_id
;
296 struct draw_llvm
*llvm
;
297 struct gallivm_state
*own_gallivm
;
300 struct pipe_sampler_view
*sampler_views
[PIPE_MAX_VERTEX_SAMPLERS
];
301 unsigned num_sampler_views
;
302 const struct pipe_sampler_state
*samplers
[PIPE_MAX_VERTEX_SAMPLERS
];
303 unsigned num_samplers
;
305 void *driver_private
;
309 struct draw_fetch_info
{
312 const unsigned *elts
;
316 struct draw_vertex_info
{
317 struct vertex_header
*verts
;
318 unsigned vertex_size
;
323 /* these flags are set if the primitive is a segment of a larger one */
324 #define DRAW_SPLIT_BEFORE 0x1
325 #define DRAW_SPLIT_AFTER 0x2
327 struct draw_prim_info
{
336 unsigned *primitive_lengths
;
337 unsigned primitive_count
;
341 /*******************************************************************************
342 * Draw common initialization code
344 boolean
draw_init(struct draw_context
*draw
);
346 /*******************************************************************************
347 * Vertex shader code:
349 boolean
draw_vs_init( struct draw_context
*draw
);
350 void draw_vs_destroy( struct draw_context
*draw
);
352 void draw_vs_set_viewport( struct draw_context
*,
353 const struct pipe_viewport_state
* );
356 draw_vs_set_constants(struct draw_context
*,
358 const void *constants
,
363 /*******************************************************************************
364 * Geometry shading code:
366 boolean
draw_gs_init( struct draw_context
*draw
);
369 draw_gs_set_constants(struct draw_context
*,
371 const void *constants
,
374 void draw_gs_destroy( struct draw_context
*draw
);
376 /*******************************************************************************
377 * Common shading code:
379 uint
draw_current_shader_outputs(const struct draw_context
*draw
);
380 uint
draw_current_shader_position_output(const struct draw_context
*draw
);
382 int draw_alloc_extra_vertex_attrib(struct draw_context
*draw
,
383 uint semantic_name
, uint semantic_index
);
384 void draw_remove_extra_vertex_attribs(struct draw_context
*draw
);
387 /*******************************************************************************
388 * Vertex processing (was passthrough) code:
390 boolean
draw_pt_init( struct draw_context
*draw
);
391 void draw_pt_destroy( struct draw_context
*draw
);
392 void draw_pt_reset_vertex_ids( struct draw_context
*draw
);
395 /*******************************************************************************
396 * Primitive processing (pipeline) code:
399 boolean
draw_pipeline_init( struct draw_context
*draw
);
400 void draw_pipeline_destroy( struct draw_context
*draw
);
407 * These flags are used by the pipeline when unfilled and/or line stipple modes
410 #define DRAW_PIPE_EDGE_FLAG_0 0x1
411 #define DRAW_PIPE_EDGE_FLAG_1 0x2
412 #define DRAW_PIPE_EDGE_FLAG_2 0x4
413 #define DRAW_PIPE_EDGE_FLAG_ALL 0x7
414 #define DRAW_PIPE_RESET_STIPPLE 0x8
416 void draw_pipeline_run( struct draw_context
*draw
,
417 const struct draw_vertex_info
*vert
,
418 const struct draw_prim_info
*prim
);
420 void draw_pipeline_run_linear( struct draw_context
*draw
,
421 const struct draw_vertex_info
*vert
,
422 const struct draw_prim_info
*prim
);
427 void draw_pipeline_flush( struct draw_context
*draw
,
432 /*******************************************************************************
436 #define DRAW_FLUSH_STATE_CHANGE 0x8
437 #define DRAW_FLUSH_BACKEND 0x10
440 void draw_do_flush( struct draw_context
*draw
, unsigned flags
);
445 draw_get_rasterizer_no_cull( struct draw_context
*draw
,
450 #endif /* DRAW_PRIVATE_H */