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 #include <llvm/Config/llvm-config.h>
50 static const struct debug_named_value debug_options
[] = {
51 /* Shader logging options: */
52 { "vs", DBG(VS
), "Print vertex shaders" },
53 { "ps", DBG(PS
), "Print pixel shaders" },
54 { "gs", DBG(GS
), "Print geometry shaders" },
55 { "tcs", DBG(TCS
), "Print tessellation control shaders" },
56 { "tes", DBG(TES
), "Print tessellation evaluation shaders" },
57 { "cs", DBG(CS
), "Print compute shaders" },
58 { "noir", DBG(NO_IR
), "Don't print the LLVM IR"},
59 { "notgsi", DBG(NO_TGSI
), "Don't print the TGSI"},
60 { "noasm", DBG(NO_ASM
), "Don't print disassembled shaders"},
61 { "preoptir", DBG(PREOPT_IR
), "Print the LLVM IR before initial optimizations" },
63 /* Shader compiler options the shader cache should be aware of: */
64 { "sisched", DBG(SI_SCHED
), "Enable LLVM SI Machine Instruction Scheduler." },
65 { "gisel", DBG(GISEL
), "Enable LLVM global instruction selector." },
66 { "w32ge", DBG(W32_GE
), "Use Wave32 for vertex, tessellation, and geometry shaders." },
67 { "w32ps", DBG(W32_PS
), "Use Wave32 for pixel shaders." },
68 { "w32cs", DBG(W32_CS
), "Use Wave32 for computes shaders." },
69 { "w64ge", DBG(W64_GE
), "Use Wave64 for vertex, tessellation, and geometry shaders." },
70 { "w64ps", DBG(W64_PS
), "Use Wave64 for pixel shaders." },
71 { "w64cs", DBG(W64_CS
), "Use Wave64 for computes shaders." },
73 /* Shader compiler options (with no effect on the shader cache): */
74 { "checkir", DBG(CHECK_IR
), "Enable additional sanity checks on shader IR" },
75 { "mono", DBG(MONOLITHIC_SHADERS
), "Use old-style monolithic shaders compiled on demand" },
76 { "nooptvariant", DBG(NO_OPT_VARIANT
), "Disable compiling optimized shader variants." },
78 /* Information logging options: */
79 { "info", DBG(INFO
), "Print driver information" },
80 { "tex", DBG(TEX
), "Print texture info" },
81 { "compute", DBG(COMPUTE
), "Print compute info" },
82 { "vm", DBG(VM
), "Print virtual addresses when creating resources" },
85 { "forcedma", DBG(FORCE_DMA
), "Use asynchronous DMA for all operations when possible." },
86 { "nodma", DBG(NO_ASYNC_DMA
), "Disable asynchronous DMA" },
87 { "nowc", DBG(NO_WC
), "Disable GTT write combining" },
88 { "check_vm", DBG(CHECK_VM
), "Check VM faults and dump debug info." },
89 { "reserve_vmid", DBG(RESERVE_VMID
), "Force VMID reservation per context." },
90 { "zerovram", DBG(ZERO_VRAM
), "Clear VRAM allocations." },
92 /* 3D engine options: */
93 { "nogfx", DBG(NO_GFX
), "Disable graphics. Only multimedia compute paths can be used." },
94 { "nongg", DBG(NO_NGG
), "Disable NGG and use the legacy pipeline." },
95 { "alwayspd", DBG(ALWAYS_PD
), "Always enable the primitive discard compute shader." },
96 { "pd", DBG(PD
), "Enable the primitive discard compute shader for large draw calls." },
97 { "nopd", DBG(NO_PD
), "Disable the primitive discard compute shader." },
98 { "switch_on_eop", DBG(SWITCH_ON_EOP
), "Program WD/IA to switch on end-of-packet." },
99 { "nooutoforder", DBG(NO_OUT_OF_ORDER
), "Disable out-of-order rasterization" },
100 { "nodpbb", DBG(NO_DPBB
), "Disable DPBB." },
101 { "nodfsm", DBG(NO_DFSM
), "Disable DFSM." },
102 { "dpbb", DBG(DPBB
), "Enable DPBB." },
103 { "dfsm", DBG(DFSM
), "Enable DFSM." },
104 { "nohyperz", DBG(NO_HYPERZ
), "Disable Hyper-Z" },
105 { "norbplus", DBG(NO_RB_PLUS
), "Disable RB+." },
106 { "no2d", DBG(NO_2D_TILING
), "Disable 2D tiling" },
107 { "notiling", DBG(NO_TILING
), "Disable tiling" },
108 { "nodcc", DBG(NO_DCC
), "Disable DCC." },
109 { "nodccclear", DBG(NO_DCC_CLEAR
), "Disable DCC fast clear." },
110 { "nodccfb", DBG(NO_DCC_FB
), "Disable separate DCC on the main framebuffer" },
111 { "nodccmsaa", DBG(NO_DCC_MSAA
), "Disable DCC for MSAA" },
112 { "nofmask", DBG(NO_FMASK
), "Disable MSAA compression" },
115 { "testdma", DBG(TEST_DMA
), "Invoke SDMA tests and exit." },
116 { "testvmfaultcp", DBG(TEST_VMFAULT_CP
), "Invoke a CP VM fault test and exit." },
117 { "testvmfaultsdma", DBG(TEST_VMFAULT_SDMA
), "Invoke a SDMA VM fault test and exit." },
118 { "testvmfaultshader", DBG(TEST_VMFAULT_SHADER
), "Invoke a shader VM fault test and exit." },
119 { "testdmaperf", DBG(TEST_DMA_PERF
), "Test DMA performance" },
120 { "testgds", DBG(TEST_GDS
), "Test GDS." },
121 { "testgdsmm", DBG(TEST_GDS_MM
), "Test GDS memory management." },
122 { "testgdsoamm", DBG(TEST_GDS_OA_MM
), "Test GDS OA memory management." },
124 DEBUG_NAMED_VALUE_END
/* must be last */
127 static void si_init_compiler(struct si_screen
*sscreen
,
128 struct ac_llvm_compiler
*compiler
)
130 /* Only create the less-optimizing version of the compiler on APUs
131 * predating Ryzen (Raven). */
132 bool create_low_opt_compiler
= !sscreen
->info
.has_dedicated_vram
&&
133 sscreen
->info
.chip_class
<= GFX8
;
135 enum ac_target_machine_options tm_options
=
136 (sscreen
->debug_flags
& DBG(SI_SCHED
) ? AC_TM_SISCHED
: 0) |
137 (sscreen
->debug_flags
& DBG(GISEL
) ? AC_TM_ENABLE_GLOBAL_ISEL
: 0) |
138 (sscreen
->info
.chip_class
>= GFX9
? AC_TM_FORCE_ENABLE_XNACK
: 0) |
139 (sscreen
->info
.chip_class
< GFX9
? AC_TM_FORCE_DISABLE_XNACK
: 0) |
140 (!sscreen
->llvm_has_working_vgpr_indexing
? AC_TM_PROMOTE_ALLOCA_TO_SCRATCH
: 0) |
141 (sscreen
->debug_flags
& DBG(CHECK_IR
) ? AC_TM_CHECK_IR
: 0) |
142 (create_low_opt_compiler
? AC_TM_CREATE_LOW_OPT
: 0);
145 ac_init_llvm_compiler(compiler
, sscreen
->info
.family
, tm_options
);
146 compiler
->passes
= ac_create_llvm_passes(compiler
->tm
);
148 if (compiler
->tm_wave32
)
149 compiler
->passes_wave32
= ac_create_llvm_passes(compiler
->tm_wave32
);
150 if (compiler
->low_opt_tm
)
151 compiler
->low_opt_passes
= ac_create_llvm_passes(compiler
->low_opt_tm
);
154 static void si_destroy_compiler(struct ac_llvm_compiler
*compiler
)
156 ac_destroy_llvm_compiler(compiler
);
162 static void si_destroy_context(struct pipe_context
*context
)
164 struct si_context
*sctx
= (struct si_context
*)context
;
167 util_queue_finish(&sctx
->screen
->shader_compiler_queue
);
168 util_queue_finish(&sctx
->screen
->shader_compiler_queue_low_priority
);
170 /* Unreference the framebuffer normally to disable related logic
173 struct pipe_framebuffer_state fb
= {};
174 if (context
->set_framebuffer_state
)
175 context
->set_framebuffer_state(context
, &fb
);
177 si_release_all_descriptors(sctx
);
179 if (sctx
->chip_class
>= GFX10
)
180 gfx10_destroy_query(sctx
);
182 pipe_resource_reference(&sctx
->esgs_ring
, NULL
);
183 pipe_resource_reference(&sctx
->gsvs_ring
, NULL
);
184 pipe_resource_reference(&sctx
->tess_rings
, NULL
);
185 pipe_resource_reference(&sctx
->null_const_buf
.buffer
, NULL
);
186 pipe_resource_reference(&sctx
->sample_pos_buffer
, NULL
);
187 si_resource_reference(&sctx
->border_color_buffer
, NULL
);
188 free(sctx
->border_color_table
);
189 si_resource_reference(&sctx
->scratch_buffer
, NULL
);
190 si_resource_reference(&sctx
->compute_scratch_buffer
, NULL
);
191 si_resource_reference(&sctx
->wait_mem_scratch
, NULL
);
193 si_pm4_free_state(sctx
, sctx
->init_config
, ~0);
194 if (sctx
->init_config_gs_rings
)
195 si_pm4_free_state(sctx
, sctx
->init_config_gs_rings
, ~0);
196 for (i
= 0; i
< ARRAY_SIZE(sctx
->vgt_shader_config
); i
++)
197 si_pm4_delete_state(sctx
, vgt_shader_config
, sctx
->vgt_shader_config
[i
]);
199 if (sctx
->fixed_func_tcs_shader
.cso
)
200 sctx
->b
.delete_tcs_state(&sctx
->b
, sctx
->fixed_func_tcs_shader
.cso
);
201 if (sctx
->custom_dsa_flush
)
202 sctx
->b
.delete_depth_stencil_alpha_state(&sctx
->b
, sctx
->custom_dsa_flush
);
203 if (sctx
->custom_blend_resolve
)
204 sctx
->b
.delete_blend_state(&sctx
->b
, sctx
->custom_blend_resolve
);
205 if (sctx
->custom_blend_fmask_decompress
)
206 sctx
->b
.delete_blend_state(&sctx
->b
, sctx
->custom_blend_fmask_decompress
);
207 if (sctx
->custom_blend_eliminate_fastclear
)
208 sctx
->b
.delete_blend_state(&sctx
->b
, sctx
->custom_blend_eliminate_fastclear
);
209 if (sctx
->custom_blend_dcc_decompress
)
210 sctx
->b
.delete_blend_state(&sctx
->b
, sctx
->custom_blend_dcc_decompress
);
211 if (sctx
->vs_blit_pos
)
212 sctx
->b
.delete_vs_state(&sctx
->b
, sctx
->vs_blit_pos
);
213 if (sctx
->vs_blit_pos_layered
)
214 sctx
->b
.delete_vs_state(&sctx
->b
, sctx
->vs_blit_pos_layered
);
215 if (sctx
->vs_blit_color
)
216 sctx
->b
.delete_vs_state(&sctx
->b
, sctx
->vs_blit_color
);
217 if (sctx
->vs_blit_color_layered
)
218 sctx
->b
.delete_vs_state(&sctx
->b
, sctx
->vs_blit_color_layered
);
219 if (sctx
->vs_blit_texcoord
)
220 sctx
->b
.delete_vs_state(&sctx
->b
, sctx
->vs_blit_texcoord
);
221 if (sctx
->cs_clear_buffer
)
222 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_clear_buffer
);
223 if (sctx
->cs_copy_buffer
)
224 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_copy_buffer
);
225 if (sctx
->cs_copy_image
)
226 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_copy_image
);
227 if (sctx
->cs_copy_image_1d_array
)
228 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_copy_image_1d_array
);
229 if (sctx
->cs_clear_render_target
)
230 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_clear_render_target
);
231 if (sctx
->cs_clear_render_target_1d_array
)
232 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_clear_render_target_1d_array
);
233 if (sctx
->cs_dcc_retile
)
234 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->cs_dcc_retile
);
237 util_blitter_destroy(sctx
->blitter
);
239 /* Release DCC stats. */
240 for (int i
= 0; i
< ARRAY_SIZE(sctx
->dcc_stats
); i
++) {
241 assert(!sctx
->dcc_stats
[i
].query_active
);
243 for (int j
= 0; j
< ARRAY_SIZE(sctx
->dcc_stats
[i
].ps_stats
); j
++)
244 if (sctx
->dcc_stats
[i
].ps_stats
[j
])
245 sctx
->b
.destroy_query(&sctx
->b
,
246 sctx
->dcc_stats
[i
].ps_stats
[j
]);
248 si_texture_reference(&sctx
->dcc_stats
[i
].tex
, NULL
);
251 if (sctx
->query_result_shader
)
252 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->query_result_shader
);
253 if (sctx
->sh_query_result_shader
)
254 sctx
->b
.delete_compute_state(&sctx
->b
, sctx
->sh_query_result_shader
);
257 sctx
->ws
->cs_destroy(sctx
->gfx_cs
);
259 sctx
->ws
->cs_destroy(sctx
->dma_cs
);
261 sctx
->ws
->ctx_destroy(sctx
->ctx
);
263 if (sctx
->b
.stream_uploader
)
264 u_upload_destroy(sctx
->b
.stream_uploader
);
265 if (sctx
->b
.const_uploader
)
266 u_upload_destroy(sctx
->b
.const_uploader
);
267 if (sctx
->cached_gtt_allocator
)
268 u_upload_destroy(sctx
->cached_gtt_allocator
);
270 slab_destroy_child(&sctx
->pool_transfers
);
271 slab_destroy_child(&sctx
->pool_transfers_unsync
);
273 if (sctx
->allocator_zeroed_memory
)
274 u_suballocator_destroy(sctx
->allocator_zeroed_memory
);
276 sctx
->ws
->fence_reference(&sctx
->last_gfx_fence
, NULL
);
277 sctx
->ws
->fence_reference(&sctx
->last_sdma_fence
, NULL
);
278 sctx
->ws
->fence_reference(&sctx
->last_ib_barrier_fence
, NULL
);
279 si_resource_reference(&sctx
->eop_bug_scratch
, NULL
);
280 si_resource_reference(&sctx
->index_ring
, NULL
);
281 si_resource_reference(&sctx
->barrier_buf
, NULL
);
282 si_resource_reference(&sctx
->last_ib_barrier_buf
, NULL
);
283 pb_reference(&sctx
->gds
, NULL
);
284 pb_reference(&sctx
->gds_oa
, NULL
);
286 si_destroy_compiler(&sctx
->compiler
);
288 si_saved_cs_reference(&sctx
->current_saved_cs
, NULL
);
290 _mesa_hash_table_destroy(sctx
->tex_handles
, NULL
);
291 _mesa_hash_table_destroy(sctx
->img_handles
, NULL
);
293 util_dynarray_fini(&sctx
->resident_tex_handles
);
294 util_dynarray_fini(&sctx
->resident_img_handles
);
295 util_dynarray_fini(&sctx
->resident_tex_needs_color_decompress
);
296 util_dynarray_fini(&sctx
->resident_img_needs_color_decompress
);
297 util_dynarray_fini(&sctx
->resident_tex_needs_depth_decompress
);
298 si_unref_sdma_uploads(sctx
);
299 free(sctx
->sdma_uploads
);
303 static enum pipe_reset_status
si_get_reset_status(struct pipe_context
*ctx
)
305 struct si_context
*sctx
= (struct si_context
*)ctx
;
307 return sctx
->ws
->ctx_query_reset_status(sctx
->ctx
);
310 static void si_set_device_reset_callback(struct pipe_context
*ctx
,
311 const struct pipe_device_reset_callback
*cb
)
313 struct si_context
*sctx
= (struct si_context
*)ctx
;
316 sctx
->device_reset_callback
= *cb
;
318 memset(&sctx
->device_reset_callback
, 0,
319 sizeof(sctx
->device_reset_callback
));
322 bool si_check_device_reset(struct si_context
*sctx
)
324 enum pipe_reset_status status
;
326 if (!sctx
->device_reset_callback
.reset
)
329 status
= sctx
->ws
->ctx_query_reset_status(sctx
->ctx
);
330 if (status
== PIPE_NO_RESET
)
333 sctx
->device_reset_callback
.reset(sctx
->device_reset_callback
.data
, status
);
337 /* Apitrace profiling:
338 * 1) qapitrace : Tools -> Profile: Measure CPU & GPU times
339 * 2) In the middle panel, zoom in (mouse wheel) on some bad draw call
340 * and remember its number.
341 * 3) In Mesa, enable queries and performance counters around that draw
342 * call and print the results.
343 * 4) glretrace --benchmark --markers ..
345 static void si_emit_string_marker(struct pipe_context
*ctx
,
346 const char *string
, int len
)
348 struct si_context
*sctx
= (struct si_context
*)ctx
;
350 dd_parse_apitrace_marker(string
, len
, &sctx
->apitrace_call_number
);
353 u_log_printf(sctx
->log
, "\nString marker: %*s\n", len
, string
);
356 static void si_set_debug_callback(struct pipe_context
*ctx
,
357 const struct pipe_debug_callback
*cb
)
359 struct si_context
*sctx
= (struct si_context
*)ctx
;
360 struct si_screen
*screen
= sctx
->screen
;
362 util_queue_finish(&screen
->shader_compiler_queue
);
363 util_queue_finish(&screen
->shader_compiler_queue_low_priority
);
368 memset(&sctx
->debug
, 0, sizeof(sctx
->debug
));
371 static void si_set_log_context(struct pipe_context
*ctx
,
372 struct u_log_context
*log
)
374 struct si_context
*sctx
= (struct si_context
*)ctx
;
378 u_log_add_auto_logger(log
, si_auto_log_cs
, sctx
);
381 static void si_set_context_param(struct pipe_context
*ctx
,
382 enum pipe_context_param param
,
385 struct radeon_winsys
*ws
= ((struct si_context
*)ctx
)->ws
;
388 case PIPE_CONTEXT_PARAM_PIN_THREADS_TO_L3_CACHE
:
389 ws
->pin_threads_to_L3_cache(ws
, value
);
395 static struct pipe_context
*si_create_context(struct pipe_screen
*screen
,
398 struct si_screen
* sscreen
= (struct si_screen
*)screen
;
400 /* Don't create a context if it's not compute-only and hw is compute-only. */
401 if (!sscreen
->info
.has_graphics
&&
402 !(flags
& PIPE_CONTEXT_COMPUTE_ONLY
))
405 struct si_context
*sctx
= CALLOC_STRUCT(si_context
);
406 struct radeon_winsys
*ws
= sscreen
->ws
;
408 bool stop_exec_on_failure
= (flags
& PIPE_CONTEXT_LOSE_CONTEXT_ON_RESET
) != 0;
413 sctx
->has_graphics
= sscreen
->info
.chip_class
== GFX6
||
414 !(flags
& PIPE_CONTEXT_COMPUTE_ONLY
);
416 if (flags
& PIPE_CONTEXT_DEBUG
)
417 sscreen
->record_llvm_ir
= true; /* racy but not critical */
419 sctx
->b
.screen
= screen
; /* this must be set first */
421 sctx
->b
.destroy
= si_destroy_context
;
422 sctx
->screen
= sscreen
; /* Easy accessing of screen/winsys. */
423 sctx
->is_debug
= (flags
& PIPE_CONTEXT_DEBUG
) != 0;
425 slab_create_child(&sctx
->pool_transfers
, &sscreen
->pool_transfers
);
426 slab_create_child(&sctx
->pool_transfers_unsync
, &sscreen
->pool_transfers
);
428 sctx
->ws
= sscreen
->ws
;
429 sctx
->family
= sscreen
->info
.family
;
430 sctx
->chip_class
= sscreen
->info
.chip_class
;
432 if (sctx
->chip_class
== GFX7
||
433 sctx
->chip_class
== GFX8
||
434 sctx
->chip_class
== GFX9
) {
435 sctx
->eop_bug_scratch
= si_resource(
436 pipe_buffer_create(&sscreen
->b
, 0, PIPE_USAGE_DEFAULT
,
437 16 * sscreen
->info
.num_render_backends
));
438 if (!sctx
->eop_bug_scratch
)
442 /* Initialize context allocators. */
443 sctx
->allocator_zeroed_memory
=
444 u_suballocator_create(&sctx
->b
, 128 * 1024,
445 0, PIPE_USAGE_DEFAULT
,
446 SI_RESOURCE_FLAG_UNMAPPABLE
|
447 SI_RESOURCE_FLAG_CLEAR
, false);
448 if (!sctx
->allocator_zeroed_memory
)
451 sctx
->b
.stream_uploader
= u_upload_create(&sctx
->b
, 1024 * 1024,
452 0, PIPE_USAGE_STREAM
,
453 SI_RESOURCE_FLAG_READ_ONLY
);
454 if (!sctx
->b
.stream_uploader
)
457 sctx
->cached_gtt_allocator
= u_upload_create(&sctx
->b
, 16 * 1024,
458 0, PIPE_USAGE_STAGING
, 0);
459 if (!sctx
->cached_gtt_allocator
)
462 sctx
->ctx
= sctx
->ws
->ctx_create(sctx
->ws
);
466 if (sscreen
->info
.num_sdma_rings
&& !(sscreen
->debug_flags
& DBG(NO_ASYNC_DMA
))) {
467 sctx
->dma_cs
= sctx
->ws
->cs_create(sctx
->ctx
, RING_DMA
,
468 (void*)si_flush_dma_cs
,
469 sctx
, stop_exec_on_failure
);
472 bool use_sdma_upload
= sscreen
->info
.has_dedicated_vram
&& sctx
->dma_cs
;
473 sctx
->b
.const_uploader
= u_upload_create(&sctx
->b
, 256 * 1024,
474 0, PIPE_USAGE_DEFAULT
,
475 SI_RESOURCE_FLAG_32BIT
|
477 SI_RESOURCE_FLAG_UPLOAD_FLUSH_EXPLICIT_VIA_SDMA
: 0));
478 if (!sctx
->b
.const_uploader
)
482 u_upload_enable_flush_explicit(sctx
->b
.const_uploader
);
484 sctx
->gfx_cs
= ws
->cs_create(sctx
->ctx
,
485 sctx
->has_graphics
? RING_GFX
: RING_COMPUTE
,
486 (void*)si_flush_gfx_cs
, sctx
, stop_exec_on_failure
);
489 sctx
->border_color_table
= malloc(SI_MAX_BORDER_COLORS
*
490 sizeof(*sctx
->border_color_table
));
491 if (!sctx
->border_color_table
)
494 sctx
->border_color_buffer
= si_resource(
495 pipe_buffer_create(screen
, 0, PIPE_USAGE_DEFAULT
,
496 SI_MAX_BORDER_COLORS
*
497 sizeof(*sctx
->border_color_table
)));
498 if (!sctx
->border_color_buffer
)
501 sctx
->border_color_map
=
502 ws
->buffer_map(sctx
->border_color_buffer
->buf
,
503 NULL
, PIPE_TRANSFER_WRITE
);
504 if (!sctx
->border_color_map
)
507 sctx
->ngg
= sscreen
->use_ngg
;
509 /* Initialize context functions used by graphics and compute. */
510 if (sctx
->chip_class
>= GFX10
)
511 sctx
->emit_cache_flush
= gfx10_emit_cache_flush
;
513 sctx
->emit_cache_flush
= si_emit_cache_flush
;
515 sctx
->b
.emit_string_marker
= si_emit_string_marker
;
516 sctx
->b
.set_debug_callback
= si_set_debug_callback
;
517 sctx
->b
.set_log_context
= si_set_log_context
;
518 sctx
->b
.set_context_param
= si_set_context_param
;
519 sctx
->b
.get_device_reset_status
= si_get_reset_status
;
520 sctx
->b
.set_device_reset_callback
= si_set_device_reset_callback
;
522 si_init_all_descriptors(sctx
);
523 si_init_buffer_functions(sctx
);
524 si_init_clear_functions(sctx
);
525 si_init_blit_functions(sctx
);
526 si_init_compute_functions(sctx
);
527 si_init_compute_blit_functions(sctx
);
528 si_init_debug_functions(sctx
);
529 si_init_fence_functions(sctx
);
530 si_init_query_functions(sctx
);
531 si_init_state_compute_functions(sctx
);
532 si_init_context_texture_functions(sctx
);
534 /* Initialize graphics-only context functions. */
535 if (sctx
->has_graphics
) {
536 if (sctx
->chip_class
>= GFX10
)
537 gfx10_init_query(sctx
);
538 si_init_msaa_functions(sctx
);
539 si_init_shader_functions(sctx
);
540 si_init_state_functions(sctx
);
541 si_init_streamout_functions(sctx
);
542 si_init_viewport_functions(sctx
);
544 sctx
->blitter
= util_blitter_create(&sctx
->b
);
545 if (sctx
->blitter
== NULL
)
547 sctx
->blitter
->skip_viewport_restore
= true;
549 /* Some states are expected to be always non-NULL. */
550 sctx
->noop_blend
= util_blitter_get_noop_blend_state(sctx
->blitter
);
551 sctx
->queued
.named
.blend
= sctx
->noop_blend
;
553 sctx
->noop_dsa
= util_blitter_get_noop_dsa_state(sctx
->blitter
);
554 sctx
->queued
.named
.dsa
= sctx
->noop_dsa
;
556 sctx
->discard_rasterizer_state
=
557 util_blitter_get_discard_rasterizer_state(sctx
->blitter
);
558 sctx
->queued
.named
.rasterizer
= sctx
->discard_rasterizer_state
;
560 si_init_draw_functions(sctx
);
561 si_initialize_prim_discard_tunables(sctx
);
564 /* Initialize SDMA functions. */
565 if (sctx
->chip_class
>= GFX7
)
566 cik_init_sdma_functions(sctx
);
568 si_init_dma_functions(sctx
);
570 if (sscreen
->debug_flags
& DBG(FORCE_DMA
))
571 sctx
->b
.resource_copy_region
= sctx
->dma_copy
;
573 sctx
->sample_mask
= 0xffff;
575 /* Initialize multimedia functions. */
576 if (sscreen
->info
.has_hw_decode
) {
577 sctx
->b
.create_video_codec
= si_uvd_create_decoder
;
578 sctx
->b
.create_video_buffer
= si_video_buffer_create
;
580 sctx
->b
.create_video_codec
= vl_create_decoder
;
581 sctx
->b
.create_video_buffer
= vl_video_buffer_create
;
584 if (sctx
->chip_class
>= GFX9
) {
585 sctx
->wait_mem_scratch
= si_resource(
586 pipe_buffer_create(screen
, 0, PIPE_USAGE_DEFAULT
, 8));
587 if (!sctx
->wait_mem_scratch
)
590 /* Initialize the memory. */
591 si_cp_write_data(sctx
, sctx
->wait_mem_scratch
, 0, 4,
592 V_370_MEM
, V_370_ME
, &sctx
->wait_mem_number
);
595 /* GFX7 cannot unbind a constant buffer (S_BUFFER_LOAD doesn't skip loads
596 * if NUM_RECORDS == 0). We need to use a dummy buffer instead. */
597 if (sctx
->chip_class
== GFX7
) {
598 sctx
->null_const_buf
.buffer
=
599 pipe_aligned_buffer_create(screen
,
600 SI_RESOURCE_FLAG_32BIT
,
601 PIPE_USAGE_DEFAULT
, 16,
602 sctx
->screen
->info
.tcc_cache_line_size
);
603 if (!sctx
->null_const_buf
.buffer
)
605 sctx
->null_const_buf
.buffer_size
= sctx
->null_const_buf
.buffer
->width0
;
607 unsigned start_shader
= sctx
->has_graphics
? 0 : PIPE_SHADER_COMPUTE
;
608 for (shader
= start_shader
; shader
< SI_NUM_SHADERS
; shader
++) {
609 for (i
= 0; i
< SI_NUM_CONST_BUFFERS
; i
++) {
610 sctx
->b
.set_constant_buffer(&sctx
->b
, shader
, i
,
611 &sctx
->null_const_buf
);
615 si_set_rw_buffer(sctx
, SI_HS_CONST_DEFAULT_TESS_LEVELS
,
616 &sctx
->null_const_buf
);
617 si_set_rw_buffer(sctx
, SI_VS_CONST_INSTANCE_DIVISORS
,
618 &sctx
->null_const_buf
);
619 si_set_rw_buffer(sctx
, SI_VS_CONST_CLIP_PLANES
,
620 &sctx
->null_const_buf
);
621 si_set_rw_buffer(sctx
, SI_PS_CONST_POLY_STIPPLE
,
622 &sctx
->null_const_buf
);
623 si_set_rw_buffer(sctx
, SI_PS_CONST_SAMPLE_POSITIONS
,
624 &sctx
->null_const_buf
);
627 uint64_t max_threads_per_block
;
628 screen
->get_compute_param(screen
, PIPE_SHADER_IR_TGSI
,
629 PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK
,
630 &max_threads_per_block
);
632 /* The maximum number of scratch waves. Scratch space isn't divided
633 * evenly between CUs. The number is only a function of the number of CUs.
634 * We can decrease the constant to decrease the scratch buffer size.
636 * sctx->scratch_waves must be >= the maximum posible size of
637 * 1 threadgroup, so that the hw doesn't hang from being unable
640 * The recommended value is 4 per CU at most. Higher numbers don't
641 * bring much benefit, but they still occupy chip resources (think
642 * async compute). I've seen ~2% performance difference between 4 and 32.
644 sctx
->scratch_waves
= MAX2(32 * sscreen
->info
.num_good_compute_units
,
645 max_threads_per_block
/ 64);
647 si_init_compiler(sscreen
, &sctx
->compiler
);
649 /* Bindless handles. */
650 sctx
->tex_handles
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
651 _mesa_key_pointer_equal
);
652 sctx
->img_handles
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
653 _mesa_key_pointer_equal
);
655 util_dynarray_init(&sctx
->resident_tex_handles
, NULL
);
656 util_dynarray_init(&sctx
->resident_img_handles
, NULL
);
657 util_dynarray_init(&sctx
->resident_tex_needs_color_decompress
, NULL
);
658 util_dynarray_init(&sctx
->resident_img_needs_color_decompress
, NULL
);
659 util_dynarray_init(&sctx
->resident_tex_needs_depth_decompress
, NULL
);
661 sctx
->sample_pos_buffer
=
662 pipe_buffer_create(sctx
->b
.screen
, 0, PIPE_USAGE_DEFAULT
,
663 sizeof(sctx
->sample_positions
));
664 pipe_buffer_write(&sctx
->b
, sctx
->sample_pos_buffer
, 0,
665 sizeof(sctx
->sample_positions
), &sctx
->sample_positions
);
667 /* this must be last */
668 si_begin_new_gfx_cs(sctx
);
670 if (sctx
->chip_class
== GFX7
) {
671 /* Clear the NULL constant buffer, because loads should return zeros.
672 * Note that this forces CP DMA to be used, because clover deadlocks
673 * for some reason when the compute codepath is used.
675 uint32_t clear_value
= 0;
676 si_clear_buffer(sctx
, sctx
->null_const_buf
.buffer
, 0,
677 sctx
->null_const_buf
.buffer
->width0
,
678 &clear_value
, 4, SI_COHERENCY_SHADER
, true);
682 fprintf(stderr
, "radeonsi: Failed to create a context.\n");
683 si_destroy_context(&sctx
->b
);
687 static struct pipe_context
*si_pipe_create_context(struct pipe_screen
*screen
,
688 void *priv
, unsigned flags
)
690 struct si_screen
*sscreen
= (struct si_screen
*)screen
;
691 struct pipe_context
*ctx
;
693 if (sscreen
->debug_flags
& DBG(CHECK_VM
))
694 flags
|= PIPE_CONTEXT_DEBUG
;
696 ctx
= si_create_context(screen
, flags
);
698 if (!(flags
& PIPE_CONTEXT_PREFER_THREADED
))
701 /* Clover (compute-only) is unsupported. */
702 if (flags
& PIPE_CONTEXT_COMPUTE_ONLY
)
705 /* When shaders are logged to stderr, asynchronous compilation is
707 if (sscreen
->debug_flags
& DBG_ALL_SHADERS
)
710 /* Use asynchronous flushes only on amdgpu, since the radeon
711 * implementation for fence_server_sync is incomplete. */
712 return threaded_context_create(ctx
, &sscreen
->pool_transfers
,
713 si_replace_buffer_storage
,
714 sscreen
->info
.is_amdgpu
? si_create_fence
: NULL
,
715 &((struct si_context
*)ctx
)->tc
);
721 static void si_destroy_screen(struct pipe_screen
* pscreen
)
723 struct si_screen
*sscreen
= (struct si_screen
*)pscreen
;
724 struct si_shader_part
*parts
[] = {
726 sscreen
->tcs_epilogs
,
733 if (!sscreen
->ws
->unref(sscreen
->ws
))
736 mtx_destroy(&sscreen
->aux_context_lock
);
738 struct u_log_context
*aux_log
= ((struct si_context
*)sscreen
->aux_context
)->log
;
740 sscreen
->aux_context
->set_log_context(sscreen
->aux_context
, NULL
);
741 u_log_context_destroy(aux_log
);
745 sscreen
->aux_context
->destroy(sscreen
->aux_context
);
747 util_queue_destroy(&sscreen
->shader_compiler_queue
);
748 util_queue_destroy(&sscreen
->shader_compiler_queue_low_priority
);
750 /* Release the reference on glsl types of the compiler threads. */
751 glsl_type_singleton_decref();
753 for (i
= 0; i
< ARRAY_SIZE(sscreen
->compiler
); i
++)
754 si_destroy_compiler(&sscreen
->compiler
[i
]);
756 for (i
= 0; i
< ARRAY_SIZE(sscreen
->compiler_lowp
); i
++)
757 si_destroy_compiler(&sscreen
->compiler_lowp
[i
]);
759 /* Free shader parts. */
760 for (i
= 0; i
< ARRAY_SIZE(parts
); i
++) {
762 struct si_shader_part
*part
= parts
[i
];
764 parts
[i
] = part
->next
;
765 si_shader_binary_clean(&part
->binary
);
769 mtx_destroy(&sscreen
->shader_parts_mutex
);
770 si_destroy_shader_cache(sscreen
);
772 si_destroy_perfcounters(sscreen
);
773 si_gpu_load_kill_thread(sscreen
);
775 mtx_destroy(&sscreen
->gpu_load_mutex
);
777 slab_destroy_parent(&sscreen
->pool_transfers
);
779 disk_cache_destroy(sscreen
->disk_shader_cache
);
780 sscreen
->ws
->destroy(sscreen
->ws
);
784 static void si_init_gs_info(struct si_screen
*sscreen
)
786 sscreen
->gs_table_depth
= ac_get_gs_table_depth(sscreen
->info
.chip_class
,
787 sscreen
->info
.family
);
790 static void si_test_vmfault(struct si_screen
*sscreen
)
792 struct pipe_context
*ctx
= sscreen
->aux_context
;
793 struct si_context
*sctx
= (struct si_context
*)ctx
;
794 struct pipe_resource
*buf
=
795 pipe_buffer_create_const0(&sscreen
->b
, 0, PIPE_USAGE_DEFAULT
, 64);
798 puts("Buffer allocation failed.");
802 si_resource(buf
)->gpu_address
= 0; /* cause a VM fault */
804 if (sscreen
->debug_flags
& DBG(TEST_VMFAULT_CP
)) {
805 si_cp_dma_copy_buffer(sctx
, buf
, buf
, 0, 4, 4, 0,
806 SI_COHERENCY_NONE
, L2_BYPASS
);
807 ctx
->flush(ctx
, NULL
, 0);
808 puts("VM fault test: CP - done.");
810 if (sscreen
->debug_flags
& DBG(TEST_VMFAULT_SDMA
)) {
811 si_sdma_clear_buffer(sctx
, buf
, 0, 4, 0);
812 ctx
->flush(ctx
, NULL
, 0);
813 puts("VM fault test: SDMA - done.");
815 if (sscreen
->debug_flags
& DBG(TEST_VMFAULT_SHADER
)) {
816 util_test_constant_buffer(ctx
, buf
);
817 puts("VM fault test: Shader - done.");
822 static void si_test_gds_memory_management(struct si_context
*sctx
,
823 unsigned alloc_size
, unsigned alignment
,
824 enum radeon_bo_domain domain
)
826 struct radeon_winsys
*ws
= sctx
->ws
;
827 struct radeon_cmdbuf
*cs
[8];
828 struct pb_buffer
*gds_bo
[ARRAY_SIZE(cs
)];
830 for (unsigned i
= 0; i
< ARRAY_SIZE(cs
); i
++) {
831 cs
[i
] = ws
->cs_create(sctx
->ctx
, RING_COMPUTE
,
833 gds_bo
[i
] = ws
->buffer_create(ws
, alloc_size
, alignment
, domain
, 0);
837 for (unsigned iterations
= 0; iterations
< 20000; iterations
++) {
838 for (unsigned i
= 0; i
< ARRAY_SIZE(cs
); i
++) {
839 /* This clears GDS with CP DMA.
841 * We don't care if GDS is present. Just add some packet
842 * to make the GPU busy for a moment.
844 si_cp_dma_clear_buffer(sctx
, cs
[i
], NULL
, 0, alloc_size
, 0,
845 SI_CPDMA_SKIP_BO_LIST_UPDATE
|
846 SI_CPDMA_SKIP_CHECK_CS_SPACE
|
847 SI_CPDMA_SKIP_GFX_SYNC
, 0, 0);
849 ws
->cs_add_buffer(cs
[i
], gds_bo
[i
], domain
,
850 RADEON_USAGE_READWRITE
, 0);
851 ws
->cs_flush(cs
[i
], PIPE_FLUSH_ASYNC
, NULL
);
857 static void si_disk_cache_create(struct si_screen
*sscreen
)
859 /* Don't use the cache if shader dumping is enabled. */
860 if (sscreen
->debug_flags
& DBG_ALL_SHADERS
)
863 struct mesa_sha1 ctx
;
864 unsigned char sha1
[20];
865 char cache_id
[20 * 2 + 1];
867 _mesa_sha1_init(&ctx
);
869 if (!disk_cache_get_function_identifier(si_disk_cache_create
, &ctx
) ||
870 !disk_cache_get_function_identifier(LLVMInitializeAMDGPUTargetInfo
,
874 _mesa_sha1_final(&ctx
, sha1
);
875 disk_cache_format_hex_id(cache_id
, sha1
, 20 * 2);
877 /* These flags affect shader compilation. */
878 #define ALL_FLAGS (DBG(SI_SCHED) | DBG(GISEL))
879 uint64_t shader_debug_flags
= sscreen
->debug_flags
& ALL_FLAGS
;
881 /* Add the high bits of 32-bit addresses, which affects
882 * how 32-bit addresses are expanded to 64 bits.
884 STATIC_ASSERT(ALL_FLAGS
<= UINT_MAX
);
885 assert((int16_t)sscreen
->info
.address32_hi
== (int32_t)sscreen
->info
.address32_hi
);
886 shader_debug_flags
|= (uint64_t)(sscreen
->info
.address32_hi
& 0xffff) << 32;
888 sscreen
->disk_shader_cache
=
889 disk_cache_create(sscreen
->info
.name
,
894 static void si_set_max_shader_compiler_threads(struct pipe_screen
*screen
,
895 unsigned max_threads
)
897 struct si_screen
*sscreen
= (struct si_screen
*)screen
;
899 /* This function doesn't allow a greater number of threads than
900 * the queue had at its creation. */
901 util_queue_adjust_num_threads(&sscreen
->shader_compiler_queue
,
903 /* Don't change the number of threads on the low priority queue. */
906 static bool si_is_parallel_shader_compilation_finished(struct pipe_screen
*screen
,
908 enum pipe_shader_type shader_type
)
910 struct si_shader_selector
*sel
= (struct si_shader_selector
*)shader
;
912 return util_queue_fence_is_signalled(&sel
->ready
);
915 static struct pipe_screen
*
916 radeonsi_screen_create_impl(struct radeon_winsys
*ws
,
917 const struct pipe_screen_config
*config
)
919 struct si_screen
*sscreen
= CALLOC_STRUCT(si_screen
);
920 unsigned hw_threads
, num_comp_hi_threads
, num_comp_lo_threads
, i
;
927 ws
->query_info(ws
, &sscreen
->info
);
929 if (sscreen
->info
.chip_class
== GFX10
&& LLVM_VERSION_MAJOR
< 9) {
930 fprintf(stderr
, "radeonsi: Navi family support requires LLVM 9 or higher\n");
935 if (sscreen
->info
.chip_class
>= GFX9
) {
936 sscreen
->se_tile_repeat
= 32 * sscreen
->info
.max_se
;
938 ac_get_raster_config(&sscreen
->info
,
939 &sscreen
->pa_sc_raster_config
,
940 &sscreen
->pa_sc_raster_config_1
,
941 &sscreen
->se_tile_repeat
);
944 sscreen
->debug_flags
= debug_get_flags_option("R600_DEBUG",
946 sscreen
->debug_flags
|= debug_get_flags_option("AMD_DEBUG",
949 if (sscreen
->debug_flags
& DBG(NO_GFX
))
950 sscreen
->info
.has_graphics
= false;
952 /* Set functions first. */
953 sscreen
->b
.context_create
= si_pipe_create_context
;
954 sscreen
->b
.destroy
= si_destroy_screen
;
955 sscreen
->b
.set_max_shader_compiler_threads
=
956 si_set_max_shader_compiler_threads
;
957 sscreen
->b
.is_parallel_shader_compilation_finished
=
958 si_is_parallel_shader_compilation_finished
;
960 si_init_screen_get_functions(sscreen
);
961 si_init_screen_buffer_functions(sscreen
);
962 si_init_screen_fence_functions(sscreen
);
963 si_init_screen_state_functions(sscreen
);
964 si_init_screen_texture_functions(sscreen
);
965 si_init_screen_query_functions(sscreen
);
967 /* Set these flags in debug_flags early, so that the shader cache takes
970 if (driQueryOptionb(config
->options
,
971 "glsl_correct_derivatives_after_discard"))
972 sscreen
->debug_flags
|= DBG(FS_CORRECT_DERIVS_AFTER_KILL
);
973 if (driQueryOptionb(config
->options
, "radeonsi_enable_sisched"))
974 sscreen
->debug_flags
|= DBG(SI_SCHED
);
976 if (sscreen
->debug_flags
& DBG(INFO
))
977 ac_print_gpu_info(&sscreen
->info
);
979 slab_create_parent(&sscreen
->pool_transfers
,
980 sizeof(struct si_transfer
), 64);
982 sscreen
->force_aniso
= MIN2(16, debug_get_num_option("R600_TEX_ANISO", -1));
983 if (sscreen
->force_aniso
== -1) {
984 sscreen
->force_aniso
= MIN2(16, debug_get_num_option("AMD_TEX_ANISO", -1));
987 if (sscreen
->force_aniso
>= 0) {
988 printf("radeonsi: Forcing anisotropy filter to %ix\n",
989 /* round down to a power of two */
990 1 << util_logbase2(sscreen
->force_aniso
));
993 (void) mtx_init(&sscreen
->aux_context_lock
, mtx_plain
);
994 (void) mtx_init(&sscreen
->gpu_load_mutex
, mtx_plain
);
996 si_init_gs_info(sscreen
);
997 if (!si_init_shader_cache(sscreen
)) {
1002 si_disk_cache_create(sscreen
);
1004 /* Determine the number of shader compiler threads. */
1005 hw_threads
= sysconf(_SC_NPROCESSORS_ONLN
);
1007 if (hw_threads
>= 12) {
1008 num_comp_hi_threads
= hw_threads
* 3 / 4;
1009 num_comp_lo_threads
= hw_threads
/ 3;
1010 } else if (hw_threads
>= 6) {
1011 num_comp_hi_threads
= hw_threads
- 2;
1012 num_comp_lo_threads
= hw_threads
/ 2;
1013 } else if (hw_threads
>= 2) {
1014 num_comp_hi_threads
= hw_threads
- 1;
1015 num_comp_lo_threads
= hw_threads
/ 2;
1017 num_comp_hi_threads
= 1;
1018 num_comp_lo_threads
= 1;
1021 num_comp_hi_threads
= MIN2(num_comp_hi_threads
,
1022 ARRAY_SIZE(sscreen
->compiler
));
1023 num_comp_lo_threads
= MIN2(num_comp_lo_threads
,
1024 ARRAY_SIZE(sscreen
->compiler_lowp
));
1026 /* Take a reference on the glsl types for the compiler threads. */
1027 glsl_type_singleton_init_or_ref();
1029 if (!util_queue_init(&sscreen
->shader_compiler_queue
, "sh",
1030 64, num_comp_hi_threads
,
1031 UTIL_QUEUE_INIT_RESIZE_IF_FULL
|
1032 UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY
)) {
1033 si_destroy_shader_cache(sscreen
);
1035 glsl_type_singleton_decref();
1039 if (!util_queue_init(&sscreen
->shader_compiler_queue_low_priority
,
1041 64, num_comp_lo_threads
,
1042 UTIL_QUEUE_INIT_RESIZE_IF_FULL
|
1043 UTIL_QUEUE_INIT_SET_FULL_THREAD_AFFINITY
|
1044 UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY
)) {
1045 si_destroy_shader_cache(sscreen
);
1047 glsl_type_singleton_decref();
1051 if (!debug_get_bool_option("RADEON_DISABLE_PERFCOUNTERS", false))
1052 si_init_perfcounters(sscreen
);
1054 /* Determine tessellation ring info. */
1055 bool double_offchip_buffers
= sscreen
->info
.chip_class
>= GFX7
&&
1056 sscreen
->info
.family
!= CHIP_CARRIZO
&&
1057 sscreen
->info
.family
!= CHIP_STONEY
;
1058 /* This must be one less than the maximum number due to a hw limitation.
1059 * Various hardware bugs need this.
1061 unsigned max_offchip_buffers_per_se
;
1063 if (sscreen
->info
.chip_class
>= GFX10
)
1064 max_offchip_buffers_per_se
= 256;
1065 /* Only certain chips can use the maximum value. */
1066 else if (sscreen
->info
.family
== CHIP_VEGA12
||
1067 sscreen
->info
.family
== CHIP_VEGA20
)
1068 max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1070 max_offchip_buffers_per_se
= double_offchip_buffers
? 127 : 63;
1072 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1073 sscreen
->info
.max_se
;
1074 unsigned offchip_granularity
;
1076 /* Hawaii has a bug with offchip buffers > 256 that can be worked
1077 * around by setting 4K granularity.
1079 if (sscreen
->info
.family
== CHIP_HAWAII
) {
1080 sscreen
->tess_offchip_block_dw_size
= 4096;
1081 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1083 sscreen
->tess_offchip_block_dw_size
= 8192;
1084 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1087 sscreen
->tess_factor_ring_size
= 32768 * sscreen
->info
.max_se
;
1088 sscreen
->tess_offchip_ring_size
= max_offchip_buffers
*
1089 sscreen
->tess_offchip_block_dw_size
* 4;
1091 if (sscreen
->info
.chip_class
>= GFX7
) {
1092 if (sscreen
->info
.chip_class
>= GFX8
)
1093 --max_offchip_buffers
;
1094 sscreen
->vgt_hs_offchip_param
=
1095 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1096 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1098 assert(offchip_granularity
== V_03093C_X_8K_DWORDS
);
1099 sscreen
->vgt_hs_offchip_param
=
1100 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1103 sscreen
->has_draw_indirect_multi
=
1104 (sscreen
->info
.family
>= CHIP_POLARIS10
) ||
1105 (sscreen
->info
.chip_class
== GFX8
&&
1106 sscreen
->info
.pfp_fw_version
>= 121 &&
1107 sscreen
->info
.me_fw_version
>= 87) ||
1108 (sscreen
->info
.chip_class
== GFX7
&&
1109 sscreen
->info
.pfp_fw_version
>= 211 &&
1110 sscreen
->info
.me_fw_version
>= 173) ||
1111 (sscreen
->info
.chip_class
== GFX6
&&
1112 sscreen
->info
.pfp_fw_version
>= 79 &&
1113 sscreen
->info
.me_fw_version
>= 142);
1115 sscreen
->has_out_of_order_rast
= sscreen
->info
.has_out_of_order_rast
&&
1116 !(sscreen
->debug_flags
& DBG(NO_OUT_OF_ORDER
));
1117 sscreen
->assume_no_z_fights
=
1118 driQueryOptionb(config
->options
, "radeonsi_assume_no_z_fights");
1119 sscreen
->commutative_blend_add
=
1120 driQueryOptionb(config
->options
, "radeonsi_commutative_blend_add");
1123 #define OPT_BOOL(name, dflt, description) \
1124 sscreen->options.name = \
1125 driQueryOptionb(config->options, "radeonsi_"#name);
1126 #include "si_debug_options.h"
1129 sscreen
->use_ngg
= sscreen
->info
.chip_class
>= GFX10
&&
1130 sscreen
->info
.family
!= CHIP_NAVI14
&&
1131 !(sscreen
->debug_flags
& DBG(NO_NGG
));
1132 sscreen
->use_ngg_streamout
= false;
1134 /* Only enable primitive binning on APUs by default. */
1135 if (sscreen
->info
.chip_class
>= GFX10
) {
1136 sscreen
->dpbb_allowed
= true;
1137 sscreen
->dfsm_allowed
= !sscreen
->info
.has_dedicated_vram
;
1138 } else if (sscreen
->info
.chip_class
== GFX9
) {
1139 sscreen
->dpbb_allowed
= !sscreen
->info
.has_dedicated_vram
;
1140 sscreen
->dfsm_allowed
= !sscreen
->info
.has_dedicated_vram
;
1143 /* Process DPBB enable flags. */
1144 if (sscreen
->debug_flags
& DBG(DPBB
)) {
1145 sscreen
->dpbb_allowed
= true;
1146 if (sscreen
->debug_flags
& DBG(DFSM
))
1147 sscreen
->dfsm_allowed
= true;
1150 /* Process DPBB disable flags. */
1151 if (sscreen
->debug_flags
& DBG(NO_DPBB
)) {
1152 sscreen
->dpbb_allowed
= false;
1153 sscreen
->dfsm_allowed
= false;
1154 } else if (sscreen
->debug_flags
& DBG(NO_DFSM
)) {
1155 sscreen
->dfsm_allowed
= false;
1158 /* While it would be nice not to have this flag, we are constrained
1159 * by the reality that LLVM 9.0 has buggy VGPR indexing on GFX9.
1161 sscreen
->llvm_has_working_vgpr_indexing
= sscreen
->info
.chip_class
!= GFX9
;
1163 sscreen
->dcc_msaa_allowed
=
1164 !(sscreen
->debug_flags
& DBG(NO_DCC_MSAA
));
1166 (void) mtx_init(&sscreen
->shader_parts_mutex
, mtx_plain
);
1167 sscreen
->use_monolithic_shaders
=
1168 (sscreen
->debug_flags
& DBG(MONOLITHIC_SHADERS
)) != 0;
1170 sscreen
->barrier_flags
.cp_to_L2
= SI_CONTEXT_INV_SCACHE
|
1171 SI_CONTEXT_INV_VCACHE
;
1172 if (sscreen
->info
.chip_class
<= GFX8
) {
1173 sscreen
->barrier_flags
.cp_to_L2
|= SI_CONTEXT_INV_L2
;
1174 sscreen
->barrier_flags
.L2_to_cp
|= SI_CONTEXT_WB_L2
;
1177 if (debug_get_bool_option("RADEON_DUMP_SHADERS", false))
1178 sscreen
->debug_flags
|= DBG_ALL_SHADERS
;
1185 * That means 8 coverage samples, 4 Z/S samples, and 2 color samples.
1187 * s >= z >= c (ignoring this only wastes memory)
1192 * Only MSAA color and depth buffers are overriden.
1194 if (sscreen
->info
.has_eqaa_surface_allocator
) {
1195 const char *eqaa
= debug_get_option("EQAA", NULL
);
1198 if (eqaa
&& sscanf(eqaa
, "%u,%u,%u", &s
, &z
, &f
) == 3 && s
&& z
&& f
) {
1199 sscreen
->eqaa_force_coverage_samples
= s
;
1200 sscreen
->eqaa_force_z_samples
= z
;
1201 sscreen
->eqaa_force_color_samples
= f
;
1205 for (i
= 0; i
< num_comp_hi_threads
; i
++)
1206 si_init_compiler(sscreen
, &sscreen
->compiler
[i
]);
1207 for (i
= 0; i
< num_comp_lo_threads
; i
++)
1208 si_init_compiler(sscreen
, &sscreen
->compiler_lowp
[i
]);
1210 sscreen
->ge_wave_size
= 64;
1211 sscreen
->ps_wave_size
= 64;
1212 sscreen
->compute_wave_size
= 64;
1214 if (sscreen
->info
.chip_class
>= GFX10
) {
1215 /* Pixels shaders: Wave64 is recommended.
1216 * Compute shaders: There are piglit failures with Wave32.
1218 sscreen
->ge_wave_size
= 32;
1220 if (sscreen
->debug_flags
& DBG(W32_GE
))
1221 sscreen
->ge_wave_size
= 32;
1222 if (sscreen
->debug_flags
& DBG(W32_PS
))
1223 sscreen
->ps_wave_size
= 32;
1224 if (sscreen
->debug_flags
& DBG(W32_CS
))
1225 sscreen
->compute_wave_size
= 32;
1227 if (sscreen
->debug_flags
& DBG(W64_GE
))
1228 sscreen
->ge_wave_size
= 64;
1229 if (sscreen
->debug_flags
& DBG(W64_PS
))
1230 sscreen
->ps_wave_size
= 64;
1231 if (sscreen
->debug_flags
& DBG(W64_CS
))
1232 sscreen
->compute_wave_size
= 64;
1235 /* Create the auxiliary context. This must be done last. */
1236 sscreen
->aux_context
= si_create_context(&sscreen
->b
,
1237 (sscreen
->options
.aux_debug
? PIPE_CONTEXT_DEBUG
: 0) |
1238 (sscreen
->info
.has_graphics
? 0 : PIPE_CONTEXT_COMPUTE_ONLY
));
1239 if (sscreen
->options
.aux_debug
) {
1240 struct u_log_context
*log
= CALLOC_STRUCT(u_log_context
);
1241 u_log_context_init(log
);
1242 sscreen
->aux_context
->set_log_context(sscreen
->aux_context
, log
);
1245 if (sscreen
->debug_flags
& DBG(TEST_DMA
))
1246 si_test_dma(sscreen
);
1248 if (sscreen
->debug_flags
& DBG(TEST_DMA_PERF
)) {
1249 si_test_dma_perf(sscreen
);
1252 if (sscreen
->debug_flags
& (DBG(TEST_VMFAULT_CP
) |
1253 DBG(TEST_VMFAULT_SDMA
) |
1254 DBG(TEST_VMFAULT_SHADER
)))
1255 si_test_vmfault(sscreen
);
1257 if (sscreen
->debug_flags
& DBG(TEST_GDS
))
1258 si_test_gds((struct si_context
*)sscreen
->aux_context
);
1260 if (sscreen
->debug_flags
& DBG(TEST_GDS_MM
)) {
1261 si_test_gds_memory_management((struct si_context
*)sscreen
->aux_context
,
1262 32 * 1024, 4, RADEON_DOMAIN_GDS
);
1264 if (sscreen
->debug_flags
& DBG(TEST_GDS_OA_MM
)) {
1265 si_test_gds_memory_management((struct si_context
*)sscreen
->aux_context
,
1266 4, 1, RADEON_DOMAIN_OA
);
1272 struct pipe_screen
*radeonsi_screen_create(int fd
, const struct pipe_screen_config
*config
)
1274 drmVersionPtr version
= drmGetVersion(fd
);
1275 struct radeon_winsys
*rw
= NULL
;
1277 switch (version
->version_major
) {
1279 rw
= radeon_drm_winsys_create(fd
, config
, radeonsi_screen_create_impl
);
1282 rw
= amdgpu_winsys_create(fd
, config
, radeonsi_screen_create_impl
);
1286 drmFreeVersion(version
);
1287 return rw
? rw
->screen
: NULL
;