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
;
48 struct draw_varient_output
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 */
55 struct draw_varient_element
{
56 struct draw_varient_input in
;
57 struct draw_varient_output out
;
60 struct draw_vs_varient_key
{
61 unsigned output_stride
;
62 unsigned nr_elements
:8; /* max2(nr_inputs, nr_outputs) */
64 unsigned nr_outputs
:8;
67 unsigned const_vbuffers
:5;
68 struct draw_varient_element element
[PIPE_MAX_ATTRIBS
];
71 struct draw_vs_varient
;
74 struct draw_vs_varient
{
75 struct draw_vs_varient_key key
;
77 struct draw_vertex_shader
*vs
;
79 void (*set_buffer
)( struct draw_vs_varient
*,
84 void (PIPE_CDECL
*run_linear
)( struct draw_vs_varient
*shader
,
87 void *output_buffer
);
89 void (PIPE_CDECL
*run_elts
)( struct draw_vs_varient
*shader
,
92 void *output_buffer
);
94 void (*destroy
)( struct draw_vs_varient
* );
99 * Private version of the compiled vertex_shader
101 struct draw_vertex_shader
{
102 struct draw_context
*draw
;
104 /* This member will disappear shortly:
106 struct pipe_shader_state state
;
108 struct tgsi_shader_info info
;
109 unsigned position_output
;
111 /* Extracted from shader:
113 const float (*immediates
)[4];
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
);
124 void (*prepare
)( struct draw_vertex_shader
*shader
,
125 struct draw_context
*draw
);
127 /* Run the shader - this interface will get cleaned up in the
130 void (*run_linear
)( struct draw_vertex_shader
*shader
,
131 const float (*input
)[4],
133 const float (*constants
)[4],
135 unsigned input_stride
,
136 unsigned output_stride
);
139 void (*delete)( struct draw_vertex_shader
* );
143 struct draw_vs_varient
*
144 draw_vs_lookup_varient( struct draw_vertex_shader
*base
,
145 const struct draw_vs_varient_key
*key
);
148 /********************************************************************************
149 * Internal functions:
152 struct draw_vertex_shader
*
153 draw_create_vs_exec(struct draw_context
*draw
,
154 const struct pipe_shader_state
*templ
);
156 struct draw_vertex_shader
*
157 draw_create_vs_sse(struct draw_context
*draw
,
158 const struct pipe_shader_state
*templ
);
160 struct draw_vertex_shader
*
161 draw_create_vs_ppc(struct draw_context
*draw
,
162 const struct pipe_shader_state
*templ
);
164 struct draw_vertex_shader
*
165 draw_create_vs_llvm(struct draw_context
*draw
,
166 const struct pipe_shader_state
*templ
);
170 struct draw_vs_varient_key
;
171 struct draw_vertex_shader
;
173 struct draw_vs_varient
*draw_vs_varient_aos_sse( struct draw_vertex_shader
*vs
,
174 const struct draw_vs_varient_key
*key
);
178 /********************************************************************************
179 * Helpers for vs implementations that don't do their own fetch/emit varients.
180 * Means these can be shared between shaders.
183 struct translate_key
;
185 struct translate
*draw_vs_get_fetch( struct draw_context
*draw
,
186 struct translate_key
*key
);
189 struct translate
*draw_vs_get_emit( struct draw_context
*draw
,
190 struct translate_key
*key
);
192 struct draw_vs_varient
*draw_vs_varient_generic( struct draw_vertex_shader
*vs
,
193 const struct draw_vs_varient_key
*key
);
197 static INLINE
int draw_vs_varient_keysize( const struct draw_vs_varient_key
*key
)
199 return 2 * sizeof(int) + key
->nr_elements
* sizeof(struct draw_varient_element
);
202 static INLINE
int draw_vs_varient_key_compare( const struct draw_vs_varient_key
*a
,
203 const struct draw_vs_varient_key
*b
)
205 int keysize
= draw_vs_varient_keysize(a
);
206 return memcmp(a
, b
, keysize
);
210 struct aos_machine
*draw_vs_aos_machine( void );
211 void draw_vs_aos_machine_destroy( struct aos_machine
*machine
);
213 void draw_vs_aos_machine_constants( struct aos_machine
*machine
,
214 const float (*constants
)[4] );
216 void draw_vs_aos_machine_viewport( struct aos_machine
*machine
,
217 const struct pipe_viewport_state
*viewport
);
220 #define MAX_TGSI_VERTICES 4