1 /*
2 * GStreamer
3 * Copyright (C) 2019 Matthew Waters <matthew@centricular.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <glib/gprintf.h>
26
27 #include "gstvkerror.h"
28 #include "gstvkdebug.h"
29 #include "gstvkdebug-private.h"
30
31 /**
32 * SECTION:vkdebug
33 * @title: GstVulkanDebug
34 * @short_description: Vulkan debugging utilities
35 * @see_also: #GstVulkanDevice
36 */
37
38 #define FLAGS_TO_STRING(under_name, VkType) \
39 gchar * G_PASTE(G_PASTE(gst_vulkan_,under_name),_flags_to_string) (VkType flag_bits) \
40 { \
41 GString *s = g_string_new (NULL); \
42 gboolean first = TRUE; \
43 int i; \
44 for (i = 0; i < G_N_ELEMENTS (G_PASTE(G_PASTE(vk_,under_name),_flags_map)); i++) { \
45 if (flag_bits & G_PASTE(G_PASTE(vk_,under_name),_flags_map)[i].flag_bit) { \
46 if (!first) { \
47 g_string_append (s, "|"); \
48 } \
49 g_string_append (s, G_PASTE(G_PASTE(vk_,under_name),_flags_map)[i].str); \
50 first = FALSE; \
51 } \
52 } \
53 return g_string_free (s, FALSE); \
54 }
55
56 /* *INDENT-OFF* */
57 static const struct
58 {
59 VkMemoryPropertyFlagBits flag_bit;
60 const char *str;
61 } vk_memory_property_flags_map[] = {
62 {VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, "device-local"},
63 {VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, "host-visible"},
64 {VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, "host-coherent"},
65 {VK_MEMORY_PROPERTY_HOST_CACHED_BIT, "host-cached"},
66 {VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT, "lazily-allocated"},
67 #if VK_HEADER_VERSION >= 70
68 {VK_MEMORY_PROPERTY_PROTECTED_BIT, "protected"},
69 #endif
70 #if VK_HEADER_VERSION >= 121
71 {VK_MEMORY_PROPERTY_DEVICE_COHERENT_BIT_AMD, "device-coherent"},
72 {VK_MEMORY_PROPERTY_DEVICE_UNCACHED_BIT_AMD, "device-uncached"},
73 #endif
74 };
75 /**
76 * gst_vulkan_memory_property_flags_to_string:
77 *
78 * Since: 1.18
79 */
80 FLAGS_TO_STRING(memory_property, VkMemoryPropertyFlags);
81
82 static const struct
83 {
84 VkMemoryHeapFlagBits flag_bit;
85 const char *str;
86 } vk_memory_heap_flags_map[] = {
87 {VK_MEMORY_HEAP_DEVICE_LOCAL_BIT, "device-local"},
88 #if VK_HEADER_VERSION >= 70
89 {VK_MEMORY_HEAP_MULTI_INSTANCE_BIT, "multi-instance"},
90 #endif
91 };
92 /**
93 * gst_vulkan_memory_heap_flags_to_string:
94 *
95 * Since: 1.18
96 */
97 FLAGS_TO_STRING(memory_heap, VkMemoryHeapFlagBits);
98
99 static const struct
100 {
101 VkQueueFlagBits flag_bit;
102 const char *str;
103 } vk_queue_flags_map[] = {
104 {VK_QUEUE_GRAPHICS_BIT, "graphics"},
105 {VK_QUEUE_COMPUTE_BIT, "compute"},
106 {VK_QUEUE_TRANSFER_BIT, "transfer"},
107 {VK_QUEUE_SPARSE_BINDING_BIT, "sparse-binding"},
108 #if VK_HEADER_VERSION >= 70
109 {VK_QUEUE_PROTECTED_BIT, "protected"},
110 #endif
111 };
112 /**
113 * gst_vulkan_queue_flags_to_string:
114 *
115 * Since: 1.18
116 */
117 FLAGS_TO_STRING(queue, VkQueueFlags);
118
119 static const struct
120 {
121 VkSampleCountFlagBits flag_bit;
122 const char *str;
123 } vk_sample_count_flags_map[] = {
124 {VK_SAMPLE_COUNT_1_BIT, "1"},
125 {VK_SAMPLE_COUNT_2_BIT, "2"},
126 {VK_SAMPLE_COUNT_4_BIT, "4"},
127 {VK_SAMPLE_COUNT_8_BIT, "8"},
128 {VK_SAMPLE_COUNT_16_BIT, "16"},
129 {VK_SAMPLE_COUNT_32_BIT, "32"},
130 {VK_SAMPLE_COUNT_64_BIT, "64"},
131 };
132 /**
133 * gst_vulkan_sample_count_flags_to_string:
134 *
135 * Since: 1.18
136 */
137 FLAGS_TO_STRING(sample_count, VkSampleCountFlags);
138 /* *INDENT-ON* */
139
140 /**
141 * gst_vulkan_physical_device_type_to_string:
142 * @type: a `VkPhysicalDeviceType
143 *
144 * Returns: name of @type
145 *
146 * Since: 1.18
147 */
148 const gchar *
gst_vulkan_physical_device_type_to_string(VkPhysicalDeviceType type)149 gst_vulkan_physical_device_type_to_string (VkPhysicalDeviceType type)
150 {
151 switch (type) {
152 case VK_PHYSICAL_DEVICE_TYPE_OTHER:
153 return "other";
154 case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
155 return "integrated";
156 case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
157 return "discrete";
158 case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU:
159 return "virtual";
160 case VK_PHYSICAL_DEVICE_TYPE_CPU:
161 return "CPU";
162 default:
163 return "unknown";
164 }
165 }
166
167 /**
168 * gst_vulkan_present_mode_to_string:
169 * @present_mode: a `VkPresentModeKHR`
170 *
171 * Returns: name of @present_mode
172 *
173 * Since: 1.20
174 */
175 const gchar *
gst_vulkan_present_mode_to_string(VkPresentModeKHR present_mode)176 gst_vulkan_present_mode_to_string (VkPresentModeKHR present_mode)
177 {
178 switch (present_mode) {
179 case VK_PRESENT_MODE_FIFO_KHR:
180 return "FIFO";
181 case VK_PRESENT_MODE_IMMEDIATE_KHR:
182 return "immediate";
183 case VK_PRESENT_MODE_MAILBOX_KHR:
184 return "mailbox";
185 /* XXX: add other values as necessary */
186 default:
187 return "unknown";
188 }
189 }
190