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