Path: blob/21.2-virgl/src/virtio/vulkan/vn_common.c
4560 views
/*1* Copyright 2019 Google LLC2* SPDX-License-Identifier: MIT3*4* based in part on anv and radv which are:5* Copyright © 2015 Intel Corporation6* Copyright © 2016 Red Hat.7* Copyright © 2016 Bas Nieuwenhuizen8*/910#include "vn_common.h"1112#include <stdarg.h>1314#include "util/debug.h"15#include "util/log.h"16#include "util/os_misc.h"17#include "vk_enum_to_str.h"1819static const struct debug_control vn_debug_options[] = {20{ "init", VN_DEBUG_INIT },21{ "result", VN_DEBUG_RESULT },22{ "vtest", VN_DEBUG_VTEST },23{ "wsi", VN_DEBUG_WSI },24{ NULL, 0 },25};2627uint64_t vn_debug;2829static void30vn_debug_init_once(void)31{32vn_debug = parse_debug_string(os_get_option("VN_DEBUG"), vn_debug_options);33}3435void36vn_debug_init(void)37{38static once_flag once = ONCE_FLAG_INIT;39call_once(&once, vn_debug_init_once);40}4142void43vn_log(struct vn_instance *instance, const char *format, ...)44{45va_list ap;4647va_start(ap, format);48mesa_log_v(MESA_LOG_DEBUG, "MESA-VIRTIO", format, ap);49va_end(ap);5051/* instance may be NULL or partially initialized */52}5354VkResult55vn_log_result(struct vn_instance *instance,56VkResult result,57const char *where)58{59vn_log(instance, "%s: %s", where, vk_Result_to_str(result));60return result;61}6263void64vn_relax(uint32_t *iter)65{66const uint32_t busy_wait_order = 4;67const uint32_t base_sleep_us = 10;6869(*iter)++;70if (*iter < (1 << busy_wait_order)) {71thrd_yield();72return;73}7475const uint32_t shift = util_last_bit(*iter) - busy_wait_order - 1;76os_time_sleep(base_sleep_us << shift);77}787980