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