1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
/*
* Copyright © 2021 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "vk_physical_device.h"
#include "vk_common_entrypoints.h"
#include "vk_util.h"
VkResult
vk_physical_device_init(struct vk_physical_device *pdevice,
struct vk_instance *instance,
const struct vk_device_extension_table *supported_extensions,
const struct vk_physical_device_dispatch_table *dispatch_table)
{
memset(pdevice, 0, sizeof(*pdevice));
vk_object_base_init(NULL, &pdevice->base, VK_OBJECT_TYPE_PHYSICAL_DEVICE);
pdevice->instance = instance;
if (supported_extensions != NULL)
pdevice->supported_extensions = *supported_extensions;
pdevice->dispatch_table = *dispatch_table;
/* Add common entrypoints without overwriting driver-provided ones. */
vk_physical_device_dispatch_table_from_entrypoints(
&pdevice->dispatch_table, &vk_common_physical_device_entrypoints, false);
return VK_SUCCESS;
}
void
vk_physical_device_finish(struct vk_physical_device *physical_device)
{
vk_object_base_finish(&physical_device->base);
}
VKAPI_ATTR VkResult VKAPI_CALL
vk_common_EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice,
uint32_t *pPropertyCount,
VkLayerProperties *pProperties)
{
if (pProperties == NULL) {
*pPropertyCount = 0;
return VK_SUCCESS;
}
/* None supported at this time */
return VK_ERROR_LAYER_NOT_PRESENT;
}
VKAPI_ATTR VkResult VKAPI_CALL
vk_common_EnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
const char *pLayerName,
uint32_t *pPropertyCount,
VkExtensionProperties *pProperties)
{
VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice);
VK_OUTARRAY_MAKE_TYPED(VkExtensionProperties, out, pProperties, pPropertyCount);
for (int i = 0; i < VK_DEVICE_EXTENSION_COUNT; i++) {
if (!pdevice->supported_extensions.extensions[i])
continue;
#ifdef ANDROID
if (!vk_android_allowed_device_extensions.extensions[i])
continue;
#endif
vk_outarray_append_typed(VkExtensionProperties, &out, prop) {
*prop = vk_device_extensions[i];
}
}
return vk_outarray_status(&out);
}
VKAPI_ATTR void VKAPI_CALL
vk_common_GetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice,
VkPhysicalDeviceFeatures *pFeatures)
{
VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice);
/* Don't zero-init this struct since the driver fills it out entirely */
VkPhysicalDeviceFeatures2 features2;
features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
features2.pNext = NULL;
pdevice->dispatch_table.GetPhysicalDeviceFeatures2(physicalDevice,
&features2);
*pFeatures = features2.features;
}
VKAPI_ATTR void VKAPI_CALL
vk_common_GetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice,
VkPhysicalDeviceProperties *pProperties)
{
VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice);
/* Don't zero-init this struct since the driver fills it out entirely */
VkPhysicalDeviceProperties2 props2;
props2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
props2.pNext = NULL;
pdevice->dispatch_table.GetPhysicalDeviceProperties2(physicalDevice,
&props2);
*pProperties = props2.properties;
}
VKAPI_ATTR void VKAPI_CALL
vk_common_GetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice,
VkPhysicalDeviceMemoryProperties *pMemoryProperties)
{
VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice);
/* Don't zero-init this struct since the driver fills it out entirely */
VkPhysicalDeviceMemoryProperties2 props2;
props2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2;
props2.pNext = NULL;
pdevice->dispatch_table.GetPhysicalDeviceMemoryProperties2(physicalDevice,
&props2);
/* dEQP-VK.api.info.get_physical_device_properties2.memory_properties memsets
* the struct to 0xcd and expects that the unused array elements are
* untouched.
*/
pMemoryProperties->memoryHeapCount = props2.memoryProperties.memoryHeapCount;
for (int i = 0; i < pMemoryProperties->memoryHeapCount; i++) {
pMemoryProperties->memoryHeaps[i].flags = props2.memoryProperties.memoryHeaps[i].flags;
pMemoryProperties->memoryHeaps[i].size = props2.memoryProperties.memoryHeaps[i].size;
}
pMemoryProperties->memoryTypeCount = props2.memoryProperties.memoryTypeCount;
for (int i = 0; i < pMemoryProperties->memoryTypeCount; i++) {
pMemoryProperties->memoryTypes[i].heapIndex = props2.memoryProperties.memoryTypes[i].heapIndex;
pMemoryProperties->memoryTypes[i].propertyFlags = props2.memoryProperties.memoryTypes[i].propertyFlags;
}
}
VKAPI_ATTR void VKAPI_CALL
vk_common_GetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice,
VkFormat format,
VkFormatProperties *pFormatProperties)
{
VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice);
/* Don't zero-init this struct since the driver fills it out entirely */
VkFormatProperties2 props2;
props2.sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2;
props2.pNext = NULL;
pdevice->dispatch_table.GetPhysicalDeviceFormatProperties2(physicalDevice,
format, &props2);
*pFormatProperties = props2.formatProperties;
}
VKAPI_ATTR VkResult VKAPI_CALL
vk_common_GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice,
VkFormat format,
VkImageType type,
VkImageTiling tiling,
VkImageUsageFlags usage,
VkImageCreateFlags flags,
VkImageFormatProperties *pImageFormatProperties)
{
VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice);
VkPhysicalDeviceImageFormatInfo2 info = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2,
.format = format,
.type = type,
.tiling = tiling,
.usage = usage,
.flags = flags
};
/* Don't zero-init this struct since the driver fills it out entirely */
VkImageFormatProperties2 props2;
props2.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2;
props2.pNext = NULL;
VkResult result =
pdevice->dispatch_table.GetPhysicalDeviceImageFormatProperties2(physicalDevice,
&info, &props2);
*pImageFormatProperties = props2.imageFormatProperties;
return result;
}
VKAPI_ATTR void VKAPI_CALL
vk_common_GetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice,
VkFormat format,
VkImageType type,
uint32_t samples,
VkImageUsageFlags usage,
VkImageTiling tiling,
uint32_t *pNumProperties,
VkSparseImageFormatProperties *pProperties)
{
VK_FROM_HANDLE(vk_physical_device, pdevice, physicalDevice);
VkPhysicalDeviceSparseImageFormatInfo2 info = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SPARSE_IMAGE_FORMAT_INFO_2,
.format = format,
.type = type,
.samples = samples,
.usage = usage,
.tiling = tiling
};
if (!pProperties) {
pdevice->dispatch_table.GetPhysicalDeviceSparseImageFormatProperties2(physicalDevice,
&info,
pNumProperties,
NULL);
return;
}
STACK_ARRAY(VkSparseImageFormatProperties2, props2, *pNumProperties);
for (unsigned i = 0; i < *pNumProperties; ++i) {
props2[i].sType = VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2;
props2[i].pNext = NULL;
}
pdevice->dispatch_table.GetPhysicalDeviceSparseImageFormatProperties2(physicalDevice,
&info,
pNumProperties,
props2);
for (unsigned i = 0; i < *pNumProperties; ++i)
pProperties[i] = props2[i].properties;
STACK_ARRAY_FINISH(props2);
}
|