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