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