Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/virtio/vulkan/vn_common.c
4560 views
1
/*
2
* Copyright 2019 Google LLC
3
* SPDX-License-Identifier: MIT
4
*
5
* based in part on anv and radv which are:
6
* Copyright © 2015 Intel Corporation
7
* Copyright © 2016 Red Hat.
8
* Copyright © 2016 Bas Nieuwenhuizen
9
*/
10
11
#include "vn_common.h"
12
13
#include <stdarg.h>
14
15
#include "util/debug.h"
16
#include "util/log.h"
17
#include "util/os_misc.h"
18
#include "vk_enum_to_str.h"
19
20
static const struct debug_control vn_debug_options[] = {
21
{ "init", VN_DEBUG_INIT },
22
{ "result", VN_DEBUG_RESULT },
23
{ "vtest", VN_DEBUG_VTEST },
24
{ "wsi", VN_DEBUG_WSI },
25
{ NULL, 0 },
26
};
27
28
uint64_t vn_debug;
29
30
static void
31
vn_debug_init_once(void)
32
{
33
vn_debug = parse_debug_string(os_get_option("VN_DEBUG"), vn_debug_options);
34
}
35
36
void
37
vn_debug_init(void)
38
{
39
static once_flag once = ONCE_FLAG_INIT;
40
call_once(&once, vn_debug_init_once);
41
}
42
43
void
44
vn_log(struct vn_instance *instance, const char *format, ...)
45
{
46
va_list ap;
47
48
va_start(ap, format);
49
mesa_log_v(MESA_LOG_DEBUG, "MESA-VIRTIO", format, ap);
50
va_end(ap);
51
52
/* instance may be NULL or partially initialized */
53
}
54
55
VkResult
56
vn_log_result(struct vn_instance *instance,
57
VkResult result,
58
const char *where)
59
{
60
vn_log(instance, "%s: %s", where, vk_Result_to_str(result));
61
return result;
62
}
63
64
void
65
vn_relax(uint32_t *iter)
66
{
67
const uint32_t busy_wait_order = 4;
68
const uint32_t base_sleep_us = 10;
69
70
(*iter)++;
71
if (*iter < (1 << busy_wait_order)) {
72
thrd_yield();
73
return;
74
}
75
76
const uint32_t shift = util_last_bit(*iter) - busy_wait_order - 1;
77
os_time_sleep(base_sleep_us << shift);
78
}
79
80