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 **************************************************************************/
31 * Keith Whitwell <keith@tungstengraphics.com>
35 #include "util/u_memory.h"
36 #include "pipe/p_shader_tokens.h"
37 #include "draw_private.h"
38 #include "draw_context.h"
41 #include "tgsi/tgsi_parse.h"
45 #include "gallivm/gallivm.h"
47 struct draw_llvm_vertex_shader
{
48 struct draw_vertex_shader base
;
49 struct gallivm_prog
*llvm_prog
;
50 struct tgsi_exec_machine
*machine
;
55 vs_llvm_prepare( struct draw_vertex_shader
*base
,
56 struct draw_context
*draw
)
64 vs_llvm_run_linear( struct draw_vertex_shader
*base
,
65 const float (*input
)[4],
67 const void *constants
[PIPE_MAX_CONSTANT_BUFFERS
],
69 unsigned input_stride
,
70 unsigned output_stride
)
72 struct draw_llvm_vertex_shader
*shader
=
73 (struct draw_llvm_vertex_shader
*)base
;
75 gallivm_cpu_vs_exec(shader
->llvm_prog
, shader
->machine
,
76 input
, base
->info
.num_inputs
, output
, base
->info
.num_outputs
,
77 (const float (*)[4])constants
[0],
78 count
, input_stride
, output_stride
);
84 vs_llvm_delete( struct draw_vertex_shader
*base
)
86 struct draw_llvm_vertex_shader
*shader
=
87 (struct draw_llvm_vertex_shader
*)base
;
89 /* Do something to free compiled shader:
92 FREE( (void*) shader
->base
.state
.tokens
);
99 struct draw_vertex_shader
*
100 draw_create_vs_llvm(struct draw_context
*draw
,
101 const struct pipe_shader_state
*templ
)
103 struct draw_llvm_vertex_shader
*vs
;
105 vs
= CALLOC_STRUCT( draw_llvm_vertex_shader
);
109 /* we make a private copy of the tokens */
110 vs
->base
.state
.tokens
= tgsi_dup_tokens(templ
->tokens
);
111 if (!vs
->base
.state
.tokens
) {
116 tgsi_scan_shader(vs
->base
.state
.tokens
, &vs
->base
.info
);
118 vs
->base
.draw
= draw
;
119 vs
->base
.prepare
= vs_llvm_prepare
;
120 vs
->base
.create_varient
= draw_vs_varient_generic
;
121 vs
->base
.run_linear
= vs_llvm_run_linear
;
122 vs
->base
.delete = vs_llvm_delete
;
123 vs
->machine
= draw
->vs
.machine
;
126 struct gallivm_ir
*ir
= gallivm_ir_new(GALLIVM_VS
);
127 gallivm_ir_set_layout(ir
, GALLIVM_SOA
);
128 gallivm_ir_set_components(ir
, 4);
129 gallivm_ir_fill_from_tgsi(ir
, vs
->base
.state
.tokens
);
130 vs
->llvm_prog
= gallivm_ir_compile(ir
);
131 gallivm_ir_delete(ir
);
134 draw
->vs
.engine
= gallivm_global_cpu_engine();
136 /* XXX: Why are there two versions of this? Shouldn't creating the
137 * engine be a separate operation to compiling a shader?
139 if (!draw
->vs
.engine
) {
140 draw
->vs
.engine
= gallivm_cpu_engine_create(vs
->llvm_prog
);
143 gallivm_cpu_jit_compile(draw
->vs
.engine
, vs
->llvm_prog
);
155 struct draw_vertex_shader
*
156 draw_create_vs_llvm(struct draw_context
*draw
,
157 const struct pipe_shader_state
*shader
)