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(register_file file
, int reg
, const glsl_type
*type
);
47 src_reg(uint8_t vf
[4]);
48 src_reg(uint8_t vf0
, uint8_t vf1
, uint8_t vf2
, uint8_t vf3
);
49 src_reg(struct brw_reg reg
);
51 bool equals(const src_reg
&r
) const;
53 src_reg(class vec4_visitor
*v
, const struct glsl_type
*type
);
54 src_reg(class vec4_visitor
*v
, const struct glsl_type
*type
, int size
);
56 explicit src_reg(const dst_reg
®
);
58 unsigned swizzle
; /**< BRW_SWIZZLE_XYZW macros from brw_reg.h. */
64 retype(src_reg reg
, enum brw_reg_type type
)
66 reg
.fixed_hw_reg
.type
= reg
.type
= type
;
71 offset(src_reg reg
, unsigned delta
)
73 assert(delta
== 0 || (reg
.file
!= HW_REG
&& reg
.file
!= IMM
));
74 reg
.reg_offset
+= delta
;
79 * Reswizzle a given source register.
83 swizzle(src_reg reg
, unsigned swizzle
)
85 assert(reg
.file
!= HW_REG
);
86 reg
.swizzle
= brw_compose_swizzle(swizzle
, reg
.swizzle
);
93 assert(reg
.file
!= HW_REG
&& reg
.file
!= IMM
);
94 reg
.negate
= !reg
.negate
;
99 is_uniform(const src_reg
®
)
101 return (reg
.file
== IMM
|| reg
.file
== UNIFORM
|| reg
.is_null()) &&
102 (!reg
.reladdr
|| is_uniform(*reg
.reladdr
));
105 class dst_reg
: public backend_reg
108 DECLARE_RALLOC_CXX_OPERATORS(dst_reg
)
113 dst_reg(register_file file
, int reg
);
114 dst_reg(register_file file
, int reg
, const glsl_type
*type
,
116 dst_reg(register_file file
, int reg
, brw_reg_type type
,
118 dst_reg(struct brw_reg reg
);
119 dst_reg(class vec4_visitor
*v
, const struct glsl_type
*type
);
121 explicit dst_reg(const src_reg
®
);
123 bool equals(const dst_reg
&r
) const;
125 unsigned writemask
; /**< Bitfield of WRITEMASK_[XYZW] */
130 static inline dst_reg
131 retype(dst_reg reg
, enum brw_reg_type type
)
133 reg
.fixed_hw_reg
.type
= reg
.type
= type
;
137 static inline dst_reg
138 offset(dst_reg reg
, unsigned delta
)
140 assert(delta
== 0 || (reg
.file
!= HW_REG
&& reg
.file
!= IMM
));
141 reg
.reg_offset
+= delta
;
145 static inline dst_reg
146 writemask(dst_reg reg
, unsigned mask
)
148 assert(reg
.file
!= HW_REG
&& reg
.file
!= IMM
);
149 assert((reg
.writemask
& mask
) != 0);
150 reg
.writemask
&= mask
;
154 class vec4_instruction
: public backend_instruction
{
156 DECLARE_RALLOC_CXX_OPERATORS(vec4_instruction
)
158 vec4_instruction(enum opcode opcode
,
159 const dst_reg
&dst
= dst_reg(),
160 const src_reg
&src0
= src_reg(),
161 const src_reg
&src1
= src_reg(),
162 const src_reg
&src2
= src_reg());
167 enum brw_urb_write_flags urb_write_flags
;
169 unsigned sol_binding
; /**< gen6: SOL binding table index */
170 bool sol_final_write
; /**< gen6: send commit message */
171 unsigned sol_vertex
; /**< gen6: used for setting dst index in SVB header */
173 bool is_send_from_grf();
174 unsigned regs_read(unsigned arg
) const;
175 bool can_reswizzle(const struct brw_device_info
*devinfo
, int dst_writemask
,
176 int swizzle
, int swizzle_mask
);
177 void reswizzle(int dst_writemask
, int swizzle
);
178 bool can_do_source_mods(const struct brw_device_info
*devinfo
);
179 bool can_change_types() const;
183 return predicate
|| opcode
== VS_OPCODE_UNPACK_FLAGS_SIMD4X2
;
186 bool reads_flag(unsigned c
)
188 if (opcode
== VS_OPCODE_UNPACK_FLAGS_SIMD4X2
)
192 case BRW_PREDICATE_NONE
:
194 case BRW_PREDICATE_ALIGN16_REPLICATE_X
:
196 case BRW_PREDICATE_ALIGN16_REPLICATE_Y
:
198 case BRW_PREDICATE_ALIGN16_REPLICATE_Z
:
200 case BRW_PREDICATE_ALIGN16_REPLICATE_W
:
209 return (conditional_mod
&& (opcode
!= BRW_OPCODE_SEL
&&
210 opcode
!= BRW_OPCODE_IF
&&
211 opcode
!= BRW_OPCODE_WHILE
));
216 * Make the execution of \p inst dependent on the evaluation of a possibly
217 * inverted predicate.
219 inline vec4_instruction
*
220 set_predicate_inv(enum brw_predicate pred
, bool inverse
,
221 vec4_instruction
*inst
)
223 inst
->predicate
= pred
;
224 inst
->predicate_inverse
= inverse
;
229 * Make the execution of \p inst dependent on the evaluation of a predicate.
231 inline vec4_instruction
*
232 set_predicate(enum brw_predicate pred
, vec4_instruction
*inst
)
234 return set_predicate_inv(pred
, false, inst
);
238 * Write the result of evaluating the condition given by \p mod to a flag
241 inline vec4_instruction
*
242 set_condmod(enum brw_conditional_mod mod
, vec4_instruction
*inst
)
244 inst
->conditional_mod
= mod
;
249 * Clamp the result of \p inst to the saturation range of its destination
252 inline vec4_instruction
*
253 set_saturate(bool saturate
, vec4_instruction
*inst
)
255 inst
->saturate
= saturate
;
259 } /* namespace brw */