r600g : add basic loop support.
[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 "radeon.h"
27 #include "util/u_double_list.h"
28
29 struct r600_bc_alu_src {
30 unsigned sel;
31 unsigned chan;
32 unsigned neg;
33 unsigned abs;
34 };
35
36 struct r600_bc_alu_dst {
37 unsigned sel;
38 unsigned chan;
39 unsigned clamp;
40 unsigned write;
41 };
42
43 struct r600_bc_alu {
44 struct list_head list;
45 struct r600_bc_alu_src src[3];
46 struct r600_bc_alu_dst dst;
47 unsigned inst;
48 unsigned last;
49 unsigned is_op3;
50 unsigned predicate;
51 unsigned nliteral;
52 unsigned literal_added;
53 u32 value[4];
54 };
55
56 struct r600_bc_tex {
57 struct list_head list;
58 unsigned inst;
59 unsigned resource_id;
60 unsigned src_gpr;
61 unsigned src_rel;
62 unsigned dst_gpr;
63 unsigned dst_rel;
64 unsigned dst_sel_x;
65 unsigned dst_sel_y;
66 unsigned dst_sel_z;
67 unsigned dst_sel_w;
68 unsigned lod_bias;
69 unsigned coord_type_x;
70 unsigned coord_type_y;
71 unsigned coord_type_z;
72 unsigned coord_type_w;
73 unsigned offset_x;
74 unsigned offset_y;
75 unsigned offset_z;
76 unsigned sampler_id;
77 unsigned src_sel_x;
78 unsigned src_sel_y;
79 unsigned src_sel_z;
80 unsigned src_sel_w;
81 };
82
83 struct r600_bc_vtx {
84 struct list_head list;
85 unsigned inst;
86 unsigned fetch_type;
87 unsigned buffer_id;
88 unsigned src_gpr;
89 unsigned src_sel_x;
90 unsigned mega_fetch_count;
91 unsigned dst_gpr;
92 unsigned dst_sel_x;
93 unsigned dst_sel_y;
94 unsigned dst_sel_z;
95 unsigned dst_sel_w;
96 };
97
98 struct r600_bc_output {
99 unsigned array_base;
100 unsigned type;
101 unsigned end_of_program;
102 unsigned inst;
103 unsigned elem_size;
104 unsigned gpr;
105 unsigned swizzle_x;
106 unsigned swizzle_y;
107 unsigned swizzle_z;
108 unsigned swizzle_w;
109 unsigned barrier;
110 };
111
112 struct r600_bc_cf {
113 struct list_head list;
114 unsigned inst;
115 unsigned addr;
116 unsigned ndw;
117 unsigned id;
118 unsigned cond;
119 unsigned pop_count;
120 unsigned cf_addr; /* control flow addr */
121 struct list_head alu;
122 struct list_head tex;
123 struct list_head vtx;
124 struct r600_bc_output output;
125 };
126
127 #define FC_NONE 0
128 #define FC_IF 1
129 #define FC_LOOP 2
130 #define FC_REP 3
131 #define FC_PUSH_VPM 4
132 #define FC_PUSH_WQM 5
133
134 struct r600_cf_stack_entry {
135 int type;
136 struct r600_bc_cf *start;
137 struct r600_bc_cf **mid; /* used to store the else point */
138 int num_mid;
139 };
140
141 #define SQ_MAX_CALL_DEPTH 0x00000020
142 struct r600_cf_callstack {
143 unsigned fc_sp_before_entry;
144 int sub_desc_index;
145 int current;
146 int max;
147 };
148
149 struct r600_bc {
150 enum radeon_family family;
151 int chiprev; /* 0 - r600, 1 - r700, 2 - evergreen */
152 struct list_head cf;
153 struct r600_bc_cf *cf_last;
154 unsigned ndw;
155 unsigned ncf;
156 unsigned ngpr;
157 unsigned nstack;
158 unsigned nresource;
159 unsigned force_add_cf;
160 u32 *bytecode;
161
162 u32 fc_sp;
163 struct r600_cf_stack_entry fc_stack[32];
164
165 unsigned call_sp;
166 struct r600_cf_callstack callstack[SQ_MAX_CALL_DEPTH];
167 };
168
169 int r600_bc_init(struct r600_bc *bc, enum radeon_family family);
170 int r600_bc_add_alu(struct r600_bc *bc, const struct r600_bc_alu *alu);
171 int r600_bc_add_literal(struct r600_bc *bc, const u32 *value);
172 int r600_bc_add_vtx(struct r600_bc *bc, const struct r600_bc_vtx *vtx);
173 int r600_bc_add_tex(struct r600_bc *bc, const struct r600_bc_tex *tex);
174 int r600_bc_add_output(struct r600_bc *bc, const struct r600_bc_output *output);
175 int r600_bc_build(struct r600_bc *bc);
176 int r600_bc_add_cfinst(struct r600_bc *bc, int inst);
177 int r600_bc_add_alu_type(struct r600_bc *bc, const struct r600_bc_alu *alu, int type);
178 #endif