9ad1e052c6c01bc2ac53cfb32318d33d3b280739
[mesa.git] / src / gallium / auxiliary / vl / vl_shader_build.c
1 #include "vl_shader_build.h"
2 #include <assert.h>
3 #include <tgsi/tgsi_parse.h>
4 #include <tgsi/tgsi_build.h>
5
6 struct tgsi_full_declaration vl_decl_input(unsigned int name, unsigned int index, unsigned int first, unsigned int last)
7 {
8 struct tgsi_full_declaration decl = tgsi_default_full_declaration();
9
10 decl.Declaration.File = TGSI_FILE_INPUT;
11 decl.Declaration.Semantic = 1;
12 decl.Semantic.SemanticName = name;
13 decl.Semantic.SemanticIndex = index;
14 decl.DeclarationRange.First = first;
15 decl.DeclarationRange.Last = last;
16
17 return decl;
18 }
19
20 struct tgsi_full_declaration vl_decl_interpolated_input
21 (
22 unsigned int name,
23 unsigned int index,
24 unsigned int first,
25 unsigned int last,
26 int interpolation
27 )
28 {
29 struct tgsi_full_declaration decl = tgsi_default_full_declaration();
30
31 assert
32 (
33 interpolation == TGSI_INTERPOLATE_CONSTANT ||
34 interpolation == TGSI_INTERPOLATE_LINEAR ||
35 interpolation == TGSI_INTERPOLATE_PERSPECTIVE
36 );
37
38 decl.Declaration.File = TGSI_FILE_INPUT;
39 decl.Declaration.Semantic = 1;
40 decl.Semantic.SemanticName = name;
41 decl.Semantic.SemanticIndex = index;
42 decl.Declaration.Interpolate = interpolation;;
43 decl.DeclarationRange.First = first;
44 decl.DeclarationRange.Last = last;
45
46 return decl;
47 }
48
49 struct tgsi_full_declaration vl_decl_constants(unsigned int name, unsigned int index, unsigned int first, unsigned int last)
50 {
51 struct tgsi_full_declaration decl = tgsi_default_full_declaration();
52
53 decl.Declaration.File = TGSI_FILE_CONSTANT;
54 decl.Declaration.Semantic = 1;
55 decl.Semantic.SemanticName = name;
56 decl.Semantic.SemanticIndex = index;
57 decl.DeclarationRange.First = first;
58 decl.DeclarationRange.Last = last;
59
60 return decl;
61 }
62
63 struct tgsi_full_declaration vl_decl_output(unsigned int name, unsigned int index, unsigned int first, unsigned int last)
64 {
65 struct tgsi_full_declaration decl = tgsi_default_full_declaration();
66
67 decl.Declaration.File = TGSI_FILE_OUTPUT;
68 decl.Declaration.Semantic = 1;
69 decl.Semantic.SemanticName = name;
70 decl.Semantic.SemanticIndex = index;
71 decl.DeclarationRange.First = first;
72 decl.DeclarationRange.Last = last;
73
74 return decl;
75 }
76
77 struct tgsi_full_declaration vl_decl_temps(unsigned int first, unsigned int last)
78 {
79 struct tgsi_full_declaration decl = tgsi_default_full_declaration();
80
81 decl = tgsi_default_full_declaration();
82 decl.Declaration.File = TGSI_FILE_TEMPORARY;
83 decl.DeclarationRange.First = first;
84 decl.DeclarationRange.Last = last;
85
86 return decl;
87 }
88
89 struct tgsi_full_declaration vl_decl_samplers(unsigned int first, unsigned int last)
90 {
91 struct tgsi_full_declaration decl = tgsi_default_full_declaration();
92
93 decl = tgsi_default_full_declaration();
94 decl.Declaration.File = TGSI_FILE_SAMPLER;
95 decl.DeclarationRange.First = first;
96 decl.DeclarationRange.Last = last;
97
98 return decl;
99 }
100
101 struct tgsi_full_instruction vl_inst2
102 (
103 int opcode,
104 enum tgsi_file_type dst_file,
105 unsigned int dst_index,
106 enum tgsi_file_type src_file,
107 unsigned int src_index
108 )
109 {
110 struct tgsi_full_instruction inst = tgsi_default_full_instruction();
111
112 inst.Instruction.Opcode = opcode;
113 inst.Instruction.NumDstRegs = 1;
114 inst.FullDstRegisters[0].DstRegister.File = dst_file;
115 inst.FullDstRegisters[0].DstRegister.Index = dst_index;
116 inst.Instruction.NumSrcRegs = 1;
117 inst.FullSrcRegisters[0].SrcRegister.File = src_file;
118 inst.FullSrcRegisters[0].SrcRegister.Index = src_index;
119
120 return inst;
121 }
122
123 struct tgsi_full_instruction vl_inst3
124 (
125 int opcode,
126 enum tgsi_file_type dst_file,
127 unsigned int dst_index,
128 enum tgsi_file_type src1_file,
129 unsigned int src1_index,
130 enum tgsi_file_type src2_file,
131 unsigned int src2_index
132 )
133 {
134 struct tgsi_full_instruction inst = tgsi_default_full_instruction();
135
136 inst.Instruction.Opcode = opcode;
137 inst.Instruction.NumDstRegs = 1;
138 inst.FullDstRegisters[0].DstRegister.File = dst_file;
139 inst.FullDstRegisters[0].DstRegister.Index = dst_index;
140 inst.Instruction.NumSrcRegs = 2;
141 inst.FullSrcRegisters[0].SrcRegister.File = src1_file;
142 inst.FullSrcRegisters[0].SrcRegister.Index = src1_index;
143 inst.FullSrcRegisters[1].SrcRegister.File = src2_file;
144 inst.FullSrcRegisters[1].SrcRegister.Index = src2_index;
145
146 return inst;
147 }
148
149 struct tgsi_full_instruction vl_tex
150 (
151 int tex,
152 enum tgsi_file_type dst_file,
153 unsigned int dst_index,
154 enum tgsi_file_type src1_file,
155 unsigned int src1_index,
156 enum tgsi_file_type src2_file,
157 unsigned int src2_index
158 )
159 {
160 struct tgsi_full_instruction inst = tgsi_default_full_instruction();
161
162 inst.Instruction.Opcode = TGSI_OPCODE_TEX;
163 inst.Instruction.NumDstRegs = 1;
164 inst.FullDstRegisters[0].DstRegister.File = dst_file;
165 inst.FullDstRegisters[0].DstRegister.Index = dst_index;
166 inst.Instruction.NumSrcRegs = 2;
167 inst.InstructionExtTexture.Texture = tex;
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_inst4
177 (
178 int opcode,
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 enum tgsi_file_type src3_file,
186 unsigned int src3_index
187 )
188 {
189 struct tgsi_full_instruction inst = tgsi_default_full_instruction();
190
191 inst.Instruction.Opcode = opcode;
192 inst.Instruction.NumDstRegs = 1;
193 inst.FullDstRegisters[0].DstRegister.File = dst_file;
194 inst.FullDstRegisters[0].DstRegister.Index = dst_index;
195 inst.Instruction.NumSrcRegs = 3;
196 inst.FullSrcRegisters[0].SrcRegister.File = src1_file;
197 inst.FullSrcRegisters[0].SrcRegister.Index = src1_index;
198 inst.FullSrcRegisters[1].SrcRegister.File = src2_file;
199 inst.FullSrcRegisters[1].SrcRegister.Index = src2_index;
200 inst.FullSrcRegisters[2].SrcRegister.File = src3_file;
201 inst.FullSrcRegisters[2].SrcRegister.Index = src3_index;
202
203 return inst;
204 }
205
206 struct tgsi_full_instruction vl_end(void)
207 {
208 struct tgsi_full_instruction inst = tgsi_default_full_instruction();
209
210 inst.Instruction.Opcode = TGSI_OPCODE_END;
211 inst.Instruction.NumDstRegs = 0;
212 inst.Instruction.NumSrcRegs = 0;
213
214 return inst;
215 }