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