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_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 unsigned kcache0_mode;
139 unsigned kcache1_mode;
140 unsigned kcache0_addr;
141 unsigned kcache1_addr;
142 unsigned kcache0_bank;
143 unsigned kcache1_bank;
144 unsigned r6xx_uses_waterfall;
145 struct list_head alu;
146 struct list_head tex;
147 struct list_head vtx;
148 struct r600_bc_output output;
149 struct r600_bc_alu *curr_bs_head;
150 };
151
152 #define FC_NONE 0
153 #define FC_IF 1
154 #define FC_LOOP 2
155 #define FC_REP 3
156 #define FC_PUSH_VPM 4
157 #define FC_PUSH_WQM 5
158
159 struct r600_cf_stack_entry {
160 int type;
161 struct r600_bc_cf *start;
162 struct r600_bc_cf **mid; /* used to store the else point */
163 int num_mid;
164 };
165
166 #define SQ_MAX_CALL_DEPTH 0x00000020
167 struct r600_cf_callstack {
168 unsigned fc_sp_before_entry;
169 int sub_desc_index;
170 int current;
171 int max;
172 };
173
174 struct r600_bc {
175 enum radeon_family family;
176 int chiprev; /* 0 - r600, 1 - r700, 2 - evergreen */
177 int type;
178 struct list_head cf;
179 struct r600_bc_cf *cf_last;
180 unsigned ndw;
181 unsigned ncf;
182 unsigned ngpr;
183 unsigned nstack;
184 unsigned nresource;
185 unsigned force_add_cf;
186 u32 *bytecode;
187 u32 fc_sp;
188 struct r600_cf_stack_entry fc_stack[32];
189 unsigned call_sp;
190 struct r600_cf_callstack callstack[SQ_MAX_CALL_DEPTH];
191 };
192
193 /* eg_asm.c */
194 int eg_bc_cf_build(struct r600_bc *bc, struct r600_bc_cf *cf);
195 void eg_cf_vtx(struct r600_vertex_element *ve, u32 *bytecode, unsigned count);
196
197 /* r600_asm.c */
198 int r600_bc_init(struct r600_bc *bc, enum radeon_family family);
199 void r600_bc_clear(struct r600_bc *bc);
200 int r600_bc_add_alu(struct r600_bc *bc, const struct r600_bc_alu *alu);
201 int r600_bc_add_literal(struct r600_bc *bc, const u32 *value);
202 int r600_bc_add_vtx(struct r600_bc *bc, const struct r600_bc_vtx *vtx);
203 int r600_bc_add_tex(struct r600_bc *bc, const struct r600_bc_tex *tex);
204 int r600_bc_add_output(struct r600_bc *bc, const struct r600_bc_output *output);
205 int r600_bc_build(struct r600_bc *bc);
206 int r600_bc_add_cfinst(struct r600_bc *bc, int inst);
207 int r600_bc_add_alu_type(struct r600_bc *bc, const struct r600_bc_alu *alu, int type);
208 void r600_bc_dump(struct r600_bc *bc);
209 void r600_cf_vtx(struct r600_vertex_element *ve, u32 *bytecode, unsigned count);
210 void r600_cf_vtx_tc(struct r600_vertex_element *ve, u32 *bytecode, unsigned count);
211
212 int r600_vertex_elements_build_fetch_shader(struct r600_pipe_context *rctx, struct r600_vertex_element *ve);
213
214 /* r700_asm.c */
215 int r700_bc_alu_build(struct r600_bc *bc, struct r600_bc_alu *alu, unsigned id);
216
217 #endif