r600g: don't use dynamic state allocation for states
[mesa.git] / src / gallium / drivers / r600 / r600_context.c
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 * Authors:
24 * Jerome Glisse
25 * Corbin Simpson
26 */
27 #include <stdio.h>
28 #include <util/u_inlines.h>
29 #include <util/u_format.h>
30 #include <util/u_memory.h>
31 #include <util/u_blitter.h>
32 #include "r600_screen.h"
33 #include "r600_context.h"
34 #include "r600_resource.h"
35 #include "r600d.h"
36
37 static void r600_destroy_context(struct pipe_context *context)
38 {
39 struct r600_context *rctx = r600_context(context);
40
41 FREE(rctx);
42 }
43
44 void r600_flush(struct pipe_context *ctx, unsigned flags,
45 struct pipe_fence_handle **fence)
46 {
47 struct r600_context *rctx = r600_context(ctx);
48 struct r600_screen *rscreen = rctx->screen;
49 static int dc = 0;
50
51 if (radeon_ctx_pm4(&rctx->ctx))
52 return;
53 /* FIXME dumping should be removed once shader support instructions
54 * without throwing bad code
55 */
56 if (!dc)
57 radeon_ctx_dump_bof(&rctx->ctx, "gallium.bof");
58 radeon_ctx_submit(&rctx->ctx);
59 dc++;
60 }
61
62 static void r600_init_config(struct r600_context *rctx)
63 {
64 int ps_prio;
65 int vs_prio;
66 int gs_prio;
67 int es_prio;
68 int num_ps_gprs;
69 int num_vs_gprs;
70 int num_gs_gprs;
71 int num_es_gprs;
72 int num_temp_gprs;
73 int num_ps_threads;
74 int num_vs_threads;
75 int num_gs_threads;
76 int num_es_threads;
77 int num_ps_stack_entries;
78 int num_vs_stack_entries;
79 int num_gs_stack_entries;
80 int num_es_stack_entries;
81 enum radeon_family family;
82
83 family = radeon_get_family(rctx->rw);
84 ps_prio = 0;
85 vs_prio = 1;
86 gs_prio = 2;
87 es_prio = 3;
88 switch (family) {
89 case CHIP_R600:
90 num_ps_gprs = 192;
91 num_vs_gprs = 56;
92 num_temp_gprs = 4;
93 num_gs_gprs = 0;
94 num_es_gprs = 0;
95 num_ps_threads = 136;
96 num_vs_threads = 48;
97 num_gs_threads = 4;
98 num_es_threads = 4;
99 num_ps_stack_entries = 128;
100 num_vs_stack_entries = 128;
101 num_gs_stack_entries = 0;
102 num_es_stack_entries = 0;
103 break;
104 case CHIP_RV630:
105 case CHIP_RV635:
106 num_ps_gprs = 84;
107 num_vs_gprs = 36;
108 num_temp_gprs = 4;
109 num_gs_gprs = 0;
110 num_es_gprs = 0;
111 num_ps_threads = 144;
112 num_vs_threads = 40;
113 num_gs_threads = 4;
114 num_es_threads = 4;
115 num_ps_stack_entries = 40;
116 num_vs_stack_entries = 40;
117 num_gs_stack_entries = 32;
118 num_es_stack_entries = 16;
119 break;
120 case CHIP_RV610:
121 case CHIP_RV620:
122 case CHIP_RS780:
123 case CHIP_RS880:
124 default:
125 num_ps_gprs = 84;
126 num_vs_gprs = 36;
127 num_temp_gprs = 4;
128 num_gs_gprs = 0;
129 num_es_gprs = 0;
130 num_ps_threads = 136;
131 num_vs_threads = 48;
132 num_gs_threads = 4;
133 num_es_threads = 4;
134 num_ps_stack_entries = 40;
135 num_vs_stack_entries = 40;
136 num_gs_stack_entries = 32;
137 num_es_stack_entries = 16;
138 break;
139 case CHIP_RV670:
140 num_ps_gprs = 144;
141 num_vs_gprs = 40;
142 num_temp_gprs = 4;
143 num_gs_gprs = 0;
144 num_es_gprs = 0;
145 num_ps_threads = 136;
146 num_vs_threads = 48;
147 num_gs_threads = 4;
148 num_es_threads = 4;
149 num_ps_stack_entries = 40;
150 num_vs_stack_entries = 40;
151 num_gs_stack_entries = 32;
152 num_es_stack_entries = 16;
153 break;
154 case CHIP_RV770:
155 num_ps_gprs = 192;
156 num_vs_gprs = 56;
157 num_temp_gprs = 4;
158 num_gs_gprs = 0;
159 num_es_gprs = 0;
160 num_ps_threads = 188;
161 num_vs_threads = 60;
162 num_gs_threads = 0;
163 num_es_threads = 0;
164 num_ps_stack_entries = 256;
165 num_vs_stack_entries = 256;
166 num_gs_stack_entries = 0;
167 num_es_stack_entries = 0;
168 break;
169 case CHIP_RV730:
170 case CHIP_RV740:
171 num_ps_gprs = 84;
172 num_vs_gprs = 36;
173 num_temp_gprs = 4;
174 num_gs_gprs = 0;
175 num_es_gprs = 0;
176 num_ps_threads = 188;
177 num_vs_threads = 60;
178 num_gs_threads = 0;
179 num_es_threads = 0;
180 num_ps_stack_entries = 128;
181 num_vs_stack_entries = 128;
182 num_gs_stack_entries = 0;
183 num_es_stack_entries = 0;
184 break;
185 case CHIP_RV710:
186 num_ps_gprs = 192;
187 num_vs_gprs = 56;
188 num_temp_gprs = 4;
189 num_gs_gprs = 0;
190 num_es_gprs = 0;
191 num_ps_threads = 144;
192 num_vs_threads = 48;
193 num_gs_threads = 0;
194 num_es_threads = 0;
195 num_ps_stack_entries = 128;
196 num_vs_stack_entries = 128;
197 num_gs_stack_entries = 0;
198 num_es_stack_entries = 0;
199 break;
200 }
201 printf("ps_prio : %d\n", ps_prio);
202 printf("vs_prio : %d\n", vs_prio);
203 printf("gs_prio : %d\n", gs_prio);
204 printf("es_prio : %d\n", es_prio);
205 printf("num_ps_gprs : %d\n", num_ps_gprs);
206 printf("num_vs_gprs : %d\n", num_vs_gprs);
207 printf("num_gs_gprs : %d\n", num_gs_gprs);
208 printf("num_es_gprs : %d\n", num_es_gprs);
209 printf("num_temp_gprs : %d\n", num_temp_gprs);
210 printf("num_ps_threads : %d\n", num_ps_threads);
211 printf("num_vs_threads : %d\n", num_vs_threads);
212 printf("num_gs_threads : %d\n", num_gs_threads);
213 printf("num_es_threads : %d\n", num_es_threads);
214 printf("num_ps_stack_entries : %d\n", num_ps_stack_entries);
215 printf("num_vs_stack_entries : %d\n", num_vs_stack_entries);
216 printf("num_gs_stack_entries : %d\n", num_gs_stack_entries);
217 printf("num_es_stack_entries : %d\n", num_es_stack_entries);
218
219 radeon_state_init(&rctx->config, rctx->rw, R600_CONFIG_TYPE, R600_CONFIG);
220 rctx->config.states[R600_CONFIG__SQ_CONFIG] = 0x00000000;
221 switch (family) {
222 case CHIP_RV610:
223 case CHIP_RV620:
224 case CHIP_RS780:
225 case CHIP_RS880:
226 case CHIP_RV710:
227 break;
228 default:
229 rctx->config.states[R600_CONFIG__SQ_CONFIG] |= S_008C00_VC_ENABLE(1);
230 break;
231 }
232 rctx->config.states[R600_CONFIG__SQ_CONFIG] |= S_008C00_DX9_CONSTS(1);
233 rctx->config.states[R600_CONFIG__SQ_CONFIG] |= S_008C00_ALU_INST_PREFER_VECTOR(1);
234 rctx->config.states[R600_CONFIG__SQ_CONFIG] |= S_008C00_PS_PRIO(ps_prio);
235 rctx->config.states[R600_CONFIG__SQ_CONFIG] |= S_008C00_VS_PRIO(vs_prio);
236 rctx->config.states[R600_CONFIG__SQ_CONFIG] |= S_008C00_GS_PRIO(gs_prio);
237 rctx->config.states[R600_CONFIG__SQ_CONFIG] |= S_008C00_ES_PRIO(es_prio);
238
239 rctx->config.states[R600_CONFIG__SQ_GPR_RESOURCE_MGMT_1] = 0;
240 rctx->config.states[R600_CONFIG__SQ_GPR_RESOURCE_MGMT_1] |= S_008C04_NUM_PS_GPRS(num_ps_gprs);
241 rctx->config.states[R600_CONFIG__SQ_GPR_RESOURCE_MGMT_1] |= S_008C04_NUM_VS_GPRS(num_vs_gprs);
242 rctx->config.states[R600_CONFIG__SQ_GPR_RESOURCE_MGMT_1] |= S_008C04_NUM_CLAUSE_TEMP_GPRS(num_temp_gprs);
243
244 rctx->config.states[R600_CONFIG__SQ_GPR_RESOURCE_MGMT_2] = 0;
245 rctx->config.states[R600_CONFIG__SQ_GPR_RESOURCE_MGMT_2] |= S_008C08_NUM_GS_GPRS(num_gs_gprs);
246 rctx->config.states[R600_CONFIG__SQ_GPR_RESOURCE_MGMT_2] |= S_008C08_NUM_GS_GPRS(num_es_gprs);
247
248 rctx->config.states[R600_CONFIG__SQ_THREAD_RESOURCE_MGMT] = 0;
249 rctx->config.states[R600_CONFIG__SQ_THREAD_RESOURCE_MGMT] |= S_008C0C_NUM_PS_THREADS(num_ps_threads);
250 rctx->config.states[R600_CONFIG__SQ_THREAD_RESOURCE_MGMT] |= S_008C0C_NUM_VS_THREADS(num_vs_threads);
251 rctx->config.states[R600_CONFIG__SQ_THREAD_RESOURCE_MGMT] |= S_008C0C_NUM_GS_THREADS(num_gs_threads);
252 rctx->config.states[R600_CONFIG__SQ_THREAD_RESOURCE_MGMT] |= S_008C0C_NUM_ES_THREADS(num_es_threads);
253
254 rctx->config.states[R600_CONFIG__SQ_STACK_RESOURCE_MGMT_1] = 0;
255 rctx->config.states[R600_CONFIG__SQ_STACK_RESOURCE_MGMT_1] |= S_008C10_NUM_PS_STACK_ENTRIES(num_ps_stack_entries);
256 rctx->config.states[R600_CONFIG__SQ_STACK_RESOURCE_MGMT_1] |= S_008C10_NUM_VS_STACK_ENTRIES(num_vs_stack_entries);
257
258 rctx->config.states[R600_CONFIG__SQ_STACK_RESOURCE_MGMT_2] = 0;
259 rctx->config.states[R600_CONFIG__SQ_STACK_RESOURCE_MGMT_2] |= S_008C14_NUM_GS_STACK_ENTRIES(num_gs_stack_entries);
260 rctx->config.states[R600_CONFIG__SQ_STACK_RESOURCE_MGMT_2] |= S_008C14_NUM_ES_STACK_ENTRIES(num_es_stack_entries);
261
262 rctx->config.states[R600_CONFIG__SQ_DYN_GPR_CNTL_PS_FLUSH_REQ] = 0x00004000;
263 rctx->config.states[R600_CONFIG__TA_CNTL_AUX] = 0x07000002;
264 rctx->config.states[R600_CONFIG__VC_ENHANCE] = 0x00000000;
265 rctx->config.states[R600_CONFIG__DB_DEBUG] = 0x00000000;
266 rctx->config.states[R600_CONFIG__DB_WATERMARKS] = 0x00420204;
267 rctx->config.states[R600_CONFIG__SX_MISC] = 0x00000000;
268 rctx->config.states[R600_CONFIG__SPI_THREAD_GROUPING] = 0x00000001;
269 rctx->config.states[R600_CONFIG__CB_SHADER_CONTROL] = 0x00000003;
270 rctx->config.states[R600_CONFIG__SQ_ESGS_RING_ITEMSIZE] = 0x00000000;
271 rctx->config.states[R600_CONFIG__SQ_GSVS_RING_ITEMSIZE] = 0x00000000;
272 rctx->config.states[R600_CONFIG__SQ_ESTMP_RING_ITEMSIZE] = 0x00000000;
273 rctx->config.states[R600_CONFIG__SQ_GSTMP_RING_ITEMSIZE] = 0x00000000;
274 rctx->config.states[R600_CONFIG__SQ_VSTMP_RING_ITEMSIZE] = 0x00000000;
275 rctx->config.states[R600_CONFIG__SQ_PSTMP_RING_ITEMSIZE] = 0x00000000;
276 rctx->config.states[R600_CONFIG__SQ_FBUF_RING_ITEMSIZE] = 0x00000000;
277 rctx->config.states[R600_CONFIG__SQ_REDUC_RING_ITEMSIZE] = 0x00000000;
278 rctx->config.states[R600_CONFIG__SQ_GS_VERT_ITEMSIZE] = 0x00000000;
279 rctx->config.states[R600_CONFIG__VGT_OUTPUT_PATH_CNTL] = 0x00000000;
280 rctx->config.states[R600_CONFIG__VGT_HOS_CNTL] = 0x00000000;
281 rctx->config.states[R600_CONFIG__VGT_HOS_MAX_TESS_LEVEL] = 0x00000000;
282 rctx->config.states[R600_CONFIG__VGT_HOS_MIN_TESS_LEVEL] = 0x00000000;
283 rctx->config.states[R600_CONFIG__VGT_HOS_REUSE_DEPTH] = 0x00000000;
284 rctx->config.states[R600_CONFIG__VGT_GROUP_PRIM_TYPE] = 0x00000000;
285 rctx->config.states[R600_CONFIG__VGT_GROUP_FIRST_DECR] = 0x00000000;
286 rctx->config.states[R600_CONFIG__VGT_GROUP_DECR] = 0x00000000;
287 rctx->config.states[R600_CONFIG__VGT_GROUP_VECT_0_CNTL] = 0x00000000;
288 rctx->config.states[R600_CONFIG__VGT_GROUP_VECT_1_CNTL] = 0x00000000;
289 rctx->config.states[R600_CONFIG__VGT_GROUP_VECT_0_FMT_CNTL] = 0x00000000;
290 rctx->config.states[R600_CONFIG__VGT_GROUP_VECT_1_FMT_CNTL] = 0x00000000;
291 rctx->config.states[R600_CONFIG__VGT_GS_MODE] = 0x00000000;
292 rctx->config.states[R600_CONFIG__PA_SC_MODE_CNTL] = 0x00514000;
293 rctx->config.states[R600_CONFIG__VGT_STRMOUT_EN] = 0x00000000;
294 rctx->config.states[R600_CONFIG__VGT_REUSE_OFF] = 0x00000001;
295 rctx->config.states[R600_CONFIG__VGT_VTX_CNT_EN] = 0x00000000;
296 rctx->config.states[R600_CONFIG__VGT_STRMOUT_BUFFER_EN] = 0x00000000;
297 radeon_state_pm4(&rctx->config);
298 }
299
300 struct pipe_context *r600_create_context(struct pipe_screen *screen, void *priv)
301 {
302 struct r600_context *rctx = CALLOC_STRUCT(r600_context);
303 struct r600_screen* rscreen = r600_screen(screen);
304
305 if (rctx == NULL)
306 return NULL;
307 rctx->context.winsys = rscreen->screen.winsys;
308 rctx->context.screen = screen;
309 rctx->context.priv = priv;
310 rctx->context.destroy = r600_destroy_context;
311 rctx->context.draw_vbo = r600_draw_vbo;
312 rctx->context.flush = r600_flush;
313
314 /* Easy accessing of screen/winsys. */
315 rctx->screen = rscreen;
316 rctx->rw = rscreen->rw;
317
318 r600_init_blit_functions(rctx);
319 r600_init_query_functions(rctx);
320 r600_init_state_functions(rctx);
321 r600_init_context_resource_functions(rctx);
322
323 rctx->blitter = util_blitter_create(&rctx->context);
324 if (rctx->blitter == NULL) {
325 FREE(rctx);
326 return NULL;
327 }
328
329 r600_init_config(rctx);
330
331 radeon_ctx_init(&rctx->ctx, rscreen->rw);
332 radeon_draw_init(&rctx->draw, rscreen->rw);
333 return &rctx->context;
334 }