blob: 1e6e01af9e281cd0f20333f8c2543d71dd139fd8 [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;
Keith Whitwell280bcff2008-04-17 14:20:00 +010051struct draw_vertex_shader;
Keith Whitwell507fbe22008-04-19 15:29:27 +010052struct draw_context;
53struct draw_stage;
54struct vbuf_render;
Keith Whitwellc202fe12009-07-16 00:21:17 +010055struct tgsi_exec_machine;
56struct tgsi_sampler;
Keith Whitwellf40357e2008-03-23 16:44:59 +000057
Zack Rusinaadbb1d2008-04-12 15:45:28 -040058
Brian279ffe32007-07-09 16:14:26 -060059/**
60 * Basic vertex info.
61 * Carry some useful information around with the vertices in the prim pipe.
62 */
63struct vertex_header {
Brianfd0a6d62007-08-16 12:52:20 -060064 unsigned clipmask:12;
65 unsigned edgeflag:1;
Keith Whitwella37e0da2007-09-25 13:20:53 +010066 unsigned pad:3;
67 unsigned vertex_id:16;
Brian279ffe32007-07-09 16:14:26 -060068
Brianfd0a6d62007-08-16 12:52:20 -060069 float clip[4];
Brian279ffe32007-07-09 16:14:26 -060070
Keith Whitwell507fbe22008-04-19 15:29:27 +010071 /* This will probably become float (*data)[4] soon:
72 */
73 float data[][4];
Brian279ffe32007-07-09 16:14:26 -060074};
75
José Fonsecac28fdf32007-11-07 12:08:19 +000076/* NOTE: It should match vertex_id size above */
77#define UNDEFINED_VERTEX_ID 0xffff
78
Brian279ffe32007-07-09 16:14:26 -060079
80/**
Brian279ffe32007-07-09 16:14:26 -060081 * Private context for the drawing module.
82 */
83struct draw_context
84{
Brianfd0a6d62007-08-16 12:52:20 -060085 /** Drawing/primitive pipeline stages */
Brian279ffe32007-07-09 16:14:26 -060086 struct {
Brianea470ee2007-07-12 13:32:31 -060087 struct draw_stage *first; /**< one of the following */
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010088
Keith Whitwell08589f72007-09-26 11:56:17 +010089 struct draw_stage *validate;
90
Brian279ffe32007-07-09 16:14:26 -060091 /* stages (in logical order) */
Brianea470ee2007-07-12 13:32:31 -060092 struct draw_stage *flatshade;
93 struct draw_stage *clip;
94 struct draw_stage *cull;
95 struct draw_stage *twoside;
96 struct draw_stage *offset;
97 struct draw_stage *unfilled;
Brian329a8472008-01-21 14:08:20 -070098 struct draw_stage *stipple;
Brianeb4dc2d2008-02-21 16:18:05 -070099 struct draw_stage *aapoint;
Brianaceeb802008-02-18 16:19:05 -0700100 struct draw_stage *aaline;
Brian446bfc32008-02-21 16:56:32 -0700101 struct draw_stage *pstipple;
Brian Paula1a13952008-02-28 17:49:22 -0700102 struct draw_stage *wide_line;
103 struct draw_stage *wide_point;
Zack Rusinde69fc12007-09-18 10:02:16 -0400104 struct draw_stage *rasterize;
Keith Whitwell507fbe22008-04-19 15:29:27 +0100105
106 float wide_point_threshold; /**< convert pnts to tris if larger than this */
107 float wide_line_threshold; /**< convert lines to tris if wider than this */
108 boolean line_stipple; /**< do line stipple? */
109 boolean point_sprite; /**< convert points to quads for sprites? */
110
Keith Whitwellbee1d312008-04-19 16:39:24 +0100111 /* Temporary storage while the pipeline is being run:
112 */
113 char *verts;
114 unsigned vertex_stride;
115 unsigned vertex_count;
Brian279ffe32007-07-09 16:14:26 -0600116 } pipeline;
117
Keith Whitwell297b3be2008-03-10 19:49:15 +0000118
119 struct vbuf_render *render;
120
121 /* Support prototype passthrough path:
122 */
123 struct {
Keith Whitwellf40357e2008-03-23 16:44:59 +0000124 struct {
Keith Whitwell1246d062008-04-19 13:20:26 +0100125 struct draw_pt_middle_end *fetch_emit;
Keith Whitwellbbda45e2008-05-12 19:40:20 +0100126 struct draw_pt_middle_end *fetch_shade_emit;
Keith Whitwell1246d062008-04-19 13:20:26 +0100127 struct draw_pt_middle_end *general;
Keith Whitwellf40357e2008-03-23 16:44:59 +0000128 } middle;
129
130 struct {
Keith Whitwellf40357e2008-03-23 16:44:59 +0000131 struct draw_pt_front_end *vcache;
Zack Rusin992d0b92008-04-24 16:22:47 -0400132 struct draw_pt_front_end *varray;
Keith Whitwellf40357e2008-03-23 16:44:59 +0000133 } front;
Keith Whitwell7d726072008-04-19 17:27:52 +0100134
135 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
136 unsigned nr_vertex_buffers;
137
138 struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS];
139 unsigned nr_vertex_elements;
140
141 /* user-space vertex data, buffers */
142 struct {
Keith Whitwell7d726072008-04-19 17:27:52 +0100143 /** vertex element/index buffer (ex: glDrawElements) */
144 const void *elts;
145 /** bytes per index (0, 1, 2 or 4) */
146 unsigned eltSize;
Keith Whitwell82605d72008-05-29 11:46:43 +0100147 unsigned min_index;
148 unsigned max_index;
Keith Whitwell7d726072008-04-19 17:27:52 +0100149
150 /** vertex arrays */
151 const void *vbuffer[PIPE_MAX_ATTRIBS];
152
Zack Rusin89d85772009-12-14 17:11:46 -0500153 /** constant buffer (for vertex/geometry shader) */
Michal Krol7c5f2552010-01-25 13:29:33 +0100154 const void *vs_constants[PIPE_MAX_CONSTANT_BUFFERS];
155 const void *gs_constants[PIPE_MAX_CONSTANT_BUFFERS];
Keith Whitwell7d726072008-04-19 17:27:52 +0100156 } user;
157
Keith Whitwell807e7c42008-05-29 14:35:30 +0100158 boolean test_fse; /* enable FSE even though its not correct (eg for softpipe) */
159 boolean no_fse; /* disable FSE even when it is correct */
Keith Whitwell297b3be2008-03-10 19:49:15 +0000160 } pt;
161
Keith Whitwell05888582008-04-22 20:50:20 +0100162 struct {
163 boolean bypass_clipping;
Keith Whitwellc48da7d2008-10-06 12:22:55 +0100164 boolean bypass_vs;
Keith Whitwell05888582008-04-22 20:50:20 +0100165 } driver;
166
Brian Paul14d1ca82008-04-23 18:08:20 -0600167 boolean flushing; /**< debugging/sanity */
168 boolean suspend_flushing; /**< internally set */
169 boolean bypass_clipping; /**< set if either api or driver bypass_clipping true */
Keith Whitwell297b3be2008-03-10 19:49:15 +0000170
Keith Whitwellc48da7d2008-10-06 12:22:55 +0100171 boolean force_passthrough; /**< never clip or shade */
172
Luca Barbierif7748d72010-01-15 07:28:18 +0100173 boolean dump_vs;
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 Whitwell62628c42008-05-29 00:17:53 +0100194 /* Here's another one:
195 */
196 struct aos_machine *aos_machine;
197
Keith Whitwell2f0d1392008-05-13 13:40:22 +0100198
Michal Krol7c5f2552010-01-25 13:29:33 +0100199 const void *aligned_constants[PIPE_MAX_CONSTANT_BUFFERS];
Keith Whitwellbb2e13b2008-05-29 12:38:49 +0100200
Michal Krol7c5f2552010-01-25 13:29:33 +0100201 const void *aligned_constant_storage[PIPE_MAX_CONSTANT_BUFFERS];
202 unsigned const_storage_size[PIPE_MAX_CONSTANT_BUFFERS];
Keith Whitwellbb2e13b2008-05-29 12:38:49 +0100203
204
Keith Whitwell7c99d7f2008-05-15 12:39:08 +0100205 struct translate *fetch;
Keith Whitwell2f0d1392008-05-13 13:40:22 +0100206 struct translate_cache *fetch_cache;
Keith Whitwell7c99d7f2008-05-15 12:39:08 +0100207 struct translate *emit;
Keith Whitwell2f0d1392008-05-13 13:40:22 +0100208 struct translate_cache *emit_cache;
209 } vs;
210
Zack Rusin89d85772009-12-14 17:11:46 -0500211 struct {
212 struct draw_geometry_shader *geometry_shader;
213 uint num_gs_outputs; /**< convenience, from geometry_shader */
214 uint position_output;
215
216 /** TGSI program interpreter runtime state */
217 struct tgsi_exec_machine *machine;
218
219 uint num_samplers;
220 struct tgsi_sampler **samplers;
221 } gs;
222
Brian279ffe32007-07-09 16:14:26 -0600223 /* Clip derived state:
224 */
Brianfd0a6d62007-08-16 12:52:20 -0600225 float plane[12][4];
226 unsigned nr_planes;
Brian279ffe32007-07-09 16:14:26 -0600227
Brianaceeb802008-02-18 16:19:05 -0700228 /* If a prim stage introduces new vertex attributes, they'll be stored here
229 */
230 struct {
231 uint semantic_name;
232 uint semantic_index;
233 int slot;
Zack Rusin89d85772009-12-14 17:11:46 -0500234 } extra_shader_outputs;
Brianaceeb802008-02-18 16:19:05 -0700235
Brianfd0a6d62007-08-16 12:52:20 -0600236 unsigned reduced_prim;
237
Michal Krol7ca0ce32009-12-29 23:21:01 +0100238 unsigned instance_id;
239
Ian Romanicka89ee8a2008-01-30 20:10:45 -0800240 void *driver_private;
Brian279ffe32007-07-09 16:14:26 -0600241};
242
243
Keith Whitwell2f0d1392008-05-13 13:40:22 +0100244/*******************************************************************************
245 * Vertex shader code:
246 */
247boolean draw_vs_init( struct draw_context *draw );
248void draw_vs_destroy( struct draw_context *draw );
Brian279ffe32007-07-09 16:14:26 -0600249
Keith Whitwell62628c42008-05-29 00:17:53 +0100250void draw_vs_set_viewport( struct draw_context *,
251 const struct pipe_viewport_state * );
252
Michal Krol98516442010-01-25 12:36:50 +0100253void
254draw_vs_set_constants(struct draw_context *,
255 unsigned slot,
256 const void *constants,
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 );
Michal Krol98516442010-01-25 12:36:50 +0100265
266void
267draw_gs_set_constants(struct draw_context *,
268 unsigned slot,
269 const void *constants,
270 unsigned size);
271
Jakob Bornecrantza5c03bd2010-01-16 09:30:28 +0000272void draw_gs_destroy( struct draw_context *draw );
Zack Rusin89d85772009-12-14 17:11:46 -0500273
274/*******************************************************************************
275 * Common shading code:
276 */
Brian Paul256f7f52010-02-02 18:54:12 -0700277uint draw_current_shader_outputs(const struct draw_context *draw);
278uint draw_current_shader_position_output(const struct draw_context *draw);
Brian9a11a4a2007-08-31 11:28:31 -0600279
Keith Whitwell507fbe22008-04-19 15:29:27 +0100280/*******************************************************************************
281 * Vertex processing (was passthrough) code:
Keith Whitwellf40357e2008-03-23 16:44:59 +0000282 */
283boolean draw_pt_init( struct draw_context *draw );
284void draw_pt_destroy( struct draw_context *draw );
Keith Whitwell0b20d1b2008-04-04 13:18:09 +0100285void draw_pt_reset_vertex_ids( struct draw_context *draw );
Keith Whitwellf40357e2008-03-23 16:44:59 +0000286
Keith Whitwell507fbe22008-04-19 15:29:27 +0100287
288/*******************************************************************************
Keith Whitwelle7bac422008-04-19 16:43:15 +0100289 * Primitive processing (pipeline) code:
Keith Whitwell507fbe22008-04-19 15:29:27 +0100290 */
291
292boolean draw_pipeline_init( struct draw_context *draw );
293void draw_pipeline_destroy( struct draw_context *draw );
294
Keith Whitwellf93332d2008-04-24 12:38:15 +0100295
296
297
298
299/* We use the top few bits in the elts[] parameter to convey a little
300 * API information. This limits the number of vertices we can address
301 * to only 4096 -- if that becomes a problem, we can switch to 32-bit
302 * draw indices.
303 *
304 * These flags expected at first vertex of lines & triangles when
305 * unfilled and/or line stipple modes are operational.
306 */
Keith Whitwell0a4aea02008-06-02 12:59:16 +0100307#define DRAW_PIPE_MAX_VERTICES (0x1<<12)
Keith Whitwellf93332d2008-04-24 12:38:15 +0100308#define DRAW_PIPE_EDGE_FLAG_0 (0x1<<12)
309#define DRAW_PIPE_EDGE_FLAG_1 (0x2<<12)
310#define DRAW_PIPE_EDGE_FLAG_2 (0x4<<12)
311#define DRAW_PIPE_EDGE_FLAG_ALL (0x7<<12)
312#define DRAW_PIPE_RESET_STIPPLE (0x8<<12)
313#define DRAW_PIPE_FLAG_MASK (0xf<<12)
314
Keith Whitwellbee1d312008-04-19 16:39:24 +0100315void draw_pipeline_run( struct draw_context *draw,
316 unsigned prim,
317 struct vertex_header *vertices,
318 unsigned vertex_count,
319 unsigned stride,
320 const ushort *elts,
321 unsigned count );
322
Zack Rusinfe586f82008-05-06 18:59:45 -0400323void draw_pipeline_run_linear( struct draw_context *draw,
324 unsigned prim,
325 struct vertex_header *vertices,
326 unsigned count,
327 unsigned stride );
328
Keith Whitwellf93332d2008-04-24 12:38:15 +0100329
330
Keith Whitwelle7bac422008-04-19 16:43:15 +0100331void draw_pipeline_flush( struct draw_context *draw,
332 unsigned flags );
333
Keith Whitwell507fbe22008-04-19 15:29:27 +0100334
335
Keith Whitwellbee1d312008-04-19 16:39:24 +0100336/*******************************************************************************
337 * Flushing
338 */
339
Brian1603a332008-01-25 17:21:05 -0700340#define DRAW_FLUSH_STATE_CHANGE 0x8
341#define DRAW_FLUSH_BACKEND 0x10
Keith Whitwell08589f72007-09-26 11:56:17 +0100342
343
Brian1603a332008-01-25 17:21:05 -0700344void draw_do_flush( struct draw_context *draw, unsigned flags );
Keith Whitwell08589f72007-09-26 11:56:17 +0100345
Keith Whitwell08589f72007-09-26 11:56:17 +0100346
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100347
Zack Rusin3f7a3dd2008-04-12 21:52:46 -0400348
Brian279ffe32007-07-09 16:14:26 -0600349#endif /* DRAW_PRIVATE_H */