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