2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
3 * Copyright 2018 Advanced Micro Devices, Inc.
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:
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
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.
27 #include "si_public.h"
28 #include "si_shader_internal.h"
29 #include "si_compute.h"
32 #include "ac_llvm_util.h"
33 #include "radeon/radeon_uvd.h"
34 #include "gallivm/lp_bld_misc.h"
35 #include "util/disk_cache.h"
36 #include "util/u_log.h"
37 #include "util/u_memory.h"
38 #include "util/u_suballoc.h"
39 #include "util/u_tests.h"
40 #include "util/u_upload_mgr.h"
41 #include "util/xmlconfig.h"
42 #include "vl/vl_decoder.h"
43 #include "driver_ddebug/dd_util.h"
45 static const struct debug_named_value debug_options
[] = {
46 /* Shader logging options: */
47 { "vs", DBG(VS
), "Print vertex shaders" },
48 { "ps", DBG(PS
), "Print pixel shaders" },
49 { "gs", DBG(GS
), "Print geometry shaders" },
50 { "tcs", DBG(TCS
), "Print tessellation control shaders" },
51 { "tes", DBG(TES
), "Print tessellation evaluation shaders" },
52 { "cs", DBG(CS
), "Print compute shaders" },
53 { "noir", DBG(NO_IR
), "Don't print the LLVM IR"},
54 { "notgsi", DBG(NO_TGSI
), "Don't print the TGSI"},
55 { "noasm", DBG(NO_ASM
), "Don't print disassembled shaders"},
56 { "preoptir", DBG(PREOPT_IR
), "Print the LLVM IR before initial optimizations" },
58 /* Shader compiler options the shader cache should be aware of: */
59 { "unsafemath", DBG(UNSAFE_MATH
), "Enable unsafe math shader optimizations" },
60 { "sisched", DBG(SI_SCHED
), "Enable LLVM SI Machine Instruction Scheduler." },
61 { "gisel", DBG(GISEL
), "Enable LLVM global instruction selector." },
63 /* Shader compiler options (with no effect on the shader cache): */
64 { "checkir", DBG(CHECK_IR
), "Enable additional sanity checks on shader IR" },
65 { "mono", DBG(MONOLITHIC_SHADERS
), "Use old-style monolithic shaders compiled on demand" },
66 { "nooptvariant", DBG(NO_OPT_VARIANT
), "Disable compiling optimized shader variants." },
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" },
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." },
82 /* 3D engine options: */
83 { "alwayspd", DBG(ALWAYS_PD
), "Always enable the primitive discard compute shader." },
84 { "pd", DBG(PD
), "Enable the primitive discard compute shader for large draw calls." },
85 { "nopd", DBG(NO_PD
), "Disable the primitive discard compute shader." },
86 { "switch_on_eop", DBG(SWITCH_ON_EOP
), "Program WD/IA to switch on end-of-packet." },
87 { "nooutoforder", DBG(NO_OUT_OF_ORDER
), "Disable out-of-order rasterization" },
88 { "nodpbb", DBG(NO_DPBB
), "Disable DPBB." },
89 { "nodfsm", DBG(NO_DFSM
), "Disable DFSM." },
90 { "dpbb", DBG(DPBB
), "Enable DPBB." },
91 { "dfsm", DBG(DFSM
), "Enable DFSM." },
92 { "nohyperz", DBG(NO_HYPERZ
), "Disable Hyper-Z" },
93 { "norbplus", DBG(NO_RB_PLUS
), "Disable RB+." },
94 { "no2d", DBG(NO_2D_TILING
), "Disable 2D tiling" },
95 { "notiling", DBG(NO_TILING
), "Disable tiling" },
96 { "nodcc", DBG(NO_DCC
), "Disable DCC." },
97 { "nodccclear", DBG(NO_DCC_CLEAR
), "Disable DCC fast clear." },
98 { "nodccfb", DBG(NO_DCC_FB
), "Disable separate DCC on the main framebuffer" },
99 { "nodccmsaa", DBG(NO_DCC_MSAA
), "Disable DCC for MSAA" },
100 { "nofmask", DBG(NO_FMASK
), "Disable MSAA compression" },
103 { "testdma", DBG(TEST_DMA
), "Invoke SDMA tests and exit." },
104 { "testvmfaultcp", DBG(TEST_VMFAULT_CP
), "Invoke a CP VM fault test and exit." },
105 { "testvmfaultsdma", DBG(TEST_VMFAULT_SDMA
), "Invoke a SDMA VM fault test and exit." },
106 { "testvmfaultshader", DBG(TEST_VMFAULT_SHADER
), "Invoke a shader VM fault test and exit." },
107 { "testdmaperf", DBG(TEST_DMA_PERF
), "Test DMA performance" },
108 { "testgds", DBG(TEST_GDS
), "Test GDS." },
109 { "testgdsmm", DBG(TEST_GDS_MM
), "Test GDS memory management." },
110 { "testgdsoamm", DBG(TEST_GDS_OA_MM
), "Test GDS OA memory management." },
112 DEBUG_NAMED_VALUE_END
/* must be last */
115 static void si_init_compiler(struct si_screen
*sscreen
,
116 struct ac_llvm_compiler
*compiler
)
118 /* Only create the less-optimizing version of the compiler on APUs
119 * predating Ryzen (Raven). */
120 bool create_low_opt_compiler
= !sscreen
->info
.has_dedicated_vram
&&
121 sscreen
->info
.chip_class
<= GFX8
;
123 enum ac_target_machine_options tm_options
=
124 (sscreen
->debug_flags
& DBG(SI_SCHED
) ? AC_TM_SISCHED
: 0) |
125 (sscreen
->debug_flags
& DBG(GISEL
) ? AC_TM_ENABLE_GLOBAL_ISEL
: 0) |
126 (sscreen
->info
.chip_class
>= GFX9
? AC_TM_FORCE_ENABLE_XNACK
: 0) |
127 (sscreen
->info
.chip_class
< GFX9
? AC_TM_FORCE_DISABLE_XNACK
: 0) |
128 (!sscreen
->llvm_has_working_vgpr_indexing
? AC_TM_PROMOTE_ALLOCA_TO_SCRATCH
: 0) |
129 (sscreen
->debug_flags
& DBG(CHECK_IR
) ? AC_TM_CHECK_IR
: 0) |
130 (create_low_opt_compiler
? AC_TM_CREATE_LOW_OPT
: 0);
133 ac_init_llvm_compiler(compiler
, sscreen
->info
.family
, tm_options
);
134 compiler
->passes
= ac_create_llvm_passes(compiler
->tm
);
136 if (compiler
->low_opt_tm
)
137 compiler
->low_opt_passes
= ac_create_llvm_passes(compiler
->low_opt_tm
);
140 static void si_destroy_compiler(struct ac_llvm_compiler
*compiler
)
142 ac_destroy_llvm_passes(compiler
->passes
);
143 ac_destroy_llvm_passes(compiler
->low_opt_passes
);
144 ac_destroy_llvm_compiler(compiler
);
150 static void si_destroy_context(struct pipe_context
*context
)
152 struct si_context
*sctx
= (struct si_context
*)context
;
155 util_queue_finish(&sctx
->screen
->shader_compiler_queue
);
156 util_queue_finish(&sctx
->screen
->shader_compiler_queue_low_priority
);
158 /* Unreference the framebuffer normally to disable related logic
161 struct pipe_framebuffer_state fb
= {};
162 if (context
->set_framebuffer_state
)
163 context
->set_framebuffer_state(context
, &fb
);
165 si_release_all_descriptors(sctx
);
167 pipe_resource_reference(&sctx
->esgs_ring
, NULL
);
168 pipe_resource_reference(&sctx
->gsvs_ring
, NULL
);
169 pipe_resource_reference(&sctx
->tess_rings
, NULL
);
170 pipe_resource_reference(&sctx
->null_const_buf
.buffer
, NULL
);
171 pipe_resource_reference(&sctx
->sample_pos_buffer
, NULL
);
172 si_resource_reference(&sctx
->border_color_buffer
, NULL
);
173 free(sctx
->border_color_table
);
174 si_resource_reference(&sctx
->scratch_buffer
, NULL
);
175 si_resource_reference(&sctx
->compute_scratch_buffer
, NULL
);
176 si_resource_reference(&sctx
->wait_mem_scratch
, NULL
);
178 si_pm4_free_state(sctx
, sctx
->init_config
, ~0);
179 if (sctx
->init_config_gs_rings
)
180 si_pm4_free_state(sctx
, sctx
->init_config_gs_rings
, ~0);
181 for (i
= 0; i
< ARRAY_SIZE(sctx
->vgt_shader_config
); i
++)
182 si_pm4_delete_state(sctx
, vgt_shader_config
, sctx
->vgt_shader_config
[i
]);
184 if (sctx
->fixed_func_tcs_shader
.cso
)
185 sctx
->b
.delete_tcs_state(&sctx
->b
, sctx
->fixed_func_tcs_shader
.cso
);
186 if (sctx
->custom_dsa_flush
)
187 sctx
->b
.delete_depth_stencil_alpha_state(&sctx
->b
, sctx
->custom_dsa_flush
);
188 if (sctx
->custom_blend_resolve
)
189 sctx
->b
.delete_blend_state(&sctx
->b
, sctx
->custom_blend_resolve
);
190 if (sctx
->custom_blend_fmask_decompress
)
191 sctx
->b
.delete_blend_state(&sctx
->b
, sctx
->custom_blend_fmask_decompress
);
192 if (sctx
->custom_blend_eliminate_fastclear
)
193 sctx
->b
.delete_blend_state(&sctx
->b
, sctx
->custom_blend_eliminate_fastclear
);
194 if (sctx
->custom_blend_dcc_decompress
)
195 sctx
->b
.delete_blend_state(&sctx
->b
, sctx
->custom_blend_dcc_decompress
);
196 if (sctx
->vs_blit_pos
)
197 sctx
->b
.delete_vs_state(&sctx
->b
, sctx
->vs_blit_pos
);
198 if (sctx
->vs_blit_pos_layered
)
199 sctx
->b
.delete_vs_state(&sctx
->b
, sctx
->vs_blit_pos_layered
);
200 if (sctx
->vs_blit_color
)
201 sctx
->b
.delete_vs_state(&sctx
->b
, sctx
->vs_blit_color
);
202 if (sctx
->vs_blit_color_layered
)
203 sctx
->b
.delete_vs_state(&sctx
->b
, sctx
->vs_blit_color_layered
);
204 if (sctx
->vs_blit_texcoord
)
205 sctx
->b
.delete_vs_state(&sctx
->b
, sctx
->vs_blit_texcoord
);
206 if (sctx
->cs_clear_buffer
)
207 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_clear_buffer
);
208 if (sctx
->cs_copy_buffer
)
209 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_copy_buffer
);
210 if (sctx
->cs_copy_image
)
211 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_copy_image
);
212 if (sctx
->cs_copy_image_1d_array
)
213 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_copy_image_1d_array
);
214 if (sctx
->cs_clear_render_target
)
215 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_clear_render_target
);
216 if (sctx
->cs_clear_render_target_1d_array
)
217 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_clear_render_target_1d_array
);
218 if (sctx
->cs_dcc_retile
)
219 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_dcc_retile
);
222 util_blitter_destroy(sctx
->blitter
);
224 /* Release DCC stats. */
225 for (int i
= 0; i
< ARRAY_SIZE(sctx
->dcc_stats
); i
++) {
226 assert(!sctx
->dcc_stats
[i
].query_active
);
228 for (int j
= 0; j
< ARRAY_SIZE(sctx
->dcc_stats
[i
].ps_stats
); j
++)
229 if (sctx
->dcc_stats
[i
].ps_stats
[j
])
230 sctx
->b
.destroy_query(&sctx
->b
,
231 sctx
->dcc_stats
[i
].ps_stats
[j
]);
233 si_texture_reference(&sctx
->dcc_stats
[i
].tex
, NULL
);
236 if (sctx
->query_result_shader
)
237 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->query_result_shader
);
240 sctx
->ws
->cs_destroy(sctx
->gfx_cs
);
242 sctx
->ws
->cs_destroy(sctx
->dma_cs
);
244 sctx
->ws
->ctx_destroy(sctx
->ctx
);
246 if (sctx
->b
.stream_uploader
)
247 u_upload_destroy(sctx
->b
.stream_uploader
);
248 if (sctx
->b
.const_uploader
)
249 u_upload_destroy(sctx
->b
.const_uploader
);
250 if (sctx
->cached_gtt_allocator
)
251 u_upload_destroy(sctx
->cached_gtt_allocator
);
253 slab_destroy_child(&sctx
->pool_transfers
);
254 slab_destroy_child(&sctx
->pool_transfers_unsync
);
256 if (sctx
->allocator_zeroed_memory
)
257 u_suballocator_destroy(sctx
->allocator_zeroed_memory
);
259 sctx
->ws
->fence_reference(&sctx
->last_gfx_fence
, NULL
);
260 sctx
->ws
->fence_reference(&sctx
->last_sdma_fence
, NULL
);
261 sctx
->ws
->fence_reference(&sctx
->last_ib_barrier_fence
, NULL
);
262 si_resource_reference(&sctx
->eop_bug_scratch
, NULL
);
263 si_resource_reference(&sctx
->index_ring
, NULL
);
264 si_resource_reference(&sctx
->barrier_buf
, NULL
);
265 si_resource_reference(&sctx
->last_ib_barrier_buf
, NULL
);
266 pb_reference(&sctx
->gds
, NULL
);
267 pb_reference(&sctx
->gds_oa
, NULL
);
269 si_destroy_compiler(&sctx
->compiler
);
271 si_saved_cs_reference(&sctx
->current_saved_cs
, NULL
);
273 _mesa_hash_table_destroy(sctx
->tex_handles
, NULL
);
274 _mesa_hash_table_destroy(sctx
->img_handles
, NULL
);
276 util_dynarray_fini(&sctx
->resident_tex_handles
);
277 util_dynarray_fini(&sctx
->resident_img_handles
);
278 util_dynarray_fini(&sctx
->resident_tex_needs_color_decompress
);
279 util_dynarray_fini(&sctx
->resident_img_needs_color_decompress
);
280 util_dynarray_fini(&sctx
->resident_tex_needs_depth_decompress
);
281 si_unref_sdma_uploads(sctx
);
285 static enum pipe_reset_status
si_get_reset_status(struct pipe_context
*ctx
)
287 struct si_context
*sctx
= (struct si_context
*)ctx
;
289 return sctx
->ws
->ctx_query_reset_status(sctx
->ctx
);
292 static void si_set_device_reset_callback(struct pipe_context
*ctx
,
293 const struct pipe_device_reset_callback
*cb
)
295 struct si_context
*sctx
= (struct si_context
*)ctx
;
298 sctx
->device_reset_callback
= *cb
;
300 memset(&sctx
->device_reset_callback
, 0,
301 sizeof(sctx
->device_reset_callback
));
304 bool si_check_device_reset(struct si_context
*sctx
)
306 enum pipe_reset_status status
;
308 if (!sctx
->device_reset_callback
.reset
)
311 status
= sctx
->ws
->ctx_query_reset_status(sctx
->ctx
);
312 if (status
== PIPE_NO_RESET
)
315 sctx
->device_reset_callback
.reset(sctx
->device_reset_callback
.data
, status
);
319 /* Apitrace profiling:
320 * 1) qapitrace : Tools -> Profile: Measure CPU & GPU times
321 * 2) In the middle panel, zoom in (mouse wheel) on some bad draw call
322 * and remember its number.
323 * 3) In Mesa, enable queries and performance counters around that draw
324 * call and print the results.
325 * 4) glretrace --benchmark --markers ..
327 static void si_emit_string_marker(struct pipe_context
*ctx
,
328 const char *string
, int len
)
330 struct si_context
*sctx
= (struct si_context
*)ctx
;
332 dd_parse_apitrace_marker(string
, len
, &sctx
->apitrace_call_number
);
335 u_log_printf(sctx
->log
, "\nString marker: %*s\n", len
, string
);
338 static void si_set_debug_callback(struct pipe_context
*ctx
,
339 const struct pipe_debug_callback
*cb
)
341 struct si_context
*sctx
= (struct si_context
*)ctx
;
342 struct si_screen
*screen
= sctx
->screen
;
344 util_queue_finish(&screen
->shader_compiler_queue
);
345 util_queue_finish(&screen
->shader_compiler_queue_low_priority
);
350 memset(&sctx
->debug
, 0, sizeof(sctx
->debug
));
353 static void si_set_log_context(struct pipe_context
*ctx
,
354 struct u_log_context
*log
)
356 struct si_context
*sctx
= (struct si_context
*)ctx
;
360 u_log_add_auto_logger(log
, si_auto_log_cs
, sctx
);
363 static void si_set_context_param(struct pipe_context
*ctx
,
364 enum pipe_context_param param
,
367 struct radeon_winsys
*ws
= ((struct si_context
*)ctx
)->ws
;
370 case PIPE_CONTEXT_PARAM_PIN_THREADS_TO_L3_CACHE
:
371 ws
->pin_threads_to_L3_cache(ws
, value
);
377 static struct pipe_context
*si_create_context(struct pipe_screen
*screen
,
380 struct si_context
*sctx
= CALLOC_STRUCT(si_context
);
381 struct si_screen
* sscreen
= (struct si_screen
*)screen
;
382 struct radeon_winsys
*ws
= sscreen
->ws
;
384 bool stop_exec_on_failure
= (flags
& PIPE_CONTEXT_LOSE_CONTEXT_ON_RESET
) != 0;
389 sctx
->has_graphics
= sscreen
->info
.chip_class
== GFX6
||
390 !(flags
& PIPE_CONTEXT_COMPUTE_ONLY
);
392 if (flags
& PIPE_CONTEXT_DEBUG
)
393 sscreen
->record_llvm_ir
= true; /* racy but not critical */
395 sctx
->b
.screen
= screen
; /* this must be set first */
397 sctx
->b
.destroy
= si_destroy_context
;
398 sctx
->screen
= sscreen
; /* Easy accessing of screen/winsys. */
399 sctx
->is_debug
= (flags
& PIPE_CONTEXT_DEBUG
) != 0;
401 slab_create_child(&sctx
->pool_transfers
, &sscreen
->pool_transfers
);
402 slab_create_child(&sctx
->pool_transfers_unsync
, &sscreen
->pool_transfers
);
404 sctx
->ws
= sscreen
->ws
;
405 sctx
->family
= sscreen
->info
.family
;
406 sctx
->chip_class
= sscreen
->info
.chip_class
;
408 if (sctx
->chip_class
== GFX7
||
409 sctx
->chip_class
== GFX8
||
410 sctx
->chip_class
== GFX9
) {
411 sctx
->eop_bug_scratch
= si_resource(
412 pipe_buffer_create(&sscreen
->b
, 0, PIPE_USAGE_DEFAULT
,
413 16 * sscreen
->info
.num_render_backends
));
414 if (!sctx
->eop_bug_scratch
)
418 /* Initialize context allocators. */
419 sctx
->allocator_zeroed_memory
=
420 u_suballocator_create(&sctx
->b
, 128 * 1024,
421 0, PIPE_USAGE_DEFAULT
,
422 SI_RESOURCE_FLAG_UNMAPPABLE
|
423 SI_RESOURCE_FLAG_CLEAR
, false);
424 if (!sctx
->allocator_zeroed_memory
)
427 sctx
->b
.stream_uploader
= u_upload_create(&sctx
->b
, 1024 * 1024,
428 0, PIPE_USAGE_STREAM
,
429 SI_RESOURCE_FLAG_READ_ONLY
);
430 if (!sctx
->b
.stream_uploader
)
433 sctx
->cached_gtt_allocator
= u_upload_create(&sctx
->b
, 16 * 1024,
434 0, PIPE_USAGE_STAGING
, 0);
435 if (!sctx
->cached_gtt_allocator
)
438 sctx
->ctx
= sctx
->ws
->ctx_create(sctx
->ws
);
442 if (sscreen
->info
.num_sdma_rings
&& !(sscreen
->debug_flags
& DBG(NO_ASYNC_DMA
))) {
443 sctx
->dma_cs
= sctx
->ws
->cs_create(sctx
->ctx
, RING_DMA
,
444 (void*)si_flush_dma_cs
,
445 sctx
, stop_exec_on_failure
);
448 bool use_sdma_upload
= sscreen
->info
.has_dedicated_vram
&& sctx
->dma_cs
;
449 sctx
->b
.const_uploader
= u_upload_create(&sctx
->b
, 256 * 1024,
450 0, PIPE_USAGE_DEFAULT
,
451 SI_RESOURCE_FLAG_32BIT
|
453 SI_RESOURCE_FLAG_UPLOAD_FLUSH_EXPLICIT_VIA_SDMA
:
454 (sscreen
->cpdma_prefetch_writes_memory
?
455 0 : SI_RESOURCE_FLAG_READ_ONLY
)));
456 if (!sctx
->b
.const_uploader
)
460 u_upload_enable_flush_explicit(sctx
->b
.const_uploader
);
462 sctx
->gfx_cs
= ws
->cs_create(sctx
->ctx
,
463 sctx
->has_graphics
? RING_GFX
: RING_COMPUTE
,
464 (void*)si_flush_gfx_cs
, sctx
, stop_exec_on_failure
);
467 sctx
->border_color_table
= malloc(SI_MAX_BORDER_COLORS
*
468 sizeof(*sctx
->border_color_table
));
469 if (!sctx
->border_color_table
)
472 sctx
->border_color_buffer
= si_resource(
473 pipe_buffer_create(screen
, 0, PIPE_USAGE_DEFAULT
,
474 SI_MAX_BORDER_COLORS
*
475 sizeof(*sctx
->border_color_table
)));
476 if (!sctx
->border_color_buffer
)
479 sctx
->border_color_map
=
480 ws
->buffer_map(sctx
->border_color_buffer
->buf
,
481 NULL
, PIPE_TRANSFER_WRITE
);
482 if (!sctx
->border_color_map
)
485 /* Initialize context functions used by graphics and compute. */
486 sctx
->b
.emit_string_marker
= si_emit_string_marker
;
487 sctx
->b
.set_debug_callback
= si_set_debug_callback
;
488 sctx
->b
.set_log_context
= si_set_log_context
;
489 sctx
->b
.set_context_param
= si_set_context_param
;
490 sctx
->b
.get_device_reset_status
= si_get_reset_status
;
491 sctx
->b
.set_device_reset_callback
= si_set_device_reset_callback
;
493 si_init_all_descriptors(sctx
);
494 si_init_buffer_functions(sctx
);
495 si_init_clear_functions(sctx
);
496 si_init_blit_functions(sctx
);
497 si_init_compute_functions(sctx
);
498 si_init_compute_blit_functions(sctx
);
499 si_init_debug_functions(sctx
);
500 si_init_fence_functions(sctx
);
501 si_init_state_compute_functions(sctx
);
503 if (sscreen
->debug_flags
& DBG(FORCE_DMA
))
504 sctx
->b
.resource_copy_region
= sctx
->dma_copy
;
506 /* Initialize graphics-only context functions. */
507 if (sctx
->has_graphics
) {
508 si_init_context_texture_functions(sctx
);
509 si_init_query_functions(sctx
);
510 si_init_msaa_functions(sctx
);
511 si_init_shader_functions(sctx
);
512 si_init_state_functions(sctx
);
513 si_init_streamout_functions(sctx
);
514 si_init_viewport_functions(sctx
);
516 sctx
->blitter
= util_blitter_create(&sctx
->b
);
517 if (sctx
->blitter
== NULL
)
519 sctx
->blitter
->skip_viewport_restore
= true;
521 si_init_draw_functions(sctx
);
522 si_initialize_prim_discard_tunables(sctx
);
525 /* Initialize SDMA functions. */
526 if (sctx
->chip_class
>= GFX7
)
527 cik_init_sdma_functions(sctx
);
529 si_init_dma_functions(sctx
);
531 sctx
->sample_mask
= 0xffff;
533 /* Initialize multimedia functions. */
534 if (sscreen
->info
.has_hw_decode
) {
535 sctx
->b
.create_video_codec
= si_uvd_create_decoder
;
536 sctx
->b
.create_video_buffer
= si_video_buffer_create
;
538 sctx
->b
.create_video_codec
= vl_create_decoder
;
539 sctx
->b
.create_video_buffer
= vl_video_buffer_create
;
542 if (sctx
->chip_class
>= GFX9
) {
543 sctx
->wait_mem_scratch
= si_resource(
544 pipe_buffer_create(screen
, 0, PIPE_USAGE_DEFAULT
, 8));
545 if (!sctx
->wait_mem_scratch
)
548 /* Initialize the memory. */
549 si_cp_write_data(sctx
, sctx
->wait_mem_scratch
, 0, 4,
550 V_370_MEM
, V_370_ME
, &sctx
->wait_mem_number
);
553 /* GFX7 cannot unbind a constant buffer (S_BUFFER_LOAD doesn't skip loads
554 * if NUM_RECORDS == 0). We need to use a dummy buffer instead. */
555 if (sctx
->chip_class
== GFX7
) {
556 sctx
->null_const_buf
.buffer
=
557 pipe_aligned_buffer_create(screen
,
558 SI_RESOURCE_FLAG_32BIT
,
559 PIPE_USAGE_DEFAULT
, 16,
560 sctx
->screen
->info
.tcc_cache_line_size
);
561 if (!sctx
->null_const_buf
.buffer
)
563 sctx
->null_const_buf
.buffer_size
= sctx
->null_const_buf
.buffer
->width0
;
565 unsigned start_shader
= sctx
->has_graphics
? 0 : PIPE_SHADER_COMPUTE
;
566 for (shader
= start_shader
; shader
< SI_NUM_SHADERS
; shader
++) {
567 for (i
= 0; i
< SI_NUM_CONST_BUFFERS
; i
++) {
568 sctx
->b
.set_constant_buffer(&sctx
->b
, shader
, i
,
569 &sctx
->null_const_buf
);
573 si_set_rw_buffer(sctx
, SI_HS_CONST_DEFAULT_TESS_LEVELS
,
574 &sctx
->null_const_buf
);
575 si_set_rw_buffer(sctx
, SI_VS_CONST_INSTANCE_DIVISORS
,
576 &sctx
->null_const_buf
);
577 si_set_rw_buffer(sctx
, SI_VS_CONST_CLIP_PLANES
,
578 &sctx
->null_const_buf
);
579 si_set_rw_buffer(sctx
, SI_PS_CONST_POLY_STIPPLE
,
580 &sctx
->null_const_buf
);
581 si_set_rw_buffer(sctx
, SI_PS_CONST_SAMPLE_POSITIONS
,
582 &sctx
->null_const_buf
);
585 uint64_t max_threads_per_block
;
586 screen
->get_compute_param(screen
, PIPE_SHADER_IR_TGSI
,
587 PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK
,
588 &max_threads_per_block
);
590 /* The maximum number of scratch waves. Scratch space isn't divided
591 * evenly between CUs. The number is only a function of the number of CUs.
592 * We can decrease the constant to decrease the scratch buffer size.
594 * sctx->scratch_waves must be >= the maximum posible size of
595 * 1 threadgroup, so that the hw doesn't hang from being unable
598 * The recommended value is 4 per CU at most. Higher numbers don't
599 * bring much benefit, but they still occupy chip resources (think
600 * async compute). I've seen ~2% performance difference between 4 and 32.
602 sctx
->scratch_waves
= MAX2(32 * sscreen
->info
.num_good_compute_units
,
603 max_threads_per_block
/ 64);
605 si_init_compiler(sscreen
, &sctx
->compiler
);
607 /* Bindless handles. */
608 sctx
->tex_handles
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
609 _mesa_key_pointer_equal
);
610 sctx
->img_handles
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
611 _mesa_key_pointer_equal
);
613 util_dynarray_init(&sctx
->resident_tex_handles
, NULL
);
614 util_dynarray_init(&sctx
->resident_img_handles
, NULL
);
615 util_dynarray_init(&sctx
->resident_tex_needs_color_decompress
, NULL
);
616 util_dynarray_init(&sctx
->resident_img_needs_color_decompress
, NULL
);
617 util_dynarray_init(&sctx
->resident_tex_needs_depth_decompress
, NULL
);
619 sctx
->sample_pos_buffer
=
620 pipe_buffer_create(sctx
->b
.screen
, 0, PIPE_USAGE_DEFAULT
,
621 sizeof(sctx
->sample_positions
));
622 pipe_buffer_write(&sctx
->b
, sctx
->sample_pos_buffer
, 0,
623 sizeof(sctx
->sample_positions
), &sctx
->sample_positions
);
625 /* this must be last */
626 si_begin_new_gfx_cs(sctx
);
628 if (sctx
->chip_class
== GFX7
) {
629 /* Clear the NULL constant buffer, because loads should return zeros.
630 * Note that this forces CP DMA to be used, because clover deadlocks
631 * for some reason when the compute codepath is used.
633 uint32_t clear_value
= 0;
634 si_clear_buffer(sctx
, sctx
->null_const_buf
.buffer
, 0,
635 sctx
->null_const_buf
.buffer
->width0
,
636 &clear_value
, 4, SI_COHERENCY_SHADER
, true);
640 fprintf(stderr
, "radeonsi: Failed to create a context.\n");
641 si_destroy_context(&sctx
->b
);
645 static struct pipe_context
*si_pipe_create_context(struct pipe_screen
*screen
,
646 void *priv
, unsigned flags
)
648 struct si_screen
*sscreen
= (struct si_screen
*)screen
;
649 struct pipe_context
*ctx
;
651 if (sscreen
->debug_flags
& DBG(CHECK_VM
))
652 flags
|= PIPE_CONTEXT_DEBUG
;
654 ctx
= si_create_context(screen
, flags
);
656 if (!(flags
& PIPE_CONTEXT_PREFER_THREADED
))
659 /* Clover (compute-only) is unsupported. */
660 if (flags
& PIPE_CONTEXT_COMPUTE_ONLY
)
663 /* When shaders are logged to stderr, asynchronous compilation is
665 if (sscreen
->debug_flags
& DBG_ALL_SHADERS
)
668 /* Use asynchronous flushes only on amdgpu, since the radeon
669 * implementation for fence_server_sync is incomplete. */
670 return threaded_context_create(ctx
, &sscreen
->pool_transfers
,
671 si_replace_buffer_storage
,
672 sscreen
->info
.drm_major
>= 3 ? si_create_fence
: NULL
,
673 &((struct si_context
*)ctx
)->tc
);
679 static void si_destroy_screen(struct pipe_screen
* pscreen
)
681 struct si_screen
*sscreen
= (struct si_screen
*)pscreen
;
682 struct si_shader_part
*parts
[] = {
684 sscreen
->tcs_epilogs
,
691 if (!sscreen
->ws
->unref(sscreen
->ws
))
694 mtx_destroy(&sscreen
->aux_context_lock
);
696 struct u_log_context
*aux_log
= ((struct si_context
*)sscreen
->aux_context
)->log
;
698 sscreen
->aux_context
->set_log_context(sscreen
->aux_context
, NULL
);
699 u_log_context_destroy(aux_log
);
703 sscreen
->aux_context
->destroy(sscreen
->aux_context
);
705 util_queue_destroy(&sscreen
->shader_compiler_queue
);
706 util_queue_destroy(&sscreen
->shader_compiler_queue_low_priority
);
708 for (i
= 0; i
< ARRAY_SIZE(sscreen
->compiler
); i
++)
709 si_destroy_compiler(&sscreen
->compiler
[i
]);
711 for (i
= 0; i
< ARRAY_SIZE(sscreen
->compiler_lowp
); i
++)
712 si_destroy_compiler(&sscreen
->compiler_lowp
[i
]);
714 /* Free shader parts. */
715 for (i
= 0; i
< ARRAY_SIZE(parts
); i
++) {
717 struct si_shader_part
*part
= parts
[i
];
719 parts
[i
] = part
->next
;
720 ac_shader_binary_clean(&part
->binary
);
724 mtx_destroy(&sscreen
->shader_parts_mutex
);
725 si_destroy_shader_cache(sscreen
);
727 si_destroy_perfcounters(sscreen
);
728 si_gpu_load_kill_thread(sscreen
);
730 mtx_destroy(&sscreen
->gpu_load_mutex
);
732 slab_destroy_parent(&sscreen
->pool_transfers
);
734 disk_cache_destroy(sscreen
->disk_shader_cache
);
735 sscreen
->ws
->destroy(sscreen
->ws
);
739 static void si_init_gs_info(struct si_screen
*sscreen
)
741 sscreen
->gs_table_depth
= ac_get_gs_table_depth(sscreen
->info
.chip_class
,
742 sscreen
->info
.family
);
745 static void si_test_vmfault(struct si_screen
*sscreen
)
747 struct pipe_context
*ctx
= sscreen
->aux_context
;
748 struct si_context
*sctx
= (struct si_context
*)ctx
;
749 struct pipe_resource
*buf
=
750 pipe_buffer_create_const0(&sscreen
->b
, 0, PIPE_USAGE_DEFAULT
, 64);
753 puts("Buffer allocation failed.");
757 si_resource(buf
)->gpu_address
= 0; /* cause a VM fault */
759 if (sscreen
->debug_flags
& DBG(TEST_VMFAULT_CP
)) {
760 si_cp_dma_copy_buffer(sctx
, buf
, buf
, 0, 4, 4, 0,
761 SI_COHERENCY_NONE
, L2_BYPASS
);
762 ctx
->flush(ctx
, NULL
, 0);
763 puts("VM fault test: CP - done.");
765 if (sscreen
->debug_flags
& DBG(TEST_VMFAULT_SDMA
)) {
766 si_sdma_clear_buffer(sctx
, buf
, 0, 4, 0);
767 ctx
->flush(ctx
, NULL
, 0);
768 puts("VM fault test: SDMA - done.");
770 if (sscreen
->debug_flags
& DBG(TEST_VMFAULT_SHADER
)) {
771 util_test_constant_buffer(ctx
, buf
);
772 puts("VM fault test: Shader - done.");
777 static void si_test_gds_memory_management(struct si_context
*sctx
,
778 unsigned alloc_size
, unsigned alignment
,
779 enum radeon_bo_domain domain
)
781 struct radeon_winsys
*ws
= sctx
->ws
;
782 struct radeon_cmdbuf
*cs
[8];
783 struct pb_buffer
*gds_bo
[ARRAY_SIZE(cs
)];
785 for (unsigned i
= 0; i
< ARRAY_SIZE(cs
); i
++) {
786 cs
[i
] = ws
->cs_create(sctx
->ctx
, RING_COMPUTE
,
788 gds_bo
[i
] = ws
->buffer_create(ws
, alloc_size
, alignment
, domain
, 0);
792 for (unsigned iterations
= 0; iterations
< 20000; iterations
++) {
793 for (unsigned i
= 0; i
< ARRAY_SIZE(cs
); i
++) {
794 /* This clears GDS with CP DMA.
796 * We don't care if GDS is present. Just add some packet
797 * to make the GPU busy for a moment.
799 si_cp_dma_clear_buffer(sctx
, cs
[i
], NULL
, 0, alloc_size
, 0,
800 SI_CPDMA_SKIP_BO_LIST_UPDATE
|
801 SI_CPDMA_SKIP_CHECK_CS_SPACE
|
802 SI_CPDMA_SKIP_GFX_SYNC
, 0, 0);
804 ws
->cs_add_buffer(cs
[i
], gds_bo
[i
], domain
,
805 RADEON_USAGE_READWRITE
, 0);
806 ws
->cs_flush(cs
[i
], PIPE_FLUSH_ASYNC
, NULL
);
812 static void si_disk_cache_create(struct si_screen
*sscreen
)
814 /* Don't use the cache if shader dumping is enabled. */
815 if (sscreen
->debug_flags
& DBG_ALL_SHADERS
)
818 struct mesa_sha1 ctx
;
819 unsigned char sha1
[20];
820 char cache_id
[20 * 2 + 1];
822 _mesa_sha1_init(&ctx
);
824 if (!disk_cache_get_function_identifier(si_disk_cache_create
, &ctx
) ||
825 !disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo
,
829 _mesa_sha1_final(&ctx
, sha1
);
830 disk_cache_format_hex_id(cache_id
, sha1
, 20 * 2);
832 /* These flags affect shader compilation. */
833 #define ALL_FLAGS (DBG(FS_CORRECT_DERIVS_AFTER_KILL) | \
837 uint64_t shader_debug_flags
= sscreen
->debug_flags
&
840 /* Add the high bits of 32-bit addresses, which affects
841 * how 32-bit addresses are expanded to 64 bits.
843 STATIC_ASSERT(ALL_FLAGS
<= UINT_MAX
);
844 assert((int16_t)sscreen
->info
.address32_hi
== (int32_t)sscreen
->info
.address32_hi
);
845 shader_debug_flags
|= (uint64_t)(sscreen
->info
.address32_hi
& 0xffff) << 32;
847 if (sscreen
->options
.enable_nir
)
848 shader_debug_flags
|= 1ull << 48;
850 sscreen
->disk_shader_cache
=
851 disk_cache_create(sscreen
->info
.name
,
856 static void si_set_max_shader_compiler_threads(struct pipe_screen
*screen
,
857 unsigned max_threads
)
859 struct si_screen
*sscreen
= (struct si_screen
*)screen
;
861 /* This function doesn't allow a greater number of threads than
862 * the queue had at its creation. */
863 util_queue_adjust_num_threads(&sscreen
->shader_compiler_queue
,
865 /* Don't change the number of threads on the low priority queue. */
868 static bool si_is_parallel_shader_compilation_finished(struct pipe_screen
*screen
,
870 unsigned shader_type
)
872 if (shader_type
== PIPE_SHADER_COMPUTE
) {
873 struct si_compute
*cs
= (struct si_compute
*)shader
;
875 return util_queue_fence_is_signalled(&cs
->ready
);
877 struct si_shader_selector
*sel
= (struct si_shader_selector
*)shader
;
879 return util_queue_fence_is_signalled(&sel
->ready
);
882 struct pipe_screen
*radeonsi_screen_create(struct radeon_winsys
*ws
,
883 const struct pipe_screen_config
*config
)
885 struct si_screen
*sscreen
= CALLOC_STRUCT(si_screen
);
886 unsigned hw_threads
, num_comp_hi_threads
, num_comp_lo_threads
, i
;
893 ws
->query_info(ws
, &sscreen
->info
);
895 if (sscreen
->info
.chip_class
>= GFX9
) {
896 sscreen
->se_tile_repeat
= 32 * sscreen
->info
.max_se
;
898 ac_get_raster_config(&sscreen
->info
,
899 &sscreen
->pa_sc_raster_config
,
900 &sscreen
->pa_sc_raster_config_1
,
901 &sscreen
->se_tile_repeat
);
904 sscreen
->debug_flags
= debug_get_flags_option("R600_DEBUG",
906 sscreen
->debug_flags
|= debug_get_flags_option("AMD_DEBUG",
909 /* Set functions first. */
910 sscreen
->b
.context_create
= si_pipe_create_context
;
911 sscreen
->b
.destroy
= si_destroy_screen
;
912 sscreen
->b
.set_max_shader_compiler_threads
=
913 si_set_max_shader_compiler_threads
;
914 sscreen
->b
.is_parallel_shader_compilation_finished
=
915 si_is_parallel_shader_compilation_finished
;
917 si_init_screen_get_functions(sscreen
);
918 si_init_screen_buffer_functions(sscreen
);
919 si_init_screen_fence_functions(sscreen
);
920 si_init_screen_state_functions(sscreen
);
921 si_init_screen_texture_functions(sscreen
);
922 si_init_screen_query_functions(sscreen
);
924 /* Set these flags in debug_flags early, so that the shader cache takes
927 if (driQueryOptionb(config
->options
,
928 "glsl_correct_derivatives_after_discard"))
929 sscreen
->debug_flags
|= DBG(FS_CORRECT_DERIVS_AFTER_KILL
);
930 if (driQueryOptionb(config
->options
, "radeonsi_enable_sisched"))
931 sscreen
->debug_flags
|= DBG(SI_SCHED
);
933 if (sscreen
->debug_flags
& DBG(INFO
))
934 ac_print_gpu_info(&sscreen
->info
);
936 slab_create_parent(&sscreen
->pool_transfers
,
937 sizeof(struct si_transfer
), 64);
939 sscreen
->force_aniso
= MIN2(16, debug_get_num_option("R600_TEX_ANISO", -1));
940 if (sscreen
->force_aniso
== -1) {
941 sscreen
->force_aniso
= MIN2(16, debug_get_num_option("AMD_TEX_ANISO", -1));
944 if (sscreen
->force_aniso
>= 0) {
945 printf("radeonsi: Forcing anisotropy filter to %ix\n",
946 /* round down to a power of two */
947 1 << util_logbase2(sscreen
->force_aniso
));
950 (void) mtx_init(&sscreen
->aux_context_lock
, mtx_plain
);
951 (void) mtx_init(&sscreen
->gpu_load_mutex
, mtx_plain
);
953 si_init_gs_info(sscreen
);
954 if (!si_init_shader_cache(sscreen
)) {
959 si_disk_cache_create(sscreen
);
961 /* Determine the number of shader compiler threads. */
962 hw_threads
= sysconf(_SC_NPROCESSORS_ONLN
);
964 if (hw_threads
>= 12) {
965 num_comp_hi_threads
= hw_threads
* 3 / 4;
966 num_comp_lo_threads
= hw_threads
/ 3;
967 } else if (hw_threads
>= 6) {
968 num_comp_hi_threads
= hw_threads
- 2;
969 num_comp_lo_threads
= hw_threads
/ 2;
970 } else if (hw_threads
>= 2) {
971 num_comp_hi_threads
= hw_threads
- 1;
972 num_comp_lo_threads
= hw_threads
/ 2;
974 num_comp_hi_threads
= 1;
975 num_comp_lo_threads
= 1;
978 num_comp_hi_threads
= MIN2(num_comp_hi_threads
,
979 ARRAY_SIZE(sscreen
->compiler
));
980 num_comp_lo_threads
= MIN2(num_comp_lo_threads
,
981 ARRAY_SIZE(sscreen
->compiler_lowp
));
983 if (!util_queue_init(&sscreen
->shader_compiler_queue
, "sh",
984 64, num_comp_hi_threads
,
985 UTIL_QUEUE_INIT_RESIZE_IF_FULL
|
986 UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY
)) {
987 si_destroy_shader_cache(sscreen
);
992 if (!util_queue_init(&sscreen
->shader_compiler_queue_low_priority
,
994 64, num_comp_lo_threads
,
995 UTIL_QUEUE_INIT_RESIZE_IF_FULL
|
996 UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY
|
997 UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY
)) {
998 si_destroy_shader_cache(sscreen
);
1003 if (!debug_get_bool_option("RADEON_DISABLE_PERFCOUNTERS", false))
1004 si_init_perfcounters(sscreen
);
1006 /* Determine tessellation ring info. */
1007 bool double_offchip_buffers
= sscreen
->info
.chip_class
>= GFX7
&&
1008 sscreen
->info
.family
!= CHIP_CARRIZO
&&
1009 sscreen
->info
.family
!= CHIP_STONEY
;
1010 /* This must be one less than the maximum number due to a hw limitation.
1011 * Various hardware bugs need this.
1013 unsigned max_offchip_buffers_per_se
;
1015 /* Only certain chips can use the maximum value. */
1016 if (sscreen
->info
.family
== CHIP_VEGA12
||
1017 sscreen
->info
.family
== CHIP_VEGA20
)
1018 max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1020 max_offchip_buffers_per_se
= double_offchip_buffers
? 127 : 63;
1022 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1023 sscreen
->info
.max_se
;
1024 unsigned offchip_granularity
;
1026 /* Hawaii has a bug with offchip buffers > 256 that can be worked
1027 * around by setting 4K granularity.
1029 if (sscreen
->info
.family
== CHIP_HAWAII
) {
1030 sscreen
->tess_offchip_block_dw_size
= 4096;
1031 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1033 sscreen
->tess_offchip_block_dw_size
= 8192;
1034 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1037 sscreen
->tess_factor_ring_size
= 32768 * sscreen
->info
.max_se
;
1038 assert(((sscreen
->tess_factor_ring_size
/ 4) & C_030938_SIZE
) == 0);
1039 sscreen
->tess_offchip_ring_size
= max_offchip_buffers
*
1040 sscreen
->tess_offchip_block_dw_size
* 4;
1042 if (sscreen
->info
.chip_class
>= GFX7
) {
1043 if (sscreen
->info
.chip_class
>= GFX8
)
1044 --max_offchip_buffers
;
1045 sscreen
->vgt_hs_offchip_param
=
1046 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1047 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1049 assert(offchip_granularity
== V_03093C_X_8K_DWORDS
);
1050 sscreen
->vgt_hs_offchip_param
=
1051 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1054 /* The mere presense of CLEAR_STATE in the IB causes random GPU hangs
1055 * on GFX6. Some CLEAR_STATE cause asic hang on radeon kernel, etc.
1056 * SPI_VS_OUT_CONFIG. So only enable GFX7 CLEAR_STATE on amdgpu kernel.*/
1057 sscreen
->has_clear_state
= sscreen
->info
.chip_class
>= GFX7
&&
1058 sscreen
->info
.drm_major
== 3;
1060 sscreen
->has_distributed_tess
=
1061 sscreen
->info
.chip_class
>= GFX8
&&
1062 sscreen
->info
.max_se
>= 2;
1064 sscreen
->has_draw_indirect_multi
=
1065 (sscreen
->info
.family
>= CHIP_POLARIS10
) ||
1066 (sscreen
->info
.chip_class
== GFX8
&&
1067 sscreen
->info
.pfp_fw_version
>= 121 &&
1068 sscreen
->info
.me_fw_version
>= 87) ||
1069 (sscreen
->info
.chip_class
== GFX7
&&
1070 sscreen
->info
.pfp_fw_version
>= 211 &&
1071 sscreen
->info
.me_fw_version
>= 173) ||
1072 (sscreen
->info
.chip_class
== GFX6
&&
1073 sscreen
->info
.pfp_fw_version
>= 79 &&
1074 sscreen
->info
.me_fw_version
>= 142);
1076 sscreen
->has_out_of_order_rast
= sscreen
->info
.chip_class
>= GFX8
&&
1077 sscreen
->info
.max_se
>= 2 &&
1078 !(sscreen
->debug_flags
& DBG(NO_OUT_OF_ORDER
));
1079 sscreen
->assume_no_z_fights
=
1080 driQueryOptionb(config
->options
, "radeonsi_assume_no_z_fights");
1081 sscreen
->commutative_blend_add
=
1082 driQueryOptionb(config
->options
, "radeonsi_commutative_blend_add");
1085 #define OPT_BOOL(name, dflt, description) \
1086 sscreen->options.name = \
1087 driQueryOptionb(config->options, "radeonsi_"#name);
1088 #include "si_debug_options.h"
1091 sscreen
->has_gfx9_scissor_bug
= sscreen
->info
.family
== CHIP_VEGA10
||
1092 sscreen
->info
.family
== CHIP_RAVEN
;
1093 sscreen
->has_msaa_sample_loc_bug
= (sscreen
->info
.family
>= CHIP_POLARIS10
&&
1094 sscreen
->info
.family
<= CHIP_POLARIS12
) ||
1095 sscreen
->info
.family
== CHIP_VEGA10
||
1096 sscreen
->info
.family
== CHIP_RAVEN
;
1097 sscreen
->has_ls_vgpr_init_bug
= sscreen
->info
.family
== CHIP_VEGA10
||
1098 sscreen
->info
.family
== CHIP_RAVEN
;
1099 sscreen
->has_dcc_constant_encode
= sscreen
->info
.family
== CHIP_RAVEN2
;
1101 /* Only enable primitive binning on APUs by default. */
1102 sscreen
->dpbb_allowed
= sscreen
->info
.family
== CHIP_RAVEN
||
1103 sscreen
->info
.family
== CHIP_RAVEN2
;
1105 sscreen
->dfsm_allowed
= sscreen
->info
.family
== CHIP_RAVEN
||
1106 sscreen
->info
.family
== CHIP_RAVEN2
;
1108 /* Process DPBB enable flags. */
1109 if (sscreen
->debug_flags
& DBG(DPBB
)) {
1110 sscreen
->dpbb_allowed
= true;
1111 if (sscreen
->debug_flags
& DBG(DFSM
))
1112 sscreen
->dfsm_allowed
= true;
1115 /* Process DPBB disable flags. */
1116 if (sscreen
->debug_flags
& DBG(NO_DPBB
)) {
1117 sscreen
->dpbb_allowed
= false;
1118 sscreen
->dfsm_allowed
= false;
1119 } else if (sscreen
->debug_flags
& DBG(NO_DFSM
)) {
1120 sscreen
->dfsm_allowed
= false;
1123 /* While it would be nice not to have this flag, we are constrained
1124 * by the reality that LLVM 5.0 doesn't have working VGPR indexing
1127 sscreen
->llvm_has_working_vgpr_indexing
= sscreen
->info
.chip_class
<= GFX8
;
1129 /* Some chips have RB+ registers, but don't support RB+. Those must
1130 * always disable it.
1132 if (sscreen
->info
.family
== CHIP_STONEY
||
1133 sscreen
->info
.chip_class
>= GFX9
) {
1134 sscreen
->has_rbplus
= true;
1136 sscreen
->rbplus_allowed
=
1137 !(sscreen
->debug_flags
& DBG(NO_RB_PLUS
)) &&
1138 (sscreen
->info
.family
== CHIP_STONEY
||
1139 sscreen
->info
.family
== CHIP_VEGA12
||
1140 sscreen
->info
.family
== CHIP_RAVEN
||
1141 sscreen
->info
.family
== CHIP_RAVEN2
);
1144 sscreen
->dcc_msaa_allowed
=
1145 !(sscreen
->debug_flags
& DBG(NO_DCC_MSAA
));
1147 sscreen
->cpdma_prefetch_writes_memory
= sscreen
->info
.chip_class
<= GFX8
;
1149 (void) mtx_init(&sscreen
->shader_parts_mutex
, mtx_plain
);
1150 sscreen
->use_monolithic_shaders
=
1151 (sscreen
->debug_flags
& DBG(MONOLITHIC_SHADERS
)) != 0;
1153 sscreen
->barrier_flags
.cp_to_L2
= SI_CONTEXT_INV_SMEM_L1
|
1154 SI_CONTEXT_INV_VMEM_L1
;
1155 if (sscreen
->info
.chip_class
<= GFX8
) {
1156 sscreen
->barrier_flags
.cp_to_L2
|= SI_CONTEXT_INV_GLOBAL_L2
;
1157 sscreen
->barrier_flags
.L2_to_cp
|= SI_CONTEXT_WRITEBACK_GLOBAL_L2
;
1160 if (debug_get_bool_option("RADEON_DUMP_SHADERS", false))
1161 sscreen
->debug_flags
|= DBG_ALL_SHADERS
;
1168 * That means 8 coverage samples, 4 Z/S samples, and 2 color samples.
1170 * s >= z >= c (ignoring this only wastes memory)
1175 * Only MSAA color and depth buffers are overriden.
1177 if (sscreen
->info
.has_eqaa_surface_allocator
) {
1178 const char *eqaa
= debug_get_option("EQAA", NULL
);
1181 if (eqaa
&& sscanf(eqaa
, "%u,%u,%u", &s
, &z
, &f
) == 3 && s
&& z
&& f
) {
1182 sscreen
->eqaa_force_coverage_samples
= s
;
1183 sscreen
->eqaa_force_z_samples
= z
;
1184 sscreen
->eqaa_force_color_samples
= f
;
1188 for (i
= 0; i
< num_comp_hi_threads
; i
++)
1189 si_init_compiler(sscreen
, &sscreen
->compiler
[i
]);
1190 for (i
= 0; i
< num_comp_lo_threads
; i
++)
1191 si_init_compiler(sscreen
, &sscreen
->compiler_lowp
[i
]);
1193 /* Create the auxiliary context. This must be done last. */
1194 sscreen
->aux_context
= si_create_context(
1195 &sscreen
->b
, sscreen
->options
.aux_debug
? PIPE_CONTEXT_DEBUG
: 0);
1196 if (sscreen
->options
.aux_debug
) {
1197 struct u_log_context
*log
= CALLOC_STRUCT(u_log_context
);
1198 u_log_context_init(log
);
1199 sscreen
->aux_context
->set_log_context(sscreen
->aux_context
, log
);
1202 if (sscreen
->debug_flags
& DBG(TEST_DMA
))
1203 si_test_dma(sscreen
);
1205 if (sscreen
->debug_flags
& DBG(TEST_DMA_PERF
)) {
1206 si_test_dma_perf(sscreen
);
1209 if (sscreen
->debug_flags
& (DBG(TEST_VMFAULT_CP
) |
1210 DBG(TEST_VMFAULT_SDMA
) |
1211 DBG(TEST_VMFAULT_SHADER
)))
1212 si_test_vmfault(sscreen
);
1214 if (sscreen
->debug_flags
& DBG(TEST_GDS
))
1215 si_test_gds((struct si_context
*)sscreen
->aux_context
);
1217 if (sscreen
->debug_flags
& DBG(TEST_GDS_MM
)) {
1218 si_test_gds_memory_management((struct si_context
*)sscreen
->aux_context
,
1219 32 * 1024, 4, RADEON_DOMAIN_GDS
);
1221 if (sscreen
->debug_flags
& DBG(TEST_GDS_OA_MM
)) {
1222 si_test_gds_memory_management((struct si_context
*)sscreen
->aux_context
,
1223 4, 1, RADEON_DOMAIN_OA
);