blob: 2c29d711c465758d39ede9fb41d7689ce89f9c73 [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
Dave Houltone19e20d2018-02-02 16:32:41 -0700774 if ((pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_UNDEFINED) &&
775 (pCreateInfo->initialLayout != VK_IMAGE_LAYOUT_PREINITIALIZED)) {
776 skip |= log_msg(
777 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Dave Houlton130c0212018-01-29 13:39:56 -0700778 VALIDATION_ERROR_09e007c2, LayerName,
779 "vkCreateImage(): initialLayout is %s, must be VK_IMAGE_LAYOUT_UNDEFINED or VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
780 string_VkImageLayout(pCreateInfo->initialLayout), validation_error_map[VALIDATION_ERROR_09e007c2]);
781 }
782
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600783 // If imageType is VK_IMAGE_TYPE_1D, both extent.height and extent.depth must be 1
784 if ((pCreateInfo->imageType == VK_IMAGE_TYPE_1D) && (pCreateInfo->extent.height != 1) && (pCreateInfo->extent.depth != 1)) {
785 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
Dave Houltone19e20d2018-02-02 16:32:41 -0700786 VALIDATION_ERROR_09e00778, LayerName,
787 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_1D, both "
788 "pCreateInfo->extent.height and pCreateInfo->extent.depth must be 1. %s",
789 validation_error_map[VALIDATION_ERROR_09e00778]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600790 }
791
792 if (pCreateInfo->imageType == VK_IMAGE_TYPE_2D) {
793 // If imageType is VK_IMAGE_TYPE_2D and flags contains VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, extent.width and
794 // extent.height must be equal
795 if ((pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) &&
796 (pCreateInfo->extent.width != pCreateInfo->extent.height)) {
797 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
798 VALIDATION_ERROR_09e00774, LayerName,
799 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_2D and "
800 "pCreateInfo->flags contains VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT, "
801 "pCreateInfo->extent.width and pCreateInfo->extent.height must be equal. %s",
802 validation_error_map[VALIDATION_ERROR_09e00774]);
803 }
804
805 if (pCreateInfo->extent.depth != 1) {
806 skip |= log_msg(
807 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
808 VALIDATION_ERROR_09e0077a, LayerName,
809 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_2D, pCreateInfo->extent.depth must be 1. %s",
810 validation_error_map[VALIDATION_ERROR_09e0077a]);
811 }
812 }
813
Dave Houlton130c0212018-01-29 13:39:56 -0700814 // 3D image may have only 1 layer
815 if ((pCreateInfo->imageType == VK_IMAGE_TYPE_3D) && (pCreateInfo->arrayLayers != 1)) {
816 skip |=
817 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
818 VALIDATION_ERROR_09e00782, LayerName,
819 "vkCreateImage(): if pCreateInfo->imageType is VK_IMAGE_TYPE_3D, pCreateInfo->arrayLayers must be 1. %s",
820 validation_error_map[VALIDATION_ERROR_09e00782]);
821 }
822
823 // If multi-sample, validate type, usage, tiling and mip levels.
824 if ((pCreateInfo->samples != VK_SAMPLE_COUNT_1_BIT) &&
825 ((pCreateInfo->imageType != VK_IMAGE_TYPE_2D) || (pCreateInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) ||
826 (pCreateInfo->tiling != VK_IMAGE_TILING_OPTIMAL) || (pCreateInfo->mipLevels != 1))) {
827 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
828 VALIDATION_ERROR_09e00784, LayerName,
829 "vkCreateImage(): Multi-sample image with incompatible type, usage, tiling, or mips. %s",
830 validation_error_map[VALIDATION_ERROR_09e00784]);
831 }
832
833 if (0 != (pCreateInfo->usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT)) {
834 VkImageUsageFlags legal_flags = (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT |
835 VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT);
836 // At least one of the legal attachment bits must be set
837 if (0 == (pCreateInfo->usage & legal_flags)) {
838 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
839 VALIDATION_ERROR_09e0078c, LayerName,
840 "vkCreateImage(): Transient attachment image without a compatible attachment flag set. %s",
841 validation_error_map[VALIDATION_ERROR_09e0078c]);
842 }
843 // No flags other than the legal attachment bits may be set
844 legal_flags |= VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT;
845 if (0 != (pCreateInfo->usage & ~legal_flags)) {
846 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
847 VALIDATION_ERROR_09e00786, LayerName,
848 "vkCreateImage(): Transient attachment image with incompatible usage flags set. %s",
849 validation_error_map[VALIDATION_ERROR_09e00786]);
850 }
851 }
852
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600853 // mipLevels must be less than or equal to floor(log2(max(extent.width,extent.height,extent.depth)))+1
854 uint32_t maxDim = std::max(std::max(pCreateInfo->extent.width, pCreateInfo->extent.height), pCreateInfo->extent.depth);
Petr Krause5c37652018-01-05 04:05:12 +0100855 if (maxDim > 0 && pCreateInfo->mipLevels > (floor(log2(maxDim)) + 1)) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600856 skip |=
857 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
858 VALIDATION_ERROR_09e0077c, LayerName,
859 "vkCreateImage(): pCreateInfo->mipLevels must be less than or equal to "
860 "floor(log2(max(pCreateInfo->extent.width, pCreateInfo->extent.height, pCreateInfo->extent.depth)))+1. %s",
861 validation_error_map[VALIDATION_ERROR_09e0077c]);
862 }
863
864 // If flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain
865 // VK_IMAGE_CREATE_SPARSE_BINDING_BIT
866 if (((pCreateInfo->flags & (VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT)) != 0) &&
867 ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) != VK_IMAGE_CREATE_SPARSE_BINDING_BIT)) {
868 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
869 VALIDATION_ERROR_09e007b6, LayerName,
870 "vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT or "
871 "VK_IMAGE_CREATE_SPARSE_ALIASED_BIT, it must also contain VK_IMAGE_CREATE_SPARSE_BINDING_BIT. %s",
872 validation_error_map[VALIDATION_ERROR_09e007b6]);
873 }
874
875 // Check for combinations of attributes that are incompatible with having VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT set
876 if ((pCreateInfo->flags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT) != 0) {
877 // Linear tiling is unsupported
878 if (VK_IMAGE_TILING_LINEAR == pCreateInfo->tiling) {
879 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
880 INVALID_USAGE, LayerName,
881 "vkCreateImage: if pCreateInfo->flags contains VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT "
882 "then image tiling of VK_IMAGE_TILING_LINEAR is not supported");
883 }
884
885 // Sparse 1D image isn't valid
886 if (VK_IMAGE_TYPE_1D == pCreateInfo->imageType) {
887 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
888 VALIDATION_ERROR_09e00794, LayerName,
889 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 1D image. %s",
890 validation_error_map[VALIDATION_ERROR_09e00794]);
891 }
892
893 // Sparse 2D image when device doesn't support it
894 if ((VK_FALSE == device_data->physical_device_features.sparseResidencyImage2D) &&
895 (VK_IMAGE_TYPE_2D == pCreateInfo->imageType)) {
896 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
897 VALIDATION_ERROR_09e00796, LayerName,
898 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2D image if corresponding "
899 "feature is not enabled on the device. %s",
900 validation_error_map[VALIDATION_ERROR_09e00796]);
901 }
902
903 // Sparse 3D image when device doesn't support it
904 if ((VK_FALSE == device_data->physical_device_features.sparseResidencyImage3D) &&
905 (VK_IMAGE_TYPE_3D == pCreateInfo->imageType)) {
906 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
907 VALIDATION_ERROR_09e00798, LayerName,
908 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 3D image if corresponding "
909 "feature is not enabled on the device. %s",
910 validation_error_map[VALIDATION_ERROR_09e00798]);
911 }
912
913 // Multi-sample 2D image when device doesn't support it
914 if (VK_IMAGE_TYPE_2D == pCreateInfo->imageType) {
915 if ((VK_FALSE == device_data->physical_device_features.sparseResidency2Samples) &&
916 (VK_SAMPLE_COUNT_2_BIT == pCreateInfo->samples)) {
917 skip |= log_msg(
918 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
919 VALIDATION_ERROR_09e0079a, LayerName,
920 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 2-sample image if corresponding "
921 "feature is not enabled on the device. %s",
922 validation_error_map[VALIDATION_ERROR_09e0079a]);
923 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency4Samples) &&
924 (VK_SAMPLE_COUNT_4_BIT == pCreateInfo->samples)) {
925 skip |= log_msg(
926 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
927 VALIDATION_ERROR_09e0079c, LayerName,
928 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 4-sample image if corresponding "
929 "feature is not enabled on the device. %s",
930 validation_error_map[VALIDATION_ERROR_09e0079c]);
931 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency8Samples) &&
932 (VK_SAMPLE_COUNT_8_BIT == pCreateInfo->samples)) {
933 skip |= log_msg(
934 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
935 VALIDATION_ERROR_09e0079e, LayerName,
936 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 8-sample image if corresponding "
937 "feature is not enabled on the device. %s",
938 validation_error_map[VALIDATION_ERROR_09e0079e]);
939 } else if ((VK_FALSE == device_data->physical_device_features.sparseResidency16Samples) &&
940 (VK_SAMPLE_COUNT_16_BIT == pCreateInfo->samples)) {
941 skip |= log_msg(
942 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
943 VALIDATION_ERROR_09e007a0, LayerName,
944 "vkCreateImage: cannot specify VK_IMAGE_CREATE_SPARSE_BINDING_BIT for 16-sample image if corresponding "
945 "feature is not enabled on the device. %s",
946 validation_error_map[VALIDATION_ERROR_09e007a0]);
947 }
948 }
949 }
950 }
951 return skip;
952}
953
Mark Lobodzinskid4950072017-08-01 13:02:20 -0600954bool pv_vkCreateImageView(VkDevice device, const VkImageViewCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
955 VkImageView *pView) {
956 bool skip = false;
957 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
958 debug_report_data *report_data = device_data->report_data;
959
960 if (pCreateInfo != nullptr) {
961 if ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D) || (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_2D)) {
962 if ((pCreateInfo->subresourceRange.layerCount != 1) &&
963 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
964 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
965 LayerName,
966 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_%dD, "
967 "pCreateInfo->subresourceRange.layerCount must be 1",
968 ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D) ? 1 : 2));
969 }
970 } else if ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY) ||
971 (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY)) {
972 if ((pCreateInfo->subresourceRange.layerCount < 1) &&
973 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
974 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
975 LayerName,
976 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_%dD_ARRAY, "
977 "pCreateInfo->subresourceRange.layerCount must be >= 1",
978 ((pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_1D_ARRAY) ? 1 : 2));
979 }
980 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE) {
981 if ((pCreateInfo->subresourceRange.layerCount != 6) &&
982 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
983 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
984 LayerName,
985 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_CUBE, "
986 "pCreateInfo->subresourceRange.layerCount must be 6");
987 }
988 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) {
989 if (((pCreateInfo->subresourceRange.layerCount == 0) || ((pCreateInfo->subresourceRange.layerCount % 6) != 0)) &&
990 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
991 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
992 LayerName,
993 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_CUBE_ARRAY, "
994 "pCreateInfo->subresourceRange.layerCount must be a multiple of 6");
995 }
996 if (!device_data->physical_device_features.imageCubeArray) {
997 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
998 LayerName, "vkCreateImageView: Device feature imageCubeArray not enabled.");
999 }
1000 } else if (pCreateInfo->viewType == VK_IMAGE_VIEW_TYPE_3D) {
1001 if (pCreateInfo->subresourceRange.baseArrayLayer != 0) {
1002 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1003 LayerName,
1004 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_3D, "
1005 "pCreateInfo->subresourceRange.baseArrayLayer must be 0");
1006 }
1007
1008 if ((pCreateInfo->subresourceRange.layerCount != 1) &&
1009 (pCreateInfo->subresourceRange.layerCount != VK_REMAINING_ARRAY_LAYERS)) {
1010 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, 1,
1011 LayerName,
1012 "vkCreateImageView: if pCreateInfo->viewType is VK_IMAGE_TYPE_3D, "
1013 "pCreateInfo->subresourceRange.layerCount must be 1");
1014 }
1015 }
1016 }
1017 return skip;
1018}
1019
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001020bool pv_vkCreateGraphicsPipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1021 const VkGraphicsPipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1022 VkPipeline *pPipelines) {
1023 bool skip = false;
1024 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1025 debug_report_data *report_data = device_data->report_data;
1026
1027 if (pCreateInfos != nullptr) {
1028 for (uint32_t i = 0; i < createInfoCount; ++i) {
Petr Kraus299ba622017-11-24 03:09:03 +01001029 bool has_dynamic_viewport = false;
1030 bool has_dynamic_scissor = false;
1031 bool has_dynamic_line_width = false;
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001032 bool has_dynamic_viewport_w_scaling_nv = false;
1033 bool has_dynamic_discard_rectangle_ext = false;
1034 bool has_dynamic_sample_locations_ext = false;
Petr Kraus299ba622017-11-24 03:09:03 +01001035 if (pCreateInfos[i].pDynamicState != nullptr) {
1036 const auto &dynamic_state_info = *pCreateInfos[i].pDynamicState;
1037 for (uint32_t state_index = 0; state_index < dynamic_state_info.dynamicStateCount; ++state_index) {
1038 const auto &dynamic_state = dynamic_state_info.pDynamicStates[state_index];
1039 if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT) has_dynamic_viewport = true;
1040 if (dynamic_state == VK_DYNAMIC_STATE_SCISSOR) has_dynamic_scissor = true;
1041 if (dynamic_state == VK_DYNAMIC_STATE_LINE_WIDTH) has_dynamic_line_width = true;
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001042 if (dynamic_state == VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV) has_dynamic_viewport_w_scaling_nv = true;
1043 if (dynamic_state == VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT) has_dynamic_discard_rectangle_ext = true;
1044 if (dynamic_state == VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT) has_dynamic_sample_locations_ext = true;
Petr Kraus299ba622017-11-24 03:09:03 +01001045 }
1046 }
1047
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001048 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1049 if (pCreateInfos[i].pVertexInputState != nullptr) {
1050 auto const &vertex_input_state = pCreateInfos[i].pVertexInputState;
1051 for (uint32_t d = 0; d < vertex_input_state->vertexBindingDescriptionCount; ++d) {
1052 auto const &vertex_bind_desc = vertex_input_state->pVertexBindingDescriptions[d];
1053 if (vertex_bind_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
1054 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1055 __LINE__, VALIDATION_ERROR_14c004d4, LayerName,
1056 "vkCreateGraphicsPipelines: parameter "
1057 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].binding (%u) is "
1058 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
1059 i, d, vertex_bind_desc.binding, device_data->device_limits.maxVertexInputBindings,
1060 validation_error_map[VALIDATION_ERROR_14c004d4]);
1061 }
1062
1063 if (vertex_bind_desc.stride > device_data->device_limits.maxVertexInputBindingStride) {
1064 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1065 __LINE__, VALIDATION_ERROR_14c004d6, LayerName,
1066 "vkCreateGraphicsPipelines: parameter "
1067 "pCreateInfos[%u].pVertexInputState->pVertexBindingDescriptions[%u].stride (%u) is greater "
1068 "than VkPhysicalDeviceLimits::maxVertexInputBindingStride (%u). %s",
1069 i, d, vertex_bind_desc.stride, device_data->device_limits.maxVertexInputBindingStride,
1070 validation_error_map[VALIDATION_ERROR_14c004d6]);
1071 }
1072 }
1073
1074 for (uint32_t d = 0; d < vertex_input_state->vertexAttributeDescriptionCount; ++d) {
1075 auto const &vertex_attrib_desc = vertex_input_state->pVertexAttributeDescriptions[d];
1076 if (vertex_attrib_desc.location >= device_data->device_limits.maxVertexInputAttributes) {
1077 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1078 __LINE__, VALIDATION_ERROR_14a004d8, LayerName,
1079 "vkCreateGraphicsPipelines: parameter "
1080 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].location (%u) is "
1081 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputAttributes (%u). %s",
1082 i, d, vertex_attrib_desc.location, device_data->device_limits.maxVertexInputAttributes,
1083 validation_error_map[VALIDATION_ERROR_14a004d8]);
1084 }
1085
1086 if (vertex_attrib_desc.binding >= device_data->device_limits.maxVertexInputBindings) {
1087 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1088 __LINE__, VALIDATION_ERROR_14a004da, LayerName,
1089 "vkCreateGraphicsPipelines: parameter "
1090 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].binding (%u) is "
1091 "greater than or equal to VkPhysicalDeviceLimits::maxVertexInputBindings (%u). %s",
1092 i, d, vertex_attrib_desc.binding, device_data->device_limits.maxVertexInputBindings,
1093 validation_error_map[VALIDATION_ERROR_14a004da]);
1094 }
1095
1096 if (vertex_attrib_desc.offset > device_data->device_limits.maxVertexInputAttributeOffset) {
1097 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1098 __LINE__, VALIDATION_ERROR_14a004dc, LayerName,
1099 "vkCreateGraphicsPipelines: parameter "
1100 "pCreateInfos[%u].pVertexInputState->pVertexAttributeDescriptions[%u].offset (%u) is "
1101 "greater than VkPhysicalDeviceLimits::maxVertexInputAttributeOffset (%u). %s",
1102 i, d, vertex_attrib_desc.offset, device_data->device_limits.maxVertexInputAttributeOffset,
1103 validation_error_map[VALIDATION_ERROR_14a004dc]);
1104 }
1105 }
1106 }
1107
1108 if (pCreateInfos[i].pStages != nullptr) {
1109 bool has_control = false;
1110 bool has_eval = false;
1111
1112 for (uint32_t stage_index = 0; stage_index < pCreateInfos[i].stageCount; ++stage_index) {
1113 if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT) {
1114 has_control = true;
1115 } else if (pCreateInfos[i].pStages[stage_index].stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) {
1116 has_eval = true;
1117 }
1118 }
1119
1120 // pTessellationState is ignored without both tessellation control and tessellation evaluation shaders stages
1121 if (has_control && has_eval) {
1122 if (pCreateInfos[i].pTessellationState == nullptr) {
1123 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1124 __LINE__, VALIDATION_ERROR_096005b6, LayerName,
1125 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pStages includes a tessellation control "
1126 "shader stage and a tessellation evaluation shader stage, "
1127 "pCreateInfos[%d].pTessellationState must not be NULL. %s",
1128 i, i, validation_error_map[VALIDATION_ERROR_096005b6]);
1129 } else {
1130 skip |= validate_struct_pnext(
1131 report_data, "vkCreateGraphicsPipelines",
1132 ParameterName("pCreateInfos[%i].pTessellationState->pNext", ParameterName::IndexVector{i}), NULL,
1133 pCreateInfos[i].pTessellationState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0961c40d);
1134
1135 skip |= validate_reserved_flags(
1136 report_data, "vkCreateGraphicsPipelines",
1137 ParameterName("pCreateInfos[%i].pTessellationState->flags", ParameterName::IndexVector{i}),
1138 pCreateInfos[i].pTessellationState->flags, VALIDATION_ERROR_10809005);
1139
1140 if (pCreateInfos[i].pTessellationState->sType !=
1141 VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO) {
1142 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1143 __LINE__, VALIDATION_ERROR_1082b00b, LayerName,
1144 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pTessellationState->sType must "
1145 "be VK_STRUCTURE_TYPE_PIPELINE_TESSELLATION_STATE_CREATE_INFO. %s",
1146 i, validation_error_map[VALIDATION_ERROR_1082b00b]);
1147 }
1148
1149 if (pCreateInfos[i].pTessellationState->patchControlPoints == 0 ||
1150 pCreateInfos[i].pTessellationState->patchControlPoints >
1151 device_data->device_limits.maxTessellationPatchSize) {
1152 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1153 __LINE__, VALIDATION_ERROR_1080097c, LayerName,
1154 "vkCreateGraphicsPipelines: invalid parameter "
1155 "pCreateInfos[%d].pTessellationState->patchControlPoints value %u. patchControlPoints "
1156 "should be >0 and <=%u. %s",
1157 i, pCreateInfos[i].pTessellationState->patchControlPoints,
1158 device_data->device_limits.maxTessellationPatchSize,
1159 validation_error_map[VALIDATION_ERROR_1080097c]);
1160 }
1161 }
1162 }
1163 }
1164
1165 // pViewportState, pMultisampleState, pDepthStencilState, and pColorBlendState ignored when rasterization is disabled
1166 if ((pCreateInfos[i].pRasterizationState != nullptr) &&
1167 (pCreateInfos[i].pRasterizationState->rasterizerDiscardEnable == VK_FALSE)) {
1168 if (pCreateInfos[i].pViewportState == nullptr) {
Petr Krausa6103552017-11-16 21:21:58 +01001169 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1170 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_096005dc, LayerName,
1171 "vkCreateGraphicsPipelines: Rasterization is enabled (pCreateInfos[%" PRIu32
1172 "].pRasterizationState->rasterizerDiscardEnable is VK_FALSE), but pCreateInfos[%" PRIu32
1173 "].pViewportState (=NULL) is not a valid pointer. %s",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001174 i, i, validation_error_map[VALIDATION_ERROR_096005dc]);
1175 } else {
Petr Krausa6103552017-11-16 21:21:58 +01001176 const auto &viewport_state = *pCreateInfos[i].pViewportState;
1177
1178 if (viewport_state.sType != VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO) {
1179 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1180 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c2b00b, LayerName,
1181 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1182 "].pViewportState->sType is not VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO. %s",
1183 i, validation_error_map[VALIDATION_ERROR_10c2b00b]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001184 }
1185
Petr Krausa6103552017-11-16 21:21:58 +01001186 const VkStructureType allowed_structs_VkPipelineViewportStateCreateInfo[] = {
1187 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_SWIZZLE_STATE_CREATE_INFO_NV,
1188 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_W_SCALING_STATE_CREATE_INFO_NV};
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001189 skip |= validate_struct_pnext(
1190 report_data, "vkCreateGraphicsPipelines",
Petr Krausa6103552017-11-16 21:21:58 +01001191 ParameterName("pCreateInfos[%i].pViewportState->pNext", ParameterName::IndexVector{i}),
1192 "VkPipelineViewportSwizzleStateCreateInfoNV, VkPipelineViewportWScalingStateCreateInfoNV",
1193 viewport_state.pNext, ARRAY_SIZE(allowed_structs_VkPipelineViewportStateCreateInfo),
1194 allowed_structs_VkPipelineViewportStateCreateInfo, 65, VALIDATION_ERROR_10c1c40d);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001195
1196 skip |= validate_reserved_flags(
1197 report_data, "vkCreateGraphicsPipelines",
1198 ParameterName("pCreateInfos[%i].pViewportState->flags", ParameterName::IndexVector{i}),
Petr Krausa6103552017-11-16 21:21:58 +01001199 viewport_state.flags, VALIDATION_ERROR_10c09005);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001200
Petr Krausa6103552017-11-16 21:21:58 +01001201 if (!device_data->physical_device_features.multiViewport) {
1202 if (viewport_state.viewportCount != 1) {
1203 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1204 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00980, LayerName,
1205 "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
1206 "disabled, but pCreateInfos[%" PRIu32 "].pViewportState->viewportCount (=%" PRIu32
1207 ") is not 1. %s",
1208 i, viewport_state.viewportCount, validation_error_map[VALIDATION_ERROR_10c00980]);
1209 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001210
Petr Krausa6103552017-11-16 21:21:58 +01001211 if (viewport_state.scissorCount != 1) {
1212 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1213 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00982, LayerName,
1214 "vkCreateGraphicsPipelines: The VkPhysicalDeviceFeatures::multiViewport feature is "
1215 "disabled, but pCreateInfos[%" PRIu32 "].pViewportState->scissorCount (=%" PRIu32
1216 ") is not 1. %s",
1217 i, viewport_state.scissorCount, validation_error_map[VALIDATION_ERROR_10c00982]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001218 }
Petr Krausa6103552017-11-16 21:21:58 +01001219 } else { // multiViewport enabled
1220 if (viewport_state.viewportCount == 0) {
1221 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1222 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c30a1b, LayerName,
Petr Krausf62dd8f2017-11-23 15:47:38 +01001223 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Petr Krausa6103552017-11-16 21:21:58 +01001224 "].pViewportState->viewportCount is 0. %s",
1225 i, validation_error_map[VALIDATION_ERROR_10c30a1b]);
1226 } else if (viewport_state.viewportCount > device_data->device_limits.maxViewports) {
1227 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1228 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00984, LayerName,
1229 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1230 "].pViewportState->viewportCount (=%" PRIu32
1231 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
1232 i, viewport_state.viewportCount, device_data->device_limits.maxViewports,
1233 validation_error_map[VALIDATION_ERROR_10c00984]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001234 }
Petr Krausa6103552017-11-16 21:21:58 +01001235
1236 if (viewport_state.scissorCount == 0) {
1237 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1238 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c2b61b, LayerName,
Petr Krausf62dd8f2017-11-23 15:47:38 +01001239 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
Petr Krausa6103552017-11-16 21:21:58 +01001240 "].pViewportState->scissorCount is 0. %s",
1241 i, validation_error_map[VALIDATION_ERROR_10c2b61b]);
1242 } else if (viewport_state.scissorCount > device_data->device_limits.maxViewports) {
1243 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1244 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00986, LayerName,
1245 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1246 "].pViewportState->scissorCount (=%" PRIu32
1247 ") is greater than VkPhysicalDeviceLimits::maxViewports (=%" PRIu32 "). %s",
1248 i, viewport_state.scissorCount, device_data->device_limits.maxViewports,
1249 validation_error_map[VALIDATION_ERROR_10c00986]);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001250 }
1251 }
1252
Petr Krausa6103552017-11-16 21:21:58 +01001253 if (viewport_state.scissorCount != viewport_state.viewportCount) {
1254 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1255 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_10c00988, LayerName,
1256 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1257 "].pViewportState->scissorCount (=%" PRIu32 ") is not identical to pCreateInfos[%" PRIu32
1258 "].pViewportState->viewportCount (=%" PRIu32 "). %s",
1259 i, viewport_state.scissorCount, i, viewport_state.viewportCount,
1260 validation_error_map[VALIDATION_ERROR_10c00988]);
1261 }
1262
Petr Krausa6103552017-11-16 21:21:58 +01001263 if (!has_dynamic_viewport && viewport_state.viewportCount > 0 && viewport_state.pViewports == nullptr) {
1264 skip |= log_msg(
1265 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, VK_NULL_HANDLE,
1266 __LINE__, VALIDATION_ERROR_096005d6, LayerName,
1267 "vkCreateGraphicsPipelines: The viewport state is static (pCreateInfos[%" PRIu32
1268 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_VIEWPORT), but pCreateInfos[%" PRIu32
Petr Krausf62dd8f2017-11-23 15:47:38 +01001269 "].pViewportState->pViewports (=NULL) is an invalid pointer. %s",
Petr Krausa6103552017-11-16 21:21:58 +01001270 i, i, validation_error_map[VALIDATION_ERROR_096005d6]);
1271 }
1272
1273 if (!has_dynamic_scissor && viewport_state.scissorCount > 0 && viewport_state.pScissors == nullptr) {
1274 skip |= log_msg(
1275 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, VK_NULL_HANDLE,
1276 __LINE__, VALIDATION_ERROR_096005d8, LayerName,
1277 "vkCreateGraphicsPipelines: The scissor state is static (pCreateInfos[%" PRIu32
1278 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_SCISSOR), but pCreateInfos[%" PRIu32
Petr Krausf62dd8f2017-11-23 15:47:38 +01001279 "].pViewportState->pScissors (=NULL) is an invalid pointer. %s",
Petr Krausa6103552017-11-16 21:21:58 +01001280 i, i, validation_error_map[VALIDATION_ERROR_096005d8]);
1281 }
1282
1283 // TODO: validate the VkViewports in pViewports here
Jeremy Kniager71fd5f02017-11-15 13:27:03 -07001284
1285 if (has_dynamic_viewport_w_scaling_nv && !device_data->extensions.vk_nv_clip_space_w_scaling) {
1286 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1287 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1288 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1289 "].pDynamicState->pDynamicStates "
1290 "contains VK_DYNAMIC_STATE_VIEWPORT_W_SCALING_NV, but "
1291 "VK_NV_clip_space_w_scaling extension is not enabled.",
1292 i);
1293 }
1294
1295 if (has_dynamic_discard_rectangle_ext && !device_data->extensions.vk_ext_discard_rectangles) {
1296 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1297 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1298 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1299 "].pDynamicState->pDynamicStates "
1300 "contains VK_DYNAMIC_STATE_DISCARD_RECTANGLE_EXT, but "
1301 "VK_EXT_discard_rectangles extension is not enabled.",
1302 i);
1303 }
1304
1305 if (has_dynamic_sample_locations_ext && !device_data->extensions.vk_ext_sample_locations) {
1306 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT,
1307 VK_NULL_HANDLE, __LINE__, EXTENSION_NOT_ENABLED, LayerName,
1308 "vkCreateGraphicsPipelines: pCreateInfos[%" PRIu32
1309 "].pDynamicState->pDynamicStates "
1310 "contains VK_DYNAMIC_STATE_SAMPLE_LOCATIONS_EXT, but "
1311 "VK_EXT_sample_locations extension is not enabled.",
1312 i);
1313 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001314 }
1315
1316 if (pCreateInfos[i].pMultisampleState == nullptr) {
1317 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1318 __LINE__, VALIDATION_ERROR_096005de, LayerName,
1319 "vkCreateGraphicsPipelines: if pCreateInfos[%d].pRasterizationState->rasterizerDiscardEnable "
1320 "is VK_FALSE, pCreateInfos[%d].pMultisampleState must not be NULL. %s",
1321 i, i, validation_error_map[VALIDATION_ERROR_096005de]);
1322 } else {
Dave Houltonb3bbec72018-01-17 10:13:33 -07001323 const VkStructureType valid_next_stypes[] = {LvlTypeMap<VkPipelineCoverageModulationStateCreateInfoNV>::kSType,
1324 LvlTypeMap<VkPipelineCoverageToColorStateCreateInfoNV>::kSType,
1325 LvlTypeMap<VkPipelineSampleLocationsStateCreateInfoEXT>::kSType};
Mike Schuchardt97662b02017-12-06 13:31:29 -07001326 const char *valid_struct_names =
John Zulauf96b0e422017-11-14 11:43:19 -07001327 "VkPipelineCoverageModulationStateCreateInfoNV, "
1328 "VkPipelineCoverageToColorStateCreateInfoNV, "
1329 "VkPipelineSampleLocationsStateCreateInfoEXT";
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001330 skip |= validate_struct_pnext(
1331 report_data, "vkCreateGraphicsPipelines",
John Zulauf96b0e422017-11-14 11:43:19 -07001332 ParameterName("pCreateInfos[%i].pMultisampleState->pNext", ParameterName::IndexVector{i}),
1333 valid_struct_names, pCreateInfos[i].pMultisampleState->pNext, 3, valid_next_stypes, GeneratedHeaderVersion,
1334 VALIDATION_ERROR_1001c40d);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001335
1336 skip |= validate_reserved_flags(
1337 report_data, "vkCreateGraphicsPipelines",
1338 ParameterName("pCreateInfos[%i].pMultisampleState->flags", ParameterName::IndexVector{i}),
1339 pCreateInfos[i].pMultisampleState->flags, VALIDATION_ERROR_10009005);
1340
1341 skip |= validate_bool32(
1342 report_data, "vkCreateGraphicsPipelines",
1343 ParameterName("pCreateInfos[%i].pMultisampleState->sampleShadingEnable", ParameterName::IndexVector{i}),
1344 pCreateInfos[i].pMultisampleState->sampleShadingEnable);
1345
1346 skip |= validate_array(
1347 report_data, "vkCreateGraphicsPipelines",
1348 ParameterName("pCreateInfos[%i].pMultisampleState->rasterizationSamples", ParameterName::IndexVector{i}),
1349 ParameterName("pCreateInfos[%i].pMultisampleState->pSampleMask", ParameterName::IndexVector{i}),
1350 pCreateInfos[i].pMultisampleState->rasterizationSamples, pCreateInfos[i].pMultisampleState->pSampleMask,
1351 true, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1352
1353 skip |= validate_bool32(
1354 report_data, "vkCreateGraphicsPipelines",
1355 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToCoverageEnable", ParameterName::IndexVector{i}),
1356 pCreateInfos[i].pMultisampleState->alphaToCoverageEnable);
1357
1358 skip |= validate_bool32(
1359 report_data, "vkCreateGraphicsPipelines",
1360 ParameterName("pCreateInfos[%i].pMultisampleState->alphaToOneEnable", ParameterName::IndexVector{i}),
1361 pCreateInfos[i].pMultisampleState->alphaToOneEnable);
1362
1363 if (pCreateInfos[i].pMultisampleState->sType != VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO) {
1364 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1365 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1366 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pMultisampleState->sType must be "
1367 "VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO",
1368 i);
1369 }
John Zulauf7acac592017-11-06 11:15:53 -07001370 if (pCreateInfos[i].pMultisampleState->sampleShadingEnable == VK_TRUE) {
1371 if (!device_data->physical_device_features.sampleRateShading) {
1372 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1373 __LINE__, VALIDATION_ERROR_10000620, LayerName,
1374 "vkCreateGraphicsPipelines(): parameter "
1375 "pCreateInfos[%d].pMultisampleState->sampleShadingEnable: %s",
1376 i, validation_error_map[VALIDATION_ERROR_10000620]);
1377 }
1378 // TODO Add documentation issue about when minSampleShading must be in range and when it is ignored
1379 // For now a "least noise" test *only* when sampleShadingEnable is VK_TRUE.
1380 if (!in_inclusive_range(pCreateInfos[i].pMultisampleState->minSampleShading, 0.F, 1.0F)) {
1381 skip |= log_msg(
1382 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1383 VALIDATION_ERROR_10000624, LayerName,
1384 "vkCreateGraphicsPipelines(): parameter pCreateInfos[%d].pMultisampleState->minSampleShading: %s",
1385 i, validation_error_map[VALIDATION_ERROR_10000624]);
1386 }
1387 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001388 }
1389
Petr Krause91f7a12017-12-14 20:57:36 +01001390 bool uses_color_attachment = false;
1391 bool uses_depthstencil_attachment = false;
1392 {
1393 const auto subpasses_uses_it = device_data->renderpasses_states.find(pCreateInfos[i].renderPass);
1394 if (subpasses_uses_it != device_data->renderpasses_states.end()) {
1395 const auto &subpasses_uses = subpasses_uses_it->second;
1396 if (subpasses_uses.subpasses_using_color_attachment.count(pCreateInfos[i].subpass))
1397 uses_color_attachment = true;
1398 if (subpasses_uses.subpasses_using_depthstencil_attachment.count(pCreateInfos[i].subpass))
1399 uses_depthstencil_attachment = true;
1400 }
1401 }
1402
1403 if (pCreateInfos[i].pDepthStencilState != nullptr && uses_depthstencil_attachment) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001404 skip |= validate_struct_pnext(
1405 report_data, "vkCreateGraphicsPipelines",
1406 ParameterName("pCreateInfos[%i].pDepthStencilState->pNext", ParameterName::IndexVector{i}), NULL,
1407 pCreateInfos[i].pDepthStencilState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f61c40d);
1408
1409 skip |= validate_reserved_flags(
1410 report_data, "vkCreateGraphicsPipelines",
1411 ParameterName("pCreateInfos[%i].pDepthStencilState->flags", ParameterName::IndexVector{i}),
1412 pCreateInfos[i].pDepthStencilState->flags, VALIDATION_ERROR_0f609005);
1413
1414 skip |= validate_bool32(
1415 report_data, "vkCreateGraphicsPipelines",
1416 ParameterName("pCreateInfos[%i].pDepthStencilState->depthTestEnable", ParameterName::IndexVector{i}),
1417 pCreateInfos[i].pDepthStencilState->depthTestEnable);
1418
1419 skip |= validate_bool32(
1420 report_data, "vkCreateGraphicsPipelines",
1421 ParameterName("pCreateInfos[%i].pDepthStencilState->depthWriteEnable", ParameterName::IndexVector{i}),
1422 pCreateInfos[i].pDepthStencilState->depthWriteEnable);
1423
1424 skip |= validate_ranged_enum(
1425 report_data, "vkCreateGraphicsPipelines",
1426 ParameterName("pCreateInfos[%i].pDepthStencilState->depthCompareOp", ParameterName::IndexVector{i}),
1427 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->depthCompareOp,
1428 VALIDATION_ERROR_0f604001);
1429
1430 skip |= validate_bool32(
1431 report_data, "vkCreateGraphicsPipelines",
1432 ParameterName("pCreateInfos[%i].pDepthStencilState->depthBoundsTestEnable", ParameterName::IndexVector{i}),
1433 pCreateInfos[i].pDepthStencilState->depthBoundsTestEnable);
1434
1435 skip |= validate_bool32(
1436 report_data, "vkCreateGraphicsPipelines",
1437 ParameterName("pCreateInfos[%i].pDepthStencilState->stencilTestEnable", ParameterName::IndexVector{i}),
1438 pCreateInfos[i].pDepthStencilState->stencilTestEnable);
1439
1440 skip |= validate_ranged_enum(
1441 report_data, "vkCreateGraphicsPipelines",
1442 ParameterName("pCreateInfos[%i].pDepthStencilState->front.failOp", ParameterName::IndexVector{i}),
1443 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.failOp,
1444 VALIDATION_ERROR_13a08601);
1445
1446 skip |= validate_ranged_enum(
1447 report_data, "vkCreateGraphicsPipelines",
1448 ParameterName("pCreateInfos[%i].pDepthStencilState->front.passOp", ParameterName::IndexVector{i}),
1449 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.passOp,
1450 VALIDATION_ERROR_13a27801);
1451
1452 skip |= validate_ranged_enum(
1453 report_data, "vkCreateGraphicsPipelines",
1454 ParameterName("pCreateInfos[%i].pDepthStencilState->front.depthFailOp", ParameterName::IndexVector{i}),
1455 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->front.depthFailOp,
1456 VALIDATION_ERROR_13a04201);
1457
1458 skip |= validate_ranged_enum(
1459 report_data, "vkCreateGraphicsPipelines",
1460 ParameterName("pCreateInfos[%i].pDepthStencilState->front.compareOp", ParameterName::IndexVector{i}),
1461 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->front.compareOp,
1462 VALIDATION_ERROR_0f604001);
1463
1464 skip |= validate_ranged_enum(
1465 report_data, "vkCreateGraphicsPipelines",
1466 ParameterName("pCreateInfos[%i].pDepthStencilState->back.failOp", ParameterName::IndexVector{i}),
1467 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.failOp,
1468 VALIDATION_ERROR_13a08601);
1469
1470 skip |= validate_ranged_enum(
1471 report_data, "vkCreateGraphicsPipelines",
1472 ParameterName("pCreateInfos[%i].pDepthStencilState->back.passOp", ParameterName::IndexVector{i}),
1473 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.passOp,
1474 VALIDATION_ERROR_13a27801);
1475
1476 skip |= validate_ranged_enum(
1477 report_data, "vkCreateGraphicsPipelines",
1478 ParameterName("pCreateInfos[%i].pDepthStencilState->back.depthFailOp", ParameterName::IndexVector{i}),
1479 "VkStencilOp", AllVkStencilOpEnums, pCreateInfos[i].pDepthStencilState->back.depthFailOp,
1480 VALIDATION_ERROR_13a04201);
1481
1482 skip |= validate_ranged_enum(
1483 report_data, "vkCreateGraphicsPipelines",
1484 ParameterName("pCreateInfos[%i].pDepthStencilState->back.compareOp", ParameterName::IndexVector{i}),
1485 "VkCompareOp", AllVkCompareOpEnums, pCreateInfos[i].pDepthStencilState->back.compareOp,
1486 VALIDATION_ERROR_0f604001);
1487
1488 if (pCreateInfos[i].pDepthStencilState->sType != VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO) {
1489 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1490 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1491 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pDepthStencilState->sType must be "
1492 "VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO",
1493 i);
1494 }
1495 }
1496
Petr Krause91f7a12017-12-14 20:57:36 +01001497 if (pCreateInfos[i].pColorBlendState != nullptr && uses_color_attachment) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001498 skip |= validate_struct_pnext(
1499 report_data, "vkCreateGraphicsPipelines",
1500 ParameterName("pCreateInfos[%i].pColorBlendState->pNext", ParameterName::IndexVector{i}), NULL,
1501 pCreateInfos[i].pColorBlendState->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0f41c40d);
1502
1503 skip |= validate_reserved_flags(
1504 report_data, "vkCreateGraphicsPipelines",
1505 ParameterName("pCreateInfos[%i].pColorBlendState->flags", ParameterName::IndexVector{i}),
1506 pCreateInfos[i].pColorBlendState->flags, VALIDATION_ERROR_0f409005);
1507
1508 skip |= validate_bool32(
1509 report_data, "vkCreateGraphicsPipelines",
1510 ParameterName("pCreateInfos[%i].pColorBlendState->logicOpEnable", ParameterName::IndexVector{i}),
1511 pCreateInfos[i].pColorBlendState->logicOpEnable);
1512
1513 skip |= validate_array(
1514 report_data, "vkCreateGraphicsPipelines",
1515 ParameterName("pCreateInfos[%i].pColorBlendState->attachmentCount", ParameterName::IndexVector{i}),
1516 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments", ParameterName::IndexVector{i}),
1517 pCreateInfos[i].pColorBlendState->attachmentCount, pCreateInfos[i].pColorBlendState->pAttachments, false,
1518 true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1519
1520 if (pCreateInfos[i].pColorBlendState->pAttachments != NULL) {
1521 for (uint32_t attachmentIndex = 0; attachmentIndex < pCreateInfos[i].pColorBlendState->attachmentCount;
1522 ++attachmentIndex) {
1523 skip |= validate_bool32(report_data, "vkCreateGraphicsPipelines",
1524 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].blendEnable",
1525 ParameterName::IndexVector{i, attachmentIndex}),
1526 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].blendEnable);
1527
1528 skip |= validate_ranged_enum(
1529 report_data, "vkCreateGraphicsPipelines",
1530 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcColorBlendFactor",
1531 ParameterName::IndexVector{i, attachmentIndex}),
1532 "VkBlendFactor", AllVkBlendFactorEnums,
1533 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcColorBlendFactor,
1534 VALIDATION_ERROR_0f22cc01);
1535
1536 skip |= validate_ranged_enum(
1537 report_data, "vkCreateGraphicsPipelines",
1538 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstColorBlendFactor",
1539 ParameterName::IndexVector{i, attachmentIndex}),
1540 "VkBlendFactor", AllVkBlendFactorEnums,
1541 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstColorBlendFactor,
1542 VALIDATION_ERROR_0f207001);
1543
1544 skip |= validate_ranged_enum(
1545 report_data, "vkCreateGraphicsPipelines",
1546 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorBlendOp",
1547 ParameterName::IndexVector{i, attachmentIndex}),
1548 "VkBlendOp", AllVkBlendOpEnums,
1549 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorBlendOp,
1550 VALIDATION_ERROR_0f202001);
1551
1552 skip |= validate_ranged_enum(
1553 report_data, "vkCreateGraphicsPipelines",
1554 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].srcAlphaBlendFactor",
1555 ParameterName::IndexVector{i, attachmentIndex}),
1556 "VkBlendFactor", AllVkBlendFactorEnums,
1557 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].srcAlphaBlendFactor,
1558 VALIDATION_ERROR_0f22c601);
1559
1560 skip |= validate_ranged_enum(
1561 report_data, "vkCreateGraphicsPipelines",
1562 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].dstAlphaBlendFactor",
1563 ParameterName::IndexVector{i, attachmentIndex}),
1564 "VkBlendFactor", AllVkBlendFactorEnums,
1565 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].dstAlphaBlendFactor,
1566 VALIDATION_ERROR_0f206a01);
1567
1568 skip |= validate_ranged_enum(
1569 report_data, "vkCreateGraphicsPipelines",
1570 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].alphaBlendOp",
1571 ParameterName::IndexVector{i, attachmentIndex}),
1572 "VkBlendOp", AllVkBlendOpEnums,
1573 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].alphaBlendOp,
1574 VALIDATION_ERROR_0f200801);
1575
1576 skip |=
1577 validate_flags(report_data, "vkCreateGraphicsPipelines",
1578 ParameterName("pCreateInfos[%i].pColorBlendState->pAttachments[%i].colorWriteMask",
1579 ParameterName::IndexVector{i, attachmentIndex}),
1580 "VkColorComponentFlagBits", AllVkColorComponentFlagBits,
1581 pCreateInfos[i].pColorBlendState->pAttachments[attachmentIndex].colorWriteMask,
1582 false, false, VALIDATION_ERROR_0f202201);
1583 }
1584 }
1585
1586 if (pCreateInfos[i].pColorBlendState->sType != VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO) {
1587 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1588 __LINE__, INVALID_STRUCT_STYPE, LayerName,
1589 "vkCreateGraphicsPipelines: parameter pCreateInfos[%d].pColorBlendState->sType must be "
1590 "VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO",
1591 i);
1592 }
1593
1594 // If logicOpEnable is VK_TRUE, logicOp must be a valid VkLogicOp value
1595 if (pCreateInfos[i].pColorBlendState->logicOpEnable == VK_TRUE) {
1596 skip |= validate_ranged_enum(
1597 report_data, "vkCreateGraphicsPipelines",
1598 ParameterName("pCreateInfos[%i].pColorBlendState->logicOp", ParameterName::IndexVector{i}), "VkLogicOp",
1599 AllVkLogicOpEnums, pCreateInfos[i].pColorBlendState->logicOp, VALIDATION_ERROR_0f4004be);
1600 }
1601 }
1602 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001603
Petr Kraus9752aae2017-11-24 03:05:50 +01001604 if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_DERIVATIVE_BIT) {
1605 if (pCreateInfos[i].basePipelineIndex != -1) {
1606 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001607 skip |= log_msg(
1608 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1609 VALIDATION_ERROR_096005a8, LayerName,
1610 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineHandle, must be VK_NULL_HANDLE if "
1611 "pCreateInfos->flags "
1612 "contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag and pCreateInfos->basePipelineIndex is not -1. %s",
1613 validation_error_map[VALIDATION_ERROR_096005a8]);
1614 }
1615 }
1616
Petr Kraus9752aae2017-11-24 03:05:50 +01001617 if (pCreateInfos[i].basePipelineHandle != VK_NULL_HANDLE) {
1618 if (pCreateInfos[i].basePipelineIndex != -1) {
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001619 skip |= log_msg(
1620 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1621 VALIDATION_ERROR_096005aa, LayerName,
1622 "vkCreateGraphicsPipelines parameter, pCreateInfos->basePipelineIndex, must be -1 if "
1623 "pCreateInfos->flags "
1624 "contains the VK_PIPELINE_CREATE_DERIVATIVE_BIT flag and pCreateInfos->basePipelineHandle is not "
1625 "VK_NULL_HANDLE. %s",
1626 validation_error_map[VALIDATION_ERROR_096005aa]);
1627 }
1628 }
1629 }
1630
Petr Kraus9752aae2017-11-24 03:05:50 +01001631 if (pCreateInfos[i].pRasterizationState) {
1632 if ((pCreateInfos[i].pRasterizationState->polygonMode != VK_POLYGON_MODE_FILL) &&
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001633 (device_data->physical_device_features.fillModeNonSolid == false)) {
1634 skip |= log_msg(
1635 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1636 DEVICE_FEATURE, LayerName,
1637 "vkCreateGraphicsPipelines parameter, VkPolygonMode pCreateInfos->pRasterizationState->polygonMode cannot "
1638 "be "
1639 "VK_POLYGON_MODE_POINT or VK_POLYGON_MODE_LINE if VkPhysicalDeviceFeatures->fillModeNonSolid is false.");
1640 }
Petr Kraus299ba622017-11-24 03:09:03 +01001641
1642 if (!has_dynamic_line_width && !device_data->physical_device_features.wideLines &&
1643 (pCreateInfos[i].pRasterizationState->lineWidth != 1.0f)) {
1644 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1645 VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, 0, __LINE__, VALIDATION_ERROR_096005da, LayerName,
1646 "The line width state is static (pCreateInfos[%" PRIu32
1647 "].pDynamicState->pDynamicStates does not contain VK_DYNAMIC_STATE_LINE_WIDTH) and "
1648 "VkPhysicalDeviceFeatures::wideLines is disabled, but pCreateInfos[%" PRIu32
1649 "].pRasterizationState->lineWidth (=%f) is not 1.0. %s",
1650 i, i, pCreateInfos[i].pRasterizationState->lineWidth,
1651 validation_error_map[VALIDATION_ERROR_096005da]);
1652 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001653 }
1654
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001655 for (size_t j = 0; j < pCreateInfos[i].stageCount; j++) {
1656 skip |= validate_string(device_data->report_data, "vkCreateGraphicsPipelines",
1657 ParameterName("pCreateInfos[%i].pStages[%i].pName", ParameterName::IndexVector{i, j}),
1658 pCreateInfos[i].pStages[j].pName);
1659 }
1660 }
1661 }
1662
1663 return skip;
1664}
1665
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001666bool pv_vkCreateComputePipelines(VkDevice device, VkPipelineCache pipelineCache, uint32_t createInfoCount,
1667 const VkComputePipelineCreateInfo *pCreateInfos, const VkAllocationCallbacks *pAllocator,
1668 VkPipeline *pPipelines) {
1669 bool skip = false;
1670 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1671
1672 for (uint32_t i = 0; i < createInfoCount; i++) {
1673 skip |= validate_string(device_data->report_data, "vkCreateComputePipelines",
1674 ParameterName("pCreateInfos[%i].stage.pName", ParameterName::IndexVector{i}),
1675 pCreateInfos[i].stage.pName);
1676 }
1677
1678 return skip;
1679}
1680
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001681bool pv_vkCreateSampler(VkDevice device, const VkSamplerCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1682 VkSampler *pSampler) {
1683 bool skip = false;
1684 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1685 debug_report_data *report_data = device_data->report_data;
1686
1687 if (pCreateInfo != nullptr) {
John Zulauf71968502017-10-26 13:51:15 -06001688 const auto &features = device_data->physical_device_features;
1689 const auto &limits = device_data->device_limits;
1690 if (pCreateInfo->anisotropyEnable == VK_TRUE) {
1691 if (!in_inclusive_range(pCreateInfo->maxAnisotropy, 1.0F, limits.maxSamplerAnisotropy)) {
1692 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1693 VALIDATION_ERROR_1260085e, LayerName,
1694 "vkCreateSampler(): value of %s must be in range [1.0, %f] %s, but %f found. %s",
1695 "pCreateInfo->maxAnisotropy", limits.maxSamplerAnisotropy,
1696 "VkPhysicalDeviceLimits::maxSamplerAnistropy", pCreateInfo->maxAnisotropy,
1697 validation_error_map[VALIDATION_ERROR_1260085e]);
1698 }
1699
1700 // Anistropy cannot be enabled in sampler unless enabled as a feature
1701 if (features.samplerAnisotropy == VK_FALSE) {
1702 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1703 VALIDATION_ERROR_1260085c, LayerName,
1704 "vkCreateSampler(): Anisotropic sampling feature is not enabled, %s must be VK_FALSE. %s",
1705 "pCreateInfo->anisotropyEnable", validation_error_map[VALIDATION_ERROR_1260085c]);
1706 }
1707
1708 // Anistropy and unnormalized coordinates cannot be enabled simultaneously
1709 if (pCreateInfo->unnormalizedCoordinates == VK_TRUE) {
1710 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1711 VALIDATION_ERROR_12600868, LayerName,
1712 "vkCreateSampler(): pCreateInfo->anisotropyEnable and pCreateInfo->unnormalizedCoordinates "
1713 "must not both be VK_TRUE. %s",
1714 validation_error_map[VALIDATION_ERROR_12600868]);
1715 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001716 }
1717
1718 // If compareEnable is VK_TRUE, compareOp must be a valid VkCompareOp value
1719 if (pCreateInfo->compareEnable == VK_TRUE) {
1720 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->compareOp", "VkCompareOp",
1721 AllVkCompareOpEnums, pCreateInfo->compareOp, VALIDATION_ERROR_12600870);
1722 }
1723
1724 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, borderColor must be a
1725 // valid VkBorderColor value
1726 if ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
1727 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER) ||
1728 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)) {
1729 skip |= validate_ranged_enum(report_data, "vkCreateSampler", "pCreateInfo->borderColor", "VkBorderColor",
1730 AllVkBorderColorEnums, pCreateInfo->borderColor, VALIDATION_ERROR_1260086c);
1731 }
1732
1733 // If any of addressModeU, addressModeV or addressModeW are VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE, the
1734 // VK_KHR_sampler_mirror_clamp_to_edge extension must be enabled
1735 if (!device_data->extensions.vk_khr_sampler_mirror_clamp_to_edge &&
1736 ((pCreateInfo->addressModeU == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
1737 (pCreateInfo->addressModeV == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE) ||
1738 (pCreateInfo->addressModeW == VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE))) {
1739 skip |=
1740 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1741 VALIDATION_ERROR_1260086e, LayerName,
1742 "vkCreateSampler(): A VkSamplerAddressMode value is set to VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE "
1743 "but the VK_KHR_sampler_mirror_clamp_to_edge extension has not been enabled. %s",
1744 validation_error_map[VALIDATION_ERROR_1260086e]);
1745 }
John Zulauf275805c2017-10-26 15:34:49 -06001746
1747 // Checks for the IMG cubic filtering extension
1748 if (device_data->extensions.vk_img_filter_cubic) {
1749 if ((pCreateInfo->anisotropyEnable == VK_TRUE) &&
1750 ((pCreateInfo->minFilter == VK_FILTER_CUBIC_IMG) || (pCreateInfo->magFilter == VK_FILTER_CUBIC_IMG))) {
1751 skip |=
1752 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1753 VALIDATION_ERROR_12600872, LayerName,
1754 "vkCreateSampler(): Anisotropic sampling must not be VK_TRUE when either minFilter or magFilter are "
1755 "VK_FILTER_CUBIC_IMG. %s",
1756 validation_error_map[VALIDATION_ERROR_12600872]);
1757 }
1758 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001759 }
1760
1761 return skip;
1762}
1763
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001764bool pv_vkCreateDescriptorSetLayout(VkDevice device, const VkDescriptorSetLayoutCreateInfo *pCreateInfo,
1765 const VkAllocationCallbacks *pAllocator, VkDescriptorSetLayout *pSetLayout) {
1766 bool skip = false;
1767 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1768 debug_report_data *report_data = device_data->report_data;
1769
1770 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1771 if ((pCreateInfo != nullptr) && (pCreateInfo->pBindings != nullptr)) {
1772 for (uint32_t i = 0; i < pCreateInfo->bindingCount; ++i) {
1773 if (pCreateInfo->pBindings[i].descriptorCount != 0) {
1774 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER or VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, and descriptorCount
1775 // is not 0 and pImmutableSamplers is not NULL, pImmutableSamplers must be a pointer to an array of descriptorCount
1776 // valid VkSampler handles
1777 if (((pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
1778 (pCreateInfo->pBindings[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)) &&
1779 (pCreateInfo->pBindings[i].pImmutableSamplers != nullptr)) {
1780 for (uint32_t descriptor_index = 0; descriptor_index < pCreateInfo->pBindings[i].descriptorCount;
1781 ++descriptor_index) {
1782 if (pCreateInfo->pBindings[i].pImmutableSamplers[descriptor_index] == VK_NULL_HANDLE) {
1783 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1784 __LINE__, REQUIRED_PARAMETER, LayerName,
1785 "vkCreateDescriptorSetLayout: required parameter "
1786 "pCreateInfo->pBindings[%d].pImmutableSamplers[%d]"
1787 " specified as VK_NULL_HANDLE",
1788 i, descriptor_index);
1789 }
1790 }
1791 }
1792
1793 // If descriptorCount is not 0, stageFlags must be a valid combination of VkShaderStageFlagBits values
1794 if ((pCreateInfo->pBindings[i].stageFlags != 0) &&
1795 ((pCreateInfo->pBindings[i].stageFlags & (~AllVkShaderStageFlagBits)) != 0)) {
1796 skip |= log_msg(
1797 report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1798 VALIDATION_ERROR_04e00236, LayerName,
1799 "vkCreateDescriptorSetLayout(): if pCreateInfo->pBindings[%d].descriptorCount is not 0, "
1800 "pCreateInfo->pBindings[%d].stageFlags must be a valid combination of VkShaderStageFlagBits values. %s",
1801 i, i, validation_error_map[VALIDATION_ERROR_04e00236]);
1802 }
1803 }
1804 }
1805 }
1806
1807 return skip;
1808}
1809
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001810bool pv_vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount,
1811 const VkDescriptorSet *pDescriptorSets) {
1812 bool skip = false;
1813 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1814 debug_report_data *report_data = device_data->report_data;
1815
1816 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1817 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
1818 // validate_array()
1819 skip |= validate_array(report_data, "vkFreeDescriptorSets", "descriptorSetCount", "pDescriptorSets", descriptorSetCount,
1820 pDescriptorSets, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
1821 return skip;
1822}
1823
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001824bool pv_vkUpdateDescriptorSets(VkDevice device, uint32_t descriptorWriteCount, const VkWriteDescriptorSet *pDescriptorWrites,
1825 uint32_t descriptorCopyCount, const VkCopyDescriptorSet *pDescriptorCopies) {
1826 bool skip = false;
1827 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1828 debug_report_data *report_data = device_data->report_data;
1829
1830 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
1831 if (pDescriptorWrites != NULL) {
1832 for (uint32_t i = 0; i < descriptorWriteCount; ++i) {
1833 // descriptorCount must be greater than 0
1834 if (pDescriptorWrites[i].descriptorCount == 0) {
1835 skip |=
1836 log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
1837 VALIDATION_ERROR_15c0441b, LayerName,
1838 "vkUpdateDescriptorSets(): parameter pDescriptorWrites[%d].descriptorCount must be greater than 0. %s",
1839 i, validation_error_map[VALIDATION_ERROR_15c0441b]);
1840 }
1841
1842 // dstSet must be a valid VkDescriptorSet handle
1843 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1844 ParameterName("pDescriptorWrites[%i].dstSet", ParameterName::IndexVector{i}),
1845 pDescriptorWrites[i].dstSet);
1846
1847 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLER) ||
1848 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) ||
1849 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE) ||
1850 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_IMAGE) ||
1851 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT)) {
1852 // If descriptorType is VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
1853 // VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
1854 // pImageInfo must be a pointer to an array of descriptorCount valid VkDescriptorImageInfo structures
1855 if (pDescriptorWrites[i].pImageInfo == nullptr) {
1856 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1857 __LINE__, VALIDATION_ERROR_15c00284, LayerName,
1858 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
1859 "VK_DESCRIPTOR_TYPE_SAMPLER, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, "
1860 "VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or "
1861 "VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, pDescriptorWrites[%d].pImageInfo must not be NULL. %s",
1862 i, i, validation_error_map[VALIDATION_ERROR_15c00284]);
1863 } else if (pDescriptorWrites[i].descriptorType != VK_DESCRIPTOR_TYPE_SAMPLER) {
1864 // If descriptorType is VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
1865 // VK_DESCRIPTOR_TYPE_STORAGE_IMAGE or VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, the imageView and imageLayout
1866 // members of any given element of pImageInfo must be a valid VkImageView and VkImageLayout, respectively
1867 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
1868 ++descriptor_index) {
1869 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1870 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageView",
1871 ParameterName::IndexVector{i, descriptor_index}),
1872 pDescriptorWrites[i].pImageInfo[descriptor_index].imageView);
1873 skip |= validate_ranged_enum(report_data, "vkUpdateDescriptorSets",
1874 ParameterName("pDescriptorWrites[%i].pImageInfo[%i].imageLayout",
1875 ParameterName::IndexVector{i, descriptor_index}),
1876 "VkImageLayout", AllVkImageLayoutEnums,
1877 pDescriptorWrites[i].pImageInfo[descriptor_index].imageLayout,
1878 VALIDATION_ERROR_UNDEFINED);
1879 }
1880 }
1881 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
1882 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
1883 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) ||
1884 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1885 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER,
1886 // VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, pBufferInfo must be a
1887 // pointer to an array of descriptorCount valid VkDescriptorBufferInfo structures
1888 if (pDescriptorWrites[i].pBufferInfo == nullptr) {
1889 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1890 __LINE__, VALIDATION_ERROR_15c00288, LayerName,
1891 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
1892 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, "
1893 "VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC or VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, "
1894 "pDescriptorWrites[%d].pBufferInfo must not be NULL. %s",
1895 i, i, validation_error_map[VALIDATION_ERROR_15c00288]);
1896 } else {
1897 for (uint32_t descriptorIndex = 0; descriptorIndex < pDescriptorWrites[i].descriptorCount; ++descriptorIndex) {
1898 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1899 ParameterName("pDescriptorWrites[%i].pBufferInfo[%i].buffer",
1900 ParameterName::IndexVector{i, descriptorIndex}),
1901 pDescriptorWrites[i].pBufferInfo[descriptorIndex].buffer);
1902 }
1903 }
1904 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER) ||
1905 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER)) {
1906 // If descriptorType is VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
1907 // pTexelBufferView must be a pointer to an array of descriptorCount valid VkBufferView handles
1908 if (pDescriptorWrites[i].pTexelBufferView == nullptr) {
1909 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1910 __LINE__, VALIDATION_ERROR_15c00286, LayerName,
1911 "vkUpdateDescriptorSets(): if pDescriptorWrites[%d].descriptorType is "
1912 "VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER or VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, "
1913 "pDescriptorWrites[%d].pTexelBufferView must not be NULL. %s",
1914 i, i, validation_error_map[VALIDATION_ERROR_15c00286]);
1915 } else {
1916 for (uint32_t descriptor_index = 0; descriptor_index < pDescriptorWrites[i].descriptorCount;
1917 ++descriptor_index) {
1918 skip |= validate_required_handle(report_data, "vkUpdateDescriptorSets",
1919 ParameterName("pDescriptorWrites[%i].pTexelBufferView[%i]",
1920 ParameterName::IndexVector{i, descriptor_index}),
1921 pDescriptorWrites[i].pTexelBufferView[descriptor_index]);
1922 }
1923 }
1924 }
1925
1926 if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) ||
1927 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC)) {
1928 VkDeviceSize uniformAlignment = device_data->device_limits.minUniformBufferOffsetAlignment;
1929 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
1930 if (pDescriptorWrites[i].pBufferInfo != NULL) {
1931 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment) != 0) {
1932 skip |= log_msg(
1933 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1934 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c0028e, LayerName,
1935 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
1936 ") must be a multiple of device limit minUniformBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
1937 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, uniformAlignment,
1938 validation_error_map[VALIDATION_ERROR_15c0028e]);
1939 }
1940 }
1941 }
1942 } else if ((pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) ||
1943 (pDescriptorWrites[i].descriptorType == VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC)) {
1944 VkDeviceSize storageAlignment = device_data->device_limits.minStorageBufferOffsetAlignment;
1945 for (uint32_t j = 0; j < pDescriptorWrites[i].descriptorCount; j++) {
1946 if (pDescriptorWrites[i].pBufferInfo != NULL) {
1947 if (SafeModulo(pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment) != 0) {
1948 skip |= log_msg(
1949 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
1950 VK_DEBUG_REPORT_OBJECT_TYPE_PHYSICAL_DEVICE_EXT, 0, __LINE__, VALIDATION_ERROR_15c00290, LayerName,
1951 "vkUpdateDescriptorSets(): pDescriptorWrites[%d].pBufferInfo[%d].offset (0x%" PRIxLEAST64
1952 ") must be a multiple of device limit minStorageBufferOffsetAlignment 0x%" PRIxLEAST64 ". %s",
1953 i, j, pDescriptorWrites[i].pBufferInfo[j].offset, storageAlignment,
1954 validation_error_map[VALIDATION_ERROR_15c00290]);
1955 }
1956 }
1957 }
1958 }
1959 }
1960 }
1961 return skip;
1962}
1963
Mark Lobodzinskid4950072017-08-01 13:02:20 -06001964bool pv_vkCreateRenderPass(VkDevice device, const VkRenderPassCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
1965 VkRenderPass *pRenderPass) {
1966 bool skip = false;
1967 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
1968 uint32_t max_color_attachments = device_data->device_limits.maxColorAttachments;
1969
1970 for (uint32_t i = 0; i < pCreateInfo->attachmentCount; ++i) {
1971 if (pCreateInfo->pAttachments[i].format == VK_FORMAT_UNDEFINED) {
1972 std::stringstream ss;
1973 ss << "vkCreateRenderPass: pCreateInfo->pAttachments[" << i << "].format is VK_FORMAT_UNDEFINED. "
1974 << validation_error_map[VALIDATION_ERROR_00809201];
1975 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1976 __LINE__, VALIDATION_ERROR_00809201, "IMAGE", "%s", ss.str().c_str());
1977 }
1978 if (pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_UNDEFINED ||
1979 pCreateInfo->pAttachments[i].finalLayout == VK_IMAGE_LAYOUT_PREINITIALIZED) {
1980 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1981 __LINE__, VALIDATION_ERROR_00800696, "DL",
1982 "pCreateInfo->pAttachments[%d].finalLayout must not be VK_IMAGE_LAYOUT_UNDEFINED or "
1983 "VK_IMAGE_LAYOUT_PREINITIALIZED. %s",
1984 i, validation_error_map[VALIDATION_ERROR_00800696]);
1985 }
1986 }
1987
1988 for (uint32_t i = 0; i < pCreateInfo->subpassCount; ++i) {
1989 if (pCreateInfo->pSubpasses[i].colorAttachmentCount > max_color_attachments) {
1990 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
1991 __LINE__, VALIDATION_ERROR_1400069a, "DL",
1992 "Cannot create a render pass with %d color attachments. Max is %d. %s",
1993 pCreateInfo->pSubpasses[i].colorAttachmentCount, max_color_attachments,
1994 validation_error_map[VALIDATION_ERROR_1400069a]);
1995 }
1996 }
1997 return skip;
1998}
1999
2000bool pv_vkFreeCommandBuffers(VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
2001 const VkCommandBuffer *pCommandBuffers) {
2002 bool skip = false;
2003 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2004 debug_report_data *report_data = device_data->report_data;
2005
2006 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2007 // This is an array of handles, where the elements are allowed to be VK_NULL_HANDLE, and does not require any validation beyond
2008 // validate_array()
2009 skip |= validate_array(report_data, "vkFreeCommandBuffers", "commandBufferCount", "pCommandBuffers", commandBufferCount,
2010 pCommandBuffers, true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2011 return skip;
2012}
2013
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002014bool pv_vkBeginCommandBuffer(VkCommandBuffer commandBuffer, const VkCommandBufferBeginInfo *pBeginInfo) {
2015 bool skip = false;
2016 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2017 debug_report_data *report_data = device_data->report_data;
2018 const VkCommandBufferInheritanceInfo *pInfo = pBeginInfo->pInheritanceInfo;
2019
2020 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2021 // TODO: pBeginInfo->pInheritanceInfo must not be NULL if commandBuffer is a secondary command buffer
2022 skip |= validate_struct_type(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo",
2023 "VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO", pBeginInfo->pInheritanceInfo,
2024 VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, false, VALIDATION_ERROR_UNDEFINED);
2025
2026 if (pBeginInfo->pInheritanceInfo != NULL) {
2027 skip |=
2028 validate_struct_pnext(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pNext", NULL,
2029 pBeginInfo->pInheritanceInfo->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_0281c40d);
2030
2031 skip |= validate_bool32(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->occlusionQueryEnable",
2032 pBeginInfo->pInheritanceInfo->occlusionQueryEnable);
2033
2034 // TODO: This only needs to be validated when the inherited queries feature is enabled
2035 // skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
2036 // "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pBeginInfo->pInheritanceInfo->queryFlags, false);
2037
2038 // TODO: This must be 0 if the pipeline statistics queries feature is not enabled
2039 skip |= validate_flags(report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->pipelineStatistics",
2040 "VkQueryPipelineStatisticFlagBits", AllVkQueryPipelineStatisticFlagBits,
2041 pBeginInfo->pInheritanceInfo->pipelineStatistics, false, false, VALIDATION_ERROR_UNDEFINED);
2042 }
2043
2044 if (pInfo != NULL) {
2045 if ((device_data->physical_device_features.inheritedQueries == VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
2046 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2047 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_02a00070, LayerName,
2048 "Cannot set inherited occlusionQueryEnable in vkBeginCommandBuffer() when device does not support "
2049 "inheritedQueries. %s",
2050 validation_error_map[VALIDATION_ERROR_02a00070]);
2051 }
2052 if ((device_data->physical_device_features.inheritedQueries != VK_FALSE) && (pInfo->occlusionQueryEnable != VK_FALSE)) {
2053 skip |= validate_flags(device_data->report_data, "vkBeginCommandBuffer", "pBeginInfo->pInheritanceInfo->queryFlags",
2054 "VkQueryControlFlagBits", AllVkQueryControlFlagBits, pInfo->queryFlags, false, false,
2055 VALIDATION_ERROR_02a00072);
2056 }
2057 }
2058
2059 return skip;
2060}
2061
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002062bool pv_vkCmdSetViewport(VkCommandBuffer commandBuffer, uint32_t firstViewport, uint32_t viewportCount,
2063 const VkViewport *pViewports) {
2064 bool skip = false;
2065 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2066
2067 skip |= validate_array(device_data->report_data, "vkCmdSetViewport", "viewportCount", "pViewports", viewportCount, pViewports,
2068 true, true, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2069
2070 if (viewportCount > 0 && pViewports != nullptr) {
2071 const VkPhysicalDeviceLimits &limits = device_data->device_limits;
2072 for (uint32_t viewportIndex = 0; viewportIndex < viewportCount; ++viewportIndex) {
2073 const VkViewport &viewport = pViewports[viewportIndex];
2074
2075 if (device_data->physical_device_features.multiViewport == false) {
2076 if (viewportCount != 1) {
2077 skip |= log_msg(
2078 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2079 __LINE__, DEVICE_FEATURE, LayerName,
2080 "vkCmdSetViewport(): The multiViewport feature is not enabled, so viewportCount must be 1 but is %d.",
2081 viewportCount);
2082 }
2083 if (firstViewport != 0) {
2084 skip |= log_msg(
2085 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2086 __LINE__, DEVICE_FEATURE, LayerName,
2087 "vkCmdSetViewport(): The multiViewport feature is not enabled, so firstViewport must be 0 but is %d.",
2088 firstViewport);
2089 }
2090 }
2091
2092 if (viewport.width <= 0 || viewport.width > limits.maxViewportDimensions[0]) {
2093 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2094 __LINE__, VALIDATION_ERROR_15000996, LayerName,
2095 "vkCmdSetViewport %d: width (%f) exceeds permitted bounds (0,%u). %s", viewportIndex,
2096 viewport.width, limits.maxViewportDimensions[0], validation_error_map[VALIDATION_ERROR_15000996]);
2097 }
2098
2099 if (device_data->extensions.vk_amd_negative_viewport_height || device_data->extensions.vk_khr_maintenance1) {
2100 // Check lower bound against negative viewport height instead of zero
2101 if (viewport.height <= -(static_cast<int32_t>(limits.maxViewportDimensions[1])) ||
2102 (viewport.height > limits.maxViewportDimensions[1])) {
2103 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2104 VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__, VALIDATION_ERROR_1500099a, LayerName,
2105 "vkCmdSetViewport %d: height (%f) exceeds permitted bounds (-%u,%u). %s", viewportIndex,
2106 viewport.height, limits.maxViewportDimensions[1], limits.maxViewportDimensions[1],
2107 validation_error_map[VALIDATION_ERROR_1500099a]);
2108 }
2109 } else {
2110 if ((viewport.height <= 0) || (viewport.height > limits.maxViewportDimensions[1])) {
2111 skip |=
2112 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2113 __LINE__, VALIDATION_ERROR_15000998, LayerName,
2114 "vkCmdSetViewport %d: height (%f) exceeds permitted bounds (0,%u). %s", viewportIndex,
2115 viewport.height, limits.maxViewportDimensions[1], validation_error_map[VALIDATION_ERROR_15000998]);
2116 }
2117 }
2118
2119 if (viewport.x < limits.viewportBoundsRange[0] || viewport.x > limits.viewportBoundsRange[1]) {
2120 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2121 __LINE__, VALIDATION_ERROR_1500099e, LayerName,
2122 "vkCmdSetViewport %d: x (%f) exceeds permitted bounds (%f,%f). %s", viewportIndex, viewport.x,
2123 limits.viewportBoundsRange[0], limits.viewportBoundsRange[1],
2124 validation_error_map[VALIDATION_ERROR_1500099e]);
2125 }
2126
2127 if (viewport.y < limits.viewportBoundsRange[0] || viewport.y > limits.viewportBoundsRange[1]) {
2128 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2129 __LINE__, VALIDATION_ERROR_1500099e, LayerName,
2130 "vkCmdSetViewport %d: y (%f) exceeds permitted bounds (%f,%f). %s", viewportIndex, viewport.y,
2131 limits.viewportBoundsRange[0], limits.viewportBoundsRange[1],
2132 validation_error_map[VALIDATION_ERROR_1500099e]);
2133 }
2134
2135 if (viewport.x + viewport.width > limits.viewportBoundsRange[1]) {
2136 skip |=
2137 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2138 __LINE__, VALIDATION_ERROR_150009a0, LayerName,
2139 "vkCmdSetViewport %d: x (%f) + width (%f) exceeds permitted bound (%f). %s", viewportIndex, viewport.x,
2140 viewport.width, limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a0]);
2141 }
2142
2143 if (viewport.y + viewport.height > limits.viewportBoundsRange[1]) {
2144 skip |=
2145 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2146 __LINE__, VALIDATION_ERROR_150009a2, LayerName,
2147 "vkCmdSetViewport %d: y (%f) + height (%f) exceeds permitted bound (%f). %s", viewportIndex, viewport.y,
2148 viewport.height, limits.viewportBoundsRange[1], validation_error_map[VALIDATION_ERROR_150009a2]);
2149 }
2150 }
2151 }
2152 return skip;
2153}
2154
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002155bool pv_vkCmdSetScissor(VkCommandBuffer commandBuffer, uint32_t firstScissor, uint32_t scissorCount, const VkRect2D *pScissors) {
2156 bool skip = false;
2157 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2158 debug_report_data *report_data = device_data->report_data;
2159
2160 if (device_data->physical_device_features.multiViewport == false) {
2161 if (scissorCount != 1) {
2162 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2163 DEVICE_FEATURE, LayerName,
2164 "vkCmdSetScissor(): The multiViewport feature is not enabled, so scissorCount must be 1 but is %d.",
2165 scissorCount);
2166 }
2167 if (firstScissor != 0) {
2168 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2169 DEVICE_FEATURE, LayerName,
2170 "vkCmdSetScissor(): The multiViewport feature is not enabled, so firstScissor must be 0 but is %d.",
2171 firstScissor);
2172 }
2173 }
2174
2175 for (uint32_t scissorIndex = 0; scissorIndex < scissorCount; ++scissorIndex) {
2176 const VkRect2D &pScissor = pScissors[scissorIndex];
2177
2178 if (pScissor.offset.x < 0) {
2179 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2180 VALIDATION_ERROR_1d8004a6, LayerName, "vkCmdSetScissor %d: offset.x (%d) must not be negative. %s",
2181 scissorIndex, pScissor.offset.x, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2182 } else if (static_cast<int32_t>(pScissor.extent.width) > (INT_MAX - pScissor.offset.x)) {
2183 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2184 VALIDATION_ERROR_1d8004a8, LayerName,
2185 "vkCmdSetScissor %d: adding offset.x (%d) and extent.width (%u) will overflow. %s", scissorIndex,
2186 pScissor.offset.x, pScissor.extent.width, validation_error_map[VALIDATION_ERROR_1d8004a8]);
2187 }
2188
2189 if (pScissor.offset.y < 0) {
2190 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2191 VALIDATION_ERROR_1d8004a6, LayerName, "vkCmdSetScissor %d: offset.y (%d) must not be negative. %s",
2192 scissorIndex, pScissor.offset.y, validation_error_map[VALIDATION_ERROR_1d8004a6]);
2193 } else if (static_cast<int32_t>(pScissor.extent.height) > (INT_MAX - pScissor.offset.y)) {
2194 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2195 VALIDATION_ERROR_1d8004aa, LayerName,
2196 "vkCmdSetScissor %d: adding offset.y (%d) and extent.height (%u) will overflow. %s", scissorIndex,
2197 pScissor.offset.y, pScissor.extent.height, validation_error_map[VALIDATION_ERROR_1d8004aa]);
2198 }
2199 }
2200 return skip;
2201}
2202
Petr Kraus299ba622017-11-24 03:09:03 +01002203bool pv_vkCmdSetLineWidth(VkCommandBuffer commandBuffer, float lineWidth) {
2204 bool skip = false;
2205 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2206 debug_report_data *report_data = device_data->report_data;
2207
2208 if (!device_data->physical_device_features.wideLines && (lineWidth != 1.0f)) {
2209 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2210 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_1d600628, LayerName,
2211 "VkPhysicalDeviceFeatures::wideLines is disabled, but lineWidth (=%f) is not 1.0. %s", lineWidth,
2212 validation_error_map[VALIDATION_ERROR_1d600628]);
2213 }
2214
2215 return skip;
2216}
2217
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002218bool pv_vkCmdDraw(VkCommandBuffer commandBuffer, uint32_t vertexCount, uint32_t instanceCount, uint32_t firstVertex,
2219 uint32_t firstInstance) {
2220 bool skip = false;
2221 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2222 if (vertexCount == 0) {
2223 // TODO: Verify against Valid Usage section. I don't see a non-zero vertexCount listed, may need to add that and make
2224 // this an error or leave as is.
2225 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2226 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t vertexCount, is 0");
2227 }
2228
2229 if (instanceCount == 0) {
2230 // TODO: Verify against Valid Usage section. I don't see a non-zero instanceCount listed, may need to add that and make
2231 // this an error or leave as is.
2232 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2233 __LINE__, REQUIRED_PARAMETER, LayerName, "vkCmdDraw parameter, uint32_t instanceCount, is 0");
2234 }
2235 return skip;
2236}
2237
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002238bool pv_vkCmdDrawIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count, uint32_t stride) {
2239 bool skip = false;
2240 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2241
2242 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2243 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2244 __LINE__, DEVICE_FEATURE, LayerName,
2245 "CmdDrawIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2246 }
2247 return skip;
2248}
2249
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002250bool pv_vkCmdDrawIndexedIndirect(VkCommandBuffer commandBuffer, VkBuffer buffer, VkDeviceSize offset, uint32_t count,
2251 uint32_t stride) {
2252 bool skip = false;
2253 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2254 if (!device_data->physical_device_features.multiDrawIndirect && ((count > 1))) {
2255 skip |=
2256 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2257 DEVICE_FEATURE, LayerName,
2258 "CmdDrawIndexedIndirect(): Device feature multiDrawIndirect disabled: count must be 0 or 1 but is %d", count);
2259 }
2260 return skip;
2261}
2262
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002263bool pv_vkCmdCopyImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2264 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageCopy *pRegions) {
2265 bool skip = false;
2266 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2267
2268 if (pRegions != nullptr) {
2269 if ((pRegions->srcSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2270 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2271 skip |= log_msg(
2272 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2273 VALIDATION_ERROR_0a600c01, LayerName,
2274 "vkCmdCopyImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator. %s",
2275 validation_error_map[VALIDATION_ERROR_0a600c01]);
2276 }
2277 if ((pRegions->dstSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2278 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2279 skip |= log_msg(
2280 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2281 VALIDATION_ERROR_0a600c01, LayerName,
2282 "vkCmdCopyImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator. %s",
2283 validation_error_map[VALIDATION_ERROR_0a600c01]);
2284 }
2285 }
2286 return skip;
2287}
2288
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002289bool pv_vkCmdBlitImage(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkImage dstImage,
2290 VkImageLayout dstImageLayout, uint32_t regionCount, const VkImageBlit *pRegions, VkFilter filter) {
2291 bool skip = false;
2292 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2293
2294 if (pRegions != nullptr) {
2295 if ((pRegions->srcSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2296 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2297 skip |= log_msg(
2298 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2299 UNRECOGNIZED_VALUE, LayerName,
2300 "vkCmdBlitImage() parameter, VkImageAspect pRegions->srcSubresource.aspectMask, is an unrecognized enumerator");
2301 }
2302 if ((pRegions->dstSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2303 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2304 skip |= log_msg(
2305 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2306 UNRECOGNIZED_VALUE, LayerName,
2307 "vkCmdBlitImage() parameter, VkImageAspect pRegions->dstSubresource.aspectMask, is an unrecognized enumerator");
2308 }
2309 }
2310 return skip;
2311}
2312
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002313bool pv_vkCmdCopyBufferToImage(VkCommandBuffer commandBuffer, VkBuffer srcBuffer, VkImage dstImage, VkImageLayout dstImageLayout,
2314 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2315 bool skip = false;
2316 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2317
2318 if (pRegions != nullptr) {
2319 if ((pRegions->imageSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2320 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2321 skip |= log_msg(
2322 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2323 UNRECOGNIZED_VALUE, LayerName,
2324 "vkCmdCopyBufferToImage() parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an unrecognized "
2325 "enumerator");
2326 }
2327 }
2328 return skip;
2329}
2330
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002331bool pv_vkCmdCopyImageToBuffer(VkCommandBuffer commandBuffer, VkImage srcImage, VkImageLayout srcImageLayout, VkBuffer dstBuffer,
2332 uint32_t regionCount, const VkBufferImageCopy *pRegions) {
2333 bool skip = false;
2334 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2335
2336 if (pRegions != nullptr) {
2337 if ((pRegions->imageSubresource.aspectMask & (VK_IMAGE_ASPECT_COLOR_BIT | VK_IMAGE_ASPECT_DEPTH_BIT |
2338 VK_IMAGE_ASPECT_STENCIL_BIT | VK_IMAGE_ASPECT_METADATA_BIT)) == 0) {
2339 log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2340 UNRECOGNIZED_VALUE, LayerName,
2341 "vkCmdCopyImageToBuffer parameter, VkImageAspect pRegions->imageSubresource.aspectMask, is an unrecognized "
2342 "enumerator");
2343 }
2344 }
2345 return skip;
2346}
2347
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002348bool pv_vkCmdUpdateBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize dataSize,
2349 const void *pData) {
2350 bool skip = false;
2351 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2352
2353 if (dstOffset & 3) {
2354 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2355 __LINE__, VALIDATION_ERROR_1e400048, LayerName,
2356 "vkCmdUpdateBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2357 dstOffset, validation_error_map[VALIDATION_ERROR_1e400048]);
2358 }
2359
2360 if ((dataSize <= 0) || (dataSize > 65536)) {
2361 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2362 __LINE__, VALIDATION_ERROR_1e40004a, LayerName,
2363 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64
2364 "), must be greater than zero and less than or equal to 65536. %s",
2365 dataSize, validation_error_map[VALIDATION_ERROR_1e40004a]);
2366 } else if (dataSize & 3) {
2367 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2368 __LINE__, VALIDATION_ERROR_1e40004c, LayerName,
2369 "vkCmdUpdateBuffer() parameter, VkDeviceSize dataSize (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2370 dataSize, validation_error_map[VALIDATION_ERROR_1e40004c]);
2371 }
2372 return skip;
2373}
2374
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002375bool pv_vkCmdFillBuffer(VkCommandBuffer commandBuffer, VkBuffer dstBuffer, VkDeviceSize dstOffset, VkDeviceSize size,
2376 uint32_t data) {
2377 bool skip = false;
2378 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2379
2380 if (dstOffset & 3) {
2381 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2382 __LINE__, VALIDATION_ERROR_1b400032, LayerName,
2383 "vkCmdFillBuffer() parameter, VkDeviceSize dstOffset (0x%" PRIxLEAST64 "), is not a multiple of 4. %s",
2384 dstOffset, validation_error_map[VALIDATION_ERROR_1b400032]);
2385 }
2386
2387 if (size != VK_WHOLE_SIZE) {
2388 if (size <= 0) {
2389 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2390 __LINE__, VALIDATION_ERROR_1b400034, LayerName,
2391 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), must be greater than zero. %s",
2392 size, validation_error_map[VALIDATION_ERROR_1b400034]);
2393 } else if (size & 3) {
2394 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2395 __LINE__, VALIDATION_ERROR_1b400038, LayerName,
2396 "vkCmdFillBuffer() parameter, VkDeviceSize size (0x%" PRIxLEAST64 "), is not a multiple of 4. %s", size,
2397 validation_error_map[VALIDATION_ERROR_1b400038]);
2398 }
2399 }
2400 return skip;
2401}
2402
2403VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount, VkLayerProperties *pProperties) {
2404 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2405}
2406
2407VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
2408 VkLayerProperties *pProperties) {
2409 return util_GetLayerProperties(1, &global_layer, pCount, pProperties);
2410}
2411
2412VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
2413 VkExtensionProperties *pProperties) {
2414 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2415 return util_GetExtensionProperties(1, instance_extensions, pCount, pProperties);
2416
2417 return VK_ERROR_LAYER_NOT_PRESENT;
2418}
2419
2420VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice, const char *pLayerName,
2421 uint32_t *pPropertyCount, VkExtensionProperties *pProperties) {
2422 // Parameter_validation does not have any physical device extensions
2423 if (pLayerName && !strcmp(pLayerName, global_layer.layerName))
2424 return util_GetExtensionProperties(0, NULL, pPropertyCount, pProperties);
2425
2426 instance_layer_data *local_data = GetLayerDataPtr(get_dispatch_key(physicalDevice), instance_layer_data_map);
2427 bool skip =
2428 validate_array(local_data->report_data, "vkEnumerateDeviceExtensionProperties", "pPropertyCount", "pProperties",
2429 pPropertyCount, pProperties, true, false, false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_2761f401);
2430 if (skip) return VK_ERROR_VALIDATION_FAILED_EXT;
2431
2432 return local_data->dispatch_table.EnumerateDeviceExtensionProperties(physicalDevice, NULL, pPropertyCount, pProperties);
2433}
2434
2435static bool require_device_extension(layer_data *device_data, bool flag, char const *function_name, char const *extension_name) {
2436 if (!flag) {
2437 return log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2438 __LINE__, EXTENSION_NOT_ENABLED, LayerName,
2439 "%s() called even though the %s extension was not enabled for this VkDevice.", function_name,
2440 extension_name);
2441 }
2442
2443 return false;
2444}
2445
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002446bool pv_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pCreateInfo, const VkAllocationCallbacks *pAllocator,
2447 VkSwapchainKHR *pSwapchain) {
2448 bool skip = false;
2449 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2450 debug_report_data *report_data = device_data->report_data;
2451
Petr Krause5c37652018-01-05 04:05:12 +01002452 const LogMiscParams log_misc{report_data, VK_DEBUG_REPORT_OBJECT_TYPE_SWAPCHAIN_KHR_EXT, VK_NULL_HANDLE, LayerName,
2453 "vkCreateSwapchainKHR"};
2454
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002455 if (pCreateInfo != nullptr) {
2456 if ((device_data->physical_device_features.textureCompressionETC2 == false) &&
2457 FormatIsCompressed_ETC2_EAC(pCreateInfo->imageFormat)) {
2458 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2459 DEVICE_FEATURE, LayerName,
2460 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2461 "textureCompressionETC2 feature is not enabled: neither ETC2 nor EAC formats can be used to create "
2462 "images.",
2463 string_VkFormat(pCreateInfo->imageFormat));
2464 }
2465
2466 if ((device_data->physical_device_features.textureCompressionASTC_LDR == false) &&
2467 FormatIsCompressed_ASTC_LDR(pCreateInfo->imageFormat)) {
2468 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2469 DEVICE_FEATURE, LayerName,
2470 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2471 "textureCompressionASTC_LDR feature is not enabled: ASTC formats cannot be used to create images.",
2472 string_VkFormat(pCreateInfo->imageFormat));
2473 }
2474
2475 if ((device_data->physical_device_features.textureCompressionBC == false) &&
2476 FormatIsCompressed_BC(pCreateInfo->imageFormat)) {
2477 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2478 DEVICE_FEATURE, LayerName,
2479 "vkCreateSwapchainKHR(): Attempting to create swapchain VkImage with format %s. The "
2480 "textureCompressionBC feature is not enabled: BC compressed formats cannot be used to create images.",
2481 string_VkFormat(pCreateInfo->imageFormat));
2482 }
2483
2484 // Validation for parameters excluded from the generated validation code due to a 'noautovalidity' tag in vk.xml
2485 if (pCreateInfo->imageSharingMode == VK_SHARING_MODE_CONCURRENT) {
2486 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, queueFamilyIndexCount must be greater than 1
2487 if (pCreateInfo->queueFamilyIndexCount <= 1) {
2488 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2489 VALIDATION_ERROR_146009fc, LayerName,
2490 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2491 "pCreateInfo->queueFamilyIndexCount must be greater than 1. %s",
2492 validation_error_map[VALIDATION_ERROR_146009fc]);
2493 }
2494
2495 // If imageSharingMode is VK_SHARING_MODE_CONCURRENT, pQueueFamilyIndices must be a pointer to an array of
2496 // queueFamilyIndexCount uint32_t values
2497 if (pCreateInfo->pQueueFamilyIndices == nullptr) {
2498 skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, __LINE__,
2499 VALIDATION_ERROR_146009fa, LayerName,
2500 "vkCreateSwapchainKHR(): if pCreateInfo->imageSharingMode is VK_SHARING_MODE_CONCURRENT, "
2501 "pCreateInfo->pQueueFamilyIndices must be a pointer to an array of "
2502 "pCreateInfo->queueFamilyIndexCount uint32_t values. %s",
2503 validation_error_map[VALIDATION_ERROR_146009fa]);
2504 } else {
2505 // TODO: Not in the spec VUs. Probably missing -- KhronosGroup/Vulkan-Docs#501. Update error codes when resolved.
2506 skip |= ValidateQueueFamilies(device_data, pCreateInfo->queueFamilyIndexCount, pCreateInfo->pQueueFamilyIndices,
2507 "vkCreateSwapchainKHR", "pCreateInfo->pQueueFamilyIndices", INVALID_USAGE,
2508 INVALID_USAGE, false, "", "");
2509 }
2510 }
2511
Petr Krause5c37652018-01-05 04:05:12 +01002512 skip |= ValidateGreaterThanZero(pCreateInfo->imageArrayLayers, "pCreateInfo->imageArrayLayers", VALIDATION_ERROR_146009f6,
2513 log_misc);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002514 }
2515
2516 return skip;
2517}
2518
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002519bool pv_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) {
2520 bool skip = false;
2521 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(queue), layer_data_map);
2522
2523 if (pPresentInfo && pPresentInfo->pNext) {
John Zulaufde972ac2017-10-26 12:07:05 -06002524 const auto *present_regions = lvl_find_in_chain<VkPresentRegionsKHR>(pPresentInfo->pNext);
2525 if (present_regions) {
2526 // TODO: This and all other pNext extension dependencies should be added to code-generation
2527 skip |= require_device_extension(device_data, device_data->extensions.vk_khr_incremental_present, "vkQueuePresentKHR",
2528 VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME);
2529 if (present_regions->swapchainCount != pPresentInfo->swapchainCount) {
2530 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2531 __LINE__, INVALID_USAGE, LayerName,
2532 "QueuePresentKHR(): pPresentInfo->swapchainCount has a value of %i"
2533 " but VkPresentRegionsKHR extension swapchainCount is %i. These values must be equal.",
2534 pPresentInfo->swapchainCount, present_regions->swapchainCount);
2535 }
2536 skip |= validate_struct_pnext(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pNext", NULL,
2537 present_regions->pNext, 0, NULL, GeneratedHeaderVersion, VALIDATION_ERROR_1121c40d);
2538 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->swapchainCount",
2539 "pCreateInfo->pNext->pRegions", present_regions->swapchainCount, present_regions->pRegions, true,
2540 false, VALIDATION_ERROR_UNDEFINED, VALIDATION_ERROR_UNDEFINED);
2541 for (uint32_t i = 0; i < present_regions->swapchainCount; ++i) {
2542 skip |= validate_array(device_data->report_data, "QueuePresentKHR", "pCreateInfo->pNext->pRegions[].rectangleCount",
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002543 "pCreateInfo->pNext->pRegions[].pRectangles", present_regions->pRegions[i].rectangleCount,
2544 present_regions->pRegions[i].pRectangles, true, false, VALIDATION_ERROR_UNDEFINED,
2545 VALIDATION_ERROR_UNDEFINED);
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002546 }
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002547 }
2548 }
2549
2550 return skip;
2551}
2552
2553#ifdef VK_USE_PLATFORM_WIN32_KHR
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002554bool pv_vkCreateWin32SurfaceKHR(VkInstance instance, const VkWin32SurfaceCreateInfoKHR *pCreateInfo,
2555 const VkAllocationCallbacks *pAllocator, VkSurfaceKHR *pSurface) {
2556 auto device_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2557 bool skip = false;
2558
2559 if (pCreateInfo->hwnd == nullptr) {
2560 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0,
2561 __LINE__, VALIDATION_ERROR_15a00a38, LayerName,
2562 "vkCreateWin32SurfaceKHR(): hwnd must be a valid Win32 HWND but hwnd is NULL. %s",
2563 validation_error_map[VALIDATION_ERROR_15a00a38]);
2564 }
2565
2566 return skip;
2567}
2568#endif // VK_USE_PLATFORM_WIN32_KHR
2569
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002570bool pv_vkDebugMarkerSetObjectNameEXT(VkDevice device, const VkDebugMarkerObjectNameInfoEXT *pNameInfo) {
2571 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2572 if (pNameInfo->pObjectName) {
2573 device_data->report_data->debugObjectNameMap->insert(
2574 std::make_pair<uint64_t, std::string>((uint64_t &&) pNameInfo->object, pNameInfo->pObjectName));
2575 } else {
2576 device_data->report_data->debugObjectNameMap->erase(pNameInfo->object);
2577 }
2578 return false;
2579}
2580
Petr Krausc8655be2017-09-27 18:56:51 +02002581bool pv_vkCreateDescriptorPool(VkDevice device, const VkDescriptorPoolCreateInfo *pCreateInfo,
2582 const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool) {
2583 auto device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2584 bool skip = false;
2585
2586 if (pCreateInfo) {
2587 if (pCreateInfo->maxSets <= 0) {
2588 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT,
2589 VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT, VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_0480025a,
2590 LayerName, "vkCreateDescriptorPool(): pCreateInfo->maxSets is not greater than 0. %s",
2591 validation_error_map[VALIDATION_ERROR_0480025a]);
2592 }
2593
2594 if (pCreateInfo->pPoolSizes) {
2595 for (uint32_t i = 0; i < pCreateInfo->poolSizeCount; ++i) {
2596 if (pCreateInfo->pPoolSizes[i].descriptorCount <= 0) {
2597 skip |= log_msg(
2598 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DESCRIPTOR_POOL_EXT,
2599 VK_NULL_HANDLE, __LINE__, VALIDATION_ERROR_04a0025c, LayerName,
2600 "vkCreateDescriptorPool(): pCreateInfo->pPoolSizes[%" PRIu32 "].descriptorCount is not greater than 0. %s",
2601 i, validation_error_map[VALIDATION_ERROR_04a0025c]);
2602 }
2603 }
2604 }
2605 }
2606
2607 return skip;
2608}
2609
Dave Houltonbb7d3fe2018-01-11 17:09:16 -07002610bool pv_vkCmdDispatch(VkCommandBuffer commandBuffer, uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) {
2611 bool skip = false;
2612 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2613
2614 if (groupCountX > device_data->device_limits.maxComputeWorkGroupCount[0]) {
2615 skip |= log_msg(
2616 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2617 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00304, LayerName,
2618 "vkCmdDispatch(): groupCountX (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
2619 groupCountX, device_data->device_limits.maxComputeWorkGroupCount[0], validation_error_map[VALIDATION_ERROR_19c00304]);
2620 }
2621
2622 if (groupCountY > device_data->device_limits.maxComputeWorkGroupCount[1]) {
2623 skip |= log_msg(
2624 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2625 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00306, LayerName,
2626 "vkCmdDispatch(): groupCountY (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
2627 groupCountY, device_data->device_limits.maxComputeWorkGroupCount[1], validation_error_map[VALIDATION_ERROR_19c00306]);
2628 }
2629
2630 if (groupCountZ > device_data->device_limits.maxComputeWorkGroupCount[2]) {
2631 skip |= log_msg(
2632 device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2633 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19c00308, LayerName,
2634 "vkCmdDispatch(): groupCountZ (%" PRIu32 ") exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
2635 groupCountZ, device_data->device_limits.maxComputeWorkGroupCount[2], validation_error_map[VALIDATION_ERROR_19c00308]);
2636 }
2637
2638 return skip;
2639}
2640
2641bool pv_vkCmdDispatchBaseKHX(VkCommandBuffer commandBuffer, uint32_t baseGroupX, uint32_t baseGroupY, uint32_t baseGroupZ,
2642 uint32_t groupCountX, uint32_t groupCountY, uint32_t groupCountZ) {
2643 bool skip = false;
2644 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(commandBuffer), layer_data_map);
2645
2646 // Paired if {} else if {} tests used to avoid any possible uint underflow
2647 uint32_t limit = device_data->device_limits.maxComputeWorkGroupCount[0];
2648 if (baseGroupX >= limit) {
2649 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2650 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034a, LayerName,
2651 "vkCmdDispatch(): baseGroupX (%" PRIu32
2652 ") equals or exceeds device limit maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
2653 baseGroupX, limit, validation_error_map[VALIDATION_ERROR_19e0034a]);
2654 } else if (groupCountX > (limit - baseGroupX)) {
2655 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2656 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00350, LayerName,
2657 "vkCmdDispatchBaseKHX(): baseGroupX (%" PRIu32 ") + groupCountX (%" PRIu32
2658 ") exceeds device limit "
2659 "maxComputeWorkGroupCount[0] (%" PRIu32 "). %s",
2660 baseGroupX, groupCountX, limit, validation_error_map[VALIDATION_ERROR_19e00350]);
2661 }
2662
2663 limit = device_data->device_limits.maxComputeWorkGroupCount[1];
2664 if (baseGroupY >= limit) {
2665 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2666 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034c, LayerName,
2667 "vkCmdDispatch(): baseGroupY (%" PRIu32
2668 ") equals or exceeds device limit maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
2669 baseGroupY, limit, validation_error_map[VALIDATION_ERROR_19e0034c]);
2670 } else if (groupCountY > (limit - baseGroupY)) {
2671 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2672 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00352, LayerName,
2673 "vkCmdDispatchBaseKHX(): baseGroupY (%" PRIu32 ") + groupCountY (%" PRIu32
2674 ") exceeds device limit "
2675 "maxComputeWorkGroupCount[1] (%" PRIu32 "). %s",
2676 baseGroupY, groupCountY, limit, validation_error_map[VALIDATION_ERROR_19e00352]);
2677 }
2678
2679 limit = device_data->device_limits.maxComputeWorkGroupCount[2];
2680 if (baseGroupZ >= limit) {
2681 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2682 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e0034e, LayerName,
2683 "vkCmdDispatch(): baseGroupZ (%" PRIu32
2684 ") equals or exceeds device limit maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
2685 baseGroupZ, limit, validation_error_map[VALIDATION_ERROR_19e0034e]);
2686 } else if (groupCountZ > (limit - baseGroupZ)) {
2687 skip |= log_msg(device_data->report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_COMMAND_BUFFER_EXT,
2688 HandleToUint64(commandBuffer), __LINE__, VALIDATION_ERROR_19e00354, LayerName,
2689 "vkCmdDispatchBaseKHX(): baseGroupZ (%" PRIu32 ") + groupCountZ (%" PRIu32
2690 ") exceeds device limit "
2691 "maxComputeWorkGroupCount[2] (%" PRIu32 "). %s",
2692 baseGroupZ, groupCountZ, limit, validation_error_map[VALIDATION_ERROR_19e00354]);
2693 }
2694
2695 return skip;
2696}
2697
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002698VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice device, const char *funcName) {
2699 const auto item = name_to_funcptr_map.find(funcName);
2700 if (item != name_to_funcptr_map.end()) {
2701 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2702 }
2703
2704 layer_data *device_data = GetLayerDataPtr(get_dispatch_key(device), layer_data_map);
2705 const auto &table = device_data->dispatch_table;
2706 if (!table.GetDeviceProcAddr) return nullptr;
2707 return table.GetDeviceProcAddr(device, funcName);
2708}
2709
2710VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2711 const auto item = name_to_funcptr_map.find(funcName);
2712 if (item != name_to_funcptr_map.end()) {
2713 return reinterpret_cast<PFN_vkVoidFunction>(item->second);
2714 }
2715
2716 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2717 auto &table = instance_data->dispatch_table;
2718 if (!table.GetInstanceProcAddr) return nullptr;
2719 return table.GetInstanceProcAddr(instance, funcName);
2720}
2721
2722VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetPhysicalDeviceProcAddr(VkInstance instance, const char *funcName) {
2723 assert(instance);
2724 auto instance_data = GetLayerDataPtr(get_dispatch_key(instance), instance_layer_data_map);
2725
2726 if (!instance_data->dispatch_table.GetPhysicalDeviceProcAddr) return nullptr;
2727 return instance_data->dispatch_table.GetPhysicalDeviceProcAddr(instance, funcName);
2728}
2729
2730// If additional validation is needed outside of the generated checks, a manual routine can be added to this file
2731// 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 +02002732void InitializeManualParameterValidationFunctionPointers() {
Dave Houltonb3bbec72018-01-17 10:13:33 -07002733 custom_functions["vkGetDeviceQueue"] = (void *)pv_vkGetDeviceQueue;
2734 custom_functions["vkCreateBuffer"] = (void *)pv_vkCreateBuffer;
2735 custom_functions["vkCreateImage"] = (void *)pv_vkCreateImage;
2736 custom_functions["vkCreateImageView"] = (void *)pv_vkCreateImageView;
2737 custom_functions["vkCreateGraphicsPipelines"] = (void *)pv_vkCreateGraphicsPipelines;
2738 custom_functions["vkCreateComputePipelines"] = (void *)pv_vkCreateComputePipelines;
2739 custom_functions["vkCreateSampler"] = (void *)pv_vkCreateSampler;
2740 custom_functions["vkCreateDescriptorSetLayout"] = (void *)pv_vkCreateDescriptorSetLayout;
2741 custom_functions["vkFreeDescriptorSets"] = (void *)pv_vkFreeDescriptorSets;
2742 custom_functions["vkUpdateDescriptorSets"] = (void *)pv_vkUpdateDescriptorSets;
2743 custom_functions["vkCreateRenderPass"] = (void *)pv_vkCreateRenderPass;
2744 custom_functions["vkBeginCommandBuffer"] = (void *)pv_vkBeginCommandBuffer;
2745 custom_functions["vkCmdSetViewport"] = (void *)pv_vkCmdSetViewport;
2746 custom_functions["vkCmdSetScissor"] = (void *)pv_vkCmdSetScissor;
Petr Kraus299ba622017-11-24 03:09:03 +01002747 custom_functions["vkCmdSetLineWidth"] = (void *)pv_vkCmdSetLineWidth;
Dave Houltonb3bbec72018-01-17 10:13:33 -07002748 custom_functions["vkCmdDraw"] = (void *)pv_vkCmdDraw;
2749 custom_functions["vkCmdDrawIndirect"] = (void *)pv_vkCmdDrawIndirect;
2750 custom_functions["vkCmdDrawIndexedIndirect"] = (void *)pv_vkCmdDrawIndexedIndirect;
2751 custom_functions["vkCmdCopyImage"] = (void *)pv_vkCmdCopyImage;
2752 custom_functions["vkCmdBlitImage"] = (void *)pv_vkCmdBlitImage;
2753 custom_functions["vkCmdCopyBufferToImage"] = (void *)pv_vkCmdCopyBufferToImage;
2754 custom_functions["vkCmdCopyImageToBuffer"] = (void *)pv_vkCmdCopyImageToBuffer;
2755 custom_functions["vkCmdUpdateBuffer"] = (void *)pv_vkCmdUpdateBuffer;
2756 custom_functions["vkCmdFillBuffer"] = (void *)pv_vkCmdFillBuffer;
2757 custom_functions["vkCreateSwapchainKHR"] = (void *)pv_vkCreateSwapchainKHR;
2758 custom_functions["vkQueuePresentKHR"] = (void *)pv_vkQueuePresentKHR;
2759 custom_functions["vkCreateDescriptorPool"] = (void *)pv_vkCreateDescriptorPool;
2760 custom_functions["vkCmdDispatch"] = (void *)pv_vkCmdDispatch;
2761 custom_functions["vkCmdDispatchBaseKHX"] = (void *)pv_vkCmdDispatchBaseKHX;
Mark Lobodzinskid4950072017-08-01 13:02:20 -06002762}
2763
2764} // namespace parameter_validation
2765
2766VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
2767 VkExtensionProperties *pProperties) {
2768 return parameter_validation::vkEnumerateInstanceExtensionProperties(pLayerName, pCount, pProperties);
2769}
2770
2771VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateInstanceLayerProperties(uint32_t *pCount,
2772 VkLayerProperties *pProperties) {
2773 return parameter_validation::vkEnumerateInstanceLayerProperties(pCount, pProperties);
2774}
2775
2776VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, uint32_t *pCount,
2777 VkLayerProperties *pProperties) {
2778 // the layer command handles VK_NULL_HANDLE just fine internally
2779 assert(physicalDevice == VK_NULL_HANDLE);
2780 return parameter_validation::vkEnumerateDeviceLayerProperties(VK_NULL_HANDLE, pCount, pProperties);
2781}
2782
2783VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
2784 const char *pLayerName, uint32_t *pCount,
2785 VkExtensionProperties *pProperties) {
2786 // the layer command handles VK_NULL_HANDLE just fine internally
2787 assert(physicalDevice == VK_NULL_HANDLE);
2788 return parameter_validation::vkEnumerateDeviceExtensionProperties(VK_NULL_HANDLE, pLayerName, pCount, pProperties);
2789}
2790
2791VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetDeviceProcAddr(VkDevice dev, const char *funcName) {
2792 return parameter_validation::vkGetDeviceProcAddr(dev, funcName);
2793}
2794
2795VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
2796 return parameter_validation::vkGetInstanceProcAddr(instance, funcName);
2797}
2798
2799VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL vk_layerGetPhysicalDeviceProcAddr(VkInstance instance,
2800 const char *funcName) {
2801 return parameter_validation::vkGetPhysicalDeviceProcAddr(instance, funcName);
2802}
2803
2804VK_LAYER_EXPORT bool pv_vkNegotiateLoaderLayerInterfaceVersion(VkNegotiateLayerInterface *pVersionStruct) {
2805 assert(pVersionStruct != NULL);
2806 assert(pVersionStruct->sType == LAYER_NEGOTIATE_INTERFACE_STRUCT);
2807
2808 // Fill in the function pointers if our version is at least capable of having the structure contain them.
2809 if (pVersionStruct->loaderLayerInterfaceVersion >= 2) {
2810 pVersionStruct->pfnGetInstanceProcAddr = vkGetInstanceProcAddr;
2811 pVersionStruct->pfnGetDeviceProcAddr = vkGetDeviceProcAddr;
2812 pVersionStruct->pfnGetPhysicalDeviceProcAddr = vk_layerGetPhysicalDeviceProcAddr;
2813 }
2814
2815 if (pVersionStruct->loaderLayerInterfaceVersion < CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
2816 parameter_validation::loader_layer_if_version = pVersionStruct->loaderLayerInterfaceVersion;
2817 } else if (pVersionStruct->loaderLayerInterfaceVersion > CURRENT_LOADER_LAYER_INTERFACE_VERSION) {
2818 pVersionStruct->loaderLayerInterfaceVersion = CURRENT_LOADER_LAYER_INTERFACE_VERSION;
2819 }
2820
2821 return VK_SUCCESS;
2822}