2 * Copyright © 2010 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 #include "brw_defines.h"
27 #include "main/compiler.h"
31 #include "brw_ir_allocator.h"
36 #define MAX_SAMPLER_MESSAGE_SIZE 11
37 #define MAX_VGRF_SIZE 16
39 enum PACKED register_file
{
44 HW_REG
, /* a struct brw_reg */
46 UNIFORM
, /* prog_data->params[reg] */
54 bool is_negative_one() const;
56 bool is_accumulator() const;
59 enum register_file file
; /**< Register file: GRF, MRF, IMM. */
60 enum brw_reg_type type
; /**< Register type: BRW_REGISTER_TYPE_* */
65 * For GRF, it's a virtual register number until register allocation.
67 * For MRF, it's the hardware register.
72 * Offset within the virtual register.
74 * In the scalar backend, this is in units of a float per pixel for pre-
75 * register allocation registers (i.e., one register in SIMD8 mode and two
76 * registers in SIMD16 mode).
78 * For uniforms, this is in units of 1 float.
82 struct brw_reg fixed_hw_reg
;
92 struct backend_instruction
: public exec_node
{
96 bool is_control_flow() const;
97 bool can_do_source_mods() const;
98 bool can_do_saturate() const;
99 bool can_do_cmod() const;
100 bool reads_accumulator_implicitly() const;
101 bool writes_accumulator_implicitly(struct brw_context
*brw
) const;
103 void remove(bblock_t
*block
);
104 void insert_after(bblock_t
*block
, backend_instruction
*inst
);
105 void insert_before(bblock_t
*block
, backend_instruction
*inst
);
106 void insert_before(bblock_t
*block
, exec_list
*list
);
109 * True if the instruction has side effects other than writing to
110 * its destination registers. You are expected not to reorder or
111 * optimize these out unless you know what you are doing.
113 bool has_side_effects() const;
115 struct backend_instruction
{
116 struct exec_node link
;
119 * Annotation for the generated IR. One of the two can be set.
122 const char *annotation
;
125 uint32_t offset
; /**< spill/unspill offset or texture offset bitfield */
126 uint8_t mlen
; /**< SEND message length */
127 int8_t base_mrf
; /**< First MRF in the SEND message, if mlen is nonzero. */
128 uint8_t target
; /**< MRT target. */
129 uint8_t regs_written
; /**< Number of registers written by the instruction. */
131 enum opcode opcode
; /* BRW_OPCODE_* or FS_OPCODE_* */
132 enum brw_conditional_mod conditional_mod
; /**< BRW_CONDITIONAL_* */
133 enum brw_predicate predicate
;
134 bool predicate_inverse
:1;
135 bool writes_accumulator
:1; /**< instruction implicitly writes accumulator */
136 bool force_writemask_all
:1;
140 bool shadow_compare
:1;
141 bool header_present
:1;
143 /* Chooses which flag subregister (f0.0 or f0.1) is used for conditional
144 * mod and predication.
146 unsigned flag_subreg
:1;
151 enum instruction_scheduler_mode
{
153 SCHEDULE_PRE_NON_LIFO
,
158 class backend_visitor
: public ir_visitor
{
161 backend_visitor(struct brw_context
*brw
,
162 struct gl_shader_program
*shader_prog
,
163 struct gl_program
*prog
,
164 struct brw_stage_prog_data
*stage_prog_data
,
165 gl_shader_stage stage
);
169 struct brw_context
* const brw
;
170 struct gl_context
* const ctx
;
171 struct brw_shader
* const shader
;
172 struct gl_shader_program
* const shader_prog
;
173 struct gl_program
* const prog
;
174 struct brw_stage_prog_data
* const stage_prog_data
;
176 /** ralloc context for temporary data used during compile */
180 * List of either fs_inst or vec4_instruction (inheriting from
181 * backend_instruction)
183 exec_list instructions
;
187 gl_shader_stage stage
;
189 brw::simple_allocator alloc
;
191 virtual void dump_instruction(backend_instruction
*inst
) = 0;
192 virtual void dump_instruction(backend_instruction
*inst
, FILE *file
) = 0;
193 virtual void dump_instructions();
194 virtual void dump_instructions(const char *name
);
196 void calculate_cfg();
197 void invalidate_cfg();
199 void assign_common_binding_table_offsets(uint32_t next_binding_table_offset
);
201 virtual void invalidate_live_intervals() = 0;
204 uint32_t brw_texture_offset(struct gl_context
*ctx
, int *offsets
,
205 unsigned num_components
);
207 #endif /* __cplusplus */
209 enum brw_reg_type
brw_type_for_base_type(const struct glsl_type
*type
);
210 enum brw_conditional_mod
brw_conditional_for_comparison(unsigned int op
);
211 uint32_t brw_math_function(enum opcode op
);
212 const char *brw_instruction_name(enum opcode op
);
213 bool brw_saturate_immediate(enum brw_reg_type type
, struct brw_reg
*reg
);
214 bool brw_negate_immediate(enum brw_reg_type type
, struct brw_reg
*reg
);
215 bool brw_abs_immediate(enum brw_reg_type type
, struct brw_reg
*reg
);
221 bool brw_vs_precompile(struct gl_context
*ctx
,
222 struct gl_shader_program
*shader_prog
,
223 struct gl_program
*prog
);
224 bool brw_gs_precompile(struct gl_context
*ctx
,
225 struct gl_shader_program
*shader_prog
,
226 struct gl_program
*prog
);
227 bool brw_fs_precompile(struct gl_context
*ctx
,
228 struct gl_shader_program
*shader_prog
,
229 struct gl_program
*prog
);