draw_vs.h revision 7c99d7fe60e7bb0b7cf103a851aeef4614278ca6
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
38struct draw_context;
39struct pipe_shader_state;
40
41struct draw_vs_input
42{
43   enum pipe_format format;
44   unsigned buffer;
45   unsigned offset;
46};
47
48struct draw_vs_output
49{
50   enum pipe_format format;
51   unsigned offset;
52};
53
54struct draw_vs_element {
55   struct draw_vs_input in;
56   struct draw_vs_output out;
57};
58
59struct draw_vs_varient_key {
60   unsigned output_stride;
61   unsigned nr_elements;
62   struct draw_vs_element element[PIPE_MAX_ATTRIBS];
63};
64
65struct draw_vs_varient {
66   struct draw_vs_varient_key key;
67
68   struct draw_vertex_shader *vs;
69
70   void (*set_input)( struct draw_vs_varient *,
71                      unsigned i,
72                      const void *ptr,
73                      unsigned stride );
74
75   void (*set_constants)( struct draw_vs_varient *,
76                          const float (*constants)[4] );
77
78
79   void (*run_linear)( struct draw_vs_varient *shader,
80                       unsigned start,
81		       unsigned count,
82		       void *output_buffer );
83
84   void (*run_elts)( struct draw_vs_varient *shader,
85                     const unsigned *elts,
86                     unsigned count,
87                     void *output_buffer );
88
89   void (*destroy)( struct draw_vs_varient * );
90};
91
92
93/**
94 * Private version of the compiled vertex_shader
95 */
96struct draw_vertex_shader {
97   struct draw_context *draw;
98
99   /* This member will disappear shortly:
100    */
101   struct pipe_shader_state   state;
102
103   struct tgsi_shader_info info;
104
105   /*
106    */
107   struct draw_vs_varient *varient[16];
108   unsigned nr_varients;
109   struct draw_vs_varient *(*create_varient)( struct draw_vertex_shader *shader,
110                                              const struct draw_vs_varient_key *key );
111
112
113   void (*prepare)( struct draw_vertex_shader *shader,
114		    struct draw_context *draw );
115
116   /* Run the shader - this interface will get cleaned up in the
117    * future:
118    */
119   void (*run_linear)( struct draw_vertex_shader *shader,
120		       const float (*input)[4],
121		       float (*output)[4],
122		       const float (*constants)[4],
123		       unsigned count,
124		       unsigned input_stride,
125		       unsigned output_stride );
126
127
128   void (*delete)( struct draw_vertex_shader * );
129};
130
131
132struct draw_vs_varient *
133draw_vs_lookup_varient( struct draw_vertex_shader *base,
134                        const struct draw_vs_varient_key *key );
135
136
137/********************************************************************************
138 * Internal functions:
139 */
140
141struct draw_vertex_shader *
142draw_create_vs_exec(struct draw_context *draw,
143		    const struct pipe_shader_state *templ);
144
145struct draw_vertex_shader *
146draw_create_vs_sse(struct draw_context *draw,
147		   const struct pipe_shader_state *templ);
148
149struct draw_vertex_shader *
150draw_create_vs_llvm(struct draw_context *draw,
151		    const struct pipe_shader_state *templ);
152
153/********************************************************************************
154 * Helpers for vs implementations that don't do their own fetch/emit varients.
155 * Means these can be shared between shaders.
156 */
157struct translate;
158struct translate_key;
159
160struct translate *draw_vs_get_fetch( struct draw_context *draw,
161                                     struct translate_key *key );
162
163
164struct translate *draw_vs_get_emit( struct draw_context *draw,
165                                    struct translate_key *key );
166
167struct draw_vs_varient *draw_vs_varient_generic( struct draw_vertex_shader *vs,
168                                                 const struct draw_vs_varient_key *key );
169
170
171
172static INLINE int draw_vs_varient_keysize( const struct draw_vs_varient_key *key )
173{
174   return 2 * sizeof(int) + key->nr_elements * sizeof(struct draw_vs_element);
175}
176
177static INLINE int draw_vs_varient_key_compare( const struct draw_vs_varient_key *a,
178                                         const struct draw_vs_varient_key *b )
179{
180   int keysize = draw_vs_varient_keysize(a);
181   return memcmp(a, b, keysize);
182}
183
184
185
186
187
188#define MAX_TGSI_VERTICES 4
189
190
191
192#endif
193