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
*,
85 void (PIPE_CDECL
*run_linear
)( struct draw_vs_varient
*shader
,
88 void *output_buffer
);
90 void (PIPE_CDECL
*run_elts
)( struct draw_vs_varient
*shader
,
93 void *output_buffer
);
95 void (*destroy
)( struct draw_vs_varient
* );
100 * Private version of the compiled vertex_shader
102 struct draw_vertex_shader
{
103 struct draw_context
*draw
;
105 /* This member will disappear shortly:
107 struct pipe_shader_state state
;
109 struct tgsi_shader_info info
;
110 unsigned position_output
;
111 unsigned edgeflag_output
;
113 /* Extracted from shader:
115 const float (*immediates
)[4];
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
);
126 void (*prepare
)( struct draw_vertex_shader
*shader
,
127 struct draw_context
*draw
);
129 /* Run the shader - this interface will get cleaned up in the
132 void (*run_linear
)( struct draw_vertex_shader
*shader
,
133 const float (*input
)[4],
135 const void *constants
[PIPE_MAX_CONSTANT_BUFFERS
],
137 unsigned input_stride
,
138 unsigned output_stride
);
141 void (*delete)( struct draw_vertex_shader
* );
145 struct draw_vs_varient
*
146 draw_vs_lookup_varient( struct draw_vertex_shader
*base
,
147 const struct draw_vs_varient_key
*key
);
150 /********************************************************************************
151 * Internal functions:
154 struct draw_vertex_shader
*
155 draw_create_vs_exec(struct draw_context
*draw
,
156 const struct pipe_shader_state
*templ
);
158 struct draw_vertex_shader
*
159 draw_create_vs_sse(struct draw_context
*draw
,
160 const struct pipe_shader_state
*templ
);
162 struct draw_vertex_shader
*
163 draw_create_vs_ppc(struct draw_context
*draw
,
164 const struct pipe_shader_state
*templ
);
166 struct draw_vertex_shader
*
167 draw_create_vs_llvm(struct draw_context
*draw
,
168 const struct pipe_shader_state
*templ
);
172 struct draw_vs_varient_key
;
173 struct draw_vertex_shader
;
175 struct draw_vs_varient
*draw_vs_varient_aos_sse( struct draw_vertex_shader
*vs
,
176 const struct draw_vs_varient_key
*key
);
180 /********************************************************************************
181 * Helpers for vs implementations that don't do their own fetch/emit varients.
182 * Means these can be shared between shaders.
185 struct translate_key
;
187 struct translate
*draw_vs_get_fetch( struct draw_context
*draw
,
188 struct translate_key
*key
);
191 struct translate
*draw_vs_get_emit( struct draw_context
*draw
,
192 struct translate_key
*key
);
194 struct draw_vs_varient
*draw_vs_varient_generic( struct draw_vertex_shader
*vs
,
195 const struct draw_vs_varient_key
*key
);
199 static INLINE
int draw_vs_varient_keysize( const struct draw_vs_varient_key
*key
)
201 return 2 * sizeof(int) + key
->nr_elements
* sizeof(struct draw_varient_element
);
204 static INLINE
int draw_vs_varient_key_compare( const struct draw_vs_varient_key
*a
,
205 const struct draw_vs_varient_key
*b
)
207 int keysize
= draw_vs_varient_keysize(a
);
208 return memcmp(a
, b
, keysize
);
212 struct aos_machine
*draw_vs_aos_machine( void );
213 void draw_vs_aos_machine_destroy( struct aos_machine
*machine
);
216 draw_vs_aos_machine_constants(struct aos_machine
*machine
,
218 const void *constants
);
220 void draw_vs_aos_machine_viewport( struct aos_machine
*machine
,
221 const struct pipe_viewport_state
*viewport
);
224 #define MAX_TGSI_VERTICES 4