2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 #include "si_public.h"
26 #include "si_shader_internal.h"
29 #include "radeon/radeon_uvd.h"
30 #include "util/hash_table.h"
31 #include "util/u_log.h"
32 #include "util/u_memory.h"
33 #include "util/u_suballoc.h"
34 #include "util/u_tests.h"
35 #include "util/xmlconfig.h"
36 #include "vl/vl_decoder.h"
37 #include "../ddebug/dd_util.h"
42 static void si_destroy_context(struct pipe_context
*context
)
44 struct si_context
*sctx
= (struct si_context
*)context
;
47 /* Unreference the framebuffer normally to disable related logic
50 struct pipe_framebuffer_state fb
= {};
51 if (context
->set_framebuffer_state
)
52 context
->set_framebuffer_state(context
, &fb
);
54 si_release_all_descriptors(sctx
);
56 pipe_resource_reference(&sctx
->esgs_ring
, NULL
);
57 pipe_resource_reference(&sctx
->gsvs_ring
, NULL
);
58 pipe_resource_reference(&sctx
->tf_ring
, NULL
);
59 pipe_resource_reference(&sctx
->tess_offchip_ring
, NULL
);
60 pipe_resource_reference(&sctx
->null_const_buf
.buffer
, NULL
);
61 r600_resource_reference(&sctx
->border_color_buffer
, NULL
);
62 free(sctx
->border_color_table
);
63 r600_resource_reference(&sctx
->scratch_buffer
, NULL
);
64 r600_resource_reference(&sctx
->compute_scratch_buffer
, NULL
);
65 r600_resource_reference(&sctx
->wait_mem_scratch
, NULL
);
67 si_pm4_free_state(sctx
, sctx
->init_config
, ~0);
68 if (sctx
->init_config_gs_rings
)
69 si_pm4_free_state(sctx
, sctx
->init_config_gs_rings
, ~0);
70 for (i
= 0; i
< ARRAY_SIZE(sctx
->vgt_shader_config
); i
++)
71 si_pm4_delete_state(sctx
, vgt_shader_config
, sctx
->vgt_shader_config
[i
]);
73 if (sctx
->fixed_func_tcs_shader
.cso
)
74 sctx
->b
.b
.delete_tcs_state(&sctx
->b
.b
, sctx
->fixed_func_tcs_shader
.cso
);
75 if (sctx
->custom_dsa_flush
)
76 sctx
->b
.b
.delete_depth_stencil_alpha_state(&sctx
->b
.b
, sctx
->custom_dsa_flush
);
77 if (sctx
->custom_blend_resolve
)
78 sctx
->b
.b
.delete_blend_state(&sctx
->b
.b
, sctx
->custom_blend_resolve
);
79 if (sctx
->custom_blend_fmask_decompress
)
80 sctx
->b
.b
.delete_blend_state(&sctx
->b
.b
, sctx
->custom_blend_fmask_decompress
);
81 if (sctx
->custom_blend_eliminate_fastclear
)
82 sctx
->b
.b
.delete_blend_state(&sctx
->b
.b
, sctx
->custom_blend_eliminate_fastclear
);
83 if (sctx
->custom_blend_dcc_decompress
)
84 sctx
->b
.b
.delete_blend_state(&sctx
->b
.b
, sctx
->custom_blend_dcc_decompress
);
85 if (sctx
->vs_blit_pos
)
86 sctx
->b
.b
.delete_vs_state(&sctx
->b
.b
, sctx
->vs_blit_pos
);
87 if (sctx
->vs_blit_pos_layered
)
88 sctx
->b
.b
.delete_vs_state(&sctx
->b
.b
, sctx
->vs_blit_pos_layered
);
89 if (sctx
->vs_blit_color
)
90 sctx
->b
.b
.delete_vs_state(&sctx
->b
.b
, sctx
->vs_blit_color
);
91 if (sctx
->vs_blit_color_layered
)
92 sctx
->b
.b
.delete_vs_state(&sctx
->b
.b
, sctx
->vs_blit_color_layered
);
93 if (sctx
->vs_blit_texcoord
)
94 sctx
->b
.b
.delete_vs_state(&sctx
->b
.b
, sctx
->vs_blit_texcoord
);
97 util_blitter_destroy(sctx
->blitter
);
99 si_common_context_cleanup(&sctx
->b
);
101 LLVMDisposeTargetMachine(sctx
->tm
);
103 si_saved_cs_reference(&sctx
->current_saved_cs
, NULL
);
105 _mesa_hash_table_destroy(sctx
->tex_handles
, NULL
);
106 _mesa_hash_table_destroy(sctx
->img_handles
, NULL
);
108 util_dynarray_fini(&sctx
->resident_tex_handles
);
109 util_dynarray_fini(&sctx
->resident_img_handles
);
110 util_dynarray_fini(&sctx
->resident_tex_needs_color_decompress
);
111 util_dynarray_fini(&sctx
->resident_img_needs_color_decompress
);
112 util_dynarray_fini(&sctx
->resident_tex_needs_depth_decompress
);
116 static enum pipe_reset_status
117 si_amdgpu_get_reset_status(struct pipe_context
*ctx
)
119 struct si_context
*sctx
= (struct si_context
*)ctx
;
121 return sctx
->b
.ws
->ctx_query_reset_status(sctx
->b
.ctx
);
124 /* Apitrace profiling:
125 * 1) qapitrace : Tools -> Profile: Measure CPU & GPU times
126 * 2) In the middle panel, zoom in (mouse wheel) on some bad draw call
127 * and remember its number.
128 * 3) In Mesa, enable queries and performance counters around that draw
129 * call and print the results.
130 * 4) glretrace --benchmark --markers ..
132 static void si_emit_string_marker(struct pipe_context
*ctx
,
133 const char *string
, int len
)
135 struct si_context
*sctx
= (struct si_context
*)ctx
;
137 dd_parse_apitrace_marker(string
, len
, &sctx
->apitrace_call_number
);
140 u_log_printf(sctx
->b
.log
, "\nString marker: %*s\n", len
, string
);
143 static LLVMTargetMachineRef
144 si_create_llvm_target_machine(struct si_screen
*sscreen
)
146 enum ac_target_machine_options tm_options
=
147 (sscreen
->b
.debug_flags
& DBG(SI_SCHED
) ? AC_TM_SISCHED
: 0) |
148 (sscreen
->b
.chip_class
>= GFX9
? AC_TM_FORCE_ENABLE_XNACK
: 0) |
149 (sscreen
->b
.chip_class
< GFX9
? AC_TM_FORCE_DISABLE_XNACK
: 0) |
150 (!sscreen
->llvm_has_working_vgpr_indexing
? AC_TM_PROMOTE_ALLOCA_TO_SCRATCH
: 0);
152 return ac_create_target_machine(sscreen
->b
.family
, tm_options
);
155 static void si_set_debug_callback(struct pipe_context
*ctx
,
156 const struct pipe_debug_callback
*cb
)
158 struct si_context
*sctx
= (struct si_context
*)ctx
;
159 struct si_screen
*screen
= sctx
->screen
;
161 util_queue_finish(&screen
->shader_compiler_queue
);
162 util_queue_finish(&screen
->shader_compiler_queue_low_priority
);
167 memset(&sctx
->debug
, 0, sizeof(sctx
->debug
));
170 static void si_set_log_context(struct pipe_context
*ctx
,
171 struct u_log_context
*log
)
173 struct si_context
*sctx
= (struct si_context
*)ctx
;
177 u_log_add_auto_logger(log
, si_auto_log_cs
, sctx
);
180 static struct pipe_context
*si_create_context(struct pipe_screen
*screen
,
183 struct si_context
*sctx
= CALLOC_STRUCT(si_context
);
184 struct si_screen
* sscreen
= (struct si_screen
*)screen
;
185 struct radeon_winsys
*ws
= sscreen
->b
.ws
;
191 if (flags
& PIPE_CONTEXT_DEBUG
)
192 sscreen
->record_llvm_ir
= true; /* racy but not critical */
194 sctx
->b
.b
.screen
= screen
; /* this must be set first */
195 sctx
->b
.b
.priv
= NULL
;
196 sctx
->b
.b
.destroy
= si_destroy_context
;
197 sctx
->b
.b
.emit_string_marker
= si_emit_string_marker
;
198 sctx
->b
.b
.set_debug_callback
= si_set_debug_callback
;
199 sctx
->b
.b
.set_log_context
= si_set_log_context
;
200 sctx
->b
.set_atom_dirty
= (void *)si_set_atom_dirty
;
201 sctx
->screen
= sscreen
; /* Easy accessing of screen/winsys. */
202 sctx
->is_debug
= (flags
& PIPE_CONTEXT_DEBUG
) != 0;
204 if (!si_common_context_init(&sctx
->b
, &sscreen
->b
, flags
))
207 if (sscreen
->b
.info
.drm_major
== 3)
208 sctx
->b
.b
.get_device_reset_status
= si_amdgpu_get_reset_status
;
210 si_init_buffer_functions(sctx
);
211 si_init_clear_functions(sctx
);
212 si_init_blit_functions(sctx
);
213 si_init_compute_functions(sctx
);
214 si_init_cp_dma_functions(sctx
);
215 si_init_debug_functions(sctx
);
216 si_init_msaa_functions(sctx
);
217 si_init_streamout_functions(sctx
);
219 if (sscreen
->b
.info
.has_hw_decode
) {
220 sctx
->b
.b
.create_video_codec
= si_uvd_create_decoder
;
221 sctx
->b
.b
.create_video_buffer
= si_video_buffer_create
;
223 sctx
->b
.b
.create_video_codec
= vl_create_decoder
;
224 sctx
->b
.b
.create_video_buffer
= vl_video_buffer_create
;
227 sctx
->b
.gfx
.cs
= ws
->cs_create(sctx
->b
.ctx
, RING_GFX
,
228 si_context_gfx_flush
, sctx
);
229 sctx
->b
.gfx
.flush
= si_context_gfx_flush
;
232 sctx
->border_color_table
= malloc(SI_MAX_BORDER_COLORS
*
233 sizeof(*sctx
->border_color_table
));
234 if (!sctx
->border_color_table
)
237 sctx
->border_color_buffer
= (struct r600_resource
*)
238 pipe_buffer_create(screen
, 0, PIPE_USAGE_DEFAULT
,
239 SI_MAX_BORDER_COLORS
*
240 sizeof(*sctx
->border_color_table
));
241 if (!sctx
->border_color_buffer
)
244 sctx
->border_color_map
=
245 ws
->buffer_map(sctx
->border_color_buffer
->buf
,
246 NULL
, PIPE_TRANSFER_WRITE
);
247 if (!sctx
->border_color_map
)
250 si_init_all_descriptors(sctx
);
251 si_init_fence_functions(sctx
);
252 si_init_state_functions(sctx
);
253 si_init_shader_functions(sctx
);
254 si_init_viewport_functions(sctx
);
255 si_init_ia_multi_vgt_param_table(sctx
);
257 if (sctx
->b
.chip_class
>= CIK
)
258 cik_init_sdma_functions(sctx
);
260 si_init_dma_functions(sctx
);
262 if (sscreen
->b
.debug_flags
& DBG(FORCE_DMA
))
263 sctx
->b
.b
.resource_copy_region
= sctx
->b
.dma_copy
;
265 sctx
->blitter
= util_blitter_create(&sctx
->b
.b
);
266 if (sctx
->blitter
== NULL
)
268 sctx
->blitter
->draw_rectangle
= si_draw_rectangle
;
269 sctx
->blitter
->skip_viewport_restore
= true;
271 sctx
->sample_mask
.sample_mask
= 0xffff;
273 /* these must be last */
274 si_begin_new_cs(sctx
);
276 if (sctx
->b
.chip_class
>= GFX9
) {
277 sctx
->wait_mem_scratch
= (struct r600_resource
*)
278 pipe_buffer_create(screen
, 0, PIPE_USAGE_DEFAULT
, 4);
279 if (!sctx
->wait_mem_scratch
)
282 /* Initialize the memory. */
283 struct radeon_winsys_cs
*cs
= sctx
->b
.gfx
.cs
;
284 radeon_emit(cs
, PKT3(PKT3_WRITE_DATA
, 3, 0));
285 radeon_emit(cs
, S_370_DST_SEL(V_370_MEMORY_SYNC
) |
286 S_370_WR_CONFIRM(1) |
287 S_370_ENGINE_SEL(V_370_ME
));
288 radeon_emit(cs
, sctx
->wait_mem_scratch
->gpu_address
);
289 radeon_emit(cs
, sctx
->wait_mem_scratch
->gpu_address
>> 32);
290 radeon_emit(cs
, sctx
->wait_mem_number
);
293 /* CIK cannot unbind a constant buffer (S_BUFFER_LOAD doesn't skip loads
294 * if NUM_RECORDS == 0). We need to use a dummy buffer instead. */
295 if (sctx
->b
.chip_class
== CIK
) {
296 sctx
->null_const_buf
.buffer
=
297 si_aligned_buffer_create(screen
,
298 R600_RESOURCE_FLAG_UNMAPPABLE
,
299 PIPE_USAGE_DEFAULT
, 16,
300 sctx
->screen
->b
.info
.tcc_cache_line_size
);
301 if (!sctx
->null_const_buf
.buffer
)
303 sctx
->null_const_buf
.buffer_size
= sctx
->null_const_buf
.buffer
->width0
;
305 for (shader
= 0; shader
< SI_NUM_SHADERS
; shader
++) {
306 for (i
= 0; i
< SI_NUM_CONST_BUFFERS
; i
++) {
307 sctx
->b
.b
.set_constant_buffer(&sctx
->b
.b
, shader
, i
,
308 &sctx
->null_const_buf
);
312 si_set_rw_buffer(sctx
, SI_HS_CONST_DEFAULT_TESS_LEVELS
,
313 &sctx
->null_const_buf
);
314 si_set_rw_buffer(sctx
, SI_VS_CONST_INSTANCE_DIVISORS
,
315 &sctx
->null_const_buf
);
316 si_set_rw_buffer(sctx
, SI_VS_CONST_CLIP_PLANES
,
317 &sctx
->null_const_buf
);
318 si_set_rw_buffer(sctx
, SI_PS_CONST_POLY_STIPPLE
,
319 &sctx
->null_const_buf
);
320 si_set_rw_buffer(sctx
, SI_PS_CONST_SAMPLE_POSITIONS
,
321 &sctx
->null_const_buf
);
323 /* Clear the NULL constant buffer, because loads should return zeros. */
324 si_clear_buffer(&sctx
->b
.b
, sctx
->null_const_buf
.buffer
, 0,
325 sctx
->null_const_buf
.buffer
->width0
, 0,
326 R600_COHERENCY_SHADER
);
329 uint64_t max_threads_per_block
;
330 screen
->get_compute_param(screen
, PIPE_SHADER_IR_TGSI
,
331 PIPE_COMPUTE_CAP_MAX_THREADS_PER_BLOCK
,
332 &max_threads_per_block
);
334 /* The maximum number of scratch waves. Scratch space isn't divided
335 * evenly between CUs. The number is only a function of the number of CUs.
336 * We can decrease the constant to decrease the scratch buffer size.
338 * sctx->scratch_waves must be >= the maximum posible size of
339 * 1 threadgroup, so that the hw doesn't hang from being unable
342 * The recommended value is 4 per CU at most. Higher numbers don't
343 * bring much benefit, but they still occupy chip resources (think
344 * async compute). I've seen ~2% performance difference between 4 and 32.
346 sctx
->scratch_waves
= MAX2(32 * sscreen
->b
.info
.num_good_compute_units
,
347 max_threads_per_block
/ 64);
349 sctx
->tm
= si_create_llvm_target_machine(sscreen
);
351 /* Bindless handles. */
352 sctx
->tex_handles
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
353 _mesa_key_pointer_equal
);
354 sctx
->img_handles
= _mesa_hash_table_create(NULL
, _mesa_hash_pointer
,
355 _mesa_key_pointer_equal
);
357 util_dynarray_init(&sctx
->resident_tex_handles
, NULL
);
358 util_dynarray_init(&sctx
->resident_img_handles
, NULL
);
359 util_dynarray_init(&sctx
->resident_tex_needs_color_decompress
, NULL
);
360 util_dynarray_init(&sctx
->resident_img_needs_color_decompress
, NULL
);
361 util_dynarray_init(&sctx
->resident_tex_needs_depth_decompress
, NULL
);
365 fprintf(stderr
, "radeonsi: Failed to create a context.\n");
366 si_destroy_context(&sctx
->b
.b
);
370 static struct pipe_context
*si_pipe_create_context(struct pipe_screen
*screen
,
371 void *priv
, unsigned flags
)
373 struct si_screen
*sscreen
= (struct si_screen
*)screen
;
374 struct pipe_context
*ctx
;
376 if (sscreen
->b
.debug_flags
& DBG(CHECK_VM
))
377 flags
|= PIPE_CONTEXT_DEBUG
;
379 ctx
= si_create_context(screen
, flags
);
381 if (!(flags
& PIPE_CONTEXT_PREFER_THREADED
))
384 /* Clover (compute-only) is unsupported. */
385 if (flags
& PIPE_CONTEXT_COMPUTE_ONLY
)
388 /* When shaders are logged to stderr, asynchronous compilation is
390 if (sscreen
->b
.debug_flags
& DBG_ALL_SHADERS
)
393 /* Use asynchronous flushes only on amdgpu, since the radeon
394 * implementation for fence_server_sync is incomplete. */
395 return threaded_context_create(ctx
, &sscreen
->b
.pool_transfers
,
396 si_replace_buffer_storage
,
397 sscreen
->b
.info
.drm_major
>= 3 ? si_create_fence
: NULL
,
398 &((struct si_context
*)ctx
)->b
.tc
);
405 static void si_destroy_screen(struct pipe_screen
* pscreen
)
407 struct si_screen
*sscreen
= (struct si_screen
*)pscreen
;
408 struct si_shader_part
*parts
[] = {
410 sscreen
->tcs_epilogs
,
417 if (!sscreen
->b
.ws
->unref(sscreen
->b
.ws
))
420 util_queue_destroy(&sscreen
->shader_compiler_queue
);
421 util_queue_destroy(&sscreen
->shader_compiler_queue_low_priority
);
423 for (i
= 0; i
< ARRAY_SIZE(sscreen
->tm
); i
++)
425 LLVMDisposeTargetMachine(sscreen
->tm
[i
]);
427 for (i
= 0; i
< ARRAY_SIZE(sscreen
->tm_low_priority
); i
++)
428 if (sscreen
->tm_low_priority
[i
])
429 LLVMDisposeTargetMachine(sscreen
->tm_low_priority
[i
]);
431 /* Free shader parts. */
432 for (i
= 0; i
< ARRAY_SIZE(parts
); i
++) {
434 struct si_shader_part
*part
= parts
[i
];
436 parts
[i
] = part
->next
;
437 ac_shader_binary_clean(&part
->binary
);
441 mtx_destroy(&sscreen
->shader_parts_mutex
);
442 si_destroy_shader_cache(sscreen
);
443 si_destroy_common_screen(&sscreen
->b
);
446 static bool si_init_gs_info(struct si_screen
*sscreen
)
448 /* gs_table_depth is not used by GFX9 */
449 if (sscreen
->b
.chip_class
>= GFX9
)
452 switch (sscreen
->b
.family
) {
461 sscreen
->gs_table_depth
= 16;
473 sscreen
->gs_table_depth
= 32;
480 static void si_handle_env_var_force_family(struct si_screen
*sscreen
)
482 const char *family
= debug_get_option("SI_FORCE_FAMILY", NULL
);
488 for (i
= CHIP_TAHITI
; i
< CHIP_LAST
; i
++) {
489 if (!strcmp(family
, ac_get_llvm_processor_name(i
))) {
490 /* Override family and chip_class. */
491 sscreen
->b
.family
= sscreen
->b
.info
.family
= i
;
493 if (i
>= CHIP_VEGA10
)
494 sscreen
->b
.chip_class
= sscreen
->b
.info
.chip_class
= GFX9
;
495 else if (i
>= CHIP_TONGA
)
496 sscreen
->b
.chip_class
= sscreen
->b
.info
.chip_class
= VI
;
497 else if (i
>= CHIP_BONAIRE
)
498 sscreen
->b
.chip_class
= sscreen
->b
.info
.chip_class
= CIK
;
500 sscreen
->b
.chip_class
= sscreen
->b
.info
.chip_class
= SI
;
502 /* Don't submit any IBs. */
503 setenv("RADEON_NOOP", "1", 1);
508 fprintf(stderr
, "radeonsi: Unknown family: %s\n", family
);
512 static void si_test_vmfault(struct si_screen
*sscreen
)
514 struct pipe_context
*ctx
= sscreen
->b
.aux_context
;
515 struct si_context
*sctx
= (struct si_context
*)ctx
;
516 struct pipe_resource
*buf
=
517 pipe_buffer_create(&sscreen
->b
.b
, 0, PIPE_USAGE_DEFAULT
, 64);
520 puts("Buffer allocation failed.");
524 r600_resource(buf
)->gpu_address
= 0; /* cause a VM fault */
526 if (sscreen
->b
.debug_flags
& DBG(TEST_VMFAULT_CP
)) {
527 si_copy_buffer(sctx
, buf
, buf
, 0, 4, 4, 0);
528 ctx
->flush(ctx
, NULL
, 0);
529 puts("VM fault test: CP - done.");
531 if (sscreen
->b
.debug_flags
& DBG(TEST_VMFAULT_SDMA
)) {
532 sctx
->b
.dma_clear_buffer(ctx
, buf
, 0, 4, 0);
533 ctx
->flush(ctx
, NULL
, 0);
534 puts("VM fault test: SDMA - done.");
536 if (sscreen
->b
.debug_flags
& DBG(TEST_VMFAULT_SHADER
)) {
537 util_test_constant_buffer(ctx
, buf
);
538 puts("VM fault test: Shader - done.");
543 static void si_disk_cache_create(struct si_screen
*sscreen
)
545 /* Don't use the cache if shader dumping is enabled. */
546 if (sscreen
->b
.debug_flags
& DBG_ALL_SHADERS
)
549 /* TODO: remove this once gallium supports a nir cache */
550 if (sscreen
->b
.debug_flags
& DBG(NIR
))
553 uint32_t mesa_timestamp
;
554 if (disk_cache_get_function_timestamp(si_disk_cache_create
,
558 uint32_t llvm_timestamp
;
560 if (disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo
,
562 res
= asprintf(×tamp_str
, "%u_%u",
563 mesa_timestamp
, llvm_timestamp
);
567 /* These flags affect shader compilation. */
568 uint64_t shader_debug_flags
=
569 sscreen
->b
.debug_flags
&
570 (DBG(FS_CORRECT_DERIVS_AFTER_KILL
) |
574 sscreen
->b
.disk_shader_cache
=
575 disk_cache_create(si_get_family_name(sscreen
),
583 struct pipe_screen
*radeonsi_screen_create(struct radeon_winsys
*ws
,
584 const struct pipe_screen_config
*config
)
586 struct si_screen
*sscreen
= CALLOC_STRUCT(si_screen
);
587 unsigned num_threads
, num_compiler_threads
, num_compiler_threads_lowprio
, i
;
594 ws
->query_info(ws
, &sscreen
->b
.info
);
596 sscreen
->b
.family
= sscreen
->b
.info
.family
;
597 sscreen
->b
.chip_class
= sscreen
->b
.info
.chip_class
;
599 /* Set functions first. */
600 sscreen
->b
.b
.context_create
= si_pipe_create_context
;
601 sscreen
->b
.b
.destroy
= si_destroy_screen
;
603 si_init_screen_get_functions(sscreen
);
604 si_init_screen_buffer_functions(sscreen
);
605 si_init_screen_fence_functions(sscreen
);
606 si_init_screen_state_functions(sscreen
);
608 /* Set these flags in debug_flags early, so that the shader cache takes
611 if (driQueryOptionb(config
->options
,
612 "glsl_correct_derivatives_after_discard"))
613 sscreen
->b
.debug_flags
|= DBG(FS_CORRECT_DERIVS_AFTER_KILL
);
614 if (driQueryOptionb(config
->options
, "radeonsi_enable_sisched"))
615 sscreen
->b
.debug_flags
|= DBG(SI_SCHED
);
617 if (!si_common_screen_init(&sscreen
->b
, ws
) ||
618 !si_init_gs_info(sscreen
) ||
619 !si_init_shader_cache(sscreen
)) {
624 si_disk_cache_create(sscreen
);
626 /* Only enable as many threads as we have target machines, but at most
627 * the number of CPUs - 1 if there is more than one.
629 num_threads
= sysconf(_SC_NPROCESSORS_ONLN
);
630 num_threads
= MAX2(1, num_threads
- 1);
631 num_compiler_threads
= MIN2(num_threads
, ARRAY_SIZE(sscreen
->tm
));
632 num_compiler_threads_lowprio
=
633 MIN2(num_threads
, ARRAY_SIZE(sscreen
->tm_low_priority
));
635 if (!util_queue_init(&sscreen
->shader_compiler_queue
, "si_shader",
636 32, num_compiler_threads
,
637 UTIL_QUEUE_INIT_RESIZE_IF_FULL
)) {
638 si_destroy_shader_cache(sscreen
);
643 if (!util_queue_init(&sscreen
->shader_compiler_queue_low_priority
,
645 32, num_compiler_threads_lowprio
,
646 UTIL_QUEUE_INIT_RESIZE_IF_FULL
|
647 UTIL_QUEUE_INIT_USE_MINIMUM_PRIORITY
)) {
648 si_destroy_shader_cache(sscreen
);
653 si_handle_env_var_force_family(sscreen
);
655 if (!debug_get_bool_option("RADEON_DISABLE_PERFCOUNTERS", false))
656 si_init_perfcounters(sscreen
);
658 /* Hawaii has a bug with offchip buffers > 256 that can be worked
659 * around by setting 4K granularity.
661 sscreen
->tess_offchip_block_dw_size
=
662 sscreen
->b
.family
== CHIP_HAWAII
? 4096 : 8192;
664 /* The mere presense of CLEAR_STATE in the IB causes random GPU hangs
666 sscreen
->has_clear_state
= sscreen
->b
.chip_class
>= CIK
;
668 sscreen
->has_distributed_tess
=
669 sscreen
->b
.chip_class
>= VI
&&
670 sscreen
->b
.info
.max_se
>= 2;
672 sscreen
->has_draw_indirect_multi
=
673 (sscreen
->b
.family
>= CHIP_POLARIS10
) ||
674 (sscreen
->b
.chip_class
== VI
&&
675 sscreen
->b
.info
.pfp_fw_version
>= 121 &&
676 sscreen
->b
.info
.me_fw_version
>= 87) ||
677 (sscreen
->b
.chip_class
== CIK
&&
678 sscreen
->b
.info
.pfp_fw_version
>= 211 &&
679 sscreen
->b
.info
.me_fw_version
>= 173) ||
680 (sscreen
->b
.chip_class
== SI
&&
681 sscreen
->b
.info
.pfp_fw_version
>= 79 &&
682 sscreen
->b
.info
.me_fw_version
>= 142);
684 sscreen
->has_out_of_order_rast
= sscreen
->b
.chip_class
>= VI
&&
685 sscreen
->b
.info
.max_se
>= 2 &&
686 !(sscreen
->b
.debug_flags
& DBG(NO_OUT_OF_ORDER
));
687 sscreen
->assume_no_z_fights
=
688 driQueryOptionb(config
->options
, "radeonsi_assume_no_z_fights");
689 sscreen
->commutative_blend_add
=
690 driQueryOptionb(config
->options
, "radeonsi_commutative_blend_add");
691 sscreen
->clear_db_cache_before_clear
=
692 driQueryOptionb(config
->options
, "radeonsi_clear_db_cache_before_clear");
693 sscreen
->has_msaa_sample_loc_bug
= (sscreen
->b
.family
>= CHIP_POLARIS10
&&
694 sscreen
->b
.family
<= CHIP_POLARIS12
) ||
695 sscreen
->b
.family
== CHIP_VEGA10
||
696 sscreen
->b
.family
== CHIP_RAVEN
;
697 sscreen
->has_ls_vgpr_init_bug
= sscreen
->b
.family
== CHIP_VEGA10
||
698 sscreen
->b
.family
== CHIP_RAVEN
;
700 if (sscreen
->b
.debug_flags
& DBG(DPBB
)) {
701 sscreen
->dpbb_allowed
= true;
703 /* Only enable primitive binning on Raven by default. */
704 sscreen
->dpbb_allowed
= sscreen
->b
.family
== CHIP_RAVEN
&&
705 !(sscreen
->b
.debug_flags
& DBG(NO_DPBB
));
708 if (sscreen
->b
.debug_flags
& DBG(DFSM
)) {
709 sscreen
->dfsm_allowed
= sscreen
->dpbb_allowed
;
711 sscreen
->dfsm_allowed
= sscreen
->dpbb_allowed
&&
712 !(sscreen
->b
.debug_flags
& DBG(NO_DFSM
));
715 /* While it would be nice not to have this flag, we are constrained
716 * by the reality that LLVM 5.0 doesn't have working VGPR indexing
719 sscreen
->llvm_has_working_vgpr_indexing
= sscreen
->b
.chip_class
<= VI
;
721 /* Some chips have RB+ registers, but don't support RB+. Those must
724 if (sscreen
->b
.family
== CHIP_STONEY
||
725 sscreen
->b
.chip_class
>= GFX9
) {
726 sscreen
->b
.has_rbplus
= true;
728 sscreen
->b
.rbplus_allowed
=
729 !(sscreen
->b
.debug_flags
& DBG(NO_RB_PLUS
)) &&
730 (sscreen
->b
.family
== CHIP_STONEY
||
731 sscreen
->b
.family
== CHIP_RAVEN
);
734 sscreen
->b
.dcc_msaa_allowed
=
735 !(sscreen
->b
.debug_flags
& DBG(NO_DCC_MSAA
)) &&
736 (sscreen
->b
.debug_flags
& DBG(DCC_MSAA
) ||
737 sscreen
->b
.chip_class
== VI
);
739 (void) mtx_init(&sscreen
->shader_parts_mutex
, mtx_plain
);
740 sscreen
->use_monolithic_shaders
=
741 (sscreen
->b
.debug_flags
& DBG(MONOLITHIC_SHADERS
)) != 0;
743 sscreen
->b
.barrier_flags
.cp_to_L2
= SI_CONTEXT_INV_SMEM_L1
|
744 SI_CONTEXT_INV_VMEM_L1
;
745 if (sscreen
->b
.chip_class
<= VI
) {
746 sscreen
->b
.barrier_flags
.cp_to_L2
|= SI_CONTEXT_INV_GLOBAL_L2
;
747 sscreen
->b
.barrier_flags
.L2_to_cp
|= SI_CONTEXT_WRITEBACK_GLOBAL_L2
;
750 sscreen
->b
.barrier_flags
.compute_to_L2
= SI_CONTEXT_CS_PARTIAL_FLUSH
;
752 if (debug_get_bool_option("RADEON_DUMP_SHADERS", false))
753 sscreen
->b
.debug_flags
|= DBG_ALL_SHADERS
;
755 for (i
= 0; i
< num_compiler_threads
; i
++)
756 sscreen
->tm
[i
] = si_create_llvm_target_machine(sscreen
);
757 for (i
= 0; i
< num_compiler_threads_lowprio
; i
++)
758 sscreen
->tm_low_priority
[i
] = si_create_llvm_target_machine(sscreen
);
760 /* Create the auxiliary context. This must be done last. */
761 sscreen
->b
.aux_context
= si_create_context(&sscreen
->b
.b
, 0);
763 if (sscreen
->b
.debug_flags
& DBG(TEST_DMA
))
764 si_test_dma(sscreen
);
766 if (sscreen
->b
.debug_flags
& (DBG(TEST_VMFAULT_CP
) |
767 DBG(TEST_VMFAULT_SDMA
) |
768 DBG(TEST_VMFAULT_SHADER
)))
769 si_test_vmfault(sscreen
);
771 return &sscreen
->b
.b
;