1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 /* Authors: Keith Whitwell <keith@tungstengraphics.com>
34 #include "draw_context.h"
35 #include "draw_private.h"
39 struct pipe_shader_state
;
41 struct draw_varient_input
43 enum pipe_format format
;
46 unsigned instance_divisor
;
49 struct draw_varient_output
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 */
56 struct draw_varient_element
{
57 struct draw_varient_input in
;
58 struct draw_varient_output out
;
61 struct draw_vs_varient_key
{
62 unsigned output_stride
;
63 unsigned nr_elements
:8; /* max2(nr_inputs, nr_outputs) */
65 unsigned nr_outputs
:8;
68 unsigned const_vbuffers
:5;
69 struct draw_varient_element element
[PIPE_MAX_ATTRIBS
];
72 struct draw_vs_varient
;
75 struct draw_vs_varient
{
76 struct draw_vs_varient_key key
;
78 struct draw_vertex_shader
*vs
;
80 void (*set_buffer
)( struct draw_vs_varient
*,
84 unsigned max_stride
);
86 void (PIPE_CDECL
*run_linear
)( struct draw_vs_varient
*shader
,
89 void *output_buffer
);
91 void (PIPE_CDECL
*run_elts
)( struct draw_vs_varient
*shader
,
94 void *output_buffer
);
96 void (*destroy
)( struct draw_vs_varient
* );
101 * Private version of the compiled vertex_shader
103 struct draw_vertex_shader
{
104 struct draw_context
*draw
;
106 /* This member will disappear shortly:
108 struct pipe_shader_state state
;
110 struct tgsi_shader_info info
;
111 unsigned position_output
;
112 unsigned edgeflag_output
;
114 /* Extracted from shader:
116 const float (*immediates
)[4];
120 struct draw_vs_varient
*varient
[16];
121 unsigned nr_varients
;
122 unsigned last_varient
;
123 struct draw_vs_varient
*(*create_varient
)( struct draw_vertex_shader
*shader
,
124 const struct draw_vs_varient_key
*key
);
127 void (*prepare
)( struct draw_vertex_shader
*shader
,
128 struct draw_context
*draw
);
130 /* Run the shader - this interface will get cleaned up in the
133 void (*run_linear
)( struct draw_vertex_shader
*shader
,
134 const float (*input
)[4],
136 const void *constants
[PIPE_MAX_CONSTANT_BUFFERS
],
138 unsigned input_stride
,
139 unsigned output_stride
);
142 void (*delete)( struct draw_vertex_shader
* );
146 struct draw_vs_varient
*
147 draw_vs_lookup_varient( struct draw_vertex_shader
*base
,
148 const struct draw_vs_varient_key
*key
);
151 /********************************************************************************
152 * Internal functions:
155 struct draw_vertex_shader
*
156 draw_create_vs_exec(struct draw_context
*draw
,
157 const struct pipe_shader_state
*templ
);
159 struct draw_vertex_shader
*
160 draw_create_vs_sse(struct draw_context
*draw
,
161 const struct pipe_shader_state
*templ
);
163 struct draw_vertex_shader
*
164 draw_create_vs_ppc(struct draw_context
*draw
,
165 const struct pipe_shader_state
*templ
);
168 struct draw_vs_varient_key
;
169 struct draw_vertex_shader
;
171 struct draw_vs_varient
*
172 draw_vs_create_varient_aos_sse( struct draw_vertex_shader
*vs
,
173 const struct draw_vs_varient_key
*key
);
176 struct draw_vertex_shader
*
177 draw_create_vs_llvm(struct draw_context
*draw
,
178 const struct pipe_shader_state
*state
);
182 /********************************************************************************
183 * Helpers for vs implementations that don't do their own fetch/emit varients.
184 * Means these can be shared between shaders.
187 struct translate_key
;
189 struct translate
*draw_vs_get_fetch( struct draw_context
*draw
,
190 struct translate_key
*key
);
193 struct translate
*draw_vs_get_emit( struct draw_context
*draw
,
194 struct translate_key
*key
);
196 struct draw_vs_varient
*
197 draw_vs_create_varient_generic( struct draw_vertex_shader
*vs
,
198 const struct draw_vs_varient_key
*key
);
202 static INLINE
int draw_vs_varient_keysize( const struct draw_vs_varient_key
*key
)
204 return 2 * sizeof(int) + key
->nr_elements
* sizeof(struct draw_varient_element
);
207 static INLINE
int draw_vs_varient_key_compare( const struct draw_vs_varient_key
*a
,
208 const struct draw_vs_varient_key
*b
)
210 int keysize
= draw_vs_varient_keysize(a
);
211 return memcmp(a
, b
, keysize
);
215 struct aos_machine
*draw_vs_aos_machine( void );
216 void draw_vs_aos_machine_destroy( struct aos_machine
*machine
);
219 draw_vs_aos_machine_constants(struct aos_machine
*machine
,
221 const void *constants
);
223 void draw_vs_aos_machine_viewport( struct aos_machine
*machine
,
224 const struct pipe_viewport_state
*viewport
);
227 #define MAX_TGSI_VERTICES 4