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 "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"
44 #include "gallium/winsys/radeon/drm/radeon_drm_public.h"
45 #include "gallium/winsys/amdgpu/drm/amdgpu_public.h"
48 static const struct debug_named_value debug_options
[] = {
49 /* Shader logging options: */
50 { "vs", DBG(VS
), "Print vertex shaders" },
51 { "ps", DBG(PS
), "Print pixel shaders" },
52 { "gs", DBG(GS
), "Print geometry shaders" },
53 { "tcs", DBG(TCS
), "Print tessellation control shaders" },
54 { "tes", DBG(TES
), "Print tessellation evaluation shaders" },
55 { "cs", DBG(CS
), "Print compute shaders" },
56 { "noir", DBG(NO_IR
), "Don't print the LLVM IR"},
57 { "notgsi", DBG(NO_TGSI
), "Don't print the TGSI"},
58 { "noasm", DBG(NO_ASM
), "Don't print disassembled shaders"},
59 { "preoptir", DBG(PREOPT_IR
), "Print the LLVM IR before initial optimizations" },
61 /* Shader compiler options the shader cache should be aware of: */
62 { "unsafemath", DBG(UNSAFE_MATH
), "Enable unsafe math shader optimizations" },
63 { "sisched", DBG(SI_SCHED
), "Enable LLVM SI Machine Instruction Scheduler." },
64 { "gisel", DBG(GISEL
), "Enable LLVM global instruction selector." },
65 { "w32ge", DBG(W32_GE
), "Use Wave32 for vertex, tessellation, and geometry shaders." },
66 { "w32ps", DBG(W32_PS
), "Use Wave32 for pixel shaders." },
67 { "w32cs", DBG(W32_CS
), "Use Wave32 for computes shaders." },
68 { "w64ge", DBG(W64_GE
), "Use Wave64 for vertex, tessellation, and geometry shaders." },
69 { "w64ps", DBG(W64_PS
), "Use Wave64 for pixel shaders." },
70 { "w64cs", DBG(W64_CS
), "Use Wave64 for computes shaders." },
72 /* Shader compiler options (with no effect on the shader cache): */
73 { "checkir", DBG(CHECK_IR
), "Enable additional sanity checks on shader IR" },
74 { "mono", DBG(MONOLITHIC_SHADERS
), "Use old-style monolithic shaders compiled on demand" },
75 { "nooptvariant", DBG(NO_OPT_VARIANT
), "Disable compiling optimized shader variants." },
77 /* Information logging options: */
78 { "info", DBG(INFO
), "Print driver information" },
79 { "tex", DBG(TEX
), "Print texture info" },
80 { "compute", DBG(COMPUTE
), "Print compute info" },
81 { "vm", DBG(VM
), "Print virtual addresses when creating resources" },
84 { "forcedma", DBG(FORCE_DMA
), "Use asynchronous DMA for all operations when possible." },
85 { "nodma", DBG(NO_ASYNC_DMA
), "Disable asynchronous DMA" },
86 { "nowc", DBG(NO_WC
), "Disable GTT write combining" },
87 { "check_vm", DBG(CHECK_VM
), "Check VM faults and dump debug info." },
88 { "reserve_vmid", DBG(RESERVE_VMID
), "Force VMID reservation per context." },
89 { "zerovram", DBG(ZERO_VRAM
), "Clear VRAM allocations." },
91 /* 3D engine options: */
92 { "nogfx", DBG(NO_GFX
), "Disable graphics. Only multimedia compute paths can be used." },
93 { "alwayspd", DBG(ALWAYS_PD
), "Always enable the primitive discard compute shader." },
94 { "pd", DBG(PD
), "Enable the primitive discard compute shader for large draw calls." },
95 { "nopd", DBG(NO_PD
), "Disable the primitive discard compute shader." },
96 { "switch_on_eop", DBG(SWITCH_ON_EOP
), "Program WD/IA to switch on end-of-packet." },
97 { "nooutoforder", DBG(NO_OUT_OF_ORDER
), "Disable out-of-order rasterization" },
98 { "nodpbb", DBG(NO_DPBB
), "Disable DPBB." },
99 { "nodfsm", DBG(NO_DFSM
), "Disable DFSM." },
100 { "dpbb", DBG(DPBB
), "Enable DPBB." },
101 { "dfsm", DBG(DFSM
), "Enable DFSM." },
102 { "nohyperz", DBG(NO_HYPERZ
), "Disable Hyper-Z" },
103 { "norbplus", DBG(NO_RB_PLUS
), "Disable RB+." },
104 { "no2d", DBG(NO_2D_TILING
), "Disable 2D tiling" },
105 { "notiling", DBG(NO_TILING
), "Disable tiling" },
106 { "nodcc", DBG(NO_DCC
), "Disable DCC." },
107 { "nodccclear", DBG(NO_DCC_CLEAR
), "Disable DCC fast clear." },
108 { "nodccfb", DBG(NO_DCC_FB
), "Disable separate DCC on the main framebuffer" },
109 { "nodccmsaa", DBG(NO_DCC_MSAA
), "Disable DCC for MSAA" },
110 { "nofmask", DBG(NO_FMASK
), "Disable MSAA compression" },
113 { "testdma", DBG(TEST_DMA
), "Invoke SDMA tests and exit." },
114 { "testvmfaultcp", DBG(TEST_VMFAULT_CP
), "Invoke a CP VM fault test and exit." },
115 { "testvmfaultsdma", DBG(TEST_VMFAULT_SDMA
), "Invoke a SDMA VM fault test and exit." },
116 { "testvmfaultshader", DBG(TEST_VMFAULT_SHADER
), "Invoke a shader VM fault test and exit." },
117 { "testdmaperf", DBG(TEST_DMA_PERF
), "Test DMA performance" },
118 { "testgds", DBG(TEST_GDS
), "Test GDS." },
119 { "testgdsmm", DBG(TEST_GDS_MM
), "Test GDS memory management." },
120 { "testgdsoamm", DBG(TEST_GDS_OA_MM
), "Test GDS OA memory management." },
122 DEBUG_NAMED_VALUE_END
/* must be last */
125 static void si_init_compiler(struct si_screen
*sscreen
,
126 struct ac_llvm_compiler
*compiler
)
128 /* Only create the less-optimizing version of the compiler on APUs
129 * predating Ryzen (Raven). */
130 bool create_low_opt_compiler
= !sscreen
->info
.has_dedicated_vram
&&
131 sscreen
->info
.chip_class
<= GFX8
;
133 enum ac_target_machine_options tm_options
=
134 (sscreen
->debug_flags
& DBG(SI_SCHED
) ? AC_TM_SISCHED
: 0) |
135 (sscreen
->debug_flags
& DBG(GISEL
) ? AC_TM_ENABLE_GLOBAL_ISEL
: 0) |
136 (sscreen
->info
.chip_class
>= GFX9
? AC_TM_FORCE_ENABLE_XNACK
: 0) |
137 (sscreen
->info
.chip_class
< GFX9
? AC_TM_FORCE_DISABLE_XNACK
: 0) |
138 (!sscreen
->llvm_has_working_vgpr_indexing
? AC_TM_PROMOTE_ALLOCA_TO_SCRATCH
: 0) |
139 (sscreen
->debug_flags
& DBG(CHECK_IR
) ? AC_TM_CHECK_IR
: 0) |
140 (create_low_opt_compiler
? AC_TM_CREATE_LOW_OPT
: 0);
143 ac_init_llvm_compiler(compiler
, sscreen
->info
.family
, tm_options
);
144 compiler
->passes
= ac_create_llvm_passes(compiler
->tm
);
146 if (compiler
->tm_wave32
)
147 compiler
->passes_wave32
= ac_create_llvm_passes(compiler
->tm_wave32
);
148 if (compiler
->low_opt_tm
)
149 compiler
->low_opt_passes
= ac_create_llvm_passes(compiler
->low_opt_tm
);
152 static void si_destroy_compiler(struct ac_llvm_compiler
*compiler
)
154 ac_destroy_llvm_compiler(compiler
);
160 static void si_destroy_context(struct pipe_context
*context
)
162 struct si_context
*sctx
= (struct si_context
*)context
;
165 util_queue_finish(&sctx
->screen
->shader_compiler_queue
);
166 util_queue_finish(&sctx
->screen
->shader_compiler_queue_low_priority
);
168 /* Unreference the framebuffer normally to disable related logic
171 struct pipe_framebuffer_state fb
= {};
172 if (context
->set_framebuffer_state
)
173 context
->set_framebuffer_state(context
, &fb
);
175 si_release_all_descriptors(sctx
);
177 if (sctx
->chip_class
>= GFX10
)
178 gfx10_destroy_query(sctx
);
180 pipe_resource_reference(&sctx
->esgs_ring
, NULL
);
181 pipe_resource_reference(&sctx
->gsvs_ring
, NULL
);
182 pipe_resource_reference(&sctx
->tess_rings
, NULL
);
183 pipe_resource_reference(&sctx
->null_const_buf
.buffer
, NULL
);
184 pipe_resource_reference(&sctx
->sample_pos_buffer
, NULL
);
185 si_resource_reference(&sctx
->border_color_buffer
, NULL
);
186 free(sctx
->border_color_table
);
187 si_resource_reference(&sctx
->scratch_buffer
, NULL
);
188 si_resource_reference(&sctx
->compute_scratch_buffer
, NULL
);
189 si_resource_reference(&sctx
->wait_mem_scratch
, NULL
);
191 si_pm4_free_state(sctx
, sctx
->init_config
, ~0);
192 if (sctx
->init_config_gs_rings
)
193 si_pm4_free_state(sctx
, sctx
->init_config_gs_rings
, ~0);
194 for (i
= 0; i
< ARRAY_SIZE(sctx
->vgt_shader_config
); i
++)
195 si_pm4_delete_state(sctx
, vgt_shader_config
, sctx
->vgt_shader_config
[i
]);
197 if (sctx
->fixed_func_tcs_shader
.cso
)
198 sctx
->b
.delete_tcs_state(&sctx
->b
, sctx
->fixed_func_tcs_shader
.cso
);
199 if (sctx
->custom_dsa_flush
)
200 sctx
->b
.delete_depth_stencil_alpha_state(&sctx
->b
, sctx
->custom_dsa_flush
);
201 if (sctx
->custom_blend_resolve
)
202 sctx
->b
.delete_blend_state(&sctx
->b
, sctx
->custom_blend_resolve
);
203 if (sctx
->custom_blend_fmask_decompress
)
204 sctx
->b
.delete_blend_state(&sctx
->b
, sctx
->custom_blend_fmask_decompress
);
205 if (sctx
->custom_blend_eliminate_fastclear
)
206 sctx
->b
.delete_blend_state(&sctx
->b
, sctx
->custom_blend_eliminate_fastclear
);
207 if (sctx
->custom_blend_dcc_decompress
)
208 sctx
->b
.delete_blend_state(&sctx
->b
, sctx
->custom_blend_dcc_decompress
);
209 if (sctx
->vs_blit_pos
)
210 sctx
->b
.delete_vs_state(&sctx
->b
, sctx
->vs_blit_pos
);
211 if (sctx
->vs_blit_pos_layered
)
212 sctx
->b
.delete_vs_state(&sctx
->b
, sctx
->vs_blit_pos_layered
);
213 if (sctx
->vs_blit_color
)
214 sctx
->b
.delete_vs_state(&sctx
->b
, sctx
->vs_blit_color
);
215 if (sctx
->vs_blit_color_layered
)
216 sctx
->b
.delete_vs_state(&sctx
->b
, sctx
->vs_blit_color_layered
);
217 if (sctx
->vs_blit_texcoord
)
218 sctx
->b
.delete_vs_state(&sctx
->b
, sctx
->vs_blit_texcoord
);
219 if (sctx
->cs_clear_buffer
)
220 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_clear_buffer
);
221 if (sctx
->cs_copy_buffer
)
222 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_copy_buffer
);
223 if (sctx
->cs_copy_image
)
224 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_copy_image
);
225 if (sctx
->cs_copy_image_1d_array
)
226 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_copy_image_1d_array
);
227 if (sctx
->cs_clear_render_target
)
228 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_clear_render_target
);
229 if (sctx
->cs_clear_render_target_1d_array
)
230 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_clear_render_target_1d_array
);
231 if (sctx
->cs_dcc_retile
)
232 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_dcc_retile
);
235 util_blitter_destroy(sctx
->blitter
);
237 /* Release DCC stats. */
238 for (int i
= 0; i
< ARRAY_SIZE(sctx
->dcc_stats
); i
++) {
239 assert(!sctx
->dcc_stats
[i
].query_active
);
241 for (int j
= 0; j
< ARRAY_SIZE(sctx
->dcc_stats
[i
].ps_stats
); j
++)
242 if (sctx
->dcc_stats
[i
].ps_stats
[j
])
243 sctx
->b
.destroy_query(&sctx
->b
,
244 sctx
->dcc_stats
[i
].ps_stats
[j
]);
246 si_texture_reference(&sctx
->dcc_stats
[i
].tex
, NULL
);
249 if (sctx
->query_result_shader
)
250 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->query_result_shader
);
251 if (sctx
->sh_query_result_shader
)
252 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->sh_query_result_shader
);
255 sctx
->ws
->cs_destroy(sctx
->gfx_cs
);
257 sctx
->ws
->cs_destroy(sctx
->dma_cs
);
259 sctx
->ws
->ctx_destroy(sctx
->ctx
);
261 if (sctx
->b
.stream_uploader
)
262 u_upload_destroy(sctx
->b
.stream_uploader
);
263 if (sctx
->b
.const_uploader
)
264 u_upload_destroy(sctx
->b
.const_uploader
);
265 if (sctx
->cached_gtt_allocator
)
266 u_upload_destroy(sctx
->cached_gtt_allocator
);
268 slab_destroy_child(&sctx
->pool_transfers
);
269 slab_destroy_child(&sctx
->pool_transfers_unsync
);
271 if (sctx
->allocator_zeroed_memory
)
272 u_suballocator_destroy(sctx
->allocator_zeroed_memory
);
274 sctx
->ws
->fence_reference(&sctx
->last_gfx_fence
, NULL
);
275 sctx
->ws
->fence_reference(&sctx
->last_sdma_fence
, NULL
);
276 sctx
->ws
->fence_reference(&sctx
->last_ib_barrier_fence
, NULL
);
277 si_resource_reference(&sctx
->eop_bug_scratch
, NULL
);
278 si_resource_reference(&sctx
->index_ring
, NULL
);
279 si_resource_reference(&sctx
->barrier_buf
, NULL
);
280 si_resource_reference(&sctx
->last_ib_barrier_buf
, NULL
);
281 pb_reference(&sctx
->gds
, NULL
);
282 pb_reference(&sctx
->gds_oa
, NULL
);
284 si_destroy_compiler(&sctx
->compiler
);
286 si_saved_cs_reference(&sctx
->current_saved_cs
, NULL
);
288 _mesa_hash_table_destroy(sctx
->tex_handles
, NULL
);
289 _mesa_hash_table_destroy(sctx
->img_handles
, NULL
);
291 util_dynarray_fini(&sctx
->resident_tex_handles
);
292 util_dynarray_fini(&sctx
->resident_img_handles
);
293 util_dynarray_fini(&sctx
->resident_tex_needs_color_decompress
);
294 util_dynarray_fini(&sctx
->resident_img_needs_color_decompress
);
295 util_dynarray_fini(&sctx
->resident_tex_needs_depth_decompress
);
296 si_unref_sdma_uploads(sctx
);
300 static enum pipe_reset_status
si_get_reset_status(struct pipe_context
*ctx
)
302 struct si_context
*sctx
= (struct si_context
*)ctx
;
304 return sctx
->ws
->ctx_query_reset_status(sctx
->ctx
);
307 static void si_set_device_reset_callback(struct pipe_context
*ctx
,
308 const struct pipe_device_reset_callback
*cb
)
310 struct si_context
*sctx
= (struct si_context
*)ctx
;
313 sctx
->device_reset_callback
= *cb
;
315 memset(&sctx
->device_reset_callback
, 0,
316 sizeof(sctx
->device_reset_callback
));
319 bool si_check_device_reset(struct si_context
*sctx
)
321 enum pipe_reset_status status
;
323 if (!sctx
->device_reset_callback
.reset
)
326 status
= sctx
->ws
->ctx_query_reset_status(sctx
->ctx
);
327 if (status
== PIPE_NO_RESET
)
330 sctx
->device_reset_callback
.reset(sctx
->device_reset_callback
.data
, status
);
334 /* Apitrace profiling:
335 * 1) qapitrace : Tools -> Profile: Measure CPU & GPU times
336 * 2) In the middle panel, zoom in (mouse wheel) on some bad draw call
337 * and remember its number.
338 * 3) In Mesa, enable queries and performance counters around that draw
339 * call and print the results.
340 * 4) glretrace --benchmark --markers ..
342 static void si_emit_string_marker(struct pipe_context
*ctx
,
343 const char *string
, int len
)
345 struct si_context
*sctx
= (struct si_context
*)ctx
;
347 dd_parse_apitrace_marker(string
, len
, &sctx
->apitrace_call_number
);
350 u_log_printf(sctx
->log
, "\nString marker: %*s\n", len
, string
);
353 static void si_set_debug_callback(struct pipe_context
*ctx
,
354 const struct pipe_debug_callback
*cb
)
356 struct si_context
*sctx
= (struct si_context
*)ctx
;
357 struct si_screen
*screen
= sctx
->screen
;
359 util_queue_finish(&screen
->shader_compiler_queue
);
360 util_queue_finish(&screen
->shader_compiler_queue_low_priority
);
365 memset(&sctx
->debug
, 0, sizeof(sctx
->debug
));
368 static void si_set_log_context(struct pipe_context
*ctx
,
369 struct u_log_context
*log
)
371 struct si_context
*sctx
= (struct si_context
*)ctx
;
375 u_log_add_auto_logger(log
, si_auto_log_cs
, sctx
);
378 static void si_set_context_param(struct pipe_context
*ctx
,
379 enum pipe_context_param param
,
382 struct radeon_winsys
*ws
= ((struct si_context
*)ctx
)->ws
;
385 case PIPE_CONTEXT_PARAM_PIN_THREADS_TO_L3_CACHE
:
386 ws
->pin_threads_to_L3_cache(ws
, value
);
392 static struct pipe_context
*si_create_context(struct pipe_screen
*screen
,
395 struct si_screen
* sscreen
= (struct si_screen
*)screen
;
397 /* Don't create a context if it's not compute-only and hw is compute-only. */
398 if (!sscreen
->info
.has_graphics
&&
399 !(flags
& PIPE_CONTEXT_COMPUTE_ONLY
))
402 struct si_context
*sctx
= CALLOC_STRUCT(si_context
);
403 struct radeon_winsys
*ws
= sscreen
->ws
;
405 bool stop_exec_on_failure
= (flags
& PIPE_CONTEXT_LOSE_CONTEXT_ON_RESET
) != 0;
410 sctx
->has_graphics
= sscreen
->info
.chip_class
== GFX6
||
411 !(flags
& PIPE_CONTEXT_COMPUTE_ONLY
);
413 if (flags
& PIPE_CONTEXT_DEBUG
)
414 sscreen
->record_llvm_ir
= true; /* racy but not critical */
416 sctx
->b
.screen
= screen
; /* this must be set first */
418 sctx
->b
.destroy
= si_destroy_context
;
419 sctx
->screen
= sscreen
; /* Easy accessing of screen/winsys. */
420 sctx
->is_debug
= (flags
& PIPE_CONTEXT_DEBUG
) != 0;
422 slab_create_child(&sctx
->pool_transfers
, &sscreen
->pool_transfers
);
423 slab_create_child(&sctx
->pool_transfers_unsync
, &sscreen
->pool_transfers
);
425 sctx
->ws
= sscreen
->ws
;
426 sctx
->family
= sscreen
->info
.family
;
427 sctx
->chip_class
= sscreen
->info
.chip_class
;
429 if (sctx
->chip_class
== GFX7
||
430 sctx
->chip_class
== GFX8
||
431 sctx
->chip_class
== GFX9
) {
432 sctx
->eop_bug_scratch
= si_resource(
433 pipe_buffer_create(&sscreen
->b
, 0, PIPE_USAGE_DEFAULT
,
434 16 * sscreen
->info
.num_render_backends
));
435 if (!sctx
->eop_bug_scratch
)
439 /* Initialize context allocators. */
440 sctx
->allocator_zeroed_memory
=
441 u_suballocator_create(&sctx
->b
, 128 * 1024,
442 0, PIPE_USAGE_DEFAULT
,
443 SI_RESOURCE_FLAG_UNMAPPABLE
|
444 SI_RESOURCE_FLAG_CLEAR
, false);
445 if (!sctx
->allocator_zeroed_memory
)
448 sctx
->b
.stream_uploader
= u_upload_create(&sctx
->b
, 1024 * 1024,
449 0, PIPE_USAGE_STREAM
,
450 SI_RESOURCE_FLAG_READ_ONLY
);
451 if (!sctx
->b
.stream_uploader
)
454 sctx
->cached_gtt_allocator
= u_upload_create(&sctx
->b
, 16 * 1024,
455 0, PIPE_USAGE_STAGING
, 0);
456 if (!sctx
->cached_gtt_allocator
)
459 sctx
->ctx
= sctx
->ws
->ctx_create(sctx
->ws
);
463 if (sscreen
->info
.num_sdma_rings
&& !(sscreen
->debug_flags
& DBG(NO_ASYNC_DMA
))) {
464 sctx
->dma_cs
= sctx
->ws
->cs_create(sctx
->ctx
, RING_DMA
,
465 (void*)si_flush_dma_cs
,
466 sctx
, stop_exec_on_failure
);
469 bool use_sdma_upload
= sscreen
->info
.has_dedicated_vram
&& sctx
->dma_cs
;
470 sctx
->b
.const_uploader
= u_upload_create(&sctx
->b
, 256 * 1024,
471 0, PIPE_USAGE_DEFAULT
,
472 SI_RESOURCE_FLAG_32BIT
|
474 SI_RESOURCE_FLAG_UPLOAD_FLUSH_EXPLICIT_VIA_SDMA
: 0));
475 if (!sctx
->b
.const_uploader
)
479 u_upload_enable_flush_explicit(sctx
->b
.const_uploader
);
481 sctx
->gfx_cs
= ws
->cs_create(sctx
->ctx
,
482 sctx
->has_graphics
? RING_GFX
: RING_COMPUTE
,
483 (void*)si_flush_gfx_cs
, sctx
, stop_exec_on_failure
);
486 sctx
->border_color_table
= malloc(SI_MAX_BORDER_COLORS
*
487 sizeof(*sctx
->border_color_table
));
488 if (!sctx
->border_color_table
)
491 sctx
->border_color_buffer
= si_resource(
492 pipe_buffer_create(screen
, 0, PIPE_USAGE_DEFAULT
,
493 SI_MAX_BORDER_COLORS
*
494 sizeof(*sctx
->border_color_table
)));
495 if (!sctx
->border_color_buffer
)
498 sctx
->border_color_map
=
499 ws
->buffer_map(sctx
->border_color_buffer
->buf
,
500 NULL
, PIPE_TRANSFER_WRITE
);
501 if (!sctx
->border_color_map
)
504 sctx
->ngg
= sscreen
->use_ngg
;
506 /* Initialize context functions used by graphics and compute. */
507 if (sctx
->chip_class
>= GFX10
)
508 sctx
->emit_cache_flush
= gfx10_emit_cache_flush
;
510 sctx
->emit_cache_flush
= si_emit_cache_flush
;
512 sctx
->b
.emit_string_marker
= si_emit_string_marker
;
513 sctx
->b
.set_debug_callback
= si_set_debug_callback
;
514 sctx
->b
.set_log_context
= si_set_log_context
;
515 sctx
->b
.set_context_param
= si_set_context_param
;
516 sctx
->b
.get_device_reset_status
= si_get_reset_status
;
517 sctx
->b
.set_device_reset_callback
= si_set_device_reset_callback
;
519 si_init_all_descriptors(sctx
);
520 si_init_buffer_functions(sctx
);
521 si_init_clear_functions(sctx
);
522 si_init_blit_functions(sctx
);
523 si_init_compute_functions(sctx
);
524 si_init_compute_blit_functions(sctx
);
525 si_init_debug_functions(sctx
);
526 si_init_fence_functions(sctx
);
527 si_init_query_functions(sctx
);
528 si_init_state_compute_functions(sctx
);
529 si_init_context_texture_functions(sctx
);
531 /* Initialize graphics-only context functions. */
532 if (sctx
->has_graphics
) {
533 if (sctx
->chip_class
>= GFX10
)
534 gfx10_init_query(sctx
);
535 si_init_msaa_functions(sctx
);
536 si_init_shader_functions(sctx
);
537 si_init_state_functions(sctx
);
538 si_init_streamout_functions(sctx
);
539 si_init_viewport_functions(sctx
);
541 sctx
->blitter
= util_blitter_create(&sctx
->b
);
542 if (sctx
->blitter
== NULL
)
544 sctx
->blitter
->skip_viewport_restore
= true;
546 /* Some states are expected to be always non-NULL. */
547 sctx
->noop_blend
= util_blitter_get_noop_blend_state(sctx
->blitter
);
548 sctx
->queued
.named
.blend
= sctx
->noop_blend
;
550 sctx
->noop_dsa
= util_blitter_get_noop_dsa_state(sctx
->blitter
);
551 sctx
->queued
.named
.dsa
= sctx
->noop_dsa
;
553 sctx
->discard_rasterizer_state
=
554 util_blitter_get_discard_rasterizer_state(sctx
->blitter
);
555 sctx
->queued
.named
.rasterizer
= sctx
->discard_rasterizer_state
;
557 si_init_draw_functions(sctx
);
558 si_initialize_prim_discard_tunables(sctx
);
561 /* Initialize SDMA functions. */
562 if (sctx
->chip_class
>= GFX7
)
563 cik_init_sdma_functions(sctx
);
565 si_init_dma_functions(sctx
);
567 if (sscreen
->debug_flags
& DBG(FORCE_DMA
))
568 sctx
->b
.resource_copy_region
= sctx
->dma_copy
;
570 sctx
->sample_mask
= 0xffff;
572 /* Initialize multimedia functions. */
573 if (sscreen
->info
.has_hw_decode
) {
574 sctx
->b
.create_video_codec
= si_uvd_create_decoder
;
575 sctx
->b
.create_video_buffer
= si_video_buffer_create
;
577 sctx
->b
.create_video_codec
= vl_create_decoder
;
578 sctx
->b
.create_video_buffer
= vl_video_buffer_create
;
581 if (sctx
->chip_class
>= GFX9
) {
582 sctx
->wait_mem_scratch
= si_resource(
583 pipe_buffer_create(screen
, 0, PIPE_USAGE_DEFAULT
, 8));
584 if (!sctx
->wait_mem_scratch
)
587 /* Initialize the memory. */
588 si_cp_write_data(sctx
, sctx
->wait_mem_scratch
, 0, 4,
589 V_370_MEM
, V_370_ME
, &sctx
->wait_mem_number
);
592 /* GFX7 cannot unbind a constant buffer (S_BUFFER_LOAD doesn't skip loads
593 * if NUM_RECORDS == 0). We need to use a dummy buffer instead. */
594 if (sctx
->chip_class
== GFX7
) {
595 sctx
->null_const_buf
.buffer
=
596 pipe_aligned_buffer_create(screen
,
597 SI_RESOURCE_FLAG_32BIT
,
598 PIPE_USAGE_DEFAULT
, 16,
599 sctx
->screen
->info
.tcc_cache_line_size
);
600 if (!sctx
->null_const_buf
.buffer
)
602 sctx
->null_const_buf
.buffer_size
= sctx
->null_const_buf
.buffer
->width0
;
604 unsigned start_shader
= sctx
->has_graphics
? 0 : PIPE_SHADER_COMPUTE
;
605 for (shader
= start_shader
; shader
< SI_NUM_SHADERS
; shader
++) {
606 for (i
= 0; i
< SI_NUM_CONST_BUFFERS
; i
++) {
607 sctx
->b
.set_constant_buffer(&sctx
->b
, shader
, i
,
608 &sctx
->null_const_buf
);
612 si_set_rw_buffer(sctx
, SI_HS_CONST_DEFAULT_TESS_LEVELS
,
613 &sctx
->null_const_buf
);
614 si_set_rw_buffer(sctx
, SI_VS_CONST_INSTANCE_DIVISORS
,
615 &sctx
->null_const_buf
);
616 si_set_rw_buffer(sctx
, SI_VS_CONST_CLIP_PLANES
,
617 &sctx
->null_const_buf
);
618 si_set_rw_buffer(sctx
, SI_PS_CONST_POLY_STIPPLE
,
619 &sctx
->null_const_buf
);
620 si_set_rw_buffer(sctx
, SI_PS_CONST_SAMPLE_POSITIONS
,
621 &sctx
->null_const_buf
);
624 uint64_t max_threads_per_block
;
625 screen
->get_compute_param(screen
, PIPE_SHADER_IR_TGSI
,
626 PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK
,
627 &max_threads_per_block
);
629 /* The maximum number of scratch waves. Scratch space isn't divided
630 * evenly between CUs. The number is only a function of the number of CUs.
631 * We can decrease the constant to decrease the scratch buffer size.
633 * sctx->scratch_waves must be >= the maximum posible size of
634 * 1 threadgroup, so that the hw doesn't hang from being unable
637 * The recommended value is 4 per CU at most. Higher numbers don't
638 * bring much benefit, but they still occupy chip resources (think
639 * async compute). I've seen ~2% performance difference between 4 and 32.
641 sctx
->scratch_waves
= MAX2(32 * sscreen
->info
.num_good_compute_units
,
642 max_threads_per_block
/ 64);
644 si_init_compiler(sscreen
, &sctx
->compiler
);
646 /* Bindless handles. */
647 sctx
->tex_handles
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
648 _mesa_key_pointer_equal
);
649 sctx
->img_handles
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
650 _mesa_key_pointer_equal
);
652 util_dynarray_init(&sctx
->resident_tex_handles
, NULL
);
653 util_dynarray_init(&sctx
->resident_img_handles
, NULL
);
654 util_dynarray_init(&sctx
->resident_tex_needs_color_decompress
, NULL
);
655 util_dynarray_init(&sctx
->resident_img_needs_color_decompress
, NULL
);
656 util_dynarray_init(&sctx
->resident_tex_needs_depth_decompress
, NULL
);
658 sctx
->sample_pos_buffer
=
659 pipe_buffer_create(sctx
->b
.screen
, 0, PIPE_USAGE_DEFAULT
,
660 sizeof(sctx
->sample_positions
));
661 pipe_buffer_write(&sctx
->b
, sctx
->sample_pos_buffer
, 0,
662 sizeof(sctx
->sample_positions
), &sctx
->sample_positions
);
664 /* this must be last */
665 si_begin_new_gfx_cs(sctx
);
667 if (sctx
->chip_class
== GFX7
) {
668 /* Clear the NULL constant buffer, because loads should return zeros.
669 * Note that this forces CP DMA to be used, because clover deadlocks
670 * for some reason when the compute codepath is used.
672 uint32_t clear_value
= 0;
673 si_clear_buffer(sctx
, sctx
->null_const_buf
.buffer
, 0,
674 sctx
->null_const_buf
.buffer
->width0
,
675 &clear_value
, 4, SI_COHERENCY_SHADER
, true);
679 fprintf(stderr
, "radeonsi: Failed to create a context.\n");
680 si_destroy_context(&sctx
->b
);
684 static struct pipe_context
*si_pipe_create_context(struct pipe_screen
*screen
,
685 void *priv
, unsigned flags
)
687 struct si_screen
*sscreen
= (struct si_screen
*)screen
;
688 struct pipe_context
*ctx
;
690 if (sscreen
->debug_flags
& DBG(CHECK_VM
))
691 flags
|= PIPE_CONTEXT_DEBUG
;
693 ctx
= si_create_context(screen
, flags
);
695 if (!(flags
& PIPE_CONTEXT_PREFER_THREADED
))
698 /* Clover (compute-only) is unsupported. */
699 if (flags
& PIPE_CONTEXT_COMPUTE_ONLY
)
702 /* When shaders are logged to stderr, asynchronous compilation is
704 if (sscreen
->debug_flags
& DBG_ALL_SHADERS
)
707 /* Use asynchronous flushes only on amdgpu, since the radeon
708 * implementation for fence_server_sync is incomplete. */
709 return threaded_context_create(ctx
, &sscreen
->pool_transfers
,
710 si_replace_buffer_storage
,
711 sscreen
->info
.is_amdgpu
? si_create_fence
: NULL
,
712 &((struct si_context
*)ctx
)->tc
);
718 static void si_destroy_screen(struct pipe_screen
* pscreen
)
720 struct si_screen
*sscreen
= (struct si_screen
*)pscreen
;
721 struct si_shader_part
*parts
[] = {
723 sscreen
->tcs_epilogs
,
730 if (!sscreen
->ws
->unref(sscreen
->ws
))
733 mtx_destroy(&sscreen
->aux_context_lock
);
735 struct u_log_context
*aux_log
= ((struct si_context
*)sscreen
->aux_context
)->log
;
737 sscreen
->aux_context
->set_log_context(sscreen
->aux_context
, NULL
);
738 u_log_context_destroy(aux_log
);
742 sscreen
->aux_context
->destroy(sscreen
->aux_context
);
744 util_queue_destroy(&sscreen
->shader_compiler_queue
);
745 util_queue_destroy(&sscreen
->shader_compiler_queue_low_priority
);
747 for (i
= 0; i
< ARRAY_SIZE(sscreen
->compiler
); i
++)
748 si_destroy_compiler(&sscreen
->compiler
[i
]);
750 for (i
= 0; i
< ARRAY_SIZE(sscreen
->compiler_lowp
); i
++)
751 si_destroy_compiler(&sscreen
->compiler_lowp
[i
]);
753 /* Free shader parts. */
754 for (i
= 0; i
< ARRAY_SIZE(parts
); i
++) {
756 struct si_shader_part
*part
= parts
[i
];
758 parts
[i
] = part
->next
;
759 si_shader_binary_clean(&part
->binary
);
763 mtx_destroy(&sscreen
->shader_parts_mutex
);
764 si_destroy_shader_cache(sscreen
);
766 si_destroy_perfcounters(sscreen
);
767 si_gpu_load_kill_thread(sscreen
);
769 mtx_destroy(&sscreen
->gpu_load_mutex
);
771 slab_destroy_parent(&sscreen
->pool_transfers
);
773 disk_cache_destroy(sscreen
->disk_shader_cache
);
774 sscreen
->ws
->destroy(sscreen
->ws
);
778 static void si_init_gs_info(struct si_screen
*sscreen
)
780 sscreen
->gs_table_depth
= ac_get_gs_table_depth(sscreen
->info
.chip_class
,
781 sscreen
->info
.family
);
784 static void si_test_vmfault(struct si_screen
*sscreen
)
786 struct pipe_context
*ctx
= sscreen
->aux_context
;
787 struct si_context
*sctx
= (struct si_context
*)ctx
;
788 struct pipe_resource
*buf
=
789 pipe_buffer_create_const0(&sscreen
->b
, 0, PIPE_USAGE_DEFAULT
, 64);
792 puts("Buffer allocation failed.");
796 si_resource(buf
)->gpu_address
= 0; /* cause a VM fault */
798 if (sscreen
->debug_flags
& DBG(TEST_VMFAULT_CP
)) {
799 si_cp_dma_copy_buffer(sctx
, buf
, buf
, 0, 4, 4, 0,
800 SI_COHERENCY_NONE
, L2_BYPASS
);
801 ctx
->flush(ctx
, NULL
, 0);
802 puts("VM fault test: CP - done.");
804 if (sscreen
->debug_flags
& DBG(TEST_VMFAULT_SDMA
)) {
805 si_sdma_clear_buffer(sctx
, buf
, 0, 4, 0);
806 ctx
->flush(ctx
, NULL
, 0);
807 puts("VM fault test: SDMA - done.");
809 if (sscreen
->debug_flags
& DBG(TEST_VMFAULT_SHADER
)) {
810 util_test_constant_buffer(ctx
, buf
);
811 puts("VM fault test: Shader - done.");
816 static void si_test_gds_memory_management(struct si_context
*sctx
,
817 unsigned alloc_size
, unsigned alignment
,
818 enum radeon_bo_domain domain
)
820 struct radeon_winsys
*ws
= sctx
->ws
;
821 struct radeon_cmdbuf
*cs
[8];
822 struct pb_buffer
*gds_bo
[ARRAY_SIZE(cs
)];
824 for (unsigned i
= 0; i
< ARRAY_SIZE(cs
); i
++) {
825 cs
[i
] = ws
->cs_create(sctx
->ctx
, RING_COMPUTE
,
827 gds_bo
[i
] = ws
->buffer_create(ws
, alloc_size
, alignment
, domain
, 0);
831 for (unsigned iterations
= 0; iterations
< 20000; iterations
++) {
832 for (unsigned i
= 0; i
< ARRAY_SIZE(cs
); i
++) {
833 /* This clears GDS with CP DMA.
835 * We don't care if GDS is present. Just add some packet
836 * to make the GPU busy for a moment.
838 si_cp_dma_clear_buffer(sctx
, cs
[i
], NULL
, 0, alloc_size
, 0,
839 SI_CPDMA_SKIP_BO_LIST_UPDATE
|
840 SI_CPDMA_SKIP_CHECK_CS_SPACE
|
841 SI_CPDMA_SKIP_GFX_SYNC
, 0, 0);
843 ws
->cs_add_buffer(cs
[i
], gds_bo
[i
], domain
,
844 RADEON_USAGE_READWRITE
, 0);
845 ws
->cs_flush(cs
[i
], PIPE_FLUSH_ASYNC
, NULL
);
851 static void si_disk_cache_create(struct si_screen
*sscreen
)
853 /* Don't use the cache if shader dumping is enabled. */
854 if (sscreen
->debug_flags
& DBG_ALL_SHADERS
)
857 struct mesa_sha1 ctx
;
858 unsigned char sha1
[20];
859 char cache_id
[20 * 2 + 1];
861 _mesa_sha1_init(&ctx
);
863 if (!disk_cache_get_function_identifier(si_disk_cache_create
, &ctx
) ||
864 !disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo
,
868 _mesa_sha1_final(&ctx
, sha1
);
869 disk_cache_format_hex_id(cache_id
, sha1
, 20 * 2);
871 /* These flags affect shader compilation. */
872 #define ALL_FLAGS (DBG(FS_CORRECT_DERIVS_AFTER_KILL) | \
882 uint64_t shader_debug_flags
= sscreen
->debug_flags
& ALL_FLAGS
;
884 if (sscreen
->options
.enable_nir
) {
885 STATIC_ASSERT((ALL_FLAGS
& (1u << 31)) == 0);
886 shader_debug_flags
|= 1u << 31;
889 /* Add the high bits of 32-bit addresses, which affects
890 * how 32-bit addresses are expanded to 64 bits.
892 STATIC_ASSERT(ALL_FLAGS
<= UINT_MAX
);
893 assert((int16_t)sscreen
->info
.address32_hi
== (int32_t)sscreen
->info
.address32_hi
);
894 shader_debug_flags
|= (uint64_t)(sscreen
->info
.address32_hi
& 0xffff) << 32;
896 sscreen
->disk_shader_cache
=
897 disk_cache_create(sscreen
->info
.name
,
902 static void si_set_max_shader_compiler_threads(struct pipe_screen
*screen
,
903 unsigned max_threads
)
905 struct si_screen
*sscreen
= (struct si_screen
*)screen
;
907 /* This function doesn't allow a greater number of threads than
908 * the queue had at its creation. */
909 util_queue_adjust_num_threads(&sscreen
->shader_compiler_queue
,
911 /* Don't change the number of threads on the low priority queue. */
914 static bool si_is_parallel_shader_compilation_finished(struct pipe_screen
*screen
,
916 enum pipe_shader_type shader_type
)
918 struct si_shader_selector
*sel
= (struct si_shader_selector
*)shader
;
920 return util_queue_fence_is_signalled(&sel
->ready
);
923 static struct pipe_screen
*
924 radeonsi_screen_create_impl(struct radeon_winsys
*ws
,
925 const struct pipe_screen_config
*config
)
927 struct si_screen
*sscreen
= CALLOC_STRUCT(si_screen
);
928 unsigned hw_threads
, num_comp_hi_threads
, num_comp_lo_threads
, i
;
935 ws
->query_info(ws
, &sscreen
->info
);
937 if (sscreen
->info
.chip_class
== GFX10
&& HAVE_LLVM
< 0x0900) {
938 fprintf(stderr
, "radeonsi: Navi family support requires LLVM 9 or higher\n");
943 if (sscreen
->info
.chip_class
>= GFX9
) {
944 sscreen
->se_tile_repeat
= 32 * sscreen
->info
.max_se
;
946 ac_get_raster_config(&sscreen
->info
,
947 &sscreen
->pa_sc_raster_config
,
948 &sscreen
->pa_sc_raster_config_1
,
949 &sscreen
->se_tile_repeat
);
952 sscreen
->debug_flags
= debug_get_flags_option("R600_DEBUG",
954 sscreen
->debug_flags
|= debug_get_flags_option("AMD_DEBUG",
957 if (sscreen
->debug_flags
& DBG(NO_GFX
))
958 sscreen
->info
.has_graphics
= false;
960 /* Set functions first. */
961 sscreen
->b
.context_create
= si_pipe_create_context
;
962 sscreen
->b
.destroy
= si_destroy_screen
;
963 sscreen
->b
.set_max_shader_compiler_threads
=
964 si_set_max_shader_compiler_threads
;
965 sscreen
->b
.is_parallel_shader_compilation_finished
=
966 si_is_parallel_shader_compilation_finished
;
968 si_init_screen_get_functions(sscreen
);
969 si_init_screen_buffer_functions(sscreen
);
970 si_init_screen_fence_functions(sscreen
);
971 si_init_screen_state_functions(sscreen
);
972 si_init_screen_texture_functions(sscreen
);
973 si_init_screen_query_functions(sscreen
);
975 /* Set these flags in debug_flags early, so that the shader cache takes
978 if (driQueryOptionb(config
->options
,
979 "glsl_correct_derivatives_after_discard"))
980 sscreen
->debug_flags
|= DBG(FS_CORRECT_DERIVS_AFTER_KILL
);
981 if (driQueryOptionb(config
->options
, "radeonsi_enable_sisched"))
982 sscreen
->debug_flags
|= DBG(SI_SCHED
);
984 if (sscreen
->debug_flags
& DBG(INFO
))
985 ac_print_gpu_info(&sscreen
->info
);
987 slab_create_parent(&sscreen
->pool_transfers
,
988 sizeof(struct si_transfer
), 64);
990 sscreen
->force_aniso
= MIN2(16, debug_get_num_option("R600_TEX_ANISO", -1));
991 if (sscreen
->force_aniso
== -1) {
992 sscreen
->force_aniso
= MIN2(16, debug_get_num_option("AMD_TEX_ANISO", -1));
995 if (sscreen
->force_aniso
>= 0) {
996 printf("radeonsi: Forcing anisotropy filter to %ix\n",
997 /* round down to a power of two */
998 1 << util_logbase2(sscreen
->force_aniso
));
1001 (void) mtx_init(&sscreen
->aux_context_lock
, mtx_plain
);
1002 (void) mtx_init(&sscreen
->gpu_load_mutex
, mtx_plain
);
1004 si_init_gs_info(sscreen
);
1005 if (!si_init_shader_cache(sscreen
)) {
1010 si_disk_cache_create(sscreen
);
1012 /* Determine the number of shader compiler threads. */
1013 hw_threads
= sysconf(_SC_NPROCESSORS_ONLN
);
1015 if (hw_threads
>= 12) {
1016 num_comp_hi_threads
= hw_threads
* 3 / 4;
1017 num_comp_lo_threads
= hw_threads
/ 3;
1018 } else if (hw_threads
>= 6) {
1019 num_comp_hi_threads
= hw_threads
- 2;
1020 num_comp_lo_threads
= hw_threads
/ 2;
1021 } else if (hw_threads
>= 2) {
1022 num_comp_hi_threads
= hw_threads
- 1;
1023 num_comp_lo_threads
= hw_threads
/ 2;
1025 num_comp_hi_threads
= 1;
1026 num_comp_lo_threads
= 1;
1029 num_comp_hi_threads
= MIN2(num_comp_hi_threads
,
1030 ARRAY_SIZE(sscreen
->compiler
));
1031 num_comp_lo_threads
= MIN2(num_comp_lo_threads
,
1032 ARRAY_SIZE(sscreen
->compiler_lowp
));
1034 if (!util_queue_init(&sscreen
->shader_compiler_queue
, "sh",
1035 64, num_comp_hi_threads
,
1036 UTIL_QUEUE_INIT_RESIZE_IF_FULL
|
1037 UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY
)) {
1038 si_destroy_shader_cache(sscreen
);
1043 if (!util_queue_init(&sscreen
->shader_compiler_queue_low_priority
,
1045 64, num_comp_lo_threads
,
1046 UTIL_QUEUE_INIT_RESIZE_IF_FULL
|
1047 UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY
|
1048 UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY
)) {
1049 si_destroy_shader_cache(sscreen
);
1054 if (!debug_get_bool_option("RADEON_DISABLE_PERFCOUNTERS", false))
1055 si_init_perfcounters(sscreen
);
1057 /* Determine tessellation ring info. */
1058 bool double_offchip_buffers
= sscreen
->info
.chip_class
>= GFX7
&&
1059 sscreen
->info
.family
!= CHIP_CARRIZO
&&
1060 sscreen
->info
.family
!= CHIP_STONEY
;
1061 /* This must be one less than the maximum number due to a hw limitation.
1062 * Various hardware bugs need this.
1064 unsigned max_offchip_buffers_per_se
;
1066 if (sscreen
->info
.chip_class
>= GFX10
)
1067 max_offchip_buffers_per_se
= 256;
1068 /* Only certain chips can use the maximum value. */
1069 else if (sscreen
->info
.family
== CHIP_VEGA12
||
1070 sscreen
->info
.family
== CHIP_VEGA20
)
1071 max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1073 max_offchip_buffers_per_se
= double_offchip_buffers
? 127 : 63;
1075 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1076 sscreen
->info
.max_se
;
1077 unsigned offchip_granularity
;
1079 /* Hawaii has a bug with offchip buffers > 256 that can be worked
1080 * around by setting 4K granularity.
1082 if (sscreen
->info
.family
== CHIP_HAWAII
) {
1083 sscreen
->tess_offchip_block_dw_size
= 4096;
1084 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1086 sscreen
->tess_offchip_block_dw_size
= 8192;
1087 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1090 sscreen
->tess_factor_ring_size
= 32768 * sscreen
->info
.max_se
;
1091 assert(((sscreen
->tess_factor_ring_size
/ 4) & C_030938_SIZE
) == 0);
1092 sscreen
->tess_offchip_ring_size
= max_offchip_buffers
*
1093 sscreen
->tess_offchip_block_dw_size
* 4;
1095 if (sscreen
->info
.chip_class
>= GFX7
) {
1096 if (sscreen
->info
.chip_class
>= GFX8
)
1097 --max_offchip_buffers
;
1098 sscreen
->vgt_hs_offchip_param
=
1099 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1100 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1102 assert(offchip_granularity
== V_03093C_X_8K_DWORDS
);
1103 sscreen
->vgt_hs_offchip_param
=
1104 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1107 /* The mere presense of CLEAR_STATE in the IB causes random GPU hangs
1108 * on GFX6. Some CLEAR_STATE cause asic hang on radeon kernel, etc.
1109 * SPI_VS_OUT_CONFIG. So only enable GFX7 CLEAR_STATE on amdgpu kernel. */
1110 sscreen
->has_clear_state
= sscreen
->info
.chip_class
>= GFX7
&&
1111 sscreen
->info
.is_amdgpu
;
1113 sscreen
->has_distributed_tess
=
1114 sscreen
->info
.chip_class
>= GFX8
&&
1115 sscreen
->info
.max_se
>= 2;
1117 sscreen
->has_draw_indirect_multi
=
1118 (sscreen
->info
.family
>= CHIP_POLARIS10
) ||
1119 (sscreen
->info
.chip_class
== GFX8
&&
1120 sscreen
->info
.pfp_fw_version
>= 121 &&
1121 sscreen
->info
.me_fw_version
>= 87) ||
1122 (sscreen
->info
.chip_class
== GFX7
&&
1123 sscreen
->info
.pfp_fw_version
>= 211 &&
1124 sscreen
->info
.me_fw_version
>= 173) ||
1125 (sscreen
->info
.chip_class
== GFX6
&&
1126 sscreen
->info
.pfp_fw_version
>= 79 &&
1127 sscreen
->info
.me_fw_version
>= 142);
1129 sscreen
->has_out_of_order_rast
= sscreen
->info
.chip_class
>= GFX8
&&
1130 sscreen
->info
.max_se
>= 2 &&
1131 !(sscreen
->debug_flags
& DBG(NO_OUT_OF_ORDER
));
1132 sscreen
->assume_no_z_fights
=
1133 driQueryOptionb(config
->options
, "radeonsi_assume_no_z_fights");
1134 sscreen
->commutative_blend_add
=
1135 driQueryOptionb(config
->options
, "radeonsi_commutative_blend_add");
1138 #define OPT_BOOL(name, dflt, description) \
1139 sscreen->options.name = \
1140 driQueryOptionb(config->options, "radeonsi_"#name);
1141 #include "si_debug_options.h"
1144 sscreen
->has_gfx9_scissor_bug
= sscreen
->info
.family
== CHIP_VEGA10
||
1145 sscreen
->info
.family
== CHIP_RAVEN
;
1146 sscreen
->has_msaa_sample_loc_bug
= (sscreen
->info
.family
>= CHIP_POLARIS10
&&
1147 sscreen
->info
.family
<= CHIP_POLARIS12
) ||
1148 sscreen
->info
.family
== CHIP_VEGA10
||
1149 sscreen
->info
.family
== CHIP_RAVEN
;
1150 sscreen
->has_ls_vgpr_init_bug
= sscreen
->info
.family
== CHIP_VEGA10
||
1151 sscreen
->info
.family
== CHIP_RAVEN
;
1152 sscreen
->has_dcc_constant_encode
= sscreen
->info
.family
== CHIP_RAVEN2
||
1153 sscreen
->info
.family
== CHIP_RENOIR
||
1154 sscreen
->info
.chip_class
>= GFX10
;
1155 sscreen
->use_ngg
= sscreen
->info
.chip_class
>= GFX10
;
1156 sscreen
->use_ngg_streamout
= sscreen
->info
.chip_class
>= GFX10
;
1158 /* Only enable primitive binning on APUs by default. */
1159 if (sscreen
->info
.chip_class
>= GFX10
) {
1160 sscreen
->dpbb_allowed
= true;
1161 sscreen
->dfsm_allowed
= !sscreen
->info
.has_dedicated_vram
;
1162 } else if (sscreen
->info
.chip_class
== GFX9
) {
1163 sscreen
->dpbb_allowed
= !sscreen
->info
.has_dedicated_vram
;
1164 sscreen
->dfsm_allowed
= !sscreen
->info
.has_dedicated_vram
;
1167 /* Process DPBB enable flags. */
1168 if (sscreen
->debug_flags
& DBG(DPBB
)) {
1169 sscreen
->dpbb_allowed
= true;
1170 if (sscreen
->debug_flags
& DBG(DFSM
))
1171 sscreen
->dfsm_allowed
= true;
1174 /* Process DPBB disable flags. */
1175 if (sscreen
->debug_flags
& DBG(NO_DPBB
)) {
1176 sscreen
->dpbb_allowed
= false;
1177 sscreen
->dfsm_allowed
= false;
1178 } else if (sscreen
->debug_flags
& DBG(NO_DFSM
)) {
1179 sscreen
->dfsm_allowed
= false;
1182 /* While it would be nice not to have this flag, we are constrained
1183 * by the reality that LLVM 9.0 has buggy VGPR indexing on GFX9.
1185 sscreen
->llvm_has_working_vgpr_indexing
= sscreen
->info
.chip_class
!= GFX9
;
1187 /* Some chips have RB+ registers, but don't support RB+. Those must
1188 * always disable it.
1190 if (sscreen
->info
.family
== CHIP_STONEY
||
1191 sscreen
->info
.chip_class
>= GFX9
) {
1192 sscreen
->has_rbplus
= true;
1194 sscreen
->rbplus_allowed
=
1195 !(sscreen
->debug_flags
& DBG(NO_RB_PLUS
)) &&
1196 (sscreen
->info
.family
== CHIP_STONEY
||
1197 sscreen
->info
.family
== CHIP_VEGA12
||
1198 sscreen
->info
.family
== CHIP_RAVEN
||
1199 sscreen
->info
.family
== CHIP_RAVEN2
||
1200 sscreen
->info
.family
== CHIP_RENOIR
);
1203 sscreen
->dcc_msaa_allowed
=
1204 !(sscreen
->debug_flags
& DBG(NO_DCC_MSAA
));
1206 sscreen
->cpdma_prefetch_writes_memory
= sscreen
->info
.chip_class
<= GFX8
;
1208 (void) mtx_init(&sscreen
->shader_parts_mutex
, mtx_plain
);
1209 sscreen
->use_monolithic_shaders
=
1210 (sscreen
->debug_flags
& DBG(MONOLITHIC_SHADERS
)) != 0;
1212 sscreen
->barrier_flags
.cp_to_L2
= SI_CONTEXT_INV_SCACHE
|
1213 SI_CONTEXT_INV_VCACHE
;
1214 if (sscreen
->info
.chip_class
<= GFX8
) {
1215 sscreen
->barrier_flags
.cp_to_L2
|= SI_CONTEXT_INV_L2
;
1216 sscreen
->barrier_flags
.L2_to_cp
|= SI_CONTEXT_WB_L2
;
1219 if (debug_get_bool_option("RADEON_DUMP_SHADERS", false))
1220 sscreen
->debug_flags
|= DBG_ALL_SHADERS
;
1227 * That means 8 coverage samples, 4 Z/S samples, and 2 color samples.
1229 * s >= z >= c (ignoring this only wastes memory)
1234 * Only MSAA color and depth buffers are overriden.
1236 if (sscreen
->info
.has_eqaa_surface_allocator
) {
1237 const char *eqaa
= debug_get_option("EQAA", NULL
);
1240 if (eqaa
&& sscanf(eqaa
, "%u,%u,%u", &s
, &z
, &f
) == 3 && s
&& z
&& f
) {
1241 sscreen
->eqaa_force_coverage_samples
= s
;
1242 sscreen
->eqaa_force_z_samples
= z
;
1243 sscreen
->eqaa_force_color_samples
= f
;
1247 for (i
= 0; i
< num_comp_hi_threads
; i
++)
1248 si_init_compiler(sscreen
, &sscreen
->compiler
[i
]);
1249 for (i
= 0; i
< num_comp_lo_threads
; i
++)
1250 si_init_compiler(sscreen
, &sscreen
->compiler_lowp
[i
]);
1252 sscreen
->ge_wave_size
= 64;
1253 sscreen
->ps_wave_size
= 64;
1254 sscreen
->compute_wave_size
= 64;
1256 if (sscreen
->info
.chip_class
>= GFX10
) {
1257 /* Pixels shaders: Wave64 is recommended.
1258 * Compute shaders: There are piglit failures with Wave32.
1260 sscreen
->ge_wave_size
= 32;
1262 if (sscreen
->debug_flags
& DBG(W32_GE
))
1263 sscreen
->ge_wave_size
= 32;
1264 if (sscreen
->debug_flags
& DBG(W32_PS
))
1265 sscreen
->ps_wave_size
= 32;
1266 if (sscreen
->debug_flags
& DBG(W32_CS
))
1267 sscreen
->compute_wave_size
= 32;
1269 if (sscreen
->debug_flags
& DBG(W64_GE
))
1270 sscreen
->ge_wave_size
= 64;
1271 if (sscreen
->debug_flags
& DBG(W64_PS
))
1272 sscreen
->ps_wave_size
= 64;
1273 if (sscreen
->debug_flags
& DBG(W64_CS
))
1274 sscreen
->compute_wave_size
= 64;
1277 /* Create the auxiliary context. This must be done last. */
1278 sscreen
->aux_context
= si_create_context(&sscreen
->b
,
1279 (sscreen
->options
.aux_debug
? PIPE_CONTEXT_DEBUG
: 0) |
1280 (sscreen
->info
.has_graphics
? 0 : PIPE_CONTEXT_COMPUTE_ONLY
));
1281 if (sscreen
->options
.aux_debug
) {
1282 struct u_log_context
*log
= CALLOC_STRUCT(u_log_context
);
1283 u_log_context_init(log
);
1284 sscreen
->aux_context
->set_log_context(sscreen
->aux_context
, log
);
1287 if (sscreen
->debug_flags
& DBG(TEST_DMA
))
1288 si_test_dma(sscreen
);
1290 if (sscreen
->debug_flags
& DBG(TEST_DMA_PERF
)) {
1291 si_test_dma_perf(sscreen
);
1294 if (sscreen
->debug_flags
& (DBG(TEST_VMFAULT_CP
) |
1295 DBG(TEST_VMFAULT_SDMA
) |
1296 DBG(TEST_VMFAULT_SHADER
)))
1297 si_test_vmfault(sscreen
);
1299 if (sscreen
->debug_flags
& DBG(TEST_GDS
))
1300 si_test_gds((struct si_context
*)sscreen
->aux_context
);
1302 if (sscreen
->debug_flags
& DBG(TEST_GDS_MM
)) {
1303 si_test_gds_memory_management((struct si_context
*)sscreen
->aux_context
,
1304 32 * 1024, 4, RADEON_DOMAIN_GDS
);
1306 if (sscreen
->debug_flags
& DBG(TEST_GDS_OA_MM
)) {
1307 si_test_gds_memory_management((struct si_context
*)sscreen
->aux_context
,
1308 4, 1, RADEON_DOMAIN_OA
);
1314 struct pipe_screen
*radeonsi_screen_create(int fd
, const struct pipe_screen_config
*config
)
1316 drmVersionPtr version
= drmGetVersion(fd
);
1317 struct radeon_winsys
*rw
= NULL
;
1319 switch (version
->version_major
) {
1321 rw
= radeon_drm_winsys_create(fd
, config
, radeonsi_screen_create_impl
);
1324 rw
= amdgpu_winsys_create(fd
, config
, radeonsi_screen_create_impl
);
1328 drmFreeVersion(version
);
1329 return rw
? rw
->screen
: NULL
;