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