radeonsi: split si_copy_buffer
[mesa.git] / src / gallium / drivers / radeonsi / si_pipe.c
1 /*
2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3 * Copyright 2018 Advanced Micro Devices, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * on the rights to use, copy, modify, merge, publish, distribute, sub
10 * license, and/or sell copies of the Software, and to permit persons to whom
11 * the Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 #include "si_pipe.h"
27 #include "si_public.h"
28 #include "si_shader_internal.h"
29 #include "sid.h"
30
31 #include "ac_llvm_util.h"
32 #include "radeon/radeon_uvd.h"
33 #include "gallivm/lp_bld_misc.h"
34 #include "util/disk_cache.h"
35 #include "util/u_log.h"
36 #include "util/u_memory.h"
37 #include "util/u_suballoc.h"
38 #include "util/u_tests.h"
39 #include "util/u_upload_mgr.h"
40 #include "util/xmlconfig.h"
41 #include "vl/vl_decoder.h"
42 #include "driver_ddebug/dd_util.h"
43
44 static const struct debug_named_value debug_options[] = {
45 /* Shader logging options: */
46 { "vs", DBG(VS), "Print vertex shaders" },
47 { "ps", DBG(PS), "Print pixel shaders" },
48 { "gs", DBG(GS), "Print geometry shaders" },
49 { "tcs", DBG(TCS), "Print tessellation control shaders" },
50 { "tes", DBG(TES), "Print tessellation evaluation shaders" },
51 { "cs", DBG(CS), "Print compute shaders" },
52 { "noir", DBG(NO_IR), "Don't print the LLVM IR"},
53 { "notgsi", DBG(NO_TGSI), "Don't print the TGSI"},
54 { "noasm", DBG(NO_ASM), "Don't print disassembled shaders"},
55 { "preoptir", DBG(PREOPT_IR), "Print the LLVM IR before initial optimizations" },
56
57 /* Shader compiler options the shader cache should be aware of: */
58 { "unsafemath", DBG(UNSAFE_MATH), "Enable unsafe math shader optimizations" },
59 { "sisched", DBG(SI_SCHED), "Enable LLVM SI Machine Instruction Scheduler." },
60 { "gisel", DBG(GISEL), "Enable LLVM global instruction selector." },
61
62 /* Shader compiler options (with no effect on the shader cache): */
63 { "checkir", DBG(CHECK_IR), "Enable additional sanity checks on shader IR" },
64 { "nir", DBG(NIR), "Enable experimental NIR shaders" },
65 { "mono", DBG(MONOLITHIC_SHADERS), "Use old-style monolithic shaders compiled on demand" },
66 { "nooptvariant", DBG(NO_OPT_VARIANT), "Disable compiling optimized shader variants." },
67
68 /* Information logging options: */
69 { "info", DBG(INFO), "Print driver information" },
70 { "tex", DBG(TEX), "Print texture info" },
71 { "compute", DBG(COMPUTE), "Print compute info" },
72 { "vm", DBG(VM), "Print virtual addresses when creating resources" },
73
74 /* Driver options: */
75 { "forcedma", DBG(FORCE_DMA), "Use asynchronous DMA for all operations when possible." },
76 { "nodma", DBG(NO_ASYNC_DMA), "Disable asynchronous DMA" },
77 { "nowc", DBG(NO_WC), "Disable GTT write combining" },
78 { "check_vm", DBG(CHECK_VM), "Check VM faults and dump debug info." },
79 { "reserve_vmid", DBG(RESERVE_VMID), "Force VMID reservation per context." },
80 { "zerovram", DBG(ZERO_VRAM), "Clear VRAM allocations." },
81
82 /* 3D engine options: */
83 { "switch_on_eop", DBG(SWITCH_ON_EOP), "Program WD/IA to switch on end-of-packet." },
84 { "nooutoforder", DBG(NO_OUT_OF_ORDER), "Disable out-of-order rasterization" },
85 { "nodpbb", DBG(NO_DPBB), "Disable DPBB." },
86 { "nodfsm", DBG(NO_DFSM), "Disable DFSM." },
87 { "dpbb", DBG(DPBB), "Enable DPBB." },
88 { "dfsm", DBG(DFSM), "Enable DFSM." },
89 { "nohyperz", DBG(NO_HYPERZ), "Disable Hyper-Z" },
90 { "norbplus", DBG(NO_RB_PLUS), "Disable RB+." },
91 { "no2d", DBG(NO_2D_TILING), "Disable 2D tiling" },
92 { "notiling", DBG(NO_TILING), "Disable tiling" },
93 { "nodcc", DBG(NO_DCC), "Disable DCC." },
94 { "nodccclear", DBG(NO_DCC_CLEAR), "Disable DCC fast clear." },
95 { "nodccfb", DBG(NO_DCC_FB), "Disable separate DCC on the main framebuffer" },
96 { "nodccmsaa", DBG(NO_DCC_MSAA), "Disable DCC for MSAA" },
97 { "nofmask", DBG(NO_FMASK), "Disable MSAA compression" },
98
99 /* Tests: */
100 { "testdma", DBG(TEST_DMA), "Invoke SDMA tests and exit." },
101 { "testvmfaultcp", DBG(TEST_VMFAULT_CP), "Invoke a CP VM fault test and exit." },
102 { "testvmfaultsdma", DBG(TEST_VMFAULT_SDMA), "Invoke a SDMA VM fault test and exit." },
103 { "testvmfaultshader", DBG(TEST_VMFAULT_SHADER), "Invoke a shader VM fault test and exit." },
104 { "testdmaperf", DBG(TEST_DMA_PERF), "Test DMA performance" },
105
106 DEBUG_NAMED_VALUE_END /* must be last */
107 };
108
109 static void si_init_compiler(struct si_screen *sscreen,
110 struct ac_llvm_compiler *compiler)
111 {
112 /* Only create the less-optimizing version of the compiler on APUs
113 * predating Ryzen (Raven). */
114 bool create_low_opt_compiler = !sscreen->info.has_dedicated_vram &&
115 sscreen->info.chip_class <= VI;
116
117 enum ac_target_machine_options tm_options =
118 (sscreen->debug_flags & DBG(SI_SCHED) ? AC_TM_SISCHED : 0) |
119 (sscreen->debug_flags & DBG(GISEL) ? AC_TM_ENABLE_GLOBAL_ISEL : 0) |
120 (sscreen->info.chip_class >= GFX9 ? AC_TM_FORCE_ENABLE_XNACK : 0) |
121 (sscreen->info.chip_class < GFX9 ? AC_TM_FORCE_DISABLE_XNACK : 0) |
122 (!sscreen->llvm_has_working_vgpr_indexing ? AC_TM_PROMOTE_ALLOCA_TO_SCRATCH : 0) |
123 (sscreen->debug_flags & DBG(CHECK_IR) ? AC_TM_CHECK_IR : 0) |
124 (create_low_opt_compiler ? AC_TM_CREATE_LOW_OPT : 0);
125
126 ac_init_llvm_once();
127 ac_init_llvm_compiler(compiler, true, sscreen->info.family, tm_options);
128 compiler->passes = ac_create_llvm_passes(compiler->tm);
129
130 if (compiler->low_opt_tm)
131 compiler->low_opt_passes = ac_create_llvm_passes(compiler->low_opt_tm);
132 }
133
134 static void si_destroy_compiler(struct ac_llvm_compiler *compiler)
135 {
136 ac_destroy_llvm_passes(compiler->passes);
137 ac_destroy_llvm_passes(compiler->low_opt_passes);
138 ac_destroy_llvm_compiler(compiler);
139 }
140
141 /*
142 * pipe_context
143 */
144 static void si_destroy_context(struct pipe_context *context)
145 {
146 struct si_context *sctx = (struct si_context *)context;
147 int i;
148
149 /* Unreference the framebuffer normally to disable related logic
150 * properly.
151 */
152 struct pipe_framebuffer_state fb = {};
153 if (context->set_framebuffer_state)
154 context->set_framebuffer_state(context, &fb);
155
156 si_release_all_descriptors(sctx);
157
158 pipe_resource_reference(&sctx->esgs_ring, NULL);
159 pipe_resource_reference(&sctx->gsvs_ring, NULL);
160 pipe_resource_reference(&sctx->tess_rings, NULL);
161 pipe_resource_reference(&sctx->null_const_buf.buffer, NULL);
162 r600_resource_reference(&sctx->border_color_buffer, NULL);
163 free(sctx->border_color_table);
164 r600_resource_reference(&sctx->scratch_buffer, NULL);
165 r600_resource_reference(&sctx->compute_scratch_buffer, NULL);
166 r600_resource_reference(&sctx->wait_mem_scratch, NULL);
167
168 si_pm4_free_state(sctx, sctx->init_config, ~0);
169 if (sctx->init_config_gs_rings)
170 si_pm4_free_state(sctx, sctx->init_config_gs_rings, ~0);
171 for (i = 0; i < ARRAY_SIZE(sctx->vgt_shader_config); i++)
172 si_pm4_delete_state(sctx, vgt_shader_config, sctx->vgt_shader_config[i]);
173
174 if (sctx->fixed_func_tcs_shader.cso)
175 sctx->b.delete_tcs_state(&sctx->b, sctx->fixed_func_tcs_shader.cso);
176 if (sctx->custom_dsa_flush)
177 sctx->b.delete_depth_stencil_alpha_state(&sctx->b, sctx->custom_dsa_flush);
178 if (sctx->custom_blend_resolve)
179 sctx->b.delete_blend_state(&sctx->b, sctx->custom_blend_resolve);
180 if (sctx->custom_blend_fmask_decompress)
181 sctx->b.delete_blend_state(&sctx->b, sctx->custom_blend_fmask_decompress);
182 if (sctx->custom_blend_eliminate_fastclear)
183 sctx->b.delete_blend_state(&sctx->b, sctx->custom_blend_eliminate_fastclear);
184 if (sctx->custom_blend_dcc_decompress)
185 sctx->b.delete_blend_state(&sctx->b, sctx->custom_blend_dcc_decompress);
186 if (sctx->vs_blit_pos)
187 sctx->b.delete_vs_state(&sctx->b, sctx->vs_blit_pos);
188 if (sctx->vs_blit_pos_layered)
189 sctx->b.delete_vs_state(&sctx->b, sctx->vs_blit_pos_layered);
190 if (sctx->vs_blit_color)
191 sctx->b.delete_vs_state(&sctx->b, sctx->vs_blit_color);
192 if (sctx->vs_blit_color_layered)
193 sctx->b.delete_vs_state(&sctx->b, sctx->vs_blit_color_layered);
194 if (sctx->vs_blit_texcoord)
195 sctx->b.delete_vs_state(&sctx->b, sctx->vs_blit_texcoord);
196
197 if (sctx->blitter)
198 util_blitter_destroy(sctx->blitter);
199
200 /* Release DCC stats. */
201 for (int i = 0; i < ARRAY_SIZE(sctx->dcc_stats); i++) {
202 assert(!sctx->dcc_stats[i].query_active);
203
204 for (int j = 0; j < ARRAY_SIZE(sctx->dcc_stats[i].ps_stats); j++)
205 if (sctx->dcc_stats[i].ps_stats[j])
206 sctx->b.destroy_query(&sctx->b,
207 sctx->dcc_stats[i].ps_stats[j]);
208
209 si_texture_reference(&sctx->dcc_stats[i].tex, NULL);
210 }
211
212 if (sctx->query_result_shader)
213 sctx->b.delete_compute_state(&sctx->b, sctx->query_result_shader);
214
215 if (sctx->gfx_cs)
216 sctx->ws->cs_destroy(sctx->gfx_cs);
217 if (sctx->dma_cs)
218 sctx->ws->cs_destroy(sctx->dma_cs);
219 if (sctx->ctx)
220 sctx->ws->ctx_destroy(sctx->ctx);
221
222 if (sctx->b.stream_uploader)
223 u_upload_destroy(sctx->b.stream_uploader);
224 if (sctx->b.const_uploader)
225 u_upload_destroy(sctx->b.const_uploader);
226 if (sctx->cached_gtt_allocator)
227 u_upload_destroy(sctx->cached_gtt_allocator);
228
229 slab_destroy_child(&sctx->pool_transfers);
230 slab_destroy_child(&sctx->pool_transfers_unsync);
231
232 if (sctx->allocator_zeroed_memory)
233 u_suballocator_destroy(sctx->allocator_zeroed_memory);
234
235 sctx->ws->fence_reference(&sctx->last_gfx_fence, NULL);
236 sctx->ws->fence_reference(&sctx->last_sdma_fence, NULL);
237 r600_resource_reference(&sctx->eop_bug_scratch, NULL);
238
239 si_destroy_compiler(&sctx->compiler);
240
241 si_saved_cs_reference(&sctx->current_saved_cs, NULL);
242
243 _mesa_hash_table_destroy(sctx->tex_handles, NULL);
244 _mesa_hash_table_destroy(sctx->img_handles, NULL);
245
246 util_dynarray_fini(&sctx->resident_tex_handles);
247 util_dynarray_fini(&sctx->resident_img_handles);
248 util_dynarray_fini(&sctx->resident_tex_needs_color_decompress);
249 util_dynarray_fini(&sctx->resident_img_needs_color_decompress);
250 util_dynarray_fini(&sctx->resident_tex_needs_depth_decompress);
251 FREE(sctx);
252 }
253
254 static enum pipe_reset_status si_get_reset_status(struct pipe_context *ctx)
255 {
256 struct si_context *sctx = (struct si_context *)ctx;
257
258 if (sctx->screen->info.has_gpu_reset_status_query)
259 return sctx->ws->ctx_query_reset_status(sctx->ctx);
260
261 if (sctx->screen->info.has_gpu_reset_counter_query) {
262 unsigned latest = sctx->ws->query_value(sctx->ws,
263 RADEON_GPU_RESET_COUNTER);
264
265 if (sctx->gpu_reset_counter == latest)
266 return PIPE_NO_RESET;
267
268 sctx->gpu_reset_counter = latest;
269 return PIPE_UNKNOWN_CONTEXT_RESET;
270 }
271
272 return PIPE_NO_RESET;
273 }
274
275 static void si_set_device_reset_callback(struct pipe_context *ctx,
276 const struct pipe_device_reset_callback *cb)
277 {
278 struct si_context *sctx = (struct si_context *)ctx;
279
280 if (cb)
281 sctx->device_reset_callback = *cb;
282 else
283 memset(&sctx->device_reset_callback, 0,
284 sizeof(sctx->device_reset_callback));
285 }
286
287 bool si_check_device_reset(struct si_context *sctx)
288 {
289 enum pipe_reset_status status;
290
291 if (!sctx->device_reset_callback.reset)
292 return false;
293
294 if (!sctx->b.get_device_reset_status)
295 return false;
296
297 status = sctx->b.get_device_reset_status(&sctx->b);
298 if (status == PIPE_NO_RESET)
299 return false;
300
301 sctx->device_reset_callback.reset(sctx->device_reset_callback.data, status);
302 return true;
303 }
304
305 /* Apitrace profiling:
306 * 1) qapitrace : Tools -> Profile: Measure CPU & GPU times
307 * 2) In the middle panel, zoom in (mouse wheel) on some bad draw call
308 * and remember its number.
309 * 3) In Mesa, enable queries and performance counters around that draw
310 * call and print the results.
311 * 4) glretrace --benchmark --markers ..
312 */
313 static void si_emit_string_marker(struct pipe_context *ctx,
314 const char *string, int len)
315 {
316 struct si_context *sctx = (struct si_context *)ctx;
317
318 dd_parse_apitrace_marker(string, len, &sctx->apitrace_call_number);
319
320 if (sctx->log)
321 u_log_printf(sctx->log, "\nString marker: %*s\n", len, string);
322 }
323
324 static void si_set_debug_callback(struct pipe_context *ctx,
325 const struct pipe_debug_callback *cb)
326 {
327 struct si_context *sctx = (struct si_context *)ctx;
328 struct si_screen *screen = sctx->screen;
329
330 util_queue_finish(&screen->shader_compiler_queue);
331 util_queue_finish(&screen->shader_compiler_queue_low_priority);
332
333 if (cb)
334 sctx->debug = *cb;
335 else
336 memset(&sctx->debug, 0, sizeof(sctx->debug));
337 }
338
339 static void si_set_log_context(struct pipe_context *ctx,
340 struct u_log_context *log)
341 {
342 struct si_context *sctx = (struct si_context *)ctx;
343 sctx->log = log;
344
345 if (log)
346 u_log_add_auto_logger(log, si_auto_log_cs, sctx);
347 }
348
349 static void si_set_context_param(struct pipe_context *ctx,
350 enum pipe_context_param param,
351 unsigned value)
352 {
353 struct radeon_winsys *ws = ((struct si_context *)ctx)->ws;
354
355 switch (param) {
356 case PIPE_CONTEXT_PARAM_PIN_THREADS_TO_L3_CACHE:
357 ws->pin_threads_to_L3_cache(ws, value);
358 break;
359 default:;
360 }
361 }
362
363 static struct pipe_context *si_create_context(struct pipe_screen *screen,
364 unsigned flags)
365 {
366 struct si_context *sctx = CALLOC_STRUCT(si_context);
367 struct si_screen* sscreen = (struct si_screen *)screen;
368 struct radeon_winsys *ws = sscreen->ws;
369 int shader, i;
370
371 if (!sctx)
372 return NULL;
373
374 if (flags & PIPE_CONTEXT_DEBUG)
375 sscreen->record_llvm_ir = true; /* racy but not critical */
376
377 sctx->b.screen = screen; /* this must be set first */
378 sctx->b.priv = NULL;
379 sctx->b.destroy = si_destroy_context;
380 sctx->b.emit_string_marker = si_emit_string_marker;
381 sctx->b.set_debug_callback = si_set_debug_callback;
382 sctx->b.set_log_context = si_set_log_context;
383 sctx->b.set_context_param = si_set_context_param;
384 sctx->screen = sscreen; /* Easy accessing of screen/winsys. */
385 sctx->is_debug = (flags & PIPE_CONTEXT_DEBUG) != 0;
386
387 slab_create_child(&sctx->pool_transfers, &sscreen->pool_transfers);
388 slab_create_child(&sctx->pool_transfers_unsync, &sscreen->pool_transfers);
389
390 sctx->ws = sscreen->ws;
391 sctx->family = sscreen->info.family;
392 sctx->chip_class = sscreen->info.chip_class;
393
394 if (sscreen->info.has_gpu_reset_counter_query) {
395 sctx->gpu_reset_counter =
396 sctx->ws->query_value(sctx->ws, RADEON_GPU_RESET_COUNTER);
397 }
398
399 sctx->b.get_device_reset_status = si_get_reset_status;
400 sctx->b.set_device_reset_callback = si_set_device_reset_callback;
401
402 si_init_context_texture_functions(sctx);
403 si_init_query_functions(sctx);
404
405 if (sctx->chip_class == CIK ||
406 sctx->chip_class == VI ||
407 sctx->chip_class == GFX9) {
408 sctx->eop_bug_scratch = r600_resource(
409 pipe_buffer_create(&sscreen->b, 0, PIPE_USAGE_DEFAULT,
410 16 * sscreen->info.num_render_backends));
411 if (!sctx->eop_bug_scratch)
412 goto fail;
413 }
414
415 sctx->allocator_zeroed_memory =
416 u_suballocator_create(&sctx->b, sscreen->info.gart_page_size,
417 0, PIPE_USAGE_DEFAULT, 0, true);
418 if (!sctx->allocator_zeroed_memory)
419 goto fail;
420
421 sctx->b.stream_uploader = u_upload_create(&sctx->b, 1024 * 1024,
422 0, PIPE_USAGE_STREAM,
423 SI_RESOURCE_FLAG_READ_ONLY);
424 if (!sctx->b.stream_uploader)
425 goto fail;
426
427 sctx->b.const_uploader = u_upload_create(&sctx->b, 128 * 1024,
428 0, PIPE_USAGE_DEFAULT,
429 SI_RESOURCE_FLAG_32BIT |
430 (sscreen->cpdma_prefetch_writes_memory ?
431 0 : SI_RESOURCE_FLAG_READ_ONLY));
432 if (!sctx->b.const_uploader)
433 goto fail;
434
435 sctx->cached_gtt_allocator = u_upload_create(&sctx->b, 16 * 1024,
436 0, PIPE_USAGE_STAGING, 0);
437 if (!sctx->cached_gtt_allocator)
438 goto fail;
439
440 sctx->ctx = sctx->ws->ctx_create(sctx->ws);
441 if (!sctx->ctx)
442 goto fail;
443
444 if (sscreen->info.num_sdma_rings && !(sscreen->debug_flags & DBG(NO_ASYNC_DMA))) {
445 sctx->dma_cs = sctx->ws->cs_create(sctx->ctx, RING_DMA,
446 (void*)si_flush_dma_cs,
447 sctx);
448 }
449
450 si_init_buffer_functions(sctx);
451 si_init_clear_functions(sctx);
452 si_init_blit_functions(sctx);
453 si_init_compute_functions(sctx);
454 si_init_cp_dma_functions(sctx);
455 si_init_debug_functions(sctx);
456 si_init_msaa_functions(sctx);
457 si_init_streamout_functions(sctx);
458
459 if (sscreen->info.has_hw_decode) {
460 sctx->b.create_video_codec = si_uvd_create_decoder;
461 sctx->b.create_video_buffer = si_video_buffer_create;
462 } else {
463 sctx->b.create_video_codec = vl_create_decoder;
464 sctx->b.create_video_buffer = vl_video_buffer_create;
465 }
466
467 sctx->gfx_cs = ws->cs_create(sctx->ctx, RING_GFX,
468 (void*)si_flush_gfx_cs, sctx);
469
470 /* Border colors. */
471 sctx->border_color_table = malloc(SI_MAX_BORDER_COLORS *
472 sizeof(*sctx->border_color_table));
473 if (!sctx->border_color_table)
474 goto fail;
475
476 sctx->border_color_buffer = r600_resource(
477 pipe_buffer_create(screen, 0, PIPE_USAGE_DEFAULT,
478 SI_MAX_BORDER_COLORS *
479 sizeof(*sctx->border_color_table)));
480 if (!sctx->border_color_buffer)
481 goto fail;
482
483 sctx->border_color_map =
484 ws->buffer_map(sctx->border_color_buffer->buf,
485 NULL, PIPE_TRANSFER_WRITE);
486 if (!sctx->border_color_map)
487 goto fail;
488
489 si_init_all_descriptors(sctx);
490 si_init_fence_functions(sctx);
491 si_init_state_functions(sctx);
492 si_init_shader_functions(sctx);
493 si_init_viewport_functions(sctx);
494 si_init_ia_multi_vgt_param_table(sctx);
495
496 if (sctx->chip_class >= CIK)
497 cik_init_sdma_functions(sctx);
498 else
499 si_init_dma_functions(sctx);
500
501 if (sscreen->debug_flags & DBG(FORCE_DMA))
502 sctx->b.resource_copy_region = sctx->dma_copy;
503
504 sctx->blitter = util_blitter_create(&sctx->b);
505 if (sctx->blitter == NULL)
506 goto fail;
507 sctx->blitter->draw_rectangle = si_draw_rectangle;
508 sctx->blitter->skip_viewport_restore = true;
509
510 sctx->sample_mask = 0xffff;
511
512 if (sctx->chip_class >= GFX9) {
513 sctx->wait_mem_scratch = r600_resource(
514 pipe_buffer_create(screen, 0, PIPE_USAGE_DEFAULT, 4));
515 if (!sctx->wait_mem_scratch)
516 goto fail;
517
518 /* Initialize the memory. */
519 struct radeon_cmdbuf *cs = sctx->gfx_cs;
520 radeon_emit(cs, PKT3(PKT3_WRITE_DATA, 3, 0));
521 radeon_emit(cs, S_370_DST_SEL(V_370_MEMORY_SYNC) |
522 S_370_WR_CONFIRM(1) |
523 S_370_ENGINE_SEL(V_370_ME));
524 radeon_emit(cs, sctx->wait_mem_scratch->gpu_address);
525 radeon_emit(cs, sctx->wait_mem_scratch->gpu_address >> 32);
526 radeon_emit(cs, sctx->wait_mem_number);
527 radeon_add_to_buffer_list(sctx, cs, sctx->wait_mem_scratch,
528 RADEON_USAGE_WRITE, RADEON_PRIO_FENCE);
529 }
530
531 /* CIK cannot unbind a constant buffer (S_BUFFER_LOAD doesn't skip loads
532 * if NUM_RECORDS == 0). We need to use a dummy buffer instead. */
533 if (sctx->chip_class == CIK) {
534 sctx->null_const_buf.buffer =
535 pipe_aligned_buffer_create(screen,
536 SI_RESOURCE_FLAG_32BIT,
537 PIPE_USAGE_DEFAULT, 16,
538 sctx->screen->info.tcc_cache_line_size);
539 if (!sctx->null_const_buf.buffer)
540 goto fail;
541 sctx->null_const_buf.buffer_size = sctx->null_const_buf.buffer->width0;
542
543 for (shader = 0; shader < SI_NUM_SHADERS; shader++) {
544 for (i = 0; i < SI_NUM_CONST_BUFFERS; i++) {
545 sctx->b.set_constant_buffer(&sctx->b, shader, i,
546 &sctx->null_const_buf);
547 }
548 }
549
550 si_set_rw_buffer(sctx, SI_HS_CONST_DEFAULT_TESS_LEVELS,
551 &sctx->null_const_buf);
552 si_set_rw_buffer(sctx, SI_VS_CONST_INSTANCE_DIVISORS,
553 &sctx->null_const_buf);
554 si_set_rw_buffer(sctx, SI_VS_CONST_CLIP_PLANES,
555 &sctx->null_const_buf);
556 si_set_rw_buffer(sctx, SI_PS_CONST_POLY_STIPPLE,
557 &sctx->null_const_buf);
558 si_set_rw_buffer(sctx, SI_PS_CONST_SAMPLE_POSITIONS,
559 &sctx->null_const_buf);
560
561 /* Clear the NULL constant buffer, because loads should return zeros. */
562 si_clear_buffer(sctx, sctx->null_const_buf.buffer, 0,
563 sctx->null_const_buf.buffer->width0, 0,
564 SI_COHERENCY_SHADER);
565 }
566
567 uint64_t max_threads_per_block;
568 screen->get_compute_param(screen, PIPE_SHADER_IR_TGSI,
569 PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK,
570 &max_threads_per_block);
571
572 /* The maximum number of scratch waves. Scratch space isn't divided
573 * evenly between CUs. The number is only a function of the number of CUs.
574 * We can decrease the constant to decrease the scratch buffer size.
575 *
576 * sctx->scratch_waves must be >= the maximum posible size of
577 * 1 threadgroup, so that the hw doesn't hang from being unable
578 * to start any.
579 *
580 * The recommended value is 4 per CU at most. Higher numbers don't
581 * bring much benefit, but they still occupy chip resources (think
582 * async compute). I've seen ~2% performance difference between 4 and 32.
583 */
584 sctx->scratch_waves = MAX2(32 * sscreen->info.num_good_compute_units,
585 max_threads_per_block / 64);
586
587 si_init_compiler(sscreen, &sctx->compiler);
588
589 /* Bindless handles. */
590 sctx->tex_handles = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
591 _mesa_key_pointer_equal);
592 sctx->img_handles = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
593 _mesa_key_pointer_equal);
594
595 util_dynarray_init(&sctx->resident_tex_handles, NULL);
596 util_dynarray_init(&sctx->resident_img_handles, NULL);
597 util_dynarray_init(&sctx->resident_tex_needs_color_decompress, NULL);
598 util_dynarray_init(&sctx->resident_img_needs_color_decompress, NULL);
599 util_dynarray_init(&sctx->resident_tex_needs_depth_decompress, NULL);
600
601 /* this must be last */
602 si_begin_new_gfx_cs(sctx);
603 return &sctx->b;
604 fail:
605 fprintf(stderr, "radeonsi: Failed to create a context.\n");
606 si_destroy_context(&sctx->b);
607 return NULL;
608 }
609
610 static struct pipe_context *si_pipe_create_context(struct pipe_screen *screen,
611 void *priv, unsigned flags)
612 {
613 struct si_screen *sscreen = (struct si_screen *)screen;
614 struct pipe_context *ctx;
615
616 if (sscreen->debug_flags & DBG(CHECK_VM))
617 flags |= PIPE_CONTEXT_DEBUG;
618
619 ctx = si_create_context(screen, flags);
620
621 if (!(flags & PIPE_CONTEXT_PREFER_THREADED))
622 return ctx;
623
624 /* Clover (compute-only) is unsupported. */
625 if (flags & PIPE_CONTEXT_COMPUTE_ONLY)
626 return ctx;
627
628 /* When shaders are logged to stderr, asynchronous compilation is
629 * disabled too. */
630 if (sscreen->debug_flags & DBG_ALL_SHADERS)
631 return ctx;
632
633 /* Use asynchronous flushes only on amdgpu, since the radeon
634 * implementation for fence_server_sync is incomplete. */
635 return threaded_context_create(ctx, &sscreen->pool_transfers,
636 si_replace_buffer_storage,
637 sscreen->info.drm_major >= 3 ? si_create_fence : NULL,
638 &((struct si_context*)ctx)->tc);
639 }
640
641 /*
642 * pipe_screen
643 */
644 static void si_destroy_screen(struct pipe_screen* pscreen)
645 {
646 struct si_screen *sscreen = (struct si_screen *)pscreen;
647 struct si_shader_part *parts[] = {
648 sscreen->vs_prologs,
649 sscreen->tcs_epilogs,
650 sscreen->gs_prologs,
651 sscreen->ps_prologs,
652 sscreen->ps_epilogs
653 };
654 unsigned i;
655
656 if (!sscreen->ws->unref(sscreen->ws))
657 return;
658
659 util_queue_destroy(&sscreen->shader_compiler_queue);
660 util_queue_destroy(&sscreen->shader_compiler_queue_low_priority);
661
662 for (i = 0; i < ARRAY_SIZE(sscreen->compiler); i++)
663 si_destroy_compiler(&sscreen->compiler[i]);
664
665 for (i = 0; i < ARRAY_SIZE(sscreen->compiler_lowp); i++)
666 si_destroy_compiler(&sscreen->compiler_lowp[i]);
667
668 /* Free shader parts. */
669 for (i = 0; i < ARRAY_SIZE(parts); i++) {
670 while (parts[i]) {
671 struct si_shader_part *part = parts[i];
672
673 parts[i] = part->next;
674 ac_shader_binary_clean(&part->binary);
675 FREE(part);
676 }
677 }
678 mtx_destroy(&sscreen->shader_parts_mutex);
679 si_destroy_shader_cache(sscreen);
680
681 si_perfcounters_destroy(sscreen);
682 si_gpu_load_kill_thread(sscreen);
683
684 mtx_destroy(&sscreen->gpu_load_mutex);
685 mtx_destroy(&sscreen->aux_context_lock);
686 sscreen->aux_context->destroy(sscreen->aux_context);
687
688 slab_destroy_parent(&sscreen->pool_transfers);
689
690 disk_cache_destroy(sscreen->disk_shader_cache);
691 sscreen->ws->destroy(sscreen->ws);
692 FREE(sscreen);
693 }
694
695 static void si_init_gs_info(struct si_screen *sscreen)
696 {
697 sscreen->gs_table_depth = ac_get_gs_table_depth(sscreen->info.chip_class,
698 sscreen->info.family);
699 }
700
701 static void si_handle_env_var_force_family(struct si_screen *sscreen)
702 {
703 const char *family = debug_get_option("SI_FORCE_FAMILY", NULL);
704 unsigned i;
705
706 if (!family)
707 return;
708
709 for (i = CHIP_TAHITI; i < CHIP_LAST; i++) {
710 if (!strcmp(family, ac_get_llvm_processor_name(i))) {
711 /* Override family and chip_class. */
712 sscreen->info.family = i;
713
714 if (i >= CHIP_VEGA10)
715 sscreen->info.chip_class = GFX9;
716 else if (i >= CHIP_TONGA)
717 sscreen->info.chip_class = VI;
718 else if (i >= CHIP_BONAIRE)
719 sscreen->info.chip_class = CIK;
720 else
721 sscreen->info.chip_class = SI;
722
723 /* Don't submit any IBs. */
724 setenv("RADEON_NOOP", "1", 1);
725 return;
726 }
727 }
728
729 fprintf(stderr, "radeonsi: Unknown family: %s\n", family);
730 exit(1);
731 }
732
733 static void si_test_vmfault(struct si_screen *sscreen)
734 {
735 struct pipe_context *ctx = sscreen->aux_context;
736 struct si_context *sctx = (struct si_context *)ctx;
737 struct pipe_resource *buf =
738 pipe_buffer_create_const0(&sscreen->b, 0, PIPE_USAGE_DEFAULT, 64);
739
740 if (!buf) {
741 puts("Buffer allocation failed.");
742 exit(1);
743 }
744
745 r600_resource(buf)->gpu_address = 0; /* cause a VM fault */
746
747 if (sscreen->debug_flags & DBG(TEST_VMFAULT_CP)) {
748 si_cp_dma_copy_buffer(sctx, buf, buf, 0, 4, 4, 0,
749 SI_COHERENCY_NONE, L2_BYPASS);
750 ctx->flush(ctx, NULL, 0);
751 puts("VM fault test: CP - done.");
752 }
753 if (sscreen->debug_flags & DBG(TEST_VMFAULT_SDMA)) {
754 si_sdma_clear_buffer(sctx, buf, 0, 4, 0);
755 ctx->flush(ctx, NULL, 0);
756 puts("VM fault test: SDMA - done.");
757 }
758 if (sscreen->debug_flags & DBG(TEST_VMFAULT_SHADER)) {
759 util_test_constant_buffer(ctx, buf);
760 puts("VM fault test: Shader - done.");
761 }
762 exit(0);
763 }
764
765 static void si_disk_cache_create(struct si_screen *sscreen)
766 {
767 /* Don't use the cache if shader dumping is enabled. */
768 if (sscreen->debug_flags & DBG_ALL_SHADERS)
769 return;
770
771 uint32_t mesa_timestamp;
772 if (disk_cache_get_function_timestamp(si_disk_cache_create,
773 &mesa_timestamp)) {
774 char *timestamp_str;
775 int res = -1;
776 uint32_t llvm_timestamp;
777
778 if (disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo,
779 &llvm_timestamp)) {
780 res = asprintf(&timestamp_str, "%u_%u",
781 mesa_timestamp, llvm_timestamp);
782 }
783
784 if (res != -1) {
785 /* These flags affect shader compilation. */
786 #define ALL_FLAGS (DBG(FS_CORRECT_DERIVS_AFTER_KILL) | \
787 DBG(SI_SCHED) | \
788 DBG(GISEL) | \
789 DBG(UNSAFE_MATH) | \
790 DBG(NIR))
791 uint64_t shader_debug_flags = sscreen->debug_flags &
792 ALL_FLAGS;
793
794 /* Add the high bits of 32-bit addresses, which affects
795 * how 32-bit addresses are expanded to 64 bits.
796 */
797 STATIC_ASSERT(ALL_FLAGS <= UINT_MAX);
798 shader_debug_flags |= (uint64_t)sscreen->info.address32_hi << 32;
799
800 sscreen->disk_shader_cache =
801 disk_cache_create(sscreen->info.name,
802 timestamp_str,
803 shader_debug_flags);
804 free(timestamp_str);
805 }
806 }
807 }
808
809 struct pipe_screen *radeonsi_screen_create(struct radeon_winsys *ws,
810 const struct pipe_screen_config *config)
811 {
812 struct si_screen *sscreen = CALLOC_STRUCT(si_screen);
813 unsigned hw_threads, num_comp_hi_threads, num_comp_lo_threads, i;
814
815 if (!sscreen) {
816 return NULL;
817 }
818
819 sscreen->ws = ws;
820 ws->query_info(ws, &sscreen->info);
821 si_handle_env_var_force_family(sscreen);
822
823 sscreen->debug_flags = debug_get_flags_option("R600_DEBUG",
824 debug_options, 0);
825
826 /* Set functions first. */
827 sscreen->b.context_create = si_pipe_create_context;
828 sscreen->b.destroy = si_destroy_screen;
829
830 si_init_screen_get_functions(sscreen);
831 si_init_screen_buffer_functions(sscreen);
832 si_init_screen_fence_functions(sscreen);
833 si_init_screen_state_functions(sscreen);
834 si_init_screen_texture_functions(sscreen);
835 si_init_screen_query_functions(sscreen);
836
837 /* Set these flags in debug_flags early, so that the shader cache takes
838 * them into account.
839 */
840 if (driQueryOptionb(config->options,
841 "glsl_correct_derivatives_after_discard"))
842 sscreen->debug_flags |= DBG(FS_CORRECT_DERIVS_AFTER_KILL);
843 if (driQueryOptionb(config->options, "radeonsi_enable_sisched"))
844 sscreen->debug_flags |= DBG(SI_SCHED);
845
846
847 if (sscreen->debug_flags & DBG(INFO))
848 ac_print_gpu_info(&sscreen->info);
849
850 slab_create_parent(&sscreen->pool_transfers,
851 sizeof(struct si_transfer), 64);
852
853 sscreen->force_aniso = MIN2(16, debug_get_num_option("R600_TEX_ANISO", -1));
854 if (sscreen->force_aniso >= 0) {
855 printf("radeonsi: Forcing anisotropy filter to %ix\n",
856 /* round down to a power of two */
857 1 << util_logbase2(sscreen->force_aniso));
858 }
859
860 (void) mtx_init(&sscreen->aux_context_lock, mtx_plain);
861 (void) mtx_init(&sscreen->gpu_load_mutex, mtx_plain);
862
863 si_init_gs_info(sscreen);
864 if (!si_init_shader_cache(sscreen)) {
865 FREE(sscreen);
866 return NULL;
867 }
868
869 si_disk_cache_create(sscreen);
870
871 /* Determine the number of shader compiler threads. */
872 hw_threads = sysconf(_SC_NPROCESSORS_ONLN);
873
874 if (hw_threads >= 12) {
875 num_comp_hi_threads = hw_threads * 3 / 4;
876 num_comp_lo_threads = hw_threads / 3;
877 } else if (hw_threads >= 6) {
878 num_comp_hi_threads = hw_threads - 2;
879 num_comp_lo_threads = hw_threads / 2;
880 } else if (hw_threads >= 2) {
881 num_comp_hi_threads = hw_threads - 1;
882 num_comp_lo_threads = hw_threads / 2;
883 } else {
884 num_comp_hi_threads = 1;
885 num_comp_lo_threads = 1;
886 }
887
888 num_comp_hi_threads = MIN2(num_comp_hi_threads,
889 ARRAY_SIZE(sscreen->compiler));
890 num_comp_lo_threads = MIN2(num_comp_lo_threads,
891 ARRAY_SIZE(sscreen->compiler_lowp));
892
893 if (!util_queue_init(&sscreen->shader_compiler_queue, "sh",
894 64, num_comp_hi_threads,
895 UTIL_QUEUE_INIT_RESIZE_IF_FULL)) {
896 si_destroy_shader_cache(sscreen);
897 FREE(sscreen);
898 return NULL;
899 }
900
901 if (!util_queue_init(&sscreen->shader_compiler_queue_low_priority,
902 "shlo",
903 64, num_comp_lo_threads,
904 UTIL_QUEUE_INIT_RESIZE_IF_FULL |
905 UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY)) {
906 si_destroy_shader_cache(sscreen);
907 FREE(sscreen);
908 return NULL;
909 }
910
911 if (!debug_get_bool_option("RADEON_DISABLE_PERFCOUNTERS", false))
912 si_init_perfcounters(sscreen);
913
914 /* Determine tessellation ring info. */
915 bool double_offchip_buffers = sscreen->info.chip_class >= CIK &&
916 sscreen->info.family != CHIP_CARRIZO &&
917 sscreen->info.family != CHIP_STONEY;
918 /* This must be one less than the maximum number due to a hw limitation.
919 * Various hardware bugs in SI, CIK, and GFX9 need this.
920 */
921 unsigned max_offchip_buffers_per_se;
922
923 /* Only certain chips can use the maximum value. */
924 if (sscreen->info.family == CHIP_VEGA12 ||
925 sscreen->info.family == CHIP_VEGA20)
926 max_offchip_buffers_per_se = double_offchip_buffers ? 128 : 64;
927 else
928 max_offchip_buffers_per_se = double_offchip_buffers ? 127 : 63;
929
930 unsigned max_offchip_buffers = max_offchip_buffers_per_se *
931 sscreen->info.max_se;
932 unsigned offchip_granularity;
933
934 /* Hawaii has a bug with offchip buffers > 256 that can be worked
935 * around by setting 4K granularity.
936 */
937 if (sscreen->info.family == CHIP_HAWAII) {
938 sscreen->tess_offchip_block_dw_size = 4096;
939 offchip_granularity = V_03093C_X_4K_DWORDS;
940 } else {
941 sscreen->tess_offchip_block_dw_size = 8192;
942 offchip_granularity = V_03093C_X_8K_DWORDS;
943 }
944
945 sscreen->tess_factor_ring_size = 32768 * sscreen->info.max_se;
946 assert(((sscreen->tess_factor_ring_size / 4) & C_030938_SIZE) == 0);
947 sscreen->tess_offchip_ring_size = max_offchip_buffers *
948 sscreen->tess_offchip_block_dw_size * 4;
949
950 if (sscreen->info.chip_class >= CIK) {
951 if (sscreen->info.chip_class >= VI)
952 --max_offchip_buffers;
953 sscreen->vgt_hs_offchip_param =
954 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers) |
955 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity);
956 } else {
957 assert(offchip_granularity == V_03093C_X_8K_DWORDS);
958 sscreen->vgt_hs_offchip_param =
959 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers);
960 }
961
962 /* The mere presense of CLEAR_STATE in the IB causes random GPU hangs
963 * on SI. */
964 sscreen->has_clear_state = sscreen->info.chip_class >= CIK;
965
966 sscreen->has_distributed_tess =
967 sscreen->info.chip_class >= VI &&
968 sscreen->info.max_se >= 2;
969
970 sscreen->has_draw_indirect_multi =
971 (sscreen->info.family >= CHIP_POLARIS10) ||
972 (sscreen->info.chip_class == VI &&
973 sscreen->info.pfp_fw_version >= 121 &&
974 sscreen->info.me_fw_version >= 87) ||
975 (sscreen->info.chip_class == CIK &&
976 sscreen->info.pfp_fw_version >= 211 &&
977 sscreen->info.me_fw_version >= 173) ||
978 (sscreen->info.chip_class == SI &&
979 sscreen->info.pfp_fw_version >= 79 &&
980 sscreen->info.me_fw_version >= 142);
981
982 sscreen->has_out_of_order_rast = sscreen->info.chip_class >= VI &&
983 sscreen->info.max_se >= 2 &&
984 !(sscreen->debug_flags & DBG(NO_OUT_OF_ORDER));
985 sscreen->assume_no_z_fights =
986 driQueryOptionb(config->options, "radeonsi_assume_no_z_fights");
987 sscreen->commutative_blend_add =
988 driQueryOptionb(config->options, "radeonsi_commutative_blend_add");
989 sscreen->clear_db_cache_before_clear =
990 driQueryOptionb(config->options, "radeonsi_clear_db_cache_before_clear");
991 sscreen->has_msaa_sample_loc_bug = (sscreen->info.family >= CHIP_POLARIS10 &&
992 sscreen->info.family <= CHIP_POLARIS12) ||
993 sscreen->info.family == CHIP_VEGA10 ||
994 sscreen->info.family == CHIP_RAVEN;
995 sscreen->has_ls_vgpr_init_bug = sscreen->info.family == CHIP_VEGA10 ||
996 sscreen->info.family == CHIP_RAVEN;
997
998 if (sscreen->debug_flags & DBG(DPBB)) {
999 sscreen->dpbb_allowed = true;
1000 } else {
1001 /* Only enable primitive binning on Raven by default. */
1002 /* TODO: Investigate if binning is profitable on Vega12. */
1003 sscreen->dpbb_allowed = sscreen->info.family == CHIP_RAVEN &&
1004 !(sscreen->debug_flags & DBG(NO_DPBB));
1005 }
1006
1007 if (sscreen->debug_flags & DBG(DFSM)) {
1008 sscreen->dfsm_allowed = sscreen->dpbb_allowed;
1009 } else {
1010 sscreen->dfsm_allowed = sscreen->dpbb_allowed &&
1011 !(sscreen->debug_flags & DBG(NO_DFSM));
1012 }
1013
1014 /* While it would be nice not to have this flag, we are constrained
1015 * by the reality that LLVM 5.0 doesn't have working VGPR indexing
1016 * on GFX9.
1017 */
1018 sscreen->llvm_has_working_vgpr_indexing = sscreen->info.chip_class <= VI;
1019
1020 /* Some chips have RB+ registers, but don't support RB+. Those must
1021 * always disable it.
1022 */
1023 if (sscreen->info.family == CHIP_STONEY ||
1024 sscreen->info.chip_class >= GFX9) {
1025 sscreen->has_rbplus = true;
1026
1027 sscreen->rbplus_allowed =
1028 !(sscreen->debug_flags & DBG(NO_RB_PLUS)) &&
1029 (sscreen->info.family == CHIP_STONEY ||
1030 sscreen->info.family == CHIP_VEGA12 ||
1031 sscreen->info.family == CHIP_RAVEN);
1032 }
1033
1034 sscreen->dcc_msaa_allowed =
1035 !(sscreen->debug_flags & DBG(NO_DCC_MSAA));
1036
1037 sscreen->cpdma_prefetch_writes_memory = sscreen->info.chip_class <= VI;
1038
1039 (void) mtx_init(&sscreen->shader_parts_mutex, mtx_plain);
1040 sscreen->use_monolithic_shaders =
1041 (sscreen->debug_flags & DBG(MONOLITHIC_SHADERS)) != 0;
1042
1043 sscreen->barrier_flags.cp_to_L2 = SI_CONTEXT_INV_SMEM_L1 |
1044 SI_CONTEXT_INV_VMEM_L1;
1045 if (sscreen->info.chip_class <= VI) {
1046 sscreen->barrier_flags.cp_to_L2 |= SI_CONTEXT_INV_GLOBAL_L2;
1047 sscreen->barrier_flags.L2_to_cp |= SI_CONTEXT_WRITEBACK_GLOBAL_L2;
1048 }
1049
1050 if (debug_get_bool_option("RADEON_DUMP_SHADERS", false))
1051 sscreen->debug_flags |= DBG_ALL_SHADERS;
1052
1053 /* Syntax:
1054 * EQAA=s,z,c
1055 * Example:
1056 * EQAA=8,4,2
1057
1058 * That means 8 coverage samples, 4 Z/S samples, and 2 color samples.
1059 * Constraints:
1060 * s >= z >= c (ignoring this only wastes memory)
1061 * s = [2..16]
1062 * z = [2..8]
1063 * c = [2..8]
1064 *
1065 * Only MSAA color and depth buffers are overriden.
1066 */
1067 if (sscreen->info.has_eqaa_surface_allocator) {
1068 const char *eqaa = debug_get_option("EQAA", NULL);
1069 unsigned s,z,f;
1070
1071 if (eqaa && sscanf(eqaa, "%u,%u,%u", &s, &z, &f) == 3 && s && z && f) {
1072 sscreen->eqaa_force_coverage_samples = s;
1073 sscreen->eqaa_force_z_samples = z;
1074 sscreen->eqaa_force_color_samples = f;
1075 }
1076 }
1077
1078 for (i = 0; i < num_comp_hi_threads; i++)
1079 si_init_compiler(sscreen, &sscreen->compiler[i]);
1080 for (i = 0; i < num_comp_lo_threads; i++)
1081 si_init_compiler(sscreen, &sscreen->compiler_lowp[i]);
1082
1083 /* Create the auxiliary context. This must be done last. */
1084 sscreen->aux_context = si_create_context(&sscreen->b, 0);
1085
1086 if (sscreen->debug_flags & DBG(TEST_DMA))
1087 si_test_dma(sscreen);
1088
1089 if (sscreen->debug_flags & DBG(TEST_DMA_PERF)) {
1090 si_test_dma_perf(sscreen);
1091 }
1092
1093 if (sscreen->debug_flags & (DBG(TEST_VMFAULT_CP) |
1094 DBG(TEST_VMFAULT_SDMA) |
1095 DBG(TEST_VMFAULT_SHADER)))
1096 si_test_vmfault(sscreen);
1097
1098 return &sscreen->b;
1099 }