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