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
*vcache
;
144 struct draw_pt_front_end
*varray
;
147 struct pipe_vertex_buffer vertex_buffer
[PIPE_MAX_ATTRIBS
];
148 unsigned nr_vertex_buffers
;
150 struct pipe_vertex_element vertex_element
[PIPE_MAX_ATTRIBS
];
151 unsigned nr_vertex_elements
;
153 /* user-space vertex data, buffers */
155 /** vertex element/index buffer (ex: glDrawElements) */
157 /** bytes per index (0, 1, 2 or 4) */
164 const void *vbuffer
[PIPE_MAX_ATTRIBS
];
166 /** constant buffer (for vertex/geometry shader) */
167 const void *vs_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
168 const void *gs_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
171 boolean test_fse
; /* enable FSE even though its not correct (eg for softpipe) */
172 boolean no_fse
; /* disable FSE even when it is correct */
176 boolean bypass_clipping
;
180 boolean flushing
; /**< debugging/sanity */
181 boolean suspend_flushing
; /**< internally set */
182 boolean bypass_clipping
; /**< set if either api or driver bypass_clipping true */
184 boolean force_passthrough
; /**< never clip or shade */
188 double mrd
; /**< minimum resolvable depth value, for polygon offset */
190 /** Current rasterizer state given to us by the driver */
191 const struct pipe_rasterizer_state
*rasterizer
;
192 /** Driver CSO handle for the current rasterizer state */
195 /** Rasterizer CSOs without culling/stipple/etc */
196 void *rasterizer_no_cull
[2][2];
198 struct pipe_viewport_state viewport
;
199 boolean identity_viewport
;
202 struct draw_vertex_shader
*vertex_shader
;
203 uint num_vs_outputs
; /**< convenience, from vertex_shader */
204 uint position_output
;
205 uint edgeflag_output
;
207 /** TGSI program interpreter runtime state */
208 struct tgsi_exec_machine
*machine
;
211 struct tgsi_sampler
**samplers
;
213 /* Here's another one:
215 struct aos_machine
*aos_machine
;
218 const void *aligned_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
220 const void *aligned_constant_storage
[PIPE_MAX_CONSTANT_BUFFERS
];
221 unsigned const_storage_size
[PIPE_MAX_CONSTANT_BUFFERS
];
224 struct translate
*fetch
;
225 struct translate_cache
*fetch_cache
;
226 struct translate
*emit
;
227 struct translate_cache
*emit_cache
;
231 struct draw_geometry_shader
*geometry_shader
;
232 uint num_gs_outputs
; /**< convenience, from geometry_shader */
233 uint position_output
;
235 /** TGSI program interpreter runtime state */
236 struct tgsi_exec_machine
*machine
;
239 struct tgsi_sampler
**samplers
;
243 struct pipe_stream_output_state state
;
244 void *buffers
[PIPE_MAX_SO_BUFFERS
];
248 /* Clip derived state:
254 /* If a prim stage introduces new vertex attributes, they'll be stored here
260 } extra_shader_outputs
;
262 unsigned reduced_prim
;
264 unsigned instance_id
;
267 struct draw_llvm
*llvm
;
268 LLVMExecutionEngineRef engine
;
271 struct pipe_sampler_view
*sampler_views
[PIPE_MAX_VERTEX_SAMPLERS
];
272 unsigned num_sampler_views
;
273 const struct pipe_sampler_state
*samplers
[PIPE_MAX_VERTEX_SAMPLERS
];
274 unsigned num_samplers
;
276 void *driver_private
;
280 struct draw_fetch_info
{
283 const unsigned *elts
;
287 struct draw_vertex_info
{
288 struct vertex_header
*verts
;
289 unsigned vertex_size
;
294 struct draw_prim_info
{
302 unsigned *primitive_lengths
;
303 unsigned primitive_count
;
307 /*******************************************************************************
308 * Draw common initialization code
310 boolean
draw_init(struct draw_context
*draw
);
312 /*******************************************************************************
313 * Vertex shader code:
315 boolean
draw_vs_init( struct draw_context
*draw
);
316 void draw_vs_destroy( struct draw_context
*draw
);
318 void draw_vs_set_viewport( struct draw_context
*,
319 const struct pipe_viewport_state
* );
322 draw_vs_set_constants(struct draw_context
*,
324 const void *constants
,
329 /*******************************************************************************
330 * Geometry shading code:
332 boolean
draw_gs_init( struct draw_context
*draw
);
335 draw_gs_set_constants(struct draw_context
*,
337 const void *constants
,
340 void draw_gs_destroy( struct draw_context
*draw
);
342 /*******************************************************************************
343 * Common shading code:
345 uint
draw_current_shader_outputs(const struct draw_context
*draw
);
346 uint
draw_current_shader_position_output(const struct draw_context
*draw
);
348 /*******************************************************************************
349 * Vertex processing (was passthrough) code:
351 boolean
draw_pt_init( struct draw_context
*draw
);
352 void draw_pt_destroy( struct draw_context
*draw
);
353 void draw_pt_reset_vertex_ids( struct draw_context
*draw
);
356 /*******************************************************************************
357 * Primitive processing (pipeline) code:
360 boolean
draw_pipeline_init( struct draw_context
*draw
);
361 void draw_pipeline_destroy( struct draw_context
*draw
);
367 /* We use the top few bits in the elts[] parameter to convey a little
368 * API information. This limits the number of vertices we can address
369 * to only 4096 -- if that becomes a problem, we can switch to 32-bit
372 * These flags expected at first vertex of lines & triangles when
373 * unfilled and/or line stipple modes are operational.
375 #define DRAW_PIPE_MAX_VERTICES (0x1<<12)
376 #define DRAW_PIPE_EDGE_FLAG_0 (0x1<<12)
377 #define DRAW_PIPE_EDGE_FLAG_1 (0x2<<12)
378 #define DRAW_PIPE_EDGE_FLAG_2 (0x4<<12)
379 #define DRAW_PIPE_EDGE_FLAG_ALL (0x7<<12)
380 #define DRAW_PIPE_RESET_STIPPLE (0x8<<12)
381 #define DRAW_PIPE_FLAG_MASK (0xf<<12)
383 void draw_pipeline_run( struct draw_context
*draw
,
384 const struct draw_vertex_info
*vert
,
385 const struct draw_prim_info
*prim
);
387 void draw_pipeline_run_linear( struct draw_context
*draw
,
388 const struct draw_vertex_info
*vert
,
389 const struct draw_prim_info
*prim
);
394 void draw_pipeline_flush( struct draw_context
*draw
,
399 /*******************************************************************************
403 #define DRAW_FLUSH_STATE_CHANGE 0x8
404 #define DRAW_FLUSH_BACKEND 0x10
407 void draw_do_flush( struct draw_context
*draw
, unsigned flags
);
412 draw_get_rasterizer_no_cull( struct draw_context
*draw
,
417 #endif /* DRAW_PRIVATE_H */