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