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.
61 /** Register region horizontal stride */
68 assert(reg
.file
!= IMM
);
69 reg
.negate
= !reg
.negate
;
74 retype(fs_reg reg
, enum brw_reg_type type
)
81 byte_offset(fs_reg reg
, unsigned delta
)
83 reg
.subreg_offset
+= delta
;
90 reg
.reg_offset
+= reg
.subreg_offset
/ 32;
96 reg
.reg_offset
+= reg
.subreg_offset
/ 4;
97 reg
.subreg_offset
%= 4;
105 reg
.subreg_offset
%= 32;
110 horiz_offset(fs_reg reg
, unsigned delta
)
116 /* These only have a single component that is implicitly splatted. A
117 * horizontal offset should be a harmless no-op.
123 return byte_offset(reg
, delta
* reg
.stride
* type_sz(reg
.type
));
132 * Get the scalar channel of \p reg given by \p idx and replicate it to all
133 * channels of the result.
136 component(fs_reg reg
, unsigned idx
)
138 reg
= horiz_offset(reg
, idx
);
144 is_uniform(const fs_reg
®
)
146 return (reg
.stride
== 0 || reg
.is_null());
150 * Get either of the 8-component halves of a 16-component register.
152 * Note: this also works if \c reg represents a SIMD16 pair of registers.
155 half(fs_reg reg
, unsigned idx
)
167 return horiz_offset(reg
, 8 * idx
);
172 unreachable("Cannot take half of this register type");
178 * Reinterpret each channel of register \p reg as a vector of values of the
179 * given smaller type and take the i-th subcomponent from each.
182 subscript(fs_reg reg
, brw_reg_type type
, unsigned i
)
184 assert((i
+ 1) * type_sz(type
) <= type_sz(reg
.type
));
186 if (reg
.file
== ARF
|| reg
.file
== FIXED_GRF
) {
187 /* The stride is encoded inconsistently for fixed GRF and ARF registers
188 * as the log2 of the actual vertical and horizontal strides.
190 const int delta
= _mesa_logbase2(type_sz(reg
.type
)) -
191 _mesa_logbase2(type_sz(type
));
192 reg
.hstride
+= (reg
.hstride
? delta
: 0);
193 reg
.vstride
+= (reg
.vstride
? delta
: 0);
195 } else if (reg
.file
== IMM
) {
196 assert(reg
.type
== type
);
199 reg
.stride
*= type_sz(reg
.type
) / type_sz(type
);
202 return byte_offset(retype(reg
, type
), i
* type_sz(type
));
205 static const fs_reg reg_undef
;
207 class fs_inst
: public backend_instruction
{
208 fs_inst
&operator=(const fs_inst
&);
210 void init(enum opcode opcode
, uint8_t exec_width
, const fs_reg
&dst
,
211 const fs_reg
*src
, unsigned sources
);
214 DECLARE_RALLOC_CXX_OPERATORS(fs_inst
)
217 fs_inst(enum opcode opcode
, uint8_t exec_size
);
218 fs_inst(enum opcode opcode
, uint8_t exec_size
, const fs_reg
&dst
);
219 fs_inst(enum opcode opcode
, uint8_t exec_size
, const fs_reg
&dst
,
221 fs_inst(enum opcode opcode
, uint8_t exec_size
, const fs_reg
&dst
,
222 const fs_reg
&src0
, const fs_reg
&src1
);
223 fs_inst(enum opcode opcode
, uint8_t exec_size
, const fs_reg
&dst
,
224 const fs_reg
&src0
, const fs_reg
&src1
, const fs_reg
&src2
);
225 fs_inst(enum opcode opcode
, uint8_t exec_size
, const fs_reg
&dst
,
226 const fs_reg src
[], unsigned sources
);
227 fs_inst(const fs_inst
&that
);
230 void resize_sources(uint8_t num_sources
);
232 bool equals(fs_inst
*inst
) const;
233 bool overwrites_reg(const fs_reg
®
) const;
234 bool is_send_from_grf() const;
235 bool is_partial_write() const;
236 bool is_copy_payload(const brw::simple_allocator
&grf_alloc
) const;
237 unsigned components_read(unsigned i
) const;
238 int regs_read(int arg
) const;
239 bool can_do_source_mods(const struct brw_device_info
*devinfo
);
240 bool can_change_types() const;
241 bool has_side_effects() const;
242 bool has_source_and_destination_hazard() const;
244 bool reads_flag() const;
245 bool writes_flag() const;
250 uint8_t sources
; /**< Number of fs_reg sources. */
253 * Execution size of the instruction. This is used by the generator to
254 * generate the correct binary for the given fs_inst. Current valid
255 * values are 1, 8, 16.
260 bool force_sechalf
:1;
261 bool pi_noperspective
:1; /**< Pixel interpolator noperspective flag */
265 * Set second-half quarter control on \p inst.
267 static inline fs_inst
*
268 set_sechalf(fs_inst
*inst
)
270 inst
->force_sechalf
= true;
275 * Make the execution of \p inst dependent on the evaluation of a possibly
276 * inverted predicate.
278 static inline fs_inst
*
279 set_predicate_inv(enum brw_predicate pred
, bool inverse
,
282 inst
->predicate
= pred
;
283 inst
->predicate_inverse
= inverse
;
288 * Make the execution of \p inst dependent on the evaluation of a predicate.
290 static inline fs_inst
*
291 set_predicate(enum brw_predicate pred
, fs_inst
*inst
)
293 return set_predicate_inv(pred
, false, inst
);
297 * Write the result of evaluating the condition given by \p mod to a flag
300 static inline fs_inst
*
301 set_condmod(enum brw_conditional_mod mod
, fs_inst
*inst
)
303 inst
->conditional_mod
= mod
;
308 * Clamp the result of \p inst to the saturation range of its destination
311 static inline fs_inst
*
312 set_saturate(bool saturate
, fs_inst
*inst
)
314 inst
->saturate
= saturate
;