blob: 7bd1e670b4b9120f93bde2be07b5b18cf4bfe431 [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 Whitwellf40357e2008-03-23 16:44:59 +0000134 } front;
Keith Whitwell7d726072008-04-19 17:27:52 +0100135
136 struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
137 unsigned nr_vertex_buffers;
138
139 struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS];
140 unsigned nr_vertex_elements;
141
142 /* user-space vertex data, buffers */
143 struct {
144 const unsigned *edgeflag;
145
146 /** vertex element/index buffer (ex: glDrawElements) */
147 const void *elts;
148 /** bytes per index (0, 1, 2 or 4) */
149 unsigned eltSize;
Keith Whitwell82605d72008-05-29 11:46:43 +0100150 unsigned min_index;
151 unsigned max_index;
Keith Whitwell7d726072008-04-19 17:27:52 +0100152
153 /** vertex arrays */
154 const void *vbuffer[PIPE_MAX_ATTRIBS];
155
156 /** constant buffer (for vertex shader) */
157 const void *constants;
158 } 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;
166 } driver;
167
Brian Paul14d1ca82008-04-23 18:08:20 -0600168 boolean flushing; /**< debugging/sanity */
169 boolean suspend_flushing; /**< internally set */
170 boolean bypass_clipping; /**< set if either api or driver bypass_clipping true */
Keith Whitwell297b3be2008-03-10 19:49:15 +0000171
Brian279ffe32007-07-09 16:14:26 -0600172 /* pipe state that we need: */
Zack Rusin29440182007-09-17 12:59:50 -0400173 const struct pipe_rasterizer_state *rasterizer;
Brian279ffe32007-07-09 16:14:26 -0600174 struct pipe_viewport_state viewport;
Brian594dab42008-03-31 14:14:30 -0600175 boolean identity_viewport;
176
Keith Whitwell2f0d1392008-05-13 13:40:22 +0100177 struct {
178 struct draw_vertex_shader *vertex_shader;
179 uint num_vs_outputs; /**< convenience, from vertex_shader */
Keith Whitwell2161b0f2008-06-11 23:48:13 +0100180 uint position_output;
Brian63a51ae2007-09-06 17:07:09 -0600181
Keith Whitwell2f0d1392008-05-13 13:40:22 +0100182 /** TGSI program interpreter runtime state */
183 struct tgsi_exec_machine machine;
184
185 /* This (and the tgsi_exec_machine struct) probably need to be moved somewhere private.
186 */
187 struct gallivm_cpu_engine *engine;
188
Keith Whitwell62628c42008-05-29 00:17:53 +0100189 /* Here's another one:
190 */
191 struct aos_machine *aos_machine;
192
Keith Whitwell2f0d1392008-05-13 13:40:22 +0100193
Keith Whitwellbb2e13b2008-05-29 12:38:49 +0100194 const float (*aligned_constants)[4];
195
Michal Krol13581952008-05-31 18:19:21 +0200196 float (*aligned_constant_storage)[4];
Keith Whitwellbb2e13b2008-05-29 12:38:49 +0100197 unsigned const_storage_size;
198
199
Keith Whitwell7c99d7f2008-05-15 12:39:08 +0100200 struct translate *fetch;
Keith Whitwell2f0d1392008-05-13 13:40:22 +0100201 struct translate_cache *fetch_cache;
Keith Whitwell7c99d7f2008-05-15 12:39:08 +0100202 struct translate *emit;
Keith Whitwell2f0d1392008-05-13 13:40:22 +0100203 struct translate_cache *emit_cache;
204 } vs;
205
Brian279ffe32007-07-09 16:14:26 -0600206 /* Clip derived state:
207 */
Brianfd0a6d62007-08-16 12:52:20 -0600208 float plane[12][4];
209 unsigned nr_planes;
Brian279ffe32007-07-09 16:14:26 -0600210
Brianaceeb802008-02-18 16:19:05 -0700211 /* If a prim stage introduces new vertex attributes, they'll be stored here
212 */
213 struct {
214 uint semantic_name;
215 uint semantic_index;
216 int slot;
217 } extra_vp_outputs;
218
Brianfd0a6d62007-08-16 12:52:20 -0600219 unsigned reduced_prim;
220
Ian Romanicka89ee8a2008-01-30 20:10:45 -0800221 void *driver_private;
Brian279ffe32007-07-09 16:14:26 -0600222};
223
224
Keith Whitwell2f0d1392008-05-13 13:40:22 +0100225/*******************************************************************************
226 * Vertex shader code:
227 */
228boolean draw_vs_init( struct draw_context *draw );
229void draw_vs_destroy( struct draw_context *draw );
Brian279ffe32007-07-09 16:14:26 -0600230
Keith Whitwell62628c42008-05-29 00:17:53 +0100231void draw_vs_set_viewport( struct draw_context *,
232 const struct pipe_viewport_state * );
233
234void draw_vs_set_constants( struct draw_context *,
Keith Whitwellbb2e13b2008-05-29 12:38:49 +0100235 const float (*constants)[4],
236 unsigned size );
Brian279ffe32007-07-09 16:14:26 -0600237
José Fonseca3e221802007-11-07 13:07:20 +0000238
Brian279ffe32007-07-09 16:14:26 -0600239
Brian9a11a4a2007-08-31 11:28:31 -0600240
Keith Whitwell507fbe22008-04-19 15:29:27 +0100241/*******************************************************************************
242 * Vertex processing (was passthrough) code:
Keith Whitwellf40357e2008-03-23 16:44:59 +0000243 */
244boolean draw_pt_init( struct draw_context *draw );
245void draw_pt_destroy( struct draw_context *draw );
Keith Whitwell0b20d1b2008-04-04 13:18:09 +0100246void draw_pt_reset_vertex_ids( struct draw_context *draw );
Keith Whitwellf40357e2008-03-23 16:44:59 +0000247
Keith Whitwell507fbe22008-04-19 15:29:27 +0100248
249/*******************************************************************************
Keith Whitwelle7bac422008-04-19 16:43:15 +0100250 * Primitive processing (pipeline) code:
Keith Whitwell507fbe22008-04-19 15:29:27 +0100251 */
252
253boolean draw_pipeline_init( struct draw_context *draw );
254void draw_pipeline_destroy( struct draw_context *draw );
255
Keith Whitwellf93332d2008-04-24 12:38:15 +0100256
257
258
259
260/* We use the top few bits in the elts[] parameter to convey a little
261 * API information. This limits the number of vertices we can address
262 * to only 4096 -- if that becomes a problem, we can switch to 32-bit
263 * draw indices.
264 *
265 * These flags expected at first vertex of lines & triangles when
266 * unfilled and/or line stipple modes are operational.
267 */
Keith Whitwell0a4aea02008-06-02 12:59:16 +0100268#define DRAW_PIPE_MAX_VERTICES (0x1<<12)
Keith Whitwellf93332d2008-04-24 12:38:15 +0100269#define DRAW_PIPE_EDGE_FLAG_0 (0x1<<12)
270#define DRAW_PIPE_EDGE_FLAG_1 (0x2<<12)
271#define DRAW_PIPE_EDGE_FLAG_2 (0x4<<12)
272#define DRAW_PIPE_EDGE_FLAG_ALL (0x7<<12)
273#define DRAW_PIPE_RESET_STIPPLE (0x8<<12)
274#define DRAW_PIPE_FLAG_MASK (0xf<<12)
275
Keith Whitwellbee1d312008-04-19 16:39:24 +0100276void draw_pipeline_run( struct draw_context *draw,
277 unsigned prim,
278 struct vertex_header *vertices,
279 unsigned vertex_count,
280 unsigned stride,
281 const ushort *elts,
282 unsigned count );
283
Zack Rusinfe586f82008-05-06 18:59:45 -0400284void draw_pipeline_run_linear( struct draw_context *draw,
285 unsigned prim,
286 struct vertex_header *vertices,
287 unsigned count,
288 unsigned stride );
289
Keith Whitwellf93332d2008-04-24 12:38:15 +0100290
291
Keith Whitwelle7bac422008-04-19 16:43:15 +0100292void draw_pipeline_flush( struct draw_context *draw,
293 unsigned flags );
294
Keith Whitwell507fbe22008-04-19 15:29:27 +0100295
296
Keith Whitwellbee1d312008-04-19 16:39:24 +0100297/*******************************************************************************
298 * Flushing
299 */
300
Brian1603a332008-01-25 17:21:05 -0700301#define DRAW_FLUSH_STATE_CHANGE 0x8
302#define DRAW_FLUSH_BACKEND 0x10
Keith Whitwell08589f72007-09-26 11:56:17 +0100303
304
Brian1603a332008-01-25 17:21:05 -0700305void draw_do_flush( struct draw_context *draw, unsigned flags );
Keith Whitwell08589f72007-09-26 11:56:17 +0100306
Keith Whitwell08589f72007-09-26 11:56:17 +0100307
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100308
Zack Rusin3f7a3dd2008-04-12 21:52:46 -0400309
Brian279ffe32007-07-09 16:14:26 -0600310#endif /* DRAW_PRIVATE_H */