summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/r600/sb/sb_shader.h
blob: 470f972148b07c00b9327f738493860d5e61b6f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
 * Copyright 2013 Vadim Girlin <vadimgirlin@gmail.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * on the rights to use, copy, modify, merge, publish, distribute, sub
 * license, and/or sell copies of the Software, and to permit persons to whom
 * the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 * USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors:
 *      Vadim Girlin
 */

#ifndef SB_SHADER_H_
#define SB_SHADER_H_

#include <list>
#include <string>

#include "sb_valtable.h"
#include "sb_ir.h"
#include "sb_expr.h"

#include "sb_ra_coalesce.h"

namespace r600_sb {

struct shader_input {
	unsigned comp_mask;
	unsigned preloaded;
};

struct error_info {
	node *n;
	unsigned arg_index;
	std::string message;
};

typedef std::multimap<node*, error_info> error_map;

class sb_context;

typedef std::vector<shader_input> inputs_vec;

enum shader_target
{
	TARGET_UNKNOWN,
	TARGET_VS,
	TARGET_PS,
	TARGET_GS,
	TARGET_COMPUTE
};

typedef std::vector<region_node*> regions_vec;
typedef std::vector<bb_node*> bbs_vec;
typedef std::list<node*> sched_queue;
typedef sched_queue::iterator sq_iterator;
typedef std::vector<node*> node_vec;
typedef std::list<node*> node_list;
typedef std::set<node*> node_set;

typedef std::vector<gpr_array*> gpr_array_vec;

class shader {

	sb_context &ctx;

	typedef sb_map<uint32_t, value*> value_map;
	value_map reg_values;

	// read-only values
	value_map const_values; // immediate constants key -const  value (uint32_t)
	value_map special_ro_values; //  key - hw alu_sel & chan
	value_map kcache_values;

	gpr_array_vec gpr_arrays;

	unsigned next_temp_value_index;

	unsigned prep_regs_count;

	value* pred_sels[2];

	regions_vec regions;
	inputs_vec inputs;

	value *undef;

	sb_value_pool val_pool;
	sb_pool pool;

	std::vector<node*> all_nodes;

public:
	error_map errors;

	coalescer coal;

	static const unsigned temp_regid_offset = 512;

	bbs_vec bbs;

	const shader_target target;

	value_table vt;
	expr_handler ex;

	container_node *root;

	bool compute_interferences;

	bool has_alu_predication;
	bool uses_gradients;

	unsigned ngpr, nstack;

	shader(sb_context &sctx, shader_target t);

	~shader();

	sb_context &get_ctx() const { return ctx; }

	value* get_const_value(const literal & v);
	value* get_special_value(unsigned sv_id, unsigned version = 0);
	value* create_temp_value();
	value* get_gpr_value(bool src, unsigned reg, unsigned chan, bool rel,
                         unsigned version = 0);


	value* get_special_ro_value(unsigned sel);
	value* get_kcache_value(unsigned bank, unsigned index, unsigned chan);

	value* get_value_version(value* v, unsigned ver);

	void init();
	void add_gpr_values(vvec& vec, unsigned gpr, unsigned comp_mask, bool src);

	void dump_ir();

	void add_gpr_array(unsigned gpr_start, unsigned gpr_count,
	                   unsigned comp_mask);

	value* get_pred_sel(int sel);
	bool assign_slot(alu_node *n, alu_node *slots[5]);

	gpr_array* get_gpr_array(unsigned reg, unsigned chan);

	void add_input(unsigned gpr, bool preloaded = false,
	               unsigned comp_mask = 0xF);

	const inputs_vec & get_inputs() {return inputs; }

	regions_vec & get_regions() { return regions; }

	void init_call_fs(cf_node *cf);

	value *get_undef_value();
	void set_undef(val_set &s);

	void transfer_pins(vvec& vv, vvec &sv);

	node* create_node(node_type nt, node_subtype nst,
	                  node_flags flags = NF_EMPTY);
	alu_node* create_alu();
	alu_group_node* create_alu_group();
	alu_packed_node* create_alu_packed();
	cf_node* create_cf();
	cf_node* create_cf(unsigned op);
	fetch_node* create_fetch();
	region_node* create_region();
	depart_node* create_depart(region_node *target);
	repeat_node* create_repeat(region_node *target);
	container_node* create_container(node_type nt = NT_LIST,
	                                 node_subtype nst = NST_LIST,
	                                 node_flags flags = NF_EMPTY);
	if_node* create_if();
	bb_node* create_bb(unsigned id, unsigned loop_level);

	void prepare_regs(unsigned cnt);

	value* get_value_by_uid(unsigned id) { return val_pool[id - 1]; }

	cf_node* create_clause(node_subtype nst);

	void create_bbs();
	void expand_bbs();

	alu_node* create_mov(value* dst, value* src);
	alu_node* create_copy_mov(value *dst, value *src, unsigned affcost = 1);

	const char * get_hw_class_name();
	const char * get_hw_chip_name();
	const char * get_shader_target_name();

	std::string get_full_target_name();

	void create_bbs(container_node* n, bbs_vec &bbs, int loop_level = 0);
	void expand_bbs(bbs_vec &bbs);

	queue_id get_queue_id(node* n);

	void simplify_dep_rep(node *dr);

	unsigned first_temp_gpr();
	unsigned num_nontemp_gpr();

	gpr_array_vec& arrays() { return gpr_arrays; }

	void set_uses_kill();

	void fill_array_values(gpr_array *a, vvec &vv);

	alu_node* clone(alu_node *n);

	sb_value_pool& get_value_pool() { return val_pool; }

private:
	value* create_value(value_kind k, sel_chan regid, unsigned ver);
	value* get_value(value_kind kind, sel_chan id,
	                         unsigned version = 0);
	value* get_ro_value(value_map &vm, value_kind vk, unsigned key);
};

}

#endif /* SHADER_H_ */