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