blob: 86b901a3c812fa925d0982c2bc27857badbcc42b [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é Fonseca6acd63a2008-02-15 17:50:12 +090047#include "tgsi/exec/tgsi_exec.h"
Briancddeca52008-02-27 16:02:58 -070048#include "tgsi/util/tgsi_scan.h"
Brian0d13ade2007-10-02 11:46:11 -060049
Brian279ffe32007-07-09 16:14:26 -060050
Brianaceeb802008-02-18 16:19:05 -070051struct pipe_context;
Zack Rusin25b17b22007-10-29 08:27:32 -040052struct gallivm_prog;
53struct gallivm_cpu_engine;
Keith Whitwell280bcff2008-04-17 14:20:00 +010054struct draw_vertex_shader;
Keith Whitwell507fbe22008-04-19 15:29:27 +010055struct draw_context;
56struct draw_stage;
57struct vbuf_render;
Keith Whitwellf40357e2008-03-23 16:44:59 +000058
Zack Rusinaadbb1d2008-04-12 15:45:28 -040059
Brian279ffe32007-07-09 16:14:26 -060060/**
61 * Basic vertex info.
62 * Carry some useful information around with the vertices in the prim pipe.
63 */
64struct vertex_header {
Brianfd0a6d62007-08-16 12:52:20 -060065 unsigned clipmask:12;
66 unsigned edgeflag:1;
Keith Whitwella37e0da2007-09-25 13:20:53 +010067 unsigned pad:3;
68 unsigned vertex_id:16;
Brian279ffe32007-07-09 16:14:26 -060069
Brianfd0a6d62007-08-16 12:52:20 -060070 float clip[4];
Brian279ffe32007-07-09 16:14:26 -060071
Keith Whitwell507fbe22008-04-19 15:29:27 +010072 /* This will probably become float (*data)[4] soon:
73 */
74 float data[][4];
Brian279ffe32007-07-09 16:14:26 -060075};
76
José Fonsecac28fdf32007-11-07 12:08:19 +000077/* NOTE: It should match vertex_id size above */
78#define UNDEFINED_VERTEX_ID 0xffff
79
Brian279ffe32007-07-09 16:14:26 -060080
81/**
Brian279ffe32007-07-09 16:14:26 -060082 * Private context for the drawing module.
83 */
84struct draw_context
85{
Brianfd0a6d62007-08-16 12:52:20 -060086 /** Drawing/primitive pipeline stages */
Brian279ffe32007-07-09 16:14:26 -060087 struct {
Brianea470ee2007-07-12 13:32:31 -060088 struct draw_stage *first; /**< one of the following */
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010089
Keith Whitwell08589f72007-09-26 11:56:17 +010090 struct draw_stage *validate;
91
Brian279ffe32007-07-09 16:14:26 -060092 /* stages (in logical order) */
Brianea470ee2007-07-12 13:32:31 -060093 struct draw_stage *flatshade;
94 struct draw_stage *clip;
95 struct draw_stage *cull;
96 struct draw_stage *twoside;
97 struct draw_stage *offset;
98 struct draw_stage *unfilled;
Brian329a8472008-01-21 14:08:20 -070099 struct draw_stage *stipple;
Brianeb4dc2d2008-02-21 16:18:05 -0700100 struct draw_stage *aapoint;
Brianaceeb802008-02-18 16:19:05 -0700101 struct draw_stage *aaline;
Brian446bfc32008-02-21 16:56:32 -0700102 struct draw_stage *pstipple;
Brian Paula1a13952008-02-28 17:49:22 -0700103 struct draw_stage *wide_line;
104 struct draw_stage *wide_point;
Zack Rusinde69fc12007-09-18 10:02:16 -0400105 struct draw_stage *rasterize;
Keith Whitwell507fbe22008-04-19 15:29:27 +0100106
107 float wide_point_threshold; /**< convert pnts to tris if larger than this */
108 float wide_line_threshold; /**< convert lines to tris if wider than this */
109 boolean line_stipple; /**< do line stipple? */
110 boolean point_sprite; /**< convert points to quads for sprites? */
111
Keith Whitwellbee1d312008-04-19 16:39:24 +0100112 /* Temporary storage while the pipeline is being run:
113 */
114 char *verts;
115 unsigned vertex_stride;
116 unsigned vertex_count;
Brian279ffe32007-07-09 16:14:26 -0600117 } pipeline;
118
Keith Whitwell297b3be2008-03-10 19:49:15 +0000119
120 struct vbuf_render *render;
121
122 /* Support prototype passthrough path:
123 */
124 struct {
Keith Whitwellf40357e2008-03-23 16:44:59 +0000125 struct {
Keith Whitwell1246d062008-04-19 13:20:26 +0100126 struct draw_pt_middle_end *fetch_emit;
Keith Whitwellbbda45e2008-05-12 19:40:20 +0100127 struct draw_pt_middle_end *fetch_shade_emit;
Keith Whitwell1246d062008-04-19 13:20:26 +0100128 struct draw_pt_middle_end *general;
Keith Whitwellf40357e2008-03-23 16:44:59 +0000129 } middle;
130
131 struct {
Keith Whitwellf40357e2008-03-23 16:44:59 +0000132 struct draw_pt_front_end *vcache;
Zack Rusin992d0b92008-04-24 16:22:47 -0400133 struct draw_pt_front_end *varray;
Keith Whitwellb5e53692008-05-12 15:20:38 +0100134 struct draw_pt_front_end *fetch_shade_emit; /* temp hack */
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 {
145 const unsigned *edgeflag;
146
147 /** vertex element/index buffer (ex: glDrawElements) */
148 const void *elts;
149 /** bytes per index (0, 1, 2 or 4) */
150 unsigned eltSize;
151
152 /** vertex arrays */
153 const void *vbuffer[PIPE_MAX_ATTRIBS];
154
155 /** constant buffer (for vertex shader) */
156 const void *constants;
157 } user;
158
Keith Whitwellb5e53692008-05-12 15:20:38 +0100159 boolean test_fse;
Keith Whitwell297b3be2008-03-10 19:49:15 +0000160 } pt;
161
Keith Whitwell05888582008-04-22 20:50:20 +0100162 struct {
163 boolean bypass_clipping;
164 } driver;
165
Brian Paul14d1ca82008-04-23 18:08:20 -0600166 boolean flushing; /**< debugging/sanity */
167 boolean suspend_flushing; /**< internally set */
168 boolean bypass_clipping; /**< set if either api or driver bypass_clipping true */
Keith Whitwell297b3be2008-03-10 19:49:15 +0000169
Brian279ffe32007-07-09 16:14:26 -0600170 /* pipe state that we need: */
Zack Rusin29440182007-09-17 12:59:50 -0400171 const struct pipe_rasterizer_state *rasterizer;
Brian279ffe32007-07-09 16:14:26 -0600172 struct pipe_viewport_state viewport;
Keith Whitwellc96d5652008-04-17 13:14:22 +0100173
Keith Whitwellb29d8d22008-02-15 13:37:01 +0000174 struct draw_vertex_shader *vertex_shader;
Brian3e2be1c2007-08-15 18:54:05 -0600175
Brian594dab42008-03-31 14:14:30 -0600176 boolean identity_viewport;
177
Briancd364362008-01-23 12:48:41 -0700178 uint num_vs_outputs; /**< convenience, from vertex_shader */
179
Brian63a51ae2007-09-06 17:07:09 -0600180
Brian279ffe32007-07-09 16:14:26 -0600181 /* Clip derived state:
182 */
Brianfd0a6d62007-08-16 12:52:20 -0600183 float plane[12][4];
184 unsigned nr_planes;
Brian279ffe32007-07-09 16:14:26 -0600185
Brianaceeb802008-02-18 16:19:05 -0700186 /* If a prim stage introduces new vertex attributes, they'll be stored here
187 */
188 struct {
189 uint semantic_name;
190 uint semantic_index;
191 int slot;
192 } extra_vp_outputs;
193
Brianfd0a6d62007-08-16 12:52:20 -0600194 unsigned reduced_prim;
195
Brian0d13ade2007-10-02 11:46:11 -0600196 /** TGSI program interpreter runtime state */
197 struct tgsi_exec_machine machine;
Keith Whitwell4bb21342007-08-14 15:44:41 +0100198
Keith Whitwellb29d8d22008-02-15 13:37:01 +0000199 /* This (and the tgsi_exec_machine struct) probably need to be moved somewhere private.
200 */
201 struct gallivm_cpu_engine *engine;
Ian Romanicka89ee8a2008-01-30 20:10:45 -0800202 void *driver_private;
Brian279ffe32007-07-09 16:14:26 -0600203};
204
205
206
Brian279ffe32007-07-09 16:14:26 -0600207
José Fonseca3e221802007-11-07 13:07:20 +0000208
Brian279ffe32007-07-09 16:14:26 -0600209
Brian9a11a4a2007-08-31 11:28:31 -0600210
Keith Whitwell507fbe22008-04-19 15:29:27 +0100211/*******************************************************************************
212 * Vertex processing (was passthrough) code:
Keith Whitwellf40357e2008-03-23 16:44:59 +0000213 */
214boolean draw_pt_init( struct draw_context *draw );
215void draw_pt_destroy( struct draw_context *draw );
Keith Whitwell0b20d1b2008-04-04 13:18:09 +0100216void draw_pt_reset_vertex_ids( struct draw_context *draw );
Keith Whitwellf40357e2008-03-23 16:44:59 +0000217
Keith Whitwell507fbe22008-04-19 15:29:27 +0100218
219/*******************************************************************************
Keith Whitwelle7bac422008-04-19 16:43:15 +0100220 * Primitive processing (pipeline) code:
Keith Whitwell507fbe22008-04-19 15:29:27 +0100221 */
222
223boolean draw_pipeline_init( struct draw_context *draw );
224void draw_pipeline_destroy( struct draw_context *draw );
225
Keith Whitwellf93332d2008-04-24 12:38:15 +0100226
227
228
229
230/* We use the top few bits in the elts[] parameter to convey a little
231 * API information. This limits the number of vertices we can address
232 * to only 4096 -- if that becomes a problem, we can switch to 32-bit
233 * draw indices.
234 *
235 * These flags expected at first vertex of lines & triangles when
236 * unfilled and/or line stipple modes are operational.
237 */
238#define DRAW_PIPE_EDGE_FLAG_0 (0x1<<12)
239#define DRAW_PIPE_EDGE_FLAG_1 (0x2<<12)
240#define DRAW_PIPE_EDGE_FLAG_2 (0x4<<12)
241#define DRAW_PIPE_EDGE_FLAG_ALL (0x7<<12)
242#define DRAW_PIPE_RESET_STIPPLE (0x8<<12)
243#define DRAW_PIPE_FLAG_MASK (0xf<<12)
244
Keith Whitwellbee1d312008-04-19 16:39:24 +0100245void draw_pipeline_run( struct draw_context *draw,
246 unsigned prim,
247 struct vertex_header *vertices,
248 unsigned vertex_count,
249 unsigned stride,
250 const ushort *elts,
251 unsigned count );
252
Zack Rusinfe586f82008-05-06 18:59:45 -0400253void draw_pipeline_run_linear( struct draw_context *draw,
254 unsigned prim,
255 struct vertex_header *vertices,
256 unsigned count,
257 unsigned stride );
258
Keith Whitwellf93332d2008-04-24 12:38:15 +0100259
260
Keith Whitwelle7bac422008-04-19 16:43:15 +0100261void draw_pipeline_flush( struct draw_context *draw,
262 unsigned flags );
263
Keith Whitwell507fbe22008-04-19 15:29:27 +0100264
265
Keith Whitwellbee1d312008-04-19 16:39:24 +0100266/*******************************************************************************
267 * Flushing
268 */
269
Brian1603a332008-01-25 17:21:05 -0700270#define DRAW_FLUSH_STATE_CHANGE 0x8
271#define DRAW_FLUSH_BACKEND 0x10
Keith Whitwell08589f72007-09-26 11:56:17 +0100272
273
Brian1603a332008-01-25 17:21:05 -0700274void draw_do_flush( struct draw_context *draw, unsigned flags );
Keith Whitwell08589f72007-09-26 11:56:17 +0100275
Keith Whitwell08589f72007-09-26 11:56:17 +0100276
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100277
Zack Rusin3f7a3dd2008-04-12 21:52:46 -0400278
Brian279ffe32007-07-09 16:14:26 -0600279#endif /* DRAW_PRIVATE_H */