r600g: merge alu groups
[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 #include "util/u_double_list.h"
27
28 struct r600_vertex_element;
29 struct r600_pipe_context;
30
31 struct r600_bc_alu_src {
32 unsigned sel;
33 unsigned chan;
34 unsigned neg;
35 unsigned abs;
36 unsigned rel;
37 };
38
39 struct r600_bc_alu_dst {
40 unsigned sel;
41 unsigned chan;
42 unsigned clamp;
43 unsigned write;
44 unsigned rel;
45 };
46
47 struct r600_bc_alu {
48 struct list_head list;
49 struct r600_bc_alu_src src[3];
50 struct r600_bc_alu_dst dst;
51 unsigned inst;
52 unsigned last;
53 unsigned is_op3;
54 unsigned predicate;
55 unsigned nliteral;
56 unsigned literal_added;
57 unsigned bank_swizzle;
58 unsigned bank_swizzle_force;
59 u32 value[4];
60 unsigned omod;
61 };
62
63 struct r600_bc_tex {
64 struct list_head list;
65 unsigned inst;
66 unsigned resource_id;
67 unsigned src_gpr;
68 unsigned src_rel;
69 unsigned dst_gpr;
70 unsigned dst_rel;
71 unsigned dst_sel_x;
72 unsigned dst_sel_y;
73 unsigned dst_sel_z;
74 unsigned dst_sel_w;
75 unsigned lod_bias;
76 unsigned coord_type_x;
77 unsigned coord_type_y;
78 unsigned coord_type_z;
79 unsigned coord_type_w;
80 unsigned offset_x;
81 unsigned offset_y;
82 unsigned offset_z;
83 unsigned sampler_id;
84 unsigned src_sel_x;
85 unsigned src_sel_y;
86 unsigned src_sel_z;
87 unsigned src_sel_w;
88 };
89
90 struct r600_bc_vtx {
91 struct list_head list;
92 unsigned inst;
93 unsigned fetch_type;
94 unsigned buffer_id;
95 unsigned src_gpr;
96 unsigned src_sel_x;
97 unsigned mega_fetch_count;
98 unsigned dst_gpr;
99 unsigned dst_sel_x;
100 unsigned dst_sel_y;
101 unsigned dst_sel_z;
102 unsigned dst_sel_w;
103 unsigned use_const_fields;
104 unsigned data_format;
105 unsigned num_format_all;
106 unsigned format_comp_all;
107 unsigned srf_mode_all;
108 };
109
110 struct r600_bc_output {
111 unsigned array_base;
112 unsigned type;
113 unsigned end_of_program;
114 unsigned inst;
115 unsigned elem_size;
116 unsigned gpr;
117 unsigned swizzle_x;
118 unsigned swizzle_y;
119 unsigned swizzle_z;
120 unsigned swizzle_w;
121 unsigned barrier;
122 };
123
124 struct r600_bc_kcache {
125 unsigned bank;
126 unsigned mode;
127 unsigned addr;
128 };
129
130 struct r600_bc_cf {
131 struct list_head list;
132 unsigned inst;
133 unsigned addr;
134 unsigned ndw;
135 unsigned id;
136 unsigned cond;
137 unsigned pop_count;
138 unsigned cf_addr; /* control flow addr */
139 struct r600_bc_kcache kcache[2];
140 unsigned r6xx_uses_waterfall;
141 struct list_head alu;
142 struct list_head tex;
143 struct list_head vtx;
144 struct r600_bc_output output;
145 struct r600_bc_alu *curr_bs_head;
146 struct r600_bc_alu *prev_bs_head;
147 struct r600_bc_alu *prev2_bs_head;
148 };
149
150 #define FC_NONE 0
151 #define FC_IF 1
152 #define FC_LOOP 2
153 #define FC_REP 3
154 #define FC_PUSH_VPM 4
155 #define FC_PUSH_WQM 5
156
157 struct r600_cf_stack_entry {
158 int type;
159 struct r600_bc_cf *start;
160 struct r600_bc_cf **mid; /* used to store the else point */
161 int num_mid;
162 };
163
164 #define SQ_MAX_CALL_DEPTH 0x00000020
165 struct r600_cf_callstack {
166 unsigned fc_sp_before_entry;
167 int sub_desc_index;
168 int current;
169 int max;
170 };
171
172 struct r600_bc {
173 enum radeon_family family;
174 int chiprev; /* 0 - r600, 1 - r700, 2 - evergreen */
175 int type;
176 struct list_head cf;
177 struct r600_bc_cf *cf_last;
178 unsigned ndw;
179 unsigned ncf;
180 unsigned ngpr;
181 unsigned nstack;
182 unsigned nresource;
183 unsigned force_add_cf;
184 u32 *bytecode;
185 u32 fc_sp;
186 struct r600_cf_stack_entry fc_stack[32];
187 unsigned call_sp;
188 struct r600_cf_callstack callstack[SQ_MAX_CALL_DEPTH];
189 };
190
191 /* eg_asm.c */
192 int eg_bc_cf_build(struct r600_bc *bc, struct r600_bc_cf *cf);
193 void eg_cf_vtx(struct r600_vertex_element *ve, u32 *bytecode, unsigned count);
194
195 /* r600_asm.c */
196 int r600_bc_init(struct r600_bc *bc, enum radeon_family family);
197 void r600_bc_clear(struct r600_bc *bc);
198 int r600_bc_add_alu(struct r600_bc *bc, const struct r600_bc_alu *alu);
199 int r600_bc_add_literal(struct r600_bc *bc, const u32 *value);
200 int r600_bc_add_vtx(struct r600_bc *bc, const struct r600_bc_vtx *vtx);
201 int r600_bc_add_tex(struct r600_bc *bc, const struct r600_bc_tex *tex);
202 int r600_bc_add_output(struct r600_bc *bc, const struct r600_bc_output *output);
203 int r600_bc_build(struct r600_bc *bc);
204 int r600_bc_add_cfinst(struct r600_bc *bc, int inst);
205 int r600_bc_add_alu_type(struct r600_bc *bc, const struct r600_bc_alu *alu, int type);
206 void r600_bc_dump(struct r600_bc *bc);
207 void r600_cf_vtx(struct r600_vertex_element *ve, u32 *bytecode, unsigned count);
208 void r600_cf_vtx_tc(struct r600_vertex_element *ve, u32 *bytecode, unsigned count);
209
210 int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context *rctx, struct r600_vertex_element *ve);
211
212 /* r700_asm.c */
213 int r700_bc_alu_build(struct r600_bc *bc, struct r600_bc_alu *alu, unsigned id);
214
215 #endif