2 * Copyright © 2010 Intel Corporation
3 * Copyright © 2011 Bryan Cain
4 * Copyright © 2017 Gert Wollny
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
26 #include "st_glsl_to_tgsi_private.h"
27 #include <tgsi/tgsi_info.h>
28 #include <mesa/program/prog_instruction.h>
30 static int swizzle_for_type(const glsl_type
*type
, int component
= 0)
32 unsigned num_elements
= 4;
35 type
= type
->without_array();
36 if (type
->is_scalar() || type
->is_vector() || type
->is_matrix())
37 num_elements
= type
->vector_elements
;
40 int swizzle
= swizzle_for_size(num_elements
);
41 assert(num_elements
+ component
<= 4);
43 swizzle
+= component
* MAKE_SWIZZLE4(1, 1, 1, 1);
48 dup_reladdr(const st_src_reg
*input
)
53 st_src_reg
*reg
= ralloc(input
, st_src_reg
);
55 assert(!"can't create reladdr, expect shader breakage");
63 st_src_reg::st_src_reg(gl_register_file file
, int index
, const glsl_type
*type
,
64 int component
, unsigned array_id
)
66 assert(file
!= PROGRAM_ARRAY
|| array_id
!= 0);
69 this->swizzle
= swizzle_for_type(type
, component
);
73 this->type
= type
? type
->base_type
: GLSL_TYPE_ERROR
;
75 this->reladdr2
= NULL
;
76 this->has_index2
= false;
77 this->double_reg2
= false;
78 this->array_id
= array_id
;
79 this->is_double_vertex_input
= false;
82 st_src_reg::st_src_reg(gl_register_file file
, int index
, enum glsl_base_type type
)
84 assert(file
!= PROGRAM_ARRAY
); /* need array_id > 0 */
89 this->swizzle
= SWIZZLE_XYZW
;
93 this->reladdr2
= NULL
;
94 this->has_index2
= false;
95 this->double_reg2
= false;
97 this->is_double_vertex_input
= false;
100 st_src_reg::st_src_reg(gl_register_file file
, int index
, enum glsl_base_type type
, int index2D
)
102 assert(file
!= PROGRAM_ARRAY
); /* need array_id > 0 */
106 this->index2D
= index2D
;
107 this->swizzle
= SWIZZLE_XYZW
;
110 this->reladdr
= NULL
;
111 this->reladdr2
= NULL
;
112 this->has_index2
= false;
113 this->double_reg2
= false;
115 this->is_double_vertex_input
= false;
118 st_src_reg::st_src_reg()
120 this->type
= GLSL_TYPE_ERROR
;
121 this->file
= PROGRAM_UNDEFINED
;
127 this->reladdr
= NULL
;
128 this->reladdr2
= NULL
;
129 this->has_index2
= false;
130 this->double_reg2
= false;
132 this->is_double_vertex_input
= false;
135 st_src_reg::st_src_reg(const st_src_reg
®
)
140 void st_src_reg::operator=(const st_src_reg
®
)
142 this->type
= reg
.type
;
143 this->file
= reg
.file
;
144 this->index
= reg
.index
;
145 this->index2D
= reg
.index2D
;
146 this->swizzle
= reg
.swizzle
;
147 this->negate
= reg
.negate
;
149 this->reladdr
= dup_reladdr(reg
.reladdr
);
150 this->reladdr2
= dup_reladdr(reg
.reladdr2
);
151 this->has_index2
= reg
.has_index2
;
152 this->double_reg2
= reg
.double_reg2
;
153 this->array_id
= reg
.array_id
;
154 this->is_double_vertex_input
= reg
.is_double_vertex_input
;
157 st_src_reg::st_src_reg(st_dst_reg reg
)
159 this->type
= reg
.type
;
160 this->file
= reg
.file
;
161 this->index
= reg
.index
;
162 this->swizzle
= SWIZZLE_XYZW
;
165 this->reladdr
= dup_reladdr(reg
.reladdr
);
166 this->index2D
= reg
.index2D
;
167 this->reladdr2
= dup_reladdr(reg
.reladdr2
);
168 this->has_index2
= reg
.has_index2
;
169 this->double_reg2
= false;
170 this->array_id
= reg
.array_id
;
171 this->is_double_vertex_input
= false;
174 st_src_reg
st_src_reg::get_abs()
176 st_src_reg reg
= *this;
182 st_dst_reg::st_dst_reg(st_src_reg reg
)
184 this->type
= reg
.type
;
185 this->file
= reg
.file
;
186 this->index
= reg
.index
;
187 this->writemask
= WRITEMASK_XYZW
;
188 this->reladdr
= dup_reladdr(reg
.reladdr
);
189 this->index2D
= reg
.index2D
;
190 this->reladdr2
= dup_reladdr(reg
.reladdr2
);
191 this->has_index2
= reg
.has_index2
;
192 this->array_id
= reg
.array_id
;
195 st_dst_reg::st_dst_reg(gl_register_file file
, int writemask
, enum glsl_base_type type
, int index
)
197 assert(file
!= PROGRAM_ARRAY
); /* need array_id > 0 */
201 this->writemask
= writemask
;
202 this->reladdr
= NULL
;
203 this->reladdr2
= NULL
;
204 this->has_index2
= false;
209 st_dst_reg::st_dst_reg(gl_register_file file
, int writemask
, enum glsl_base_type type
)
211 assert(file
!= PROGRAM_ARRAY
); /* need array_id > 0 */
215 this->writemask
= writemask
;
216 this->reladdr
= NULL
;
217 this->reladdr2
= NULL
;
218 this->has_index2
= false;
223 st_dst_reg::st_dst_reg()
225 this->type
= GLSL_TYPE_ERROR
;
226 this->file
= PROGRAM_UNDEFINED
;
230 this->reladdr
= NULL
;
231 this->reladdr2
= NULL
;
232 this->has_index2
= false;
236 st_dst_reg::st_dst_reg(const st_dst_reg
®
)
241 void st_dst_reg::operator=(const st_dst_reg
®
)
243 this->type
= reg
.type
;
244 this->file
= reg
.file
;
245 this->index
= reg
.index
;
246 this->writemask
= reg
.writemask
;
247 this->reladdr
= dup_reladdr(reg
.reladdr
);
248 this->index2D
= reg
.index2D
;
249 this->reladdr2
= dup_reladdr(reg
.reladdr2
);
250 this->has_index2
= reg
.has_index2
;
251 this->array_id
= reg
.array_id
;