1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
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 VMWARE 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 <keithw@vmware.com>
34 #include "draw_context.h"
35 #include "draw_private.h"
36 #include "draw_vertex.h"
40 struct pipe_shader_state
;
42 struct draw_variant_input
44 enum pipe_format format
;
47 unsigned instance_divisor
;
50 struct draw_variant_output
52 enum attrib_emit format
; /* output format */
53 unsigned vs_output
:8; /* which vertex shader output is this? */
54 unsigned offset
:24; /* offset into output vertex */
57 struct draw_variant_element
{
58 struct draw_variant_input in
;
59 struct draw_variant_output out
;
62 struct draw_vs_variant_key
{
63 unsigned output_stride
;
64 unsigned nr_elements
:8; /* max2(nr_inputs, nr_outputs) */
66 unsigned nr_outputs
:8;
69 unsigned const_vbuffers
:5;
70 struct draw_variant_element element
[PIPE_MAX_ATTRIBS
];
73 struct draw_vs_variant
;
76 struct draw_vs_variant
{
77 struct draw_vs_variant_key key
;
79 struct draw_vertex_shader
*vs
;
81 void (*set_buffer
)( struct draw_vs_variant
*,
85 unsigned max_stride
);
87 void (PIPE_CDECL
*run_linear
)( struct draw_vs_variant
*shader
,
90 void *output_buffer
);
92 void (PIPE_CDECL
*run_elts
)( struct draw_vs_variant
*shader
,
95 void *output_buffer
);
97 void (*destroy
)( struct draw_vs_variant
* );
102 * Private version of the compiled vertex_shader
104 struct draw_vertex_shader
{
105 struct draw_context
*draw
;
107 /* This member will disappear shortly:
109 struct pipe_shader_state state
;
111 struct tgsi_shader_info info
;
112 unsigned position_output
;
113 unsigned viewport_index_output
;
114 unsigned edgeflag_output
;
115 unsigned clipvertex_output
;
116 unsigned ccdistance_output
[PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT
];
117 /* Extracted from shader:
119 const float (*immediates
)[4];
123 struct draw_vs_variant
*variant
[16];
124 unsigned nr_variants
;
125 unsigned last_variant
;
126 struct draw_vs_variant
*(*create_variant
)( struct draw_vertex_shader
*shader
,
127 const struct draw_vs_variant_key
*key
);
130 void (*prepare
)( struct draw_vertex_shader
*shader
,
131 struct draw_context
*draw
);
133 /* Run the shader - this interface will get cleaned up in the
136 void (*run_linear
)( struct draw_vertex_shader
*shader
,
137 const float (*input
)[4],
139 const void *constants
[PIPE_MAX_CONSTANT_BUFFERS
],
140 const unsigned const_size
[PIPE_MAX_CONSTANT_BUFFERS
],
142 unsigned input_stride
,
143 unsigned output_stride
);
146 void (*delete)( struct draw_vertex_shader
* );
150 struct draw_vs_variant
*
151 draw_vs_lookup_variant( struct draw_vertex_shader
*base
,
152 const struct draw_vs_variant_key
*key
);
155 /********************************************************************************
156 * Internal functions:
159 struct draw_vertex_shader
*
160 draw_create_vs_exec(struct draw_context
*draw
,
161 const struct pipe_shader_state
*templ
);
163 struct draw_vs_variant_key
;
164 struct draw_vertex_shader
;
167 struct draw_vertex_shader
*
168 draw_create_vs_llvm(struct draw_context
*draw
,
169 const struct pipe_shader_state
*state
);
173 /********************************************************************************
174 * Helpers for vs implementations that don't do their own fetch/emit variants.
175 * Means these can be shared between shaders.
178 struct translate_key
;
180 struct translate
*draw_vs_get_fetch( struct draw_context
*draw
,
181 struct translate_key
*key
);
184 struct translate
*draw_vs_get_emit( struct draw_context
*draw
,
185 struct translate_key
*key
);
187 struct draw_vs_variant
*
188 draw_vs_create_variant_generic( struct draw_vertex_shader
*vs
,
189 const struct draw_vs_variant_key
*key
);
193 static inline int draw_vs_variant_keysize( const struct draw_vs_variant_key
*key
)
195 return 2 * sizeof(int) + key
->nr_elements
* sizeof(struct draw_variant_element
);
198 static inline int draw_vs_variant_key_compare( const struct draw_vs_variant_key
*a
,
199 const struct draw_vs_variant_key
*b
)
201 int keysize
= draw_vs_variant_keysize(a
);
202 return memcmp(a
, b
, keysize
);
206 #define MAX_TGSI_VERTICES 4