r600g: merge r600_context with r600_pipe_context
[mesa.git] / src / gallium / drivers / r600 / r600_asm.h
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 #ifndef R600_ASM_H
24 #define R600_ASM_H
25
26 struct r600_vertex_element;
27 struct r600_context;
28
29 struct r600_bytecode_alu_src {
30 unsigned sel;
31 unsigned chan;
32 unsigned neg;
33 unsigned abs;
34 unsigned rel;
35 unsigned kc_bank;
36 uint32_t value;
37 };
38
39 struct r600_bytecode_alu_dst {
40 unsigned sel;
41 unsigned chan;
42 unsigned clamp;
43 unsigned write;
44 unsigned rel;
45 };
46
47 struct r600_bytecode_alu {
48 struct list_head list;
49 struct r600_bytecode_alu_src src[3];
50 struct r600_bytecode_alu_dst dst;
51 unsigned inst;
52 unsigned last;
53 unsigned is_op3;
54 unsigned predicate;
55 unsigned bank_swizzle;
56 unsigned bank_swizzle_force;
57 unsigned omod;
58 unsigned index_mode;
59 };
60
61 struct r600_bytecode_tex {
62 struct list_head list;
63 unsigned inst;
64 unsigned resource_id;
65 unsigned src_gpr;
66 unsigned src_rel;
67 unsigned dst_gpr;
68 unsigned dst_rel;
69 unsigned dst_sel_x;
70 unsigned dst_sel_y;
71 unsigned dst_sel_z;
72 unsigned dst_sel_w;
73 unsigned lod_bias;
74 unsigned coord_type_x;
75 unsigned coord_type_y;
76 unsigned coord_type_z;
77 unsigned coord_type_w;
78 unsigned offset_x;
79 unsigned offset_y;
80 unsigned offset_z;
81 unsigned sampler_id;
82 unsigned src_sel_x;
83 unsigned src_sel_y;
84 unsigned src_sel_z;
85 unsigned src_sel_w;
86 };
87
88 struct r600_bytecode_vtx {
89 struct list_head list;
90 unsigned inst;
91 unsigned fetch_type;
92 unsigned buffer_id;
93 unsigned src_gpr;
94 unsigned src_sel_x;
95 unsigned mega_fetch_count;
96 unsigned dst_gpr;
97 unsigned dst_sel_x;
98 unsigned dst_sel_y;
99 unsigned dst_sel_z;
100 unsigned dst_sel_w;
101 unsigned use_const_fields;
102 unsigned data_format;
103 unsigned num_format_all;
104 unsigned format_comp_all;
105 unsigned srf_mode_all;
106 unsigned offset;
107 unsigned endian;
108 };
109
110 struct r600_bytecode_output {
111 unsigned array_base;
112 unsigned array_size;
113 unsigned comp_mask;
114 unsigned type;
115 unsigned end_of_program;
116
117 /* CF_INST. This is already bit-shifted and only needs to be or'd for bytecode. */
118 unsigned inst;
119
120 unsigned elem_size;
121 unsigned gpr;
122 unsigned swizzle_x;
123 unsigned swizzle_y;
124 unsigned swizzle_z;
125 unsigned swizzle_w;
126 unsigned burst_count;
127 unsigned barrier;
128 };
129
130 struct r600_bytecode_kcache {
131 unsigned bank;
132 unsigned mode;
133 unsigned addr;
134 };
135
136 struct r600_bytecode_cf {
137 struct list_head list;
138
139 /* CF_INST. This is already bit-shifted and only needs to be or'd for bytecode. */
140 unsigned inst;
141
142 unsigned addr;
143 unsigned ndw;
144 unsigned id;
145 unsigned cond;
146 unsigned pop_count;
147 unsigned cf_addr; /* control flow addr */
148 struct r600_bytecode_kcache kcache[4];
149 unsigned r6xx_uses_waterfall;
150 unsigned eg_alu_extended;
151 struct list_head alu;
152 struct list_head tex;
153 struct list_head vtx;
154 struct r600_bytecode_output output;
155 struct r600_bytecode_alu *curr_bs_head;
156 struct r600_bytecode_alu *prev_bs_head;
157 struct r600_bytecode_alu *prev2_bs_head;
158 };
159
160 #define FC_NONE 0
161 #define FC_IF 1
162 #define FC_LOOP 2
163 #define FC_REP 3
164 #define FC_PUSH_VPM 4
165 #define FC_PUSH_WQM 5
166
167 struct r600_cf_stack_entry {
168 int type;
169 struct r600_bytecode_cf *start;
170 struct r600_bytecode_cf **mid; /* used to store the else point */
171 int num_mid;
172 };
173
174 #define SQ_MAX_CALL_DEPTH 0x00000020
175 struct r600_cf_callstack {
176 unsigned fc_sp_before_entry;
177 int sub_desc_index;
178 int current;
179 int max;
180 };
181
182 #define AR_HANDLE_NORMAL 0
183 #define AR_HANDLE_RV6XX 1 /* except RV670 */
184
185
186 struct r600_bytecode {
187 enum chip_class chip_class;
188 int type;
189 struct list_head cf;
190 struct r600_bytecode_cf *cf_last;
191 unsigned ndw;
192 unsigned ncf;
193 unsigned ngpr;
194 unsigned nstack;
195 unsigned nresource;
196 unsigned force_add_cf;
197 uint32_t *bytecode;
198 uint32_t fc_sp;
199 struct r600_cf_stack_entry fc_stack[32];
200 unsigned call_sp;
201 struct r600_cf_callstack callstack[SQ_MAX_CALL_DEPTH];
202 unsigned ar_loaded;
203 unsigned ar_reg;
204 unsigned ar_handling;
205 unsigned r6xx_nop_after_rel_dst;
206 };
207
208 /* eg_asm.c */
209 int eg_bytecode_cf_build(struct r600_bytecode *bc, struct r600_bytecode_cf *cf);
210
211 /* r600_asm.c */
212 void r600_bytecode_init(struct r600_bytecode *bc, enum chip_class chip_class, enum radeon_family family);
213 void r600_bytecode_clear(struct r600_bytecode *bc);
214 int r600_bytecode_add_alu(struct r600_bytecode *bc, const struct r600_bytecode_alu *alu);
215 int r600_bytecode_add_vtx(struct r600_bytecode *bc, const struct r600_bytecode_vtx *vtx);
216 int r600_bytecode_add_tex(struct r600_bytecode *bc, const struct r600_bytecode_tex *tex);
217 int r600_bytecode_add_output(struct r600_bytecode *bc, const struct r600_bytecode_output *output);
218 int r600_bytecode_build(struct r600_bytecode *bc);
219 int r600_bytecode_add_cfinst(struct r600_bytecode *bc, int inst);
220 int r600_bytecode_add_alu_type(struct r600_bytecode *bc, const struct r600_bytecode_alu *alu, int type);
221 void r600_bytecode_special_constants(uint32_t value, unsigned *sel, unsigned *neg);
222 void r600_bytecode_dump(struct r600_bytecode *bc);
223
224 int cm_bytecode_add_cf_end(struct r600_bytecode *bc);
225
226 int r600_vertex_elements_build_fetch_shader(struct r600_context *rctx, struct r600_vertex_element *ve);
227
228 /* r700_asm.c */
229 void r700_bytecode_cf_vtx_build(uint32_t *bytecode, const struct r600_bytecode_cf *cf);
230 int r700_bytecode_alu_build(struct r600_bytecode *bc, struct r600_bytecode_alu *alu, unsigned id);
231
232 #endif