Merge remote-tracking branch 'origin/master' into pipe-video
[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 uint32_t value;
38 };
39
40 struct r600_bc_alu_dst {
41 unsigned sel;
42 unsigned chan;
43 unsigned clamp;
44 unsigned write;
45 unsigned rel;
46 };
47
48 struct r600_bc_alu {
49 struct list_head list;
50 struct r600_bc_alu_src src[3];
51 struct r600_bc_alu_dst dst;
52 unsigned inst;
53 unsigned last;
54 unsigned is_op3;
55 unsigned predicate;
56 unsigned bank_swizzle;
57 unsigned bank_swizzle_force;
58 unsigned omod;
59 };
60
61 struct r600_bc_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_bc_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_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 burst_count;
122 unsigned barrier;
123 };
124
125 struct r600_bc_kcache {
126 unsigned bank;
127 unsigned mode;
128 unsigned addr;
129 };
130
131 struct r600_bc_cf {
132 struct list_head list;
133 unsigned inst;
134 unsigned addr;
135 unsigned ndw;
136 unsigned id;
137 unsigned cond;
138 unsigned pop_count;
139 unsigned cf_addr; /* control flow addr */
140 struct r600_bc_kcache kcache[2];
141 unsigned r6xx_uses_waterfall;
142 struct list_head alu;
143 struct list_head tex;
144 struct list_head vtx;
145 struct r600_bc_output output;
146 struct r600_bc_alu *curr_bs_head;
147 struct r600_bc_alu *prev_bs_head;
148 struct r600_bc_alu *prev2_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
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_vtx(struct r600_bc *bc, const struct r600_bc_vtx *vtx);
200 int r600_bc_add_tex(struct r600_bc *bc, const struct r600_bc_tex *tex);
201 int r600_bc_add_output(struct r600_bc *bc, const struct r600_bc_output *output);
202 int r600_bc_build(struct r600_bc *bc);
203 int r600_bc_add_cfinst(struct r600_bc *bc, int inst);
204 int r600_bc_add_alu_type(struct r600_bc *bc, const struct r600_bc_alu *alu, int type);
205 void r600_bc_special_constants(u32 value, unsigned *sel, unsigned *neg);
206 void r600_bc_dump(struct r600_bc *bc);
207
208 int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context *rctx, struct r600_vertex_element *ve);
209
210 /* r700_asm.c */
211 void r700_bc_cf_vtx_build(uint32_t *bytecode, const struct r600_bc_cf *cf);
212 int r700_bc_alu_build(struct r600_bc *bc, struct r600_bc_alu *alu, unsigned id);
213
214 #endif