blob: e49041556bd5d1c386e5f78448b19e5f306aad30 [file] [log] [blame]
Keith Whitwell8e4a95a2007-05-24 10:41:34 +01001/**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
Brian279ffe32007-07-09 16:14:26 -060028/**
29 * Private data structures, etc for the draw module.
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010030 */
31
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010032
Brian279ffe32007-07-09 16:14:26 -060033/**
34 * Authors:
35 * Keith Whitwell <keith@tungstengraphics.com>
36 * Brian Paul
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010037 */
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010038
Brian279ffe32007-07-09 16:14:26 -060039
40#ifndef DRAW_PRIVATE_H
41#define DRAW_PRIVATE_H
42
43
Brian279ffe32007-07-09 16:14:26 -060044#include "pipe/p_state.h"
45#include "pipe/p_defines.h"
Brian766fa512007-08-20 17:02:07 -060046
José Fonsecac208a2c2008-07-28 12:42:13 +090047#include "tgsi/tgsi_scan.h"
Brian0d13ade2007-10-02 11:46:11 -060048
Brian279ffe32007-07-09 16:14:26 -060049
Brianaceeb802008-02-18 16:19:05 -070050struct pipe_context;
Zack Rusin25b17b22007-10-29 08:27:32 -040051struct gallivm_prog;
52struct gallivm_cpu_engine;
Keith Whitwell280bcff2008-04-17 14:20:00 +010053struct draw_vertex_shader;
Keith Whitwell507fbe22008-04-19 15:29:27 +010054struct draw_context;
55struct draw_stage;
56struct vbuf_render;
Keith Whitwellc202fe12009-07-16 00:21:17 +010057struct tgsi_exec_machine;
58struct tgsi_sampler;
Keith Whitwellf40357e2008-03-23 16:44:59 +000059
Zack Rusinaadbb1d2008-04-12 15:45:28 -040060
Brian279ffe32007-07-09 16:14:26 -060061/**
62 * Basic vertex info.
63 * Carry some useful information around with the vertices in the prim pipe.
64 */
65struct vertex_header {
Brianfd0a6d62007-08-16 12:52:20 -060066 unsigned clipmask:12;
67 unsigned edgeflag:1;
Keith Whitwella37e0da2007-09-25 13:20:53 +010068 unsigned pad:3;
69 unsigned vertex_id:16;
Brian279ffe32007-07-09 16:14:26 -060070
Brianfd0a6d62007-08-16 12:52:20 -060071 float clip[4];
Brian279ffe32007-07-09 16:14:26 -060072
Keith Whitwell507fbe22008-04-19 15:29:27 +010073 /* This will probably become float (*data)[4] soon:
74 */
75 float data[][4];
Brian279ffe32007-07-09 16:14:26 -060076};
77
José Fonsecac28fdf32007-11-07 12:08:19 +000078/* NOTE: It should match vertex_id size above */
79#define UNDEFINED_VERTEX_ID 0xffff
80
Brian279ffe32007-07-09 16:14:26 -060081
82/**
Brian279ffe32007-07-09 16:14:26 -060083 * Private context for the drawing module.
84 */
85struct draw_context
86{
Brianfd0a6d62007-08-16 12:52:20 -060087 /** Drawing/primitive pipeline stages */
Brian279ffe32007-07-09 16:14:26 -060088 struct {
Brianea470ee2007-07-12 13:32:31 -060089 struct draw_stage *first; /**< one of the following */
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010090
Keith Whitwell08589f72007-09-26 11:56:17 +010091 struct draw_stage *validate;
92
Brian279ffe32007-07-09 16:14:26 -060093 /* stages (in logical order) */
Brianea470ee2007-07-12 13:32:31 -060094 struct draw_stage *flatshade;
95 struct draw_stage *clip;
96 struct draw_stage *cull;
97 struct draw_stage *twoside;
98 struct draw_stage *offset;
99 struct draw_stage *unfilled;
Brian329a8472008-01-21 14:08:20 -0700100 struct draw_stage *stipple;
Brianeb4dc2d2008-02-21 16:18:05 -0700101 struct draw_stage *aapoint;
Brianaceeb802008-02-18 16:19:05 -0700102 struct draw_stage *aaline;
Brian446bfc32008-02-21 16:56:32 -0700103 struct draw_stage *pstipple;
Brian Paula1a13952008-02-28 17:49:22 -0700104 struct draw_stage *wide_line;
105 struct draw_stage *wide_point;
Zack Rusinde69fc12007-09-18 10:02:16 -0400106 struct draw_stage *rasterize;
Keith Whitwell507fbe22008-04-19 15:29:27 +0100107
108 float wide_point_threshold; /**< convert pnts to tris if larger than this */
109 float wide_line_threshold; /**< convert lines to tris if wider than this */
110 boolean line_stipple; /**< do line stipple? */
111 boolean point_sprite; /**< convert points to quads for sprites? */
112
Keith Whitwellbee1d312008-04-19 16:39:24 +0100113 /* Temporary storage while the pipeline is being run:
114 */
115 char *verts;
116 unsigned vertex_stride;
117 unsigned vertex_count;
Brian279ffe32007-07-09 16:14:26 -0600118 } pipeline;
119
Keith Whitwell297b3be2008-03-10 19:49:15 +0000120
121 struct vbuf_render *render;
122
123 /* Support prototype passthrough path:
124 */
125 struct {
Keith Whitwellf40357e2008-03-23 16:44:59 +0000126 struct {
Keith Whitwell1246d062008-04-19 13:20:26 +0100127 struct draw_pt_middle_end *fetch_emit;
Keith Whitwellbbda45e2008-05-12 19:40:20 +0100128 struct draw_pt_middle_end *fetch_shade_emit;
Keith Whitwell1246d062008-04-19 13:20:26 +0100129 struct draw_pt_middle_end *general;
Keith Whitwellf40357e2008-03-23 16:44:59 +0000130 } middle;
131
132 struct {
Keith Whitwellf40357e2008-03-23 16:44:59 +0000133 struct draw_pt_front_end *vcache;
Zack Rusin992d0b92008-04-24 16:22:47 -0400134 struct draw_pt_front_end *varray;
Keith Whitwellf40357e2008-03-23 16:44:59 +0000135 } front;
Keith Whitwell7d726072008-04-19 17:27:52 +0100136
137 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
138 unsigned nr_vertex_buffers;
139
140 struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS];
141 unsigned nr_vertex_elements;
142
143 /* user-space vertex data, buffers */
144 struct {
Keith Whitwell7d726072008-04-19 17:27:52 +0100145 /** vertex element/index buffer (ex: glDrawElements) */
146 const void *elts;
147 /** bytes per index (0, 1, 2 or 4) */
148 unsigned eltSize;
Keith Whitwell82605d72008-05-29 11:46:43 +0100149 unsigned min_index;
150 unsigned max_index;
Keith Whitwell7d726072008-04-19 17:27:52 +0100151
152 /** vertex arrays */
153 const void *vbuffer[PIPE_MAX_ATTRIBS];
154
Zack Rusin89d85772009-12-14 17:11:46 -0500155 /** constant buffer (for vertex/geometry shader) */
156 const void *vs_constants;
157 const void *gs_constants;
Keith Whitwell7d726072008-04-19 17:27:52 +0100158 } user;
159
Keith Whitwell807e7c42008-05-29 14:35:30 +0100160 boolean test_fse; /* enable FSE even though its not correct (eg for softpipe) */
161 boolean no_fse; /* disable FSE even when it is correct */
Keith Whitwell297b3be2008-03-10 19:49:15 +0000162 } pt;
163
Keith Whitwell05888582008-04-22 20:50:20 +0100164 struct {
165 boolean bypass_clipping;
Keith Whitwellc48da7d2008-10-06 12:22:55 +0100166 boolean bypass_vs;
Keith Whitwell05888582008-04-22 20:50:20 +0100167 } driver;
168
Brian Paul14d1ca82008-04-23 18:08:20 -0600169 boolean flushing; /**< debugging/sanity */
170 boolean suspend_flushing; /**< internally set */
171 boolean bypass_clipping; /**< set if either api or driver bypass_clipping true */
Keith Whitwell297b3be2008-03-10 19:49:15 +0000172
Keith Whitwellc48da7d2008-10-06 12:22:55 +0100173 boolean force_passthrough; /**< never clip or shade */
174
Brian Pauld0bc5292008-12-10 18:02:27 -0700175 double mrd; /**< minimum resolvable depth value, for polygon offset */
176
Brian279ffe32007-07-09 16:14:26 -0600177 /* pipe state that we need: */
Zack Rusin29440182007-09-17 12:59:50 -0400178 const struct pipe_rasterizer_state *rasterizer;
Brian279ffe32007-07-09 16:14:26 -0600179 struct pipe_viewport_state viewport;
Brian594dab42008-03-31 14:14:30 -0600180 boolean identity_viewport;
181
Keith Whitwell2f0d1392008-05-13 13:40:22 +0100182 struct {
183 struct draw_vertex_shader *vertex_shader;
184 uint num_vs_outputs; /**< convenience, from vertex_shader */
Keith Whitwell2161b0f2008-06-11 23:48:13 +0100185 uint position_output;
Roland Scheideggera0127b62009-12-14 18:36:33 +0100186 uint edgeflag_output;
Brian63a51ae2007-09-06 17:07:09 -0600187
Keith Whitwell2f0d1392008-05-13 13:40:22 +0100188 /** TGSI program interpreter runtime state */
Keith Whitwell61756532009-07-15 23:44:53 +0100189 struct tgsi_exec_machine *machine;
Keith Whitwell2f0d1392008-05-13 13:40:22 +0100190
Brianf2bccfd2008-12-02 22:38:46 -0700191 uint num_samplers;
192 struct tgsi_sampler **samplers;
193
Keith Whitwell2f0d1392008-05-13 13:40:22 +0100194 /* This (and the tgsi_exec_machine struct) probably need to be moved somewhere private.
195 */
196 struct gallivm_cpu_engine *engine;
197
Keith Whitwell62628c42008-05-29 00:17:53 +0100198 /* Here's another one:
199 */
200 struct aos_machine *aos_machine;
201
Keith Whitwell2f0d1392008-05-13 13:40:22 +0100202
Keith Whitwellbb2e13b2008-05-29 12:38:49 +0100203 const float (*aligned_constants)[4];
204
Alan Hourihaneca522492008-10-10 01:31:34 +0100205 const float (*aligned_constant_storage)[4];
Keith Whitwellbb2e13b2008-05-29 12:38:49 +0100206 unsigned const_storage_size;
207
208
Keith Whitwell7c99d7f2008-05-15 12:39:08 +0100209 struct translate *fetch;
Keith Whitwell2f0d1392008-05-13 13:40:22 +0100210 struct translate_cache *fetch_cache;
Keith Whitwell7c99d7f2008-05-15 12:39:08 +0100211 struct translate *emit;
Keith Whitwell2f0d1392008-05-13 13:40:22 +0100212 struct translate_cache *emit_cache;
213 } vs;
214
Zack Rusin89d85772009-12-14 17:11:46 -0500215 struct {
216 struct draw_geometry_shader *geometry_shader;
217 uint num_gs_outputs; /**< convenience, from geometry_shader */
218 uint position_output;
219
220 /** TGSI program interpreter runtime state */
221 struct tgsi_exec_machine *machine;
222
223 uint num_samplers;
224 struct tgsi_sampler **samplers;
225 } gs;
226
Brian279ffe32007-07-09 16:14:26 -0600227 /* Clip derived state:
228 */
Brianfd0a6d62007-08-16 12:52:20 -0600229 float plane[12][4];
230 unsigned nr_planes;
Brian279ffe32007-07-09 16:14:26 -0600231
Brianaceeb802008-02-18 16:19:05 -0700232 /* If a prim stage introduces new vertex attributes, they'll be stored here
233 */
234 struct {
235 uint semantic_name;
236 uint semantic_index;
237 int slot;
Zack Rusin89d85772009-12-14 17:11:46 -0500238 } extra_shader_outputs;
Brianaceeb802008-02-18 16:19:05 -0700239
Brianfd0a6d62007-08-16 12:52:20 -0600240 unsigned reduced_prim;
241
Ian Romanicka89ee8a2008-01-30 20:10:45 -0800242 void *driver_private;
Brian279ffe32007-07-09 16:14:26 -0600243};
244
245
Keith Whitwell2f0d1392008-05-13 13:40:22 +0100246/*******************************************************************************
247 * Vertex shader code:
248 */
249boolean draw_vs_init( struct draw_context *draw );
250void draw_vs_destroy( struct draw_context *draw );
Brian279ffe32007-07-09 16:14:26 -0600251
Keith Whitwell62628c42008-05-29 00:17:53 +0100252void draw_vs_set_viewport( struct draw_context *,
253 const struct pipe_viewport_state * );
254
255void draw_vs_set_constants( struct draw_context *,
Keith Whitwellbb2e13b2008-05-29 12:38:49 +0100256 const float (*constants)[4],
257 unsigned size );
Brian279ffe32007-07-09 16:14:26 -0600258
José Fonseca3e221802007-11-07 13:07:20 +0000259
Brian279ffe32007-07-09 16:14:26 -0600260
Zack Rusin89d85772009-12-14 17:11:46 -0500261/*******************************************************************************
262 * Geometry shading code:
263 */
264boolean draw_gs_init( struct draw_context *draw );
265void draw_gs_set_constants( struct draw_context *,
266 const float (*constants)[4],
267 unsigned size );
268
269/*******************************************************************************
270 * Common shading code:
271 */
272int draw_current_shader_outputs(struct draw_context *draw);
273int draw_current_shader_position_output(struct draw_context *draw);
Brian9a11a4a2007-08-31 11:28:31 -0600274
Keith Whitwell507fbe22008-04-19 15:29:27 +0100275/*******************************************************************************
276 * Vertex processing (was passthrough) code:
Keith Whitwellf40357e2008-03-23 16:44:59 +0000277 */
278boolean draw_pt_init( struct draw_context *draw );
279void draw_pt_destroy( struct draw_context *draw );
Keith Whitwell0b20d1b2008-04-04 13:18:09 +0100280void draw_pt_reset_vertex_ids( struct draw_context *draw );
Keith Whitwellf40357e2008-03-23 16:44:59 +0000281
Keith Whitwell507fbe22008-04-19 15:29:27 +0100282
283/*******************************************************************************
Keith Whitwelle7bac422008-04-19 16:43:15 +0100284 * Primitive processing (pipeline) code:
Keith Whitwell507fbe22008-04-19 15:29:27 +0100285 */
286
287boolean draw_pipeline_init( struct draw_context *draw );
288void draw_pipeline_destroy( struct draw_context *draw );
289
Keith Whitwellf93332d2008-04-24 12:38:15 +0100290
291
292
293
294/* We use the top few bits in the elts[] parameter to convey a little
295 * API information. This limits the number of vertices we can address
296 * to only 4096 -- if that becomes a problem, we can switch to 32-bit
297 * draw indices.
298 *
299 * These flags expected at first vertex of lines & triangles when
300 * unfilled and/or line stipple modes are operational.
301 */
Keith Whitwell0a4aea02008-06-02 12:59:16 +0100302#define DRAW_PIPE_MAX_VERTICES (0x1<<12)
Keith Whitwellf93332d2008-04-24 12:38:15 +0100303#define DRAW_PIPE_EDGE_FLAG_0 (0x1<<12)
304#define DRAW_PIPE_EDGE_FLAG_1 (0x2<<12)
305#define DRAW_PIPE_EDGE_FLAG_2 (0x4<<12)
306#define DRAW_PIPE_EDGE_FLAG_ALL (0x7<<12)
307#define DRAW_PIPE_RESET_STIPPLE (0x8<<12)
308#define DRAW_PIPE_FLAG_MASK (0xf<<12)
309
Keith Whitwellbee1d312008-04-19 16:39:24 +0100310void draw_pipeline_run( struct draw_context *draw,
311 unsigned prim,
312 struct vertex_header *vertices,
313 unsigned vertex_count,
314 unsigned stride,
315 const ushort *elts,
316 unsigned count );
317
Zack Rusinfe586f82008-05-06 18:59:45 -0400318void draw_pipeline_run_linear( struct draw_context *draw,
319 unsigned prim,
320 struct vertex_header *vertices,
321 unsigned count,
322 unsigned stride );
323
Keith Whitwellf93332d2008-04-24 12:38:15 +0100324
325
Keith Whitwelle7bac422008-04-19 16:43:15 +0100326void draw_pipeline_flush( struct draw_context *draw,
327 unsigned flags );
328
Keith Whitwell507fbe22008-04-19 15:29:27 +0100329
330
Keith Whitwellbee1d312008-04-19 16:39:24 +0100331/*******************************************************************************
332 * Flushing
333 */
334
Brian1603a332008-01-25 17:21:05 -0700335#define DRAW_FLUSH_STATE_CHANGE 0x8
336#define DRAW_FLUSH_BACKEND 0x10
Keith Whitwell08589f72007-09-26 11:56:17 +0100337
338
Brian1603a332008-01-25 17:21:05 -0700339void draw_do_flush( struct draw_context *draw, unsigned flags );
Keith Whitwell08589f72007-09-26 11:56:17 +0100340
Keith Whitwell08589f72007-09-26 11:56:17 +0100341
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100342
Zack Rusin3f7a3dd2008-04-12 21:52:46 -0400343
Brian279ffe32007-07-09 16:14:26 -0600344#endif /* DRAW_PRIVATE_H */