r600g: implement output modifiers and use them to further optimize LRP
[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 unsigned omod;
66 };
67
68 struct r600_bc_tex {
69 struct list_head list;
70 unsigned inst;
71 unsigned resource_id;
72 unsigned src_gpr;
73 unsigned src_rel;
74 unsigned dst_gpr;
75 unsigned dst_rel;
76 unsigned dst_sel_x;
77 unsigned dst_sel_y;
78 unsigned dst_sel_z;
79 unsigned dst_sel_w;
80 unsigned lod_bias;
81 unsigned coord_type_x;
82 unsigned coord_type_y;
83 unsigned coord_type_z;
84 unsigned coord_type_w;
85 unsigned offset_x;
86 unsigned offset_y;
87 unsigned offset_z;
88 unsigned sampler_id;
89 unsigned src_sel_x;
90 unsigned src_sel_y;
91 unsigned src_sel_z;
92 unsigned src_sel_w;
93 };
94
95 struct r600_bc_vtx {
96 struct list_head list;
97 unsigned inst;
98 unsigned fetch_type;
99 unsigned buffer_id;
100 unsigned src_gpr;
101 unsigned src_sel_x;
102 unsigned mega_fetch_count;
103 unsigned dst_gpr;
104 unsigned dst_sel_x;
105 unsigned dst_sel_y;
106 unsigned dst_sel_z;
107 unsigned dst_sel_w;
108 unsigned use_const_fields;
109 unsigned data_format;
110 unsigned num_format_all;
111 unsigned format_comp_all;
112 unsigned srf_mode_all;
113 };
114
115 struct r600_bc_output {
116 unsigned array_base;
117 unsigned type;
118 unsigned end_of_program;
119 unsigned inst;
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 barrier;
127 };
128
129 struct r600_bc_kcache {
130 unsigned bank;
131 unsigned mode;
132 unsigned addr;
133 };
134
135 struct r600_bc_cf {
136 struct list_head list;
137 unsigned inst;
138 unsigned addr;
139 unsigned ndw;
140 unsigned id;
141 unsigned cond;
142 unsigned pop_count;
143 unsigned cf_addr; /* control flow addr */
144 struct r600_bc_kcache kcache[2];
145 unsigned r6xx_uses_waterfall;
146 struct list_head alu;
147 struct list_head tex;
148 struct list_head vtx;
149 struct r600_bc_output output;
150 struct r600_bc_alu *curr_bs_head;
151 };
152
153 #define FC_NONE 0
154 #define FC_IF 1
155 #define FC_LOOP 2
156 #define FC_REP 3
157 #define FC_PUSH_VPM 4
158 #define FC_PUSH_WQM 5
159
160 struct r600_cf_stack_entry {
161 int type;
162 struct r600_bc_cf *start;
163 struct r600_bc_cf **mid; /* used to store the else point */
164 int num_mid;
165 };
166
167 #define SQ_MAX_CALL_DEPTH 0x00000020
168 struct r600_cf_callstack {
169 unsigned fc_sp_before_entry;
170 int sub_desc_index;
171 int current;
172 int max;
173 };
174
175 struct r600_bc {
176 enum radeon_family family;
177 int chiprev; /* 0 - r600, 1 - r700, 2 - evergreen */
178 int type;
179 struct list_head cf;
180 struct r600_bc_cf *cf_last;
181 unsigned ndw;
182 unsigned ncf;
183 unsigned ngpr;
184 unsigned nstack;
185 unsigned nresource;
186 unsigned force_add_cf;
187 u32 *bytecode;
188 u32 fc_sp;
189 struct r600_cf_stack_entry fc_stack[32];
190 unsigned call_sp;
191 struct r600_cf_callstack callstack[SQ_MAX_CALL_DEPTH];
192 };
193
194 /* eg_asm.c */
195 int eg_bc_cf_build(struct r600_bc *bc, struct r600_bc_cf *cf);
196 void eg_cf_vtx(struct r600_vertex_element *ve, u32 *bytecode, unsigned count);
197
198 /* r600_asm.c */
199 int r600_bc_init(struct r600_bc *bc, enum radeon_family family);
200 void r600_bc_clear(struct r600_bc *bc);
201 int r600_bc_add_alu(struct r600_bc *bc, const struct r600_bc_alu *alu);
202 int r600_bc_add_literal(struct r600_bc *bc, const u32 *value);
203 int r600_bc_add_vtx(struct r600_bc *bc, const struct r600_bc_vtx *vtx);
204 int r600_bc_add_tex(struct r600_bc *bc, const struct r600_bc_tex *tex);
205 int r600_bc_add_output(struct r600_bc *bc, const struct r600_bc_output *output);
206 int r600_bc_build(struct r600_bc *bc);
207 int r600_bc_add_cfinst(struct r600_bc *bc, int inst);
208 int r600_bc_add_alu_type(struct r600_bc *bc, const struct r600_bc_alu *alu, int type);
209 void r600_bc_dump(struct r600_bc *bc);
210 void r600_cf_vtx(struct r600_vertex_element *ve, u32 *bytecode, unsigned count);
211 void r600_cf_vtx_tc(struct r600_vertex_element *ve, u32 *bytecode, unsigned count);
212
213 int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context *rctx, struct r600_vertex_element *ve);
214
215 /* r700_asm.c */
216 int r700_bc_alu_build(struct r600_bc *bc, struct r600_bc_alu *alu, unsigned id);
217
218 #endif