tangled
alpha
login
or
join now
matrixfurry.com
/
monado
0
fork
atom
The open source OpenXR runtime
0
fork
atom
overview
issues
pulls
pipelines
a/vk: Add vk_surface_info helpers
Jakob Bornecrantz
2 years ago
622e09bc
5432e4c1
+286
3 changed files
expand all
collapse all
unified
split
src
xrt
auxiliary
vk
CMakeLists.txt
vk_surface_info.c
vk_surface_info.h
+2
src/xrt/auxiliary/vk/CMakeLists.txt
···
19
19
vk_image_readback_to_xf_pool.h
20
20
vk_print.c
21
21
vk_state_creators.c
22
22
+
vk_surface_info.c
23
23
+
vk_surface_info.h
22
24
vk_sync_objects.c
23
25
vk_time.c
24
26
)
+214
src/xrt/auxiliary/vk/vk_surface_info.c
···
1
1
+
// Copyright 2019-2023, Collabora, Ltd.
2
2
+
// SPDX-License-Identifier: BSL-1.0
3
3
+
/*!
4
4
+
* @file
5
5
+
* @brief Helper for getting information from a VkSurfaceKHR.
6
6
+
* @author Jakob Bornecrantz <jakob@collabora.com>
7
7
+
* @ingroup aux_vk
8
8
+
*/
9
9
+
10
10
+
#include "util/u_pretty_print.h"
11
11
+
#include "vk_surface_info.h"
12
12
+
13
13
+
14
14
+
/*
15
15
+
*
16
16
+
* Helpers.
17
17
+
*
18
18
+
*/
19
19
+
20
20
+
#define P(...) u_pp(dg, __VA_ARGS__)
21
21
+
#define PNT(...) u_pp(dg, "\n\t" __VA_ARGS__)
22
22
+
#define PNTT(...) u_pp(dg, "\n\t\t" __VA_ARGS__)
23
23
+
24
24
+
XRT_CHECK_RESULT static VkResult
25
25
+
surface_info_get_present_modes(struct vk_bundle *vk, struct vk_surface_info *info, VkSurfaceKHR surface)
26
26
+
{
27
27
+
VkResult ret;
28
28
+
29
29
+
assert(info->present_modes == NULL);
30
30
+
assert(info->present_mode_count == 0);
31
31
+
32
32
+
ret = vk->vkGetPhysicalDeviceSurfacePresentModesKHR( //
33
33
+
vk->physical_device, //
34
34
+
surface, //
35
35
+
&info->present_mode_count, //
36
36
+
NULL); //
37
37
+
if (ret != VK_SUCCESS) {
38
38
+
VK_ERROR(vk, "vkGetPhysicalDeviceSurfacePresentModesKHR: %s", vk_result_string(ret));
39
39
+
return ret;
40
40
+
}
41
41
+
// Nothing to do.
42
42
+
if (info->present_mode_count == 0) {
43
43
+
return VK_SUCCESS;
44
44
+
}
45
45
+
46
46
+
info->present_modes = U_TYPED_ARRAY_CALLOC(VkPresentModeKHR, info->present_mode_count);
47
47
+
ret = vk->vkGetPhysicalDeviceSurfacePresentModesKHR( //
48
48
+
vk->physical_device, //
49
49
+
surface, //
50
50
+
&info->present_mode_count, //
51
51
+
info->present_modes); //
52
52
+
if (ret == VK_SUCCESS) {
53
53
+
return ret;
54
54
+
}
55
55
+
56
56
+
free(info->present_modes);
57
57
+
info->present_mode_count = 0;
58
58
+
info->present_modes = NULL;
59
59
+
60
60
+
VK_ERROR(vk, "vkGetPhysicalDeviceSurfacePresentModesKHR: %s", vk_result_string(ret));
61
61
+
62
62
+
return ret;
63
63
+
}
64
64
+
65
65
+
XRT_CHECK_RESULT static VkResult
66
66
+
surface_info_get_surface_formats(struct vk_bundle *vk, struct vk_surface_info *info, VkSurfaceKHR surface)
67
67
+
{
68
68
+
VkResult ret;
69
69
+
70
70
+
assert(info->formats == NULL);
71
71
+
assert(info->format_count == 0);
72
72
+
73
73
+
ret = vk->vkGetPhysicalDeviceSurfaceFormatsKHR( //
74
74
+
vk->physical_device, //
75
75
+
surface, //
76
76
+
&info->format_count, //
77
77
+
NULL); //
78
78
+
if (ret != VK_SUCCESS) {
79
79
+
VK_ERROR(vk, "vkGetPhysicalDeviceSurfaceFormatsKHR: %s", vk_result_string(ret));
80
80
+
return ret;
81
81
+
}
82
82
+
// Nothing to do.
83
83
+
if (info->format_count == 0) {
84
84
+
return VK_SUCCESS;
85
85
+
}
86
86
+
87
87
+
info->formats = U_TYPED_ARRAY_CALLOC(VkSurfaceFormatKHR, info->format_count);
88
88
+
ret = vk->vkGetPhysicalDeviceSurfaceFormatsKHR( //
89
89
+
vk->physical_device, //
90
90
+
surface, //
91
91
+
&info->format_count, //
92
92
+
info->formats); //
93
93
+
if (ret == VK_SUCCESS) {
94
94
+
return ret;
95
95
+
}
96
96
+
97
97
+
free(info->formats);
98
98
+
info->format_count = 0;
99
99
+
info->formats = NULL;
100
100
+
101
101
+
VK_ERROR(vk, "vkGetPhysicalDeviceSurfaceFormatsKHR: %s", vk_result_string(ret));
102
102
+
103
103
+
return ret;
104
104
+
}
105
105
+
106
106
+
107
107
+
/*
108
108
+
*
109
109
+
* 'Exported' functions.
110
110
+
*
111
111
+
*/
112
112
+
113
113
+
void
114
114
+
vk_surface_info_destroy(struct vk_surface_info *info)
115
115
+
{
116
116
+
if (info->present_modes != NULL) {
117
117
+
free(info->present_modes);
118
118
+
info->present_mode_count = 0;
119
119
+
info->present_modes = NULL;
120
120
+
}
121
121
+
122
122
+
if (info->formats != NULL) {
123
123
+
free(info->formats);
124
124
+
info->format_count = 0;
125
125
+
info->formats = NULL;
126
126
+
}
127
127
+
128
128
+
U_ZERO(info);
129
129
+
}
130
130
+
131
131
+
XRT_CHECK_RESULT VkResult
132
132
+
vk_surface_info_fill_in(struct vk_bundle *vk, struct vk_surface_info *info, VkSurfaceKHR surface)
133
133
+
{
134
134
+
VkResult ret;
135
135
+
136
136
+
ret = surface_info_get_present_modes(vk, info, surface);
137
137
+
if (ret != VK_SUCCESS) {
138
138
+
VK_ERROR(vk, "surface_info_get_present_modes: %s", vk_result_string(ret));
139
139
+
goto error;
140
140
+
}
141
141
+
142
142
+
ret = surface_info_get_surface_formats(vk, info, surface);
143
143
+
if (ret != VK_SUCCESS) {
144
144
+
VK_ERROR(vk, "surface_info_get_surface_formats: %s", vk_result_string(ret));
145
145
+
goto error;
146
146
+
}
147
147
+
148
148
+
ret = vk->vkGetPhysicalDeviceSurfaceCapabilitiesKHR( //
149
149
+
vk->physical_device, //
150
150
+
surface, //
151
151
+
&info->caps); //
152
152
+
if (ret != VK_SUCCESS) {
153
153
+
VK_ERROR(vk, "vkGetPhysicalDeviceSurfaceCapabilitiesKHR: %s", vk_result_string(ret));
154
154
+
goto error;
155
155
+
}
156
156
+
157
157
+
#ifdef VK_EXT_display_surface_counter
158
158
+
if (vk->has_EXT_display_control) {
159
159
+
info->caps2.sType = VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_EXT;
160
160
+
ret = vk->vkGetPhysicalDeviceSurfaceCapabilities2EXT( //
161
161
+
vk->physical_device, //
162
162
+
surface, //
163
163
+
&info->caps2); //
164
164
+
if (ret != VK_SUCCESS) {
165
165
+
VK_ERROR(vk, "vkGetPhysicalDeviceSurfaceCapabilities2EXT: %s", vk_result_string(ret));
166
166
+
goto error;
167
167
+
}
168
168
+
}
169
169
+
#endif
170
170
+
171
171
+
return VK_SUCCESS;
172
172
+
173
173
+
error:
174
174
+
vk_surface_info_destroy(info);
175
175
+
176
176
+
return ret;
177
177
+
}
178
178
+
179
179
+
void
180
180
+
vk_print_surface_info(struct vk_bundle *vk, struct vk_surface_info *info, enum u_logging_level log_level)
181
181
+
{
182
182
+
if (vk->log_level > log_level) {
183
183
+
return;
184
184
+
}
185
185
+
186
186
+
struct u_pp_sink_stack_only sink;
187
187
+
u_pp_delegate_t dg = u_pp_sink_stack_only_init(&sink);
188
188
+
189
189
+
P("VkSurfaceKHR info:");
190
190
+
PNT("caps.minImageCount: %u", info->caps.minImageCount);
191
191
+
PNT("caps.maxImageCount: %u", info->caps.maxImageCount);
192
192
+
PNT("caps.currentExtent: %ux%u", info->caps.currentExtent.width, info->caps.currentExtent.height);
193
193
+
PNT("caps.minImageExtent: %ux%u", info->caps.minImageExtent.width, info->caps.minImageExtent.height);
194
194
+
PNT("caps.maxImageExtent: %ux%u", info->caps.maxImageExtent.width, info->caps.maxImageExtent.height);
195
195
+
PNT("caps.maxImageArrayLayers: %u", info->caps.maxImageArrayLayers);
196
196
+
// PNT("caps.supportedTransforms")
197
197
+
// PNT("caps.currentTransform")
198
198
+
// PNT("caps.supportedCompositeAlpha")
199
199
+
// PNT("caps.supportedUsageFlags")
200
200
+
201
201
+
PNT("present_modes(%u):", info->present_mode_count);
202
202
+
for (uint32_t i = 0; i < info->present_mode_count; i++) {
203
203
+
PNTT("%s", vk_present_mode_string(info->present_modes[i]));
204
204
+
}
205
205
+
206
206
+
PNT("formats(%u):", info->format_count);
207
207
+
for (uint32_t i = 0; i < info->format_count; i++) {
208
208
+
VkSurfaceFormatKHR *f = &info->formats[i];
209
209
+
PNTT("[format = %s, colorSpace = %s]", vk_format_string(f->format),
210
210
+
vk_color_space_string(f->colorSpace));
211
211
+
}
212
212
+
213
213
+
U_LOG_IFL(log_level, vk->log_level, "%s", sink.buffer);
214
214
+
}
+70
src/xrt/auxiliary/vk/vk_surface_info.h
···
1
1
+
// Copyright 2019-2023, Collabora, Ltd.
2
2
+
// SPDX-License-Identifier: BSL-1.0
3
3
+
/*!
4
4
+
* @file
5
5
+
* @brief Helper for getting information from a VkSurfaceKHR.
6
6
+
* @author Jakob Bornecrantz <jakob@collabora.com>
7
7
+
* @ingroup aux_vk
8
8
+
*/
9
9
+
10
10
+
#pragma once
11
11
+
12
12
+
#include "vk/vk_helpers.h"
13
13
+
14
14
+
15
15
+
#ifdef __cplusplus
16
16
+
extern "C" {
17
17
+
#endif
18
18
+
19
19
+
20
20
+
/*
21
21
+
*
22
22
+
* Struct(s).
23
23
+
*
24
24
+
*/
25
25
+
26
26
+
struct vk_surface_info
27
27
+
{
28
28
+
VkPresentModeKHR *present_modes;
29
29
+
VkSurfaceFormatKHR *formats;
30
30
+
31
31
+
uint32_t present_mode_count;
32
32
+
uint32_t format_count;
33
33
+
34
34
+
VkSurfaceCapabilitiesKHR caps;
35
35
+
36
36
+
#ifdef VK_EXT_display_surface_counter
37
37
+
VkSurfaceCapabilities2EXT caps2;
38
38
+
#endif
39
39
+
};
40
40
+
41
41
+
42
42
+
/*
43
43
+
*
44
44
+
* Functions.
45
45
+
*
46
46
+
*/
47
47
+
48
48
+
/*!
49
49
+
* Free all lists allocated by @ref vk_surface_info.
50
50
+
*/
51
51
+
void
52
52
+
vk_surface_info_destroy(struct vk_surface_info *info);
53
53
+
54
54
+
/*!
55
55
+
* Fill in the given @ref vk_surface_info, will allocate lists.
56
56
+
*/
57
57
+
XRT_CHECK_RESULT VkResult
58
58
+
vk_surface_info_fill_in(struct vk_bundle *vk, struct vk_surface_info *info, VkSurfaceKHR surface);
59
59
+
60
60
+
/*!
61
61
+
* Print out the gathered information about the
62
62
+
* surface given to @ref vk_surface_info_fill_in.
63
63
+
*/
64
64
+
void
65
65
+
vk_print_surface_info(struct vk_bundle *vk, struct vk_surface_info *info, enum u_logging_level log_level);
66
66
+
67
67
+
68
68
+
#ifdef __cplusplus
69
69
+
}
70
70
+
#endif