91
91
{ "norp", ZINK_DEBUG_NORP, "Disable renderpass tracking/optimizations" },
92
92
{ "map", ZINK_DEBUG_MAP, "Track amount of mapped VRAM" },
93
93
{ "flushsync", ZINK_DEBUG_FLUSHSYNC, "Force synchronous flushes/presents" },
94
{ "noshobj", ZINK_DEBUG_NOSHOBJ, "Disable EXT_shader_object" },
95
{ "optimal_keys", ZINK_DEBUG_OPTIMAL_KEYS, "Debug/use optimal_keys" },
96
{ "noopt", ZINK_DEBUG_NOOPT, "Disable async optimized pipeline compiles" },
97
{ "nobgc", ZINK_DEBUG_NOBGC, "Disable all async pipeline compiles" },
98
{ "dgc", ZINK_DEBUG_DGC, "Use DGC (driver testing only)" },
99
{ "mem", ZINK_DEBUG_MEM, "Debug memory allocations" },
94
100
DEBUG_NAMED_VALUE_END
280
286
_mesa_sha1_update(&ctx, &screen->driconf, sizeof(screen->driconf));
288
/* EXT_shader_object causes different descriptor layouts for separate shaders */
289
_mesa_sha1_update(&ctx, &screen->info.have_EXT_shader_object, sizeof(screen->info.have_EXT_shader_object));
282
291
/* Finish the sha1 and format it as text. */
283
292
unsigned char sha1[20];
284
293
_mesa_sha1_final(&ctx, sha1);
286
295
char cache_id[20 * 2 + 1];
287
disk_cache_format_hex_id(cache_id, sha1, 20 * 2);
296
mesa_bytes_to_hex(cache_id, sha1, 20);
289
298
screen->disk_cache = disk_cache_create("zink", cache_id, 0);
313
322
struct zink_program *pg = data;
314
323
struct zink_screen *screen = gdata;
325
u_rwlock_rdlock(&pg->pipeline_cache_lock);
316
326
VkResult result = VKSCR(GetPipelineCacheData)(screen->dev, pg->pipeline_cache, &size, NULL);
317
327
if (result != VK_SUCCESS) {
328
u_rwlock_rdunlock(&pg->pipeline_cache_lock);
318
329
mesa_loge("ZINK: vkGetPipelineCacheData failed (%s)", vk_Result_to_str(result));
321
if (pg->pipeline_cache_size == size)
332
if (pg->pipeline_cache_size == size) {
333
u_rwlock_rdunlock(&pg->pipeline_cache_lock);
323
336
void *pipeline_data = malloc(size);
337
if (!pipeline_data) {
338
u_rwlock_rdunlock(&pg->pipeline_cache_lock);
326
341
result = VKSCR(GetPipelineCacheData)(screen->dev, pg->pipeline_cache, &size, pipeline_data);
342
u_rwlock_rdunlock(&pg->pipeline_cache_lock);
327
343
if (result == VK_SUCCESS) {
328
344
pg->pipeline_cache_size = size;
505
522
case PIPE_CAP_EMULATE_NONFIXED_PRIMITIVE_RESTART:
507
524
case PIPE_CAP_SUPPORTED_PRIM_MODES_WITH_RESTART: {
508
uint32_t modes = BITFIELD_BIT(PIPE_PRIM_LINE_STRIP) |
509
BITFIELD_BIT(PIPE_PRIM_TRIANGLE_STRIP) |
510
BITFIELD_BIT(PIPE_PRIM_LINE_STRIP_ADJACENCY) |
511
BITFIELD_BIT(PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY);
525
uint32_t modes = BITFIELD_BIT(MESA_PRIM_LINE_STRIP) |
526
BITFIELD_BIT(MESA_PRIM_TRIANGLE_STRIP) |
527
BITFIELD_BIT(MESA_PRIM_LINE_STRIP_ADJACENCY) |
528
BITFIELD_BIT(MESA_PRIM_TRIANGLE_STRIP_ADJACENCY);
512
529
if (screen->have_triangle_fans)
513
modes |= BITFIELD_BIT(PIPE_PRIM_TRIANGLE_FAN);
530
modes |= BITFIELD_BIT(MESA_PRIM_TRIANGLE_FAN);
514
531
if (screen->info.have_EXT_primitive_topology_list_restart) {
515
modes |= BITFIELD_BIT(PIPE_PRIM_POINTS) |
516
BITFIELD_BIT(PIPE_PRIM_LINES) |
517
BITFIELD_BIT(PIPE_PRIM_LINES_ADJACENCY) |
518
BITFIELD_BIT(PIPE_PRIM_TRIANGLES) |
519
BITFIELD_BIT(PIPE_PRIM_TRIANGLES_ADJACENCY);
532
modes |= BITFIELD_BIT(MESA_PRIM_POINTS) |
533
BITFIELD_BIT(MESA_PRIM_LINES) |
534
BITFIELD_BIT(MESA_PRIM_LINES_ADJACENCY) |
535
BITFIELD_BIT(MESA_PRIM_TRIANGLES) |
536
BITFIELD_BIT(MESA_PRIM_TRIANGLES_ADJACENCY);
520
537
if (screen->info.list_restart_feats.primitiveTopologyPatchListRestart)
521
modes |= BITFIELD_BIT(PIPE_PRIM_PATCHES);
538
modes |= BITFIELD_BIT(MESA_PRIM_PATCHES);
525
542
case PIPE_CAP_SUPPORTED_PRIM_MODES: {
526
uint32_t modes = BITFIELD_MASK(PIPE_PRIM_MAX);
527
modes &= ~BITFIELD_BIT(PIPE_PRIM_QUAD_STRIP);
528
modes &= ~BITFIELD_BIT(PIPE_PRIM_POLYGON);
529
modes &= ~BITFIELD_BIT(PIPE_PRIM_LINE_LOOP);
543
uint32_t modes = BITFIELD_MASK(MESA_PRIM_COUNT);
544
modes &= ~BITFIELD_BIT(MESA_PRIM_QUAD_STRIP);
545
modes &= ~BITFIELD_BIT(MESA_PRIM_POLYGON);
546
modes &= ~BITFIELD_BIT(MESA_PRIM_LINE_LOOP);
530
547
if (!screen->have_triangle_fans)
531
modes &= ~BITFIELD_BIT(PIPE_PRIM_TRIANGLE_FAN);
548
modes &= ~BITFIELD_BIT(MESA_PRIM_TRIANGLE_FAN);
2621
/* these drivers have no difference between unoptimized and optimized shader compilation */
2622
switch (screen->info.driver_props.driverID) {
2623
case VK_DRIVER_ID_MESA_LLVMPIPE:
2624
screen->driver_workarounds.disable_optimized_compile = true;
2627
if (zink_debug & ZINK_DEBUG_NOOPT)
2628
screen->driver_workarounds.disable_optimized_compile = true;
2634
init_optimal_keys(struct zink_screen *screen)
2636
screen->optimal_keys = !screen->need_decompose_attrs &&
2637
screen->info.have_EXT_non_seamless_cube_map &&
2638
screen->info.have_EXT_provoking_vertex &&
2639
!screen->driconf.inline_uniforms &&
2640
!screen->driver_workarounds.no_linestipple &&
2641
!screen->driver_workarounds.no_linesmooth &&
2642
!screen->driver_workarounds.no_hw_gl_point &&
2643
!screen->driver_workarounds.lower_robustImageAccess2 &&
2644
!screen->driconf.emulate_point_smooth &&
2645
!screen->driver_workarounds.needs_zs_shader_swizzle;
2646
if (!screen->optimal_keys && zink_debug & ZINK_DEBUG_OPTIMAL_KEYS) {
2647
fprintf(stderr, "The following criteria are preventing optimal_keys enablement:");
2648
if (screen->need_decompose_attrs)
2649
fprintf(stderr, "missing vertex attribute formats\n");
2650
if (screen->driconf.inline_uniforms)
2651
fprintf(stderr, "uniform inlining must be disabled (set ZINK_INLINE_UNIFORMS=0 in your env)\n");
2652
CHECK_OR_PRINT(have_EXT_line_rasterization);
2653
CHECK_OR_PRINT(line_rast_feats.stippledBresenhamLines);
2654
CHECK_OR_PRINT(feats.features.geometryShader);
2655
CHECK_OR_PRINT(feats.features.sampleRateShading);
2656
CHECK_OR_PRINT(have_EXT_non_seamless_cube_map);
2657
CHECK_OR_PRINT(have_EXT_provoking_vertex);
2658
if (screen->driver_workarounds.no_linesmooth)
2659
fprintf(stderr, "driver does not support smooth lines\n");
2660
if (screen->driver_workarounds.no_hw_gl_point)
2661
fprintf(stderr, "driver does not support hardware GL_POINT\n");
2662
CHECK_OR_PRINT(rb2_feats.robustImageAccess2);
2663
CHECK_OR_PRINT(feats.features.robustBufferAccess);
2664
CHECK_OR_PRINT(rb_image_feats.robustImageAccess);
2665
if (screen->driconf.emulate_point_smooth)
2666
fprintf(stderr, "smooth point emulation is enabled\n");
2667
if (screen->driver_workarounds.needs_zs_shader_swizzle)
2668
fprintf(stderr, "Z/S shader swizzle workaround is enabled\n");
2669
mesa_logw("zink: force-enabling optimal_keys despite missing features. Good luck!");
2670
screen->optimal_keys = true;
2672
if (!screen->optimal_keys)
2673
screen->info.have_EXT_graphics_pipeline_library = false;
2675
if (!screen->optimal_keys ||
2676
/* EXT_shader_object needs either dynamic feedback loop or per-app enablement */
2677
(!screen->driconf.zink_shader_object_enable && !screen->info.have_EXT_attachment_feedback_loop_dynamic_state))
2678
screen->info.have_EXT_shader_object = false;
2679
if (screen->info.have_EXT_shader_object)
2680
screen->have_full_ds3 = true;
2681
if (zink_debug & ZINK_DEBUG_DGC) {
2682
if (!screen->optimal_keys) {
2683
mesa_loge("zink: can't DGC without optimal_keys!");
2684
zink_debug &= ~ZINK_DEBUG_DGC;
2686
screen->info.have_EXT_multi_draw = false;
2687
screen->info.have_EXT_shader_object = false;
2688
screen->info.have_EXT_graphics_pipeline_library = false;
2689
screen->info.have_EXT_vertex_input_dynamic_state = false;
2580
2694
static struct disk_cache *
2689
2803
struct zink_screen *screen = rzalloc(NULL, struct zink_screen);
2805
mesa_loge("ZINK: failed to allocate screen");
2693
2809
zink_debug = debug_get_option_zink_debug();
2694
zink_descriptor_mode = debug_get_option_zink_descriptor_mode();
2810
if (zink_descriptor_mode == ZINK_DESCRIPTOR_MODE_AUTO)
2811
zink_descriptor_mode = debug_get_option_zink_descriptor_mode();
2696
2813
screen->threaded = util_get_cpu_caps()->nr_cpus > 1 && debug_get_bool_option("GALLIUM_THREAD", util_get_cpu_caps()->nr_cpus > 1);
2697
2814
if (zink_debug & ZINK_DEBUG_FLUSHSYNC)
2704
2821
u_trace_state_init();
2706
2823
screen->loader_lib = util_dl_open(VK_LIBNAME);
2707
if (!screen->loader_lib)
2824
if (!screen->loader_lib) {
2825
mesa_loge("ZINK: failed to load "VK_LIBNAME);
2710
2829
screen->vk_GetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)util_dl_get_proc_address(screen->loader_lib, "vkGetInstanceProcAddr");
2711
2830
screen->vk_GetDeviceProcAddr = (PFN_vkGetDeviceProcAddr)util_dl_get_proc_address(screen->loader_lib, "vkGetDeviceProcAddr");
2712
2831
if (!screen->vk_GetInstanceProcAddr ||
2713
!screen->vk_GetDeviceProcAddr)
2832
!screen->vk_GetDeviceProcAddr) {
2833
mesa_loge("ZINK: failed to get proc address");
2716
2837
screen->instance_info.loader_version = zink_get_loader_version(screen);
2778
2902
mesa_loge("zink: KHR_timeline_semaphore is required");
2905
if (zink_debug & ZINK_DEBUG_DGC) {
2906
if (!screen->info.have_NV_device_generated_commands) {
2907
mesa_loge("zink: can't use DGC without NV_device_generated_commands");
2912
if (zink_debug & ZINK_DEBUG_MEM) {
2913
simple_mtx_init(&screen->debug_mem_lock, mtx_plain);
2914
screen->debug_mem_sizes = _mesa_hash_table_create(screen, _mesa_hash_string, _mesa_key_string_equal);
2782
2917
init_driver_workarounds(screen);
2888
3023
if (!zink_screen_resource_init(&screen->base))
2890
zink_bo_init(screen);
3025
if (!zink_bo_init(screen)) {
3026
mesa_loge("ZINK: failed to initialize suballocator");
2891
3029
zink_screen_fence_init(&screen->base);
2893
3031
zink_screen_init_compiler(screen);
2894
if (!disk_cache_init(screen))
3032
if (!disk_cache_init(screen)) {
3033
mesa_loge("ZINK: failed to initialize disk cache");
2896
3036
if (!util_queue_init(&screen->cache_get_thread, "zcfq", 8, 4,
2897
3037
UTIL_QUEUE_INIT_RESIZE_IF_FULL | UTIL_QUEUE_INIT_SCALE_THREADS, screen))
2901
3041
slab_create_parent(&screen->transfer_pool, sizeof(struct zink_transfer), 16);
2903
screen->driconf.inline_uniforms = debug_get_bool_option("ZINK_INLINE_UNIFORMS", screen->is_cpu);
3043
screen->driconf.inline_uniforms = debug_get_bool_option("ZINK_INLINE_UNIFORMS", screen->is_cpu) && !(zink_debug & ZINK_DEBUG_DGC);
2905
3045
screen->total_video_mem = get_video_mem(screen);
2906
3046
screen->clamp_video_mem = screen->total_video_mem * 0.8;
2907
if (!os_get_total_physical_memory(&screen->total_mem))
3047
if (!os_get_total_physical_memory(&screen->total_mem)) {
3048
mesa_loge("ZINK: failed to get total physical memory");
2910
3052
if (!zink_screen_init_semaphore(screen)) {
2911
3053
mesa_loge("zink: failed to create timeline semaphore");
2926
3068
/* not found: use compatible heap */
2927
3069
if (screen->heap_map[i][0] == UINT8_MAX) {
2928
3070
/* only cached mem has a failure case for now */
2929
assert(i == ZINK_HEAP_HOST_VISIBLE_CACHED || i == ZINK_HEAP_DEVICE_LOCAL_LAZY ||
3071
assert(i == ZINK_HEAP_HOST_VISIBLE_COHERENT_CACHED || i == ZINK_HEAP_DEVICE_LOCAL_LAZY ||
2930
3072
i == ZINK_HEAP_DEVICE_LOCAL_VISIBLE);
2931
if (i == ZINK_HEAP_HOST_VISIBLE_CACHED) {
3073
if (i == ZINK_HEAP_HOST_VISIBLE_COHERENT_CACHED) {
2932
3074
memcpy(screen->heap_map[i], screen->heap_map[ZINK_HEAP_HOST_VISIBLE_COHERENT], screen->heap_count[ZINK_HEAP_HOST_VISIBLE_COHERENT]);
2933
3075
screen->heap_count[i] = screen->heap_count[ZINK_HEAP_HOST_VISIBLE_COHERENT];
3048
3190
zink_init_screen_pipeline_libs(screen);
3050
if (!init_layouts(screen))
3192
if (!init_layouts(screen)) {
3193
mesa_loge("ZINK: failed to initialize layouts");
3053
if (!zink_descriptor_layouts_init(screen))
3197
if (!zink_descriptor_layouts_init(screen)) {
3198
mesa_loge("ZINK: failed to initialize descriptor layouts");
3056
3202
simple_mtx_init(&screen->copy_context_lock, mtx_plain);
3058
screen->optimal_keys = !screen->need_decompose_attrs &&
3059
screen->info.have_EXT_non_seamless_cube_map &&
3060
screen->info.have_EXT_provoking_vertex &&
3061
!screen->driconf.inline_uniforms &&
3062
!screen->driver_workarounds.no_linestipple &&
3063
!screen->driver_workarounds.no_linesmooth &&
3064
!screen->driver_workarounds.no_hw_gl_point &&
3065
!screen->driver_workarounds.lower_robustImageAccess2 &&
3066
!screen->driconf.emulate_point_smooth &&
3067
!screen->driver_workarounds.needs_zs_shader_swizzle;
3068
if (!screen->optimal_keys)
3069
screen->info.have_EXT_graphics_pipeline_library = false;
3204
init_optimal_keys(screen);
3071
3206
screen->screen_id = p_atomic_inc_return(&num_screens);
3072
3207
zink_tracing = screen->instance_info.have_EXT_debug_utils &&