Merge commit 'origin/gallium-master-merge'
[mesa.git] / src / gallium / auxiliary / gallivm / gallivm.h
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 /*
29 * Authors:
30 * Zack Rusin zack@tungstengraphics.com
31 */
32
33 #ifndef GALLIVM_H
34 #define GALLIVM_H
35
36 /*
37 LLVM representation consists of two stages - layout independent
38 intermediate representation gallivm_ir and driver specific
39 gallivm_prog. TGSI is first being translated into gallivm_ir
40 after that driver can set number of options on gallivm_ir and
41 have it compiled into gallivm_prog. gallivm_prog can be either
42 executed (assuming there's LLVM JIT backend for the current
43 target) or machine code generation can be done (assuming there's
44 a LLVM code generator for thecurrent target)
45 */
46 #if defined __cplusplus
47 extern "C" {
48 #endif
49
50 #include "pipe/p_state.h"
51
52 #ifdef MESA_LLVM
53
54 struct tgsi_token;
55
56 struct gallivm_ir;
57 struct gallivm_prog;
58 struct gallivm_cpu_engine;
59 struct tgsi_interp_coef;
60 struct tgsi_sampler;
61 struct tgsi_exec_vector;
62
63 enum gallivm_shader_type {
64 GALLIVM_VS,
65 GALLIVM_FS
66 };
67
68 enum gallivm_vector_layout {
69 GALLIVM_AOS,
70 GALLIVM_SOA
71 };
72
73 struct gallivm_ir *gallivm_ir_new(enum gallivm_shader_type type);
74 void gallivm_ir_set_layout(struct gallivm_ir *ir,
75 enum gallivm_vector_layout layout);
76 void gallivm_ir_set_components(struct gallivm_ir *ir, int num);
77 void gallivm_ir_fill_from_tgsi(struct gallivm_ir *ir,
78 const struct tgsi_token *tokens);
79 void gallivm_ir_delete(struct gallivm_ir *ir);
80
81
82 struct gallivm_prog *gallivm_ir_compile(struct gallivm_ir *ir);
83
84 void gallivm_prog_inputs_interpolate(struct gallivm_prog *prog,
85 float (*inputs)[PIPE_MAX_SHADER_INPUTS][4],
86 const struct tgsi_interp_coef *coefs);
87 void gallivm_prog_dump(struct gallivm_prog *prog, const char *file_prefix);
88
89
90 struct gallivm_cpu_engine *gallivm_cpu_engine_create(struct gallivm_prog *prog);
91 struct gallivm_cpu_engine *gallivm_global_cpu_engine();
92 int gallivm_cpu_vs_exec(struct gallivm_prog *prog,
93 struct tgsi_exec_machine *machine,
94 const float (*input)[4],
95 unsigned num_inputs,
96 float (*output)[4],
97 unsigned num_outputs,
98 const float (*constants)[4],
99 unsigned count,
100 unsigned input_stride,
101 unsigned output_stride);
102 int gallivm_cpu_fs_exec(struct gallivm_prog *prog,
103 float x, float y,
104 float (*dests)[PIPE_MAX_SHADER_INPUTS][4],
105 float (*inputs)[PIPE_MAX_SHADER_INPUTS][4],
106 float (*consts)[4],
107 struct tgsi_sampler *samplers);
108 void gallivm_cpu_jit_compile(struct gallivm_cpu_engine *ee, struct gallivm_prog *prog);
109 void gallivm_cpu_engine_delete(struct gallivm_cpu_engine *ee);
110
111
112 #endif /* MESA_LLVM */
113
114 #if defined __cplusplus
115 }
116 #endif
117
118 #endif