4455f07907168c90d7af0e3bf05ba78723113365
[mesa.git] / src / intel / compiler / brw_shader.h
1 /*
2 * Copyright © 2010 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
24 #ifndef BRW_SHADER_H
25 #define BRW_SHADER_H
26
27 #include <stdint.h>
28 #include "brw_cfg.h"
29 #include "brw_compiler.h"
30 #include "compiler/nir/nir.h"
31
32 #ifdef __cplusplus
33 #include "brw_ir_allocator.h"
34
35 enum instruction_scheduler_mode {
36 SCHEDULE_PRE,
37 SCHEDULE_PRE_NON_LIFO,
38 SCHEDULE_PRE_LIFO,
39 SCHEDULE_POST,
40 };
41
42 struct backend_shader {
43 protected:
44
45 backend_shader(const struct brw_compiler *compiler,
46 void *log_data,
47 void *mem_ctx,
48 const nir_shader *shader,
49 struct brw_stage_prog_data *stage_prog_data);
50
51 public:
52 virtual ~backend_shader();
53
54 const struct brw_compiler *compiler;
55 void *log_data; /* Passed to compiler->*_log functions */
56
57 const struct gen_device_info * const devinfo;
58 const nir_shader *nir;
59 struct brw_stage_prog_data * const stage_prog_data;
60
61 /** ralloc context for temporary data used during compile */
62 void *mem_ctx;
63
64 /**
65 * List of either fs_inst or vec4_instruction (inheriting from
66 * backend_instruction)
67 */
68 exec_list instructions;
69
70 cfg_t *cfg;
71
72 gl_shader_stage stage;
73 bool debug_enabled;
74 const char *stage_name;
75 const char *stage_abbrev;
76
77 brw::simple_allocator alloc;
78
79 virtual void dump_instruction(backend_instruction *inst) = 0;
80 virtual void dump_instruction(backend_instruction *inst, FILE *file) = 0;
81 virtual void dump_instructions();
82 virtual void dump_instructions(const char *name);
83
84 void calculate_cfg();
85
86 virtual void invalidate_live_intervals() = 0;
87 };
88
89 bool brw_texture_offset(const nir_tex_instr *tex, unsigned src,
90 uint32_t *offset_bits);
91
92 #else
93 struct backend_shader;
94 #endif /* __cplusplus */
95
96 enum brw_reg_type brw_type_for_base_type(const struct glsl_type *type);
97 enum brw_conditional_mod brw_conditional_for_comparison(unsigned int op);
98 uint32_t brw_math_function(enum opcode op);
99 const char *brw_instruction_name(const struct gen_device_info *devinfo,
100 enum opcode op);
101 bool brw_saturate_immediate(enum brw_reg_type type, struct brw_reg *reg);
102 bool brw_negate_immediate(enum brw_reg_type type, struct brw_reg *reg);
103 bool brw_abs_immediate(enum brw_reg_type type, struct brw_reg *reg);
104
105 bool opt_predicated_break(struct backend_shader *s);
106
107 #ifdef __cplusplus
108 extern "C" {
109 #endif
110
111 /* brw_fs_reg_allocate.cpp */
112 void brw_fs_alloc_reg_sets(struct brw_compiler *compiler);
113
114 /* brw_vec4_reg_allocate.cpp */
115 void brw_vec4_alloc_reg_set(struct brw_compiler *compiler);
116
117 /* brw_disasm.c */
118 extern const char *const conditional_modifier[16];
119 extern const char *const pred_ctrl_align16[16];
120
121 /* Per-thread scratch space is a power-of-two multiple of 1KB. */
122 static inline int
123 brw_get_scratch_size(int size)
124 {
125 return MAX2(1024, util_next_power_of_two(size));
126 }
127
128 /**
129 * Scratch data used when compiling a GLSL geometry shader.
130 */
131 struct brw_gs_compile
132 {
133 struct brw_gs_prog_key key;
134 struct brw_vue_map input_vue_map;
135
136 unsigned control_data_bits_per_vertex;
137 unsigned control_data_header_size_bits;
138 };
139
140 #ifdef __cplusplus
141 }
142 #endif
143
144 #endif /* BRW_SHADER_H */