Merge branch 'mesa_7_7_branch'
[mesa.git] / src / gallium / auxiliary / vl / vl_shader_build.c
1 /**************************************************************************
2 *
3 * Copyright 2009 Younes Manton.
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 #include "vl_shader_build.h"
29 #include <assert.h>
30 #include <tgsi/tgsi_parse.h>
31 #include <tgsi/tgsi_build.h>
32
33 struct tgsi_full_declaration vl_decl_input(unsigned int name, unsigned int index, unsigned int first, unsigned int last)
34 {
35 struct tgsi_full_declaration decl = tgsi_default_full_declaration();
36
37 decl.Declaration.File = TGSI_FILE_INPUT;
38 decl.Declaration.Semantic = 1;
39 decl.Semantic.Name = name;
40 decl.Semantic.Index = index;
41 decl.Range.First = first;
42 decl.Range.Last = last;
43
44 return decl;
45 }
46
47 struct tgsi_full_declaration vl_decl_interpolated_input
48 (
49 unsigned int name,
50 unsigned int index,
51 unsigned int first,
52 unsigned int last,
53 int interpolation
54 )
55 {
56 struct tgsi_full_declaration decl = tgsi_default_full_declaration();
57
58 assert
59 (
60 interpolation == TGSI_INTERPOLATE_CONSTANT ||
61 interpolation == TGSI_INTERPOLATE_LINEAR ||
62 interpolation == TGSI_INTERPOLATE_PERSPECTIVE
63 );
64
65 decl.Declaration.File = TGSI_FILE_INPUT;
66 decl.Declaration.Semantic = 1;
67 decl.Semantic.Name = name;
68 decl.Semantic.Index = index;
69 decl.Declaration.Interpolate = interpolation;;
70 decl.Range.First = first;
71 decl.Range.Last = last;
72
73 return decl;
74 }
75
76 struct tgsi_full_declaration vl_decl_constants(unsigned int name, unsigned int index, unsigned int first, unsigned int last)
77 {
78 struct tgsi_full_declaration decl = tgsi_default_full_declaration();
79
80 decl.Declaration.File = TGSI_FILE_CONSTANT;
81 decl.Declaration.Semantic = 1;
82 decl.Semantic.Name = name;
83 decl.Semantic.Index = index;
84 decl.Range.First = first;
85 decl.Range.Last = last;
86
87 return decl;
88 }
89
90 struct tgsi_full_declaration vl_decl_output(unsigned int name, unsigned int index, unsigned int first, unsigned int last)
91 {
92 struct tgsi_full_declaration decl = tgsi_default_full_declaration();
93
94 decl.Declaration.File = TGSI_FILE_OUTPUT;
95 decl.Declaration.Semantic = 1;
96 decl.Semantic.Name = name;
97 decl.Semantic.Index = index;
98 decl.Range.First = first;
99 decl.Range.Last = last;
100
101 return decl;
102 }
103
104 struct tgsi_full_declaration vl_decl_temps(unsigned int first, unsigned int last)
105 {
106 struct tgsi_full_declaration decl = tgsi_default_full_declaration();
107
108 decl = tgsi_default_full_declaration();
109 decl.Declaration.File = TGSI_FILE_TEMPORARY;
110 decl.Range.First = first;
111 decl.Range.Last = last;
112
113 return decl;
114 }
115
116 struct tgsi_full_declaration vl_decl_samplers(unsigned int first, unsigned int last)
117 {
118 struct tgsi_full_declaration decl = tgsi_default_full_declaration();
119
120 decl = tgsi_default_full_declaration();
121 decl.Declaration.File = TGSI_FILE_SAMPLER;
122 decl.Range.First = first;
123 decl.Range.Last = last;
124
125 return decl;
126 }
127
128 struct tgsi_full_instruction vl_inst2
129 (
130 int opcode,
131 enum tgsi_file_type dst_file,
132 unsigned int dst_index,
133 enum tgsi_file_type src_file,
134 unsigned int src_index
135 )
136 {
137 struct tgsi_full_instruction inst = tgsi_default_full_instruction();
138
139 inst.Instruction.Opcode = opcode;
140 inst.Instruction.NumDstRegs = 1;
141 inst.Dst[0].Register.File = dst_file;
142 inst.Dst[0].Register.Index = dst_index;
143 inst.Instruction.NumSrcRegs = 1;
144 inst.Src[0].Register.File = src_file;
145 inst.Src[0].Register.Index = src_index;
146
147 return inst;
148 }
149
150 struct tgsi_full_instruction vl_inst3
151 (
152 int opcode,
153 enum tgsi_file_type dst_file,
154 unsigned int dst_index,
155 enum tgsi_file_type src1_file,
156 unsigned int src1_index,
157 enum tgsi_file_type src2_file,
158 unsigned int src2_index
159 )
160 {
161 struct tgsi_full_instruction inst = tgsi_default_full_instruction();
162
163 inst.Instruction.Opcode = opcode;
164 inst.Instruction.NumDstRegs = 1;
165 inst.Dst[0].Register.File = dst_file;
166 inst.Dst[0].Register.Index = dst_index;
167 inst.Instruction.NumSrcRegs = 2;
168 inst.Src[0].Register.File = src1_file;
169 inst.Src[0].Register.Index = src1_index;
170 inst.Src[1].Register.File = src2_file;
171 inst.Src[1].Register.Index = src2_index;
172
173 return inst;
174 }
175
176 struct tgsi_full_instruction vl_tex
177 (
178 int tex,
179 enum tgsi_file_type dst_file,
180 unsigned int dst_index,
181 enum tgsi_file_type src1_file,
182 unsigned int src1_index,
183 enum tgsi_file_type src2_file,
184 unsigned int src2_index
185 )
186 {
187 struct tgsi_full_instruction inst = tgsi_default_full_instruction();
188
189 inst.Instruction.Opcode = TGSI_OPCODE_TEX;
190 inst.Instruction.NumDstRegs = 1;
191 inst.Dst[0].Register.File = dst_file;
192 inst.Dst[0].Register.Index = dst_index;
193 inst.Instruction.NumSrcRegs = 2;
194 inst.Instruction.Texture = 1;
195 inst.Texture.Texture = tex;
196 inst.Src[0].Register.File = src1_file;
197 inst.Src[0].Register.Index = src1_index;
198 inst.Src[1].Register.File = src2_file;
199 inst.Src[1].Register.Index = src2_index;
200
201 return inst;
202 }
203
204 struct tgsi_full_instruction vl_inst4
205 (
206 int opcode,
207 enum tgsi_file_type dst_file,
208 unsigned int dst_index,
209 enum tgsi_file_type src1_file,
210 unsigned int src1_index,
211 enum tgsi_file_type src2_file,
212 unsigned int src2_index,
213 enum tgsi_file_type src3_file,
214 unsigned int src3_index
215 )
216 {
217 struct tgsi_full_instruction inst = tgsi_default_full_instruction();
218
219 inst.Instruction.Opcode = opcode;
220 inst.Instruction.NumDstRegs = 1;
221 inst.Dst[0].Register.File = dst_file;
222 inst.Dst[0].Register.Index = dst_index;
223 inst.Instruction.NumSrcRegs = 3;
224 inst.Src[0].Register.File = src1_file;
225 inst.Src[0].Register.Index = src1_index;
226 inst.Src[1].Register.File = src2_file;
227 inst.Src[1].Register.Index = src2_index;
228 inst.Src[2].Register.File = src3_file;
229 inst.Src[2].Register.Index = src3_index;
230
231 return inst;
232 }
233
234 struct tgsi_full_instruction vl_end(void)
235 {
236 struct tgsi_full_instruction inst = tgsi_default_full_instruction();
237
238 inst.Instruction.Opcode = TGSI_OPCODE_END;
239 inst.Instruction.NumDstRegs = 0;
240 inst.Instruction.NumSrcRegs = 0;
241
242 return inst;
243 }