3 * Copyright © 2010-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"
32 class fs_reg
: public backend_reg
{
34 DECLARE_RALLOC_CXX_OPERATORS(fs_reg
)
39 fs_reg(struct ::brw_reg reg
);
40 fs_reg(enum brw_reg_file file
, int nr
);
41 fs_reg(enum brw_reg_file file
, int nr
, enum brw_reg_type type
);
43 bool equals(const fs_reg
&r
) const;
44 bool is_contiguous() const;
47 * Return the size in bytes of a single logical component of the
48 * register assuming the given execution width.
50 unsigned component_size(unsigned width
) const;
52 /** Smear a channel of the reg to all channels. */
53 fs_reg
&set_smear(unsigned subreg
);
56 * Offset in bytes from the start of the register. Values up to a
57 * backend_reg::reg_offset unit are valid.
63 /** Register region horizontal stride */
70 assert(reg
.file
!= IMM
);
71 reg
.negate
= !reg
.negate
;
76 retype(fs_reg reg
, enum brw_reg_type type
)
83 byte_offset(fs_reg reg
, unsigned delta
)
90 reg
.reg_offset
+= delta
/ 32;
101 reg
.subreg_offset
+= delta
% 32;
106 horiz_offset(fs_reg reg
, unsigned delta
)
112 /* These only have a single component that is implicitly splatted. A
113 * horizontal offset should be a harmless no-op.
119 return byte_offset(reg
, delta
* reg
.stride
* type_sz(reg
.type
));
128 component(fs_reg reg
, unsigned idx
)
130 assert(reg
.subreg_offset
== 0);
131 reg
.subreg_offset
= idx
* type_sz(reg
.type
);
137 is_uniform(const fs_reg
®
)
139 return (reg
.stride
== 0 || reg
.is_null()) &&
140 (!reg
.reladdr
|| is_uniform(*reg
.reladdr
));
144 * Get either of the 8-component halves of a 16-component register.
146 * Note: this also works if \c reg represents a SIMD16 pair of registers.
149 half(fs_reg reg
, unsigned idx
)
161 return horiz_offset(reg
, 8 * idx
);
166 unreachable("Cannot take half of this register type");
171 static const fs_reg reg_undef
;
173 class fs_inst
: public backend_instruction
{
174 fs_inst
&operator=(const fs_inst
&);
176 void init(enum opcode opcode
, uint8_t exec_width
, const fs_reg
&dst
,
177 const fs_reg
*src
, unsigned sources
);
180 DECLARE_RALLOC_CXX_OPERATORS(fs_inst
)
183 fs_inst(enum opcode opcode
, uint8_t exec_size
);
184 fs_inst(enum opcode opcode
, uint8_t exec_size
, const fs_reg
&dst
);
185 fs_inst(enum opcode opcode
, uint8_t exec_size
, const fs_reg
&dst
,
187 fs_inst(enum opcode opcode
, uint8_t exec_size
, const fs_reg
&dst
,
188 const fs_reg
&src0
, const fs_reg
&src1
);
189 fs_inst(enum opcode opcode
, uint8_t exec_size
, const fs_reg
&dst
,
190 const fs_reg
&src0
, const fs_reg
&src1
, const fs_reg
&src2
);
191 fs_inst(enum opcode opcode
, uint8_t exec_size
, const fs_reg
&dst
,
192 const fs_reg src
[], unsigned sources
);
193 fs_inst(const fs_inst
&that
);
196 void resize_sources(uint8_t num_sources
);
198 bool equals(fs_inst
*inst
) const;
199 bool overwrites_reg(const fs_reg
®
) const;
200 bool is_send_from_grf() const;
201 bool is_partial_write() const;
202 bool is_copy_payload(const brw::simple_allocator
&grf_alloc
) const;
203 unsigned components_read(unsigned i
) const;
204 int regs_read(int arg
) const;
205 bool can_do_source_mods(const struct brw_device_info
*devinfo
);
206 bool can_change_types() const;
207 bool has_side_effects() const;
208 bool has_source_and_destination_hazard() const;
210 bool reads_flag() const;
211 bool writes_flag() const;
216 uint8_t sources
; /**< Number of fs_reg sources. */
219 * Execution size of the instruction. This is used by the generator to
220 * generate the correct binary for the given fs_inst. Current valid
221 * values are 1, 8, 16.
226 bool force_sechalf
:1;
227 bool pi_noperspective
:1; /**< Pixel interpolator noperspective flag */
231 * Set second-half quarter control on \p inst.
233 static inline fs_inst
*
234 set_sechalf(fs_inst
*inst
)
236 inst
->force_sechalf
= true;
241 * Make the execution of \p inst dependent on the evaluation of a possibly
242 * inverted predicate.
244 static inline fs_inst
*
245 set_predicate_inv(enum brw_predicate pred
, bool inverse
,
248 inst
->predicate
= pred
;
249 inst
->predicate_inverse
= inverse
;
254 * Make the execution of \p inst dependent on the evaluation of a predicate.
256 static inline fs_inst
*
257 set_predicate(enum brw_predicate pred
, fs_inst
*inst
)
259 return set_predicate_inv(pred
, false, inst
);
263 * Write the result of evaluating the condition given by \p mod to a flag
266 static inline fs_inst
*
267 set_condmod(enum brw_conditional_mod mod
, fs_inst
*inst
)
269 inst
->conditional_mod
= mod
;
274 * Clamp the result of \p inst to the saturation range of its destination
277 static inline fs_inst
*
278 set_saturate(bool saturate
, fs_inst
*inst
)
280 inst
->saturate
= saturate
;