Merge branch 'mesa_7_6_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.SemanticName = name;
40 decl.Semantic.SemanticIndex = index;
41 decl.DeclarationRange.First = first;
42 decl.DeclarationRange.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.SemanticName = name;
68 decl.Semantic.SemanticIndex = index;
69 decl.Declaration.Interpolate = interpolation;;
70 decl.DeclarationRange.First = first;
71 decl.DeclarationRange.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.SemanticName = name;
83 decl.Semantic.SemanticIndex = index;
84 decl.DeclarationRange.First = first;
85 decl.DeclarationRange.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.SemanticName = name;
97 decl.Semantic.SemanticIndex = index;
98 decl.DeclarationRange.First = first;
99 decl.DeclarationRange.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.DeclarationRange.First = first;
111 decl.DeclarationRange.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.DeclarationRange.First = first;
123 decl.DeclarationRange.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.FullDstRegisters[0].DstRegister.File = dst_file;
142 inst.FullDstRegisters[0].DstRegister.Index = dst_index;
143 inst.Instruction.NumSrcRegs = 1;
144 inst.FullSrcRegisters[0].SrcRegister.File = src_file;
145 inst.FullSrcRegisters[0].SrcRegister.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.FullDstRegisters[0].DstRegister.File = dst_file;
166 inst.FullDstRegisters[0].DstRegister.Index = dst_index;
167 inst.Instruction.NumSrcRegs = 2;
168 inst.FullSrcRegisters[0].SrcRegister.File = src1_file;
169 inst.FullSrcRegisters[0].SrcRegister.Index = src1_index;
170 inst.FullSrcRegisters[1].SrcRegister.File = src2_file;
171 inst.FullSrcRegisters[1].SrcRegister.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.FullDstRegisters[0].DstRegister.File = dst_file;
192 inst.FullDstRegisters[0].DstRegister.Index = dst_index;
193 inst.Instruction.NumSrcRegs = 2;
194 inst.InstructionExtTexture.Texture = tex;
195 inst.FullSrcRegisters[0].SrcRegister.File = src1_file;
196 inst.FullSrcRegisters[0].SrcRegister.Index = src1_index;
197 inst.FullSrcRegisters[1].SrcRegister.File = src2_file;
198 inst.FullSrcRegisters[1].SrcRegister.Index = src2_index;
199
200 return inst;
201 }
202
203 struct tgsi_full_instruction vl_inst4
204 (
205 int opcode,
206 enum tgsi_file_type dst_file,
207 unsigned int dst_index,
208 enum tgsi_file_type src1_file,
209 unsigned int src1_index,
210 enum tgsi_file_type src2_file,
211 unsigned int src2_index,
212 enum tgsi_file_type src3_file,
213 unsigned int src3_index
214 )
215 {
216 struct tgsi_full_instruction inst = tgsi_default_full_instruction();
217
218 inst.Instruction.Opcode = opcode;
219 inst.Instruction.NumDstRegs = 1;
220 inst.FullDstRegisters[0].DstRegister.File = dst_file;
221 inst.FullDstRegisters[0].DstRegister.Index = dst_index;
222 inst.Instruction.NumSrcRegs = 3;
223 inst.FullSrcRegisters[0].SrcRegister.File = src1_file;
224 inst.FullSrcRegisters[0].SrcRegister.Index = src1_index;
225 inst.FullSrcRegisters[1].SrcRegister.File = src2_file;
226 inst.FullSrcRegisters[1].SrcRegister.Index = src2_index;
227 inst.FullSrcRegisters[2].SrcRegister.File = src3_file;
228 inst.FullSrcRegisters[2].SrcRegister.Index = src3_index;
229
230 return inst;
231 }
232
233 struct tgsi_full_instruction vl_end(void)
234 {
235 struct tgsi_full_instruction inst = tgsi_default_full_instruction();
236
237 inst.Instruction.Opcode = TGSI_OPCODE_END;
238 inst.Instruction.NumDstRegs = 0;
239 inst.Instruction.NumSrcRegs = 0;
240
241 return inst;
242 }