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 "util/u_math.h"
35 #include "util/u_memory.h"
37 #include "pipe/p_shader_tokens.h"
39 #include "draw_private.h"
40 #include "draw_context.h"
43 #include "translate/translate.h"
44 #include "translate/translate_cache.h"
46 #include "tgsi/tgsi_exec.h"
51 void draw_vs_set_constants( struct draw_context
*draw
,
52 const float (*constants
)[4],
55 if (((uintptr_t)constants
) & 0xf) {
56 if (size
> draw
->vs
.const_storage_size
) {
57 if (draw
->vs
.aligned_constant_storage
)
58 align_free((void *)draw
->vs
.aligned_constant_storage
);
59 draw
->vs
.aligned_constant_storage
= align_malloc( size
, 16 );
61 memcpy( (void*)draw
->vs
.aligned_constant_storage
,
64 constants
= draw
->vs
.aligned_constant_storage
;
67 draw
->vs
.aligned_constants
= constants
;
68 draw_vs_aos_machine_constants( draw
->vs
.aos_machine
, constants
);
72 void draw_vs_set_viewport( struct draw_context
*draw
,
73 const struct pipe_viewport_state
*viewport
)
75 draw_vs_aos_machine_viewport( draw
->vs
.aos_machine
, viewport
);
80 struct draw_vertex_shader
*
81 draw_create_vertex_shader(struct draw_context
*draw
,
82 const struct pipe_shader_state
*shader
)
84 struct draw_vertex_shader
*vs
;
86 vs
= draw_create_vs_llvm( draw
, shader
);
88 vs
= draw_create_vs_sse( draw
, shader
);
90 vs
= draw_create_vs_ppc( draw
, shader
);
92 vs
= draw_create_vs_exec( draw
, shader
);
100 for (i
= 0; i
< vs
->info
.num_outputs
; i
++) {
101 if (vs
->info
.output_semantic_name
[i
] == TGSI_SEMANTIC_POSITION
&&
102 vs
->info
.output_semantic_index
[i
] == 0)
103 vs
->position_output
= i
;
104 else if (vs
->info
.output_semantic_name
[i
] == TGSI_SEMANTIC_EDGEFLAG
&&
105 vs
->info
.output_semantic_index
[i
] == 0)
106 vs
->edgeflag_output
= i
;
116 draw_bind_vertex_shader(struct draw_context
*draw
,
117 struct draw_vertex_shader
*dvs
)
119 draw_do_flush( draw
, DRAW_FLUSH_STATE_CHANGE
);
123 draw
->vs
.vertex_shader
= dvs
;
124 draw
->vs
.num_vs_outputs
= dvs
->info
.num_outputs
;
125 draw
->vs
.position_output
= dvs
->position_output
;
126 draw
->vs
.edgeflag_output
= dvs
->edgeflag_output
;
127 dvs
->prepare( dvs
, draw
);
130 draw
->vs
.vertex_shader
= NULL
;
131 draw
->vs
.num_vs_outputs
= 0;
137 draw_delete_vertex_shader(struct draw_context
*draw
,
138 struct draw_vertex_shader
*dvs
)
142 for (i
= 0; i
< dvs
->nr_varients
; i
++)
143 dvs
->varient
[i
]->destroy( dvs
->varient
[i
] );
145 dvs
->nr_varients
= 0;
153 draw_vs_init( struct draw_context
*draw
)
155 draw
->vs
.machine
= tgsi_exec_machine_create();
156 if (!draw
->vs
.machine
)
159 draw
->vs
.emit_cache
= translate_cache_create();
160 if (!draw
->vs
.emit_cache
)
163 draw
->vs
.fetch_cache
= translate_cache_create();
164 if (!draw
->vs
.fetch_cache
)
167 draw
->vs
.aos_machine
= draw_vs_aos_machine();
169 if (!draw
->vs
.aos_machine
)
177 draw_vs_destroy( struct draw_context
*draw
)
179 if (draw
->vs
.fetch_cache
)
180 translate_cache_destroy(draw
->vs
.fetch_cache
);
182 if (draw
->vs
.emit_cache
)
183 translate_cache_destroy(draw
->vs
.emit_cache
);
185 if (draw
->vs
.aos_machine
)
186 draw_vs_aos_machine_destroy(draw
->vs
.aos_machine
);
188 if (draw
->vs
.aligned_constant_storage
)
189 align_free((void*)draw
->vs
.aligned_constant_storage
);
191 tgsi_exec_machine_destroy(draw
->vs
.machine
);
195 struct draw_vs_varient
*
196 draw_vs_lookup_varient( struct draw_vertex_shader
*vs
,
197 const struct draw_vs_varient_key
*key
)
199 struct draw_vs_varient
*varient
;
202 /* Lookup existing varient:
204 for (i
= 0; i
< vs
->nr_varients
; i
++)
205 if (draw_vs_varient_key_compare(key
, &vs
->varient
[i
]->key
) == 0)
206 return vs
->varient
[i
];
208 /* Else have to create a new one:
210 varient
= vs
->create_varient( vs
, key
);
214 /* Add it to our list, could be smarter:
216 if (vs
->nr_varients
< Elements(vs
->varient
)) {
217 vs
->varient
[vs
->nr_varients
++] = varient
;
221 vs
->last_varient
%= Elements(vs
->varient
);
222 vs
->varient
[vs
->last_varient
]->destroy(vs
->varient
[vs
->last_varient
]);
223 vs
->varient
[vs
->last_varient
] = varient
;
233 draw_vs_get_fetch( struct draw_context
*draw
,
234 struct translate_key
*key
)
236 if (!draw
->vs
.fetch
||
237 translate_key_compare(&draw
->vs
.fetch
->key
, key
) != 0)
239 translate_key_sanitize(key
);
240 draw
->vs
.fetch
= translate_cache_find(draw
->vs
.fetch_cache
, key
);
243 return draw
->vs
.fetch
;
247 draw_vs_get_emit( struct draw_context
*draw
,
248 struct translate_key
*key
)
250 if (!draw
->vs
.emit
||
251 translate_key_compare(&draw
->vs
.emit
->key
, key
) != 0)
253 translate_key_sanitize(key
);
254 draw
->vs
.emit
= translate_cache_find(draw
->vs
.emit_cache
, key
);
257 return draw
->vs
.emit
;