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