blob: add4afc998ab22fc77d133c517a49a592f468793 [file] [log] [blame]
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -06001/*
2 * Vulkan
3 *
4 * Copyright (C) 2015 LunarG, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unordered_map>
29#include <memory>
30
31#include "vk_loader_platform.h"
32#include "vk_dispatch_table_helper.h"
33#include "vk_struct_string_helper_cpp.h"
34#if defined(__GNUC__)
35#pragma GCC diagnostic ignored "-Wwrite-strings"
36#endif
37#if defined(__GNUC__)
38#pragma GCC diagnostic warning "-Wwrite-strings"
39#endif
40#include "vk_struct_size_helper.h"
41#include "device_limits.h"
42#include "vk_layer_config.h"
43#include "vk_debug_marker_layer.h"
44// The following is #included again to catch certain OS-specific functions
45// being used:
46#include "vk_loader_platform.h"
47#include "vk_layer_msg.h"
48#include "vk_layer_table.h"
49#include "vk_layer_debug_marker_table.h"
50#include "vk_layer_data.h"
51#include "vk_layer_logging.h"
52#include "vk_layer_extension_utils.h"
53
54typedef struct _layer_data {
55 debug_report_data *report_data;
56 // TODO: put instance data here
57 VkDbgMsgCallback logging_callback;
58} layer_data;
59
60static std::unordered_map<void *, layer_data *> layer_data_map;
61static device_table_map device_limits_device_table_map;
62static instance_table_map device_limits_instance_table_map;
63
64// Track state of each instance
65unordered_map<VkInstance, unique_ptr<INSTANCE_STATE>> instanceMap;
66unordered_map<VkPhysicalDevice, unique_ptr<PHYSICAL_DEVICE_STATE>> physicalDeviceMap;
67unordered_map<VkPhysicalDevice, unordered_map<uint32_t, unique_ptr<VkQueueFamilyProperties>>> queueFamilyPropertiesMap;
68unordered_map<VkPhysicalDevice, unique_ptr<VkPhysicalDeviceFeatures>> physicalDeviceFeaturesMap;
69unordered_map<VkDevice, VkPhysicalDevice> deviceMap;
70
71struct devExts {
72 bool debug_marker_enabled;
73};
74
75static std::unordered_map<void *, struct devExts> deviceExtMap;
76
77static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
78
79// TODO : This can be much smarter, using separate locks for separate global data
80static int globalLockInitialized = 0;
81static loader_platform_thread_mutex globalLock;
82
83template layer_data *get_my_data_ptr<layer_data>(
84 void *data_key,
85 std::unordered_map<void *, layer_data *> &data_map);
86
87debug_report_data *mdd(void* object)
88{
89 dispatch_key key = get_dispatch_key(object);
90 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
91#if DISPATCH_MAP_DEBUG
92 fprintf(stderr, "MDD: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
93#endif
94 return my_data->report_data;
95}
96
97debug_report_data *mid(VkInstance object)
98{
99 dispatch_key key = get_dispatch_key(object);
100 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
101#if DISPATCH_MAP_DEBUG
102 fprintf(stderr, "MID: map: %p, object: %p, key: %p, data: %p\n", &layer_data_map, object, key, my_data);
103#endif
104 return my_data->report_data;
105}
106
107static void init_device_limits(layer_data *my_data)
108{
109 uint32_t report_flags = 0;
110 uint32_t debug_action = 0;
111 FILE *log_output = NULL;
112 const char *option_str;
113 // initialize DeviceLimits options
114 report_flags = getLayerOptionFlags("DeviceLimitsReportFlags", 0);
115 getLayerOptionEnum("DeviceLimitsDebugAction", (uint32_t *) &debug_action);
116
117 if (debug_action & VK_DBG_LAYER_ACTION_LOG_MSG)
118 {
119 option_str = getLayerOption("DeviceLimitsLogFilename");
Tobin Ehlisb1df55e2015-09-15 09:55:54 -0600120 log_output = getLayerLogOutput(option_str, "DeviceLimits");
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600121 layer_create_msg_callback(my_data->report_data, report_flags, log_callback, (void *) log_output, &my_data->logging_callback);
122 }
123
124 if (!globalLockInitialized)
125 {
126 // TODO/TBD: Need to delete this mutex sometime. How??? One
127 // suggestion is to call this during vkCreateInstance(), and then we
128 // can clean it up during vkDestroyInstance(). However, that requires
129 // that the layer have per-instance locks. We need to come back and
130 // address this soon.
131 loader_platform_thread_create_mutex(&globalLock);
132 globalLockInitialized = 1;
133 }
134}
135
136VK_LAYER_EXPORT VkResult VKAPI vkCreateInstance(const VkInstanceCreateInfo* pCreateInfo, VkInstance* pInstance)
137{
138 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(device_limits_instance_table_map,*pInstance);
139 VkResult result = pTable->CreateInstance(pCreateInfo, pInstance);
140
141 if (result == VK_SUCCESS) {
142 layer_data *my_data = get_my_data_ptr(get_dispatch_key(*pInstance), layer_data_map);
143 my_data->report_data = debug_report_create_instance(
144 pTable,
145 *pInstance,
146 pCreateInfo->extensionCount,
147 pCreateInfo->ppEnabledExtensionNames);
148
149 init_device_limits(my_data);
150 instanceMap[*pInstance] = unique_ptr<INSTANCE_STATE>(new INSTANCE_STATE());
151 }
152 return result;
153}
154
155/* hook DestroyInstance to remove tableInstanceMap entry */
Mark Lobodzinski2141f652015-09-07 13:59:43 -0600156VK_LAYER_EXPORT void VKAPI vkDestroyInstance(VkInstance instance)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600157{
158 dispatch_key key = get_dispatch_key(instance);
159 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(device_limits_instance_table_map, instance);
Mark Lobodzinski2141f652015-09-07 13:59:43 -0600160 pTable->DestroyInstance(instance);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600161
162 // Clean up logging callback, if any
163 layer_data *my_data = get_my_data_ptr(key, layer_data_map);
164 if (my_data->logging_callback) {
165 layer_destroy_msg_callback(my_data->report_data, my_data->logging_callback);
166 }
167
168 layer_debug_report_destroy_instance(my_data->report_data);
169 layer_data_map.erase(pTable);
170 instanceMap.erase(instance);
171 device_limits_instance_table_map.erase(key);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600172}
173
174VK_LAYER_EXPORT VkResult VKAPI vkEnumeratePhysicalDevices(VkInstance instance, uint32_t* pPhysicalDeviceCount, VkPhysicalDevice* pPhysicalDevices)
175{
176 auto it = instanceMap.find(instance);
177 if (it != instanceMap.end()) {
178 // For this instance, flag when vkEnumeratePhysicalDevices goes to QUERY_COUNT and then QUERY_DETAILS
179 if (NULL == pPhysicalDevices) {
180 it->second->vkEnumeratePhysicalDevicesState = QUERY_COUNT;
181 } else {
182 if (UNCALLED == it->second->vkEnumeratePhysicalDevicesState) {
183 // Flag error here, shouldn't be calling this without having queried count
184 log_msg(mid(instance), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_INSTANCE, 0, 0, DEVLIMITS_MUST_QUERY_COUNT, "DL",
185 "Invalid call sequence to vkEnumeratePhysicalDevices() w/ non-NULL pPhysicalDevices. You should first call vkEnumeratePhysicalDevices() w/ NULL pPhysicalDevices to query pPhysicalDeviceCount.");
186 } // TODO : Could also flag a warning if re-calling this function in QUERY_DETAILS state
187 else if (it->second->physicalDevicesCount != *pPhysicalDeviceCount) {
188 log_msg(mid(instance), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
189 "Call to vkEnumeratePhysicalDevices() w/ pPhysicalDeviceCount value %u, but actual count supported by this instance is %u.", *pPhysicalDeviceCount, it->second->physicalDevicesCount);
190 }
191 it->second->vkEnumeratePhysicalDevicesState = QUERY_DETAILS;
192 }
193 VkResult result = get_dispatch_table(device_limits_instance_table_map,instance)->EnumeratePhysicalDevices(instance, pPhysicalDeviceCount, pPhysicalDevices);
194 if (NULL == pPhysicalDevices) {
195 it->second->physicalDevicesCount = *pPhysicalDeviceCount;
196 } else { // Save physical devices
197 for (uint32_t i=0; i < *pPhysicalDeviceCount; i++) {
198 physicalDeviceMap[pPhysicalDevices[i]] = unique_ptr<PHYSICAL_DEVICE_STATE>(new PHYSICAL_DEVICE_STATE());
199 }
200 }
201 return result;
202 } else {
203 log_msg(mid(instance), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_INSTANCE, 0, 0, DEVLIMITS_INVALID_INSTANCE, "DL",
204 "Invalid instance (%#" PRIxLEAST64 ") passed into vkEnumeratePhysicalDevices().", instance);
205 }
206}
207
208VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFeatures(VkPhysicalDevice physicalDevice, VkPhysicalDeviceFeatures* pFeatures)
209{
210 auto it = physicalDeviceMap.find(physicalDevice);
211 if (it != physicalDeviceMap.end()) {
212 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceFeatures(physicalDevice, pFeatures);
213 // Save Features
214 physicalDeviceFeaturesMap[physicalDevice] = unique_ptr<VkPhysicalDeviceFeatures>(new VkPhysicalDeviceFeatures(*pFeatures));
215 return result;
216 }
217}
218
219VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkFormatProperties* pFormatProperties)
220{
221 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceFormatProperties(physicalDevice, format, pFormatProperties);
222 return result;
223}
224
Courtney Goeltzenleuchtera22097a2015-09-10 13:44:12 -0600225VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* pImageFormatProperties)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600226{
Courtney Goeltzenleuchtera22097a2015-09-10 13:44:12 -0600227 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, pImageFormatProperties);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600228 return result;
229}
230
231VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceProperties* pProperties)
232{
233 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceProperties(physicalDevice, pProperties);
234 return result;
235}
236
237VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice physicalDevice, uint32_t* pCount, VkQueueFamilyProperties* pQueueFamilyProperties)
238{
239 auto it = physicalDeviceMap.find(physicalDevice);
240 if (it != physicalDeviceMap.end()) {
241 if (NULL == pQueueFamilyProperties) {
242 it->second->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_COUNT;
243 } else {
244 // Verify that for each physical device, this function is called first with NULL pQueueFamilyProperties ptr in order to get count
245 if (UNCALLED == it->second->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
246 log_msg(mdd(physicalDevice), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_MUST_QUERY_COUNT, "DL",
247 "Invalid call sequence to vkGetPhysicalDeviceQueueFamilyProperties() w/ non-NULL pQueueFamilyProperties. You should first call vkGetPhysicalDeviceQueueFamilyProperties() w/ NULL pQueueFamilyProperties to query pCount.");
248 }
249 if (it->second->queueFamilyPropertiesCount != *pCount) {
250 log_msg(mdd(physicalDevice), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_COUNT_MISMATCH, "DL",
251 "Call to vkGetPhysicalDeviceQueueFamilyProperties() w/ pCount value %u, but actual count supported by this physicalDevice is %u.", *pCount, it->second->queueFamilyPropertiesCount);
252 }
253 it->second->vkGetPhysicalDeviceQueueFamilyPropertiesState = QUERY_DETAILS;
254 }
255 // Then verify that pCount that is passed in on second call matches what was returned
256 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceQueueFamilyProperties(physicalDevice, pCount, pQueueFamilyProperties);
257 if (NULL == pQueueFamilyProperties) {
258 it->second->queueFamilyPropertiesCount = *pCount;
259 } else { // Save queue family properties
260 for (uint32_t i=0; i < *pCount; i++) {
261 queueFamilyPropertiesMap[physicalDevice][i] = unique_ptr<VkQueueFamilyProperties>(new VkQueueFamilyProperties(pQueueFamilyProperties[i]));
262 }
263 }
264 return result;
265 } else {
266 log_msg(mdd(physicalDevice), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_PHYSICAL_DEVICE, "DL",
267 "Invalid physicalDevice (%#" PRIxLEAST64 ") passed into vkGetPhysicalDeviceQueueFamilyProperties().", physicalDevice);
268 }
269}
270
271VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceMemoryProperties(VkPhysicalDevice physicalDevice, VkPhysicalDeviceMemoryProperties* pMemoryProperties)
272{
273 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceMemoryProperties(physicalDevice, pMemoryProperties);
274 return result;
275}
276
277VK_LAYER_EXPORT VkResult VKAPI vkGetPhysicalDeviceSparseImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, uint32_t samples, VkImageUsageFlags usage, VkImageTiling tiling, uint32_t* pNumProperties, VkSparseImageFormatProperties* pProperties)
278{
279 VkResult result = get_dispatch_table(device_limits_instance_table_map, physicalDevice)->GetPhysicalDeviceSparseImageFormatProperties(physicalDevice, format, type, samples, usage, tiling, pNumProperties, pProperties);
280 return result;
281}
282
283static void createDeviceRegisterExtensions(const VkDeviceCreateInfo* pCreateInfo, VkDevice device)
284{
285 uint32_t i;
286 VkLayerDispatchTable *pDisp = get_dispatch_table(device_limits_device_table_map, device);
287 deviceExtMap[pDisp].debug_marker_enabled = false;
288
289 for (i = 0; i < pCreateInfo->extensionCount; i++) {
290 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], DEBUG_MARKER_EXTENSION_NAME) == 0) {
291 /* Found a matching extension name, mark it enabled and init dispatch table*/
292 initDebugMarkerTable(device);
293 deviceExtMap[pDisp].debug_marker_enabled = true;
294 }
295
296 }
297}
298
299VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalDevice gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
300{
Tobin Ehlis54a6c182015-09-22 14:00:58 -0600301 // First check is app has actually requested queueFamilyProperties
302 auto it = physicalDeviceMap.find(gpu);
303 if (it == physicalDeviceMap.end()) {
304 log_msg(mdd(gpu), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_MUST_QUERY_COUNT, "DL",
305 "Invalid call to vkCreateDevice() w/o first calling vkEnumeratePhysicalDevices().");
306 } else if (QUERY_DETAILS != it->second->vkGetPhysicalDeviceQueueFamilyPropertiesState) {
307 log_msg(mdd(gpu), VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
308 "Invalid call to vkCreateDevice() w/o first calling vkGetPhysicalDeviceQueueFamilyProperties().");
309 } else {
310 // Check that the requested queue properties are valid
311 for (uint32_t i=0; i<pCreateInfo->queueRecordCount; i++) {
312 uint32_t requestedIndex = pCreateInfo->pRequestedQueues[i].queueFamilyIndex;
313 auto qfp_it = queueFamilyPropertiesMap[gpu].find(requestedIndex);
314 if (qfp_it == queueFamilyPropertiesMap[gpu].end()) { // requested index is out of bounds for this physical device
315 log_msg(mdd(gpu), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
316 "Invalid queue create request in vkCreateDevice(). Invalid queueFamilyIndex %u requested.", requestedIndex);
317 } else if (pCreateInfo->pRequestedQueues[i].queueCount > qfp_it->second->queueCount) {
318 log_msg(mdd(gpu), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
319 "Invalid queue create request in vkCreateDevice(). QueueFamilyIndex %u only has %u queues, but requested queueCount is %u.", requestedIndex, qfp_it->second->queueCount, pCreateInfo->pRequestedQueues[i].queueCount);
320 }
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600321 }
322 }
323 VkLayerDispatchTable *pDeviceTable = get_dispatch_table(device_limits_device_table_map, *pDevice);
324 VkResult result = pDeviceTable->CreateDevice(gpu, pCreateInfo, pDevice);
325 if (result == VK_SUCCESS) {
326 layer_data *my_instance_data = get_my_data_ptr(get_dispatch_key(gpu), layer_data_map);
327 VkLayerDispatchTable *pTable = get_dispatch_table(device_limits_device_table_map, *pDevice);
328 layer_data *my_device_data = get_my_data_ptr(get_dispatch_key(*pDevice), layer_data_map);
329 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
330 createDeviceRegisterExtensions(pCreateInfo, *pDevice);
331 deviceMap[*pDevice] = gpu;
332 }
333 return result;
334}
335
Mark Lobodzinski2141f652015-09-07 13:59:43 -0600336VK_LAYER_EXPORT void VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600337{
338 // Free device lifetime allocations
339 dispatch_key key = get_dispatch_key(device);
340 VkLayerDispatchTable *pDisp = get_dispatch_table(device_limits_device_table_map, device);
Mark Lobodzinski2141f652015-09-07 13:59:43 -0600341 pDisp->DestroyDevice(device);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600342 deviceExtMap.erase(pDisp);
343 device_limits_device_table_map.erase(key);
344 tableDebugMarkerMap.erase(pDisp);
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600345}
346
347static const VkLayerProperties ds_global_layers[] = {
348 {
349 "DeviceLimits",
350 VK_API_VERSION,
351 VK_MAKE_VERSION(0, 1, 0),
352 "Validation layer: DeviceLimits",
353 }
354};
355
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600356VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceExtensionProperties(
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600357 const char *pLayerName,
358 uint32_t *pCount,
359 VkExtensionProperties* pProperties)
360{
361 /* DeviceLimits does not have any global extensions */
362 return util_GetExtensionProperties(0, NULL, pCount, pProperties);
363}
364
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600365VK_LAYER_EXPORT VkResult VKAPI vkEnumerateInstanceLayerProperties(
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600366 uint32_t *pCount,
367 VkLayerProperties* pProperties)
368{
369 return util_GetLayerProperties(ARRAY_SIZE(ds_global_layers),
370 ds_global_layers,
371 pCount, pProperties);
372}
373
374static const VkExtensionProperties ds_device_extensions[] = {
375 {
376 DEBUG_MARKER_EXTENSION_NAME,
377 VK_MAKE_VERSION(0, 1, 0),
378 }
379};
380
381static const VkLayerProperties ds_device_layers[] = {
382 {
383 "DeviceLimits",
384 VK_API_VERSION,
385 VK_MAKE_VERSION(0, 1, 0),
386 "Validation layer: DeviceLimits",
387 }
388};
389
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600390VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceExtensionProperties(
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600391 VkPhysicalDevice physicalDevice,
392 const char* pLayerName,
393 uint32_t* pCount,
394 VkExtensionProperties* pProperties)
395{
396 /* Device Limits does not have any physical device extensions */
397 return util_GetExtensionProperties(ARRAY_SIZE(ds_device_extensions), ds_device_extensions,
398 pCount, pProperties);
399}
400
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600401VK_LAYER_EXPORT VkResult VKAPI vkEnumerateDeviceLayerProperties(
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600402 VkPhysicalDevice physicalDevice,
403 uint32_t* pCount,
404 VkLayerProperties* pProperties)
405{
406 /* Device Limits' physical device layers are the same as global */
407 return util_GetLayerProperties(ARRAY_SIZE(ds_device_layers), ds_device_layers,
408 pCount, pProperties);
409}
410
411VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue* pQueue)
412{
413 VkPhysicalDevice gpu = deviceMap[device];
414 auto qfp_it = queueFamilyPropertiesMap[gpu].find(queueFamilyIndex);
415 if (qfp_it == queueFamilyPropertiesMap[gpu].end()) { // requested index is out of bounds for this physical device
416 log_msg(mdd(gpu), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
417 "Invalid queueFamilyIndex %u requested in vkGetDeviceQueue().", queueFamilyIndex);
418 } else if (queueIndex >= qfp_it->second->queueCount) {
419 log_msg(mdd(gpu), VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PHYSICAL_DEVICE, 0, 0, DEVLIMITS_INVALID_QUEUE_CREATE_REQUEST, "DL",
420 "Invalid queue request in vkGetDeviceQueue(). QueueFamilyIndex %u only has %u queues, but requested queueIndex is %u.", queueFamilyIndex, qfp_it->second->queueCount, queueIndex);
421 }
422 VkResult result = get_dispatch_table(device_limits_device_table_map, device)->GetDeviceQueue(device, queueFamilyIndex, queueIndex, pQueue);
423 return result;
424}
425
426VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
427 VkInstance instance,
428 VkFlags msgFlags,
429 const PFN_vkDbgMsgCallback pfnMsgCallback,
430 void* pUserData,
431 VkDbgMsgCallback* pMsgCallback)
432{
433 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(device_limits_instance_table_map, instance);
434 VkResult res = pTable->DbgCreateMsgCallback(instance, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
435 if (VK_SUCCESS == res) {
436 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
437 res = layer_create_msg_callback(my_data->report_data, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
438 }
439 return res;
440}
441
442VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
443 VkInstance instance,
444 VkDbgMsgCallback msgCallback)
445{
446 VkLayerInstanceDispatchTable *pTable = get_dispatch_table(device_limits_instance_table_map, instance);
447 VkResult res = pTable->DbgDestroyMsgCallback(instance, msgCallback);
448 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
449 layer_destroy_msg_callback(my_data->report_data, msgCallback);
450 return res;
451}
452
453VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetDeviceProcAddr(VkDevice dev, const char* funcName)
454{
455 if (dev == NULL)
456 return NULL;
457
458 /* loader uses this to force layer initialization; device object is wrapped */
459 if (!strcmp(funcName, "vkGetDeviceProcAddr")) {
460 initDeviceTable(device_limits_device_table_map, (const VkBaseLayerObject *) dev);
461 return (PFN_vkVoidFunction) vkGetDeviceProcAddr;
462 }
463 if (!strcmp(funcName, "vkCreateDevice"))
464 return (PFN_vkVoidFunction) vkCreateDevice;
465 if (!strcmp(funcName, "vkDestroyDevice"))
466 return (PFN_vkVoidFunction) vkDestroyDevice;
467 /*if (!strcmp(funcName, "vkQueueSubmit"))
468 return (PFN_vkVoidFunction) vkQueueSubmit;*/
469 if (!strcmp(funcName, "vkGetDeviceQueue"))
470 return (PFN_vkVoidFunction) vkGetDeviceQueue;
471/* if (!strcmp(funcName, "vkDestroyFence"))
472 return (PFN_vkVoidFunction) vkDestroyFence;
473 if (!strcmp(funcName, "vkDestroySemaphore"))
474 return (PFN_vkVoidFunction) vkDestroySemaphore;
475 if (!strcmp(funcName, "vkDestroyEvent"))
476 return (PFN_vkVoidFunction) vkDestroyEvent;
477 if (!strcmp(funcName, "vkDestroyQueryPool"))
478 return (PFN_vkVoidFunction) vkDestroyQueryPool;
479 if (!strcmp(funcName, "vkDestroyBuffer"))
480 return (PFN_vkVoidFunction) vkDestroyBuffer;
481 if (!strcmp(funcName, "vkDestroyBufferView"))
482 return (PFN_vkVoidFunction) vkDestroyBufferView;
483 if (!strcmp(funcName, "vkDestroyImage"))
484 return (PFN_vkVoidFunction) vkDestroyImage;
485 if (!strcmp(funcName, "vkDestroyImageView"))
486 return (PFN_vkVoidFunction) vkDestroyImageView;
487 if (!strcmp(funcName, "vkDestroyShaderModule"))
488 return (PFN_vkVoidFunction) vkDestroyShaderModule;
489 if (!strcmp(funcName, "vkDestroyShader"))
490 return (PFN_vkVoidFunction) vkDestroyShader;
491 if (!strcmp(funcName, "vkDestroyPipeline"))
492 return (PFN_vkVoidFunction) vkDestroyPipeline;
493 if (!strcmp(funcName, "vkDestroyPipelineLayout"))
494 return (PFN_vkVoidFunction) vkDestroyPipelineLayout;
495 if (!strcmp(funcName, "vkDestroySampler"))
496 return (PFN_vkVoidFunction) vkDestroySampler;
497 if (!strcmp(funcName, "vkDestroyDescriptorSetLayout"))
498 return (PFN_vkVoidFunction) vkDestroyDescriptorSetLayout;
499 if (!strcmp(funcName, "vkDestroyDescriptorPool"))
500 return (PFN_vkVoidFunction) vkDestroyDescriptorPool;
501 if (!strcmp(funcName, "vkDestroyDynamicViewportState"))
502 return (PFN_vkVoidFunction) vkDestroyDynamicViewportState;
503 if (!strcmp(funcName, "vkDestroyDynamicLineWidthState"))
504 return (PFN_vkVoidFunction) vkDestroyDynamicLineWidthState;
505 if (!strcmp(funcName, "vkDestroyDynamicDepthBiasState"))
506 return (PFN_vkVoidFunction) vkDestroyDynamicDepthBiasState;
507 if (!strcmp(funcName, "vkDestroyDynamicBlendState"))
508 return (PFN_vkVoidFunction) vkDestroyDynamicBlendState;
509 if (!strcmp(funcName, "vkDestroyDynamicDepthBoundsState"))
510 return (PFN_vkVoidFunction) vkDestroyDynamicDepthBoundsState;
511 if (!strcmp(funcName, "vkDestroyDynamicStencilState"))
512 return (PFN_vkVoidFunction) vkDestroyDynamicStencilState;
513 if (!strcmp(funcName, "vkDestroyCommandBuffer"))
514 return (PFN_vkVoidFunction) vkDestroyCommandBuffer;
515 if (!strcmp(funcName, "vkDestroyFramebuffer"))
516 return (PFN_vkVoidFunction) vkDestroyFramebuffer;
517 if (!strcmp(funcName, "vkDestroyRenderPass"))
518 return (PFN_vkVoidFunction) vkDestroyRenderPass;
519 if (!strcmp(funcName, "vkCreateBufferView"))
520 return (PFN_vkVoidFunction) vkCreateBufferView;
521 if (!strcmp(funcName, "vkCreateImageView"))
522 return (PFN_vkVoidFunction) vkCreateImageView;
523 if (!strcmp(funcName, "CreatePipelineCache"))
524 return (PFN_vkVoidFunction) vkCreatePipelineCache;
525 if (!strcmp(funcName, "DestroyPipelineCache"))
526 return (PFN_vkVoidFunction) vkDestroyPipelineCache;
527 if (!strcmp(funcName, "GetPipelineCacheSize"))
528 return (PFN_vkVoidFunction) vkGetPipelineCacheSize;
529 if (!strcmp(funcName, "GetPipelineCacheData"))
530 return (PFN_vkVoidFunction) vkGetPipelineCacheData;
531 if (!strcmp(funcName, "MergePipelineCaches"))
532 return (PFN_vkVoidFunction) vkMergePipelineCaches;
533 if (!strcmp(funcName, "vkCreateGraphicsPipelines"))
534 return (PFN_vkVoidFunction) vkCreateGraphicsPipelines;
535 if (!strcmp(funcName, "vkCreateSampler"))
536 return (PFN_vkVoidFunction) vkCreateSampler;
537 if (!strcmp(funcName, "vkCreateDescriptorSetLayout"))
538 return (PFN_vkVoidFunction) vkCreateDescriptorSetLayout;
539 if (!strcmp(funcName, "vkCreatePipelineLayout"))
540 return (PFN_vkVoidFunction) vkCreatePipelineLayout;
541 if (!strcmp(funcName, "vkCreateDescriptorPool"))
542 return (PFN_vkVoidFunction) vkCreateDescriptorPool;
543 if (!strcmp(funcName, "vkResetDescriptorPool"))
544 return (PFN_vkVoidFunction) vkResetDescriptorPool;
545 if (!strcmp(funcName, "vkAllocDescriptorSets"))
546 return (PFN_vkVoidFunction) vkAllocDescriptorSets;
547 if (!strcmp(funcName, "vkUpdateDescriptorSets"))
548 return (PFN_vkVoidFunction) vkUpdateDescriptorSets;
549 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
550 return (PFN_vkVoidFunction) vkCreateDynamicViewportState;
551 if (!strcmp(funcName, "vkCreateDynamicLineWidthState"))
552 return (PFN_vkVoidFunction) vkCreateDynamicLineWidthState;
553 if (!strcmp(funcName, "vkCreateDynamicDepthBiasState"))
554 return (PFN_vkVoidFunction) vkCreateDynamicDepthBiasState;
555 if (!strcmp(funcName, "vkCreateDynamicBlendState"))
556 return (PFN_vkVoidFunction) vkCreateDynamicBlendState;
557 if (!strcmp(funcName, "vkCreateDynamicDepthBoundsState"))
558 return (PFN_vkVoidFunction) vkCreateDynamicDepthBoundsState;
559 if (!strcmp(funcName, "vkCreateDynamicStencilState"))
560 return (PFN_vkVoidFunction) vkCreateDynamicStencilState;
561 if (!strcmp(funcName, "vkCreateCommandBuffer"))
562 return (PFN_vkVoidFunction) vkCreateCommandBuffer;
563 if (!strcmp(funcName, "vkBeginCommandBuffer"))
564 return (PFN_vkVoidFunction) vkBeginCommandBuffer;
565 if (!strcmp(funcName, "vkEndCommandBuffer"))
566 return (PFN_vkVoidFunction) vkEndCommandBuffer;
567 if (!strcmp(funcName, "vkResetCommandBuffer"))
568 return (PFN_vkVoidFunction) vkResetCommandBuffer;
569 if (!strcmp(funcName, "vkCmdBindPipeline"))
570 return (PFN_vkVoidFunction) vkCmdBindPipeline;
571 if (!strcmp(funcName, "vkCmdBindDynamicViewportState"))
572 return (PFN_vkVoidFunction) vkCmdBindDynamicViewportState;
573 if (!strcmp(funcName, "vkCmdBindDynamicLineWidthState"))
574 return (PFN_vkVoidFunction) vkCmdBindDynamicLineWidthState;
575 if (!strcmp(funcName, "vkCmdBindDynamicDepthBiasState"))
576 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthBiasState;
577 if (!strcmp(funcName, "vkCmdBindDynamicBlendState"))
578 return (PFN_vkVoidFunction) vkCmdBindDynamicBlendState;
579 if (!strcmp(funcName, "vkCmdBindDynamicDepthBoundsState"))
580 return (PFN_vkVoidFunction) vkCmdBindDynamicDepthBoundsState;
581 if (!strcmp(funcName, "vkCmdBindDynamicStencilState"))
582 return (PFN_vkVoidFunction) vkCmdBindDynamicStencilState;
583 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
584 return (PFN_vkVoidFunction) vkCmdBindDescriptorSets;
585 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
586 return (PFN_vkVoidFunction) vkCmdBindVertexBuffers;
587 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
588 return (PFN_vkVoidFunction) vkCmdBindIndexBuffer;
589 if (!strcmp(funcName, "vkCmdDraw"))
590 return (PFN_vkVoidFunction) vkCmdDraw;
591 if (!strcmp(funcName, "vkCmdDrawIndexed"))
592 return (PFN_vkVoidFunction) vkCmdDrawIndexed;
593 if (!strcmp(funcName, "vkCmdDrawIndirect"))
594 return (PFN_vkVoidFunction) vkCmdDrawIndirect;
595 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
596 return (PFN_vkVoidFunction) vkCmdDrawIndexedIndirect;
597 if (!strcmp(funcName, "vkCmdDispatch"))
598 return (PFN_vkVoidFunction) vkCmdDispatch;
599 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
600 return (PFN_vkVoidFunction) vkCmdDispatchIndirect;
601 if (!strcmp(funcName, "vkCmdCopyBuffer"))
602 return (PFN_vkVoidFunction) vkCmdCopyBuffer;
603 if (!strcmp(funcName, "vkCmdCopyImage"))
604 return (PFN_vkVoidFunction) vkCmdCopyImage;
605 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
606 return (PFN_vkVoidFunction) vkCmdCopyBufferToImage;
607 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
608 return (PFN_vkVoidFunction) vkCmdCopyImageToBuffer;
609 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
610 return (PFN_vkVoidFunction) vkCmdUpdateBuffer;
611 if (!strcmp(funcName, "vkCmdFillBuffer"))
612 return (PFN_vkVoidFunction) vkCmdFillBuffer;
613 if (!strcmp(funcName, "vkCmdClearColorImage"))
614 return (PFN_vkVoidFunction) vkCmdClearColorImage;
615 if (!strcmp(funcName, "vkCmdClearDepthStencilImage"))
616 return (PFN_vkVoidFunction) vkCmdClearDepthStencilImage;
617 if (!strcmp(funcName, "vkCmdClearColorAttachment"))
618 return (PFN_vkVoidFunction) vkCmdClearColorAttachment;
619 if (!strcmp(funcName, "vkCmdClearDepthStencilAttachment"))
620 return (PFN_vkVoidFunction) vkCmdClearDepthStencilAttachment;
621 if (!strcmp(funcName, "vkCmdResolveImage"))
622 return (PFN_vkVoidFunction) vkCmdResolveImage;
623 if (!strcmp(funcName, "vkCmdSetEvent"))
624 return (PFN_vkVoidFunction) vkCmdSetEvent;
625 if (!strcmp(funcName, "vkCmdResetEvent"))
626 return (PFN_vkVoidFunction) vkCmdResetEvent;
627 if (!strcmp(funcName, "vkCmdWaitEvents"))
628 return (PFN_vkVoidFunction) vkCmdWaitEvents;
629 if (!strcmp(funcName, "vkCmdPipelineBarrier"))
630 return (PFN_vkVoidFunction) vkCmdPipelineBarrier;
631 if (!strcmp(funcName, "vkCmdBeginQuery"))
632 return (PFN_vkVoidFunction) vkCmdBeginQuery;
633 if (!strcmp(funcName, "vkCmdEndQuery"))
634 return (PFN_vkVoidFunction) vkCmdEndQuery;
635 if (!strcmp(funcName, "vkCmdResetQueryPool"))
636 return (PFN_vkVoidFunction) vkCmdResetQueryPool;
637 if (!strcmp(funcName, "vkCmdWriteTimestamp"))
638 return (PFN_vkVoidFunction) vkCmdWriteTimestamp;
639 if (!strcmp(funcName, "vkCreateFramebuffer"))
640 return (PFN_vkVoidFunction) vkCreateFramebuffer;
641 if (!strcmp(funcName, "vkCreateRenderPass"))
642 return (PFN_vkVoidFunction) vkCreateRenderPass;
643 if (!strcmp(funcName, "vkCmdBeginRenderPass"))
644 return (PFN_vkVoidFunction) vkCmdBeginRenderPass;
645 if (!strcmp(funcName, "vkCmdNextSubpass"))
646 return (PFN_vkVoidFunction) vkCmdNextSubpass;
647 if (!strcmp(funcName, "vkCmdEndRenderPass"))
648 return (PFN_vkVoidFunction) vkCmdEndRenderPass;*/
649
650 VkLayerDispatchTable* pTable = get_dispatch_table(device_limits_device_table_map, dev);
651 if (deviceExtMap.size() == 0 || deviceExtMap[pTable].debug_marker_enabled)
652 {
653// if (!strcmp(funcName, "vkCmdDbgMarkerBegin"))
654// return (PFN_vkVoidFunction) vkCmdDbgMarkerBegin;
655// if (!strcmp(funcName, "vkCmdDbgMarkerEnd"))
656// return (PFN_vkVoidFunction) vkCmdDbgMarkerEnd;
657// if (!strcmp(funcName, "vkDbgSetObjectTag"))
658// return (void*) vkDbgSetObjectTag;
659// if (!strcmp(funcName, "vkDbgSetObjectName"))
660// return (void*) vkDbgSetObjectName;
661 }
662 {
663 if (pTable->GetDeviceProcAddr == NULL)
664 return NULL;
665 return pTable->GetDeviceProcAddr(dev, funcName);
666 }
667}
668
669VK_LAYER_EXPORT PFN_vkVoidFunction VKAPI vkGetInstanceProcAddr(VkInstance instance, const char* funcName)
670{
671 PFN_vkVoidFunction fptr;
672 if (instance == NULL)
673 return NULL;
674
675 /* loader uses this to force layer initialization; instance object is wrapped */
676 if (!strcmp(funcName, "vkGetInstanceProcAddr")) {
677 initInstanceTable(device_limits_instance_table_map, (const VkBaseLayerObject *) instance);
678 return (PFN_vkVoidFunction) vkGetInstanceProcAddr;
679 }
680 if (!strcmp(funcName, "vkCreateInstance"))
681 return (PFN_vkVoidFunction) vkCreateInstance;
682 if (!strcmp(funcName, "vkDestroyInstance"))
683 return (PFN_vkVoidFunction) vkDestroyInstance;
684 if (!strcmp(funcName, "vkEnumeratePhysicalDevices"))
685 return (PFN_vkVoidFunction) vkEnumeratePhysicalDevices;
686 if (!strcmp(funcName, "vkGetPhysicalDeviceFeatures"))
687 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFeatures;
688 if (!strcmp(funcName, "vkGetPhysicalDeviceFormatProperties"))
689 return (PFN_vkVoidFunction) vkGetPhysicalDeviceFormatProperties;
690 if (!strcmp(funcName, "vkGetPhysicalDeviceImageFormatProperties"))
691 return (PFN_vkVoidFunction) vkGetPhysicalDeviceImageFormatProperties;
692 if (!strcmp(funcName, "vkGetPhysicalDeviceProperties"))
693 return (PFN_vkVoidFunction) vkGetPhysicalDeviceProperties;
694 if (!strcmp(funcName, "vkGetPhysicalDeviceQueueFamilyProperties"))
695 return (PFN_vkVoidFunction) vkGetPhysicalDeviceQueueFamilyProperties;
696 if (!strcmp(funcName, "vkGetPhysicalDeviceMemoryProperties"))
697 return (PFN_vkVoidFunction) vkGetPhysicalDeviceMemoryProperties;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600698 if (!strcmp(funcName, "vkEnumerateDeviceLayerProperties"))
699 return (PFN_vkVoidFunction) vkEnumerateDeviceLayerProperties;
700 if (!strcmp(funcName, "vkEnumerateDeviceExtensionProperties"))
701 return (PFN_vkVoidFunction) vkEnumerateDeviceExtensionProperties;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600702 if (!strcmp(funcName, "vkGetPhysicalDeviceSparseImageFormatProperties"))
703 return (PFN_vkVoidFunction) vkGetPhysicalDeviceSparseImageFormatProperties;
Courtney Goeltzenleuchter35985f62015-09-14 17:22:16 -0600704 if (!strcmp(funcName, "vkEnumerateInstanceLayerProperties"))
705 return (PFN_vkVoidFunction) vkEnumerateInstanceLayerProperties;
706 if (!strcmp(funcName, "vkEnumerateInstanceExtensionProperties"))
707 return (PFN_vkVoidFunction) vkEnumerateInstanceExtensionProperties;
Tobin Ehlisb5fc4fb2015-09-03 09:50:06 -0600708
709 layer_data *my_data = get_my_data_ptr(get_dispatch_key(instance), layer_data_map);
710 fptr = debug_report_get_instance_proc_addr(my_data->report_data, funcName);
711 if (fptr)
712 return fptr;
713
714 {
715 VkLayerInstanceDispatchTable* pTable = get_dispatch_table(device_limits_instance_table_map, instance);
716 if (pTable->GetInstanceProcAddr == NULL)
717 return NULL;
718 return pTable->GetInstanceProcAddr(instance, funcName);
719 }
720}