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 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
34 #include "pipe/p_util.h"
35 #include "pipe/p_shader_tokens.h"
36 #include "draw_private.h"
37 #include "draw_context.h"
39 #include "translate/translate.h"
40 #include "translate/translate_cache.h"
44 struct draw_vertex_shader
*
45 draw_create_vertex_shader(struct draw_context
*draw
,
46 const struct pipe_shader_state
*shader
)
48 struct draw_vertex_shader
*vs
;
50 vs
= draw_create_vs_llvm( draw
, shader
);
52 vs
= draw_create_vs_sse( draw
, shader
);
54 vs
= draw_create_vs_exec( draw
, shader
);
64 draw_bind_vertex_shader(struct draw_context
*draw
,
65 struct draw_vertex_shader
*dvs
)
67 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
71 draw
->vs
.vertex_shader
= dvs
;
72 draw
->vs
.num_vs_outputs
= dvs
->info
.num_outputs
;
73 dvs
->prepare( dvs
, draw
);
76 draw
->vs
.vertex_shader
= NULL
;
77 draw
->vs
.num_vs_outputs
= 0;
83 draw_delete_vertex_shader(struct draw_context
*draw
,
84 struct draw_vertex_shader
*dvs
)
92 draw_vs_init( struct draw_context
*draw
)
94 tgsi_exec_machine_init(&draw
->vs
.machine
);
96 /* FIXME: give this machine thing a proper constructor:
98 draw
->vs
.machine
.Inputs
= align_malloc(PIPE_MAX_ATTRIBS
* sizeof(struct tgsi_exec_vector
), 16);
99 if (!draw
->vs
.machine
.Inputs
)
102 draw
->vs
.machine
.Outputs
= align_malloc(PIPE_MAX_ATTRIBS
* sizeof(struct tgsi_exec_vector
), 16);
103 if (!draw
->vs
.machine
.Outputs
)
106 draw
->vs
.emit_cache
= translate_cache_create();
107 if (!draw
->vs
.emit_cache
)
110 draw
->vs
.fetch_cache
= translate_cache_create();
111 if (!draw
->vs
.fetch_cache
)
118 draw_vs_destroy( struct draw_context
*draw
)
120 if (draw
->vs
.machine
.Inputs
)
121 align_free(draw
->vs
.machine
.Inputs
);
123 if (draw
->vs
.machine
.Outputs
)
124 align_free(draw
->vs
.machine
.Outputs
);
126 if (draw
->vs
.fetch_cache
)
127 translate_cache_destroy(draw
->vs
.fetch_cache
);
129 if (draw
->vs
.emit_cache
)
130 translate_cache_destroy(draw
->vs
.emit_cache
);
132 tgsi_exec_machine_free_data(&draw
->vs
.machine
);
137 struct draw_vs_varient
*
138 draw_vs_lookup_varient( struct draw_vertex_shader
*vs
,
139 const struct draw_vs_varient_key
*key
)
141 struct draw_vs_varient
*varient
;
144 /* Lookup existing varient:
146 for (i
= 0; i
< vs
->nr_varients
; i
++)
147 if (draw_vs_varient_key_compare(key
, &vs
->varient
[i
]->key
) == 0)
148 return vs
->varient
[i
];
150 /* Else have to create a new one:
152 varient
= vs
->create_varient( vs
, key
);
156 /* Add it to our list:
158 assert(vs
->nr_varients
< Elements(vs
->varient
));
159 vs
->varient
[vs
->nr_varients
++] = varient
;
168 draw_vs_get_fetch( struct draw_context
*draw
,
169 struct translate_key
*key
)
171 if (!draw
->vs
.fetch
||
172 translate_key_compare(&draw
->vs
.fetch
->key
, key
) != 0)
174 translate_key_sanitize(key
);
175 draw
->vs
.fetch
= translate_cache_find(draw
->vs
.fetch_cache
, key
);
178 return draw
->vs
.fetch
;
182 draw_vs_get_emit( struct draw_context
*draw
,
183 struct translate_key
*key
)
185 if (!draw
->vs
.emit
||
186 translate_key_compare(&draw
->vs
.emit
->key
, key
) != 0)
188 translate_key_sanitize(key
);
189 draw
->vs
.emit
= translate_cache_find(draw
->vs
.emit_cache
, key
);
192 return draw
->vs
.emit
;