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