blob: 7617826ee89d6573ce5d8f80235f54f22e967fd3 [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 |=
Mike Schuchardt52c3ce22017-12-13 09:45:36 -0700590 ValidateGreaterThan(report_data, "vkCreateBuffer", "pCreateInfo->size", pCreateInfo->size, static_cast<VkDeviceSize>(0));
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600591
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,
Petr Krausf62dd8f2017-11-23 15:47:38 +01001103 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Petr Krausa6103552017-11-16 21:21:58 +01001104 "].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,
Petr Krausf62dd8f2017-11-23 15:47:38 +01001119 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Petr Krausa6103552017-11-16 21:21:58 +01001120 "].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
Petr Krausf62dd8f2017-11-23 15:47:38 +01001149 "].pViewportState->pViewports (=NULL) is an invalid pointer. %s",
Petr Krausa6103552017-11-16 21:21:58 +01001150 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
Petr Krausf62dd8f2017-11-23 15:47:38 +01001159 "].pViewportState->pScissors (=NULL) is an invalid pointer. %s",
Petr Krausa6103552017-11-16 21:21:58 +01001160 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 {
Mike Schuchardt97662b02017-12-06 13:31:29 -07001173 const VkStructureType valid_next_stypes[] = {
John Zulauf96b0e422017-11-14 11:43:19 -07001174 LvlTypeMap<VkPipelineCoverageModulationStateCreateInfoNV>::kSType,
1175 LvlTypeMap<VkPipelineCoverageToColorStateCreateInfoNV>::kSType,
1176 LvlTypeMap<VkPipelineSampleLocationsStateCreateInfoEXT>::kSType};
Mike Schuchardt97662b02017-12-06 13:31:29 -07001177 const char *valid_struct_names =
John Zulauf96b0e422017-11-14 11:43:19 -07001178 "VkPipelineCoverageModulationStateCreateInfoNV, "
1179 "VkPipelineCoverageToColorStateCreateInfoNV, "
1180 "VkPipelineSampleLocationsStateCreateInfoEXT";
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001181 skip |= validate_struct_pnext(
1182 report_data, "vkCreateGraphicsPipelines",
John Zulauf96b0e422017-11-14 11:43:19 -07001183 ParameterName("pCreateInfos[%i].pMultisampleState->pNext", ParameterName::IndexVector{i}),
1184 valid_struct_names, pCreateInfos[i].pMultisampleState->pNext, 3, valid_next_stypes, GeneratedHeaderVersion,
1185 VALIDATION_ERROR_1001c40d);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001186
1187 skip |= validate_reserved_flags(
1188 report_data, "vkCreateGraphicsPipelines",
1189 ParameterName("pCreateInfos[%i].pMultisampleState->flags", ParameterName::IndexVector{i}),
1190 pCreateInfos[i].pMultisampleState->flags, VALIDATION_ERROR_10009005);
1191
1192 skip |= validate_bool32(
1193 report_data, "vkCreateGraphicsPipelines",
1194 ParameterName("pCreateInfos[%i].pMultisampleState->sampleShadingEnable", ParameterName::IndexVector{i}),
1195 pCreateInfos[i].pMultisampleState->sampleShadingEnable);
1196
1197 skip |= validate_array(
1198 report_data, "vkCreateGraphicsPipelines",
1199 ParameterName("pCreateInfos[%i].pMultisampleState->rasterizationSamples", ParameterName::IndexVector{i}),
1200 ParameterName("pCreateInfos[%i].pMultisampleState->pSampleMask", ParameterName::IndexVector{i}),
1201 pCreateInfos[i].pMultisampleState->rasterizationSamples, pCreateInfos[i].pMultisampleState->pSampleMask,
1202 true, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1203
1204 skip |= validate_bool32(
1205 report_data, "vkCreateGraphicsPipelines",
1206 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToCoverageEnable", ParameterName::IndexVector{i}),
1207 pCreateInfos[i].pMultisampleState->alphaToCoverageEnable);
1208
1209 skip |= validate_bool32(
1210 report_data, "vkCreateGraphicsPipelines",
1211 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToOneEnable", ParameterName::IndexVector{i}),
1212 pCreateInfos[i].pMultisampleState->alphaToOneEnable);
1213
1214 if (pCreateInfos[i].pMultisampleState->sType != VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO) {
1215 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1216 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1217 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pMultisampleState->sType must be "
1218 "VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO",
1219 i);
1220 }
John Zulauf7acac592017-11-06 11:15:53 -07001221 if (pCreateInfos[i].pMultisampleState->sampleShadingEnable == VK_TRUE) {
1222 if (!device_data->physical_device_features.sampleRateShading) {
1223 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1224 __LINE__, VALIDATION_ERROR_10000620, LayerName,
1225 "vkCreateGraphicsPipelines(): parameter "
1226 "pCreateInfos[%d].pMultisampleState->sampleShadingEnable: %s",
1227 i, validation_error_map[VALIDATION_ERROR_10000620]);
1228 }
1229 // TODO Add documentation issue about when minSampleShading must be in range and when it is ignored
1230 // For now a "least noise" test *only* when sampleShadingEnable is VK_TRUE.
1231 if (!in_inclusive_range(pCreateInfos[i].pMultisampleState->minSampleShading, 0.F, 1.0F)) {
1232 skip |= log_msg(
1233 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1234 VALIDATION_ERROR_10000624, LayerName,
1235 "vkCreateGraphicsPipelines(): parameter pCreateInfos[%d].pMultisampleState->minSampleShading: %s",
1236 i, validation_error_map[VALIDATION_ERROR_10000624]);
1237 }
1238 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001239 }
1240
Mark Lobodzinski5cd08512017-09-12 09:50:25 -06001241 // TODO: Conditional NULL check based on subpass depth/stencil attachment
1242 if (pCreateInfos[i].pDepthStencilState != nullptr) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001243 skip |= validate_struct_pnext(
1244 report_data, "vkCreateGraphicsPipelines",
1245 ParameterName("pCreateInfos[%i].pDepthStencilState->pNext", ParameterName::IndexVector{i}), NULL,
1246 pCreateInfos[i].pDepthStencilState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f61c40d);
1247
1248 skip |= validate_reserved_flags(
1249 report_data, "vkCreateGraphicsPipelines",
1250 ParameterName("pCreateInfos[%i].pDepthStencilState->flags", ParameterName::IndexVector{i}),
1251 pCreateInfos[i].pDepthStencilState->flags, VALIDATION_ERROR_0f609005);
1252
1253 skip |= validate_bool32(
1254 report_data, "vkCreateGraphicsPipelines",
1255 ParameterName("pCreateInfos[%i].pDepthStencilState->depthTestEnable", ParameterName::IndexVector{i}),
1256 pCreateInfos[i].pDepthStencilState->depthTestEnable);
1257
1258 skip |= validate_bool32(
1259 report_data, "vkCreateGraphicsPipelines",
1260 ParameterName("pCreateInfos[%i].pDepthStencilState->depthWriteEnable", ParameterName::IndexVector{i}),
1261 pCreateInfos[i].pDepthStencilState->depthWriteEnable);
1262
1263 skip |= validate_ranged_enum(
1264 report_data, "vkCreateGraphicsPipelines",
1265 ParameterName("pCreateInfos[%i].pDepthStencilState->depthCompareOp", ParameterName::IndexVector{i}),
1266 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->depthCompareOp,
1267 VALIDATION_ERROR_0f604001);
1268
1269 skip |= validate_bool32(
1270 report_data, "vkCreateGraphicsPipelines",
1271 ParameterName("pCreateInfos[%i].pDepthStencilState->depthBoundsTestEnable", ParameterName::IndexVector{i}),
1272 pCreateInfos[i].pDepthStencilState->depthBoundsTestEnable);
1273
1274 skip |= validate_bool32(
1275 report_data, "vkCreateGraphicsPipelines",
1276 ParameterName("pCreateInfos[%i].pDepthStencilState->stencilTestEnable", ParameterName::IndexVector{i}),
1277 pCreateInfos[i].pDepthStencilState->stencilTestEnable);
1278
1279 skip |= validate_ranged_enum(
1280 report_data, "vkCreateGraphicsPipelines",
1281 ParameterName("pCreateInfos[%i].pDepthStencilState->front.failOp", ParameterName::IndexVector{i}),
1282 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.failOp,
1283 VALIDATION_ERROR_13a08601);
1284
1285 skip |= validate_ranged_enum(
1286 report_data, "vkCreateGraphicsPipelines",
1287 ParameterName("pCreateInfos[%i].pDepthStencilState->front.passOp", ParameterName::IndexVector{i}),
1288 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.passOp,
1289 VALIDATION_ERROR_13a27801);
1290
1291 skip |= validate_ranged_enum(
1292 report_data, "vkCreateGraphicsPipelines",
1293 ParameterName("pCreateInfos[%i].pDepthStencilState->front.depthFailOp", ParameterName::IndexVector{i}),
1294 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.depthFailOp,
1295 VALIDATION_ERROR_13a04201);
1296
1297 skip |= validate_ranged_enum(
1298 report_data, "vkCreateGraphicsPipelines",
1299 ParameterName("pCreateInfos[%i].pDepthStencilState->front.compareOp", ParameterName::IndexVector{i}),
1300 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->front.compareOp,
1301 VALIDATION_ERROR_0f604001);
1302
1303 skip |= validate_ranged_enum(
1304 report_data, "vkCreateGraphicsPipelines",
1305 ParameterName("pCreateInfos[%i].pDepthStencilState->back.failOp", ParameterName::IndexVector{i}),
1306 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.failOp,
1307 VALIDATION_ERROR_13a08601);
1308
1309 skip |= validate_ranged_enum(
1310 report_data, "vkCreateGraphicsPipelines",
1311 ParameterName("pCreateInfos[%i].pDepthStencilState->back.passOp", ParameterName::IndexVector{i}),
1312 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.passOp,
1313 VALIDATION_ERROR_13a27801);
1314
1315 skip |= validate_ranged_enum(
1316 report_data, "vkCreateGraphicsPipelines",
1317 ParameterName("pCreateInfos[%i].pDepthStencilState->back.depthFailOp", ParameterName::IndexVector{i}),
1318 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.depthFailOp,
1319 VALIDATION_ERROR_13a04201);
1320
1321 skip |= validate_ranged_enum(
1322 report_data, "vkCreateGraphicsPipelines",
1323 ParameterName("pCreateInfos[%i].pDepthStencilState->back.compareOp", ParameterName::IndexVector{i}),
1324 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->back.compareOp,
1325 VALIDATION_ERROR_0f604001);
1326
1327 if (pCreateInfos[i].pDepthStencilState->sType != VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO) {
1328 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1329 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1330 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pDepthStencilState->sType must be "
1331 "VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO",
1332 i);
1333 }
1334 }
1335
Mark Lobodzinski5cd08512017-09-12 09:50:25 -06001336 // TODO: Conditional NULL check based on subpass color attachment
1337 if (pCreateInfos[i].pColorBlendState != nullptr) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001338 skip |= validate_struct_pnext(
1339 report_data, "vkCreateGraphicsPipelines",
1340 ParameterName("pCreateInfos[%i].pColorBlendState->pNext", ParameterName::IndexVector{i}), NULL,
1341 pCreateInfos[i].pColorBlendState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f41c40d);
1342
1343 skip |= validate_reserved_flags(
1344 report_data, "vkCreateGraphicsPipelines",
1345 ParameterName("pCreateInfos[%i].pColorBlendState->flags", ParameterName::IndexVector{i}),
1346 pCreateInfos[i].pColorBlendState->flags, VALIDATION_ERROR_0f409005);
1347
1348 skip |= validate_bool32(
1349 report_data, "vkCreateGraphicsPipelines",
1350 ParameterName("pCreateInfos[%i].pColorBlendState->logicOpEnable", ParameterName::IndexVector{i}),
1351 pCreateInfos[i].pColorBlendState->logicOpEnable);
1352
1353 skip |= validate_array(
1354 report_data, "vkCreateGraphicsPipelines",
1355 ParameterName("pCreateInfos[%i].pColorBlendState->attachmentCount", ParameterName::IndexVector{i}),
1356 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments", ParameterName::IndexVector{i}),
1357 pCreateInfos[i].pColorBlendState->attachmentCount, pCreateInfos[i].pColorBlendState->pAttachments, false,
1358 true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1359
1360 if (pCreateInfos[i].pColorBlendState->pAttachments != NULL) {
1361 for (uint32_t attachmentIndex = 0; attachmentIndex < pCreateInfos[i].pColorBlendState->attachmentCount;
1362 ++attachmentIndex) {
1363 skip |= validate_bool32(report_data, "vkCreateGraphicsPipelines",
1364 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].blendEnable",
1365 ParameterName::IndexVector{i, attachmentIndex}),
1366 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].blendEnable);
1367
1368 skip |= validate_ranged_enum(
1369 report_data, "vkCreateGraphicsPipelines",
1370 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcColorBlendFactor",
1371 ParameterName::IndexVector{i, attachmentIndex}),
1372 "VkBlendFactor", AllVkBlendFactorEnums,
1373 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcColorBlendFactor,
1374 VALIDATION_ERROR_0f22cc01);
1375
1376 skip |= validate_ranged_enum(
1377 report_data, "vkCreateGraphicsPipelines",
1378 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstColorBlendFactor",
1379 ParameterName::IndexVector{i, attachmentIndex}),
1380 "VkBlendFactor", AllVkBlendFactorEnums,
1381 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstColorBlendFactor,
1382 VALIDATION_ERROR_0f207001);
1383
1384 skip |= validate_ranged_enum(
1385 report_data, "vkCreateGraphicsPipelines",
1386 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorBlendOp",
1387 ParameterName::IndexVector{i, attachmentIndex}),
1388 "VkBlendOp", AllVkBlendOpEnums,
1389 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorBlendOp,
1390 VALIDATION_ERROR_0f202001);
1391
1392 skip |= validate_ranged_enum(
1393 report_data, "vkCreateGraphicsPipelines",
1394 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcAlphaBlendFactor",
1395 ParameterName::IndexVector{i, attachmentIndex}),
1396 "VkBlendFactor", AllVkBlendFactorEnums,
1397 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcAlphaBlendFactor,
1398 VALIDATION_ERROR_0f22c601);
1399
1400 skip |= validate_ranged_enum(
1401 report_data, "vkCreateGraphicsPipelines",
1402 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstAlphaBlendFactor",
1403 ParameterName::IndexVector{i, attachmentIndex}),
1404 "VkBlendFactor", AllVkBlendFactorEnums,
1405 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstAlphaBlendFactor,
1406 VALIDATION_ERROR_0f206a01);
1407
1408 skip |= validate_ranged_enum(
1409 report_data, "vkCreateGraphicsPipelines",
1410 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].alphaBlendOp",
1411 ParameterName::IndexVector{i, attachmentIndex}),
1412 "VkBlendOp", AllVkBlendOpEnums,
1413 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].alphaBlendOp,
1414 VALIDATION_ERROR_0f200801);
1415
1416 skip |=
1417 validate_flags(report_data, "vkCreateGraphicsPipelines",
1418 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorWriteMask",
1419 ParameterName::IndexVector{i, attachmentIndex}),
1420 "VkColorComponentFlagBits", AllVkColorComponentFlagBits,
1421 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorWriteMask,
1422 false, false, VALIDATION_ERROR_0f202201);
1423 }
1424 }
1425
1426 if (pCreateInfos[i].pColorBlendState->sType != VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO) {
1427 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1428 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1429 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pColorBlendState->sType must be "
1430 "VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO",
1431 i);
1432 }
1433
1434 // If logicOpEnable is VK_TRUE, logicOp must be a valid VkLogicOp value
1435 if (pCreateInfos[i].pColorBlendState->logicOpEnable == VK_TRUE) {
1436 skip |= validate_ranged_enum(
1437 report_data, "vkCreateGraphicsPipelines",
1438 ParameterName("pCreateInfos[%i].pColorBlendState->logicOp", ParameterName::IndexVector{i}), "VkLogicOp",
1439 AllVkLogicOpEnums, pCreateInfos[i].pColorBlendState->logicOp, VALIDATION_ERROR_0f4004be);
1440 }
1441 }
1442 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001443
Petr Kraus9752aae2017-11-24 03:05:50 +01001444 if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT) {
1445 if (pCreateInfos[i].basePipelineIndex != -1) {
1446 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001447 skip |= log_msg(
1448 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1449 VALIDATION_ERROR_096005a8, LayerName,
1450 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineHandle, must be VK_NULL_HANDLE if "
1451 "pCreateInfos->flags "
1452 "contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag and pCreateInfos->basePipelineIndex is not -1. %s",
1453 validation_error_map[VALIDATION_ERROR_096005a8]);
1454 }
1455 }
1456
Petr Kraus9752aae2017-11-24 03:05:50 +01001457 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
1458 if (pCreateInfos[i].basePipelineIndex != -1) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001459 skip |= log_msg(
1460 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1461 VALIDATION_ERROR_096005aa, LayerName,
1462 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineIndex, must be -1 if "
1463 "pCreateInfos->flags "
1464 "contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag and pCreateInfos->basePipelineHandle is not "
1465 "VK_NULL_HANDLE. %s",
1466 validation_error_map[VALIDATION_ERROR_096005aa]);
1467 }
1468 }
1469 }
1470
Petr Kraus9752aae2017-11-24 03:05:50 +01001471 if (pCreateInfos[i].pRasterizationState) {
1472 if ((pCreateInfos[i].pRasterizationState->polygonMode != VK_POLYGON_MODE_FILL) &&
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001473 (device_data->physical_device_features.fillModeNonSolid == false)) {
1474 skip |= log_msg(
1475 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1476 DEVICE_FEATURE, LayerName,
1477 "vkCreateGraphicsPipelines parameter, VkPolygonMode pCreateInfos->pRasterizationState->polygonMode cannot "
1478 "be "
1479 "VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE if VkPhysicalDeviceFeatures->fillModeNonSolid is false.");
1480 }
Petr Kraus299ba622017-11-24 03:09:03 +01001481
1482 if (!has_dynamic_line_width && !device_data->physical_device_features.wideLines &&
1483 (pCreateInfos[i].pRasterizationState->lineWidth != 1.0f)) {
1484 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1485 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, 0, __LINE__, VALIDATION_ERROR_096005da, LayerName,
1486 "The line width state is static (pCreateInfos[%" PRIu32
1487 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_LINE_WIDTH) and "
1488 "VkPhysicalDeviceFeatures::wideLines is disabled, but pCreateInfos[%" PRIu32
1489 "].pRasterizationState->lineWidth (=%f) is not 1.0. %s",
1490 i, i, pCreateInfos[i].pRasterizationState->lineWidth,
1491 validation_error_map[VALIDATION_ERROR_096005da]);
1492 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001493 }
1494
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001495 for (size_t j = 0; j < pCreateInfos[i].stageCount; j++) {
1496 skip |= validate_string(device_data->report_data, "vkCreateGraphicsPipelines",
1497 ParameterName("pCreateInfos[%i].pStages[%i].pName", ParameterName::IndexVector{i, j}),
1498 pCreateInfos[i].pStages[j].pName);
1499 }
1500 }
1501 }
1502
1503 return skip;
1504}
1505
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001506bool pv_vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1507 const VkComputePipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1508 VkPipeline *pPipelines) {
1509 bool skip = false;
1510 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1511
1512 for (uint32_t i = 0; i < createInfoCount; i++) {
1513 skip |= validate_string(device_data->report_data, "vkCreateComputePipelines",
1514 ParameterName("pCreateInfos[%i].stage.pName", ParameterName::IndexVector{i}),
1515 pCreateInfos[i].stage.pName);
1516 }
1517
1518 return skip;
1519}
1520
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001521bool pv_vkCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1522 VkSampler *pSampler) {
1523 bool skip = false;
1524 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1525 debug_report_data *report_data = device_data->report_data;
1526
1527 if (pCreateInfo != nullptr) {
John Zulauf71968502017-10-26 13:51:15 -06001528 const auto &features = device_data->physical_device_features;
1529 const auto &limits = device_data->device_limits;
1530 if (pCreateInfo->anisotropyEnable == VK_TRUE) {
1531 if (!in_inclusive_range(pCreateInfo->maxAnisotropy, 1.0F, limits.maxSamplerAnisotropy)) {
1532 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1533 VALIDATION_ERROR_1260085e, LayerName,
1534 "vkCreateSampler(): value of %s must be in range [1.0, %f] %s, but %f found. %s",
1535 "pCreateInfo->maxAnisotropy", limits.maxSamplerAnisotropy,
1536 "VkPhysicalDeviceLimits::maxSamplerAnistropy", pCreateInfo->maxAnisotropy,
1537 validation_error_map[VALIDATION_ERROR_1260085e]);
1538 }
1539
1540 // Anistropy cannot be enabled in sampler unless enabled as a feature
1541 if (features.samplerAnisotropy == VK_FALSE) {
1542 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1543 VALIDATION_ERROR_1260085c, LayerName,
1544 "vkCreateSampler(): Anisotropic sampling feature is not enabled, %s must be VK_FALSE. %s",
1545 "pCreateInfo->anisotropyEnable", validation_error_map[VALIDATION_ERROR_1260085c]);
1546 }
1547
1548 // Anistropy and unnormalized coordinates cannot be enabled simultaneously
1549 if (pCreateInfo->unnormalizedCoordinates == VK_TRUE) {
1550 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1551 VALIDATION_ERROR_12600868, LayerName,
1552 "vkCreateSampler(): pCreateInfo->anisotropyEnable and pCreateInfo->unnormalizedCoordinates "
1553 "must not both be VK_TRUE. %s",
1554 validation_error_map[VALIDATION_ERROR_12600868]);
1555 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001556 }
1557
1558 // If compareEnable is VK_TRUE, compareOp must be a valid VkCompareOp value
1559 if (pCreateInfo->compareEnable == VK_TRUE) {
1560 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->compareOp", "VkCompareOp",
1561 AllVkCompareOpEnums, pCreateInfo->compareOp, VALIDATION_ERROR_12600870);
1562 }
1563
1564 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, borderColor must be a
1565 // valid VkBorderColor value
1566 if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
1567 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
1568 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)) {
1569 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->borderColor", "VkBorderColor",
1570 AllVkBorderColorEnums, pCreateInfo->borderColor, VALIDATION_ERROR_1260086c);
1571 }
1572
1573 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, the
1574 // VK_KHR_sampler_mirror_clamp_to_edge extension must be enabled
1575 if (!device_data->extensions.vk_khr_sampler_mirror_clamp_to_edge &&
1576 ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
1577 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
1578 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE))) {
1579 skip |=
1580 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1581 VALIDATION_ERROR_1260086e, LayerName,
1582 "vkCreateSampler(): A VkSamplerAddressMode value is set to VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE "
1583 "but the VK_KHR_sampler_mirror_clamp_to_edge extension has not been enabled. %s",
1584 validation_error_map[VALIDATION_ERROR_1260086e]);
1585 }
John Zulauf275805c2017-10-26 15:34:49 -06001586
1587 // Checks for the IMG cubic filtering extension
1588 if (device_data->extensions.vk_img_filter_cubic) {
1589 if ((pCreateInfo->anisotropyEnable == VK_TRUE) &&
1590 ((pCreateInfo->minFilter == VK_FILTER_CUBIC_IMG) || (pCreateInfo->magFilter == VK_FILTER_CUBIC_IMG))) {
1591 skip |=
1592 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1593 VALIDATION_ERROR_12600872, LayerName,
1594 "vkCreateSampler(): Anisotropic sampling must not be VK_TRUE when either minFilter or magFilter are "
1595 "VK_FILTER_CUBIC_IMG. %s",
1596 validation_error_map[VALIDATION_ERROR_12600872]);
1597 }
1598 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001599 }
1600
1601 return skip;
1602}
1603
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001604bool pv_vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
1605 const VkAllocationCallbacks *pAllocator, VkDescriptorSetLayout *pSetLayout) {
1606 bool skip = false;
1607 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1608 debug_report_data *report_data = device_data->report_data;
1609
1610 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1611 if ((pCreateInfo != nullptr) && (pCreateInfo->pBindings != nullptr)) {
1612 for (uint32_t i = 0; i < pCreateInfo->bindingCount; ++i) {
1613 if (pCreateInfo->pBindings[i].descriptorCount != 0) {
1614 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER or VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and descriptorCount
1615 // is not 0 and pImmutableSamplers is not NULL, pImmutableSamplers must be a pointer to an array of descriptorCount
1616 // valid VkSampler handles
1617 if (((pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
1618 (pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)) &&
1619 (pCreateInfo->pBindings[i].pImmutableSamplers != nullptr)) {
1620 for (uint32_t descriptor_index = 0; descriptor_index < pCreateInfo->pBindings[i].descriptorCount;
1621 ++descriptor_index) {
1622 if (pCreateInfo->pBindings[i].pImmutableSamplers[descriptor_index] == VK_NULL_HANDLE) {
1623 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1624 __LINE__, REQUIRED_PARAMETER, LayerName,
1625 "vkCreateDescriptorSetLayout: required parameter "
1626 "pCreateInfo->pBindings[%d].pImmutableSamplers[%d]"
1627 " specified as VK_NULL_HANDLE",
1628 i, descriptor_index);
1629 }
1630 }
1631 }
1632
1633 // If descriptorCount is not 0, stageFlags must be a valid combination of VkShaderStageFlagBits values
1634 if ((pCreateInfo->pBindings[i].stageFlags != 0) &&
1635 ((pCreateInfo->pBindings[i].stageFlags & (~AllVkShaderStageFlagBits)) != 0)) {
1636 skip |= log_msg(
1637 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1638 VALIDATION_ERROR_04e00236, LayerName,
1639 "vkCreateDescriptorSetLayout(): if pCreateInfo->pBindings[%d].descriptorCount is not 0, "
1640 "pCreateInfo->pBindings[%d].stageFlags must be a valid combination of VkShaderStageFlagBits values. %s",
1641 i, i, validation_error_map[VALIDATION_ERROR_04e00236]);
1642 }
1643 }
1644 }
1645 }
1646
1647 return skip;
1648}
1649
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001650bool pv_vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
1651 const VkDescriptorSet *pDescriptorSets) {
1652 bool skip = false;
1653 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1654 debug_report_data *report_data = device_data->report_data;
1655
1656 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1657 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
1658 // validate_array()
1659 skip |= validate_array(report_data, "vkFreeDescriptorSets", "descriptorSetCount", "pDescriptorSets", descriptorSetCount,
1660 pDescriptorSets, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1661 return skip;
1662}
1663
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001664bool pv_vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites,
1665 uint32_t descriptorCopyCount, const VkCopyDescriptorSet *pDescriptorCopies) {
1666 bool skip = false;
1667 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1668 debug_report_data *report_data = device_data->report_data;
1669
1670 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1671 if (pDescriptorWrites != NULL) {
1672 for (uint32_t i = 0; i < descriptorWriteCount; ++i) {
1673 // descriptorCount must be greater than 0
1674 if (pDescriptorWrites[i].descriptorCount == 0) {
1675 skip |=
1676 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1677 VALIDATION_ERROR_15c0441b, LayerName,
1678 "vkUpdateDescriptorSets(): parameter pDescriptorWrites[%d].descriptorCount must be greater than 0. %s",
1679 i, validation_error_map[VALIDATION_ERROR_15c0441b]);
1680 }
1681
1682 // dstSet must be a valid VkDescriptorSet handle
1683 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1684 ParameterName("pDescriptorWrites[%i].dstSet", ParameterName::IndexVector{i}),
1685 pDescriptorWrites[i].dstSet);
1686
1687 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
1688 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||
1689 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||
1690 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ||
1691 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) {
1692 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
1693 // VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
1694 // pImageInfo must be a pointer to an array of descriptorCount valid VkDescriptorImageInfo structures
1695 if (pDescriptorWrites[i].pImageInfo == nullptr) {
1696 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1697 __LINE__, VALIDATION_ERROR_15c00284, LayerName,
1698 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
1699 "VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, "
1700 "VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or "
1701 "VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, pDescriptorWrites[%d].pImageInfo must not be NULL. %s",
1702 i, i, validation_error_map[VALIDATION_ERROR_15c00284]);
1703 } else if (pDescriptorWrites[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) {
1704 // If descriptorType is VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
1705 // VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, the imageView and imageLayout
1706 // members of any given element of pImageInfo must be a valid VkImageView and VkImageLayout, respectively
1707 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
1708 ++descriptor_index) {
1709 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1710 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageView",
1711 ParameterName::IndexVector{i, descriptor_index}),
1712 pDescriptorWrites[i].pImageInfo[descriptor_index].imageView);
1713 skip |= validate_ranged_enum(report_data, "vkUpdateDescriptorSets",
1714 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageLayout",
1715 ParameterName::IndexVector{i, descriptor_index}),
1716 "VkImageLayout", AllVkImageLayoutEnums,
1717 pDescriptorWrites[i].pImageInfo[descriptor_index].imageLayout,
1718 VALIDATION_ERROR_UNDEFINED);
1719 }
1720 }
1721 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
1722 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
1723 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1724 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1725 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1726 // VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pBufferInfo must be a
1727 // pointer to an array of descriptorCount valid VkDescriptorBufferInfo structures
1728 if (pDescriptorWrites[i].pBufferInfo == nullptr) {
1729 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1730 __LINE__, VALIDATION_ERROR_15c00288, LayerName,
1731 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
1732 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, "
1733 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, "
1734 "pDescriptorWrites[%d].pBufferInfo must not be NULL. %s",
1735 i, i, validation_error_map[VALIDATION_ERROR_15c00288]);
1736 } else {
1737 for (uint32_t descriptorIndex = 0; descriptorIndex < pDescriptorWrites[i].descriptorCount; ++descriptorIndex) {
1738 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1739 ParameterName("pDescriptorWrites[%i].pBufferInfo[%i].buffer",
1740 ParameterName::IndexVector{i, descriptorIndex}),
1741 pDescriptorWrites[i].pBufferInfo[descriptorIndex].buffer);
1742 }
1743 }
1744 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||
1745 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) {
1746 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
1747 // pTexelBufferView must be a pointer to an array of descriptorCount valid VkBufferView handles
1748 if (pDescriptorWrites[i].pTexelBufferView == nullptr) {
1749 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1750 __LINE__, VALIDATION_ERROR_15c00286, LayerName,
1751 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
1752 "VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, "
1753 "pDescriptorWrites[%d].pTexelBufferView must not be NULL. %s",
1754 i, i, validation_error_map[VALIDATION_ERROR_15c00286]);
1755 } else {
1756 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
1757 ++descriptor_index) {
1758 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1759 ParameterName("pDescriptorWrites[%i].pTexelBufferView[%i]",
1760 ParameterName::IndexVector{i, descriptor_index}),
1761 pDescriptorWrites[i].pTexelBufferView[descriptor_index]);
1762 }
1763 }
1764 }
1765
1766 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
1767 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)) {
1768 VkDeviceSize uniformAlignment = device_data->device_limits.minUniformBufferOffsetAlignment;
1769 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
1770 if (pDescriptorWrites[i].pBufferInfo != NULL) {
1771 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) {
1772 skip |= log_msg(
1773 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1774 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c0028e, LayerName,
1775 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
1776 ") must be a multiple of device limit minUniformBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
1777 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment,
1778 validation_error_map[VALIDATION_ERROR_15c0028e]);
1779 }
1780 }
1781 }
1782 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
1783 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1784 VkDeviceSize storageAlignment = device_data->device_limits.minStorageBufferOffsetAlignment;
1785 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
1786 if (pDescriptorWrites[i].pBufferInfo != NULL) {
1787 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) {
1788 skip |= log_msg(
1789 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1790 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c00290, LayerName,
1791 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
1792 ") must be a multiple of device limit minStorageBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
1793 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment,
1794 validation_error_map[VALIDATION_ERROR_15c00290]);
1795 }
1796 }
1797 }
1798 }
1799 }
1800 }
1801 return skip;
1802}
1803
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001804bool pv_vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1805 VkRenderPass *pRenderPass) {
1806 bool skip = false;
1807 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1808 uint32_t max_color_attachments = device_data->device_limits.maxColorAttachments;
1809
1810 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
1811 if (pCreateInfo->pAttachments[i].format == VK_FORMAT_UNDEFINED) {
1812 std::stringstream ss;
1813 ss << "vkCreateRenderPass: pCreateInfo->pAttachments[" << i << "].format is VK_FORMAT_UNDEFINED. "
1814 << validation_error_map[VALIDATION_ERROR_00809201];
1815 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1816 __LINE__, VALIDATION_ERROR_00809201, "IMAGE", "%s", ss.str().c_str());
1817 }
1818 if (pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_UNDEFINED ||
1819 pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_PREINITIALIZED) {
1820 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1821 __LINE__, VALIDATION_ERROR_00800696, "DL",
1822 "pCreateInfo->pAttachments[%d].finalLayout must not be VK_IMAGE_LAYOUT_UNDEFINED or "
1823 "VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
1824 i, validation_error_map[VALIDATION_ERROR_00800696]);
1825 }
1826 }
1827
1828 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
1829 if (pCreateInfo->pSubpasses[i].colorAttachmentCount > max_color_attachments) {
1830 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1831 __LINE__, VALIDATION_ERROR_1400069a, "DL",
1832 "Cannot create a render pass with %d color attachments. Max is %d. %s",
1833 pCreateInfo->pSubpasses[i].colorAttachmentCount, max_color_attachments,
1834 validation_error_map[VALIDATION_ERROR_1400069a]);
1835 }
1836 }
1837 return skip;
1838}
1839
1840bool pv_vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
1841 const VkCommandBuffer *pCommandBuffers) {
1842 bool skip = false;
1843 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1844 debug_report_data *report_data = device_data->report_data;
1845
1846 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1847 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
1848 // validate_array()
1849 skip |= validate_array(report_data, "vkFreeCommandBuffers", "commandBufferCount", "pCommandBuffers", commandBufferCount,
1850 pCommandBuffers, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1851 return skip;
1852}
1853
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001854bool pv_vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo) {
1855 bool skip = false;
1856 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
1857 debug_report_data *report_data = device_data->report_data;
1858 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
1859
1860 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1861 // TODO: pBeginInfo->pInheritanceInfo must not be NULL if commandBuffer is a secondary command buffer
1862 skip |= validate_struct_type(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo",
1863 "VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO", pBeginInfo->pInheritanceInfo,
1864 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, false, VALIDATION_ERROR_UNDEFINED);
1865
1866 if (pBeginInfo->pInheritanceInfo != NULL) {
1867 skip |=
1868 validate_struct_pnext(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pNext", NULL,
1869 pBeginInfo->pInheritanceInfo->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0281c40d);
1870
1871 skip |= validate_bool32(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->occlusionQueryEnable",
1872 pBeginInfo->pInheritanceInfo->occlusionQueryEnable);
1873
1874 // TODO: This only needs to be validated when the inherited queries feature is enabled
1875 // skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
1876 // "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pBeginInfo->pInheritanceInfo->queryFlags, false);
1877
1878 // TODO: This must be 0 if the pipeline statistics queries feature is not enabled
1879 skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pipelineStatistics",
1880 "VkQueryPipelineStatisticFlagBits", AllVkQueryPipelineStatisticFlagBits,
1881 pBeginInfo->pInheritanceInfo->pipelineStatistics, false, false, VALIDATION_ERROR_UNDEFINED);
1882 }
1883
1884 if (pInfo != NULL) {
1885 if ((device_data->physical_device_features.inheritedQueries == VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
1886 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
1887 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_02a00070, LayerName,
1888 "Cannot set inherited occlusionQueryEnable in vkBeginCommandBuffer() when device does not support "
1889 "inheritedQueries. %s",
1890 validation_error_map[VALIDATION_ERROR_02a00070]);
1891 }
1892 if ((device_data->physical_device_features.inheritedQueries != VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
1893 skip |= validate_flags(device_data->report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
1894 "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pInfo->queryFlags, false, false,
1895 VALIDATION_ERROR_02a00072);
1896 }
1897 }
1898
1899 return skip;
1900}
1901
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001902bool pv_vkCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount,
1903 const VkViewport *pViewports) {
1904 bool skip = false;
1905 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
1906
1907 skip |= validate_array(device_data->report_data, "vkCmdSetViewport", "viewportCount", "pViewports", viewportCount, pViewports,
1908 true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1909
1910 if (viewportCount > 0 && pViewports != nullptr) {
1911 const VkPhysicalDeviceLimits &limits = device_data->device_limits;
1912 for (uint32_t viewportIndex = 0; viewportIndex < viewportCount; ++viewportIndex) {
1913 const VkViewport &viewport = pViewports[viewportIndex];
1914
1915 if (device_data->physical_device_features.multiViewport == false) {
1916 if (viewportCount != 1) {
1917 skip |= log_msg(
1918 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1919 __LINE__, DEVICE_FEATURE, LayerName,
1920 "vkCmdSetViewport(): The multiViewport feature is not enabled, so viewportCount must be 1 but is %d.",
1921 viewportCount);
1922 }
1923 if (firstViewport != 0) {
1924 skip |= log_msg(
1925 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1926 __LINE__, DEVICE_FEATURE, LayerName,
1927 "vkCmdSetViewport(): The multiViewport feature is not enabled, so firstViewport must be 0 but is %d.",
1928 firstViewport);
1929 }
1930 }
1931
1932 if (viewport.width <= 0 || viewport.width > limits.maxViewportDimensions[0]) {
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_15000996, LayerName,
1935 "vkCmdSetViewport %d: width (%f) exceeds permitted bounds (0,%u). %s", viewportIndex,
1936 viewport.width, limits.maxViewportDimensions[0], validation_error_map[VALIDATION_ERROR_15000996]);
1937 }
1938
1939 if (device_data->extensions.vk_amd_negative_viewport_height || device_data->extensions.vk_khr_maintenance1) {
1940 // Check lower bound against negative viewport height instead of zero
1941 if (viewport.height <= -(static_cast<int32_t>(limits.maxViewportDimensions[1])) ||
1942 (viewport.height > limits.maxViewportDimensions[1])) {
1943 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1944 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, VALIDATION_ERROR_1500099a, LayerName,
1945 "vkCmdSetViewport %d: height (%f) exceeds permitted bounds (-%u,%u). %s", viewportIndex,
1946 viewport.height, limits.maxViewportDimensions[1], limits.maxViewportDimensions[1],
1947 validation_error_map[VALIDATION_ERROR_1500099a]);
1948 }
1949 } else {
1950 if ((viewport.height <= 0) || (viewport.height > limits.maxViewportDimensions[1])) {
1951 skip |=
1952 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1953 __LINE__, VALIDATION_ERROR_15000998, LayerName,
1954 "vkCmdSetViewport %d: height (%f) exceeds permitted bounds (0,%u). %s", viewportIndex,
1955 viewport.height, limits.maxViewportDimensions[1], validation_error_map[VALIDATION_ERROR_15000998]);
1956 }
1957 }
1958
1959 if (viewport.x < limits.viewportBoundsRange[0] || viewport.x > limits.viewportBoundsRange[1]) {
1960 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1961 __LINE__, VALIDATION_ERROR_1500099e, LayerName,
1962 "vkCmdSetViewport %d: x (%f) exceeds permitted bounds (%f,%f). %s", viewportIndex, viewport.x,
1963 limits.viewportBoundsRange[0], limits.viewportBoundsRange[1],
1964 validation_error_map[VALIDATION_ERROR_1500099e]);
1965 }
1966
1967 if (viewport.y < limits.viewportBoundsRange[0] || viewport.y > limits.viewportBoundsRange[1]) {
1968 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1969 __LINE__, VALIDATION_ERROR_1500099e, LayerName,
1970 "vkCmdSetViewport %d: y (%f) exceeds permitted bounds (%f,%f). %s", viewportIndex, viewport.y,
1971 limits.viewportBoundsRange[0], limits.viewportBoundsRange[1],
1972 validation_error_map[VALIDATION_ERROR_1500099e]);
1973 }
1974
1975 if (viewport.x + viewport.width > limits.viewportBoundsRange[1]) {
1976 skip |=
1977 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1978 __LINE__, VALIDATION_ERROR_150009a0, LayerName,
1979 "vkCmdSetViewport %d: x (%f) + width (%f) exceeds permitted bound (%f). %s", viewportIndex, viewport.x,
1980 viewport.width, limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a0]);
1981 }
1982
1983 if (viewport.y + viewport.height > limits.viewportBoundsRange[1]) {
1984 skip |=
1985 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1986 __LINE__, VALIDATION_ERROR_150009a2, LayerName,
1987 "vkCmdSetViewport %d: y (%f) + height (%f) exceeds permitted bound (%f). %s", viewportIndex, viewport.y,
1988 viewport.height, limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a2]);
1989 }
1990 }
1991 }
1992 return skip;
1993}
1994
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001995bool pv_vkCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *pScissors) {
1996 bool skip = false;
1997 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
1998 debug_report_data *report_data = device_data->report_data;
1999
2000 if (device_data->physical_device_features.multiViewport == false) {
2001 if (scissorCount != 1) {
2002 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2003 DEVICE_FEATURE, LayerName,
2004 "vkCmdSetScissor(): The multiViewport feature is not enabled, so scissorCount must be 1 but is %d.",
2005 scissorCount);
2006 }
2007 if (firstScissor != 0) {
2008 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2009 DEVICE_FEATURE, LayerName,
2010 "vkCmdSetScissor(): The multiViewport feature is not enabled, so firstScissor must be 0 but is %d.",
2011 firstScissor);
2012 }
2013 }
2014
2015 for (uint32_t scissorIndex = 0; scissorIndex < scissorCount; ++scissorIndex) {
2016 const VkRect2D &pScissor = pScissors[scissorIndex];
2017
2018 if (pScissor.offset.x < 0) {
2019 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2020 VALIDATION_ERROR_1d8004a6, LayerName, "vkCmdSetScissor %d: offset.x (%d) must not be negative. %s",
2021 scissorIndex, pScissor.offset.x, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2022 } else if (static_cast<int32_t>(pScissor.extent.width) > (INT_MAX - pScissor.offset.x)) {
2023 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2024 VALIDATION_ERROR_1d8004a8, LayerName,
2025 "vkCmdSetScissor %d: adding offset.x (%d) and extent.width (%u) will overflow. %s", scissorIndex,
2026 pScissor.offset.x, pScissor.extent.width, validation_error_map[VALIDATION_ERROR_1d8004a8]);
2027 }
2028
2029 if (pScissor.offset.y < 0) {
2030 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2031 VALIDATION_ERROR_1d8004a6, LayerName, "vkCmdSetScissor %d: offset.y (%d) must not be negative. %s",
2032 scissorIndex, pScissor.offset.y, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2033 } else if (static_cast<int32_t>(pScissor.extent.height) > (INT_MAX - pScissor.offset.y)) {
2034 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2035 VALIDATION_ERROR_1d8004aa, LayerName,
2036 "vkCmdSetScissor %d: adding offset.y (%d) and extent.height (%u) will overflow. %s", scissorIndex,
2037 pScissor.offset.y, pScissor.extent.height, validation_error_map[VALIDATION_ERROR_1d8004aa]);
2038 }
2039 }
2040 return skip;
2041}
2042
Petr Kraus299ba622017-11-24 03:09:03 +01002043bool pv_vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
2044 bool skip = false;
2045 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2046 debug_report_data *report_data = device_data->report_data;
2047
2048 if (!device_data->physical_device_features.wideLines && (lineWidth != 1.0f)) {
2049 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2050 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d600628, LayerName,
2051 "VkPhysicalDeviceFeatures::wideLines is disabled, but lineWidth (=%f) is not 1.0. %s", lineWidth,
2052 validation_error_map[VALIDATION_ERROR_1d600628]);
2053 }
2054
2055 return skip;
2056}
2057
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002058bool pv_vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex,
2059 uint32_t firstInstance) {
2060 bool skip = false;
2061 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2062 if (vertexCount == 0) {
2063 // TODO: Verify against Valid Usage section. I don't see a non-zero vertexCount listed, may need to add that and make
2064 // this an error or leave as is.
2065 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2066 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t vertexCount, is 0");
2067 }
2068
2069 if (instanceCount == 0) {
2070 // TODO: Verify against Valid Usage section. I don't see a non-zero instanceCount listed, may need to add that and make
2071 // this an error or leave as is.
2072 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2073 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t instanceCount, is 0");
2074 }
2075 return skip;
2076}
2077
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002078bool pv_vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride) {
2079 bool skip = false;
2080 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2081
2082 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2083 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2084 __LINE__, DEVICE_FEATURE, LayerName,
2085 "CmdDrawIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2086 }
2087 return skip;
2088}
2089
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002090bool pv_vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count,
2091 uint32_t stride) {
2092 bool skip = false;
2093 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2094 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2095 skip |=
2096 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2097 DEVICE_FEATURE, LayerName,
2098 "CmdDrawIndexedIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2099 }
2100 return skip;
2101}
2102
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002103bool pv_vkCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2104 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy *pRegions) {
2105 bool skip = false;
2106 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2107
2108 if (pRegions != nullptr) {
2109 if ((pRegions->srcSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2110 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2111 skip |= log_msg(
2112 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2113 VALIDATION_ERROR_0a600c01, LayerName,
2114 "vkCmdCopyImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator. %s",
2115 validation_error_map[VALIDATION_ERROR_0a600c01]);
2116 }
2117 if ((pRegions->dstSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2118 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2119 skip |= log_msg(
2120 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2121 VALIDATION_ERROR_0a600c01, LayerName,
2122 "vkCmdCopyImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator. %s",
2123 validation_error_map[VALIDATION_ERROR_0a600c01]);
2124 }
2125 }
2126 return skip;
2127}
2128
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002129bool pv_vkCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2130 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
2131 bool skip = false;
2132 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2133
2134 if (pRegions != nullptr) {
2135 if ((pRegions->srcSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2136 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2137 skip |= log_msg(
2138 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2139 UNRECOGNIZED_VALUE, LayerName,
2140 "vkCmdBlitImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator");
2141 }
2142 if ((pRegions->dstSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2143 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2144 skip |= log_msg(
2145 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2146 UNRECOGNIZED_VALUE, LayerName,
2147 "vkCmdBlitImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator");
2148 }
2149 }
2150 return skip;
2151}
2152
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002153bool pv_vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout,
2154 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2155 bool skip = false;
2156 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2157
2158 if (pRegions != nullptr) {
2159 if ((pRegions->imageSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2160 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2161 skip |= log_msg(
2162 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2163 UNRECOGNIZED_VALUE, LayerName,
2164 "vkCmdCopyBufferToImage() parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an unrecognized "
2165 "enumerator");
2166 }
2167 }
2168 return skip;
2169}
2170
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002171bool pv_vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer,
2172 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2173 bool skip = false;
2174 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2175
2176 if (pRegions != nullptr) {
2177 if ((pRegions->imageSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2178 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2179 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2180 UNRECOGNIZED_VALUE, LayerName,
2181 "vkCmdCopyImageToBuffer parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an unrecognized "
2182 "enumerator");
2183 }
2184 }
2185 return skip;
2186}
2187
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002188bool pv_vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize,
2189 const void *pData) {
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_1e400048, LayerName,
2196 "vkCmdUpdateBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2197 dstOffset, validation_error_map[VALIDATION_ERROR_1e400048]);
2198 }
2199
2200 if ((dataSize <= 0) || (dataSize > 65536)) {
2201 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2202 __LINE__, VALIDATION_ERROR_1e40004a, LayerName,
2203 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64
2204 "), must be greater than zero and less than or equal to 65536. %s",
2205 dataSize, validation_error_map[VALIDATION_ERROR_1e40004a]);
2206 } else if (dataSize & 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_1e40004c, LayerName,
2209 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2210 dataSize, validation_error_map[VALIDATION_ERROR_1e40004c]);
2211 }
2212 return skip;
2213}
2214
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002215bool pv_vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size,
2216 uint32_t data) {
2217 bool skip = false;
2218 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2219
2220 if (dstOffset & 3) {
2221 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2222 __LINE__, VALIDATION_ERROR_1b400032, LayerName,
2223 "vkCmdFillBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2224 dstOffset, validation_error_map[VALIDATION_ERROR_1b400032]);
2225 }
2226
2227 if (size != VK_WHOLE_SIZE) {
2228 if (size <= 0) {
2229 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2230 __LINE__, VALIDATION_ERROR_1b400034, LayerName,
2231 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), must be greater than zero. %s",
2232 size, validation_error_map[VALIDATION_ERROR_1b400034]);
2233 } else if (size & 3) {
2234 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2235 __LINE__, VALIDATION_ERROR_1b400038, LayerName,
2236 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), is not a multiple of 4. %s", size,
2237 validation_error_map[VALIDATION_ERROR_1b400038]);
2238 }
2239 }
2240 return skip;
2241}
2242
2243VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
2244 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2245}
2246
2247VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
2248 VkLayerProperties *pProperties) {
2249 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2250}
2251
2252VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
2253 VkExtensionProperties *pProperties) {
2254 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2255 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
2256
2257 return VK_ERROR_LAYER_NOT_PRESENT;
2258}
2259
2260VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
2261 uint32_t *pPropertyCount, VkExtensionProperties *pProperties) {
2262 // Parameter_validation does not have any physical device extensions
2263 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2264 return util_GetExtensionProperties(0, NULL, pPropertyCount, pProperties);
2265
2266 instance_layer_data *local_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map);
2267 bool skip =
2268 validate_array(local_data->report_data, "vkEnumerateDeviceExtensionProperties", "pPropertyCount", "pProperties",
2269 pPropertyCount, pProperties, true, false, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_2761f401);
2270 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
2271
2272 return local_data->dispatch_table.EnumerateDeviceExtensionProperties(physicalDevice, NULL, pPropertyCount, pProperties);
2273}
2274
2275static bool require_device_extension(layer_data *device_data, bool flag, char const *function_name, char const *extension_name) {
2276 if (!flag) {
2277 return log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2278 __LINE__, EXTENSION_NOT_ENABLED, LayerName,
2279 "%s() called even though the %s extension was not enabled for this VkDevice.", function_name,
2280 extension_name);
2281 }
2282
2283 return false;
2284}
2285
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002286bool pv_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator,
2287 VkSwapchainKHR *pSwapchain) {
2288 bool skip = false;
2289 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2290 debug_report_data *report_data = device_data->report_data;
2291
2292 if (pCreateInfo != nullptr) {
2293 if ((device_data->physical_device_features.textureCompressionETC2 == false) &&
2294 FormatIsCompressed_ETC2_EAC(pCreateInfo->imageFormat)) {
2295 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2296 DEVICE_FEATURE, LayerName,
2297 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2298 "textureCompressionETC2 feature is not enabled: neither ETC2 nor EAC formats can be used to create "
2299 "images.",
2300 string_VkFormat(pCreateInfo->imageFormat));
2301 }
2302
2303 if ((device_data->physical_device_features.textureCompressionASTC_LDR == false) &&
2304 FormatIsCompressed_ASTC_LDR(pCreateInfo->imageFormat)) {
2305 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2306 DEVICE_FEATURE, LayerName,
2307 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2308 "textureCompressionASTC_LDR feature is not enabled: ASTC formats cannot be used to create images.",
2309 string_VkFormat(pCreateInfo->imageFormat));
2310 }
2311
2312 if ((device_data->physical_device_features.textureCompressionBC == false) &&
2313 FormatIsCompressed_BC(pCreateInfo->imageFormat)) {
2314 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2315 DEVICE_FEATURE, LayerName,
2316 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2317 "textureCompressionBC feature is not enabled: BC compressed formats cannot be used to create images.",
2318 string_VkFormat(pCreateInfo->imageFormat));
2319 }
2320
2321 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2322 if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) {
2323 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
2324 if (pCreateInfo->queueFamilyIndexCount <= 1) {
2325 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2326 VALIDATION_ERROR_146009fc, LayerName,
2327 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2328 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
2329 validation_error_map[VALIDATION_ERROR_146009fc]);
2330 }
2331
2332 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
2333 // queueFamilyIndexCount uint32_t values
2334 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
2335 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2336 VALIDATION_ERROR_146009fa, LayerName,
2337 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2338 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
2339 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
2340 validation_error_map[VALIDATION_ERROR_146009fa]);
2341 } else {
2342 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
2343 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
2344 "vkCreateSwapchainKHR", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE,
2345 INVALID_USAGE, false, "", "");
2346 }
2347 }
2348
2349 // imageArrayLayers must be greater than 0
2350 skip |= ValidateGreaterThan(report_data, "vkCreateSwapchainKHR", "pCreateInfo->imageArrayLayers",
2351 pCreateInfo->imageArrayLayers, 0u);
2352 }
2353
2354 return skip;
2355}
2356
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002357bool pv_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
2358 bool skip = false;
2359 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
2360
2361 if (pPresentInfo && pPresentInfo->pNext) {
John Zulaufde972ac2017-10-26 12:07:05 -06002362 const auto *present_regions = lvl_find_in_chain<VkPresentRegionsKHR>(pPresentInfo->pNext);
2363 if (present_regions) {
2364 // TODO: This and all other pNext extension dependencies should be added to code-generation
2365 skip |= require_device_extension(device_data, device_data->extensions.vk_khr_incremental_present, "vkQueuePresentKHR",
2366 VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME);
2367 if (present_regions->swapchainCount != pPresentInfo->swapchainCount) {
2368 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2369 __LINE__, INVALID_USAGE, LayerName,
2370 "QueuePresentKHR(): pPresentInfo->swapchainCount has a value of %i"
2371 " but VkPresentRegionsKHR extension swapchainCount is %i. These values must be equal.",
2372 pPresentInfo->swapchainCount, present_regions->swapchainCount);
2373 }
2374 skip |= validate_struct_pnext(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pNext", NULL,
2375 present_regions->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_1121c40d);
2376 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->swapchainCount",
2377 "pCreateInfo->pNext->pRegions", present_regions->swapchainCount, present_regions->pRegions, true,
2378 false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2379 for (uint32_t i = 0; i < present_regions->swapchainCount; ++i) {
2380 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pRegions[].rectangleCount",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002381 "pCreateInfo->pNext->pRegions[].pRectangles", present_regions->pRegions[i].rectangleCount,
2382 present_regions->pRegions[i].pRectangles, true, false, VALIDATION_ERROR_UNDEFINED,
2383 VALIDATION_ERROR_UNDEFINED);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002384 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002385 }
2386 }
2387
2388 return skip;
2389}
2390
2391#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002392bool pv_vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
2393 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
2394 auto device_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2395 bool skip = false;
2396
2397 if (pCreateInfo->hwnd == nullptr) {
2398 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2399 __LINE__, VALIDATION_ERROR_15a00a38, LayerName,
2400 "vkCreateWin32SurfaceKHR(): hwnd must be a valid Win32 HWND but hwnd is NULL. %s",
2401 validation_error_map[VALIDATION_ERROR_15a00a38]);
2402 }
2403
2404 return skip;
2405}
2406#endif // VK_USE_PLATFORM_WIN32_KHR
2407
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002408bool pv_vkDebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
2409 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2410 if (pNameInfo->pObjectName) {
2411 device_data->report_data->debugObjectNameMap->insert(
2412 std::make_pair<uint64_t, std::string>((uint64_t &&) pNameInfo->object, pNameInfo->pObjectName));
2413 } else {
2414 device_data->report_data->debugObjectNameMap->erase(pNameInfo->object);
2415 }
2416 return false;
2417}
2418
Petr Krausc8655be2017-09-27 18:56:51 +02002419bool pv_vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2420 const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool) {
2421 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2422 bool skip = false;
2423
2424 if (pCreateInfo) {
2425 if (pCreateInfo->maxSets <= 0) {
2426 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2427 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_0480025a,
2428 LayerName, "vkCreateDescriptorPool(): pCreateInfo->maxSets is not greater than 0. %s",
2429 validation_error_map[VALIDATION_ERROR_0480025a]);
2430 }
2431
2432 if (pCreateInfo->pPoolSizes) {
2433 for (uint32_t i = 0; i < pCreateInfo->poolSizeCount; ++i) {
2434 if (pCreateInfo->pPoolSizes[i].descriptorCount <= 0) {
2435 skip |= log_msg(
2436 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT,
2437 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_04a0025c, LayerName,
2438 "vkCreateDescriptorPool(): pCreateInfo->pPoolSizes[%" PRIu32 "].descriptorCount is not greater than 0. %s",
2439 i, validation_error_map[VALIDATION_ERROR_04a0025c]);
2440 }
2441 }
2442 }
2443 }
2444
2445 return skip;
2446}
2447
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002448VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *funcName) {
2449 const auto item = name_to_funcptr_map.find(funcName);
2450 if (item != name_to_funcptr_map.end()) {
2451 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2452 }
2453
2454 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2455 const auto &table = device_data->dispatch_table;
2456 if (!table.GetDeviceProcAddr) return nullptr;
2457 return table.GetDeviceProcAddr(device, funcName);
2458}
2459
2460VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2461 const auto item = name_to_funcptr_map.find(funcName);
2462 if (item != name_to_funcptr_map.end()) {
2463 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2464 }
2465
2466 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2467 auto &table = instance_data->dispatch_table;
2468 if (!table.GetInstanceProcAddr) return nullptr;
2469 return table.GetInstanceProcAddr(instance, funcName);
2470}
2471
2472VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
2473 assert(instance);
2474 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2475
2476 if (!instance_data->dispatch_table.GetPhysicalDeviceProcAddr) return nullptr;
2477 return instance_data->dispatch_table.GetPhysicalDeviceProcAddr(instance, funcName);
2478}
2479
2480// If additional validation is needed outside of the generated checks, a manual routine can be added to this file
2481// 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 +02002482void InitializeManualParameterValidationFunctionPointers() {
Mark Lobodzinski78a12a92017-08-08 14:16:51 -06002483 custom_functions["vkGetDeviceQueue"] = (void*)pv_vkGetDeviceQueue;
2484 custom_functions["vkCreateBuffer"] = (void*)pv_vkCreateBuffer;
2485 custom_functions["vkCreateImage"] = (void*)pv_vkCreateImage;
2486 custom_functions["vkCreateImageView"] = (void*)pv_vkCreateImageView;
2487 custom_functions["vkCreateGraphicsPipelines"] = (void*)pv_vkCreateGraphicsPipelines;
2488 custom_functions["vkCreateComputePipelines"] = (void*)pv_vkCreateComputePipelines;
2489 custom_functions["vkCreateSampler"] = (void*)pv_vkCreateSampler;
2490 custom_functions["vkCreateDescriptorSetLayout"] = (void*)pv_vkCreateDescriptorSetLayout;
2491 custom_functions["vkFreeDescriptorSets"] = (void*)pv_vkFreeDescriptorSets;
2492 custom_functions["vkUpdateDescriptorSets"] = (void*)pv_vkUpdateDescriptorSets;
2493 custom_functions["vkCreateRenderPass"] = (void*)pv_vkCreateRenderPass;
2494 custom_functions["vkBeginCommandBuffer"] = (void*)pv_vkBeginCommandBuffer;
2495 custom_functions["vkCmdSetViewport"] = (void*)pv_vkCmdSetViewport;
2496 custom_functions["vkCmdSetScissor"] = (void*)pv_vkCmdSetScissor;
Petr Kraus299ba622017-11-24 03:09:03 +01002497 custom_functions["vkCmdSetLineWidth"] = (void *)pv_vkCmdSetLineWidth;
Mark Lobodzinski78a12a92017-08-08 14:16:51 -06002498 custom_functions["vkCmdDraw"] = (void*)pv_vkCmdDraw;
2499 custom_functions["vkCmdDrawIndirect"] = (void*)pv_vkCmdDrawIndirect;
2500 custom_functions["vkCmdDrawIndexedIndirect"] = (void*)pv_vkCmdDrawIndexedIndirect;
2501 custom_functions["vkCmdCopyImage"] = (void*)pv_vkCmdCopyImage;
2502 custom_functions["vkCmdBlitImage"] = (void*)pv_vkCmdBlitImage;
2503 custom_functions["vkCmdCopyBufferToImage"] = (void*)pv_vkCmdCopyBufferToImage;
2504 custom_functions["vkCmdCopyImageToBuffer"] = (void*)pv_vkCmdCopyImageToBuffer;
2505 custom_functions["vkCmdUpdateBuffer"] = (void*)pv_vkCmdUpdateBuffer;
2506 custom_functions["vkCmdFillBuffer"] = (void*)pv_vkCmdFillBuffer;
2507 custom_functions["vkCreateSwapchainKHR"] = (void*)pv_vkCreateSwapchainKHR;
2508 custom_functions["vkQueuePresentKHR"] = (void*)pv_vkQueuePresentKHR;
Petr Krausc8655be2017-09-27 18:56:51 +02002509 custom_functions["vkCreateDescriptorPool"] = (void*)pv_vkCreateDescriptorPool;
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002510}
2511
2512} // namespace parameter_validation
2513
2514VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
2515 VkExtensionProperties *pProperties) {
2516 return parameter_validation::vkEnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties);
2517}
2518
2519VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount,
2520 VkLayerProperties *pProperties) {
2521 return parameter_validation::vkEnumerateInstanceLayerProperties(pCount, pProperties);
2522}
2523
2524VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
2525 VkLayerProperties *pProperties) {
2526 // the layer command handles VK_NULL_HANDLE just fine internally
2527 assert(physicalDevice == VK_NULL_HANDLE);
2528 return parameter_validation::vkEnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties);
2529}
2530
2531VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
2532 const char *pLayerName, uint32_t *pCount,
2533 VkExtensionProperties *pProperties) {
2534 // the layer command handles VK_NULL_HANDLE just fine internally
2535 assert(physicalDevice == VK_NULL_HANDLE);
2536 return parameter_validation::vkEnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties);
2537}
2538
2539VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
2540 return parameter_validation::vkGetDeviceProcAddr(dev, funcName);
2541}
2542
2543VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2544 return parameter_validation::vkGetInstanceProcAddr(instance, funcName);
2545}
2546
2547VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
2548 const char *funcName) {
2549 return parameter_validation::vkGetPhysicalDeviceProcAddr(instance, funcName);
2550}
2551
2552VK_LAYER_EXPORT bool pv_vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) {
2553 assert(pVersionStruct != NULL);
2554 assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT);
2555
2556 // Fill in the function pointers if our version is at least capable of having the structure contain them.
2557 if (pVersionStruct->loaderLayerInterfaceVersion >= 2) {
2558 pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr;
2559 pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr;
2560 pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr;
2561 }
2562
2563 if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
2564 parameter_validation::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion;
2565 } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
2566 pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
2567 }
2568
2569 return VK_SUCCESS;
2570}