3 * Copyright © 2011-2015 Intel Corporation
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 #include "brw_shader.h"
29 #include "brw_context.h"
35 class src_reg
: public backend_reg
38 DECLARE_RALLOC_CXX_OPERATORS(src_reg
)
42 src_reg(enum brw_reg_file file
, int nr
, const glsl_type
*type
);
44 src_reg(struct ::brw_reg reg
);
46 bool equals(const src_reg
&r
) const;
48 src_reg(class vec4_visitor
*v
, const struct glsl_type
*type
);
49 src_reg(class vec4_visitor
*v
, const struct glsl_type
*type
, int size
);
51 explicit src_reg(const dst_reg
®
);
57 retype(src_reg reg
, enum brw_reg_type type
)
64 offset(src_reg reg
, unsigned delta
)
67 (reg
.file
!= ARF
&& reg
.file
!= FIXED_GRF
&& reg
.file
!= IMM
));
68 reg
.reg_offset
+= delta
;
73 * Reswizzle a given source register.
77 swizzle(src_reg reg
, unsigned swizzle
)
79 reg
.swizzle
= brw_compose_swizzle(swizzle
, reg
.swizzle
);
86 assert(reg
.file
!= IMM
);
87 reg
.negate
= !reg
.negate
;
92 is_uniform(const src_reg
®
)
94 return (reg
.file
== IMM
|| reg
.file
== UNIFORM
|| reg
.is_null()) &&
95 (!reg
.reladdr
|| is_uniform(*reg
.reladdr
));
98 class dst_reg
: public backend_reg
101 DECLARE_RALLOC_CXX_OPERATORS(dst_reg
)
106 dst_reg(enum brw_reg_file file
, int nr
);
107 dst_reg(enum brw_reg_file file
, int nr
, const glsl_type
*type
,
109 dst_reg(enum brw_reg_file file
, int nr
, brw_reg_type type
,
111 dst_reg(struct ::brw_reg reg
);
112 dst_reg(class vec4_visitor
*v
, const struct glsl_type
*type
);
114 explicit dst_reg(const src_reg
®
);
116 bool equals(const dst_reg
&r
) const;
121 static inline dst_reg
122 retype(dst_reg reg
, enum brw_reg_type type
)
128 static inline dst_reg
129 offset(dst_reg reg
, unsigned delta
)
132 (reg
.file
!= ARF
&& reg
.file
!= FIXED_GRF
&& reg
.file
!= IMM
));
133 reg
.reg_offset
+= delta
;
137 static inline dst_reg
138 writemask(dst_reg reg
, unsigned mask
)
140 assert(reg
.file
!= IMM
);
141 assert((reg
.writemask
& mask
) != 0);
142 reg
.writemask
&= mask
;
146 class vec4_instruction
: public backend_instruction
{
148 DECLARE_RALLOC_CXX_OPERATORS(vec4_instruction
)
150 vec4_instruction(enum opcode opcode
,
151 const dst_reg
&dst
= dst_reg(),
152 const src_reg
&src0
= src_reg(),
153 const src_reg
&src1
= src_reg(),
154 const src_reg
&src2
= src_reg());
159 enum brw_urb_write_flags urb_write_flags
;
161 unsigned sol_binding
; /**< gen6: SOL binding table index */
162 bool sol_final_write
; /**< gen6: send commit message */
163 unsigned sol_vertex
; /**< gen6: used for setting dst index in SVB header */
165 bool is_send_from_grf();
166 unsigned regs_read(unsigned arg
) const;
167 bool can_reswizzle(const struct brw_device_info
*devinfo
, int dst_writemask
,
168 int swizzle
, int swizzle_mask
);
169 void reswizzle(int dst_writemask
, int swizzle
);
170 bool can_do_source_mods(const struct brw_device_info
*devinfo
);
171 bool can_change_types() const;
172 bool has_source_and_destination_hazard() const;
176 return predicate
|| opcode
== VS_OPCODE_UNPACK_FLAGS_SIMD4X2
;
179 bool reads_flag(unsigned c
)
181 if (opcode
== VS_OPCODE_UNPACK_FLAGS_SIMD4X2
)
185 case BRW_PREDICATE_NONE
:
187 case BRW_PREDICATE_ALIGN16_REPLICATE_X
:
189 case BRW_PREDICATE_ALIGN16_REPLICATE_Y
:
191 case BRW_PREDICATE_ALIGN16_REPLICATE_Z
:
193 case BRW_PREDICATE_ALIGN16_REPLICATE_W
:
202 return (conditional_mod
&& (opcode
!= BRW_OPCODE_SEL
&&
203 opcode
!= BRW_OPCODE_IF
&&
204 opcode
!= BRW_OPCODE_WHILE
));
209 * Make the execution of \p inst dependent on the evaluation of a possibly
210 * inverted predicate.
212 inline vec4_instruction
*
213 set_predicate_inv(enum brw_predicate pred
, bool inverse
,
214 vec4_instruction
*inst
)
216 inst
->predicate
= pred
;
217 inst
->predicate_inverse
= inverse
;
222 * Make the execution of \p inst dependent on the evaluation of a predicate.
224 inline vec4_instruction
*
225 set_predicate(enum brw_predicate pred
, vec4_instruction
*inst
)
227 return set_predicate_inv(pred
, false, inst
);
231 * Write the result of evaluating the condition given by \p mod to a flag
234 inline vec4_instruction
*
235 set_condmod(enum brw_conditional_mod mod
, vec4_instruction
*inst
)
237 inst
->conditional_mod
= mod
;
242 * Clamp the result of \p inst to the saturation range of its destination
245 inline vec4_instruction
*
246 set_saturate(bool saturate
, vec4_instruction
*inst
)
248 inst
->saturate
= saturate
;
252 } /* namespace brw */