Merge branch 'gallium-vertex-linear' into gallium-0.1
[mesa.git] / src / gallium / auxiliary / draw / draw_vs.h
1 /**************************************************************************
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
28 /* Authors: Keith Whitwell <keith@tungstengraphics.com>
29 */
30
31 #ifndef DRAW_VS_H
32 #define DRAW_VS_H
33
34 #include "draw_context.h"
35 #include "draw_private.h"
36
37
38 struct draw_context;
39 struct pipe_shader_state;
40
41 struct draw_varient_input
42 {
43 enum pipe_format format;
44 unsigned buffer;
45 unsigned offset;
46 };
47
48 struct draw_varient_output
49 {
50 enum pipe_format format; /* output format */
51 unsigned vs_output:8; /* which vertex shader output is this? */
52 unsigned offset:24; /* offset into output vertex */
53 };
54
55 struct draw_varient_element {
56 struct draw_varient_input in;
57 struct draw_varient_output out;
58 };
59
60 struct draw_vs_varient_key {
61 unsigned output_stride;
62 unsigned nr_elements:8; /* max2(nr_inputs, nr_outputs) */
63 unsigned nr_inputs:8;
64 unsigned nr_outputs:8;
65 unsigned viewport:1;
66 unsigned clip:1;
67 unsigned pad:5;
68 struct draw_varient_element element[PIPE_MAX_ATTRIBS];
69 };
70
71 struct draw_vs_varient;
72
73 typedef void (PIPE_CDECL *vsv_run_elts_func)( struct draw_vs_varient *,
74 const unsigned *elts,
75 unsigned count,
76 void *output_buffer);
77
78 typedef void (PIPE_CDECL *vsv_run_linear_func)( struct draw_vs_varient *,
79 unsigned start,
80 unsigned count,
81 void *output_buffer);
82
83
84 struct draw_vs_varient {
85 struct draw_vs_varient_key key;
86
87 struct draw_vertex_shader *vs;
88
89 void (*set_input)( struct draw_vs_varient *,
90 unsigned i,
91 const void *ptr,
92 unsigned stride );
93
94 void (*set_constants)( struct draw_vs_varient *,
95 const float (*constants)[4] );
96
97 void (*set_viewport)( struct draw_vs_varient *,
98 const struct pipe_viewport_state * );
99
100 void (PIPE_CDECL *run_linear)( struct draw_vs_varient *shader,
101 unsigned start,
102 unsigned count,
103 void *output_buffer );
104
105 void (PIPE_CDECL *run_elts)( struct draw_vs_varient *shader,
106 const unsigned *elts,
107 unsigned count,
108 void *output_buffer );
109
110 void (*destroy)( struct draw_vs_varient * );
111 };
112
113
114 /**
115 * Private version of the compiled vertex_shader
116 */
117 struct draw_vertex_shader {
118 struct draw_context *draw;
119
120 /* This member will disappear shortly:
121 */
122 struct pipe_shader_state state;
123
124 struct tgsi_shader_info info;
125
126 /*
127 */
128 struct draw_vs_varient *varient[16];
129 unsigned nr_varients;
130 struct draw_vs_varient *(*create_varient)( struct draw_vertex_shader *shader,
131 const struct draw_vs_varient_key *key );
132
133
134 void (*prepare)( struct draw_vertex_shader *shader,
135 struct draw_context *draw );
136
137 /* Run the shader - this interface will get cleaned up in the
138 * future:
139 */
140 void (*run_linear)( struct draw_vertex_shader *shader,
141 const float (*input)[4],
142 float (*output)[4],
143 const float (*constants)[4],
144 unsigned count,
145 unsigned input_stride,
146 unsigned output_stride );
147
148
149 void (*delete)( struct draw_vertex_shader * );
150 };
151
152
153 struct draw_vs_varient *
154 draw_vs_lookup_varient( struct draw_vertex_shader *base,
155 const struct draw_vs_varient_key *key );
156
157
158 /********************************************************************************
159 * Internal functions:
160 */
161
162 struct draw_vertex_shader *
163 draw_create_vs_exec(struct draw_context *draw,
164 const struct pipe_shader_state *templ);
165
166 struct draw_vertex_shader *
167 draw_create_vs_sse(struct draw_context *draw,
168 const struct pipe_shader_state *templ);
169
170 struct draw_vertex_shader *
171 draw_create_vs_llvm(struct draw_context *draw,
172 const struct pipe_shader_state *templ);
173
174
175
176 struct draw_vs_varient_key;
177 struct draw_vertex_shader;
178
179 struct draw_vs_varient *draw_vs_varient_aos_sse( struct draw_vertex_shader *vs,
180 const struct draw_vs_varient_key *key );
181
182
183
184 /********************************************************************************
185 * Helpers for vs implementations that don't do their own fetch/emit varients.
186 * Means these can be shared between shaders.
187 */
188 struct translate;
189 struct translate_key;
190
191 struct translate *draw_vs_get_fetch( struct draw_context *draw,
192 struct translate_key *key );
193
194
195 struct translate *draw_vs_get_emit( struct draw_context *draw,
196 struct translate_key *key );
197
198 struct draw_vs_varient *draw_vs_varient_generic( struct draw_vertex_shader *vs,
199 const struct draw_vs_varient_key *key );
200
201
202
203 static INLINE int draw_vs_varient_keysize( const struct draw_vs_varient_key *key )
204 {
205 return 2 * sizeof(int) + key->nr_elements * sizeof(struct draw_varient_element);
206 }
207
208 static INLINE int draw_vs_varient_key_compare( const struct draw_vs_varient_key *a,
209 const struct draw_vs_varient_key *b )
210 {
211 int keysize = draw_vs_varient_keysize(a);
212 return memcmp(a, b, keysize);
213 }
214
215
216
217
218
219 #define MAX_TGSI_VERTICES 4
220
221
222
223 #endif