Merge branch 'mesa_7_7_branch'
[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 unsigned edgeflag_output;
111
112 /* Extracted from shader:
113 */
114 const float (*immediates)[4];
115
116 /*
117 */
118 struct draw_vs_varient *varient[16];
119 unsigned nr_varients;
120 unsigned last_varient;
121 struct draw_vs_varient *(*create_varient)( struct draw_vertex_shader *shader,
122 const struct draw_vs_varient_key *key );
123
124
125 void (*prepare)( struct draw_vertex_shader *shader,
126 struct draw_context *draw );
127
128 /* Run the shader - this interface will get cleaned up in the
129 * future:
130 */
131 void (*run_linear)( struct draw_vertex_shader *shader,
132 const float (*input)[4],
133 float (*output)[4],
134 const float (*constants)[4],
135 unsigned count,
136 unsigned input_stride,
137 unsigned output_stride );
138
139
140 void (*delete)( struct draw_vertex_shader * );
141 };
142
143
144 struct draw_vs_varient *
145 draw_vs_lookup_varient( struct draw_vertex_shader *base,
146 const struct draw_vs_varient_key *key );
147
148
149 /********************************************************************************
150 * Internal functions:
151 */
152
153 struct draw_vertex_shader *
154 draw_create_vs_exec(struct draw_context *draw,
155 const struct pipe_shader_state *templ);
156
157 struct draw_vertex_shader *
158 draw_create_vs_sse(struct draw_context *draw,
159 const struct pipe_shader_state *templ);
160
161 struct draw_vertex_shader *
162 draw_create_vs_ppc(struct draw_context *draw,
163 const struct pipe_shader_state *templ);
164
165 struct draw_vertex_shader *
166 draw_create_vs_llvm(struct draw_context *draw,
167 const struct pipe_shader_state *templ);
168
169
170
171 struct draw_vs_varient_key;
172 struct draw_vertex_shader;
173
174 struct draw_vs_varient *draw_vs_varient_aos_sse( struct draw_vertex_shader *vs,
175 const struct draw_vs_varient_key *key );
176
177
178
179 /********************************************************************************
180 * Helpers for vs implementations that don't do their own fetch/emit varients.
181 * Means these can be shared between shaders.
182 */
183 struct translate;
184 struct translate_key;
185
186 struct translate *draw_vs_get_fetch( struct draw_context *draw,
187 struct translate_key *key );
188
189
190 struct translate *draw_vs_get_emit( struct draw_context *draw,
191 struct translate_key *key );
192
193 struct draw_vs_varient *draw_vs_varient_generic( struct draw_vertex_shader *vs,
194 const struct draw_vs_varient_key *key );
195
196
197
198 static INLINE int draw_vs_varient_keysize( const struct draw_vs_varient_key *key )
199 {
200 return 2 * sizeof(int) + key->nr_elements * sizeof(struct draw_varient_element);
201 }
202
203 static INLINE int draw_vs_varient_key_compare( const struct draw_vs_varient_key *a,
204 const struct draw_vs_varient_key *b )
205 {
206 int keysize = draw_vs_varient_keysize(a);
207 return memcmp(a, b, keysize);
208 }
209
210
211 struct aos_machine *draw_vs_aos_machine( void );
212 void draw_vs_aos_machine_destroy( struct aos_machine *machine );
213
214 void draw_vs_aos_machine_constants( struct aos_machine *machine,
215 const float (*constants)[4] );
216
217 void draw_vs_aos_machine_viewport( struct aos_machine *machine,
218 const struct pipe_viewport_state *viewport );
219
220
221 #define MAX_TGSI_VERTICES 4
222
223
224
225 #endif