blob: c689680ef20ff8fe127a143003e39f5e1ab1acdc [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) {
Petr Kraus299ba622017-11-24 03:09:03 +0100915 bool has_dynamic_viewport = false;
916 bool has_dynamic_scissor = false;
917 bool has_dynamic_line_width = false;
918 if (pCreateInfos[i].pDynamicState != nullptr) {
919 const auto &dynamic_state_info = *pCreateInfos[i].pDynamicState;
920 for (uint32_t state_index = 0; state_index < dynamic_state_info.dynamicStateCount; ++state_index) {
921 const auto &dynamic_state = dynamic_state_info.pDynamicStates[state_index];
922 if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT) has_dynamic_viewport = true;
923 if (dynamic_state == VK_DYNAMIC_STATE_SCISSOR) has_dynamic_scissor = true;
924 if (dynamic_state == VK_DYNAMIC_STATE_LINE_WIDTH) has_dynamic_line_width = true;
925 }
926 }
927
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600928 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
929 if (pCreateInfos[i].pVertexInputState != nullptr) {
930 auto const &vertex_input_state = pCreateInfos[i].pVertexInputState;
931 for (uint32_t d = 0; d < vertex_input_state->vertexBindingDescriptionCount; ++d) {
932 auto const &vertex_bind_desc = vertex_input_state->pVertexBindingDescriptions[d];
933 if (vertex_bind_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
934 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
935 __LINE__, VALIDATION_ERROR_14c004d4, LayerName,
936 "vkCreateGraphicsPipelines: parameter "
937 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].binding (%u) is "
938 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
939 i, d, vertex_bind_desc.binding, device_data->device_limits.maxVertexInputBindings,
940 validation_error_map[VALIDATION_ERROR_14c004d4]);
941 }
942
943 if (vertex_bind_desc.stride > device_data->device_limits.maxVertexInputBindingStride) {
944 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
945 __LINE__, VALIDATION_ERROR_14c004d6, LayerName,
946 "vkCreateGraphicsPipelines: parameter "
947 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].stride (%u) is greater "
948 "than VkPhysicalDeviceLimits::maxVertexInputBindingStride (%u). %s",
949 i, d, vertex_bind_desc.stride, device_data->device_limits.maxVertexInputBindingStride,
950 validation_error_map[VALIDATION_ERROR_14c004d6]);
951 }
952 }
953
954 for (uint32_t d = 0; d < vertex_input_state->vertexAttributeDescriptionCount; ++d) {
955 auto const &vertex_attrib_desc = vertex_input_state->pVertexAttributeDescriptions[d];
956 if (vertex_attrib_desc.location >= device_data->device_limits.maxVertexInputAttributes) {
957 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
958 __LINE__, VALIDATION_ERROR_14a004d8, LayerName,
959 "vkCreateGraphicsPipelines: parameter "
960 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].location (%u) is "
961 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes (%u). %s",
962 i, d, vertex_attrib_desc.location, device_data->device_limits.maxVertexInputAttributes,
963 validation_error_map[VALIDATION_ERROR_14a004d8]);
964 }
965
966 if (vertex_attrib_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
967 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
968 __LINE__, VALIDATION_ERROR_14a004da, LayerName,
969 "vkCreateGraphicsPipelines: parameter "
970 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].binding (%u) is "
971 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
972 i, d, vertex_attrib_desc.binding, device_data->device_limits.maxVertexInputBindings,
973 validation_error_map[VALIDATION_ERROR_14a004da]);
974 }
975
976 if (vertex_attrib_desc.offset > device_data->device_limits.maxVertexInputAttributeOffset) {
977 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
978 __LINE__, VALIDATION_ERROR_14a004dc, LayerName,
979 "vkCreateGraphicsPipelines: parameter "
980 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].offset (%u) is "
981 "greater than VkPhysicalDeviceLimits::maxVertexInputAttributeOffset (%u). %s",
982 i, d, vertex_attrib_desc.offset, device_data->device_limits.maxVertexInputAttributeOffset,
983 validation_error_map[VALIDATION_ERROR_14a004dc]);
984 }
985 }
986 }
987
988 if (pCreateInfos[i].pStages != nullptr) {
989 bool has_control = false;
990 bool has_eval = false;
991
992 for (uint32_t stage_index = 0; stage_index < pCreateInfos[i].stageCount; ++stage_index) {
993 if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
994 has_control = true;
995 } else if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) {
996 has_eval = true;
997 }
998 }
999
1000 // pTessellationState is ignored without both tessellation control and tessellation evaluation shaders stages
1001 if (has_control && has_eval) {
1002 if (pCreateInfos[i].pTessellationState == nullptr) {
1003 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1004 __LINE__, VALIDATION_ERROR_096005b6, LayerName,
1005 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pStages includes a tessellation control "
1006 "shader stage and a tessellation evaluation shader stage, "
1007 "pCreateInfos[%d].pTessellationState must not be NULL. %s",
1008 i, i, validation_error_map[VALIDATION_ERROR_096005b6]);
1009 } else {
1010 skip |= validate_struct_pnext(
1011 report_data, "vkCreateGraphicsPipelines",
1012 ParameterName("pCreateInfos[%i].pTessellationState->pNext", ParameterName::IndexVector{i}), NULL,
1013 pCreateInfos[i].pTessellationState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0961c40d);
1014
1015 skip |= validate_reserved_flags(
1016 report_data, "vkCreateGraphicsPipelines",
1017 ParameterName("pCreateInfos[%i].pTessellationState->flags", ParameterName::IndexVector{i}),
1018 pCreateInfos[i].pTessellationState->flags, VALIDATION_ERROR_10809005);
1019
1020 if (pCreateInfos[i].pTessellationState->sType !=
1021 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO) {
1022 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1023 __LINE__, VALIDATION_ERROR_1082b00b, LayerName,
1024 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pTessellationState->sType must "
1025 "be VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO. %s",
1026 i, validation_error_map[VALIDATION_ERROR_1082b00b]);
1027 }
1028
1029 if (pCreateInfos[i].pTessellationState->patchControlPoints == 0 ||
1030 pCreateInfos[i].pTessellationState->patchControlPoints >
1031 device_data->device_limits.maxTessellationPatchSize) {
1032 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1033 __LINE__, VALIDATION_ERROR_1080097c, LayerName,
1034 "vkCreateGraphicsPipelines: invalid parameter "
1035 "pCreateInfos[%d].pTessellationState->patchControlPoints value %u. patchControlPoints "
1036 "should be >0 and <=%u. %s",
1037 i, pCreateInfos[i].pTessellationState->patchControlPoints,
1038 device_data->device_limits.maxTessellationPatchSize,
1039 validation_error_map[VALIDATION_ERROR_1080097c]);
1040 }
1041 }
1042 }
1043 }
1044
1045 // pViewportState, pMultisampleState, pDepthStencilState, and pColorBlendState ignored when rasterization is disabled
1046 if ((pCreateInfos[i].pRasterizationState != nullptr) &&
1047 (pCreateInfos[i].pRasterizationState->rasterizerDiscardEnable == VK_FALSE)) {
1048 if (pCreateInfos[i].pViewportState == nullptr) {
Petr Krausa6103552017-11-16 21:21:58 +01001049 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1050 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_096005dc, LayerName,
1051 "vkCreateGraphicsPipelines: Rasterization is enabled (pCreateInfos[%" PRIu32
1052 "].pRasterizationState->rasterizerDiscardEnable is VK_FALSE), but pCreateInfos[%" PRIu32
1053 "].pViewportState (=NULL) is not a valid pointer. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001054 i, i, validation_error_map[VALIDATION_ERROR_096005dc]);
1055 } else {
Petr Krausa6103552017-11-16 21:21:58 +01001056 const auto &viewport_state = *pCreateInfos[i].pViewportState;
1057
1058 if (viewport_state.sType != VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO) {
1059 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1060 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c2b00b, LayerName,
1061 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1062 "].pViewportState->sType is not VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO. %s",
1063 i, validation_error_map[VALIDATION_ERROR_10c2b00b]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001064 }
1065
Petr Krausa6103552017-11-16 21:21:58 +01001066 const VkStructureType allowed_structs_VkPipelineViewportStateCreateInfo[] = {
1067 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SWIZZLE_STATE_CREATE_INFO_NV,
1068 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_W_SCALING_STATE_CREATE_INFO_NV};
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001069 skip |= validate_struct_pnext(
1070 report_data, "vkCreateGraphicsPipelines",
Petr Krausa6103552017-11-16 21:21:58 +01001071 ParameterName("pCreateInfos[%i].pViewportState->pNext", ParameterName::IndexVector{i}),
1072 "VkPipelineViewportSwizzleStateCreateInfoNV, VkPipelineViewportWScalingStateCreateInfoNV",
1073 viewport_state.pNext, ARRAY_SIZE(allowed_structs_VkPipelineViewportStateCreateInfo),
1074 allowed_structs_VkPipelineViewportStateCreateInfo, 65, VALIDATION_ERROR_10c1c40d);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001075
1076 skip |= validate_reserved_flags(
1077 report_data, "vkCreateGraphicsPipelines",
1078 ParameterName("pCreateInfos[%i].pViewportState->flags", ParameterName::IndexVector{i}),
Petr Krausa6103552017-11-16 21:21:58 +01001079 viewport_state.flags, VALIDATION_ERROR_10c09005);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001080
Petr Krausa6103552017-11-16 21:21:58 +01001081 if (!device_data->physical_device_features.multiViewport) {
1082 if (viewport_state.viewportCount != 1) {
1083 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1084 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00980, LayerName,
1085 "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
1086 "disabled, but pCreateInfos[%" PRIu32 "].pViewportState->viewportCount (=%" PRIu32
1087 ") is not 1. %s",
1088 i, viewport_state.viewportCount, validation_error_map[VALIDATION_ERROR_10c00980]);
1089 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001090
Petr Krausa6103552017-11-16 21:21:58 +01001091 if (viewport_state.scissorCount != 1) {
1092 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1093 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00982, LayerName,
1094 "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
1095 "disabled, but pCreateInfos[%" PRIu32 "].pViewportState->scissorCount (=%" PRIu32
1096 ") is not 1. %s",
1097 i, viewport_state.scissorCount, validation_error_map[VALIDATION_ERROR_10c00982]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001098 }
Petr Krausa6103552017-11-16 21:21:58 +01001099 } else { // multiViewport enabled
1100 if (viewport_state.viewportCount == 0) {
1101 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1102 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c30a1b, LayerName,
1103 "vkCreateGraphicsPipelines: The pCreateInfos[%" PRIu32
1104 "].pViewportState->viewportCount is 0. %s",
1105 i, validation_error_map[VALIDATION_ERROR_10c30a1b]);
1106 } else if (viewport_state.viewportCount > device_data->device_limits.maxViewports) {
1107 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1108 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00984, LayerName,
1109 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1110 "].pViewportState->viewportCount (=%" PRIu32
1111 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
1112 i, viewport_state.viewportCount, device_data->device_limits.maxViewports,
1113 validation_error_map[VALIDATION_ERROR_10c00984]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001114 }
Petr Krausa6103552017-11-16 21:21:58 +01001115
1116 if (viewport_state.scissorCount == 0) {
1117 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1118 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c2b61b, LayerName,
1119 "vkCreateGraphicsPipelines: The pCreateInfos[%" PRIu32
1120 "].pViewportState->scissorCount is 0. %s",
1121 i, validation_error_map[VALIDATION_ERROR_10c2b61b]);
1122 } else if (viewport_state.scissorCount > device_data->device_limits.maxViewports) {
1123 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1124 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00986, LayerName,
1125 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1126 "].pViewportState->scissorCount (=%" PRIu32
1127 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
1128 i, viewport_state.scissorCount, device_data->device_limits.maxViewports,
1129 validation_error_map[VALIDATION_ERROR_10c00986]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001130 }
1131 }
1132
Petr Krausa6103552017-11-16 21:21:58 +01001133 if (viewport_state.scissorCount != viewport_state.viewportCount) {
1134 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1135 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00988, LayerName,
1136 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1137 "].pViewportState->scissorCount (=%" PRIu32 ") is not identical to pCreateInfos[%" PRIu32
1138 "].pViewportState->viewportCount (=%" PRIu32 "). %s",
1139 i, viewport_state.scissorCount, i, viewport_state.viewportCount,
1140 validation_error_map[VALIDATION_ERROR_10c00988]);
1141 }
1142
Petr Krausa6103552017-11-16 21:21:58 +01001143 if (!has_dynamic_viewport && viewport_state.viewportCount > 0 && viewport_state.pViewports == nullptr) {
1144 skip |= log_msg(
1145 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, VK_NULL_HANDLE,
1146 __LINE__, VALIDATION_ERROR_096005d6, LayerName,
1147 "vkCreateGraphicsPipelines: The viewport state is static (pCreateInfos[%" PRIu32
1148 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_VIEWPORT), but pCreateInfos[%" PRIu32
1149 "].pViewportState->pViewports (=NULL) is a invalid pointer. %s",
1150 i, i, validation_error_map[VALIDATION_ERROR_096005d6]);
1151 }
1152
1153 if (!has_dynamic_scissor && viewport_state.scissorCount > 0 && viewport_state.pScissors == nullptr) {
1154 skip |= log_msg(
1155 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, VK_NULL_HANDLE,
1156 __LINE__, VALIDATION_ERROR_096005d8, LayerName,
1157 "vkCreateGraphicsPipelines: The scissor state is static (pCreateInfos[%" PRIu32
1158 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_SCISSOR), but pCreateInfos[%" PRIu32
1159 "].pViewportState->pScissors (=NULL) is a invalid pointer. %s",
1160 i, i, validation_error_map[VALIDATION_ERROR_096005d8]);
1161 }
1162
1163 // TODO: validate the VkViewports in pViewports here
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001164 }
1165
1166 if (pCreateInfos[i].pMultisampleState == nullptr) {
1167 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1168 __LINE__, VALIDATION_ERROR_096005de, LayerName,
1169 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pRasterizationState->rasterizerDiscardEnable "
1170 "is VK_FALSE, pCreateInfos[%d].pMultisampleState must not be NULL. %s",
1171 i, i, validation_error_map[VALIDATION_ERROR_096005de]);
1172 } else {
1173 skip |= validate_struct_pnext(
1174 report_data, "vkCreateGraphicsPipelines",
1175 ParameterName("pCreateInfos[%i].pMultisampleState->pNext", ParameterName::IndexVector{i}), NULL,
1176 pCreateInfos[i].pMultisampleState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_1001c40d);
1177
1178 skip |= validate_reserved_flags(
1179 report_data, "vkCreateGraphicsPipelines",
1180 ParameterName("pCreateInfos[%i].pMultisampleState->flags", ParameterName::IndexVector{i}),
1181 pCreateInfos[i].pMultisampleState->flags, VALIDATION_ERROR_10009005);
1182
1183 skip |= validate_bool32(
1184 report_data, "vkCreateGraphicsPipelines",
1185 ParameterName("pCreateInfos[%i].pMultisampleState->sampleShadingEnable", ParameterName::IndexVector{i}),
1186 pCreateInfos[i].pMultisampleState->sampleShadingEnable);
1187
1188 skip |= validate_array(
1189 report_data, "vkCreateGraphicsPipelines",
1190 ParameterName("pCreateInfos[%i].pMultisampleState->rasterizationSamples", ParameterName::IndexVector{i}),
1191 ParameterName("pCreateInfos[%i].pMultisampleState->pSampleMask", ParameterName::IndexVector{i}),
1192 pCreateInfos[i].pMultisampleState->rasterizationSamples, pCreateInfos[i].pMultisampleState->pSampleMask,
1193 true, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1194
1195 skip |= validate_bool32(
1196 report_data, "vkCreateGraphicsPipelines",
1197 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToCoverageEnable", ParameterName::IndexVector{i}),
1198 pCreateInfos[i].pMultisampleState->alphaToCoverageEnable);
1199
1200 skip |= validate_bool32(
1201 report_data, "vkCreateGraphicsPipelines",
1202 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToOneEnable", ParameterName::IndexVector{i}),
1203 pCreateInfos[i].pMultisampleState->alphaToOneEnable);
1204
1205 if (pCreateInfos[i].pMultisampleState->sType != VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO) {
1206 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1207 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1208 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pMultisampleState->sType must be "
1209 "VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO",
1210 i);
1211 }
1212 }
1213
Mark Lobodzinski5cd08512017-09-12 09:50:25 -06001214 // TODO: Conditional NULL check based on subpass depth/stencil attachment
1215 if (pCreateInfos[i].pDepthStencilState != nullptr) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001216 skip |= validate_struct_pnext(
1217 report_data, "vkCreateGraphicsPipelines",
1218 ParameterName("pCreateInfos[%i].pDepthStencilState->pNext", ParameterName::IndexVector{i}), NULL,
1219 pCreateInfos[i].pDepthStencilState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f61c40d);
1220
1221 skip |= validate_reserved_flags(
1222 report_data, "vkCreateGraphicsPipelines",
1223 ParameterName("pCreateInfos[%i].pDepthStencilState->flags", ParameterName::IndexVector{i}),
1224 pCreateInfos[i].pDepthStencilState->flags, VALIDATION_ERROR_0f609005);
1225
1226 skip |= validate_bool32(
1227 report_data, "vkCreateGraphicsPipelines",
1228 ParameterName("pCreateInfos[%i].pDepthStencilState->depthTestEnable", ParameterName::IndexVector{i}),
1229 pCreateInfos[i].pDepthStencilState->depthTestEnable);
1230
1231 skip |= validate_bool32(
1232 report_data, "vkCreateGraphicsPipelines",
1233 ParameterName("pCreateInfos[%i].pDepthStencilState->depthWriteEnable", ParameterName::IndexVector{i}),
1234 pCreateInfos[i].pDepthStencilState->depthWriteEnable);
1235
1236 skip |= validate_ranged_enum(
1237 report_data, "vkCreateGraphicsPipelines",
1238 ParameterName("pCreateInfos[%i].pDepthStencilState->depthCompareOp", ParameterName::IndexVector{i}),
1239 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->depthCompareOp,
1240 VALIDATION_ERROR_0f604001);
1241
1242 skip |= validate_bool32(
1243 report_data, "vkCreateGraphicsPipelines",
1244 ParameterName("pCreateInfos[%i].pDepthStencilState->depthBoundsTestEnable", ParameterName::IndexVector{i}),
1245 pCreateInfos[i].pDepthStencilState->depthBoundsTestEnable);
1246
1247 skip |= validate_bool32(
1248 report_data, "vkCreateGraphicsPipelines",
1249 ParameterName("pCreateInfos[%i].pDepthStencilState->stencilTestEnable", ParameterName::IndexVector{i}),
1250 pCreateInfos[i].pDepthStencilState->stencilTestEnable);
1251
1252 skip |= validate_ranged_enum(
1253 report_data, "vkCreateGraphicsPipelines",
1254 ParameterName("pCreateInfos[%i].pDepthStencilState->front.failOp", ParameterName::IndexVector{i}),
1255 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.failOp,
1256 VALIDATION_ERROR_13a08601);
1257
1258 skip |= validate_ranged_enum(
1259 report_data, "vkCreateGraphicsPipelines",
1260 ParameterName("pCreateInfos[%i].pDepthStencilState->front.passOp", ParameterName::IndexVector{i}),
1261 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.passOp,
1262 VALIDATION_ERROR_13a27801);
1263
1264 skip |= validate_ranged_enum(
1265 report_data, "vkCreateGraphicsPipelines",
1266 ParameterName("pCreateInfos[%i].pDepthStencilState->front.depthFailOp", ParameterName::IndexVector{i}),
1267 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.depthFailOp,
1268 VALIDATION_ERROR_13a04201);
1269
1270 skip |= validate_ranged_enum(
1271 report_data, "vkCreateGraphicsPipelines",
1272 ParameterName("pCreateInfos[%i].pDepthStencilState->front.compareOp", ParameterName::IndexVector{i}),
1273 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->front.compareOp,
1274 VALIDATION_ERROR_0f604001);
1275
1276 skip |= validate_ranged_enum(
1277 report_data, "vkCreateGraphicsPipelines",
1278 ParameterName("pCreateInfos[%i].pDepthStencilState->back.failOp", ParameterName::IndexVector{i}),
1279 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.failOp,
1280 VALIDATION_ERROR_13a08601);
1281
1282 skip |= validate_ranged_enum(
1283 report_data, "vkCreateGraphicsPipelines",
1284 ParameterName("pCreateInfos[%i].pDepthStencilState->back.passOp", ParameterName::IndexVector{i}),
1285 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.passOp,
1286 VALIDATION_ERROR_13a27801);
1287
1288 skip |= validate_ranged_enum(
1289 report_data, "vkCreateGraphicsPipelines",
1290 ParameterName("pCreateInfos[%i].pDepthStencilState->back.depthFailOp", ParameterName::IndexVector{i}),
1291 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.depthFailOp,
1292 VALIDATION_ERROR_13a04201);
1293
1294 skip |= validate_ranged_enum(
1295 report_data, "vkCreateGraphicsPipelines",
1296 ParameterName("pCreateInfos[%i].pDepthStencilState->back.compareOp", ParameterName::IndexVector{i}),
1297 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->back.compareOp,
1298 VALIDATION_ERROR_0f604001);
1299
1300 if (pCreateInfos[i].pDepthStencilState->sType != VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO) {
1301 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1302 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1303 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pDepthStencilState->sType must be "
1304 "VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO",
1305 i);
1306 }
1307 }
1308
Mark Lobodzinski5cd08512017-09-12 09:50:25 -06001309 // TODO: Conditional NULL check based on subpass color attachment
1310 if (pCreateInfos[i].pColorBlendState != nullptr) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001311 skip |= validate_struct_pnext(
1312 report_data, "vkCreateGraphicsPipelines",
1313 ParameterName("pCreateInfos[%i].pColorBlendState->pNext", ParameterName::IndexVector{i}), NULL,
1314 pCreateInfos[i].pColorBlendState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f41c40d);
1315
1316 skip |= validate_reserved_flags(
1317 report_data, "vkCreateGraphicsPipelines",
1318 ParameterName("pCreateInfos[%i].pColorBlendState->flags", ParameterName::IndexVector{i}),
1319 pCreateInfos[i].pColorBlendState->flags, VALIDATION_ERROR_0f409005);
1320
1321 skip |= validate_bool32(
1322 report_data, "vkCreateGraphicsPipelines",
1323 ParameterName("pCreateInfos[%i].pColorBlendState->logicOpEnable", ParameterName::IndexVector{i}),
1324 pCreateInfos[i].pColorBlendState->logicOpEnable);
1325
1326 skip |= validate_array(
1327 report_data, "vkCreateGraphicsPipelines",
1328 ParameterName("pCreateInfos[%i].pColorBlendState->attachmentCount", ParameterName::IndexVector{i}),
1329 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments", ParameterName::IndexVector{i}),
1330 pCreateInfos[i].pColorBlendState->attachmentCount, pCreateInfos[i].pColorBlendState->pAttachments, false,
1331 true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1332
1333 if (pCreateInfos[i].pColorBlendState->pAttachments != NULL) {
1334 for (uint32_t attachmentIndex = 0; attachmentIndex < pCreateInfos[i].pColorBlendState->attachmentCount;
1335 ++attachmentIndex) {
1336 skip |= validate_bool32(report_data, "vkCreateGraphicsPipelines",
1337 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].blendEnable",
1338 ParameterName::IndexVector{i, attachmentIndex}),
1339 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].blendEnable);
1340
1341 skip |= validate_ranged_enum(
1342 report_data, "vkCreateGraphicsPipelines",
1343 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcColorBlendFactor",
1344 ParameterName::IndexVector{i, attachmentIndex}),
1345 "VkBlendFactor", AllVkBlendFactorEnums,
1346 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcColorBlendFactor,
1347 VALIDATION_ERROR_0f22cc01);
1348
1349 skip |= validate_ranged_enum(
1350 report_data, "vkCreateGraphicsPipelines",
1351 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstColorBlendFactor",
1352 ParameterName::IndexVector{i, attachmentIndex}),
1353 "VkBlendFactor", AllVkBlendFactorEnums,
1354 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstColorBlendFactor,
1355 VALIDATION_ERROR_0f207001);
1356
1357 skip |= validate_ranged_enum(
1358 report_data, "vkCreateGraphicsPipelines",
1359 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorBlendOp",
1360 ParameterName::IndexVector{i, attachmentIndex}),
1361 "VkBlendOp", AllVkBlendOpEnums,
1362 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorBlendOp,
1363 VALIDATION_ERROR_0f202001);
1364
1365 skip |= validate_ranged_enum(
1366 report_data, "vkCreateGraphicsPipelines",
1367 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcAlphaBlendFactor",
1368 ParameterName::IndexVector{i, attachmentIndex}),
1369 "VkBlendFactor", AllVkBlendFactorEnums,
1370 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcAlphaBlendFactor,
1371 VALIDATION_ERROR_0f22c601);
1372
1373 skip |= validate_ranged_enum(
1374 report_data, "vkCreateGraphicsPipelines",
1375 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstAlphaBlendFactor",
1376 ParameterName::IndexVector{i, attachmentIndex}),
1377 "VkBlendFactor", AllVkBlendFactorEnums,
1378 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstAlphaBlendFactor,
1379 VALIDATION_ERROR_0f206a01);
1380
1381 skip |= validate_ranged_enum(
1382 report_data, "vkCreateGraphicsPipelines",
1383 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].alphaBlendOp",
1384 ParameterName::IndexVector{i, attachmentIndex}),
1385 "VkBlendOp", AllVkBlendOpEnums,
1386 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].alphaBlendOp,
1387 VALIDATION_ERROR_0f200801);
1388
1389 skip |=
1390 validate_flags(report_data, "vkCreateGraphicsPipelines",
1391 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorWriteMask",
1392 ParameterName::IndexVector{i, attachmentIndex}),
1393 "VkColorComponentFlagBits", AllVkColorComponentFlagBits,
1394 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorWriteMask,
1395 false, false, VALIDATION_ERROR_0f202201);
1396 }
1397 }
1398
1399 if (pCreateInfos[i].pColorBlendState->sType != VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO) {
1400 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1401 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1402 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pColorBlendState->sType must be "
1403 "VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO",
1404 i);
1405 }
1406
1407 // If logicOpEnable is VK_TRUE, logicOp must be a valid VkLogicOp value
1408 if (pCreateInfos[i].pColorBlendState->logicOpEnable == VK_TRUE) {
1409 skip |= validate_ranged_enum(
1410 report_data, "vkCreateGraphicsPipelines",
1411 ParameterName("pCreateInfos[%i].pColorBlendState->logicOp", ParameterName::IndexVector{i}), "VkLogicOp",
1412 AllVkLogicOpEnums, pCreateInfos[i].pColorBlendState->logicOp, VALIDATION_ERROR_0f4004be);
1413 }
1414 }
1415 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001416
Petr Kraus9752aae2017-11-24 03:05:50 +01001417 if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT) {
1418 if (pCreateInfos[i].basePipelineIndex != -1) {
1419 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001420 skip |= log_msg(
1421 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1422 VALIDATION_ERROR_096005a8, LayerName,
1423 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineHandle, must be VK_NULL_HANDLE if "
1424 "pCreateInfos->flags "
1425 "contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag and pCreateInfos->basePipelineIndex is not -1. %s",
1426 validation_error_map[VALIDATION_ERROR_096005a8]);
1427 }
1428 }
1429
Petr Kraus9752aae2017-11-24 03:05:50 +01001430 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
1431 if (pCreateInfos[i].basePipelineIndex != -1) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001432 skip |= log_msg(
1433 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1434 VALIDATION_ERROR_096005aa, LayerName,
1435 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineIndex, must be -1 if "
1436 "pCreateInfos->flags "
1437 "contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag and pCreateInfos->basePipelineHandle is not "
1438 "VK_NULL_HANDLE. %s",
1439 validation_error_map[VALIDATION_ERROR_096005aa]);
1440 }
1441 }
1442 }
1443
Petr Kraus9752aae2017-11-24 03:05:50 +01001444 if (pCreateInfos[i].pRasterizationState) {
1445 if ((pCreateInfos[i].pRasterizationState->polygonMode != VK_POLYGON_MODE_FILL) &&
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001446 (device_data->physical_device_features.fillModeNonSolid == false)) {
1447 skip |= log_msg(
1448 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1449 DEVICE_FEATURE, LayerName,
1450 "vkCreateGraphicsPipelines parameter, VkPolygonMode pCreateInfos->pRasterizationState->polygonMode cannot "
1451 "be "
1452 "VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE if VkPhysicalDeviceFeatures->fillModeNonSolid is false.");
1453 }
Petr Kraus299ba622017-11-24 03:09:03 +01001454
1455 if (!has_dynamic_line_width && !device_data->physical_device_features.wideLines &&
1456 (pCreateInfos[i].pRasterizationState->lineWidth != 1.0f)) {
1457 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1458 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, 0, __LINE__, VALIDATION_ERROR_096005da, LayerName,
1459 "The line width state is static (pCreateInfos[%" PRIu32
1460 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_LINE_WIDTH) and "
1461 "VkPhysicalDeviceFeatures::wideLines is disabled, but pCreateInfos[%" PRIu32
1462 "].pRasterizationState->lineWidth (=%f) is not 1.0. %s",
1463 i, i, pCreateInfos[i].pRasterizationState->lineWidth,
1464 validation_error_map[VALIDATION_ERROR_096005da]);
1465 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001466 }
1467
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001468 for (size_t j = 0; j < pCreateInfos[i].stageCount; j++) {
1469 skip |= validate_string(device_data->report_data, "vkCreateGraphicsPipelines",
1470 ParameterName("pCreateInfos[%i].pStages[%i].pName", ParameterName::IndexVector{i, j}),
1471 pCreateInfos[i].pStages[j].pName);
1472 }
1473 }
1474 }
1475
1476 return skip;
1477}
1478
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001479bool pv_vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1480 const VkComputePipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1481 VkPipeline *pPipelines) {
1482 bool skip = false;
1483 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1484
1485 for (uint32_t i = 0; i < createInfoCount; i++) {
1486 skip |= validate_string(device_data->report_data, "vkCreateComputePipelines",
1487 ParameterName("pCreateInfos[%i].stage.pName", ParameterName::IndexVector{i}),
1488 pCreateInfos[i].stage.pName);
1489 }
1490
1491 return skip;
1492}
1493
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001494bool pv_vkCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1495 VkSampler *pSampler) {
1496 bool skip = false;
1497 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1498 debug_report_data *report_data = device_data->report_data;
1499
1500 if (pCreateInfo != nullptr) {
John Zulauf71968502017-10-26 13:51:15 -06001501 const auto &features = device_data->physical_device_features;
1502 const auto &limits = device_data->device_limits;
1503 if (pCreateInfo->anisotropyEnable == VK_TRUE) {
1504 if (!in_inclusive_range(pCreateInfo->maxAnisotropy, 1.0F, limits.maxSamplerAnisotropy)) {
1505 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1506 VALIDATION_ERROR_1260085e, LayerName,
1507 "vkCreateSampler(): value of %s must be in range [1.0, %f] %s, but %f found. %s",
1508 "pCreateInfo->maxAnisotropy", limits.maxSamplerAnisotropy,
1509 "VkPhysicalDeviceLimits::maxSamplerAnistropy", pCreateInfo->maxAnisotropy,
1510 validation_error_map[VALIDATION_ERROR_1260085e]);
1511 }
1512
1513 // Anistropy cannot be enabled in sampler unless enabled as a feature
1514 if (features.samplerAnisotropy == VK_FALSE) {
1515 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1516 VALIDATION_ERROR_1260085c, LayerName,
1517 "vkCreateSampler(): Anisotropic sampling feature is not enabled, %s must be VK_FALSE. %s",
1518 "pCreateInfo->anisotropyEnable", validation_error_map[VALIDATION_ERROR_1260085c]);
1519 }
1520
1521 // Anistropy and unnormalized coordinates cannot be enabled simultaneously
1522 if (pCreateInfo->unnormalizedCoordinates == VK_TRUE) {
1523 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1524 VALIDATION_ERROR_12600868, LayerName,
1525 "vkCreateSampler(): pCreateInfo->anisotropyEnable and pCreateInfo->unnormalizedCoordinates "
1526 "must not both be VK_TRUE. %s",
1527 validation_error_map[VALIDATION_ERROR_12600868]);
1528 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001529 }
1530
1531 // If compareEnable is VK_TRUE, compareOp must be a valid VkCompareOp value
1532 if (pCreateInfo->compareEnable == VK_TRUE) {
1533 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->compareOp", "VkCompareOp",
1534 AllVkCompareOpEnums, pCreateInfo->compareOp, VALIDATION_ERROR_12600870);
1535 }
1536
1537 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, borderColor must be a
1538 // valid VkBorderColor value
1539 if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
1540 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
1541 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)) {
1542 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->borderColor", "VkBorderColor",
1543 AllVkBorderColorEnums, pCreateInfo->borderColor, VALIDATION_ERROR_1260086c);
1544 }
1545
1546 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, the
1547 // VK_KHR_sampler_mirror_clamp_to_edge extension must be enabled
1548 if (!device_data->extensions.vk_khr_sampler_mirror_clamp_to_edge &&
1549 ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
1550 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
1551 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE))) {
1552 skip |=
1553 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1554 VALIDATION_ERROR_1260086e, LayerName,
1555 "vkCreateSampler(): A VkSamplerAddressMode value is set to VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE "
1556 "but the VK_KHR_sampler_mirror_clamp_to_edge extension has not been enabled. %s",
1557 validation_error_map[VALIDATION_ERROR_1260086e]);
1558 }
John Zulauf275805c2017-10-26 15:34:49 -06001559
1560 // Checks for the IMG cubic filtering extension
1561 if (device_data->extensions.vk_img_filter_cubic) {
1562 if ((pCreateInfo->anisotropyEnable == VK_TRUE) &&
1563 ((pCreateInfo->minFilter == VK_FILTER_CUBIC_IMG) || (pCreateInfo->magFilter == VK_FILTER_CUBIC_IMG))) {
1564 skip |=
1565 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1566 VALIDATION_ERROR_12600872, LayerName,
1567 "vkCreateSampler(): Anisotropic sampling must not be VK_TRUE when either minFilter or magFilter are "
1568 "VK_FILTER_CUBIC_IMG. %s",
1569 validation_error_map[VALIDATION_ERROR_12600872]);
1570 }
1571 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001572 }
1573
1574 return skip;
1575}
1576
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001577bool pv_vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
1578 const VkAllocationCallbacks *pAllocator, VkDescriptorSetLayout *pSetLayout) {
1579 bool skip = false;
1580 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1581 debug_report_data *report_data = device_data->report_data;
1582
1583 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1584 if ((pCreateInfo != nullptr) && (pCreateInfo->pBindings != nullptr)) {
1585 for (uint32_t i = 0; i < pCreateInfo->bindingCount; ++i) {
1586 if (pCreateInfo->pBindings[i].descriptorCount != 0) {
1587 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER or VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and descriptorCount
1588 // is not 0 and pImmutableSamplers is not NULL, pImmutableSamplers must be a pointer to an array of descriptorCount
1589 // valid VkSampler handles
1590 if (((pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
1591 (pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)) &&
1592 (pCreateInfo->pBindings[i].pImmutableSamplers != nullptr)) {
1593 for (uint32_t descriptor_index = 0; descriptor_index < pCreateInfo->pBindings[i].descriptorCount;
1594 ++descriptor_index) {
1595 if (pCreateInfo->pBindings[i].pImmutableSamplers[descriptor_index] == VK_NULL_HANDLE) {
1596 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1597 __LINE__, REQUIRED_PARAMETER, LayerName,
1598 "vkCreateDescriptorSetLayout: required parameter "
1599 "pCreateInfo->pBindings[%d].pImmutableSamplers[%d]"
1600 " specified as VK_NULL_HANDLE",
1601 i, descriptor_index);
1602 }
1603 }
1604 }
1605
1606 // If descriptorCount is not 0, stageFlags must be a valid combination of VkShaderStageFlagBits values
1607 if ((pCreateInfo->pBindings[i].stageFlags != 0) &&
1608 ((pCreateInfo->pBindings[i].stageFlags & (~AllVkShaderStageFlagBits)) != 0)) {
1609 skip |= log_msg(
1610 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1611 VALIDATION_ERROR_04e00236, LayerName,
1612 "vkCreateDescriptorSetLayout(): if pCreateInfo->pBindings[%d].descriptorCount is not 0, "
1613 "pCreateInfo->pBindings[%d].stageFlags must be a valid combination of VkShaderStageFlagBits values. %s",
1614 i, i, validation_error_map[VALIDATION_ERROR_04e00236]);
1615 }
1616 }
1617 }
1618 }
1619
1620 return skip;
1621}
1622
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001623bool pv_vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
1624 const VkDescriptorSet *pDescriptorSets) {
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 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
1631 // validate_array()
1632 skip |= validate_array(report_data, "vkFreeDescriptorSets", "descriptorSetCount", "pDescriptorSets", descriptorSetCount,
1633 pDescriptorSets, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1634 return skip;
1635}
1636
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001637bool pv_vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites,
1638 uint32_t descriptorCopyCount, const VkCopyDescriptorSet *pDescriptorCopies) {
1639 bool skip = false;
1640 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1641 debug_report_data *report_data = device_data->report_data;
1642
1643 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1644 if (pDescriptorWrites != NULL) {
1645 for (uint32_t i = 0; i < descriptorWriteCount; ++i) {
1646 // descriptorCount must be greater than 0
1647 if (pDescriptorWrites[i].descriptorCount == 0) {
1648 skip |=
1649 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1650 VALIDATION_ERROR_15c0441b, LayerName,
1651 "vkUpdateDescriptorSets(): parameter pDescriptorWrites[%d].descriptorCount must be greater than 0. %s",
1652 i, validation_error_map[VALIDATION_ERROR_15c0441b]);
1653 }
1654
1655 // dstSet must be a valid VkDescriptorSet handle
1656 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1657 ParameterName("pDescriptorWrites[%i].dstSet", ParameterName::IndexVector{i}),
1658 pDescriptorWrites[i].dstSet);
1659
1660 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
1661 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||
1662 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||
1663 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ||
1664 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) {
1665 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
1666 // VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
1667 // pImageInfo must be a pointer to an array of descriptorCount valid VkDescriptorImageInfo structures
1668 if (pDescriptorWrites[i].pImageInfo == nullptr) {
1669 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1670 __LINE__, VALIDATION_ERROR_15c00284, LayerName,
1671 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
1672 "VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, "
1673 "VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or "
1674 "VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, pDescriptorWrites[%d].pImageInfo must not be NULL. %s",
1675 i, i, validation_error_map[VALIDATION_ERROR_15c00284]);
1676 } else if (pDescriptorWrites[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) {
1677 // If descriptorType is VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
1678 // VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, the imageView and imageLayout
1679 // members of any given element of pImageInfo must be a valid VkImageView and VkImageLayout, respectively
1680 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
1681 ++descriptor_index) {
1682 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1683 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageView",
1684 ParameterName::IndexVector{i, descriptor_index}),
1685 pDescriptorWrites[i].pImageInfo[descriptor_index].imageView);
1686 skip |= validate_ranged_enum(report_data, "vkUpdateDescriptorSets",
1687 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageLayout",
1688 ParameterName::IndexVector{i, descriptor_index}),
1689 "VkImageLayout", AllVkImageLayoutEnums,
1690 pDescriptorWrites[i].pImageInfo[descriptor_index].imageLayout,
1691 VALIDATION_ERROR_UNDEFINED);
1692 }
1693 }
1694 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
1695 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
1696 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1697 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1698 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1699 // VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pBufferInfo must be a
1700 // pointer to an array of descriptorCount valid VkDescriptorBufferInfo structures
1701 if (pDescriptorWrites[i].pBufferInfo == nullptr) {
1702 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1703 __LINE__, VALIDATION_ERROR_15c00288, LayerName,
1704 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
1705 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, "
1706 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, "
1707 "pDescriptorWrites[%d].pBufferInfo must not be NULL. %s",
1708 i, i, validation_error_map[VALIDATION_ERROR_15c00288]);
1709 } else {
1710 for (uint32_t descriptorIndex = 0; descriptorIndex < pDescriptorWrites[i].descriptorCount; ++descriptorIndex) {
1711 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1712 ParameterName("pDescriptorWrites[%i].pBufferInfo[%i].buffer",
1713 ParameterName::IndexVector{i, descriptorIndex}),
1714 pDescriptorWrites[i].pBufferInfo[descriptorIndex].buffer);
1715 }
1716 }
1717 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||
1718 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) {
1719 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
1720 // pTexelBufferView must be a pointer to an array of descriptorCount valid VkBufferView handles
1721 if (pDescriptorWrites[i].pTexelBufferView == nullptr) {
1722 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1723 __LINE__, VALIDATION_ERROR_15c00286, LayerName,
1724 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
1725 "VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, "
1726 "pDescriptorWrites[%d].pTexelBufferView must not be NULL. %s",
1727 i, i, validation_error_map[VALIDATION_ERROR_15c00286]);
1728 } else {
1729 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
1730 ++descriptor_index) {
1731 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1732 ParameterName("pDescriptorWrites[%i].pTexelBufferView[%i]",
1733 ParameterName::IndexVector{i, descriptor_index}),
1734 pDescriptorWrites[i].pTexelBufferView[descriptor_index]);
1735 }
1736 }
1737 }
1738
1739 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
1740 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)) {
1741 VkDeviceSize uniformAlignment = device_data->device_limits.minUniformBufferOffsetAlignment;
1742 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
1743 if (pDescriptorWrites[i].pBufferInfo != NULL) {
1744 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) {
1745 skip |= log_msg(
1746 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1747 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c0028e, LayerName,
1748 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
1749 ") must be a multiple of device limit minUniformBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
1750 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment,
1751 validation_error_map[VALIDATION_ERROR_15c0028e]);
1752 }
1753 }
1754 }
1755 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
1756 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1757 VkDeviceSize storageAlignment = device_data->device_limits.minStorageBufferOffsetAlignment;
1758 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
1759 if (pDescriptorWrites[i].pBufferInfo != NULL) {
1760 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) {
1761 skip |= log_msg(
1762 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1763 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c00290, LayerName,
1764 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
1765 ") must be a multiple of device limit minStorageBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
1766 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment,
1767 validation_error_map[VALIDATION_ERROR_15c00290]);
1768 }
1769 }
1770 }
1771 }
1772 }
1773 }
1774 return skip;
1775}
1776
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001777bool pv_vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1778 VkRenderPass *pRenderPass) {
1779 bool skip = false;
1780 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1781 uint32_t max_color_attachments = device_data->device_limits.maxColorAttachments;
1782
1783 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
1784 if (pCreateInfo->pAttachments[i].format == VK_FORMAT_UNDEFINED) {
1785 std::stringstream ss;
1786 ss << "vkCreateRenderPass: pCreateInfo->pAttachments[" << i << "].format is VK_FORMAT_UNDEFINED. "
1787 << validation_error_map[VALIDATION_ERROR_00809201];
1788 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1789 __LINE__, VALIDATION_ERROR_00809201, "IMAGE", "%s", ss.str().c_str());
1790 }
1791 if (pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_UNDEFINED ||
1792 pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_PREINITIALIZED) {
1793 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1794 __LINE__, VALIDATION_ERROR_00800696, "DL",
1795 "pCreateInfo->pAttachments[%d].finalLayout must not be VK_IMAGE_LAYOUT_UNDEFINED or "
1796 "VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
1797 i, validation_error_map[VALIDATION_ERROR_00800696]);
1798 }
1799 }
1800
1801 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
1802 if (pCreateInfo->pSubpasses[i].colorAttachmentCount > max_color_attachments) {
1803 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1804 __LINE__, VALIDATION_ERROR_1400069a, "DL",
1805 "Cannot create a render pass with %d color attachments. Max is %d. %s",
1806 pCreateInfo->pSubpasses[i].colorAttachmentCount, max_color_attachments,
1807 validation_error_map[VALIDATION_ERROR_1400069a]);
1808 }
1809 }
1810 return skip;
1811}
1812
1813bool pv_vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
1814 const VkCommandBuffer *pCommandBuffers) {
1815 bool skip = false;
1816 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1817 debug_report_data *report_data = device_data->report_data;
1818
1819 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1820 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
1821 // validate_array()
1822 skip |= validate_array(report_data, "vkFreeCommandBuffers", "commandBufferCount", "pCommandBuffers", commandBufferCount,
1823 pCommandBuffers, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1824 return skip;
1825}
1826
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001827bool pv_vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo) {
1828 bool skip = false;
1829 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
1830 debug_report_data *report_data = device_data->report_data;
1831 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
1832
1833 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1834 // TODO: pBeginInfo->pInheritanceInfo must not be NULL if commandBuffer is a secondary command buffer
1835 skip |= validate_struct_type(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo",
1836 "VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO", pBeginInfo->pInheritanceInfo,
1837 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, false, VALIDATION_ERROR_UNDEFINED);
1838
1839 if (pBeginInfo->pInheritanceInfo != NULL) {
1840 skip |=
1841 validate_struct_pnext(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pNext", NULL,
1842 pBeginInfo->pInheritanceInfo->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0281c40d);
1843
1844 skip |= validate_bool32(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->occlusionQueryEnable",
1845 pBeginInfo->pInheritanceInfo->occlusionQueryEnable);
1846
1847 // TODO: This only needs to be validated when the inherited queries feature is enabled
1848 // skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
1849 // "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pBeginInfo->pInheritanceInfo->queryFlags, false);
1850
1851 // TODO: This must be 0 if the pipeline statistics queries feature is not enabled
1852 skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pipelineStatistics",
1853 "VkQueryPipelineStatisticFlagBits", AllVkQueryPipelineStatisticFlagBits,
1854 pBeginInfo->pInheritanceInfo->pipelineStatistics, false, false, VALIDATION_ERROR_UNDEFINED);
1855 }
1856
1857 if (pInfo != NULL) {
1858 if ((device_data->physical_device_features.inheritedQueries == VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
1859 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1860 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_02a00070, LayerName,
1861 "Cannot set inherited occlusionQueryEnable in vkBeginCommandBuffer() when device does not support "
1862 "inheritedQueries. %s",
1863 validation_error_map[VALIDATION_ERROR_02a00070]);
1864 }
1865 if ((device_data->physical_device_features.inheritedQueries != VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
1866 skip |= validate_flags(device_data->report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
1867 "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pInfo->queryFlags, false, false,
1868 VALIDATION_ERROR_02a00072);
1869 }
1870 }
1871
1872 return skip;
1873}
1874
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001875bool pv_vkCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount,
1876 const VkViewport *pViewports) {
1877 bool skip = false;
1878 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
1879
1880 skip |= validate_array(device_data->report_data, "vkCmdSetViewport", "viewportCount", "pViewports", viewportCount, pViewports,
1881 true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1882
1883 if (viewportCount > 0 && pViewports != nullptr) {
1884 const VkPhysicalDeviceLimits &limits = device_data->device_limits;
1885 for (uint32_t viewportIndex = 0; viewportIndex < viewportCount; ++viewportIndex) {
1886 const VkViewport &viewport = pViewports[viewportIndex];
1887
1888 if (device_data->physical_device_features.multiViewport == false) {
1889 if (viewportCount != 1) {
1890 skip |= log_msg(
1891 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1892 __LINE__, DEVICE_FEATURE, LayerName,
1893 "vkCmdSetViewport(): The multiViewport feature is not enabled, so viewportCount must be 1 but is %d.",
1894 viewportCount);
1895 }
1896 if (firstViewport != 0) {
1897 skip |= log_msg(
1898 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1899 __LINE__, DEVICE_FEATURE, LayerName,
1900 "vkCmdSetViewport(): The multiViewport feature is not enabled, so firstViewport must be 0 but is %d.",
1901 firstViewport);
1902 }
1903 }
1904
1905 if (viewport.width <= 0 || viewport.width > limits.maxViewportDimensions[0]) {
1906 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1907 __LINE__, VALIDATION_ERROR_15000996, LayerName,
1908 "vkCmdSetViewport %d: width (%f) exceeds permitted bounds (0,%u). %s", viewportIndex,
1909 viewport.width, limits.maxViewportDimensions[0], validation_error_map[VALIDATION_ERROR_15000996]);
1910 }
1911
1912 if (device_data->extensions.vk_amd_negative_viewport_height || device_data->extensions.vk_khr_maintenance1) {
1913 // Check lower bound against negative viewport height instead of zero
1914 if (viewport.height <= -(static_cast<int32_t>(limits.maxViewportDimensions[1])) ||
1915 (viewport.height > limits.maxViewportDimensions[1])) {
1916 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1917 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, VALIDATION_ERROR_1500099a, LayerName,
1918 "vkCmdSetViewport %d: height (%f) exceeds permitted bounds (-%u,%u). %s", viewportIndex,
1919 viewport.height, limits.maxViewportDimensions[1], limits.maxViewportDimensions[1],
1920 validation_error_map[VALIDATION_ERROR_1500099a]);
1921 }
1922 } else {
1923 if ((viewport.height <= 0) || (viewport.height > limits.maxViewportDimensions[1])) {
1924 skip |=
1925 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1926 __LINE__, VALIDATION_ERROR_15000998, LayerName,
1927 "vkCmdSetViewport %d: height (%f) exceeds permitted bounds (0,%u). %s", viewportIndex,
1928 viewport.height, limits.maxViewportDimensions[1], validation_error_map[VALIDATION_ERROR_15000998]);
1929 }
1930 }
1931
1932 if (viewport.x < limits.viewportBoundsRange[0] || viewport.x > limits.viewportBoundsRange[1]) {
1933 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1934 __LINE__, VALIDATION_ERROR_1500099e, LayerName,
1935 "vkCmdSetViewport %d: x (%f) exceeds permitted bounds (%f,%f). %s", viewportIndex, viewport.x,
1936 limits.viewportBoundsRange[0], limits.viewportBoundsRange[1],
1937 validation_error_map[VALIDATION_ERROR_1500099e]);
1938 }
1939
1940 if (viewport.y < limits.viewportBoundsRange[0] || viewport.y > limits.viewportBoundsRange[1]) {
1941 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1942 __LINE__, VALIDATION_ERROR_1500099e, LayerName,
1943 "vkCmdSetViewport %d: y (%f) exceeds permitted bounds (%f,%f). %s", viewportIndex, viewport.y,
1944 limits.viewportBoundsRange[0], limits.viewportBoundsRange[1],
1945 validation_error_map[VALIDATION_ERROR_1500099e]);
1946 }
1947
1948 if (viewport.x + viewport.width > limits.viewportBoundsRange[1]) {
1949 skip |=
1950 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1951 __LINE__, VALIDATION_ERROR_150009a0, LayerName,
1952 "vkCmdSetViewport %d: x (%f) + width (%f) exceeds permitted bound (%f). %s", viewportIndex, viewport.x,
1953 viewport.width, limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a0]);
1954 }
1955
1956 if (viewport.y + viewport.height > limits.viewportBoundsRange[1]) {
1957 skip |=
1958 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1959 __LINE__, VALIDATION_ERROR_150009a2, LayerName,
1960 "vkCmdSetViewport %d: y (%f) + height (%f) exceeds permitted bound (%f). %s", viewportIndex, viewport.y,
1961 viewport.height, limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a2]);
1962 }
1963 }
1964 }
1965 return skip;
1966}
1967
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001968bool pv_vkCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *pScissors) {
1969 bool skip = false;
1970 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
1971 debug_report_data *report_data = device_data->report_data;
1972
1973 if (device_data->physical_device_features.multiViewport == false) {
1974 if (scissorCount != 1) {
1975 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1976 DEVICE_FEATURE, LayerName,
1977 "vkCmdSetScissor(): The multiViewport feature is not enabled, so scissorCount must be 1 but is %d.",
1978 scissorCount);
1979 }
1980 if (firstScissor != 0) {
1981 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1982 DEVICE_FEATURE, LayerName,
1983 "vkCmdSetScissor(): The multiViewport feature is not enabled, so firstScissor must be 0 but is %d.",
1984 firstScissor);
1985 }
1986 }
1987
1988 for (uint32_t scissorIndex = 0; scissorIndex < scissorCount; ++scissorIndex) {
1989 const VkRect2D &pScissor = pScissors[scissorIndex];
1990
1991 if (pScissor.offset.x < 0) {
1992 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1993 VALIDATION_ERROR_1d8004a6, LayerName, "vkCmdSetScissor %d: offset.x (%d) must not be negative. %s",
1994 scissorIndex, pScissor.offset.x, validation_error_map[VALIDATION_ERROR_1d8004a6]);
1995 } else if (static_cast<int32_t>(pScissor.extent.width) > (INT_MAX - pScissor.offset.x)) {
1996 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1997 VALIDATION_ERROR_1d8004a8, LayerName,
1998 "vkCmdSetScissor %d: adding offset.x (%d) and extent.width (%u) will overflow. %s", scissorIndex,
1999 pScissor.offset.x, pScissor.extent.width, validation_error_map[VALIDATION_ERROR_1d8004a8]);
2000 }
2001
2002 if (pScissor.offset.y < 0) {
2003 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2004 VALIDATION_ERROR_1d8004a6, LayerName, "vkCmdSetScissor %d: offset.y (%d) must not be negative. %s",
2005 scissorIndex, pScissor.offset.y, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2006 } else if (static_cast<int32_t>(pScissor.extent.height) > (INT_MAX - pScissor.offset.y)) {
2007 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2008 VALIDATION_ERROR_1d8004aa, LayerName,
2009 "vkCmdSetScissor %d: adding offset.y (%d) and extent.height (%u) will overflow. %s", scissorIndex,
2010 pScissor.offset.y, pScissor.extent.height, validation_error_map[VALIDATION_ERROR_1d8004aa]);
2011 }
2012 }
2013 return skip;
2014}
2015
Petr Kraus299ba622017-11-24 03:09:03 +01002016bool pv_vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
2017 bool skip = false;
2018 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2019 debug_report_data *report_data = device_data->report_data;
2020
2021 if (!device_data->physical_device_features.wideLines && (lineWidth != 1.0f)) {
2022 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2023 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d600628, LayerName,
2024 "VkPhysicalDeviceFeatures::wideLines is disabled, but lineWidth (=%f) is not 1.0. %s", lineWidth,
2025 validation_error_map[VALIDATION_ERROR_1d600628]);
2026 }
2027
2028 return skip;
2029}
2030
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002031bool pv_vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex,
2032 uint32_t firstInstance) {
2033 bool skip = false;
2034 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2035 if (vertexCount == 0) {
2036 // TODO: Verify against Valid Usage section. I don't see a non-zero vertexCount listed, may need to add that and make
2037 // this an error or leave as is.
2038 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2039 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t vertexCount, is 0");
2040 }
2041
2042 if (instanceCount == 0) {
2043 // TODO: Verify against Valid Usage section. I don't see a non-zero instanceCount listed, may need to add that and make
2044 // this an error or leave as is.
2045 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2046 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t instanceCount, is 0");
2047 }
2048 return skip;
2049}
2050
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002051bool pv_vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride) {
2052 bool skip = false;
2053 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2054
2055 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2056 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2057 __LINE__, DEVICE_FEATURE, LayerName,
2058 "CmdDrawIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2059 }
2060 return skip;
2061}
2062
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002063bool pv_vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count,
2064 uint32_t stride) {
2065 bool skip = false;
2066 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2067 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2068 skip |=
2069 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2070 DEVICE_FEATURE, LayerName,
2071 "CmdDrawIndexedIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2072 }
2073 return skip;
2074}
2075
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002076bool pv_vkCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2077 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy *pRegions) {
2078 bool skip = false;
2079 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2080
2081 if (pRegions != nullptr) {
2082 if ((pRegions->srcSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2083 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2084 skip |= log_msg(
2085 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2086 VALIDATION_ERROR_0a600c01, LayerName,
2087 "vkCmdCopyImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator. %s",
2088 validation_error_map[VALIDATION_ERROR_0a600c01]);
2089 }
2090 if ((pRegions->dstSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2091 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2092 skip |= log_msg(
2093 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2094 VALIDATION_ERROR_0a600c01, LayerName,
2095 "vkCmdCopyImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator. %s",
2096 validation_error_map[VALIDATION_ERROR_0a600c01]);
2097 }
2098 }
2099 return skip;
2100}
2101
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002102bool pv_vkCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2103 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
2104 bool skip = false;
2105 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2106
2107 if (pRegions != nullptr) {
2108 if ((pRegions->srcSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2109 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2110 skip |= log_msg(
2111 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2112 UNRECOGNIZED_VALUE, LayerName,
2113 "vkCmdBlitImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator");
2114 }
2115 if ((pRegions->dstSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2116 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2117 skip |= log_msg(
2118 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2119 UNRECOGNIZED_VALUE, LayerName,
2120 "vkCmdBlitImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator");
2121 }
2122 }
2123 return skip;
2124}
2125
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002126bool pv_vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout,
2127 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2128 bool skip = false;
2129 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2130
2131 if (pRegions != nullptr) {
2132 if ((pRegions->imageSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2133 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2134 skip |= log_msg(
2135 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2136 UNRECOGNIZED_VALUE, LayerName,
2137 "vkCmdCopyBufferToImage() parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an unrecognized "
2138 "enumerator");
2139 }
2140 }
2141 return skip;
2142}
2143
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002144bool pv_vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer,
2145 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2146 bool skip = false;
2147 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2148
2149 if (pRegions != nullptr) {
2150 if ((pRegions->imageSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2151 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2152 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2153 UNRECOGNIZED_VALUE, LayerName,
2154 "vkCmdCopyImageToBuffer parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an unrecognized "
2155 "enumerator");
2156 }
2157 }
2158 return skip;
2159}
2160
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002161bool pv_vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize,
2162 const void *pData) {
2163 bool skip = false;
2164 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2165
2166 if (dstOffset & 3) {
2167 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2168 __LINE__, VALIDATION_ERROR_1e400048, LayerName,
2169 "vkCmdUpdateBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2170 dstOffset, validation_error_map[VALIDATION_ERROR_1e400048]);
2171 }
2172
2173 if ((dataSize <= 0) || (dataSize > 65536)) {
2174 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2175 __LINE__, VALIDATION_ERROR_1e40004a, LayerName,
2176 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64
2177 "), must be greater than zero and less than or equal to 65536. %s",
2178 dataSize, validation_error_map[VALIDATION_ERROR_1e40004a]);
2179 } else if (dataSize & 3) {
2180 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2181 __LINE__, VALIDATION_ERROR_1e40004c, LayerName,
2182 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2183 dataSize, validation_error_map[VALIDATION_ERROR_1e40004c]);
2184 }
2185 return skip;
2186}
2187
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002188bool pv_vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size,
2189 uint32_t data) {
2190 bool skip = false;
2191 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2192
2193 if (dstOffset & 3) {
2194 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2195 __LINE__, VALIDATION_ERROR_1b400032, LayerName,
2196 "vkCmdFillBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2197 dstOffset, validation_error_map[VALIDATION_ERROR_1b400032]);
2198 }
2199
2200 if (size != VK_WHOLE_SIZE) {
2201 if (size <= 0) {
2202 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2203 __LINE__, VALIDATION_ERROR_1b400034, LayerName,
2204 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), must be greater than zero. %s",
2205 size, validation_error_map[VALIDATION_ERROR_1b400034]);
2206 } else if (size & 3) {
2207 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2208 __LINE__, VALIDATION_ERROR_1b400038, LayerName,
2209 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), is not a multiple of 4. %s", size,
2210 validation_error_map[VALIDATION_ERROR_1b400038]);
2211 }
2212 }
2213 return skip;
2214}
2215
2216VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
2217 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2218}
2219
2220VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
2221 VkLayerProperties *pProperties) {
2222 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2223}
2224
2225VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
2226 VkExtensionProperties *pProperties) {
2227 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2228 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
2229
2230 return VK_ERROR_LAYER_NOT_PRESENT;
2231}
2232
2233VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
2234 uint32_t *pPropertyCount, VkExtensionProperties *pProperties) {
2235 // Parameter_validation does not have any physical device extensions
2236 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2237 return util_GetExtensionProperties(0, NULL, pPropertyCount, pProperties);
2238
2239 instance_layer_data *local_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map);
2240 bool skip =
2241 validate_array(local_data->report_data, "vkEnumerateDeviceExtensionProperties", "pPropertyCount", "pProperties",
2242 pPropertyCount, pProperties, true, false, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_2761f401);
2243 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
2244
2245 return local_data->dispatch_table.EnumerateDeviceExtensionProperties(physicalDevice, NULL, pPropertyCount, pProperties);
2246}
2247
2248static bool require_device_extension(layer_data *device_data, bool flag, char const *function_name, char const *extension_name) {
2249 if (!flag) {
2250 return log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2251 __LINE__, EXTENSION_NOT_ENABLED, LayerName,
2252 "%s() called even though the %s extension was not enabled for this VkDevice.", function_name,
2253 extension_name);
2254 }
2255
2256 return false;
2257}
2258
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002259bool pv_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator,
2260 VkSwapchainKHR *pSwapchain) {
2261 bool skip = false;
2262 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2263 debug_report_data *report_data = device_data->report_data;
2264
2265 if (pCreateInfo != nullptr) {
2266 if ((device_data->physical_device_features.textureCompressionETC2 == false) &&
2267 FormatIsCompressed_ETC2_EAC(pCreateInfo->imageFormat)) {
2268 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2269 DEVICE_FEATURE, LayerName,
2270 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2271 "textureCompressionETC2 feature is not enabled: neither ETC2 nor EAC formats can be used to create "
2272 "images.",
2273 string_VkFormat(pCreateInfo->imageFormat));
2274 }
2275
2276 if ((device_data->physical_device_features.textureCompressionASTC_LDR == false) &&
2277 FormatIsCompressed_ASTC_LDR(pCreateInfo->imageFormat)) {
2278 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2279 DEVICE_FEATURE, LayerName,
2280 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2281 "textureCompressionASTC_LDR feature is not enabled: ASTC formats cannot be used to create images.",
2282 string_VkFormat(pCreateInfo->imageFormat));
2283 }
2284
2285 if ((device_data->physical_device_features.textureCompressionBC == false) &&
2286 FormatIsCompressed_BC(pCreateInfo->imageFormat)) {
2287 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2288 DEVICE_FEATURE, LayerName,
2289 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2290 "textureCompressionBC feature is not enabled: BC compressed formats cannot be used to create images.",
2291 string_VkFormat(pCreateInfo->imageFormat));
2292 }
2293
2294 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2295 if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) {
2296 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
2297 if (pCreateInfo->queueFamilyIndexCount <= 1) {
2298 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2299 VALIDATION_ERROR_146009fc, LayerName,
2300 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2301 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
2302 validation_error_map[VALIDATION_ERROR_146009fc]);
2303 }
2304
2305 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
2306 // queueFamilyIndexCount uint32_t values
2307 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
2308 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2309 VALIDATION_ERROR_146009fa, LayerName,
2310 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2311 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
2312 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
2313 validation_error_map[VALIDATION_ERROR_146009fa]);
2314 } else {
2315 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
2316 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
2317 "vkCreateSwapchainKHR", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE,
2318 INVALID_USAGE, false, "", "");
2319 }
2320 }
2321
2322 // imageArrayLayers must be greater than 0
2323 skip |= ValidateGreaterThan(report_data, "vkCreateSwapchainKHR", "pCreateInfo->imageArrayLayers",
2324 pCreateInfo->imageArrayLayers, 0u);
2325 }
2326
2327 return skip;
2328}
2329
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002330bool pv_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
2331 bool skip = false;
2332 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
2333
2334 if (pPresentInfo && pPresentInfo->pNext) {
John Zulaufde972ac2017-10-26 12:07:05 -06002335 const auto *present_regions = lvl_find_in_chain<VkPresentRegionsKHR>(pPresentInfo->pNext);
2336 if (present_regions) {
2337 // TODO: This and all other pNext extension dependencies should be added to code-generation
2338 skip |= require_device_extension(device_data, device_data->extensions.vk_khr_incremental_present, "vkQueuePresentKHR",
2339 VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME);
2340 if (present_regions->swapchainCount != pPresentInfo->swapchainCount) {
2341 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2342 __LINE__, INVALID_USAGE, LayerName,
2343 "QueuePresentKHR(): pPresentInfo->swapchainCount has a value of %i"
2344 " but VkPresentRegionsKHR extension swapchainCount is %i. These values must be equal.",
2345 pPresentInfo->swapchainCount, present_regions->swapchainCount);
2346 }
2347 skip |= validate_struct_pnext(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pNext", NULL,
2348 present_regions->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_1121c40d);
2349 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->swapchainCount",
2350 "pCreateInfo->pNext->pRegions", present_regions->swapchainCount, present_regions->pRegions, true,
2351 false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2352 for (uint32_t i = 0; i < present_regions->swapchainCount; ++i) {
2353 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pRegions[].rectangleCount",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002354 "pCreateInfo->pNext->pRegions[].pRectangles", present_regions->pRegions[i].rectangleCount,
2355 present_regions->pRegions[i].pRectangles, true, false, VALIDATION_ERROR_UNDEFINED,
2356 VALIDATION_ERROR_UNDEFINED);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002357 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002358 }
2359 }
2360
2361 return skip;
2362}
2363
2364#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002365bool pv_vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
2366 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
2367 auto device_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2368 bool skip = false;
2369
2370 if (pCreateInfo->hwnd == nullptr) {
2371 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2372 __LINE__, VALIDATION_ERROR_15a00a38, LayerName,
2373 "vkCreateWin32SurfaceKHR(): hwnd must be a valid Win32 HWND but hwnd is NULL. %s",
2374 validation_error_map[VALIDATION_ERROR_15a00a38]);
2375 }
2376
2377 return skip;
2378}
2379#endif // VK_USE_PLATFORM_WIN32_KHR
2380
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002381bool pv_vkDebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
2382 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2383 if (pNameInfo->pObjectName) {
2384 device_data->report_data->debugObjectNameMap->insert(
2385 std::make_pair<uint64_t, std::string>((uint64_t &&) pNameInfo->object, pNameInfo->pObjectName));
2386 } else {
2387 device_data->report_data->debugObjectNameMap->erase(pNameInfo->object);
2388 }
2389 return false;
2390}
2391
Petr Krausc8655be2017-09-27 18:56:51 +02002392bool pv_vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2393 const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool) {
2394 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2395 bool skip = false;
2396
2397 if (pCreateInfo) {
2398 if (pCreateInfo->maxSets <= 0) {
2399 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2400 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_0480025a,
2401 LayerName, "vkCreateDescriptorPool(): pCreateInfo->maxSets is not greater than 0. %s",
2402 validation_error_map[VALIDATION_ERROR_0480025a]);
2403 }
2404
2405 if (pCreateInfo->pPoolSizes) {
2406 for (uint32_t i = 0; i < pCreateInfo->poolSizeCount; ++i) {
2407 if (pCreateInfo->pPoolSizes[i].descriptorCount <= 0) {
2408 skip |= log_msg(
2409 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT,
2410 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_04a0025c, LayerName,
2411 "vkCreateDescriptorPool(): pCreateInfo->pPoolSizes[%" PRIu32 "].descriptorCount is not greater than 0. %s",
2412 i, validation_error_map[VALIDATION_ERROR_04a0025c]);
2413 }
2414 }
2415 }
2416 }
2417
2418 return skip;
2419}
2420
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002421VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *funcName) {
2422 const auto item = name_to_funcptr_map.find(funcName);
2423 if (item != name_to_funcptr_map.end()) {
2424 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2425 }
2426
2427 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2428 const auto &table = device_data->dispatch_table;
2429 if (!table.GetDeviceProcAddr) return nullptr;
2430 return table.GetDeviceProcAddr(device, funcName);
2431}
2432
2433VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2434 const auto item = name_to_funcptr_map.find(funcName);
2435 if (item != name_to_funcptr_map.end()) {
2436 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2437 }
2438
2439 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2440 auto &table = instance_data->dispatch_table;
2441 if (!table.GetInstanceProcAddr) return nullptr;
2442 return table.GetInstanceProcAddr(instance, funcName);
2443}
2444
2445VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
2446 assert(instance);
2447 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2448
2449 if (!instance_data->dispatch_table.GetPhysicalDeviceProcAddr) return nullptr;
2450 return instance_data->dispatch_table.GetPhysicalDeviceProcAddr(instance, funcName);
2451}
2452
2453// If additional validation is needed outside of the generated checks, a manual routine can be added to this file
2454// 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 +02002455void InitializeManualParameterValidationFunctionPointers() {
Mark Lobodzinski78a12a92017-08-08 14:16:51 -06002456 custom_functions["vkGetDeviceQueue"] = (void*)pv_vkGetDeviceQueue;
2457 custom_functions["vkCreateBuffer"] = (void*)pv_vkCreateBuffer;
2458 custom_functions["vkCreateImage"] = (void*)pv_vkCreateImage;
2459 custom_functions["vkCreateImageView"] = (void*)pv_vkCreateImageView;
2460 custom_functions["vkCreateGraphicsPipelines"] = (void*)pv_vkCreateGraphicsPipelines;
2461 custom_functions["vkCreateComputePipelines"] = (void*)pv_vkCreateComputePipelines;
2462 custom_functions["vkCreateSampler"] = (void*)pv_vkCreateSampler;
2463 custom_functions["vkCreateDescriptorSetLayout"] = (void*)pv_vkCreateDescriptorSetLayout;
2464 custom_functions["vkFreeDescriptorSets"] = (void*)pv_vkFreeDescriptorSets;
2465 custom_functions["vkUpdateDescriptorSets"] = (void*)pv_vkUpdateDescriptorSets;
2466 custom_functions["vkCreateRenderPass"] = (void*)pv_vkCreateRenderPass;
2467 custom_functions["vkBeginCommandBuffer"] = (void*)pv_vkBeginCommandBuffer;
2468 custom_functions["vkCmdSetViewport"] = (void*)pv_vkCmdSetViewport;
2469 custom_functions["vkCmdSetScissor"] = (void*)pv_vkCmdSetScissor;
Petr Kraus299ba622017-11-24 03:09:03 +01002470 custom_functions["vkCmdSetLineWidth"] = (void *)pv_vkCmdSetLineWidth;
Mark Lobodzinski78a12a92017-08-08 14:16:51 -06002471 custom_functions["vkCmdDraw"] = (void*)pv_vkCmdDraw;
2472 custom_functions["vkCmdDrawIndirect"] = (void*)pv_vkCmdDrawIndirect;
2473 custom_functions["vkCmdDrawIndexedIndirect"] = (void*)pv_vkCmdDrawIndexedIndirect;
2474 custom_functions["vkCmdCopyImage"] = (void*)pv_vkCmdCopyImage;
2475 custom_functions["vkCmdBlitImage"] = (void*)pv_vkCmdBlitImage;
2476 custom_functions["vkCmdCopyBufferToImage"] = (void*)pv_vkCmdCopyBufferToImage;
2477 custom_functions["vkCmdCopyImageToBuffer"] = (void*)pv_vkCmdCopyImageToBuffer;
2478 custom_functions["vkCmdUpdateBuffer"] = (void*)pv_vkCmdUpdateBuffer;
2479 custom_functions["vkCmdFillBuffer"] = (void*)pv_vkCmdFillBuffer;
2480 custom_functions["vkCreateSwapchainKHR"] = (void*)pv_vkCreateSwapchainKHR;
2481 custom_functions["vkQueuePresentKHR"] = (void*)pv_vkQueuePresentKHR;
Petr Krausc8655be2017-09-27 18:56:51 +02002482 custom_functions["vkCreateDescriptorPool"] = (void*)pv_vkCreateDescriptorPool;
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002483}
2484
2485} // namespace parameter_validation
2486
2487VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
2488 VkExtensionProperties *pProperties) {
2489 return parameter_validation::vkEnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties);
2490}
2491
2492VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount,
2493 VkLayerProperties *pProperties) {
2494 return parameter_validation::vkEnumerateInstanceLayerProperties(pCount, pProperties);
2495}
2496
2497VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
2498 VkLayerProperties *pProperties) {
2499 // the layer command handles VK_NULL_HANDLE just fine internally
2500 assert(physicalDevice == VK_NULL_HANDLE);
2501 return parameter_validation::vkEnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties);
2502}
2503
2504VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
2505 const char *pLayerName, uint32_t *pCount,
2506 VkExtensionProperties *pProperties) {
2507 // the layer command handles VK_NULL_HANDLE just fine internally
2508 assert(physicalDevice == VK_NULL_HANDLE);
2509 return parameter_validation::vkEnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties);
2510}
2511
2512VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
2513 return parameter_validation::vkGetDeviceProcAddr(dev, funcName);
2514}
2515
2516VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2517 return parameter_validation::vkGetInstanceProcAddr(instance, funcName);
2518}
2519
2520VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
2521 const char *funcName) {
2522 return parameter_validation::vkGetPhysicalDeviceProcAddr(instance, funcName);
2523}
2524
2525VK_LAYER_EXPORT bool pv_vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) {
2526 assert(pVersionStruct != NULL);
2527 assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT);
2528
2529 // Fill in the function pointers if our version is at least capable of having the structure contain them.
2530 if (pVersionStruct->loaderLayerInterfaceVersion >= 2) {
2531 pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr;
2532 pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr;
2533 pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr;
2534 }
2535
2536 if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
2537 parameter_validation::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion;
2538 } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
2539 pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
2540 }
2541
2542 return VK_SUCCESS;
2543}