blob: d115b4fdf75608d5e374603dcb7f8836bd5643bd [file] [log] [blame]
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001/* Copyright (c) 2015-2017 The Khronos Group Inc.
2 * Copyright (c) 2015-2017 Valve Corporation
3 * Copyright (c) 2015-2017 LunarG, Inc.
4 * Copyright (C) 2015-2017 Google Inc.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Mark Lobodzinski <mark@LunarG.com>
19 */
20
21#define NOMINMAX
22
23#include <limits.h>
24#include <math.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <inttypes.h>
29
30#include <iostream>
31#include <string>
32#include <sstream>
33#include <unordered_map>
34#include <unordered_set>
35#include <vector>
36#include <mutex>
37
38#include "vk_loader_platform.h"
39#include "vulkan/vk_layer.h"
40#include "vk_layer_config.h"
41#include "vk_dispatch_table_helper.h"
John Zulaufde972ac2017-10-26 12:07:05 -060042#include "vk_typemap_helper.h"
Mark Lobodzinskid4950072017-08-01 13:02:20 -060043
44#include "vk_layer_table.h"
45#include "vk_layer_data.h"
46#include "vk_layer_logging.h"
47#include "vk_layer_extension_utils.h"
48#include "vk_layer_utils.h"
49
50#include "parameter_name.h"
51#include "parameter_validation.h"
52
53// TODO: remove on NDK update (r15 will probably have proper STL impl)
54#ifdef __ANDROID__
55namespace std {
56
57template <typename T>
58std::string to_string(T var) {
59 std::ostringstream ss;
60 ss << var;
61 return ss.str();
62}
63} // namespace std
64#endif
65
66namespace parameter_validation {
67
Mark Lobodzinski78a12a92017-08-08 14:16:51 -060068extern std::unordered_map<std::string, void *> custom_functions;
69
Mark Lobodzinskid4950072017-08-01 13:02:20 -060070extern bool parameter_validation_vkCreateInstance(VkInstance instance, const VkInstanceCreateInfo *pCreateInfo,
71 const VkAllocationCallbacks *pAllocator, VkInstance *pInstance);
72extern bool parameter_validation_vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator);
73extern bool parameter_validation_vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
74 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice);
75extern bool parameter_validation_vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator);
76extern bool parameter_validation_vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
77 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool);
78extern bool parameter_validation_vkCreateDebugReportCallbackEXT(VkInstance instance,
79 const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
80 const VkAllocationCallbacks *pAllocator,
81 VkDebugReportCallbackEXT *pMsgCallback);
82extern bool parameter_validation_vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback,
83 const VkAllocationCallbacks *pAllocator);
84extern bool parameter_validation_vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
85 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool);
86
87// TODO : This can be much smarter, using separate locks for separate global data
88std::mutex global_lock;
89
90static uint32_t loader_layer_if_version = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
91std::unordered_map<void *, layer_data *> layer_data_map;
92std::unordered_map<void *, instance_layer_data *> instance_layer_data_map;
93
94void InitializeManualParameterValidationFunctionPointers(void);
95
96static void init_parameter_validation(instance_layer_data *instance_data, const VkAllocationCallbacks *pAllocator) {
97 layer_debug_actions(instance_data->report_data, instance_data->logging_callback, pAllocator, "lunarg_parameter_validation");
98}
99
100static const VkExtensionProperties instance_extensions[] = {{VK_EXT_DEBUG_REPORT_EXTENSION_NAME, VK_EXT_DEBUG_REPORT_SPEC_VERSION}};
101
102static const VkLayerProperties global_layer = {
103 "VK_LAYER_LUNARG_parameter_validation", VK_LAYER_API_VERSION, 1, "LunarG Validation Layer",
104};
105
106static const int MaxParamCheckerStringLength = 256;
107
108static bool validate_string(debug_report_data *report_data, const char *apiName, const ParameterName &stringName,
109 const char *validateString) {
110 assert(apiName != nullptr);
111 assert(validateString != nullptr);
112
113 bool skip = false;
114
115 VkStringErrorFlags result = vk_string_validate(MaxParamCheckerStringLength, validateString);
116
117 if (result == VK_STRING_ERROR_NONE) {
118 return skip;
119 } else if (result & VK_STRING_ERROR_LENGTH) {
120 skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
121 INVALID_USAGE, LayerName, "%s: string %s exceeds max length %d", apiName, stringName.get_name().c_str(),
122 MaxParamCheckerStringLength);
123 } else if (result & VK_STRING_ERROR_BAD_DATA) {
124 skip = log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
125 INVALID_USAGE, LayerName, "%s: string %s contains invalid characters or is badly formed", apiName,
126 stringName.get_name().c_str());
127 }
128 return skip;
129}
130
131static bool ValidateDeviceQueueFamily(layer_data *device_data, uint32_t queue_family, const char *cmd_name,
132 const char *parameter_name, int32_t error_code, bool optional = false,
133 const char *vu_note = nullptr) {
134 bool skip = false;
135
136 if (!vu_note) vu_note = validation_error_map[error_code];
137 if (!optional && queue_family == VK_QUEUE_FAMILY_IGNORED) {
138 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
139 HandleToUint64(device_data->device), __LINE__, error_code, LayerName,
140 "%s: %s is VK_QUEUE_FAMILY_IGNORED, but it is required to provide a valid queue family index value. %s",
141 cmd_name, parameter_name, vu_note);
142 } else if (device_data->queueFamilyIndexMap.find(queue_family) == device_data->queueFamilyIndexMap.end()) {
143 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
144 HandleToUint64(device_data->device), __LINE__, error_code, LayerName,
145 "%s: %s (= %" PRIu32
146 ") is not one of the queue families given via VkDeviceQueueCreateInfo structures when "
147 "the device was created. %s",
148 cmd_name, parameter_name, queue_family, vu_note);
149 }
150
151 return skip;
152}
153
154static bool ValidateQueueFamilies(layer_data *device_data, uint32_t queue_family_count, const uint32_t *queue_families,
155 const char *cmd_name, const char *array_parameter_name, int32_t unique_error_code,
156 int32_t valid_error_code, bool optional = false, const char *unique_vu_note = nullptr,
157 const char *valid_vu_note = nullptr) {
158 bool skip = false;
159 if (!unique_vu_note) unique_vu_note = validation_error_map[unique_error_code];
160 if (!valid_vu_note) valid_vu_note = validation_error_map[valid_error_code];
161 if (queue_families) {
162 std::unordered_set<uint32_t> set;
163 for (uint32_t i = 0; i < queue_family_count; ++i) {
164 std::string parameter_name = std::string(array_parameter_name) + "[" + std::to_string(i) + "]";
165
166 if (set.count(queue_families[i])) {
167 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
168 HandleToUint64(device_data->device), __LINE__, VALIDATION_ERROR_056002e8, LayerName,
169 "%s: %s (=%" PRIu32 ") is not unique within %s array. %s", cmd_name, parameter_name.c_str(),
170 queue_families[i], array_parameter_name, unique_vu_note);
171 } else {
172 set.insert(queue_families[i]);
173 skip |= ValidateDeviceQueueFamily(device_data, queue_families[i], cmd_name, parameter_name.c_str(),
174 valid_error_code, optional, valid_vu_note);
175 }
176 }
177 }
178 return skip;
179}
180
181VKAPI_ATTR VkResult VKAPI_CALL vkCreateInstance(const VkInstanceCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
182 VkInstance *pInstance) {
183 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
184
185 VkLayerInstanceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
186 assert(chain_info != nullptr);
187 assert(chain_info->u.pLayerInfo != nullptr);
188
189 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
190 PFN_vkCreateInstance fpCreateInstance = (PFN_vkCreateInstance)fpGetInstanceProcAddr(NULL, "vkCreateInstance");
191 if (fpCreateInstance == NULL) {
192 return VK_ERROR_INITIALIZATION_FAILED;
193 }
194
195 // Advance the link info for the next element on the chain
196 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
197
198 result = fpCreateInstance(pCreateInfo, pAllocator, pInstance);
199
200 if (result == VK_SUCCESS) {
201 InitializeManualParameterValidationFunctionPointers();
202 auto my_instance_data = GetLayerDataPtr(get_dispatch_key(*pInstance), instance_layer_data_map);
203 assert(my_instance_data != nullptr);
204
205 layer_init_instance_dispatch_table(*pInstance, &my_instance_data->dispatch_table, fpGetInstanceProcAddr);
206 my_instance_data->instance = *pInstance;
207 my_instance_data->report_data =
208 debug_report_create_instance(&my_instance_data->dispatch_table, *pInstance, pCreateInfo->enabledExtensionCount,
209 pCreateInfo->ppEnabledExtensionNames);
210
211 // Look for one or more debug report create info structures
212 // and setup a callback(s) for each one found.
213 if (!layer_copy_tmp_callbacks(pCreateInfo->pNext, &my_instance_data->num_tmp_callbacks,
214 &my_instance_data->tmp_dbg_create_infos, &my_instance_data->tmp_callbacks)) {
215 if (my_instance_data->num_tmp_callbacks > 0) {
216 // Setup the temporary callback(s) here to catch early issues:
217 if (layer_enable_tmp_callbacks(my_instance_data->report_data, my_instance_data->num_tmp_callbacks,
218 my_instance_data->tmp_dbg_create_infos, my_instance_data->tmp_callbacks)) {
219 // Failure of setting up one or more of the callback.
220 // Therefore, clean up and don't use those callbacks:
221 layer_free_tmp_callbacks(my_instance_data->tmp_dbg_create_infos, my_instance_data->tmp_callbacks);
222 my_instance_data->num_tmp_callbacks = 0;
223 }
224 }
225 }
226
227 init_parameter_validation(my_instance_data, pAllocator);
228 my_instance_data->extensions.InitFromInstanceCreateInfo(pCreateInfo);
229
230 // Ordinarily we'd check these before calling down the chain, but none of the layer support is in place until now, if we
231 // survive we can report the issue now.
232 parameter_validation_vkCreateInstance(*pInstance, pCreateInfo, pAllocator, pInstance);
233
234 if (pCreateInfo->pApplicationInfo) {
235 if (pCreateInfo->pApplicationInfo->pApplicationName) {
236 validate_string(my_instance_data->report_data, "vkCreateInstance",
237 "pCreateInfo->VkApplicationInfo->pApplicationName",
238 pCreateInfo->pApplicationInfo->pApplicationName);
239 }
240
241 if (pCreateInfo->pApplicationInfo->pEngineName) {
242 validate_string(my_instance_data->report_data, "vkCreateInstance", "pCreateInfo->VkApplicationInfo->pEngineName",
243 pCreateInfo->pApplicationInfo->pEngineName);
244 }
245 }
246
247 // Disable the tmp callbacks:
248 if (my_instance_data->num_tmp_callbacks > 0) {
249 layer_disable_tmp_callbacks(my_instance_data->report_data, my_instance_data->num_tmp_callbacks,
250 my_instance_data->tmp_callbacks);
251 }
252 }
253
254 return result;
255}
256
257VKAPI_ATTR void VKAPI_CALL vkDestroyInstance(VkInstance instance, const VkAllocationCallbacks *pAllocator) {
258 // Grab the key before the instance is destroyed.
259 dispatch_key key = get_dispatch_key(instance);
260 bool skip = false;
261 auto instance_data = GetLayerDataPtr(key, instance_layer_data_map);
262
263 // Enable the temporary callback(s) here to catch vkDestroyInstance issues:
264 bool callback_setup = false;
265 if (instance_data->num_tmp_callbacks > 0) {
266 if (!layer_enable_tmp_callbacks(instance_data->report_data, instance_data->num_tmp_callbacks,
267 instance_data->tmp_dbg_create_infos, instance_data->tmp_callbacks)) {
268 callback_setup = true;
269 }
270 }
271
272 skip |= parameter_validation_vkDestroyInstance(instance, pAllocator);
273
274 // Disable and cleanup the temporary callback(s):
275 if (callback_setup) {
276 layer_disable_tmp_callbacks(instance_data->report_data, instance_data->num_tmp_callbacks, instance_data->tmp_callbacks);
277 }
278 if (instance_data->num_tmp_callbacks > 0) {
279 layer_free_tmp_callbacks(instance_data->tmp_dbg_create_infos, instance_data->tmp_callbacks);
280 instance_data->num_tmp_callbacks = 0;
281 }
282
283 if (!skip) {
284 instance_data->dispatch_table.DestroyInstance(instance, pAllocator);
285
286 // Clean up logging callback, if any
287 while (instance_data->logging_callback.size() > 0) {
288 VkDebugReportCallbackEXT callback = instance_data->logging_callback.back();
289 layer_destroy_msg_callback(instance_data->report_data, callback, pAllocator);
290 instance_data->logging_callback.pop_back();
291 }
292
293 layer_debug_report_destroy_instance(instance_data->report_data);
294 }
295
296 FreeLayerDataPtr(key, instance_layer_data_map);
297}
298
299VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugReportCallbackEXT(VkInstance instance,
300 const VkDebugReportCallbackCreateInfoEXT *pCreateInfo,
301 const VkAllocationCallbacks *pAllocator,
302 VkDebugReportCallbackEXT *pMsgCallback) {
303 bool skip = parameter_validation_vkCreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
304 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
305
306 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
307 VkResult result = instance_data->dispatch_table.CreateDebugReportCallbackEXT(instance, pCreateInfo, pAllocator, pMsgCallback);
308 if (result == VK_SUCCESS) {
309 result = layer_create_msg_callback(instance_data->report_data, false, pCreateInfo, pAllocator, pMsgCallback);
310 }
311 return result;
312}
313
314VKAPI_ATTR void VKAPI_CALL vkDestroyDebugReportCallbackEXT(VkInstance instance, VkDebugReportCallbackEXT msgCallback,
315 const VkAllocationCallbacks *pAllocator) {
316 bool skip = parameter_validation_vkDestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
317 if (!skip) {
318 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
319 instance_data->dispatch_table.DestroyDebugReportCallbackEXT(instance, msgCallback, pAllocator);
320 layer_destroy_msg_callback(instance_data->report_data, msgCallback, pAllocator);
321 }
322}
323
324static bool ValidateDeviceCreateInfo(instance_layer_data *instance_data, VkPhysicalDevice physicalDevice,
325 const VkDeviceCreateInfo *pCreateInfo) {
326 bool skip = false;
327
328 if ((pCreateInfo->enabledLayerCount > 0) && (pCreateInfo->ppEnabledLayerNames != NULL)) {
329 for (size_t i = 0; i < pCreateInfo->enabledLayerCount; i++) {
330 skip |= validate_string(instance_data->report_data, "vkCreateDevice", "pCreateInfo->ppEnabledLayerNames",
331 pCreateInfo->ppEnabledLayerNames[i]);
332 }
333 }
334
335 bool maint1 = false;
336 bool negative_viewport = false;
337
338 if ((pCreateInfo->enabledExtensionCount > 0) && (pCreateInfo->ppEnabledExtensionNames != NULL)) {
339 for (size_t i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
340 skip |= validate_string(instance_data->report_data, "vkCreateDevice", "pCreateInfo->ppEnabledExtensionNames",
341 pCreateInfo->ppEnabledExtensionNames[i]);
342 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_KHR_MAINTENANCE1_EXTENSION_NAME) == 0) maint1 = true;
343 if (strcmp(pCreateInfo->ppEnabledExtensionNames[i], VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_EXTENSION_NAME) == 0)
344 negative_viewport = true;
345 }
346 }
347
348 if (maint1 && negative_viewport) {
349 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
350 __LINE__, VALIDATION_ERROR_056002ec, LayerName,
351 "VkDeviceCreateInfo->ppEnabledExtensionNames must not simultaneously include VK_KHR_maintenance1 and "
352 "VK_AMD_negative_viewport_height. %s",
353 validation_error_map[VALIDATION_ERROR_056002ec]);
354 }
355
356 if (pCreateInfo->pNext != NULL && pCreateInfo->pEnabledFeatures) {
357 // Check for get_physical_device_properties2 struct
John Zulaufde972ac2017-10-26 12:07:05 -0600358 const auto *features2 = lvl_find_in_chain<VkPhysicalDeviceFeatures2KHR>(pCreateInfo->pNext);
359 if (features2) {
360 // Cannot include VkPhysicalDeviceFeatures2KHR and have non-null pEnabledFeatures
361 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
362 __LINE__, INVALID_USAGE, LayerName,
363 "VkDeviceCreateInfo->pNext includes a VkPhysicalDeviceFeatures2KHR struct when "
364 "pCreateInfo->pEnabledFeatures is non-NULL.");
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600365 }
366 }
367
368 // Validate pCreateInfo->pQueueCreateInfos
369 if (pCreateInfo->pQueueCreateInfos) {
370 std::unordered_set<uint32_t> set;
371
372 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
373 const uint32_t requested_queue_family = pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex;
374 if (requested_queue_family == VK_QUEUE_FAMILY_IGNORED) {
375 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
376 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, HandleToUint64(physicalDevice), __LINE__,
377 VALIDATION_ERROR_06c002fa, LayerName,
378 "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32
379 "].queueFamilyIndex is "
380 "VK_QUEUE_FAMILY_IGNORED, but it is required to provide a valid queue family index value. %s",
381 i, validation_error_map[VALIDATION_ERROR_06c002fa]);
382 } else if (set.count(requested_queue_family)) {
383 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
384 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, HandleToUint64(physicalDevice), __LINE__,
385 VALIDATION_ERROR_056002e8, LayerName,
386 "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32 "].queueFamilyIndex (=%" PRIu32
387 ") is "
388 "not unique within pCreateInfo->pQueueCreateInfos array. %s",
389 i, requested_queue_family, validation_error_map[VALIDATION_ERROR_056002e8]);
390 } else {
391 set.insert(requested_queue_family);
392 }
393
394 if (pCreateInfo->pQueueCreateInfos[i].pQueuePriorities != nullptr) {
395 for (uint32_t j = 0; j < pCreateInfo->pQueueCreateInfos[i].queueCount; ++j) {
396 const float queue_priority = pCreateInfo->pQueueCreateInfos[i].pQueuePriorities[j];
397 if (!(queue_priority >= 0.f) || !(queue_priority <= 1.f)) {
398 skip |= log_msg(instance_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
399 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, HandleToUint64(physicalDevice), __LINE__,
400 VALIDATION_ERROR_06c002fe, LayerName,
401 "vkCreateDevice: pCreateInfo->pQueueCreateInfos[%" PRIu32 "].pQueuePriorities[%" PRIu32
402 "] (=%f) is not between 0 and 1 (inclusive). %s",
403 i, j, queue_priority, validation_error_map[VALIDATION_ERROR_06c002fe]);
404 }
405 }
406 }
407 }
408 }
409
410 return skip;
411}
412
413VKAPI_ATTR VkResult VKAPI_CALL vkCreateDevice(VkPhysicalDevice physicalDevice, const VkDeviceCreateInfo *pCreateInfo,
414 const VkAllocationCallbacks *pAllocator, VkDevice *pDevice) {
415 // NOTE: Don't validate physicalDevice or any dispatchable object as the first parameter. We couldn't get here if it was wrong!
416
417 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
418 bool skip = false;
419 auto my_instance_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map);
420 assert(my_instance_data != nullptr);
421 std::unique_lock<std::mutex> lock(global_lock);
422
423 skip |= parameter_validation_vkCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
424
425 if (pCreateInfo != NULL) skip |= ValidateDeviceCreateInfo(my_instance_data, physicalDevice, pCreateInfo);
426
427 if (!skip) {
428 VkLayerDeviceCreateInfo *chain_info = get_chain_info(pCreateInfo, VK_LAYER_LINK_INFO);
429 assert(chain_info != nullptr);
430 assert(chain_info->u.pLayerInfo != nullptr);
431
432 PFN_vkGetInstanceProcAddr fpGetInstanceProcAddr = chain_info->u.pLayerInfo->pfnNextGetInstanceProcAddr;
433 PFN_vkGetDeviceProcAddr fpGetDeviceProcAddr = chain_info->u.pLayerInfo->pfnNextGetDeviceProcAddr;
434 PFN_vkCreateDevice fpCreateDevice = (PFN_vkCreateDevice)fpGetInstanceProcAddr(my_instance_data->instance, "vkCreateDevice");
435 if (fpCreateDevice == NULL) {
436 return VK_ERROR_INITIALIZATION_FAILED;
437 }
438
439 // Advance the link info for the next element on the chain
440 chain_info->u.pLayerInfo = chain_info->u.pLayerInfo->pNext;
441
442 lock.unlock();
443
444 result = fpCreateDevice(physicalDevice, pCreateInfo, pAllocator, pDevice);
445
446 lock.lock();
447
448 validate_result(my_instance_data->report_data, "vkCreateDevice", {}, result);
449
450 if (result == VK_SUCCESS) {
451 layer_data *my_device_data = GetLayerDataPtr(get_dispatch_key(*pDevice), layer_data_map);
452 assert(my_device_data != nullptr);
453
454 my_device_data->report_data = layer_debug_report_create_device(my_instance_data->report_data, *pDevice);
455 layer_init_device_dispatch_table(*pDevice, &my_device_data->dispatch_table, fpGetDeviceProcAddr);
456
457 my_device_data->extensions.InitFromDeviceCreateInfo(&my_instance_data->extensions, pCreateInfo);
458
459 // Store createdevice data
460 if ((pCreateInfo != nullptr) && (pCreateInfo->pQueueCreateInfos != nullptr)) {
461 for (uint32_t i = 0; i < pCreateInfo->queueCreateInfoCount; ++i) {
462 my_device_data->queueFamilyIndexMap.insert(std::make_pair(pCreateInfo->pQueueCreateInfos[i].queueFamilyIndex,
463 pCreateInfo->pQueueCreateInfos[i].queueCount));
464 }
465 }
466
467 // Query and save physical device limits for this device
468 VkPhysicalDeviceProperties device_properties = {};
469 my_instance_data->dispatch_table.GetPhysicalDeviceProperties(physicalDevice, &device_properties);
470 memcpy(&my_device_data->device_limits, &device_properties.limits, sizeof(VkPhysicalDeviceLimits));
471 my_device_data->physical_device = physicalDevice;
472 my_device_data->device = *pDevice;
473
474 // Save app-enabled features in this device's layer_data structure
John Zulauf1bde5bb2017-10-18 18:21:23 -0600475 // The enabled features can come from either pEnabledFeatures, or from the pNext chain
476 const VkPhysicalDeviceFeatures *enabled_features_found = pCreateInfo->pEnabledFeatures;
477 if ((nullptr == enabled_features_found) && my_device_data->extensions.vk_khr_get_physical_device_properties_2) {
John Zulaufde972ac2017-10-26 12:07:05 -0600478 const auto *features2 = lvl_find_in_chain<VkPhysicalDeviceFeatures2KHR>(pCreateInfo->pNext);
479 if (features2) {
480 enabled_features_found = &(features2->features);
John Zulauf1bde5bb2017-10-18 18:21:23 -0600481 }
482 }
483 if (enabled_features_found) {
484 my_device_data->physical_device_features = *enabled_features_found;
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600485 } else {
486 memset(&my_device_data->physical_device_features, 0, sizeof(VkPhysicalDeviceFeatures));
487 }
488 }
489 }
490
491 return result;
492}
493
494VKAPI_ATTR void VKAPI_CALL vkDestroyDevice(VkDevice device, const VkAllocationCallbacks *pAllocator) {
495 dispatch_key key = get_dispatch_key(device);
496 bool skip = false;
497 layer_data *device_data = GetLayerDataPtr(key, layer_data_map);
498 {
499 std::unique_lock<std::mutex> lock(global_lock);
500 skip |= parameter_validation_vkDestroyDevice(device, pAllocator);
501 }
502
503 if (!skip) {
504 layer_debug_report_destroy_device(device);
505 device_data->dispatch_table.DestroyDevice(device, pAllocator);
506 }
507 FreeLayerDataPtr(key, layer_data_map);
508}
509
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600510bool pv_vkGetDeviceQueue(VkDevice device, uint32_t queueFamilyIndex, uint32_t queueIndex, VkQueue *pQueue) {
511 bool skip = false;
512 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
513
514 skip |=
515 ValidateDeviceQueueFamily(device_data, queueFamilyIndex, "vkGetDeviceQueue", "queueFamilyIndex", VALIDATION_ERROR_29600300);
516 const auto &queue_data = device_data->queueFamilyIndexMap.find(queueFamilyIndex);
517 if (queue_data != device_data->queueFamilyIndexMap.end() && queue_data->second <= queueIndex) {
518 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT,
519 HandleToUint64(device), __LINE__, VALIDATION_ERROR_29600302, LayerName,
520 "vkGetDeviceQueue: queueIndex (=%" PRIu32
521 ") is not less than the number of queues requested from "
522 "queueFamilyIndex (=%" PRIu32 ") when the device was created (i.e. is not less than %" PRIu32 "). %s",
523 queueIndex, queueFamilyIndex, queue_data->second, validation_error_map[VALIDATION_ERROR_29600302]);
524 }
525 return skip;
526}
527
528VKAPI_ATTR VkResult VKAPI_CALL vkCreateCommandPool(VkDevice device, const VkCommandPoolCreateInfo *pCreateInfo,
529 const VkAllocationCallbacks *pAllocator, VkCommandPool *pCommandPool) {
530 layer_data *local_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
531 bool skip = false;
532 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
533 std::unique_lock<std::mutex> lock(global_lock);
534
535 skip |= ValidateDeviceQueueFamily(local_data, pCreateInfo->queueFamilyIndex, "vkCreateCommandPool",
536 "pCreateInfo->queueFamilyIndex", VALIDATION_ERROR_02c0004e);
537
538 skip |= parameter_validation_vkCreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
539
540 lock.unlock();
541 if (!skip) {
542 result = local_data->dispatch_table.CreateCommandPool(device, pCreateInfo, pAllocator, pCommandPool);
543 }
544 return result;
545}
546
547VKAPI_ATTR VkResult VKAPI_CALL vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo *pCreateInfo,
548 const VkAllocationCallbacks *pAllocator, VkQueryPool *pQueryPool) {
549 VkResult result = VK_ERROR_VALIDATION_FAILED_EXT;
550 bool skip = false;
551 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
552
553 skip |= parameter_validation_vkCreateQueryPool(device, pCreateInfo, pAllocator, pQueryPool);
554
555 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
556 if (pCreateInfo != nullptr) {
557 // If queryType is VK_QUERY_TYPE_PIPELINE_STATISTICS, pipelineStatistics must be a valid combination of
558 // VkQueryPipelineStatisticFlagBits values
559 if ((pCreateInfo->queryType == VK_QUERY_TYPE_PIPELINE_STATISTICS) && (pCreateInfo->pipelineStatistics != 0) &&
560 ((pCreateInfo->pipelineStatistics & (~AllVkQueryPipelineStatisticFlagBits)) != 0)) {
561 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
562 __LINE__, VALIDATION_ERROR_11c00630, LayerName,
563 "vkCreateQueryPool(): if pCreateInfo->queryType is "
564 "VK_QUERY_TYPE_PIPELINE_STATISTICS, pCreateInfo->pipelineStatistics must be "
565 "a valid combination of VkQueryPipelineStatisticFlagBits values. %s",
566 validation_error_map[VALIDATION_ERROR_11c00630]);
567 }
568 }
569 if (!skip) {
570 result = device_data->dispatch_table.CreateQueryPool(device, pCreateInfo, pAllocator, pQueryPool);
571 }
572 return result;
573}
574
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600575bool pv_vkCreateBuffer(VkDevice device, const VkBufferCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
576 VkBuffer *pBuffer) {
577 bool skip = false;
578 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
579 debug_report_data *report_data = device_data->report_data;
580
581 if (pCreateInfo != nullptr) {
582 // Buffer size must be greater than 0 (error 00663)
583 skip |=
584 ValidateGreaterThan(report_data, "vkCreateBuffer", "pCreateInfo->size", static_cast<uint32_t>(pCreateInfo->size), 0u);
585
586 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
587 if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
588 // If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
589 if (pCreateInfo->queueFamilyIndexCount <= 1) {
590 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
591 VALIDATION_ERROR_01400724, LayerName,
592 "vkCreateBuffer: if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
593 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
594 validation_error_map[VALIDATION_ERROR_01400724]);
595 }
596
597 // If sharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
598 // queueFamilyIndexCount uint32_t values
599 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
600 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
601 VALIDATION_ERROR_01400722, LayerName,
602 "vkCreateBuffer: if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
603 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
604 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
605 validation_error_map[VALIDATION_ERROR_01400722]);
606 } else {
607 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
608 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
609 "vkCreateBuffer", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE, INVALID_USAGE,
610 false, "", "");
611 }
612 }
613
614 // If flags contains VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT or VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, it must also contain
615 // VK_BUFFER_CREATE_SPARSE_BINDING_BIT
616 if (((pCreateInfo->flags & (VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT | VK_BUFFER_CREATE_SPARSE_ALIASED_BIT)) != 0) &&
617 ((pCreateInfo->flags & VK_BUFFER_CREATE_SPARSE_BINDING_BIT) != VK_BUFFER_CREATE_SPARSE_BINDING_BIT)) {
618 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
619 VALIDATION_ERROR_0140072c, LayerName,
620 "vkCreateBuffer: if pCreateInfo->flags contains VK_BUFFER_CREATE_SPARSE_RESIDENCY_BIT or "
621 "VK_BUFFER_CREATE_SPARSE_ALIASED_BIT, it must also contain VK_BUFFER_CREATE_SPARSE_BINDING_BIT. %s",
622 validation_error_map[VALIDATION_ERROR_0140072c]);
623 }
624 }
625
626 return skip;
627}
628
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600629bool pv_vkCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
630 VkImage *pImage) {
631 bool skip = false;
632 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
633 debug_report_data *report_data = device_data->report_data;
634
635 if (pCreateInfo != nullptr) {
636 if ((device_data->physical_device_features.textureCompressionETC2 == false) &&
637 FormatIsCompressed_ETC2_EAC(pCreateInfo->format)) {
638 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
639 DEVICE_FEATURE, LayerName,
640 "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionETC2 feature is "
641 "not enabled: neither ETC2 nor EAC formats can be used to create images.",
642 string_VkFormat(pCreateInfo->format));
643 }
644
645 if ((device_data->physical_device_features.textureCompressionASTC_LDR == false) &&
646 FormatIsCompressed_ASTC_LDR(pCreateInfo->format)) {
647 skip |=
648 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
649 DEVICE_FEATURE, LayerName,
650 "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionASTC_LDR feature is "
651 "not enabled: ASTC formats cannot be used to create images.",
652 string_VkFormat(pCreateInfo->format));
653 }
654
655 if ((device_data->physical_device_features.textureCompressionBC == false) && FormatIsCompressed_BC(pCreateInfo->format)) {
656 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
657 DEVICE_FEATURE, LayerName,
658 "vkCreateImage(): Attempting to create VkImage with format %s. The textureCompressionBC feature is "
659 "not enabled: BC compressed formats cannot be used to create images.",
660 string_VkFormat(pCreateInfo->format));
661 }
662
663 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
664 if (pCreateInfo->sharingMode == VK_SHARING_MODE_CONCURRENT) {
665 // If sharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
666 if (pCreateInfo->queueFamilyIndexCount <= 1) {
667 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
668 VALIDATION_ERROR_09e0075c, LayerName,
669 "vkCreateImage(): if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
670 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
671 validation_error_map[VALIDATION_ERROR_09e0075c]);
672 }
673
674 // If sharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
675 // queueFamilyIndexCount uint32_t values
676 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
677 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
678 VALIDATION_ERROR_09e0075a, LayerName,
679 "vkCreateImage(): if pCreateInfo->sharingMode is VK_SHARING_MODE_CONCURRENT, "
680 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
681 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
682 validation_error_map[VALIDATION_ERROR_09e0075a]);
683 } else {
684 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
685 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
686 "vkCreateImage", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE, INVALID_USAGE,
687 false, "", "");
688 }
689 }
690
691 // width, height, and depth members of extent must be greater than 0
692 skip |= ValidateGreaterThan(report_data, "vkCreateImage", "pCreateInfo->extent.width", pCreateInfo->extent.width, 0u);
693 skip |= ValidateGreaterThan(report_data, "vkCreateImage", "pCreateInfo->extent.height", pCreateInfo->extent.height, 0u);
694 skip |= ValidateGreaterThan(report_data, "vkCreateImage", "pCreateInfo->extent.depth", pCreateInfo->extent.depth, 0u);
695
696 // mipLevels must be greater than 0
697 skip |= ValidateGreaterThan(report_data, "vkCreateImage", "pCreateInfo->mipLevels", pCreateInfo->mipLevels, 0u);
698
699 // arrayLayers must be greater than 0
700 skip |= ValidateGreaterThan(report_data, "vkCreateImage", "pCreateInfo->arrayLayers", pCreateInfo->arrayLayers, 0u);
701
702 // If imageType is VK_IMAGE_TYPE_1D, both extent.height and extent.depth must be 1
703 if ((pCreateInfo->imageType == VK_IMAGE_TYPE_1D) && (pCreateInfo->extent.height != 1) && (pCreateInfo->extent.depth != 1)) {
704 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
705 VALIDATION_ERROR_09e00778, LayerName,
706 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_1D, both "
707 "pCreateInfo->extent.height and pCreateInfo->extent.depth must be 1. %s",
708 validation_error_map[VALIDATION_ERROR_09e00778]);
709 }
710
711 if (pCreateInfo->imageType == VK_IMAGE_TYPE_2D) {
712 // If imageType is VK_IMAGE_TYPE_2D and flags contains VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, extent.width and
713 // extent.height must be equal
714 if ((pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) &&
715 (pCreateInfo->extent.width != pCreateInfo->extent.height)) {
716 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
717 VALIDATION_ERROR_09e00774, LayerName,
718 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_2D and "
719 "pCreateInfo->flags contains VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, "
720 "pCreateInfo->extent.width and pCreateInfo->extent.height must be equal. %s",
721 validation_error_map[VALIDATION_ERROR_09e00774]);
722 }
723
724 if (pCreateInfo->extent.depth != 1) {
725 skip |= log_msg(
726 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
727 VALIDATION_ERROR_09e0077a, LayerName,
728 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_2D, pCreateInfo->extent.depth must be 1. %s",
729 validation_error_map[VALIDATION_ERROR_09e0077a]);
730 }
731 }
732
733 // mipLevels must be less than or equal to floor(log2(max(extent.width,extent.height,extent.depth)))+1
734 uint32_t maxDim = std::max(std::max(pCreateInfo->extent.width, pCreateInfo->extent.height), pCreateInfo->extent.depth);
735 if (pCreateInfo->mipLevels > (floor(log2(maxDim)) + 1)) {
736 skip |=
737 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
738 VALIDATION_ERROR_09e0077c, LayerName,
739 "vkCreateImage(): pCreateInfo->mipLevels must be less than or equal to "
740 "floor(log2(max(pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth)))+1. %s",
741 validation_error_map[VALIDATION_ERROR_09e0077c]);
742 }
743
744 // If flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain
745 // VK_IMAGE_CREATE_SPARSE_BINDING_BIT
746 if (((pCreateInfo->flags & (VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT)) != 0) &&
747 ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) != VK_IMAGE_CREATE_SPARSE_BINDING_BIT)) {
748 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
749 VALIDATION_ERROR_09e007b6, LayerName,
750 "vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or "
751 "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain VK_IMAGE_CREATE_SPARSE_BINDING_BIT. %s",
752 validation_error_map[VALIDATION_ERROR_09e007b6]);
753 }
754
755 // Check for combinations of attributes that are incompatible with having VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT set
756 if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) != 0) {
757 // Linear tiling is unsupported
758 if (VK_IMAGE_TILING_LINEAR == pCreateInfo->tiling) {
759 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
760 INVALID_USAGE, LayerName,
761 "vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT "
762 "then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
763 }
764
765 // Sparse 1D image isn't valid
766 if (VK_IMAGE_TYPE_1D == pCreateInfo->imageType) {
767 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
768 VALIDATION_ERROR_09e00794, LayerName,
769 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 1D image. %s",
770 validation_error_map[VALIDATION_ERROR_09e00794]);
771 }
772
773 // Sparse 2D image when device doesn't support it
774 if ((VK_FALSE == device_data->physical_device_features.sparseResidencyImage2D) &&
775 (VK_IMAGE_TYPE_2D == pCreateInfo->imageType)) {
776 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
777 VALIDATION_ERROR_09e00796, LayerName,
778 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2D image if corresponding "
779 "feature is not enabled on the device. %s",
780 validation_error_map[VALIDATION_ERROR_09e00796]);
781 }
782
783 // Sparse 3D image when device doesn't support it
784 if ((VK_FALSE == device_data->physical_device_features.sparseResidencyImage3D) &&
785 (VK_IMAGE_TYPE_3D == pCreateInfo->imageType)) {
786 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
787 VALIDATION_ERROR_09e00798, LayerName,
788 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 3D image if corresponding "
789 "feature is not enabled on the device. %s",
790 validation_error_map[VALIDATION_ERROR_09e00798]);
791 }
792
793 // Multi-sample 2D image when device doesn't support it
794 if (VK_IMAGE_TYPE_2D == pCreateInfo->imageType) {
795 if ((VK_FALSE == device_data->physical_device_features.sparseResidency2Samples) &&
796 (VK_SAMPLE_COUNT_2_BIT == pCreateInfo->samples)) {
797 skip |= log_msg(
798 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
799 VALIDATION_ERROR_09e0079a, LayerName,
800 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2-sample image if corresponding "
801 "feature is not enabled on the device. %s",
802 validation_error_map[VALIDATION_ERROR_09e0079a]);
803 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency4Samples) &&
804 (VK_SAMPLE_COUNT_4_BIT == pCreateInfo->samples)) {
805 skip |= log_msg(
806 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
807 VALIDATION_ERROR_09e0079c, LayerName,
808 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 4-sample image if corresponding "
809 "feature is not enabled on the device. %s",
810 validation_error_map[VALIDATION_ERROR_09e0079c]);
811 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency8Samples) &&
812 (VK_SAMPLE_COUNT_8_BIT == pCreateInfo->samples)) {
813 skip |= log_msg(
814 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
815 VALIDATION_ERROR_09e0079e, LayerName,
816 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 8-sample image if corresponding "
817 "feature is not enabled on the device. %s",
818 validation_error_map[VALIDATION_ERROR_09e0079e]);
819 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency16Samples) &&
820 (VK_SAMPLE_COUNT_16_BIT == pCreateInfo->samples)) {
821 skip |= log_msg(
822 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
823 VALIDATION_ERROR_09e007a0, LayerName,
824 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 16-sample image if corresponding "
825 "feature is not enabled on the device. %s",
826 validation_error_map[VALIDATION_ERROR_09e007a0]);
827 }
828 }
829 }
830 }
831 return skip;
832}
833
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600834bool pv_vkCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
835 VkImageView *pView) {
836 bool skip = false;
837 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
838 debug_report_data *report_data = device_data->report_data;
839
840 if (pCreateInfo != nullptr) {
841 if ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D) || (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_2D)) {
842 if ((pCreateInfo->subresourceRange.layerCount != 1) &&
843 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
844 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
845 LayerName,
846 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_%dD, "
847 "pCreateInfo->subresourceRange.layerCount must be 1",
848 ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D) ? 1 : 2));
849 }
850 } else if ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY) ||
851 (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY)) {
852 if ((pCreateInfo->subresourceRange.layerCount < 1) &&
853 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
854 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
855 LayerName,
856 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_%dD_ARRAY, "
857 "pCreateInfo->subresourceRange.layerCount must be >= 1",
858 ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY) ? 1 : 2));
859 }
860 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE) {
861 if ((pCreateInfo->subresourceRange.layerCount != 6) &&
862 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
863 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
864 LayerName,
865 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_CUBE, "
866 "pCreateInfo->subresourceRange.layerCount must be 6");
867 }
868 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) {
869 if (((pCreateInfo->subresourceRange.layerCount == 0) || ((pCreateInfo->subresourceRange.layerCount % 6) != 0)) &&
870 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
871 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
872 LayerName,
873 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_CUBE_ARRAY, "
874 "pCreateInfo->subresourceRange.layerCount must be a multiple of 6");
875 }
876 if (!device_data->physical_device_features.imageCubeArray) {
877 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
878 LayerName, "vkCreateImageView: Device feature imageCubeArray not enabled.");
879 }
880 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_3D) {
881 if (pCreateInfo->subresourceRange.baseArrayLayer != 0) {
882 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
883 LayerName,
884 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_3D, "
885 "pCreateInfo->subresourceRange.baseArrayLayer must be 0");
886 }
887
888 if ((pCreateInfo->subresourceRange.layerCount != 1) &&
889 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
890 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
891 LayerName,
892 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_3D, "
893 "pCreateInfo->subresourceRange.layerCount must be 1");
894 }
895 }
896 }
897 return skip;
898}
899
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600900bool pv_vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
901 const VkGraphicsPipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
902 VkPipeline *pPipelines) {
903 bool skip = false;
904 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
905 debug_report_data *report_data = device_data->report_data;
906
907 if (pCreateInfos != nullptr) {
908 for (uint32_t i = 0; i < createInfoCount; ++i) {
909 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
910 if (pCreateInfos[i].pVertexInputState != nullptr) {
911 auto const &vertex_input_state = pCreateInfos[i].pVertexInputState;
912 for (uint32_t d = 0; d < vertex_input_state->vertexBindingDescriptionCount; ++d) {
913 auto const &vertex_bind_desc = vertex_input_state->pVertexBindingDescriptions[d];
914 if (vertex_bind_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
915 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
916 __LINE__, VALIDATION_ERROR_14c004d4, LayerName,
917 "vkCreateGraphicsPipelines: parameter "
918 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].binding (%u) is "
919 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
920 i, d, vertex_bind_desc.binding, device_data->device_limits.maxVertexInputBindings,
921 validation_error_map[VALIDATION_ERROR_14c004d4]);
922 }
923
924 if (vertex_bind_desc.stride > device_data->device_limits.maxVertexInputBindingStride) {
925 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
926 __LINE__, VALIDATION_ERROR_14c004d6, LayerName,
927 "vkCreateGraphicsPipelines: parameter "
928 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].stride (%u) is greater "
929 "than VkPhysicalDeviceLimits::maxVertexInputBindingStride (%u). %s",
930 i, d, vertex_bind_desc.stride, device_data->device_limits.maxVertexInputBindingStride,
931 validation_error_map[VALIDATION_ERROR_14c004d6]);
932 }
933 }
934
935 for (uint32_t d = 0; d < vertex_input_state->vertexAttributeDescriptionCount; ++d) {
936 auto const &vertex_attrib_desc = vertex_input_state->pVertexAttributeDescriptions[d];
937 if (vertex_attrib_desc.location >= device_data->device_limits.maxVertexInputAttributes) {
938 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
939 __LINE__, VALIDATION_ERROR_14a004d8, LayerName,
940 "vkCreateGraphicsPipelines: parameter "
941 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].location (%u) is "
942 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes (%u). %s",
943 i, d, vertex_attrib_desc.location, device_data->device_limits.maxVertexInputAttributes,
944 validation_error_map[VALIDATION_ERROR_14a004d8]);
945 }
946
947 if (vertex_attrib_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
948 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
949 __LINE__, VALIDATION_ERROR_14a004da, LayerName,
950 "vkCreateGraphicsPipelines: parameter "
951 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].binding (%u) is "
952 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
953 i, d, vertex_attrib_desc.binding, device_data->device_limits.maxVertexInputBindings,
954 validation_error_map[VALIDATION_ERROR_14a004da]);
955 }
956
957 if (vertex_attrib_desc.offset > device_data->device_limits.maxVertexInputAttributeOffset) {
958 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
959 __LINE__, VALIDATION_ERROR_14a004dc, LayerName,
960 "vkCreateGraphicsPipelines: parameter "
961 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].offset (%u) is "
962 "greater than VkPhysicalDeviceLimits::maxVertexInputAttributeOffset (%u). %s",
963 i, d, vertex_attrib_desc.offset, device_data->device_limits.maxVertexInputAttributeOffset,
964 validation_error_map[VALIDATION_ERROR_14a004dc]);
965 }
966 }
967 }
968
969 if (pCreateInfos[i].pStages != nullptr) {
970 bool has_control = false;
971 bool has_eval = false;
972
973 for (uint32_t stage_index = 0; stage_index < pCreateInfos[i].stageCount; ++stage_index) {
974 if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
975 has_control = true;
976 } else if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) {
977 has_eval = true;
978 }
979 }
980
981 // pTessellationState is ignored without both tessellation control and tessellation evaluation shaders stages
982 if (has_control && has_eval) {
983 if (pCreateInfos[i].pTessellationState == nullptr) {
984 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
985 __LINE__, VALIDATION_ERROR_096005b6, LayerName,
986 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pStages includes a tessellation control "
987 "shader stage and a tessellation evaluation shader stage, "
988 "pCreateInfos[%d].pTessellationState must not be NULL. %s",
989 i, i, validation_error_map[VALIDATION_ERROR_096005b6]);
990 } else {
991 skip |= validate_struct_pnext(
992 report_data, "vkCreateGraphicsPipelines",
993 ParameterName("pCreateInfos[%i].pTessellationState->pNext", ParameterName::IndexVector{i}), NULL,
994 pCreateInfos[i].pTessellationState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0961c40d);
995
996 skip |= validate_reserved_flags(
997 report_data, "vkCreateGraphicsPipelines",
998 ParameterName("pCreateInfos[%i].pTessellationState->flags", ParameterName::IndexVector{i}),
999 pCreateInfos[i].pTessellationState->flags, VALIDATION_ERROR_10809005);
1000
1001 if (pCreateInfos[i].pTessellationState->sType !=
1002 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO) {
1003 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1004 __LINE__, VALIDATION_ERROR_1082b00b, LayerName,
1005 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pTessellationState->sType must "
1006 "be VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO. %s",
1007 i, validation_error_map[VALIDATION_ERROR_1082b00b]);
1008 }
1009
1010 if (pCreateInfos[i].pTessellationState->patchControlPoints == 0 ||
1011 pCreateInfos[i].pTessellationState->patchControlPoints >
1012 device_data->device_limits.maxTessellationPatchSize) {
1013 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1014 __LINE__, VALIDATION_ERROR_1080097c, LayerName,
1015 "vkCreateGraphicsPipelines: invalid parameter "
1016 "pCreateInfos[%d].pTessellationState->patchControlPoints value %u. patchControlPoints "
1017 "should be >0 and <=%u. %s",
1018 i, pCreateInfos[i].pTessellationState->patchControlPoints,
1019 device_data->device_limits.maxTessellationPatchSize,
1020 validation_error_map[VALIDATION_ERROR_1080097c]);
1021 }
1022 }
1023 }
1024 }
1025
1026 // pViewportState, pMultisampleState, pDepthStencilState, and pColorBlendState ignored when rasterization is disabled
1027 if ((pCreateInfos[i].pRasterizationState != nullptr) &&
1028 (pCreateInfos[i].pRasterizationState->rasterizerDiscardEnable == VK_FALSE)) {
1029 if (pCreateInfos[i].pViewportState == nullptr) {
1030 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1031 __LINE__, VALIDATION_ERROR_096005dc, LayerName,
1032 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pRasterizationState->rasterizerDiscardEnable "
1033 "is VK_FALSE, pCreateInfos[%d].pViewportState must be a pointer to a valid "
1034 "VkPipelineViewportStateCreateInfo structure. %s",
1035 i, i, validation_error_map[VALIDATION_ERROR_096005dc]);
1036 } else {
1037 if (pCreateInfos[i].pViewportState->scissorCount != pCreateInfos[i].pViewportState->viewportCount) {
1038 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1039 __LINE__, VALIDATION_ERROR_10c00988, LayerName,
1040 "Graphics Pipeline viewport count (%u) must match scissor count (%u). %s",
1041 pCreateInfos[i].pViewportState->viewportCount, pCreateInfos[i].pViewportState->scissorCount,
1042 validation_error_map[VALIDATION_ERROR_10c00988]);
1043 }
1044
1045 skip |= validate_struct_pnext(
1046 report_data, "vkCreateGraphicsPipelines",
1047 ParameterName("pCreateInfos[%i].pViewportState->pNext", ParameterName::IndexVector{i}), NULL,
1048 pCreateInfos[i].pViewportState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_10c1c40d);
1049
1050 skip |= validate_reserved_flags(
1051 report_data, "vkCreateGraphicsPipelines",
1052 ParameterName("pCreateInfos[%i].pViewportState->flags", ParameterName::IndexVector{i}),
1053 pCreateInfos[i].pViewportState->flags, VALIDATION_ERROR_10c09005);
1054
1055 if (pCreateInfos[i].pViewportState->sType != VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO) {
1056 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1057 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1058 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pViewportState->sType must be "
1059 "VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO",
1060 i);
1061 }
1062
1063 if (device_data->physical_device_features.multiViewport == false) {
1064 if (pCreateInfos[i].pViewportState->viewportCount != 1) {
1065 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1066 __LINE__, VALIDATION_ERROR_10c00980, LayerName,
1067 "vkCreateGraphicsPipelines: The multiViewport feature is not enabled, so "
1068 "pCreateInfos[%d].pViewportState->viewportCount must be 1 but is %d. %s",
1069 i, pCreateInfos[i].pViewportState->viewportCount,
1070 validation_error_map[VALIDATION_ERROR_10c00980]);
1071 }
1072 if (pCreateInfos[i].pViewportState->scissorCount != 1) {
1073 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1074 __LINE__, VALIDATION_ERROR_10c00982, LayerName,
1075 "vkCreateGraphicsPipelines: The multiViewport feature is not enabled, so "
1076 "pCreateInfos[%d].pViewportState->scissorCount must be 1 but is %d. %s",
1077 i, pCreateInfos[i].pViewportState->scissorCount,
1078 validation_error_map[VALIDATION_ERROR_10c00982]);
1079 }
1080 } else {
1081 if ((pCreateInfos[i].pViewportState->viewportCount < 1) ||
1082 (pCreateInfos[i].pViewportState->viewportCount > device_data->device_limits.maxViewports)) {
1083 skip |=
1084 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1085 __LINE__, VALIDATION_ERROR_10c00984, LayerName,
1086 "vkCreateGraphicsPipelines: multiViewport feature is enabled; "
1087 "pCreateInfos[%d].pViewportState->viewportCount is %d but must be between 1 and "
1088 "maxViewports (%d), inclusive. %s",
1089 i, pCreateInfos[i].pViewportState->viewportCount, device_data->device_limits.maxViewports,
1090 validation_error_map[VALIDATION_ERROR_10c00984]);
1091 }
1092 if ((pCreateInfos[i].pViewportState->scissorCount < 1) ||
1093 (pCreateInfos[i].pViewportState->scissorCount > device_data->device_limits.maxViewports)) {
1094 skip |=
1095 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1096 __LINE__, VALIDATION_ERROR_10c00986, LayerName,
1097 "vkCreateGraphicsPipelines: multiViewport feature is enabled; "
1098 "pCreateInfos[%d].pViewportState->scissorCount is %d but must be between 1 and "
1099 "maxViewports (%d), inclusive. %s",
1100 i, pCreateInfos[i].pViewportState->scissorCount, device_data->device_limits.maxViewports,
1101 validation_error_map[VALIDATION_ERROR_10c00986]);
1102 }
1103 }
1104
1105 if (pCreateInfos[i].pDynamicState != nullptr) {
1106 bool has_dynamic_viewport = false;
1107 bool has_dynamic_scissor = false;
1108
1109 for (uint32_t state_index = 0; state_index < pCreateInfos[i].pDynamicState->dynamicStateCount;
1110 ++state_index) {
1111 if (pCreateInfos[i].pDynamicState->pDynamicStates[state_index] == VK_DYNAMIC_STATE_VIEWPORT) {
1112 has_dynamic_viewport = true;
1113 } else if (pCreateInfos[i].pDynamicState->pDynamicStates[state_index] == VK_DYNAMIC_STATE_SCISSOR) {
1114 has_dynamic_scissor = true;
1115 }
1116 }
1117
1118 // If no element of the pDynamicStates member of pDynamicState is VK_DYNAMIC_STATE_VIEWPORT, the pViewports
1119 // member of pViewportState must be a pointer to an array of pViewportState->viewportCount VkViewport
1120 // structures
1121 if (!has_dynamic_viewport && (pCreateInfos[i].pViewportState->pViewports == nullptr)) {
1122 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1123 __LINE__, VALIDATION_ERROR_096005d6, LayerName,
1124 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pDynamicState->pDynamicStates does not "
1125 "contain VK_DYNAMIC_STATE_VIEWPORT, pCreateInfos[%d].pViewportState->pViewports must "
1126 "not be NULL. %s",
1127 i, i, validation_error_map[VALIDATION_ERROR_096005d6]);
1128 }
1129
1130 // If no element of the pDynamicStates member of pDynamicState is VK_DYNAMIC_STATE_SCISSOR, the pScissors
1131 // member
1132 // of pViewportState must be a pointer to an array of pViewportState->scissorCount VkRect2D structures
1133 if (!has_dynamic_scissor && (pCreateInfos[i].pViewportState->pScissors == nullptr)) {
1134 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1135 __LINE__, VALIDATION_ERROR_096005d8, LayerName,
1136 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pDynamicState->pDynamicStates does not "
1137 "contain VK_DYNAMIC_STATE_SCISSOR, pCreateInfos[%d].pViewportState->pScissors must not "
1138 "be NULL. %s",
1139 i, i, validation_error_map[VALIDATION_ERROR_096005d8]);
1140 }
1141 }
1142 }
1143
1144 if (pCreateInfos[i].pMultisampleState == nullptr) {
1145 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1146 __LINE__, VALIDATION_ERROR_096005de, LayerName,
1147 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pRasterizationState->rasterizerDiscardEnable "
1148 "is VK_FALSE, pCreateInfos[%d].pMultisampleState must not be NULL. %s",
1149 i, i, validation_error_map[VALIDATION_ERROR_096005de]);
1150 } else {
1151 skip |= validate_struct_pnext(
1152 report_data, "vkCreateGraphicsPipelines",
1153 ParameterName("pCreateInfos[%i].pMultisampleState->pNext", ParameterName::IndexVector{i}), NULL,
1154 pCreateInfos[i].pMultisampleState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_1001c40d);
1155
1156 skip |= validate_reserved_flags(
1157 report_data, "vkCreateGraphicsPipelines",
1158 ParameterName("pCreateInfos[%i].pMultisampleState->flags", ParameterName::IndexVector{i}),
1159 pCreateInfos[i].pMultisampleState->flags, VALIDATION_ERROR_10009005);
1160
1161 skip |= validate_bool32(
1162 report_data, "vkCreateGraphicsPipelines",
1163 ParameterName("pCreateInfos[%i].pMultisampleState->sampleShadingEnable", ParameterName::IndexVector{i}),
1164 pCreateInfos[i].pMultisampleState->sampleShadingEnable);
1165
1166 skip |= validate_array(
1167 report_data, "vkCreateGraphicsPipelines",
1168 ParameterName("pCreateInfos[%i].pMultisampleState->rasterizationSamples", ParameterName::IndexVector{i}),
1169 ParameterName("pCreateInfos[%i].pMultisampleState->pSampleMask", ParameterName::IndexVector{i}),
1170 pCreateInfos[i].pMultisampleState->rasterizationSamples, pCreateInfos[i].pMultisampleState->pSampleMask,
1171 true, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1172
1173 skip |= validate_bool32(
1174 report_data, "vkCreateGraphicsPipelines",
1175 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToCoverageEnable", ParameterName::IndexVector{i}),
1176 pCreateInfos[i].pMultisampleState->alphaToCoverageEnable);
1177
1178 skip |= validate_bool32(
1179 report_data, "vkCreateGraphicsPipelines",
1180 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToOneEnable", ParameterName::IndexVector{i}),
1181 pCreateInfos[i].pMultisampleState->alphaToOneEnable);
1182
1183 if (pCreateInfos[i].pMultisampleState->sType != VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO) {
1184 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1185 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1186 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pMultisampleState->sType must be "
1187 "VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO",
1188 i);
1189 }
1190 }
1191
Mark Lobodzinski5cd08512017-09-12 09:50:25 -06001192 // TODO: Conditional NULL check based on subpass depth/stencil attachment
1193 if (pCreateInfos[i].pDepthStencilState != nullptr) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001194 skip |= validate_struct_pnext(
1195 report_data, "vkCreateGraphicsPipelines",
1196 ParameterName("pCreateInfos[%i].pDepthStencilState->pNext", ParameterName::IndexVector{i}), NULL,
1197 pCreateInfos[i].pDepthStencilState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f61c40d);
1198
1199 skip |= validate_reserved_flags(
1200 report_data, "vkCreateGraphicsPipelines",
1201 ParameterName("pCreateInfos[%i].pDepthStencilState->flags", ParameterName::IndexVector{i}),
1202 pCreateInfos[i].pDepthStencilState->flags, VALIDATION_ERROR_0f609005);
1203
1204 skip |= validate_bool32(
1205 report_data, "vkCreateGraphicsPipelines",
1206 ParameterName("pCreateInfos[%i].pDepthStencilState->depthTestEnable", ParameterName::IndexVector{i}),
1207 pCreateInfos[i].pDepthStencilState->depthTestEnable);
1208
1209 skip |= validate_bool32(
1210 report_data, "vkCreateGraphicsPipelines",
1211 ParameterName("pCreateInfos[%i].pDepthStencilState->depthWriteEnable", ParameterName::IndexVector{i}),
1212 pCreateInfos[i].pDepthStencilState->depthWriteEnable);
1213
1214 skip |= validate_ranged_enum(
1215 report_data, "vkCreateGraphicsPipelines",
1216 ParameterName("pCreateInfos[%i].pDepthStencilState->depthCompareOp", ParameterName::IndexVector{i}),
1217 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->depthCompareOp,
1218 VALIDATION_ERROR_0f604001);
1219
1220 skip |= validate_bool32(
1221 report_data, "vkCreateGraphicsPipelines",
1222 ParameterName("pCreateInfos[%i].pDepthStencilState->depthBoundsTestEnable", ParameterName::IndexVector{i}),
1223 pCreateInfos[i].pDepthStencilState->depthBoundsTestEnable);
1224
1225 skip |= validate_bool32(
1226 report_data, "vkCreateGraphicsPipelines",
1227 ParameterName("pCreateInfos[%i].pDepthStencilState->stencilTestEnable", ParameterName::IndexVector{i}),
1228 pCreateInfos[i].pDepthStencilState->stencilTestEnable);
1229
1230 skip |= validate_ranged_enum(
1231 report_data, "vkCreateGraphicsPipelines",
1232 ParameterName("pCreateInfos[%i].pDepthStencilState->front.failOp", ParameterName::IndexVector{i}),
1233 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.failOp,
1234 VALIDATION_ERROR_13a08601);
1235
1236 skip |= validate_ranged_enum(
1237 report_data, "vkCreateGraphicsPipelines",
1238 ParameterName("pCreateInfos[%i].pDepthStencilState->front.passOp", ParameterName::IndexVector{i}),
1239 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.passOp,
1240 VALIDATION_ERROR_13a27801);
1241
1242 skip |= validate_ranged_enum(
1243 report_data, "vkCreateGraphicsPipelines",
1244 ParameterName("pCreateInfos[%i].pDepthStencilState->front.depthFailOp", ParameterName::IndexVector{i}),
1245 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.depthFailOp,
1246 VALIDATION_ERROR_13a04201);
1247
1248 skip |= validate_ranged_enum(
1249 report_data, "vkCreateGraphicsPipelines",
1250 ParameterName("pCreateInfos[%i].pDepthStencilState->front.compareOp", ParameterName::IndexVector{i}),
1251 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->front.compareOp,
1252 VALIDATION_ERROR_0f604001);
1253
1254 skip |= validate_ranged_enum(
1255 report_data, "vkCreateGraphicsPipelines",
1256 ParameterName("pCreateInfos[%i].pDepthStencilState->back.failOp", ParameterName::IndexVector{i}),
1257 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.failOp,
1258 VALIDATION_ERROR_13a08601);
1259
1260 skip |= validate_ranged_enum(
1261 report_data, "vkCreateGraphicsPipelines",
1262 ParameterName("pCreateInfos[%i].pDepthStencilState->back.passOp", ParameterName::IndexVector{i}),
1263 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.passOp,
1264 VALIDATION_ERROR_13a27801);
1265
1266 skip |= validate_ranged_enum(
1267 report_data, "vkCreateGraphicsPipelines",
1268 ParameterName("pCreateInfos[%i].pDepthStencilState->back.depthFailOp", ParameterName::IndexVector{i}),
1269 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.depthFailOp,
1270 VALIDATION_ERROR_13a04201);
1271
1272 skip |= validate_ranged_enum(
1273 report_data, "vkCreateGraphicsPipelines",
1274 ParameterName("pCreateInfos[%i].pDepthStencilState->back.compareOp", ParameterName::IndexVector{i}),
1275 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->back.compareOp,
1276 VALIDATION_ERROR_0f604001);
1277
1278 if (pCreateInfos[i].pDepthStencilState->sType != VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO) {
1279 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1280 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1281 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pDepthStencilState->sType must be "
1282 "VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO",
1283 i);
1284 }
1285 }
1286
Mark Lobodzinski5cd08512017-09-12 09:50:25 -06001287 // TODO: Conditional NULL check based on subpass color attachment
1288 if (pCreateInfos[i].pColorBlendState != nullptr) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001289 skip |= validate_struct_pnext(
1290 report_data, "vkCreateGraphicsPipelines",
1291 ParameterName("pCreateInfos[%i].pColorBlendState->pNext", ParameterName::IndexVector{i}), NULL,
1292 pCreateInfos[i].pColorBlendState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f41c40d);
1293
1294 skip |= validate_reserved_flags(
1295 report_data, "vkCreateGraphicsPipelines",
1296 ParameterName("pCreateInfos[%i].pColorBlendState->flags", ParameterName::IndexVector{i}),
1297 pCreateInfos[i].pColorBlendState->flags, VALIDATION_ERROR_0f409005);
1298
1299 skip |= validate_bool32(
1300 report_data, "vkCreateGraphicsPipelines",
1301 ParameterName("pCreateInfos[%i].pColorBlendState->logicOpEnable", ParameterName::IndexVector{i}),
1302 pCreateInfos[i].pColorBlendState->logicOpEnable);
1303
1304 skip |= validate_array(
1305 report_data, "vkCreateGraphicsPipelines",
1306 ParameterName("pCreateInfos[%i].pColorBlendState->attachmentCount", ParameterName::IndexVector{i}),
1307 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments", ParameterName::IndexVector{i}),
1308 pCreateInfos[i].pColorBlendState->attachmentCount, pCreateInfos[i].pColorBlendState->pAttachments, false,
1309 true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1310
1311 if (pCreateInfos[i].pColorBlendState->pAttachments != NULL) {
1312 for (uint32_t attachmentIndex = 0; attachmentIndex < pCreateInfos[i].pColorBlendState->attachmentCount;
1313 ++attachmentIndex) {
1314 skip |= validate_bool32(report_data, "vkCreateGraphicsPipelines",
1315 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].blendEnable",
1316 ParameterName::IndexVector{i, attachmentIndex}),
1317 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].blendEnable);
1318
1319 skip |= validate_ranged_enum(
1320 report_data, "vkCreateGraphicsPipelines",
1321 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcColorBlendFactor",
1322 ParameterName::IndexVector{i, attachmentIndex}),
1323 "VkBlendFactor", AllVkBlendFactorEnums,
1324 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcColorBlendFactor,
1325 VALIDATION_ERROR_0f22cc01);
1326
1327 skip |= validate_ranged_enum(
1328 report_data, "vkCreateGraphicsPipelines",
1329 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstColorBlendFactor",
1330 ParameterName::IndexVector{i, attachmentIndex}),
1331 "VkBlendFactor", AllVkBlendFactorEnums,
1332 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstColorBlendFactor,
1333 VALIDATION_ERROR_0f207001);
1334
1335 skip |= validate_ranged_enum(
1336 report_data, "vkCreateGraphicsPipelines",
1337 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorBlendOp",
1338 ParameterName::IndexVector{i, attachmentIndex}),
1339 "VkBlendOp", AllVkBlendOpEnums,
1340 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorBlendOp,
1341 VALIDATION_ERROR_0f202001);
1342
1343 skip |= validate_ranged_enum(
1344 report_data, "vkCreateGraphicsPipelines",
1345 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcAlphaBlendFactor",
1346 ParameterName::IndexVector{i, attachmentIndex}),
1347 "VkBlendFactor", AllVkBlendFactorEnums,
1348 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcAlphaBlendFactor,
1349 VALIDATION_ERROR_0f22c601);
1350
1351 skip |= validate_ranged_enum(
1352 report_data, "vkCreateGraphicsPipelines",
1353 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstAlphaBlendFactor",
1354 ParameterName::IndexVector{i, attachmentIndex}),
1355 "VkBlendFactor", AllVkBlendFactorEnums,
1356 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstAlphaBlendFactor,
1357 VALIDATION_ERROR_0f206a01);
1358
1359 skip |= validate_ranged_enum(
1360 report_data, "vkCreateGraphicsPipelines",
1361 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].alphaBlendOp",
1362 ParameterName::IndexVector{i, attachmentIndex}),
1363 "VkBlendOp", AllVkBlendOpEnums,
1364 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].alphaBlendOp,
1365 VALIDATION_ERROR_0f200801);
1366
1367 skip |=
1368 validate_flags(report_data, "vkCreateGraphicsPipelines",
1369 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorWriteMask",
1370 ParameterName::IndexVector{i, attachmentIndex}),
1371 "VkColorComponentFlagBits", AllVkColorComponentFlagBits,
1372 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorWriteMask,
1373 false, false, VALIDATION_ERROR_0f202201);
1374 }
1375 }
1376
1377 if (pCreateInfos[i].pColorBlendState->sType != VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO) {
1378 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1379 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1380 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pColorBlendState->sType must be "
1381 "VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO",
1382 i);
1383 }
1384
1385 // If logicOpEnable is VK_TRUE, logicOp must be a valid VkLogicOp value
1386 if (pCreateInfos[i].pColorBlendState->logicOpEnable == VK_TRUE) {
1387 skip |= validate_ranged_enum(
1388 report_data, "vkCreateGraphicsPipelines",
1389 ParameterName("pCreateInfos[%i].pColorBlendState->logicOp", ParameterName::IndexVector{i}), "VkLogicOp",
1390 AllVkLogicOpEnums, pCreateInfos[i].pColorBlendState->logicOp, VALIDATION_ERROR_0f4004be);
1391 }
1392 }
1393 }
1394 }
1395
1396 if (pCreateInfos != nullptr) {
1397 if (pCreateInfos->flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT) {
1398 if (pCreateInfos->basePipelineIndex != -1) {
1399 if (pCreateInfos->basePipelineHandle != VK_NULL_HANDLE) {
1400 skip |= log_msg(
1401 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1402 VALIDATION_ERROR_096005a8, LayerName,
1403 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineHandle, must be VK_NULL_HANDLE if "
1404 "pCreateInfos->flags "
1405 "contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag and pCreateInfos->basePipelineIndex is not -1. %s",
1406 validation_error_map[VALIDATION_ERROR_096005a8]);
1407 }
1408 }
1409
1410 if (pCreateInfos->basePipelineHandle != VK_NULL_HANDLE) {
1411 if (pCreateInfos->basePipelineIndex != -1) {
1412 skip |= log_msg(
1413 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1414 VALIDATION_ERROR_096005aa, LayerName,
1415 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineIndex, must be -1 if "
1416 "pCreateInfos->flags "
1417 "contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag and pCreateInfos->basePipelineHandle is not "
1418 "VK_NULL_HANDLE. %s",
1419 validation_error_map[VALIDATION_ERROR_096005aa]);
1420 }
1421 }
1422 }
1423
1424 if (pCreateInfos->pRasterizationState != nullptr) {
1425 if (pCreateInfos->pRasterizationState->cullMode & ~VK_CULL_MODE_FRONT_AND_BACK) {
1426 skip |= log_msg(
1427 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1428 UNRECOGNIZED_VALUE, LayerName,
1429 "vkCreateGraphicsPipelines parameter, VkCullMode pCreateInfos->pRasterizationState->cullMode, is an "
1430 "unrecognized enumerator");
1431 }
1432
1433 if ((pCreateInfos->pRasterizationState->polygonMode != VK_POLYGON_MODE_FILL) &&
1434 (device_data->physical_device_features.fillModeNonSolid == false)) {
1435 skip |= log_msg(
1436 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1437 DEVICE_FEATURE, LayerName,
1438 "vkCreateGraphicsPipelines parameter, VkPolygonMode pCreateInfos->pRasterizationState->polygonMode cannot "
1439 "be "
1440 "VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE if VkPhysicalDeviceFeatures->fillModeNonSolid is false.");
1441 }
1442 }
1443
1444 size_t i = 0;
1445 for (size_t j = 0; j < pCreateInfos[i].stageCount; j++) {
1446 skip |= validate_string(device_data->report_data, "vkCreateGraphicsPipelines",
1447 ParameterName("pCreateInfos[%i].pStages[%i].pName", ParameterName::IndexVector{i, j}),
1448 pCreateInfos[i].pStages[j].pName);
1449 }
1450 }
1451 }
1452
1453 return skip;
1454}
1455
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001456bool pv_vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1457 const VkComputePipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1458 VkPipeline *pPipelines) {
1459 bool skip = false;
1460 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1461
1462 for (uint32_t i = 0; i < createInfoCount; i++) {
1463 skip |= validate_string(device_data->report_data, "vkCreateComputePipelines",
1464 ParameterName("pCreateInfos[%i].stage.pName", ParameterName::IndexVector{i}),
1465 pCreateInfos[i].stage.pName);
1466 }
1467
1468 return skip;
1469}
1470
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001471bool pv_vkCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1472 VkSampler *pSampler) {
1473 bool skip = false;
1474 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1475 debug_report_data *report_data = device_data->report_data;
1476
1477 if (pCreateInfo != nullptr) {
1478 if ((device_data->physical_device_features.samplerAnisotropy == false) && (pCreateInfo->maxAnisotropy != 1.0)) {
1479 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1480 DEVICE_FEATURE, LayerName,
1481 "vkCreateSampler(): The samplerAnisotropy feature was not enabled at device-creation time, so the "
1482 "maxAnisotropy member of the VkSamplerCreateInfo structure must be 1.0 but is %f.",
1483 pCreateInfo->maxAnisotropy);
1484 }
1485
1486 // If compareEnable is VK_TRUE, compareOp must be a valid VkCompareOp value
1487 if (pCreateInfo->compareEnable == VK_TRUE) {
1488 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->compareOp", "VkCompareOp",
1489 AllVkCompareOpEnums, pCreateInfo->compareOp, VALIDATION_ERROR_12600870);
1490 }
1491
1492 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, borderColor must be a
1493 // valid VkBorderColor value
1494 if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
1495 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
1496 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)) {
1497 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->borderColor", "VkBorderColor",
1498 AllVkBorderColorEnums, pCreateInfo->borderColor, VALIDATION_ERROR_1260086c);
1499 }
1500
1501 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, the
1502 // VK_KHR_sampler_mirror_clamp_to_edge extension must be enabled
1503 if (!device_data->extensions.vk_khr_sampler_mirror_clamp_to_edge &&
1504 ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
1505 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
1506 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE))) {
1507 skip |=
1508 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1509 VALIDATION_ERROR_1260086e, LayerName,
1510 "vkCreateSampler(): A VkSamplerAddressMode value is set to VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE "
1511 "but the VK_KHR_sampler_mirror_clamp_to_edge extension has not been enabled. %s",
1512 validation_error_map[VALIDATION_ERROR_1260086e]);
1513 }
1514 }
1515
1516 return skip;
1517}
1518
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001519bool pv_vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
1520 const VkAllocationCallbacks *pAllocator, VkDescriptorSetLayout *pSetLayout) {
1521 bool skip = false;
1522 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1523 debug_report_data *report_data = device_data->report_data;
1524
1525 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1526 if ((pCreateInfo != nullptr) && (pCreateInfo->pBindings != nullptr)) {
1527 for (uint32_t i = 0; i < pCreateInfo->bindingCount; ++i) {
1528 if (pCreateInfo->pBindings[i].descriptorCount != 0) {
1529 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER or VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and descriptorCount
1530 // is not 0 and pImmutableSamplers is not NULL, pImmutableSamplers must be a pointer to an array of descriptorCount
1531 // valid VkSampler handles
1532 if (((pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
1533 (pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)) &&
1534 (pCreateInfo->pBindings[i].pImmutableSamplers != nullptr)) {
1535 for (uint32_t descriptor_index = 0; descriptor_index < pCreateInfo->pBindings[i].descriptorCount;
1536 ++descriptor_index) {
1537 if (pCreateInfo->pBindings[i].pImmutableSamplers[descriptor_index] == VK_NULL_HANDLE) {
1538 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1539 __LINE__, REQUIRED_PARAMETER, LayerName,
1540 "vkCreateDescriptorSetLayout: required parameter "
1541 "pCreateInfo->pBindings[%d].pImmutableSamplers[%d]"
1542 " specified as VK_NULL_HANDLE",
1543 i, descriptor_index);
1544 }
1545 }
1546 }
1547
1548 // If descriptorCount is not 0, stageFlags must be a valid combination of VkShaderStageFlagBits values
1549 if ((pCreateInfo->pBindings[i].stageFlags != 0) &&
1550 ((pCreateInfo->pBindings[i].stageFlags & (~AllVkShaderStageFlagBits)) != 0)) {
1551 skip |= log_msg(
1552 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1553 VALIDATION_ERROR_04e00236, LayerName,
1554 "vkCreateDescriptorSetLayout(): if pCreateInfo->pBindings[%d].descriptorCount is not 0, "
1555 "pCreateInfo->pBindings[%d].stageFlags must be a valid combination of VkShaderStageFlagBits values. %s",
1556 i, i, validation_error_map[VALIDATION_ERROR_04e00236]);
1557 }
1558 }
1559 }
1560 }
1561
1562 return skip;
1563}
1564
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001565bool pv_vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
1566 const VkDescriptorSet *pDescriptorSets) {
1567 bool skip = false;
1568 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1569 debug_report_data *report_data = device_data->report_data;
1570
1571 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1572 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
1573 // validate_array()
1574 skip |= validate_array(report_data, "vkFreeDescriptorSets", "descriptorSetCount", "pDescriptorSets", descriptorSetCount,
1575 pDescriptorSets, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1576 return skip;
1577}
1578
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001579bool pv_vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites,
1580 uint32_t descriptorCopyCount, const VkCopyDescriptorSet *pDescriptorCopies) {
1581 bool skip = false;
1582 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1583 debug_report_data *report_data = device_data->report_data;
1584
1585 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1586 if (pDescriptorWrites != NULL) {
1587 for (uint32_t i = 0; i < descriptorWriteCount; ++i) {
1588 // descriptorCount must be greater than 0
1589 if (pDescriptorWrites[i].descriptorCount == 0) {
1590 skip |=
1591 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1592 VALIDATION_ERROR_15c0441b, LayerName,
1593 "vkUpdateDescriptorSets(): parameter pDescriptorWrites[%d].descriptorCount must be greater than 0. %s",
1594 i, validation_error_map[VALIDATION_ERROR_15c0441b]);
1595 }
1596
1597 // dstSet must be a valid VkDescriptorSet handle
1598 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1599 ParameterName("pDescriptorWrites[%i].dstSet", ParameterName::IndexVector{i}),
1600 pDescriptorWrites[i].dstSet);
1601
1602 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
1603 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||
1604 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||
1605 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ||
1606 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) {
1607 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
1608 // VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
1609 // pImageInfo must be a pointer to an array of descriptorCount valid VkDescriptorImageInfo structures
1610 if (pDescriptorWrites[i].pImageInfo == nullptr) {
1611 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1612 __LINE__, VALIDATION_ERROR_15c00284, LayerName,
1613 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
1614 "VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, "
1615 "VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or "
1616 "VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, pDescriptorWrites[%d].pImageInfo must not be NULL. %s",
1617 i, i, validation_error_map[VALIDATION_ERROR_15c00284]);
1618 } else if (pDescriptorWrites[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) {
1619 // If descriptorType is VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
1620 // VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, the imageView and imageLayout
1621 // members of any given element of pImageInfo must be a valid VkImageView and VkImageLayout, respectively
1622 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
1623 ++descriptor_index) {
1624 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1625 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageView",
1626 ParameterName::IndexVector{i, descriptor_index}),
1627 pDescriptorWrites[i].pImageInfo[descriptor_index].imageView);
1628 skip |= validate_ranged_enum(report_data, "vkUpdateDescriptorSets",
1629 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageLayout",
1630 ParameterName::IndexVector{i, descriptor_index}),
1631 "VkImageLayout", AllVkImageLayoutEnums,
1632 pDescriptorWrites[i].pImageInfo[descriptor_index].imageLayout,
1633 VALIDATION_ERROR_UNDEFINED);
1634 }
1635 }
1636 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
1637 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
1638 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1639 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1640 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1641 // VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pBufferInfo must be a
1642 // pointer to an array of descriptorCount valid VkDescriptorBufferInfo structures
1643 if (pDescriptorWrites[i].pBufferInfo == nullptr) {
1644 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1645 __LINE__, VALIDATION_ERROR_15c00288, LayerName,
1646 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
1647 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, "
1648 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, "
1649 "pDescriptorWrites[%d].pBufferInfo must not be NULL. %s",
1650 i, i, validation_error_map[VALIDATION_ERROR_15c00288]);
1651 } else {
1652 for (uint32_t descriptorIndex = 0; descriptorIndex < pDescriptorWrites[i].descriptorCount; ++descriptorIndex) {
1653 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1654 ParameterName("pDescriptorWrites[%i].pBufferInfo[%i].buffer",
1655 ParameterName::IndexVector{i, descriptorIndex}),
1656 pDescriptorWrites[i].pBufferInfo[descriptorIndex].buffer);
1657 }
1658 }
1659 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||
1660 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) {
1661 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
1662 // pTexelBufferView must be a pointer to an array of descriptorCount valid VkBufferView handles
1663 if (pDescriptorWrites[i].pTexelBufferView == nullptr) {
1664 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1665 __LINE__, VALIDATION_ERROR_15c00286, LayerName,
1666 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
1667 "VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, "
1668 "pDescriptorWrites[%d].pTexelBufferView must not be NULL. %s",
1669 i, i, validation_error_map[VALIDATION_ERROR_15c00286]);
1670 } else {
1671 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
1672 ++descriptor_index) {
1673 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1674 ParameterName("pDescriptorWrites[%i].pTexelBufferView[%i]",
1675 ParameterName::IndexVector{i, descriptor_index}),
1676 pDescriptorWrites[i].pTexelBufferView[descriptor_index]);
1677 }
1678 }
1679 }
1680
1681 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
1682 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)) {
1683 VkDeviceSize uniformAlignment = device_data->device_limits.minUniformBufferOffsetAlignment;
1684 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
1685 if (pDescriptorWrites[i].pBufferInfo != NULL) {
1686 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) {
1687 skip |= log_msg(
1688 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1689 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c0028e, LayerName,
1690 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
1691 ") must be a multiple of device limit minUniformBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
1692 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment,
1693 validation_error_map[VALIDATION_ERROR_15c0028e]);
1694 }
1695 }
1696 }
1697 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
1698 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1699 VkDeviceSize storageAlignment = device_data->device_limits.minStorageBufferOffsetAlignment;
1700 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
1701 if (pDescriptorWrites[i].pBufferInfo != NULL) {
1702 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) {
1703 skip |= log_msg(
1704 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1705 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c00290, LayerName,
1706 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
1707 ") must be a multiple of device limit minStorageBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
1708 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment,
1709 validation_error_map[VALIDATION_ERROR_15c00290]);
1710 }
1711 }
1712 }
1713 }
1714 }
1715 }
1716 return skip;
1717}
1718
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001719bool pv_vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1720 VkRenderPass *pRenderPass) {
1721 bool skip = false;
1722 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1723 uint32_t max_color_attachments = device_data->device_limits.maxColorAttachments;
1724
1725 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
1726 if (pCreateInfo->pAttachments[i].format == VK_FORMAT_UNDEFINED) {
1727 std::stringstream ss;
1728 ss << "vkCreateRenderPass: pCreateInfo->pAttachments[" << i << "].format is VK_FORMAT_UNDEFINED. "
1729 << validation_error_map[VALIDATION_ERROR_00809201];
1730 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1731 __LINE__, VALIDATION_ERROR_00809201, "IMAGE", "%s", ss.str().c_str());
1732 }
1733 if (pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_UNDEFINED ||
1734 pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_PREINITIALIZED) {
1735 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1736 __LINE__, VALIDATION_ERROR_00800696, "DL",
1737 "pCreateInfo->pAttachments[%d].finalLayout must not be VK_IMAGE_LAYOUT_UNDEFINED or "
1738 "VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
1739 i, validation_error_map[VALIDATION_ERROR_00800696]);
1740 }
1741 }
1742
1743 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
1744 if (pCreateInfo->pSubpasses[i].colorAttachmentCount > max_color_attachments) {
1745 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1746 __LINE__, VALIDATION_ERROR_1400069a, "DL",
1747 "Cannot create a render pass with %d color attachments. Max is %d. %s",
1748 pCreateInfo->pSubpasses[i].colorAttachmentCount, max_color_attachments,
1749 validation_error_map[VALIDATION_ERROR_1400069a]);
1750 }
1751 }
1752 return skip;
1753}
1754
1755bool pv_vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
1756 const VkCommandBuffer *pCommandBuffers) {
1757 bool skip = false;
1758 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1759 debug_report_data *report_data = device_data->report_data;
1760
1761 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1762 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
1763 // validate_array()
1764 skip |= validate_array(report_data, "vkFreeCommandBuffers", "commandBufferCount", "pCommandBuffers", commandBufferCount,
1765 pCommandBuffers, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1766 return skip;
1767}
1768
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001769bool pv_vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo) {
1770 bool skip = false;
1771 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
1772 debug_report_data *report_data = device_data->report_data;
1773 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
1774
1775 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1776 // TODO: pBeginInfo->pInheritanceInfo must not be NULL if commandBuffer is a secondary command buffer
1777 skip |= validate_struct_type(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo",
1778 "VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO", pBeginInfo->pInheritanceInfo,
1779 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, false, VALIDATION_ERROR_UNDEFINED);
1780
1781 if (pBeginInfo->pInheritanceInfo != NULL) {
1782 skip |=
1783 validate_struct_pnext(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pNext", NULL,
1784 pBeginInfo->pInheritanceInfo->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0281c40d);
1785
1786 skip |= validate_bool32(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->occlusionQueryEnable",
1787 pBeginInfo->pInheritanceInfo->occlusionQueryEnable);
1788
1789 // TODO: This only needs to be validated when the inherited queries feature is enabled
1790 // skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
1791 // "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pBeginInfo->pInheritanceInfo->queryFlags, false);
1792
1793 // TODO: This must be 0 if the pipeline statistics queries feature is not enabled
1794 skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pipelineStatistics",
1795 "VkQueryPipelineStatisticFlagBits", AllVkQueryPipelineStatisticFlagBits,
1796 pBeginInfo->pInheritanceInfo->pipelineStatistics, false, false, VALIDATION_ERROR_UNDEFINED);
1797 }
1798
1799 if (pInfo != NULL) {
1800 if ((device_data->physical_device_features.inheritedQueries == VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
1801 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1802 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_02a00070, LayerName,
1803 "Cannot set inherited occlusionQueryEnable in vkBeginCommandBuffer() when device does not support "
1804 "inheritedQueries. %s",
1805 validation_error_map[VALIDATION_ERROR_02a00070]);
1806 }
1807 if ((device_data->physical_device_features.inheritedQueries != VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
1808 skip |= validate_flags(device_data->report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
1809 "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pInfo->queryFlags, false, false,
1810 VALIDATION_ERROR_02a00072);
1811 }
1812 }
1813
1814 return skip;
1815}
1816
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001817bool pv_vkCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount,
1818 const VkViewport *pViewports) {
1819 bool skip = false;
1820 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
1821
1822 skip |= validate_array(device_data->report_data, "vkCmdSetViewport", "viewportCount", "pViewports", viewportCount, pViewports,
1823 true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1824
1825 if (viewportCount > 0 && pViewports != nullptr) {
1826 const VkPhysicalDeviceLimits &limits = device_data->device_limits;
1827 for (uint32_t viewportIndex = 0; viewportIndex < viewportCount; ++viewportIndex) {
1828 const VkViewport &viewport = pViewports[viewportIndex];
1829
1830 if (device_data->physical_device_features.multiViewport == false) {
1831 if (viewportCount != 1) {
1832 skip |= log_msg(
1833 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1834 __LINE__, DEVICE_FEATURE, LayerName,
1835 "vkCmdSetViewport(): The multiViewport feature is not enabled, so viewportCount must be 1 but is %d.",
1836 viewportCount);
1837 }
1838 if (firstViewport != 0) {
1839 skip |= log_msg(
1840 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1841 __LINE__, DEVICE_FEATURE, LayerName,
1842 "vkCmdSetViewport(): The multiViewport feature is not enabled, so firstViewport must be 0 but is %d.",
1843 firstViewport);
1844 }
1845 }
1846
1847 if (viewport.width <= 0 || viewport.width > limits.maxViewportDimensions[0]) {
1848 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1849 __LINE__, VALIDATION_ERROR_15000996, LayerName,
1850 "vkCmdSetViewport %d: width (%f) exceeds permitted bounds (0,%u). %s", viewportIndex,
1851 viewport.width, limits.maxViewportDimensions[0], validation_error_map[VALIDATION_ERROR_15000996]);
1852 }
1853
1854 if (device_data->extensions.vk_amd_negative_viewport_height || device_data->extensions.vk_khr_maintenance1) {
1855 // Check lower bound against negative viewport height instead of zero
1856 if (viewport.height <= -(static_cast<int32_t>(limits.maxViewportDimensions[1])) ||
1857 (viewport.height > limits.maxViewportDimensions[1])) {
1858 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1859 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, VALIDATION_ERROR_1500099a, LayerName,
1860 "vkCmdSetViewport %d: height (%f) exceeds permitted bounds (-%u,%u). %s", viewportIndex,
1861 viewport.height, limits.maxViewportDimensions[1], limits.maxViewportDimensions[1],
1862 validation_error_map[VALIDATION_ERROR_1500099a]);
1863 }
1864 } else {
1865 if ((viewport.height <= 0) || (viewport.height > limits.maxViewportDimensions[1])) {
1866 skip |=
1867 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1868 __LINE__, VALIDATION_ERROR_15000998, LayerName,
1869 "vkCmdSetViewport %d: height (%f) exceeds permitted bounds (0,%u). %s", viewportIndex,
1870 viewport.height, limits.maxViewportDimensions[1], validation_error_map[VALIDATION_ERROR_15000998]);
1871 }
1872 }
1873
1874 if (viewport.x < limits.viewportBoundsRange[0] || viewport.x > limits.viewportBoundsRange[1]) {
1875 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1876 __LINE__, VALIDATION_ERROR_1500099e, LayerName,
1877 "vkCmdSetViewport %d: x (%f) exceeds permitted bounds (%f,%f). %s", viewportIndex, viewport.x,
1878 limits.viewportBoundsRange[0], limits.viewportBoundsRange[1],
1879 validation_error_map[VALIDATION_ERROR_1500099e]);
1880 }
1881
1882 if (viewport.y < limits.viewportBoundsRange[0] || viewport.y > limits.viewportBoundsRange[1]) {
1883 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1884 __LINE__, VALIDATION_ERROR_1500099e, LayerName,
1885 "vkCmdSetViewport %d: y (%f) exceeds permitted bounds (%f,%f). %s", viewportIndex, viewport.y,
1886 limits.viewportBoundsRange[0], limits.viewportBoundsRange[1],
1887 validation_error_map[VALIDATION_ERROR_1500099e]);
1888 }
1889
1890 if (viewport.x + viewport.width > limits.viewportBoundsRange[1]) {
1891 skip |=
1892 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1893 __LINE__, VALIDATION_ERROR_150009a0, LayerName,
1894 "vkCmdSetViewport %d: x (%f) + width (%f) exceeds permitted bound (%f). %s", viewportIndex, viewport.x,
1895 viewport.width, limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a0]);
1896 }
1897
1898 if (viewport.y + viewport.height > limits.viewportBoundsRange[1]) {
1899 skip |=
1900 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1901 __LINE__, VALIDATION_ERROR_150009a2, LayerName,
1902 "vkCmdSetViewport %d: y (%f) + height (%f) exceeds permitted bound (%f). %s", viewportIndex, viewport.y,
1903 viewport.height, limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a2]);
1904 }
1905 }
1906 }
1907 return skip;
1908}
1909
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001910bool pv_vkCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *pScissors) {
1911 bool skip = false;
1912 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
1913 debug_report_data *report_data = device_data->report_data;
1914
1915 if (device_data->physical_device_features.multiViewport == false) {
1916 if (scissorCount != 1) {
1917 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1918 DEVICE_FEATURE, LayerName,
1919 "vkCmdSetScissor(): The multiViewport feature is not enabled, so scissorCount must be 1 but is %d.",
1920 scissorCount);
1921 }
1922 if (firstScissor != 0) {
1923 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1924 DEVICE_FEATURE, LayerName,
1925 "vkCmdSetScissor(): The multiViewport feature is not enabled, so firstScissor must be 0 but is %d.",
1926 firstScissor);
1927 }
1928 }
1929
1930 for (uint32_t scissorIndex = 0; scissorIndex < scissorCount; ++scissorIndex) {
1931 const VkRect2D &pScissor = pScissors[scissorIndex];
1932
1933 if (pScissor.offset.x < 0) {
1934 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1935 VALIDATION_ERROR_1d8004a6, LayerName, "vkCmdSetScissor %d: offset.x (%d) must not be negative. %s",
1936 scissorIndex, pScissor.offset.x, validation_error_map[VALIDATION_ERROR_1d8004a6]);
1937 } else if (static_cast<int32_t>(pScissor.extent.width) > (INT_MAX - pScissor.offset.x)) {
1938 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1939 VALIDATION_ERROR_1d8004a8, LayerName,
1940 "vkCmdSetScissor %d: adding offset.x (%d) and extent.width (%u) will overflow. %s", scissorIndex,
1941 pScissor.offset.x, pScissor.extent.width, validation_error_map[VALIDATION_ERROR_1d8004a8]);
1942 }
1943
1944 if (pScissor.offset.y < 0) {
1945 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1946 VALIDATION_ERROR_1d8004a6, LayerName, "vkCmdSetScissor %d: offset.y (%d) must not be negative. %s",
1947 scissorIndex, pScissor.offset.y, validation_error_map[VALIDATION_ERROR_1d8004a6]);
1948 } else if (static_cast<int32_t>(pScissor.extent.height) > (INT_MAX - pScissor.offset.y)) {
1949 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1950 VALIDATION_ERROR_1d8004aa, LayerName,
1951 "vkCmdSetScissor %d: adding offset.y (%d) and extent.height (%u) will overflow. %s", scissorIndex,
1952 pScissor.offset.y, pScissor.extent.height, validation_error_map[VALIDATION_ERROR_1d8004aa]);
1953 }
1954 }
1955 return skip;
1956}
1957
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001958bool pv_vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex,
1959 uint32_t firstInstance) {
1960 bool skip = false;
1961 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
1962 if (vertexCount == 0) {
1963 // TODO: Verify against Valid Usage section. I don't see a non-zero vertexCount listed, may need to add that and make
1964 // this an error or leave as is.
1965 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1966 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t vertexCount, is 0");
1967 }
1968
1969 if (instanceCount == 0) {
1970 // TODO: Verify against Valid Usage section. I don't see a non-zero instanceCount listed, may need to add that and make
1971 // this an error or leave as is.
1972 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1973 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t instanceCount, is 0");
1974 }
1975 return skip;
1976}
1977
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001978bool pv_vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride) {
1979 bool skip = false;
1980 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
1981
1982 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
1983 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1984 __LINE__, DEVICE_FEATURE, LayerName,
1985 "CmdDrawIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
1986 }
1987 return skip;
1988}
1989
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001990bool pv_vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count,
1991 uint32_t stride) {
1992 bool skip = false;
1993 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
1994 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
1995 skip |=
1996 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1997 DEVICE_FEATURE, LayerName,
1998 "CmdDrawIndexedIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
1999 }
2000 return skip;
2001}
2002
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002003bool pv_vkCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2004 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy *pRegions) {
2005 bool skip = false;
2006 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2007
2008 if (pRegions != nullptr) {
2009 if ((pRegions->srcSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2010 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2011 skip |= log_msg(
2012 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2013 VALIDATION_ERROR_0a600c01, LayerName,
2014 "vkCmdCopyImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator. %s",
2015 validation_error_map[VALIDATION_ERROR_0a600c01]);
2016 }
2017 if ((pRegions->dstSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2018 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2019 skip |= log_msg(
2020 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2021 VALIDATION_ERROR_0a600c01, LayerName,
2022 "vkCmdCopyImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator. %s",
2023 validation_error_map[VALIDATION_ERROR_0a600c01]);
2024 }
2025 }
2026 return skip;
2027}
2028
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002029bool pv_vkCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2030 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
2031 bool skip = false;
2032 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2033
2034 if (pRegions != nullptr) {
2035 if ((pRegions->srcSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2036 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2037 skip |= log_msg(
2038 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2039 UNRECOGNIZED_VALUE, LayerName,
2040 "vkCmdBlitImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator");
2041 }
2042 if ((pRegions->dstSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2043 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2044 skip |= log_msg(
2045 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2046 UNRECOGNIZED_VALUE, LayerName,
2047 "vkCmdBlitImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator");
2048 }
2049 }
2050 return skip;
2051}
2052
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002053bool pv_vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout,
2054 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2055 bool skip = false;
2056 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2057
2058 if (pRegions != nullptr) {
2059 if ((pRegions->imageSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2060 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2061 skip |= log_msg(
2062 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2063 UNRECOGNIZED_VALUE, LayerName,
2064 "vkCmdCopyBufferToImage() parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an unrecognized "
2065 "enumerator");
2066 }
2067 }
2068 return skip;
2069}
2070
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002071bool pv_vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer,
2072 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2073 bool skip = false;
2074 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2075
2076 if (pRegions != nullptr) {
2077 if ((pRegions->imageSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2078 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2079 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2080 UNRECOGNIZED_VALUE, LayerName,
2081 "vkCmdCopyImageToBuffer parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an unrecognized "
2082 "enumerator");
2083 }
2084 }
2085 return skip;
2086}
2087
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002088bool pv_vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize,
2089 const void *pData) {
2090 bool skip = false;
2091 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2092
2093 if (dstOffset & 3) {
2094 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2095 __LINE__, VALIDATION_ERROR_1e400048, LayerName,
2096 "vkCmdUpdateBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2097 dstOffset, validation_error_map[VALIDATION_ERROR_1e400048]);
2098 }
2099
2100 if ((dataSize <= 0) || (dataSize > 65536)) {
2101 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2102 __LINE__, VALIDATION_ERROR_1e40004a, LayerName,
2103 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64
2104 "), must be greater than zero and less than or equal to 65536. %s",
2105 dataSize, validation_error_map[VALIDATION_ERROR_1e40004a]);
2106 } else if (dataSize & 3) {
2107 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2108 __LINE__, VALIDATION_ERROR_1e40004c, LayerName,
2109 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2110 dataSize, validation_error_map[VALIDATION_ERROR_1e40004c]);
2111 }
2112 return skip;
2113}
2114
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002115bool pv_vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size,
2116 uint32_t data) {
2117 bool skip = false;
2118 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2119
2120 if (dstOffset & 3) {
2121 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2122 __LINE__, VALIDATION_ERROR_1b400032, LayerName,
2123 "vkCmdFillBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2124 dstOffset, validation_error_map[VALIDATION_ERROR_1b400032]);
2125 }
2126
2127 if (size != VK_WHOLE_SIZE) {
2128 if (size <= 0) {
2129 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2130 __LINE__, VALIDATION_ERROR_1b400034, LayerName,
2131 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), must be greater than zero. %s",
2132 size, validation_error_map[VALIDATION_ERROR_1b400034]);
2133 } else if (size & 3) {
2134 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2135 __LINE__, VALIDATION_ERROR_1b400038, LayerName,
2136 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), is not a multiple of 4. %s", size,
2137 validation_error_map[VALIDATION_ERROR_1b400038]);
2138 }
2139 }
2140 return skip;
2141}
2142
2143VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
2144 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2145}
2146
2147VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
2148 VkLayerProperties *pProperties) {
2149 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2150}
2151
2152VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
2153 VkExtensionProperties *pProperties) {
2154 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2155 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
2156
2157 return VK_ERROR_LAYER_NOT_PRESENT;
2158}
2159
2160VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
2161 uint32_t *pPropertyCount, VkExtensionProperties *pProperties) {
2162 // Parameter_validation does not have any physical device extensions
2163 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2164 return util_GetExtensionProperties(0, NULL, pPropertyCount, pProperties);
2165
2166 instance_layer_data *local_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map);
2167 bool skip =
2168 validate_array(local_data->report_data, "vkEnumerateDeviceExtensionProperties", "pPropertyCount", "pProperties",
2169 pPropertyCount, pProperties, true, false, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_2761f401);
2170 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
2171
2172 return local_data->dispatch_table.EnumerateDeviceExtensionProperties(physicalDevice, NULL, pPropertyCount, pProperties);
2173}
2174
2175static bool require_device_extension(layer_data *device_data, bool flag, char const *function_name, char const *extension_name) {
2176 if (!flag) {
2177 return log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2178 __LINE__, EXTENSION_NOT_ENABLED, LayerName,
2179 "%s() called even though the %s extension was not enabled for this VkDevice.", function_name,
2180 extension_name);
2181 }
2182
2183 return false;
2184}
2185
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002186bool pv_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator,
2187 VkSwapchainKHR *pSwapchain) {
2188 bool skip = false;
2189 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2190 debug_report_data *report_data = device_data->report_data;
2191
2192 if (pCreateInfo != nullptr) {
2193 if ((device_data->physical_device_features.textureCompressionETC2 == false) &&
2194 FormatIsCompressed_ETC2_EAC(pCreateInfo->imageFormat)) {
2195 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2196 DEVICE_FEATURE, LayerName,
2197 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2198 "textureCompressionETC2 feature is not enabled: neither ETC2 nor EAC formats can be used to create "
2199 "images.",
2200 string_VkFormat(pCreateInfo->imageFormat));
2201 }
2202
2203 if ((device_data->physical_device_features.textureCompressionASTC_LDR == false) &&
2204 FormatIsCompressed_ASTC_LDR(pCreateInfo->imageFormat)) {
2205 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2206 DEVICE_FEATURE, LayerName,
2207 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2208 "textureCompressionASTC_LDR feature is not enabled: ASTC formats cannot be used to create images.",
2209 string_VkFormat(pCreateInfo->imageFormat));
2210 }
2211
2212 if ((device_data->physical_device_features.textureCompressionBC == false) &&
2213 FormatIsCompressed_BC(pCreateInfo->imageFormat)) {
2214 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2215 DEVICE_FEATURE, LayerName,
2216 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2217 "textureCompressionBC feature is not enabled: BC compressed formats cannot be used to create images.",
2218 string_VkFormat(pCreateInfo->imageFormat));
2219 }
2220
2221 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2222 if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) {
2223 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
2224 if (pCreateInfo->queueFamilyIndexCount <= 1) {
2225 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2226 VALIDATION_ERROR_146009fc, LayerName,
2227 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2228 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
2229 validation_error_map[VALIDATION_ERROR_146009fc]);
2230 }
2231
2232 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
2233 // queueFamilyIndexCount uint32_t values
2234 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
2235 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2236 VALIDATION_ERROR_146009fa, LayerName,
2237 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2238 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
2239 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
2240 validation_error_map[VALIDATION_ERROR_146009fa]);
2241 } else {
2242 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
2243 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
2244 "vkCreateSwapchainKHR", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE,
2245 INVALID_USAGE, false, "", "");
2246 }
2247 }
2248
2249 // imageArrayLayers must be greater than 0
2250 skip |= ValidateGreaterThan(report_data, "vkCreateSwapchainKHR", "pCreateInfo->imageArrayLayers",
2251 pCreateInfo->imageArrayLayers, 0u);
2252 }
2253
2254 return skip;
2255}
2256
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002257bool pv_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
2258 bool skip = false;
2259 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
2260
2261 if (pPresentInfo && pPresentInfo->pNext) {
John Zulaufde972ac2017-10-26 12:07:05 -06002262 const auto *present_regions = lvl_find_in_chain<VkPresentRegionsKHR>(pPresentInfo->pNext);
2263 if (present_regions) {
2264 // TODO: This and all other pNext extension dependencies should be added to code-generation
2265 skip |= require_device_extension(device_data, device_data->extensions.vk_khr_incremental_present, "vkQueuePresentKHR",
2266 VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME);
2267 if (present_regions->swapchainCount != pPresentInfo->swapchainCount) {
2268 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2269 __LINE__, INVALID_USAGE, LayerName,
2270 "QueuePresentKHR(): pPresentInfo->swapchainCount has a value of %i"
2271 " but VkPresentRegionsKHR extension swapchainCount is %i. These values must be equal.",
2272 pPresentInfo->swapchainCount, present_regions->swapchainCount);
2273 }
2274 skip |= validate_struct_pnext(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pNext", NULL,
2275 present_regions->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_1121c40d);
2276 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->swapchainCount",
2277 "pCreateInfo->pNext->pRegions", present_regions->swapchainCount, present_regions->pRegions, true,
2278 false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2279 for (uint32_t i = 0; i < present_regions->swapchainCount; ++i) {
2280 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pRegions[].rectangleCount",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002281 "pCreateInfo->pNext->pRegions[].pRectangles", present_regions->pRegions[i].rectangleCount,
2282 present_regions->pRegions[i].pRectangles, true, false, VALIDATION_ERROR_UNDEFINED,
2283 VALIDATION_ERROR_UNDEFINED);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002284 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002285 }
2286 }
2287
2288 return skip;
2289}
2290
2291#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002292bool pv_vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
2293 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
2294 auto device_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2295 bool skip = false;
2296
2297 if (pCreateInfo->hwnd == nullptr) {
2298 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2299 __LINE__, VALIDATION_ERROR_15a00a38, LayerName,
2300 "vkCreateWin32SurfaceKHR(): hwnd must be a valid Win32 HWND but hwnd is NULL. %s",
2301 validation_error_map[VALIDATION_ERROR_15a00a38]);
2302 }
2303
2304 return skip;
2305}
2306#endif // VK_USE_PLATFORM_WIN32_KHR
2307
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002308bool pv_vkDebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
2309 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2310 if (pNameInfo->pObjectName) {
2311 device_data->report_data->debugObjectNameMap->insert(
2312 std::make_pair<uint64_t, std::string>((uint64_t &&) pNameInfo->object, pNameInfo->pObjectName));
2313 } else {
2314 device_data->report_data->debugObjectNameMap->erase(pNameInfo->object);
2315 }
2316 return false;
2317}
2318
Petr Krausc8655be2017-09-27 18:56:51 +02002319bool pv_vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2320 const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool) {
2321 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2322 bool skip = false;
2323
2324 if (pCreateInfo) {
2325 if (pCreateInfo->maxSets <= 0) {
2326 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2327 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_0480025a,
2328 LayerName, "vkCreateDescriptorPool(): pCreateInfo->maxSets is not greater than 0. %s",
2329 validation_error_map[VALIDATION_ERROR_0480025a]);
2330 }
2331
2332 if (pCreateInfo->pPoolSizes) {
2333 for (uint32_t i = 0; i < pCreateInfo->poolSizeCount; ++i) {
2334 if (pCreateInfo->pPoolSizes[i].descriptorCount <= 0) {
2335 skip |= log_msg(
2336 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT,
2337 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_04a0025c, LayerName,
2338 "vkCreateDescriptorPool(): pCreateInfo->pPoolSizes[%" PRIu32 "].descriptorCount is not greater than 0. %s",
2339 i, validation_error_map[VALIDATION_ERROR_04a0025c]);
2340 }
2341 }
2342 }
2343 }
2344
2345 return skip;
2346}
2347
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002348VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *funcName) {
2349 const auto item = name_to_funcptr_map.find(funcName);
2350 if (item != name_to_funcptr_map.end()) {
2351 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2352 }
2353
2354 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2355 const auto &table = device_data->dispatch_table;
2356 if (!table.GetDeviceProcAddr) return nullptr;
2357 return table.GetDeviceProcAddr(device, funcName);
2358}
2359
2360VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2361 const auto item = name_to_funcptr_map.find(funcName);
2362 if (item != name_to_funcptr_map.end()) {
2363 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2364 }
2365
2366 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2367 auto &table = instance_data->dispatch_table;
2368 if (!table.GetInstanceProcAddr) return nullptr;
2369 return table.GetInstanceProcAddr(instance, funcName);
2370}
2371
2372VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
2373 assert(instance);
2374 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2375
2376 if (!instance_data->dispatch_table.GetPhysicalDeviceProcAddr) return nullptr;
2377 return instance_data->dispatch_table.GetPhysicalDeviceProcAddr(instance, funcName);
2378}
2379
2380// If additional validation is needed outside of the generated checks, a manual routine can be added to this file
2381// and the address filled in here. The autogenerated source will call these routines if the pointers are not NULL.
Petr Krausc8655be2017-09-27 18:56:51 +02002382void InitializeManualParameterValidationFunctionPointers() {
Mark Lobodzinski78a12a92017-08-08 14:16:51 -06002383 custom_functions["vkGetDeviceQueue"] = (void*)pv_vkGetDeviceQueue;
2384 custom_functions["vkCreateBuffer"] = (void*)pv_vkCreateBuffer;
2385 custom_functions["vkCreateImage"] = (void*)pv_vkCreateImage;
2386 custom_functions["vkCreateImageView"] = (void*)pv_vkCreateImageView;
2387 custom_functions["vkCreateGraphicsPipelines"] = (void*)pv_vkCreateGraphicsPipelines;
2388 custom_functions["vkCreateComputePipelines"] = (void*)pv_vkCreateComputePipelines;
2389 custom_functions["vkCreateSampler"] = (void*)pv_vkCreateSampler;
2390 custom_functions["vkCreateDescriptorSetLayout"] = (void*)pv_vkCreateDescriptorSetLayout;
2391 custom_functions["vkFreeDescriptorSets"] = (void*)pv_vkFreeDescriptorSets;
2392 custom_functions["vkUpdateDescriptorSets"] = (void*)pv_vkUpdateDescriptorSets;
2393 custom_functions["vkCreateRenderPass"] = (void*)pv_vkCreateRenderPass;
2394 custom_functions["vkBeginCommandBuffer"] = (void*)pv_vkBeginCommandBuffer;
2395 custom_functions["vkCmdSetViewport"] = (void*)pv_vkCmdSetViewport;
2396 custom_functions["vkCmdSetScissor"] = (void*)pv_vkCmdSetScissor;
2397 custom_functions["vkCmdDraw"] = (void*)pv_vkCmdDraw;
2398 custom_functions["vkCmdDrawIndirect"] = (void*)pv_vkCmdDrawIndirect;
2399 custom_functions["vkCmdDrawIndexedIndirect"] = (void*)pv_vkCmdDrawIndexedIndirect;
2400 custom_functions["vkCmdCopyImage"] = (void*)pv_vkCmdCopyImage;
2401 custom_functions["vkCmdBlitImage"] = (void*)pv_vkCmdBlitImage;
2402 custom_functions["vkCmdCopyBufferToImage"] = (void*)pv_vkCmdCopyBufferToImage;
2403 custom_functions["vkCmdCopyImageToBuffer"] = (void*)pv_vkCmdCopyImageToBuffer;
2404 custom_functions["vkCmdUpdateBuffer"] = (void*)pv_vkCmdUpdateBuffer;
2405 custom_functions["vkCmdFillBuffer"] = (void*)pv_vkCmdFillBuffer;
2406 custom_functions["vkCreateSwapchainKHR"] = (void*)pv_vkCreateSwapchainKHR;
2407 custom_functions["vkQueuePresentKHR"] = (void*)pv_vkQueuePresentKHR;
Petr Krausc8655be2017-09-27 18:56:51 +02002408 custom_functions["vkCreateDescriptorPool"] = (void*)pv_vkCreateDescriptorPool;
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002409}
2410
2411} // namespace parameter_validation
2412
2413VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
2414 VkExtensionProperties *pProperties) {
2415 return parameter_validation::vkEnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties);
2416}
2417
2418VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount,
2419 VkLayerProperties *pProperties) {
2420 return parameter_validation::vkEnumerateInstanceLayerProperties(pCount, pProperties);
2421}
2422
2423VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
2424 VkLayerProperties *pProperties) {
2425 // the layer command handles VK_NULL_HANDLE just fine internally
2426 assert(physicalDevice == VK_NULL_HANDLE);
2427 return parameter_validation::vkEnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties);
2428}
2429
2430VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
2431 const char *pLayerName, uint32_t *pCount,
2432 VkExtensionProperties *pProperties) {
2433 // the layer command handles VK_NULL_HANDLE just fine internally
2434 assert(physicalDevice == VK_NULL_HANDLE);
2435 return parameter_validation::vkEnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties);
2436}
2437
2438VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
2439 return parameter_validation::vkGetDeviceProcAddr(dev, funcName);
2440}
2441
2442VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2443 return parameter_validation::vkGetInstanceProcAddr(instance, funcName);
2444}
2445
2446VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
2447 const char *funcName) {
2448 return parameter_validation::vkGetPhysicalDeviceProcAddr(instance, funcName);
2449}
2450
2451VK_LAYER_EXPORT bool pv_vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) {
2452 assert(pVersionStruct != NULL);
2453 assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT);
2454
2455 // Fill in the function pointers if our version is at least capable of having the structure contain them.
2456 if (pVersionStruct->loaderLayerInterfaceVersion >= 2) {
2457 pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr;
2458 pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr;
2459 pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr;
2460 }
2461
2462 if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
2463 parameter_validation::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion;
2464 } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
2465 pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
2466 }
2467
2468 return VK_SUCCESS;
2469}