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
;
149 struct pipe_vertex_element vertex_element
[PIPE_MAX_ATTRIBS
];
150 unsigned nr_vertex_elements
;
152 /* user-space vertex data, buffers */
154 /** vertex element/index buffer (ex: glDrawElements) */
156 /** bytes per index (0, 1, 2 or 4) */
163 const void *vbuffer
[PIPE_MAX_ATTRIBS
];
165 /** constant buffers (for vertex/geometry shader) */
166 const void *vs_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
167 unsigned vs_constants_size
[PIPE_MAX_CONSTANT_BUFFERS
];
168 const void *gs_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
169 unsigned gs_constants_size
[PIPE_MAX_CONSTANT_BUFFERS
];
172 boolean test_fse
; /* enable FSE even though its not correct (eg for softpipe) */
173 boolean no_fse
; /* disable FSE even when it is correct */
177 boolean bypass_clipping
;
181 boolean flushing
; /**< debugging/sanity */
182 boolean suspend_flushing
; /**< internally set */
183 boolean bypass_clipping
; /**< set if either api or driver bypass_clipping true */
185 boolean force_passthrough
; /**< never clip or shade */
189 double mrd
; /**< minimum resolvable depth value, for polygon offset */
191 /** Current rasterizer state given to us by the driver */
192 const struct pipe_rasterizer_state
*rasterizer
;
193 /** Driver CSO handle for the current rasterizer state */
196 /** Rasterizer CSOs without culling/stipple/etc */
197 void *rasterizer_no_cull
[2][2];
199 struct pipe_viewport_state viewport
;
200 boolean identity_viewport
;
202 /** Vertex shader state */
204 struct draw_vertex_shader
*vertex_shader
;
205 uint num_vs_outputs
; /**< convenience, from vertex_shader */
206 uint position_output
;
207 uint edgeflag_output
;
209 /** TGSI program interpreter runtime state */
210 struct tgsi_exec_machine
*machine
;
213 struct tgsi_sampler
**samplers
;
215 /* Here's another one:
217 struct aos_machine
*aos_machine
;
220 const void *aligned_constants
[PIPE_MAX_CONSTANT_BUFFERS
];
222 const void *aligned_constant_storage
[PIPE_MAX_CONSTANT_BUFFERS
];
223 unsigned const_storage_size
[PIPE_MAX_CONSTANT_BUFFERS
];
226 struct translate
*fetch
;
227 struct translate_cache
*fetch_cache
;
228 struct translate
*emit
;
229 struct translate_cache
*emit_cache
;
232 /** Geometry shader state */
234 struct draw_geometry_shader
*geometry_shader
;
235 uint num_gs_outputs
; /**< convenience, from geometry_shader */
236 uint position_output
;
238 /** TGSI program interpreter runtime state */
239 struct tgsi_exec_machine
*machine
;
242 struct tgsi_sampler
**samplers
;
245 /** Stream output (vertex feedback) state */
247 struct pipe_stream_output_state state
;
248 void *buffers
[PIPE_MAX_SO_BUFFERS
];
252 /* Clip derived state:
258 /* If a prim stage introduces new vertex attributes, they'll be stored here
264 } extra_shader_outputs
;
266 unsigned reduced_prim
;
268 unsigned instance_id
;
271 struct draw_llvm
*llvm
;
272 LLVMExecutionEngineRef engine
;
275 struct pipe_sampler_view
*sampler_views
[PIPE_MAX_VERTEX_SAMPLERS
];
276 unsigned num_sampler_views
;
277 const struct pipe_sampler_state
*samplers
[PIPE_MAX_VERTEX_SAMPLERS
];
278 unsigned num_samplers
;
280 void *driver_private
;
284 struct draw_fetch_info
{
287 const unsigned *elts
;
291 struct draw_vertex_info
{
292 struct vertex_header
*verts
;
293 unsigned vertex_size
;
298 /* these flags are set if the primitive is a segment of a larger one */
299 #define DRAW_SPLIT_BEFORE 0x1
300 #define DRAW_SPLIT_AFTER 0x2
302 struct draw_prim_info
{
311 unsigned *primitive_lengths
;
312 unsigned primitive_count
;
316 /*******************************************************************************
317 * Draw common initialization code
319 boolean
draw_init(struct draw_context
*draw
);
321 /*******************************************************************************
322 * Vertex shader code:
324 boolean
draw_vs_init( struct draw_context
*draw
);
325 void draw_vs_destroy( struct draw_context
*draw
);
327 void draw_vs_set_viewport( struct draw_context
*,
328 const struct pipe_viewport_state
* );
331 draw_vs_set_constants(struct draw_context
*,
333 const void *constants
,
338 /*******************************************************************************
339 * Geometry shading code:
341 boolean
draw_gs_init( struct draw_context
*draw
);
344 draw_gs_set_constants(struct draw_context
*,
346 const void *constants
,
349 void draw_gs_destroy( struct draw_context
*draw
);
351 /*******************************************************************************
352 * Common shading code:
354 uint
draw_current_shader_outputs(const struct draw_context
*draw
);
355 uint
draw_current_shader_position_output(const struct draw_context
*draw
);
357 /*******************************************************************************
358 * Vertex processing (was passthrough) code:
360 boolean
draw_pt_init( struct draw_context
*draw
);
361 void draw_pt_destroy( struct draw_context
*draw
);
362 void draw_pt_reset_vertex_ids( struct draw_context
*draw
);
365 /*******************************************************************************
366 * Primitive processing (pipeline) code:
369 boolean
draw_pipeline_init( struct draw_context
*draw
);
370 void draw_pipeline_destroy( struct draw_context
*draw
);
376 /* We use the top few bits in the elts[] parameter to convey a little
377 * API information. This limits the number of vertices we can address
378 * to only 4096 -- if that becomes a problem, we can switch to 32-bit
381 * These flags expected at first vertex of lines & triangles when
382 * unfilled and/or line stipple modes are operational.
384 #define DRAW_PIPE_MAX_VERTICES (0x1<<12)
385 #define DRAW_PIPE_EDGE_FLAG_0 (0x1<<12)
386 #define DRAW_PIPE_EDGE_FLAG_1 (0x2<<12)
387 #define DRAW_PIPE_EDGE_FLAG_2 (0x4<<12)
388 #define DRAW_PIPE_EDGE_FLAG_ALL (0x7<<12)
389 #define DRAW_PIPE_RESET_STIPPLE (0x8<<12)
390 #define DRAW_PIPE_FLAG_MASK (0xf<<12)
392 void draw_pipeline_run( struct draw_context
*draw
,
393 const struct draw_vertex_info
*vert
,
394 const struct draw_prim_info
*prim
);
396 void draw_pipeline_run_linear( struct draw_context
*draw
,
397 const struct draw_vertex_info
*vert
,
398 const struct draw_prim_info
*prim
);
403 void draw_pipeline_flush( struct draw_context
*draw
,
408 /*******************************************************************************
412 #define DRAW_FLUSH_STATE_CHANGE 0x8
413 #define DRAW_FLUSH_BACKEND 0x10
416 void draw_do_flush( struct draw_context
*draw
, unsigned flags
);
421 draw_get_rasterizer_no_cull( struct draw_context
*draw
,
426 #endif /* DRAW_PRIVATE_H */