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 struct draw_vertex_shader
;
59 struct tgsi_exec_machine
;
65 * Carry some useful information around with the vertices in the prim pipe.
67 struct vertex_header
{
71 unsigned vertex_id
:16;
75 /* This will probably become float (*data)[4] soon:
80 /* NOTE: It should match vertex_id size above */
81 #define UNDEFINED_VERTEX_ID 0xffff
85 * Private context for the drawing module.
89 struct pipe_context
*pipe
;
91 /** Drawing/primitive pipeline stages */
93 struct draw_stage
*first
; /**< one of the following */
95 struct draw_stage
*validate
;
97 /* stages (in logical order) */
98 struct draw_stage
*flatshade
;
99 struct draw_stage
*clip
;
100 struct draw_stage
*cull
;
101 struct draw_stage
*twoside
;
102 struct draw_stage
*offset
;
103 struct draw_stage
*unfilled
;
104 struct draw_stage
*stipple
;
105 struct draw_stage
*aapoint
;
106 struct draw_stage
*aaline
;
107 struct draw_stage
*pstipple
;
108 struct draw_stage
*wide_line
;
109 struct draw_stage
*wide_point
;
110 struct draw_stage
*rasterize
;
112 float wide_point_threshold
; /**< convert pnts to tris if larger than this */
113 float wide_line_threshold
; /**< convert lines to tris if wider than this */
114 boolean wide_point_sprites
; /**< convert points to tris for sprite mode */
115 boolean line_stipple
; /**< do line stipple? */
116 boolean point_sprite
; /**< convert points to quads for sprites? */
118 /* Temporary storage while the pipeline is being run:
121 unsigned vertex_stride
;
122 unsigned vertex_count
;
126 struct vbuf_render
*render
;
128 /* Support prototype passthrough path:
132 struct draw_pt_middle_end
*fetch_emit
;
133 struct draw_pt_middle_end
*fetch_shade_emit
;
134 struct draw_pt_middle_end
*general
;
138 struct draw_pt_front_end
*vcache
;
139 struct draw_pt_front_end
*varray
;
142 struct pipe_vertex_buffer vertex_buffer
[PIPE_MAX_ATTRIBS
];
143 unsigned nr_vertex_buffers
;
145 struct pipe_vertex_element vertex_element
[PIPE_MAX_ATTRIBS
];
146 unsigned nr_vertex_elements
;
148 /* user-space vertex data, buffers */
150 /** vertex element/index buffer (ex: glDrawElements) */
152 /** bytes per index (0, 1, 2 or 4) */
159 const void *vbuffer
[PIPE_MAX_ATTRIBS
];
161 /** constant buffer (for vertex/geometry shader) */
162 const void *vs_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
163 const void *gs_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
166 boolean test_fse
; /* enable FSE even though its not correct (eg for softpipe) */
167 boolean no_fse
; /* disable FSE even when it is correct */
171 boolean bypass_clipping
;
175 boolean flushing
; /**< debugging/sanity */
176 boolean suspend_flushing
; /**< internally set */
177 boolean bypass_clipping
; /**< set if either api or driver bypass_clipping true */
179 boolean force_passthrough
; /**< never clip or shade */
183 double mrd
; /**< minimum resolvable depth value, for polygon offset */
185 /** Current rasterizer state given to us by the driver */
186 const struct pipe_rasterizer_state
*rasterizer
;
187 /** Driver CSO handle for the current rasterizer state */
190 /** Rasterizer CSOs without culling/stipple/etc */
191 void *rasterizer_no_cull
[2][2];
193 struct pipe_viewport_state viewport
;
194 boolean identity_viewport
;
197 struct draw_vertex_shader
*vertex_shader
;
198 uint num_vs_outputs
; /**< convenience, from vertex_shader */
199 uint position_output
;
200 uint edgeflag_output
;
202 /** TGSI program interpreter runtime state */
203 struct tgsi_exec_machine
*machine
;
206 struct tgsi_sampler
**samplers
;
208 /* Here's another one:
210 struct aos_machine
*aos_machine
;
213 const void *aligned_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
215 const void *aligned_constant_storage
[PIPE_MAX_CONSTANT_BUFFERS
];
216 unsigned const_storage_size
[PIPE_MAX_CONSTANT_BUFFERS
];
219 struct translate
*fetch
;
220 struct translate_cache
*fetch_cache
;
221 struct translate
*emit
;
222 struct translate_cache
*emit_cache
;
226 struct draw_geometry_shader
*geometry_shader
;
227 uint num_gs_outputs
; /**< convenience, from geometry_shader */
228 uint position_output
;
230 /** TGSI program interpreter runtime state */
231 struct tgsi_exec_machine
*machine
;
234 struct tgsi_sampler
**samplers
;
237 /* Clip derived state:
242 /* If a prim stage introduces new vertex attributes, they'll be stored here
248 } extra_shader_outputs
;
250 unsigned reduced_prim
;
252 unsigned instance_id
;
255 LLVMExecutionEngineRef engine
;
258 void *driver_private
;
261 /*******************************************************************************
262 * Draw common initialization code
264 boolean
draw_init(struct draw_context
*draw
);
266 /*******************************************************************************
267 * Vertex shader code:
269 boolean
draw_vs_init( struct draw_context
*draw
);
270 void draw_vs_destroy( struct draw_context
*draw
);
272 void draw_vs_set_viewport( struct draw_context
*,
273 const struct pipe_viewport_state
* );
276 draw_vs_set_constants(struct draw_context
*,
278 const void *constants
,
283 /*******************************************************************************
284 * Geometry shading code:
286 boolean
draw_gs_init( struct draw_context
*draw
);
289 draw_gs_set_constants(struct draw_context
*,
291 const void *constants
,
294 void draw_gs_destroy( struct draw_context
*draw
);
296 /*******************************************************************************
297 * Common shading code:
299 uint
draw_current_shader_outputs(const struct draw_context
*draw
);
300 uint
draw_current_shader_position_output(const struct draw_context
*draw
);
302 /*******************************************************************************
303 * Vertex processing (was passthrough) code:
305 boolean
draw_pt_init( struct draw_context
*draw
);
306 void draw_pt_destroy( struct draw_context
*draw
);
307 void draw_pt_reset_vertex_ids( struct draw_context
*draw
);
310 /*******************************************************************************
311 * Primitive processing (pipeline) code:
314 boolean
draw_pipeline_init( struct draw_context
*draw
);
315 void draw_pipeline_destroy( struct draw_context
*draw
);
321 /* We use the top few bits in the elts[] parameter to convey a little
322 * API information. This limits the number of vertices we can address
323 * to only 4096 -- if that becomes a problem, we can switch to 32-bit
326 * These flags expected at first vertex of lines & triangles when
327 * unfilled and/or line stipple modes are operational.
329 #define DRAW_PIPE_MAX_VERTICES (0x1<<12)
330 #define DRAW_PIPE_EDGE_FLAG_0 (0x1<<12)
331 #define DRAW_PIPE_EDGE_FLAG_1 (0x2<<12)
332 #define DRAW_PIPE_EDGE_FLAG_2 (0x4<<12)
333 #define DRAW_PIPE_EDGE_FLAG_ALL (0x7<<12)
334 #define DRAW_PIPE_RESET_STIPPLE (0x8<<12)
335 #define DRAW_PIPE_FLAG_MASK (0xf<<12)
337 void draw_pipeline_run( struct draw_context
*draw
,
339 struct vertex_header
*vertices
,
340 unsigned vertex_count
,
345 void draw_pipeline_run_linear( struct draw_context
*draw
,
347 struct vertex_header
*vertices
,
353 void draw_pipeline_flush( struct draw_context
*draw
,
358 /*******************************************************************************
362 #define DRAW_FLUSH_STATE_CHANGE 0x8
363 #define DRAW_FLUSH_BACKEND 0x10
366 void draw_do_flush( struct draw_context
*draw
, unsigned flags
);
371 draw_get_rasterizer_no_cull( struct draw_context
*draw
,
376 #endif /* DRAW_PRIVATE_H */