Merge commit 'origin/gallium-0.1' into gallium-0.2
[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 const_vbuffers:5;
68 struct draw_varient_element element[PIPE_MAX_ATTRIBS];
69 };
70
71 struct draw_vs_varient;
72
73
74 struct draw_vs_varient {
75 struct draw_vs_varient_key key;
76
77 struct draw_vertex_shader *vs;
78
79 void (*set_buffer)( struct draw_vs_varient *,
80 unsigned i,
81 const void *ptr,
82 unsigned stride );
83
84 void (PIPE_CDECL *run_linear)( struct draw_vs_varient *shader,
85 unsigned start,
86 unsigned count,
87 void *output_buffer );
88
89 void (PIPE_CDECL *run_elts)( struct draw_vs_varient *shader,
90 const unsigned *elts,
91 unsigned count,
92 void *output_buffer );
93
94 void (*destroy)( struct draw_vs_varient * );
95 };
96
97
98 /**
99 * Private version of the compiled vertex_shader
100 */
101 struct draw_vertex_shader {
102 struct draw_context *draw;
103
104 /* This member will disappear shortly:
105 */
106 struct pipe_shader_state state;
107
108 struct tgsi_shader_info info;
109 unsigned position_output;
110
111 /* Extracted from shader:
112 */
113 const float (*immediates)[4];
114
115 /*
116 */
117 struct draw_vs_varient *varient[16];
118 unsigned nr_varients;
119 unsigned last_varient;
120 struct draw_vs_varient *(*create_varient)( struct draw_vertex_shader *shader,
121 const struct draw_vs_varient_key *key );
122
123
124 void (*prepare)( struct draw_vertex_shader *shader,
125 struct draw_context *draw );
126
127 /* Run the shader - this interface will get cleaned up in the
128 * future:
129 */
130 void (*run_linear)( struct draw_vertex_shader *shader,
131 const float (*input)[4],
132 float (*output)[4],
133 const float (*constants)[4],
134 unsigned count,
135 unsigned input_stride,
136 unsigned output_stride );
137
138
139 void (*delete)( struct draw_vertex_shader * );
140 };
141
142
143 struct draw_vs_varient *
144 draw_vs_lookup_varient( struct draw_vertex_shader *base,
145 const struct draw_vs_varient_key *key );
146
147
148 /********************************************************************************
149 * Internal functions:
150 */
151
152 struct draw_vertex_shader *
153 draw_create_vs_exec(struct draw_context *draw,
154 const struct pipe_shader_state *templ);
155
156 struct draw_vertex_shader *
157 draw_create_vs_sse(struct draw_context *draw,
158 const struct pipe_shader_state *templ);
159
160 struct draw_vertex_shader *
161 draw_create_vs_ppc(struct draw_context *draw,
162 const struct pipe_shader_state *templ);
163
164 struct draw_vertex_shader *
165 draw_create_vs_llvm(struct draw_context *draw,
166 const struct pipe_shader_state *templ);
167
168
169
170 struct draw_vs_varient_key;
171 struct draw_vertex_shader;
172
173 struct draw_vs_varient *draw_vs_varient_aos_sse( struct draw_vertex_shader *vs,
174 const struct draw_vs_varient_key *key );
175
176
177
178 /********************************************************************************
179 * Helpers for vs implementations that don't do their own fetch/emit varients.
180 * Means these can be shared between shaders.
181 */
182 struct translate;
183 struct translate_key;
184
185 struct translate *draw_vs_get_fetch( struct draw_context *draw,
186 struct translate_key *key );
187
188
189 struct translate *draw_vs_get_emit( struct draw_context *draw,
190 struct translate_key *key );
191
192 struct draw_vs_varient *draw_vs_varient_generic( struct draw_vertex_shader *vs,
193 const struct draw_vs_varient_key *key );
194
195
196
197 static INLINE int draw_vs_varient_keysize( const struct draw_vs_varient_key *key )
198 {
199 return 2 * sizeof(int) + key->nr_elements * sizeof(struct draw_varient_element);
200 }
201
202 static INLINE int draw_vs_varient_key_compare( const struct draw_vs_varient_key *a,
203 const struct draw_vs_varient_key *b )
204 {
205 int keysize = draw_vs_varient_keysize(a);
206 return memcmp(a, b, keysize);
207 }
208
209
210 struct aos_machine *draw_vs_aos_machine( void );
211 void draw_vs_aos_machine_destroy( struct aos_machine *machine );
212
213 void draw_vs_aos_machine_constants( struct aos_machine *machine,
214 const float (*constants)[4] );
215
216 void draw_vs_aos_machine_viewport( struct aos_machine *machine,
217 const struct pipe_viewport_state *viewport );
218
219
220 #define MAX_TGSI_VERTICES 4
221
222
223
224 #endif